Skip to content

Commit

Permalink
Fix some minor problems detected by the analyzers.
Browse files Browse the repository at this point in the history
  • Loading branch information
claunia committed May 6, 2024
1 parent 7db553a commit debb7b9
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 86 deletions.
2 changes: 2 additions & 0 deletions Aaru.Decoders/DVD/PFI.cs
Expand Up @@ -986,11 +986,13 @@ public static string Prettify(PhysicalFormatInformation? pfi)

public static string Prettify(byte[] response, MediaType mediaType) => Prettify(Decode(response, mediaType));

#pragma warning disable PH2077 // Waiting to get more information on the actual values
public static string ManufacturerFromDVDRAM(string manufacturerId) => manufacturerId switch
{
_ =>
ManufacturerFromDVDPlusID(manufacturerId)
};
#pragma warning restore PH2077

[SuppressMessage("ReSharper", "StringLiteralTypo")]
public static string ManufacturerFromDVDPlusID(string manufacturerId)
Expand Down
2 changes: 2 additions & 0 deletions Aaru.Devices/Device/MmcCommands/MMC.cs
Expand Up @@ -39,7 +39,9 @@ namespace Aaru.Devices;

public partial class Device
{
#pragma warning disable PH2070 // Risks are known. TODO: Maybe protected property?
protected static bool _readMultipleBlockCannotSetBlockCount;
#pragma warning restore PH2070

/// <summary>Reads the CSD register from a SecureDigital or MultiMediaCard device</summary>
/// <param name="buffer">Data buffer</param>
Expand Down
30 changes: 16 additions & 14 deletions Aaru.Devices/Device/Variables.cs
Expand Up @@ -43,20 +43,6 @@ public partial class Device
const string SD_MODULE_NAME = "SecureDigital Device";
const string MMC_MODULE_NAME = "MultiMediaCard Device";

// MMC and SecureDigital, values that need to be get with card idle, something that may
// not be possible to do but usually is already done by the SDHCI driver.
private protected byte[] CachedCid;
private protected byte[] CachedCsd;
private protected byte[] CachedOcr;
private protected byte[] CachedScr;

private protected string DevicePath;
private protected ulong FirewireGuid;
private protected uint FirewireModel;
private protected uint FirewireVendor;
private protected ushort UsbProduct;
private protected ushort UsbVendor;

/// <summary>Gets the Platform ID for this device</summary>
/// <value>The Platform ID</value>
public PlatformID PlatformId { get; private protected set; }
Expand Down Expand Up @@ -163,4 +149,20 @@ public partial class Device

/// <summary>Contains the PCMCIA CIS if applicable</summary>
public byte[] Cis { get; private protected set; }

// MMC and SecureDigital, values that need to be get with card idle, something that may
// not be possible to do but usually is already done by the SDHCI driver.
#pragma warning disable PH2070 // Risks are known. TODO: Maybe protected property?
private protected byte[] CachedCid;
private protected byte[] CachedCsd;
private protected byte[] CachedOcr;
private protected byte[] CachedScr;

private protected string DevicePath;
private protected ulong FirewireGuid;
private protected uint FirewireModel;
private protected uint FirewireVendor;
private protected ushort UsbProduct;
private protected ushort UsbVendor;
#pragma warning restore PH2070
}
18 changes: 8 additions & 10 deletions Aaru.Filesystems/CPM/Super.cs
Expand Up @@ -167,8 +167,9 @@ public sealed partial class CPM
if(errno != ErrorNumber.NoError) return errno;

if(_workingDefinition.complement)
for(var b = 0; b < readSector.Length; b++)
readSector[b] = (byte)(~readSector[b] & 0xFF);
{
for(var b = 0; b < readSector.Length; b++) readSector[b] = (byte)(~readSector[b] & 0xFF);
}

deinterleavedSectors.Add((ulong)p, readSector);
}
Expand Down Expand Up @@ -757,17 +758,14 @@ public sealed partial class CPM
_decodedPasswordCache = new Dictionary<string, byte[]>();

// For each stored password, store a decoded version of it
if(_passwordCache.Count > 0)
foreach(KeyValuePair<string, byte[]> kvp in _passwordCache)
{
foreach(KeyValuePair<string, byte[]> kvp in _passwordCache)
{
var tmp = new byte[8];
Array.Copy(kvp.Value, 16, tmp, 0, 8);
var tmp = new byte[8];
Array.Copy(kvp.Value, 16, tmp, 0, 8);

for(var t = 0; t < 8; t++) tmp[t] ^= kvp.Value[13];
for(var t = 0; t < 8; t++) tmp[t] ^= kvp.Value[13];

_decodedPasswordCache.Add(kvp.Key, tmp);
}
_decodedPasswordCache.Add(kvp.Key, tmp);
}

// Generate statfs.
Expand Down
16 changes: 6 additions & 10 deletions Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs
Expand Up @@ -1423,19 +1423,15 @@ await MessageBoxManager
Progress2Value = Progress2MaxValue;
});

if(isrcs.Count > 0)
foreach(KeyValuePair<byte, string> isrc in isrcs)
{
foreach(KeyValuePair<byte, string> isrc in isrcs)
{
outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value),
isrc.Key,
SectorTagType.CdTrackIsrc);
}
outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value),
isrc.Key,
SectorTagType.CdTrackIsrc);
}

if(trackFlags.Count > 0)
foreach(KeyValuePair<byte, byte> flags in trackFlags)
outputOptical.WriteSectorTag([flags.Value], flags.Key, SectorTagType.CdTrackFlags);
foreach(KeyValuePair<byte, byte> flags in trackFlags)
outputOptical.WriteSectorTag([flags.Value], flags.Key, SectorTagType.CdTrackFlags);

if(mcn != null) outputOptical.WriteMediaTag(Encoding.UTF8.GetBytes(mcn), MediaTagType.CD_MCN);
}
Expand Down
21 changes: 3 additions & 18 deletions Aaru.Partitions/SGI.cs
Expand Up @@ -229,26 +229,17 @@ struct DeviceParameters
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct Label
{
/// <summary></summary>
public readonly uint magic;
/// <summary></summary>
public readonly uint magic;
public readonly short root_part_num;
/// <summary></summary>
public readonly short swap_part_num;
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] boot_file;
/// <summary></summary>
public readonly DeviceParameters device_params;
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
public readonly Volume[] volume;
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly Partition[] partitions;
/// <summary></summary>
public readonly uint csum;
/// <summary></summary>
public readonly uint padding;
}

Expand All @@ -259,11 +250,8 @@ struct DeviceParameters
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Partition
{
/// <summary></summary>
public readonly uint num_blocks;
/// <summary></summary>
public readonly uint first_block;
/// <summary></summary>
public readonly uint num_blocks;
public readonly uint first_block;
public readonly SGIType type;
}

Expand Down Expand Up @@ -299,12 +287,9 @@ enum SGIType : uint
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct Volume
{
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public readonly byte[] name;
/// <summary></summary>
public readonly uint block_num;
/// <summary></summary>
public readonly uint num_bytes;
}

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 2 additions & 5 deletions Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs
Expand Up @@ -404,11 +404,8 @@ public void Convert()
}
}

if(isrcs.Count > 0)
{
foreach(KeyValuePair<byte, string> isrc in isrcs)
outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value), isrc.Key, SectorTagType.CdTrackIsrc);
}
foreach(KeyValuePair<byte, string> isrc in isrcs)
outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value), isrc.Key, SectorTagType.CdTrackIsrc);

if(trackFlags.Count > 0)
{
Expand Down
11 changes: 4 additions & 7 deletions Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs
Expand Up @@ -502,14 +502,11 @@ public void Convert()
}
}
if(isrcs.Count > 0)
foreach(KeyValuePair<byte, string> isrc in isrcs)
{
foreach(KeyValuePair<byte, string> isrc in isrcs)
{
outputFormat.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value),
isrc.Key,
SectorTagType.CdTrackIsrc);
}
outputFormat.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value),
isrc.Key,
SectorTagType.CdTrackIsrc);
}
if(trackFlags.Count > 0)
Expand Down
11 changes: 4 additions & 7 deletions Aaru/Commands/Image/Convert.cs
Expand Up @@ -1412,19 +1412,16 @@ or MediaType.DVDPR
if(errno != ErrorNumber.NoError && !force) return (int)errno;
}

if(isrcs.Count > 0)
foreach(KeyValuePair<byte, string> isrc in isrcs)
{
foreach(KeyValuePair<byte, string> isrc in isrcs)
{
outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value),
isrc.Key,
SectorTagType.CdTrackIsrc);
}
outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value), isrc.Key, SectorTagType.CdTrackIsrc);
}

if(trackFlags.Count > 0)
{
foreach((byte track, byte flags) in trackFlags)
outputOptical.WriteSectorTag([flags], track, SectorTagType.CdTrackFlags);
}

if(mcn != null) outputOptical.WriteMediaTag(Encoding.UTF8.GetBytes(mcn), MediaTagType.CD_MCN);

Expand Down
2 changes: 2 additions & 0 deletions Aaru/Commands/Image/Decode.cs
Expand Up @@ -415,10 +415,12 @@ public DecodeCommand() : base("decode", UI.Image_Decode_Command_Description)
{
switch(tag)
{
#pragma warning disable PH2077 // TODO: Implement some!
default:
AaruConsole.WriteLine(UI.Decoder_for_sector_tag_type_0_not_yet_implemented_sorry, tag);

break;
#pragma warning restore PH2077
}
}
}
Expand Down
22 changes: 7 additions & 15 deletions Aaru/Commands/Media/Scan.cs
Expand Up @@ -221,29 +221,21 @@ public MediaScanCommand() : base("scan", UI.Media_Scan_Command_Description)
AaruConsole.WriteLine($"[bold]{Localization.Core.Summary}:[/]");
AaruConsole.WriteLine($"[lime]{string.Format(Localization.Core._0_sectors_took_less_than_3_ms, results.A)}[/]");

AaruConsole.WriteLine($"[green]{
string.Format(Localization.Core._0_sectors_took_less_than_10_ms_but_more_than_3_ms, results.B)}[/]");
AaruConsole.WriteLine($"[green]{string.Format(Localization.Core._0_sectors_took_less_than_10_ms_but_more_than_3_ms, results.B)}[/]");

AaruConsole.WriteLine($"[darkorange]{
string.Format(Localization.Core._0_sectors_took_less_than_50_ms_but_more_than_10_ms, results.C)}[/]");
AaruConsole.WriteLine($"[darkorange]{string.Format(Localization.Core._0_sectors_took_less_than_50_ms_but_more_than_10_ms, results.C)}[/]");

AaruConsole.WriteLine($"[olive]{
string.Format(Localization.Core._0_sectors_took_less_than_150_ms_but_more_than_50_ms, results.D)}[/]");
AaruConsole.WriteLine($"[olive]{string.Format(Localization.Core._0_sectors_took_less_than_150_ms_but_more_than_50_ms, results.D)}[/]");

AaruConsole.WriteLine($"[orange3]{
string.Format(Localization.Core._0_sectors_took_less_than_500_ms_but_more_than_150_ms, results.E)}[/]");
AaruConsole.WriteLine($"[orange3]{string.Format(Localization.Core._0_sectors_took_less_than_500_ms_but_more_than_150_ms, results.E)}[/]");

AaruConsole.WriteLine($"[red]{string.Format(Localization.Core._0_sectors_took_more_than_500_ms, results.F)
}[/]");
AaruConsole.WriteLine($"[red]{string.Format(Localization.Core._0_sectors_took_more_than_500_ms, results.F)}[/]");

AaruConsole.WriteLine($"[maroon]{string.Format(Localization.Core._0_sectors_could_not_be_read,
results.UnreadableSectors.Count)}[/]");

if(results.UnreadableSectors.Count > 0)
{
foreach(ulong bad in results.UnreadableSectors)
AaruConsole.WriteLine(Localization.Core.Sector_0_could_not_be_read, bad);
}
foreach(ulong bad in results.UnreadableSectors)
AaruConsole.WriteLine(Localization.Core.Sector_0_could_not_be_read, bad);

AaruConsole.WriteLine();

Expand Down

0 comments on commit debb7b9

Please sign in to comment.