diff --git a/CHANGELIST.md b/CHANGELIST.md index dab96a3c..9768d4c4 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -21,6 +21,7 @@ - Add sanity check output file tests - Add tests around DIC helpers - Add safety around sidecar generation +- Use recommended Min/Max/TryParse ### 3.2.4 (2024-11-24) diff --git a/MPF.ExecutionContexts/Aaru/ExecutionContext.cs b/MPF.ExecutionContexts/Aaru/ExecutionContext.cs index 5d5b33ce..ff370c1e 100644 --- a/MPF.ExecutionContexts/Aaru/ExecutionContext.cs +++ b/MPF.ExecutionContexts/Aaru/ExecutionContext.cs @@ -1548,7 +1548,7 @@ namespace MPF.ExecutionContexts.Aaru // Length longValue = ProcessInt64Parameter(parts, FlagStrings.LengthShort, FlagStrings.LengthLong, ref i); - if (longValue != null && longValue != Int64.MinValue) + if (longValue != null && longValue != long.MinValue) { LengthValue = longValue; } @@ -1563,7 +1563,7 @@ namespace MPF.ExecutionContexts.Aaru longValue = ProcessInt64Parameter(parts, FlagStrings.StartShort, FlagStrings.StartLong, ref i); if (longValue == null) return false; - else if (longValue != Int64.MinValue) + else if (longValue != long.MinValue) StartValue = longValue; #endregion diff --git a/MPF.ExecutionContexts/BaseExecutionContext.cs b/MPF.ExecutionContexts/BaseExecutionContext.cs index 86d2e0f4..eedca021 100644 --- a/MPF.ExecutionContexts/BaseExecutionContext.cs +++ b/MPF.ExecutionContexts/BaseExecutionContext.cs @@ -797,7 +797,7 @@ namespace MPF.ExecutionContexts return null; } - return Int32.MinValue; + return int.MinValue; } /// @@ -884,7 +884,7 @@ namespace MPF.ExecutionContexts return null; } - return Int64.MinValue; + return long.MinValue; } /// diff --git a/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs b/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs index b952eb0c..36f78126 100644 --- a/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs +++ b/MPF.ExecutionContexts/DiscImageCreator/ExecutionContext.cs @@ -1103,17 +1103,17 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); if (!IsValidInt32(parts[4])) return false; else - StartLBAValue = Int32.Parse(parts[4]); + StartLBAValue = int.Parse(parts[4]); if (!IsValidInt32(parts[5])) return false; else - EndLBAValue = Int32.Parse(parts[5]); + EndLBAValue = int.Parse(parts[5]); index = 6; break; @@ -1133,7 +1133,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); index = 4; break; @@ -1162,7 +1162,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); index = 4; break; @@ -1182,17 +1182,17 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); if (!IsValidInt32(parts[4])) return false; else - StartLBAValue = Int32.Parse(parts[4]); + StartLBAValue = int.Parse(parts[4]); if (!IsValidInt32(parts[5])) return false; else - EndLBAValue = Int32.Parse(parts[5]); + EndLBAValue = int.Parse(parts[5]); index = 6; break; @@ -1212,7 +1212,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 24)) // Officially 0-16 return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); index = 4; break; @@ -1277,7 +1277,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); index = 4; break; @@ -1333,7 +1333,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 16)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); index = 4; break; @@ -1382,7 +1382,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); index = 4; break; @@ -1419,7 +1419,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); index = 4; break; @@ -1441,11 +1441,11 @@ namespace MPF.ExecutionContexts.DiscImageCreator if (!IsValidInt32(parts[3], lowerBound: 0, upperBound: 72)) return false; else - DriveSpeed = Int32.Parse(parts[3]); + DriveSpeed = int.Parse(parts[3]); for (int i = 4; i < parts.Count; i++) { - if (!Int64.TryParse(parts[i], out long temp)) + if (!long.TryParse(parts[i], out long temp)) return false; } @@ -1466,7 +1466,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator // Add Offset intValue = ProcessInt32Parameter(parts, FlagStrings.AddOffset, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) AddOffsetValue = intValue; // AMSF @@ -1505,7 +1505,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator } else { - C2OpcodeValue[j] = Int32.Parse(parts[i + 1]); + C2OpcodeValue[j] = int.Parse(parts[i + 1]); i++; } } @@ -1525,7 +1525,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator // DVD/HD-DVD/BD Reread intValue = ProcessInt32Parameter(parts, FlagStrings.DVDReread, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) DVDRereadValue = intValue; // Extract MS-CAB @@ -1533,17 +1533,17 @@ namespace MPF.ExecutionContexts.DiscImageCreator // Fix intValue = ProcessInt32Parameter(parts, FlagStrings.Fix, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) FixValue = intValue; // Force Unit Access intValue = ProcessInt32Parameter(parts, FlagStrings.ForceUnitAccess, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue && intValue >= 0) + if (intValue != null && intValue != int.MinValue && intValue >= 0) ForceUnitAccessValue = intValue; // Multi-Sector Read intValue = ProcessInt32Parameter(parts, FlagStrings.MultiSectorRead, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue && intValue >= 0) + if (intValue != null && intValue != int.MinValue && intValue >= 0) MultiSectorReadValue = intValue; // NoFixSubP @@ -1563,7 +1563,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator // NoSkipSS intValue = ProcessInt32Parameter(parts, FlagStrings.NoSkipSS, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue && intValue >= 0) + if (intValue != null && intValue != int.MinValue && intValue >= 0) NoSkipSecuritySectorValue = intValue; // PadSector @@ -1582,8 +1582,8 @@ namespace MPF.ExecutionContexts.DiscImageCreator else if (!IsValidInt32(parts[i + 1], lowerBound: 0) || !IsValidInt32(parts[i + 2], lowerBound: 0)) return false; - RangeStartLBAValue = Int32.Parse(parts[i + 1]); - RangeEndLBAValue = Int32.Parse(parts[i + 2]); + RangeStartLBAValue = int.Parse(parts[i + 1]); + RangeEndLBAValue = int.Parse(parts[i + 2]); i += 2; } @@ -1607,8 +1607,8 @@ namespace MPF.ExecutionContexts.DiscImageCreator else if (!IsValidInt32(parts[i + 1], lowerBound: 0) || !IsValidInt32(parts[i + 2], lowerBound: 0)) return false; - ReverseStartLBAValue = Int32.Parse(parts[i + 1]); - ReverseEndLBAValue = Int32.Parse(parts[i + 2]); + ReverseStartLBAValue = int.Parse(parts[i + 1]); + ReverseEndLBAValue = int.Parse(parts[i + 2]); i += 2; } @@ -1620,7 +1620,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator // ScanFileProtect intValue = ProcessInt32Parameter(parts, FlagStrings.ScanFileProtect, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue && intValue >= 0) + if (intValue != null && intValue != int.MinValue && intValue >= 0) ScanFileProtectValue = intValue; // ScanSectorProtect @@ -1650,7 +1650,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator } else { - SkipSectorValue[j] = Int32.Parse(parts[i + 1]); + SkipSectorValue[j] = int.Parse(parts[i + 1]); i++; } } @@ -1661,7 +1661,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator // SubchannelReadLevel intValue = ProcessInt32Parameter(parts, FlagStrings.SubchannelReadLevel, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue && intValue >= 0 && intValue <= 2) + if (intValue != null && intValue != int.MinValue && intValue >= 0 && intValue <= 2) SubchannelReadLevelValue = intValue; // SeventyFour @@ -1669,7 +1669,7 @@ namespace MPF.ExecutionContexts.DiscImageCreator // VideoNow intValue = ProcessInt32Parameter(parts, FlagStrings.VideoNow, ref i, missingAllowed: true); - if (intValue != null && intValue != Int32.MinValue && intValue >= 0) + if (intValue != null && intValue != int.MinValue && intValue >= 0) VideoNowValue = intValue; // VideoNowColor diff --git a/MPF.ExecutionContexts/Redumper/ExecutionContext.cs b/MPF.ExecutionContexts/Redumper/ExecutionContext.cs index b172a4ce..48f81ade 100644 --- a/MPF.ExecutionContexts/Redumper/ExecutionContext.cs +++ b/MPF.ExecutionContexts/Redumper/ExecutionContext.cs @@ -748,12 +748,12 @@ namespace MPF.ExecutionContexts.Redumper // Speed intValue = ProcessInt32Parameter(parts, FlagStrings.Speed, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) SpeedValue = intValue; // Retries intValue = ProcessInt32Parameter(parts, FlagStrings.Retries, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) RetriesValue = intValue; // Image Path @@ -780,17 +780,17 @@ namespace MPF.ExecutionContexts.Redumper // Drive Read Offset intValue = ProcessInt32Parameter(parts, FlagStrings.DriveReadOffset, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) DriveReadOffsetValue = intValue; // Drive C2 Shift intValue = ProcessInt32Parameter(parts, FlagStrings.DriveC2Shift, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) DriveC2ShiftValue = intValue; // Drive Pregap Start intValue = ProcessInt32Parameter(parts, FlagStrings.DrivePregapStart, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) DrivePregapStartValue = intValue; // Drive Read Method @@ -812,7 +812,7 @@ namespace MPF.ExecutionContexts.Redumper // Plextor Leadin Retries intValue = ProcessInt32Parameter(parts, FlagStrings.PlextorLeadinRetries, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) PlextorLeadinRetriesValue = intValue; // Asus Skip Leadout @@ -824,12 +824,12 @@ namespace MPF.ExecutionContexts.Redumper // Force Offset intValue = ProcessInt32Parameter(parts, FlagStrings.ForceOffset, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) ForceOffsetValue = intValue; // Audio Silence Threshold intValue = ProcessInt32Parameter(parts, FlagStrings.AudioSilenceThreshold, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) AudioSilenceThresholdValue = intValue; // Correct Offset Shift @@ -865,12 +865,12 @@ namespace MPF.ExecutionContexts.Redumper // LBA Start intValue = ProcessInt32Parameter(parts, FlagStrings.LBAStart, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) LBAStartValue = intValue; // LBA End intValue = ProcessInt32Parameter(parts, FlagStrings.LBAEnd, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) LBAEndValue = intValue; // Refine Subchannel @@ -883,12 +883,12 @@ namespace MPF.ExecutionContexts.Redumper // Dump Write Offset intValue = ProcessInt32Parameter(parts, FlagStrings.DumpWriteOffset, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) DumpWriteOffsetValue = intValue; // Dump Read Size intValue = ProcessInt32Parameter(parts, FlagStrings.DumpReadSize, ref i); - if (intValue != null && intValue != Int32.MinValue) + if (intValue != null && intValue != int.MinValue) DumpReadSizeValue = intValue; // Overread Leadout diff --git a/MPF.Processors/Aaru.cs b/MPF.Processors/Aaru.cs index 0404d91a..d76aeda9 100644 --- a/MPF.Processors/Aaru.cs +++ b/MPF.Processors/Aaru.cs @@ -122,7 +122,7 @@ namespace MPF.Processors // If we have a dual-layer disc else { - info.SizeAndChecksums!.Layerbreak = Int64.Parse(layerbreak); + info.SizeAndChecksums!.Layerbreak = long.Parse(layerbreak); } // TODO: Investigate XGD disc outputs @@ -973,7 +973,7 @@ namespace MPF.Processors catch { // We don't care what the exception is right now - return Int64.MaxValue; + return long.MaxValue; } } diff --git a/MPF.Processors/DiscImageCreator.cs b/MPF.Processors/DiscImageCreator.cs index 480d22b0..0ef9728b 100644 --- a/MPF.Processors/DiscImageCreator.cs +++ b/MPF.Processors/DiscImageCreator.cs @@ -159,7 +159,7 @@ namespace MPF.Processors if (Type == MediaType.DVD) { string layerbreak = GetLayerbreak($"{basePath}_disc.txt", System.IsXGD()) ?? string.Empty; - info.SizeAndChecksums!.Layerbreak = !string.IsNullOrEmpty(layerbreak) ? Int64.Parse(layerbreak) : default; + info.SizeAndChecksums!.Layerbreak = !string.IsNullOrEmpty(layerbreak) ? long.Parse(layerbreak) : default; } else if (Type == MediaType.BluRay) { @@ -1889,7 +1889,7 @@ namespace MPF.Processors // ISO9660 and extensions section if (line.StartsWith("Volume Descriptor Type: ")) { - Int32.TryParse(line.Substring("Volume Descriptor Type: ".Length), out int volTypeInt); + int.TryParse(line.Substring("Volume Descriptor Type: ".Length), out int volTypeInt); volType = volTypeInt switch { // 0 => "Boot Record" // Should not not contain a Volume Identifier diff --git a/MPF.Processors/ProcessingTool.cs b/MPF.Processors/ProcessingTool.cs index 21295fc8..fba5d717 100644 --- a/MPF.Processors/ProcessingTool.cs +++ b/MPF.Processors/ProcessingTool.cs @@ -227,7 +227,7 @@ namespace MPF.Processors var rom = roms[0]; - _ = Int64.TryParse(rom.Size, out size); + _ = long.TryParse(rom.Size, out size); crc32 = rom.CRC; md5 = rom.MD5; sha1 = rom.SHA1; @@ -251,7 +251,7 @@ namespace MPF.Processors Match m = hashreg.Match(hashData); if (m.Success) { - _ = Int64.TryParse(m.Groups[1].Value, out size); + _ = long.TryParse(m.Groups[1].Value, out size); crc32 = m.Groups[2].Value; md5 = m.Groups[3].Value; sha1 = m.Groups[4].Value; diff --git a/MPF.Processors/Redumper.cs b/MPF.Processors/Redumper.cs index 0da879ed..9f7b6e34 100644 --- a/MPF.Processors/Redumper.cs +++ b/MPF.Processors/Redumper.cs @@ -104,9 +104,9 @@ namespace MPF.Processors // Deal with the layerbreaks if (GetLayerbreaks($"{basePath}.log", out var layerbreak1, out var layerbreak2, out var layerbreak3)) { - info.SizeAndChecksums!.Layerbreak = !string.IsNullOrEmpty(layerbreak1) ? Int64.Parse(layerbreak1) : default; - info.SizeAndChecksums!.Layerbreak2 = !string.IsNullOrEmpty(layerbreak2) ? Int64.Parse(layerbreak2) : default; - info.SizeAndChecksums!.Layerbreak3 = !string.IsNullOrEmpty(layerbreak3) ? Int64.Parse(layerbreak3) : default; + info.SizeAndChecksums!.Layerbreak = !string.IsNullOrEmpty(layerbreak1) ? long.Parse(layerbreak1) : default; + info.SizeAndChecksums!.Layerbreak2 = !string.IsNullOrEmpty(layerbreak2) ? long.Parse(layerbreak2) : default; + info.SizeAndChecksums!.Layerbreak3 = !string.IsNullOrEmpty(layerbreak3) ? long.Parse(layerbreak3) : default; } // Bluray-specific options diff --git a/MPF.Processors/UmdImageCreator.cs b/MPF.Processors/UmdImageCreator.cs index a5558ad6..80d86cba 100644 --- a/MPF.Processors/UmdImageCreator.cs +++ b/MPF.Processors/UmdImageCreator.cs @@ -69,7 +69,7 @@ namespace MPF.Processors info.SizeAndChecksums!.Size = size; if (!string.IsNullOrEmpty(layer)) - info.SizeAndChecksums.Layerbreak = Int64.Parse(layer ?? "-1"); + info.SizeAndChecksums.Layerbreak = long.Parse(layer ?? "-1"); } break; @@ -193,7 +193,7 @@ namespace MPF.Processors else if (line.StartsWith("L0 length")) layer = line.Split(' ')[2]; else if (line.StartsWith("FileSize:")) - size = Int64.Parse(line.Split(' ')[1]); + size = long.Parse(line.Split(' ')[1]); } // If we have a serial, format it @@ -201,7 +201,7 @@ namespace MPF.Processors serial = serial.Substring(0, 4) + "-" + serial.Substring(4); // If the L0 length is the size of the full disc, there's no layerbreak - if (Int64.TryParse(layer, out long umdlayerValue) && umdlayerValue * 2048 == size) + if (long.TryParse(layer, out long umdlayerValue) && umdlayerValue * 2048 == size) layer = null; return true; @@ -241,7 +241,7 @@ namespace MPF.Processors // ISO9660 and extensions section if (line.StartsWith("Volume Descriptor Type: ")) { - Int32.TryParse(line.Substring("Volume Descriptor Type: ".Length), out int volTypeInt); + int.TryParse(line.Substring("Volume Descriptor Type: ".Length), out int volTypeInt); volType = volTypeInt switch { // 0 => "Boot Record" // Should not not contain a Volume Identifier