Use Humanizer to print bytes.

This commit is contained in:
2023-09-26 01:29:40 +01:00
parent 06edf51ebc
commit 4cbc8da22a
12 changed files with 9507 additions and 6279 deletions

View File

@@ -73,6 +73,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

View File

@@ -47,6 +47,7 @@ using Aaru.Core.Graphics;
using Aaru.Core.Logging;
using Aaru.Decoders.SCSI;
using Aaru.Devices;
using Humanizer.Bytes;
using Version = Aaru.CommonTypes.Interop.Version;
namespace Aaru.Core.Devices.Dumping;
@@ -121,41 +122,9 @@ partial class Dump
{
blocks++;
ulong totalSize = blocks * blockSize;
switch(totalSize)
{
case > 1099511627776:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_TiB,
blocks, blockSize, totalSize / 1099511627776d));
break;
case > 1073741824:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB,
blocks, blockSize, totalSize / 1073741824d));
break;
case > 1048576:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB,
blocks, blockSize, totalSize / 1048576d));
break;
case > 1024:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB,
blocks, blockSize, totalSize / 1024d));
break;
default:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes,
blocks, blockSize, totalSize));
break;
}
UpdateStatus?.Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2,
blocks, blockSize,
ByteSize.FromBytes(blocks * blockSize).ToString("0.000")));
}
// Check how many blocks to read, if error show and return

View File

@@ -47,6 +47,7 @@ using Aaru.Core.Graphics;
using Aaru.Core.Logging;
using Aaru.Decoders.SCSI;
using Aaru.Devices;
using Humanizer.Bytes;
using Version = Aaru.CommonTypes.Interop.Version;
namespace Aaru.Core.Devices.Dumping;
@@ -90,41 +91,9 @@ public partial class Dump
blocks++;
ulong totalSize = blocks * (ulong)blockSize;
switch(totalSize)
{
case > 1099511627776:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_TiB,
blocks, blockSize, totalSize / 1099511627776d));
break;
case > 1073741824:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB,
blocks, blockSize, totalSize / 1073741824d));
break;
case > 1048576:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB,
blocks, blockSize, totalSize / 1048576d));
break;
case > 1024:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB,
blocks, blockSize, totalSize / 1024d));
break;
default:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes,
blocks, blockSize, totalSize));
break;
}
UpdateStatus?.Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2,
blocks, blockSize,
ByteSize.FromBytes(blocks * blockSize).ToString("0.000")));
if(blocks == 0)
{

View File

@@ -45,6 +45,7 @@ using Aaru.Core.Graphics;
using Aaru.Core.Logging;
using Aaru.Decoders.SCSI;
using Aaru.Devices;
using Humanizer.Bytes;
using Track = Aaru.CommonTypes.Structs.Track;
using TrackType = Aaru.CommonTypes.Enums.TrackType;
using Version = Aaru.CommonTypes.Interop.Version;
@@ -109,35 +110,9 @@ public partial class Dump
ulong blocks = umdSizeInBytes / blockSize;
string mediaPartNumber = Encoding.ASCII.GetString(readBuffer, 0, 11).Trim();
ulong totalSize = blocks * blockSize;
switch(totalSize)
{
case > 1073741824:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB,
blocks, blockSize, totalSize / 1073741824d));
break;
case > 1048576:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB,
blocks, blockSize, totalSize / 1048576d));
break;
case > 1024:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB,
blocks, blockSize, totalSize / 1024d));
break;
default:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes,
blocks, blockSize, totalSize));
break;
}
UpdateStatus?.Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2,
blocks, blockSize,
ByteSize.FromBytes(blocks * blockSize).ToString("0.000")));
UpdateStatus?.Invoke(string.Format(Localization.Core.Device_reports_0_blocks_1_bytes, blocks,
blocks * blockSize));

View File

@@ -52,6 +52,7 @@ using Aaru.Decoders.DVD;
using Aaru.Decoders.SCSI;
using Aaru.Decoders.SCSI.MMC;
using Aaru.Devices;
using Humanizer.Bytes;
using DVDDecryption = Aaru.Decryption.DVD.Dump;
using Track = Aaru.CommonTypes.Structs.Track;
using TrackType = Aaru.CommonTypes.Enums.TrackType;
@@ -223,41 +224,9 @@ partial class Dump
{
blocks++;
ulong totalSize = blocks * blockSize;
switch(totalSize)
{
case > 1099511627776:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_TiB,
blocks, blockSize, totalSize / 1099511627776d));
break;
case > 1073741824:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB,
blocks, blockSize, totalSize / 1073741824d));
break;
case > 1048576:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB,
blocks, blockSize, totalSize / 1048576d));
break;
case > 1024:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB,
blocks, blockSize, totalSize / 1024d));
break;
default:
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes,
blocks, blockSize, totalSize));
break;
}
UpdateStatus?.Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2,
blocks, blockSize,
ByteSize.FromBytes(blocks * blockSize).ToString("0.000")));
}
// Check how many blocks to read, if error show and return

View File

@@ -40,6 +40,7 @@ using Aaru.Decoders.CD;
using Aaru.Decoders.SCSI;
using Aaru.Decoders.SCSI.MMC;
using Aaru.Devices;
using Humanizer.Bytes;
namespace Aaru.Core.Devices.Scanning;
@@ -199,46 +200,10 @@ public sealed partial class MediaScan
{
results.Blocks++;
ulong totalSize = results.Blocks * blockSize;
switch(totalSize)
{
case > 1099511627776:
UpdateStatus?.
Invoke(string.
Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_TiB,
results.Blocks, blockSize, totalSize / 1099511627776d));
break;
case > 1073741824:
UpdateStatus?.
Invoke(string.
Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB,
results.Blocks, blockSize, totalSize / 1073741824d));
break;
case > 1048576:
UpdateStatus?.
Invoke(string.
Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB,
results.Blocks, blockSize, totalSize / 1048576d));
break;
case > 1024:
UpdateStatus?.
Invoke(string.
Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB,
results.Blocks, blockSize, totalSize / 1024d));
break;
default:
UpdateStatus?.
Invoke(string.
Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes,
results.Blocks, blockSize, totalSize));
break;
}
UpdateStatus?.
Invoke(string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2,
results.Blocks, blockSize,
ByteSize.FromBytes(results.Blocks * blockSize).ToString("0.000")));
}
break;

View File

@@ -34,6 +34,7 @@
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.4"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.4" />
<PackageReference Include="Claunia.Encoding" Version="1.9.2"/>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0" />
<PackageReference Include="MessageBox.Avalonia" Version="3.1.4" />
<!-- TODO: Abandoned project need to find replacement

View File

@@ -45,6 +45,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Humanizer.Bytes;
using MsBox.Avalonia;
using MsBox.Avalonia.Enums;
using ReactiveUI;
@@ -104,24 +105,9 @@ public sealed class MediaInfoViewModel : ViewModelBase
if(scsiInfo.Blocks != 0 &&
scsiInfo.BlockSize != 0)
{
ulong totalSize = scsiInfo.Blocks * scsiInfo.BlockSize;
MediaSize = totalSize switch
{
> 1099511627776 =>
string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_TiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1099511627776d),
> 1073741824 => string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1073741824d),
> 1048576 => string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1048576d),
> 1024 => string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1024d),
_ => string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize)
};
}
MediaSize = string.Format(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2,
scsiInfo.Blocks, scsiInfo.BlockSize,
ByteSize.FromBytes(scsiInfo.Blocks * scsiInfo.BlockSize).ToString("0.000"));
if(scsiInfo.MediaSerialNumber != null)
{

File diff suppressed because it is too large Load Diff

View File

@@ -285,24 +285,8 @@
<data name="Stack_trace_0" xml:space="preserve">
<value>Stack trace: {0}</value>
</data>
<data name="Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_TiB" xml:space="preserve">
<value>Media has {0} blocks of {1} bytes/each. (for a total of {2:F3} TiB)</value>
<comment>TiB = tebibyte</comment>
</data>
<data name="Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB" xml:space="preserve">
<value>Media has {0} blocks of {1} bytes/each. (for a total of {2:F3} GiB)</value>
<comment>GiB = gibibyte</comment>
</data>
<data name="Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB" xml:space="preserve">
<value>Media has {0} blocks of {1} bytes/each. (for a total of {2:F3} MiB)</value>
<comment>MiB = mebibyte</comment>
</data>
<data name="Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB" xml:space="preserve">
<value>Media has {0} blocks of {1} bytes/each. (for a total of {2:F3} KiB)</value>
<comment>KiB = kibibyte</comment>
</data>
<data name="Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes" xml:space="preserve">
<value>Media has {0} blocks of {1} bytes/each. (for a total of {2} bytes)</value>
<data name="Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2" xml:space="preserve">
<value>Media has {0} blocks of {1} bytes/each. (for a total of {2})</value>
</data>
<data name="Xbox_DMI" xml:space="preserve">
<value>Xbox DMI</value>

View File

@@ -94,6 +94,7 @@
<Content Include="..\.github\PULL_REQUEST_TEMPLATE.md" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0-rc.1.23419.6" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
<PackageReference Include="Spectre.Console.Analyzer" Version="0.47.0">

View File

@@ -59,6 +59,7 @@ using DDS = Aaru.Decoders.DVD.DDS;
using DMI = Aaru.Decoders.Xbox.DMI;
using Session = Aaru.Decoders.CD.Session;
using Spare = Aaru.Decoders.DVD.Spare;
using Humanizer.Bytes;
namespace Aaru.Commands.Media;
@@ -229,43 +230,9 @@ sealed class MediaInfoCommand : Command
if(scsiInfo.Blocks != 0 &&
scsiInfo.BlockSize != 0)
{
ulong totalSize = scsiInfo.Blocks * scsiInfo.BlockSize;
switch(totalSize)
{
case > 1099511627776:
AaruConsole.
WriteLine(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_TiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1099511627776d);
break;
case > 1073741824:
AaruConsole.
WriteLine(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_GiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1073741824d);
break;
case > 1048576:
AaruConsole.
WriteLine(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_MiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1048576d);
break;
case > 1024:
AaruConsole.
WriteLine(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_KiB,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize / 1024d);
break;
default:
AaruConsole.
WriteLine(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2_bytes,
scsiInfo.Blocks, scsiInfo.BlockSize, totalSize);
break;
}
}
AaruConsole.WriteLine(Localization.Core.Media_has_0_blocks_of_1_bytes_each_for_a_total_of_2,
scsiInfo.Blocks, scsiInfo.BlockSize,
ByteSize.FromBytes(scsiInfo.Blocks * scsiInfo.BlockSize).ToString("0.000"));
break;
case PeripheralDeviceTypes.SequentialAccess: