Fix some minor problems detected by the analyzers.

This commit is contained in:
2024-05-06 04:34:43 +01:00
parent 7db553a21c
commit debb7b9f0e
13 changed files with 56 additions and 86 deletions

View File

@@ -986,11 +986,13 @@ public static class PFI
public static string Prettify(byte[] response, MediaType mediaType) => Prettify(Decode(response, mediaType)); 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 public static string ManufacturerFromDVDRAM(string manufacturerId) => manufacturerId switch
{ {
_ => _ =>
ManufacturerFromDVDPlusID(manufacturerId) ManufacturerFromDVDPlusID(manufacturerId)
}; };
#pragma warning restore PH2077
[SuppressMessage("ReSharper", "StringLiteralTypo")] [SuppressMessage("ReSharper", "StringLiteralTypo")]
public static string ManufacturerFromDVDPlusID(string manufacturerId) public static string ManufacturerFromDVDPlusID(string manufacturerId)

View File

@@ -39,7 +39,9 @@ namespace Aaru.Devices;
public partial class Device public partial class Device
{ {
#pragma warning disable PH2070 // Risks are known. TODO: Maybe protected property?
protected static bool _readMultipleBlockCannotSetBlockCount; protected static bool _readMultipleBlockCannotSetBlockCount;
#pragma warning restore PH2070
/// <summary>Reads the CSD register from a SecureDigital or MultiMediaCard device</summary> /// <summary>Reads the CSD register from a SecureDigital or MultiMediaCard device</summary>
/// <param name="buffer">Data buffer</param> /// <param name="buffer">Data buffer</param>

View File

@@ -43,20 +43,6 @@ public partial class Device
const string SD_MODULE_NAME = "SecureDigital Device"; const string SD_MODULE_NAME = "SecureDigital Device";
const string MMC_MODULE_NAME = "MultiMediaCard 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> /// <summary>Gets the Platform ID for this device</summary>
/// <value>The Platform ID</value> /// <value>The Platform ID</value>
public PlatformID PlatformId { get; private protected set; } public PlatformID PlatformId { get; private protected set; }
@@ -163,4 +149,20 @@ public partial class Device
/// <summary>Contains the PCMCIA CIS if applicable</summary> /// <summary>Contains the PCMCIA CIS if applicable</summary>
public byte[] Cis { get; private protected set; } 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
} }

View File

@@ -167,8 +167,9 @@ public sealed partial class CPM
if(errno != ErrorNumber.NoError) return errno; if(errno != ErrorNumber.NoError) return errno;
if(_workingDefinition.complement) 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); deinterleavedSectors.Add((ulong)p, readSector);
} }
@@ -757,17 +758,14 @@ public sealed partial class CPM
_decodedPasswordCache = new Dictionary<string, byte[]>(); _decodedPasswordCache = new Dictionary<string, byte[]>();
// For each stored password, store a decoded version of it // 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. // Generate statfs.

View File

@@ -1423,19 +1423,15 @@ public sealed class ImageConvertViewModel : ViewModelBase
Progress2Value = Progress2MaxValue; 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,
outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value), SectorTagType.CdTrackIsrc);
isrc.Key,
SectorTagType.CdTrackIsrc);
}
} }
if(trackFlags.Count > 0) foreach(KeyValuePair<byte, byte> flags in trackFlags)
foreach(KeyValuePair<byte, byte> flags in trackFlags) outputOptical.WriteSectorTag([flags.Value], flags.Key, SectorTagType.CdTrackFlags);
outputOptical.WriteSectorTag([flags.Value], flags.Key, SectorTagType.CdTrackFlags);
if(mcn != null) outputOptical.WriteMediaTag(Encoding.UTF8.GetBytes(mcn), MediaTagType.CD_MCN); if(mcn != null) outputOptical.WriteMediaTag(Encoding.UTF8.GetBytes(mcn), MediaTagType.CD_MCN);
} }

View File

@@ -229,26 +229,17 @@ public sealed class SGI : IPartition
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct Label readonly struct Label
{ {
/// <summary></summary> public readonly uint magic;
public readonly uint magic;
/// <summary></summary>
public readonly short root_part_num; public readonly short root_part_num;
/// <summary></summary>
public readonly short swap_part_num; public readonly short swap_part_num;
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] boot_file; public readonly byte[] boot_file;
/// <summary></summary>
public readonly DeviceParameters device_params; public readonly DeviceParameters device_params;
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)]
public readonly Volume[] volume; public readonly Volume[] volume;
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly Partition[] partitions; public readonly Partition[] partitions;
/// <summary></summary>
public readonly uint csum; public readonly uint csum;
/// <summary></summary>
public readonly uint padding; public readonly uint padding;
} }
@@ -259,11 +250,8 @@ public sealed class SGI : IPartition
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Partition struct Partition
{ {
/// <summary></summary> public readonly uint num_blocks;
public readonly uint num_blocks; public readonly uint first_block;
/// <summary></summary>
public readonly uint first_block;
/// <summary></summary>
public readonly SGIType type; public readonly SGIType type;
} }
@@ -299,12 +287,9 @@ public sealed class SGI : IPartition
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct Volume readonly struct Volume
{ {
/// <summary></summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public readonly byte[] name; public readonly byte[] name;
/// <summary></summary>
public readonly uint block_num; public readonly uint block_num;
/// <summary></summary>
public readonly uint num_bytes; public readonly uint num_bytes;
} }

View File

@@ -404,11 +404,8 @@ public abstract class OpticalImageConvertIssueTest
} }
} }
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) if(trackFlags.Count > 0)
{ {

View File

@@ -502,14 +502,11 @@ public abstract class WritableOpticalMediaImageTest : BaseWritableMediaImageTest
} }
} }
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,
outputFormat.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value), SectorTagType.CdTrackIsrc);
isrc.Key,
SectorTagType.CdTrackIsrc);
}
} }
if(trackFlags.Count > 0) if(trackFlags.Count > 0)

View File

@@ -1412,19 +1412,16 @@ sealed class ConvertImageCommand : Command
if(errno != ErrorNumber.NoError && !force) return (int)errno; 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) if(trackFlags.Count > 0)
{
foreach((byte track, byte flags) in trackFlags) foreach((byte track, byte flags) in trackFlags)
outputOptical.WriteSectorTag([flags], track, SectorTagType.CdTrackFlags); outputOptical.WriteSectorTag([flags], track, SectorTagType.CdTrackFlags);
}
if(mcn != null) outputOptical.WriteMediaTag(Encoding.UTF8.GetBytes(mcn), MediaTagType.CD_MCN); if(mcn != null) outputOptical.WriteMediaTag(Encoding.UTF8.GetBytes(mcn), MediaTagType.CD_MCN);

View File

@@ -415,10 +415,12 @@ sealed class DecodeCommand : Command
{ {
switch(tag) switch(tag)
{ {
#pragma warning disable PH2077 // TODO: Implement some!
default: default:
AaruConsole.WriteLine(UI.Decoder_for_sector_tag_type_0_not_yet_implemented_sorry, tag); AaruConsole.WriteLine(UI.Decoder_for_sector_tag_type_0_not_yet_implemented_sorry, tag);
break; break;
#pragma warning restore PH2077
} }
} }
} }

View File

@@ -221,29 +221,21 @@ sealed class MediaScanCommand : Command
AaruConsole.WriteLine($"[bold]{Localization.Core.Summary}:[/]"); AaruConsole.WriteLine($"[bold]{Localization.Core.Summary}:[/]");
AaruConsole.WriteLine($"[lime]{string.Format(Localization.Core._0_sectors_took_less_than_3_ms, results.A)}[/]"); AaruConsole.WriteLine($"[lime]{string.Format(Localization.Core._0_sectors_took_less_than_3_ms, results.A)}[/]");
AaruConsole.WriteLine($"[green]{ AaruConsole.WriteLine($"[green]{string.Format(Localization.Core._0_sectors_took_less_than_10_ms_but_more_than_3_ms, results.B)}[/]");
string.Format(Localization.Core._0_sectors_took_less_than_10_ms_but_more_than_3_ms, results.B)}[/]");
AaruConsole.WriteLine($"[darkorange]{ AaruConsole.WriteLine($"[darkorange]{string.Format(Localization.Core._0_sectors_took_less_than_50_ms_but_more_than_10_ms, results.C)}[/]");
string.Format(Localization.Core._0_sectors_took_less_than_50_ms_but_more_than_10_ms, results.C)}[/]");
AaruConsole.WriteLine($"[olive]{ AaruConsole.WriteLine($"[olive]{string.Format(Localization.Core._0_sectors_took_less_than_150_ms_but_more_than_50_ms, results.D)}[/]");
string.Format(Localization.Core._0_sectors_took_less_than_150_ms_but_more_than_50_ms, results.D)}[/]");
AaruConsole.WriteLine($"[orange3]{ AaruConsole.WriteLine($"[orange3]{string.Format(Localization.Core._0_sectors_took_less_than_500_ms_but_more_than_150_ms, results.E)}[/]");
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, AaruConsole.WriteLine($"[maroon]{string.Format(Localization.Core._0_sectors_could_not_be_read,
results.UnreadableSectors.Count)}[/]"); 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(); AaruConsole.WriteLine();