From debb7b9f0e3f1efada5dfe4f9c3e16b803083dbd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 6 May 2024 04:34:43 +0100 Subject: [PATCH] Fix some minor problems detected by the analyzers. --- Aaru.Decoders/DVD/PFI.cs | 2 ++ Aaru.Devices/Device/MmcCommands/MMC.cs | 2 ++ Aaru.Devices/Device/Variables.cs | 30 ++++++++++--------- Aaru.Filesystems/CPM/Super.cs | 18 +++++------ .../Windows/ImageConvertViewModel.cs | 16 ++++------ Aaru.Partitions/SGI.cs | 21 ++----------- .../UFS/{NeXT Floppy.cs => NeXT_Floppy.cs} | 0 .../UFS/{Sun i86.cs => Sun_i86.cs} | 0 .../Issues/OpticalImageConvertIssueTest.cs | 7 ++--- .../WritableOpticalMediaImageTest.cs | 11 +++---- Aaru/Commands/Image/Convert.cs | 11 +++---- Aaru/Commands/Image/Decode.cs | 2 ++ Aaru/Commands/Media/Scan.cs | 22 +++++--------- 13 files changed, 56 insertions(+), 86 deletions(-) rename Aaru.Tests/Filesystems/UFS/{NeXT Floppy.cs => NeXT_Floppy.cs} (100%) rename Aaru.Tests/Filesystems/UFS/{Sun i86.cs => Sun_i86.cs} (100%) diff --git a/Aaru.Decoders/DVD/PFI.cs b/Aaru.Decoders/DVD/PFI.cs index 4038c0943..7a589a6d9 100644 --- a/Aaru.Decoders/DVD/PFI.cs +++ b/Aaru.Decoders/DVD/PFI.cs @@ -986,11 +986,13 @@ public static class 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) diff --git a/Aaru.Devices/Device/MmcCommands/MMC.cs b/Aaru.Devices/Device/MmcCommands/MMC.cs index 079e952ee..d7541182a 100644 --- a/Aaru.Devices/Device/MmcCommands/MMC.cs +++ b/Aaru.Devices/Device/MmcCommands/MMC.cs @@ -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 /// Reads the CSD register from a SecureDigital or MultiMediaCard device /// Data buffer diff --git a/Aaru.Devices/Device/Variables.cs b/Aaru.Devices/Device/Variables.cs index db5c4fd8d..41e8800b6 100644 --- a/Aaru.Devices/Device/Variables.cs +++ b/Aaru.Devices/Device/Variables.cs @@ -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; - /// Gets the Platform ID for this device /// The Platform ID public PlatformID PlatformId { get; private protected set; } @@ -163,4 +149,20 @@ public partial class Device /// Contains the PCMCIA CIS if applicable 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 } \ No newline at end of file diff --git a/Aaru.Filesystems/CPM/Super.cs b/Aaru.Filesystems/CPM/Super.cs index b257f4c7c..38129c1cb 100644 --- a/Aaru.Filesystems/CPM/Super.cs +++ b/Aaru.Filesystems/CPM/Super.cs @@ -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); } @@ -757,17 +758,14 @@ public sealed partial class CPM _decodedPasswordCache = new Dictionary(); // For each stored password, store a decoded version of it - if(_passwordCache.Count > 0) + foreach(KeyValuePair kvp in _passwordCache) { - foreach(KeyValuePair 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. diff --git a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs index 23a5a7694..70e73efed 100644 --- a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs @@ -1423,19 +1423,15 @@ public sealed class ImageConvertViewModel : ViewModelBase Progress2Value = Progress2MaxValue; }); - if(isrcs.Count > 0) + foreach(KeyValuePair isrc in isrcs) { - foreach(KeyValuePair 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 flags in trackFlags) - outputOptical.WriteSectorTag([flags.Value], flags.Key, SectorTagType.CdTrackFlags); + foreach(KeyValuePair flags in trackFlags) + outputOptical.WriteSectorTag([flags.Value], flags.Key, SectorTagType.CdTrackFlags); if(mcn != null) outputOptical.WriteMediaTag(Encoding.UTF8.GetBytes(mcn), MediaTagType.CD_MCN); } diff --git a/Aaru.Partitions/SGI.cs b/Aaru.Partitions/SGI.cs index 2d5772b9a..67dd78ef1 100644 --- a/Aaru.Partitions/SGI.cs +++ b/Aaru.Partitions/SGI.cs @@ -229,26 +229,17 @@ public sealed class SGI : IPartition [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct Label { - /// - public readonly uint magic; - /// + public readonly uint magic; public readonly short root_part_num; - /// public readonly short swap_part_num; - /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly byte[] boot_file; - /// public readonly DeviceParameters device_params; - /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 15)] public readonly Volume[] volume; - /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public readonly Partition[] partitions; - /// public readonly uint csum; - /// public readonly uint padding; } @@ -259,11 +250,8 @@ public sealed class SGI : IPartition [StructLayout(LayoutKind.Sequential, Pack = 1)] struct Partition { - /// - public readonly uint num_blocks; - /// - public readonly uint first_block; - /// + public readonly uint num_blocks; + public readonly uint first_block; public readonly SGIType type; } @@ -299,12 +287,9 @@ public sealed class SGI : IPartition [StructLayout(LayoutKind.Sequential, Pack = 1)] readonly struct Volume { - /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public readonly byte[] name; - /// public readonly uint block_num; - /// public readonly uint num_bytes; } diff --git a/Aaru.Tests/Filesystems/UFS/NeXT Floppy.cs b/Aaru.Tests/Filesystems/UFS/NeXT_Floppy.cs similarity index 100% rename from Aaru.Tests/Filesystems/UFS/NeXT Floppy.cs rename to Aaru.Tests/Filesystems/UFS/NeXT_Floppy.cs diff --git a/Aaru.Tests/Filesystems/UFS/Sun i86.cs b/Aaru.Tests/Filesystems/UFS/Sun_i86.cs similarity index 100% rename from Aaru.Tests/Filesystems/UFS/Sun i86.cs rename to Aaru.Tests/Filesystems/UFS/Sun_i86.cs diff --git a/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs b/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs index 36c9122f6..e287ef292 100644 --- a/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs +++ b/Aaru.Tests/Issues/OpticalImageConvertIssueTest.cs @@ -404,11 +404,8 @@ public abstract class OpticalImageConvertIssueTest } } - if(isrcs.Count > 0) - { - foreach(KeyValuePair isrc in isrcs) - outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value), isrc.Key, SectorTagType.CdTrackIsrc); - } + foreach(KeyValuePair isrc in isrcs) + outputOptical.WriteSectorTag(Encoding.UTF8.GetBytes(isrc.Value), isrc.Key, SectorTagType.CdTrackIsrc); if(trackFlags.Count > 0) { diff --git a/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs b/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs index 640ae1985..1c416e716 100644 --- a/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs +++ b/Aaru.Tests/WritableImages/WritableOpticalMediaImageTest.cs @@ -502,14 +502,11 @@ public abstract class WritableOpticalMediaImageTest : BaseWritableMediaImageTest } } - if(isrcs.Count > 0) + foreach(KeyValuePair isrc in isrcs) { - foreach(KeyValuePair 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) diff --git a/Aaru/Commands/Image/Convert.cs b/Aaru/Commands/Image/Convert.cs index 1b299c7b2..afbe09b7f 100644 --- a/Aaru/Commands/Image/Convert.cs +++ b/Aaru/Commands/Image/Convert.cs @@ -1412,19 +1412,16 @@ sealed class ConvertImageCommand : Command if(errno != ErrorNumber.NoError && !force) return (int)errno; } - if(isrcs.Count > 0) + foreach(KeyValuePair isrc in isrcs) { - foreach(KeyValuePair 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); diff --git a/Aaru/Commands/Image/Decode.cs b/Aaru/Commands/Image/Decode.cs index c7215ceb3..995993c78 100644 --- a/Aaru/Commands/Image/Decode.cs +++ b/Aaru/Commands/Image/Decode.cs @@ -415,10 +415,12 @@ sealed class DecodeCommand : Command { 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 } } } diff --git a/Aaru/Commands/Media/Scan.cs b/Aaru/Commands/Media/Scan.cs index 9d55156b2..9555bd848 100644 --- a/Aaru/Commands/Media/Scan.cs +++ b/Aaru/Commands/Media/Scan.cs @@ -221,29 +221,21 @@ sealed class MediaScanCommand : Command 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();