-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
5,842 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{F8BDF57B-1571-4CD0-84B3-B422088D359A}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>Aaru.Helpers</RootNamespace> | ||
<AssemblyName>Aaru.Helpers</AssemblyName> | ||
<ReleaseVersion>$(Version)</ReleaseVersion> | ||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> | ||
<Version>6.0.0-alpha9</Version> | ||
<Company>Claunia.com</Company> | ||
<Copyright>Copyright © 2011-2023 Natalia Portillo</Copyright> | ||
<Product>Aaru Data Preservation Suite</Product> | ||
<Title>Aaru.Helpers</Title> | ||
<ApplicationVersion>$(Version)</ApplicationVersion> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<LangVersion>12</LangVersion> | ||
<Description>Contains helpers used by the Aaru Data Preservation Suite.</Description> | ||
<PackageProjectUrl>https://github.com/aaru-dps/</PackageProjectUrl> | ||
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression> | ||
<RepositoryUrl>https://github.com/aaru-dps/Aaru.Helpers</RepositoryUrl> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
<Authors>Natalia Portillo <[email protected]></Authors> | ||
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports> | ||
<EnableTrimAnalyzer>true</EnableTrimAnalyzer> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<NoWarn>CS1591;CS1574</NoWarn> | ||
</PropertyGroup> | ||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<InternalsVisibleTo Include="Aaru.Tests"/> | ||
<InternalsVisibleTo Include="Aaru.Tests.Devices"/> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<NrtRevisionFormat>$(Version)+{chash:8}</NrtRevisionFormat> | ||
<NrtResolveSimpleAttributes>true</NrtResolveSimpleAttributes> | ||
<NrtShowRevision>true</NrtShowRevision> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Aaru.Console\Aaru.Console.csproj"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="..\LICENSE.LGPL"> | ||
<Link>LICENSE.LGPL</Link> | ||
</EmbeddedResource> | ||
<EmbeddedResource Update="Localization\Localization.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Localization.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="System.Memory" Version="4.5.5"/> | ||
<PackageReference Include="Unclassified.NetRevisionTask" Version="0.4.3" PrivateAssets="all"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:s="clr-namespace:System;assembly=mscorlib" | ||
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xml:space="preserve"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=localization/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// /*************************************************************************** | ||
// Aaru Data Preservation Suite | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// Filename : ArrayFill.cs | ||
// Author(s) : Natalia Portillo <[email protected]> | ||
// | ||
// Component : Helpers. | ||
// | ||
// --[ Description ] ---------------------------------------------------------- | ||
// | ||
// Fills an array with a specified value. | ||
// | ||
// --[ License ] -------------------------------------------------------------- | ||
// | ||
// No license specified by creator. | ||
// | ||
// Published on https://github.com/mykohsu/Extensions/blob/master/ArrayExtensions.cs | ||
// | ||
// Assuming open source. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// Copyright © 2011-2023 Natalia Portillo | ||
// Copyright(C) 2014 mykohsu | ||
// ****************************************************************************/ | ||
|
||
using System; | ||
using System.Text; | ||
|
||
namespace Aaru.Helpers; | ||
|
||
public static partial class ArrayHelpers | ||
{ | ||
/// <summary>Fills an array with the specified value</summary> | ||
/// <param name="destinationArray">Array</param> | ||
/// <param name="value">Value</param> | ||
/// <typeparam name="T">Array type</typeparam> | ||
public static void ArrayFill<T>(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] | ||
{ | ||
value | ||
}); | ||
|
||
/// <summary>Fills an array with the contents of the specified array</summary> | ||
/// <param name="destinationArray">Array</param> | ||
/// <param name="value">Value</param> | ||
/// <typeparam name="T">Array type</typeparam> | ||
public static void ArrayFill<T>(T[] destinationArray, T[] value) | ||
{ | ||
ArgumentNullException.ThrowIfNull(destinationArray); | ||
|
||
if(value.Length > destinationArray.Length) | ||
throw new ArgumentException(Localization.Length_of_value_array_must_not_be_more_than_length_of_destination); | ||
|
||
// set the initial array value | ||
Array.Copy(value, destinationArray, value.Length); | ||
|
||
int arrayToFillHalfLength = destinationArray.Length / 2; | ||
int copyLength; | ||
|
||
for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) | ||
Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); | ||
|
||
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); | ||
} | ||
|
||
/// <summary>Converts a byte array to its hexadecimal representation</summary> | ||
/// <param name="array">Byte array</param> | ||
/// <param name="upper"><c>true</c> to use uppercase</param> | ||
/// <returns></returns> | ||
public static string ByteArrayToHex(byte[] array, bool upper = false) | ||
{ | ||
var sb = new StringBuilder(); | ||
|
||
for(long i = 0; i < array.LongLength; i++) | ||
sb.Append($"{array[i]:x2}"); | ||
|
||
return upper ? sb.ToString().ToUpper() : sb.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// /*************************************************************************** | ||
// Aaru Data Preservation Suite | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// Filename : ArrayIsEmpty.cs | ||
// Author(s) : Natalia Portillo <[email protected]> | ||
// | ||
// Component : Helpers. | ||
// | ||
// --[ Description ] ---------------------------------------------------------- | ||
// | ||
// Methods for detecting an empty array. | ||
// | ||
// --[ License ] -------------------------------------------------------------- | ||
// | ||
// This library is free software; you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as | ||
// published by the Free Software Foundation; either version 2.1 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// Copyright © 2011-2023 Natalia Portillo | ||
// ****************************************************************************/ | ||
|
||
using System.Linq; | ||
|
||
namespace Aaru.Helpers; | ||
|
||
/// <summary>Helper operations to work with arrays</summary> | ||
public static partial class ArrayHelpers | ||
{ | ||
/// <summary>Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20)</summary> | ||
/// <param name="array">Array</param> | ||
/// <returns>True if null or whitespace</returns> | ||
public static bool ArrayIsNullOrWhiteSpace(byte[] array) => array?.All(b => b is 0x00 or 0x20) != false; | ||
|
||
/// <summary>Checks if an array is null or filled with the NULL byte (0x00)</summary> | ||
/// <param name="array">Array</param> | ||
/// <returns>True if null</returns> | ||
public static bool ArrayIsNullOrEmpty(byte[] array) => array?.All(b => b == 0x00) != false; | ||
} |
Oops, something went wrong.