mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Remove unnecessary System.ValueTuple usage
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
- Use rolling release, not AppVeyor, in issue templates
|
||||
- Update BinaryObjectScanner to 3.1.15
|
||||
- Remove unused IndexRange library
|
||||
- Remove unnecessary System.ValueTuple usage
|
||||
|
||||
### 3.2.2 (2024-09-24)
|
||||
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace MPF.ExecutionContexts
|
||||
/// <returns>True if it's a valid byte, false otherwise</returns>
|
||||
protected static bool IsValidInt8(string parameter, sbyte lowerBound = -1, sbyte upperBound = -1)
|
||||
{
|
||||
(string value, long _) = ExtractFactorFromValue(parameter);
|
||||
string value = ExtractFactorFromValue(parameter, out _);
|
||||
if (!sbyte.TryParse(value, out sbyte temp))
|
||||
return false;
|
||||
else if (lowerBound != -1 && temp < lowerBound)
|
||||
@@ -352,7 +352,7 @@ namespace MPF.ExecutionContexts
|
||||
/// <returns>True if it's a valid Int16, false otherwise</returns>
|
||||
protected static bool IsValidInt16(string parameter, short lowerBound = -1, short upperBound = -1)
|
||||
{
|
||||
(string value, long _) = ExtractFactorFromValue(parameter);
|
||||
string value = ExtractFactorFromValue(parameter, out _);
|
||||
if (!short.TryParse(value, out short temp))
|
||||
return false;
|
||||
else if (lowerBound != -1 && temp < lowerBound)
|
||||
@@ -372,7 +372,7 @@ namespace MPF.ExecutionContexts
|
||||
/// <returns>True if it's a valid Int32, false otherwise</returns>
|
||||
protected static bool IsValidInt32(string parameter, int lowerBound = -1, int upperBound = -1)
|
||||
{
|
||||
(string value, long _) = ExtractFactorFromValue(parameter);
|
||||
string value = ExtractFactorFromValue(parameter, out _);
|
||||
if (!int.TryParse(value, out int temp))
|
||||
return false;
|
||||
else if (lowerBound != -1 && temp < lowerBound)
|
||||
@@ -392,7 +392,7 @@ namespace MPF.ExecutionContexts
|
||||
/// <returns>True if it's a valid Int64, false otherwise</returns>
|
||||
protected static bool IsValidInt64(string parameter, long lowerBound = -1, long upperBound = -1)
|
||||
{
|
||||
(string value, long _) = ExtractFactorFromValue(parameter);
|
||||
string value = ExtractFactorFromValue(parameter, out _);
|
||||
if (!long.TryParse(value, out long temp))
|
||||
return false;
|
||||
else if (lowerBound != -1 && temp < lowerBound)
|
||||
@@ -568,7 +568,7 @@ namespace MPF.ExecutionContexts
|
||||
this[longFlagString] = true;
|
||||
i++;
|
||||
|
||||
(string value, long factor) = ExtractFactorFromValue(parts[i]);
|
||||
string value = ExtractFactorFromValue(parts[i], out long factor);
|
||||
if (sbyte.TryParse(value, out sbyte sByteValue))
|
||||
return (sbyte)(sByteValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -588,7 +588,7 @@ namespace MPF.ExecutionContexts
|
||||
string valuePart = commandParts[1];
|
||||
|
||||
this[longFlagString] = true;
|
||||
(string value, long factor) = ExtractFactorFromValue(valuePart);
|
||||
string value = ExtractFactorFromValue(valuePart, out long factor);
|
||||
if (sbyte.TryParse(value, out sbyte sByteValue))
|
||||
return (sbyte)(sByteValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -655,7 +655,7 @@ namespace MPF.ExecutionContexts
|
||||
|
||||
this[longFlagString] = true;
|
||||
i++;
|
||||
(string value, long factor) = ExtractFactorFromValue(parts[i]);
|
||||
string value = ExtractFactorFromValue(parts[i], out long factor);
|
||||
if (short.TryParse(value, out short shortValue))
|
||||
return (short)(shortValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -675,7 +675,7 @@ namespace MPF.ExecutionContexts
|
||||
string valuePart = commandParts[1];
|
||||
|
||||
this[longFlagString] = true;
|
||||
(string value, long factor) = ExtractFactorFromValue(valuePart);
|
||||
string value = ExtractFactorFromValue(valuePart, out long factor);
|
||||
if (short.TryParse(value, out short shortValue))
|
||||
return (short)(shortValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -742,7 +742,7 @@ namespace MPF.ExecutionContexts
|
||||
|
||||
this[longFlagString] = true;
|
||||
i++;
|
||||
(string value, long factor) = ExtractFactorFromValue(parts[i]);
|
||||
string value = ExtractFactorFromValue(parts[i], out long factor);
|
||||
if (int.TryParse(value, out int intValue))
|
||||
return (int)(intValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -762,7 +762,7 @@ namespace MPF.ExecutionContexts
|
||||
string valuePart = commandParts[1];
|
||||
|
||||
this[longFlagString] = true;
|
||||
(string value, long factor) = ExtractFactorFromValue(valuePart);
|
||||
string value = ExtractFactorFromValue(valuePart, out long factor);
|
||||
if (int.TryParse(value, out int intValue))
|
||||
return (int)(intValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -829,7 +829,7 @@ namespace MPF.ExecutionContexts
|
||||
|
||||
this[longFlagString] = true;
|
||||
i++;
|
||||
(string value, long factor) = ExtractFactorFromValue(parts[i]);
|
||||
string value = ExtractFactorFromValue(parts[i], out long factor);
|
||||
if (long.TryParse(value, out long longValue))
|
||||
return (long)(longValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -849,7 +849,7 @@ namespace MPF.ExecutionContexts
|
||||
string valuePart = commandParts[1];
|
||||
|
||||
this[longFlagString] = true;
|
||||
(string value, long factor) = ExtractFactorFromValue(valuePart);
|
||||
string value = ExtractFactorFromValue(valuePart, out long factor);
|
||||
if (long.TryParse(value, out long longValue))
|
||||
return (long)(longValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -990,7 +990,7 @@ namespace MPF.ExecutionContexts
|
||||
this[longFlagString] = true;
|
||||
i++;
|
||||
|
||||
(string value, long factor) = ExtractFactorFromValue(parts[i]);
|
||||
string value = ExtractFactorFromValue(parts[i], out long factor);
|
||||
if (byte.TryParse(value, out byte byteValue))
|
||||
return (byte)(byteValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -1010,7 +1010,7 @@ namespace MPF.ExecutionContexts
|
||||
string valuePart = commandParts[1];
|
||||
|
||||
this[longFlagString] = true;
|
||||
(string value, long factor) = ExtractFactorFromValue(valuePart);
|
||||
string value = ExtractFactorFromValue(valuePart, out long factor);
|
||||
if (byte.TryParse(value, out byte byteValue))
|
||||
return (byte)(byteValue * factor);
|
||||
string hexValue = RemoveHexIdentifier(value);
|
||||
@@ -1027,10 +1027,10 @@ namespace MPF.ExecutionContexts
|
||||
/// </summary>
|
||||
/// <param name="value">String value to treat as suffixed number</param>
|
||||
/// <returns>Trimmed value and multiplication factor</returns>
|
||||
private static (string trimmed, long factor) ExtractFactorFromValue(string value)
|
||||
private static string ExtractFactorFromValue(string value, out long factor)
|
||||
{
|
||||
value = value.Trim('"');
|
||||
long factor = 1;
|
||||
factor = 1;
|
||||
|
||||
// Characters
|
||||
if (value.EndsWith("c", StringComparison.Ordinal))
|
||||
@@ -1081,7 +1081,7 @@ namespace MPF.ExecutionContexts
|
||||
value = value.TrimEnd('G');
|
||||
}
|
||||
|
||||
return (value, factor);
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -48,9 +48,6 @@
|
||||
<PackageReference Include="MinTasksExtensionsBridge" Version="0.3.4" />
|
||||
<PackageReference Include="MinThreadingBridge" Version="0.11.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`))">
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="!$(TargetFramework.StartsWith(`net2`)) AND !$(TargetFramework.StartsWith(`net3`)) AND !$(TargetFramework.StartsWith(`net40`)) AND !$(TargetFramework.StartsWith(`net452`))">
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -158,22 +158,22 @@ namespace MPF.Frontend
|
||||
if (programFound == null && _internalProgram != InternalProgram.Aaru)
|
||||
{
|
||||
var processor = new Processors.Aaru(_system, _type);
|
||||
(bool foundOtherFiles, _) = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (foundOtherFiles)
|
||||
var missingFiles = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (missingFiles.Count == 0)
|
||||
programFound = InternalProgram.Aaru;
|
||||
}
|
||||
if (programFound == null && _internalProgram != InternalProgram.DiscImageCreator)
|
||||
{
|
||||
var processor = new Processors.DiscImageCreator(_system, _type);
|
||||
(bool foundOtherFiles, _) = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (foundOtherFiles)
|
||||
var missingFiles = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (missingFiles.Count == 0)
|
||||
programFound = InternalProgram.DiscImageCreator;
|
||||
}
|
||||
if (programFound == null && _internalProgram != InternalProgram.Redumper)
|
||||
{
|
||||
var processor = new Processors.Redumper(_system, _type);
|
||||
(bool foundOtherFiles, _) = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (foundOtherFiles)
|
||||
var missingFiles = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (missingFiles.Count == 0)
|
||||
programFound = InternalProgram.Redumper;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace MPF.Frontend
|
||||
if (_processor == null)
|
||||
return false;
|
||||
|
||||
return _processor.FoundAllFiles(outputDirectory, outputFilename).Item1;
|
||||
return _processor.FoundAllFiles(outputDirectory, outputFilename).Count == 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="BaseExecutionContext.GetDefaultExtension(MediaType?)"/>
|
||||
@@ -437,8 +437,8 @@ namespace MPF.Frontend
|
||||
var outputFilename = Path.GetFileName(OutputPath);
|
||||
|
||||
// Check to make sure that the output had all the correct files
|
||||
(bool foundFiles, List<string> missingFiles) = _processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (!foundFiles)
|
||||
List<string> missingFiles = _processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (missingFiles.Count > 0)
|
||||
{
|
||||
resultProgress?.Report(ResultEventArgs.Failure($"There were files missing from the output:\n{string.Join("\n", [.. missingFiles])}"));
|
||||
return ResultEventArgs.Failure("Error! Please check output directory as dump may be incomplete!");
|
||||
@@ -532,22 +532,36 @@ namespace MPF.Frontend
|
||||
if (_options.CompressLogFiles)
|
||||
{
|
||||
resultProgress?.Report(ResultEventArgs.Success("Compressing log files..."));
|
||||
(bool compressSuccess, string compressResult) = _processor?.CompressLogFiles(outputDirectory, filenameSuffix, outputFilename) ?? (false, "No processor provided!");
|
||||
if (compressSuccess)
|
||||
resultProgress?.Report(ResultEventArgs.Success(compressResult));
|
||||
if (_processor == null)
|
||||
{
|
||||
resultProgress?.Report(ResultEventArgs.Failure("No processor provided!"));
|
||||
}
|
||||
else
|
||||
resultProgress?.Report(ResultEventArgs.Failure(compressResult));
|
||||
{
|
||||
bool compressSuccess = _processor.CompressLogFiles(outputDirectory, filenameSuffix, outputFilename, out string compressResult);
|
||||
if (compressSuccess)
|
||||
resultProgress?.Report(ResultEventArgs.Success(compressResult));
|
||||
else
|
||||
resultProgress?.Report(ResultEventArgs.Failure(compressResult));
|
||||
}
|
||||
}
|
||||
|
||||
// Delete unnecessary files, if required
|
||||
if (_options.DeleteUnnecessaryFiles)
|
||||
{
|
||||
resultProgress?.Report(ResultEventArgs.Success("Deleting unnecessary files..."));
|
||||
(bool deleteSuccess, string deleteResult) = _processor?.DeleteUnnecessaryFiles(outputDirectory, outputFilename) ?? (false, "No processor provided!");
|
||||
if (deleteSuccess)
|
||||
resultProgress?.Report(ResultEventArgs.Success(deleteResult));
|
||||
if (_processor == null)
|
||||
{
|
||||
resultProgress?.Report(ResultEventArgs.Failure("No processor provided!"));
|
||||
}
|
||||
else
|
||||
resultProgress?.Report(ResultEventArgs.Failure(deleteResult));
|
||||
{
|
||||
bool deleteSuccess = _processor.DeleteUnnecessaryFiles(outputDirectory, outputFilename, out string deleteResult);
|
||||
if (deleteSuccess)
|
||||
resultProgress?.Report(ResultEventArgs.Success(deleteResult));
|
||||
else
|
||||
resultProgress?.Report(ResultEventArgs.Failure(deleteResult));
|
||||
}
|
||||
}
|
||||
|
||||
// Create PS3 IRD, if required
|
||||
|
||||
@@ -57,8 +57,8 @@ namespace MPF.Frontend.Tools
|
||||
string outputFilename = Path.GetFileName(outputPath);
|
||||
|
||||
// Check that all of the relevant files are there
|
||||
(bool foundFiles, List<string> missingFiles) = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (!foundFiles)
|
||||
List<string> missingFiles = processor.FoundAllFiles(outputDirectory, outputFilename);
|
||||
if (missingFiles.Count > 0)
|
||||
{
|
||||
resultProgress?.Report(ResultEventArgs.Failure($"There were files missing from the output:\n{string.Join("\n", [.. missingFiles])}"));
|
||||
resultProgress?.Report(ResultEventArgs.Failure($"This may indicate an issue with the hardware or media, including unsupported devices.\nPlease see dumping program documentation for more details."));
|
||||
|
||||
@@ -72,10 +72,11 @@ namespace MPF.Processors
|
||||
/// <param name="outputFilename">Output filename to use as the base path</param>
|
||||
/// <param name="processor">Processor object representing how to process the outputs</param>
|
||||
/// <returns>True if the process succeeded, false otherwise</returns>
|
||||
public (bool, string) CompressLogFiles(string? outputDirectory, string? filenameSuffix, string outputFilename)
|
||||
public bool CompressLogFiles(string? outputDirectory, string? filenameSuffix, string outputFilename, out string status)
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
return (false, "Log compression is not available for this framework version");
|
||||
status = "Log compression is not available for this framework version";
|
||||
return false;
|
||||
#else
|
||||
// Prepare the necessary paths
|
||||
outputFilename = Path.GetFileNameWithoutExtension(outputFilename);
|
||||
@@ -94,7 +95,10 @@ namespace MPF.Processors
|
||||
|
||||
// Don't create an archive if there are no paths
|
||||
if (!zippableFiles.Any() && !generatedFiles.Any())
|
||||
return (true, "No files to compress!");
|
||||
{
|
||||
status = "No files to compress!";
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the file already exists, we want to delete the old one
|
||||
try
|
||||
@@ -104,7 +108,8 @@ namespace MPF.Processors
|
||||
}
|
||||
catch
|
||||
{
|
||||
return (false, "Could not delete old archive!");
|
||||
status = "Could not delete old archive!";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add the log files to the archive and delete the uncompressed file after
|
||||
@@ -116,11 +121,13 @@ namespace MPF.Processors
|
||||
_ = AddToArchive(zf, zippableFiles, outputDirectory, true);
|
||||
_ = AddToArchive(zf, generatedFiles, outputDirectory, false);
|
||||
|
||||
return (true, "Compression complete!");
|
||||
status = "Compression complete!";
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return (false, $"Compression could not complete: {ex}");
|
||||
status = $"Compression could not complete: {ex}";
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -136,7 +143,7 @@ namespace MPF.Processors
|
||||
/// <param name="outputFilename">Output filename to use as the base path</param>
|
||||
/// <param name="processor">Processor object representing how to process the outputs</param>
|
||||
/// <returns>True if the process succeeded, false otherwise</returns>
|
||||
public (bool, string) DeleteUnnecessaryFiles(string? outputDirectory, string outputFilename)
|
||||
public bool DeleteUnnecessaryFiles(string? outputDirectory, string outputFilename, out string status)
|
||||
{
|
||||
// Prepare the necessary paths
|
||||
outputFilename = Path.GetFileNameWithoutExtension(outputFilename);
|
||||
@@ -150,7 +157,10 @@ namespace MPF.Processors
|
||||
var files = GetDeleteableFilePaths(combinedBase);
|
||||
|
||||
if (!files.Any())
|
||||
return (true, "No files to delete!");
|
||||
{
|
||||
status = "No files to delete!";
|
||||
return true;
|
||||
}
|
||||
|
||||
// Attempt to delete all of the files
|
||||
foreach (string file in files)
|
||||
@@ -162,7 +172,8 @@ namespace MPF.Processors
|
||||
catch { }
|
||||
}
|
||||
|
||||
return (true, "Deletion complete!");
|
||||
status = "Deletion complete!";
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -171,8 +182,8 @@ namespace MPF.Processors
|
||||
/// <param name="outputDirectory">Output folder to write to</param>
|
||||
/// <param name="outputFilename">Output filename to use as the base path</param>
|
||||
/// <param name="processor">Processor object representing how to process the outputs</param>
|
||||
/// <returns>Tuple of true if all required files exist, false otherwise and a list representing missing files</returns>
|
||||
public (bool, List<string>) FoundAllFiles(string? outputDirectory, string outputFilename)
|
||||
/// <returns>A list representing missing files, empty if none</returns>
|
||||
public List<string> FoundAllFiles(string? outputDirectory, string outputFilename)
|
||||
{
|
||||
// Sanitize the output filename to strip off any potential extension
|
||||
outputFilename = Path.GetFileNameWithoutExtension(outputFilename);
|
||||
@@ -317,8 +328,8 @@ namespace MPF.Processors
|
||||
/// Validate if all required output files exist
|
||||
/// </summary>
|
||||
/// <param name="basePath">Base filename and path to use for checking</param>
|
||||
/// <returns>Tuple of true if all required files exist, false otherwise and a list representing missing files</returns>
|
||||
private (bool, List<string>) CheckRequiredFiles(string basePath)
|
||||
/// <returns>A list representing missing files, empty if none</returns>
|
||||
private List<string> CheckRequiredFiles(string basePath)
|
||||
{
|
||||
// Split the base path for matching
|
||||
string? baseDirectory = Path.GetDirectoryName(basePath);
|
||||
@@ -327,7 +338,7 @@ namespace MPF.Processors
|
||||
// Get the list of output files
|
||||
var outputFiles = GetOutputFiles(baseDirectory, baseFilename);
|
||||
if (outputFiles.Count == 0)
|
||||
return (false, ["Media and system combination not supported"]);
|
||||
return ["Media and system combination not supported"];
|
||||
|
||||
// Check for the log file
|
||||
bool logArchiveExists = false;
|
||||
@@ -382,7 +393,7 @@ namespace MPF.Processors
|
||||
#endif
|
||||
}
|
||||
|
||||
return (missingFiles.Count == 0, missingFiles);
|
||||
return missingFiles;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace MPF.Processors
|
||||
info = Builder.EnsureAllSections(info);
|
||||
|
||||
// Get the dumping program and version
|
||||
var (dicCmd, dicVersion) = GetCommandFilePathAndVersion(basePath);
|
||||
var dicVersion = GetCommandFilePathAndVersion(basePath, out var dicCmd);
|
||||
info.DumpingInfo!.DumpingProgram ??= string.Empty;
|
||||
info.DumpingInfo.DumpingProgram += $" {dicVersion ?? "Unknown Version"}";
|
||||
info.DumpingInfo.DumpingDate = ProcessingTool.GetFileModifiedDate(dicCmd)?.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
@@ -728,12 +728,13 @@ namespace MPF.Processors
|
||||
/// Get the command file path and extract the version from it
|
||||
/// </summary>
|
||||
/// <param name="basePath">Base filename and path to use for checking</param>
|
||||
/// <returns>Tuple of file path and version as strings, both null on error</returns>
|
||||
private static (string?, string?) GetCommandFilePathAndVersion(string basePath)
|
||||
/// <returns>The version as a string, both null on error</returns>
|
||||
private static string? GetCommandFilePathAndVersion(string basePath, out string? commandPath)
|
||||
{
|
||||
// If we have an invalid base path, we can do nothing
|
||||
commandPath = null;
|
||||
if (string.IsNullOrEmpty(basePath))
|
||||
return (null, null);
|
||||
return null;
|
||||
|
||||
// Generate the matching regex based on the base path
|
||||
string baseFilename = Path.GetFileName(basePath);
|
||||
@@ -742,17 +743,16 @@ namespace MPF.Processors
|
||||
// Find the first match for the command file
|
||||
var parentDirectory = Path.GetDirectoryName(basePath);
|
||||
if (string.IsNullOrEmpty(parentDirectory))
|
||||
return (null, null);
|
||||
return null;
|
||||
|
||||
var currentFiles = Directory.GetFiles(parentDirectory);
|
||||
var commandPath = currentFiles.FirstOrDefault(f => cmdFilenameRegex.IsMatch(f));
|
||||
if (string.IsNullOrEmpty(commandPath))
|
||||
return (null, null);
|
||||
commandPath = currentFiles.FirstOrDefault(f => cmdFilenameRegex.IsMatch(f));
|
||||
if (string.IsNullOrEmpty(value: commandPath))
|
||||
return null;
|
||||
|
||||
// Extract the version string
|
||||
var match = cmdFilenameRegex.Match(commandPath);
|
||||
string version = match.Groups[1].Value;
|
||||
return (commandPath, version);
|
||||
return match.Groups[1].Value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user