Remove .NET Framework 4.8 gated code

This commit is contained in:
Matt Nadareski
2023-11-06 22:07:40 -05:00
parent d57161e4d1
commit 24de14aea5
46 changed files with 19 additions and 3692 deletions

View File

@@ -2,6 +2,7 @@
- Remove .NET Framework 4.8 from build
- Remove .NET Framework 4.8 from projects
- Remove .NET Framework 4.8 gated code
### 2.7.5 (2023-11-06)

View File

@@ -45,11 +45,7 @@ namespace MPF.Check
protectionProgress.ProgressChanged += ConsoleLogger.ProgressUpdated;
// Validate the supplied credentials
#if NET48
(bool? _, string message) = RedumpWebClient.ValidateCredentials(options?.RedumpUsername, options?.RedumpPassword);
#else
(bool? _, string? message) = RedumpHttpClient.ValidateCredentials(options.RedumpUsername ?? string.Empty, options.RedumpPassword ?? string.Empty).ConfigureAwait(false).GetAwaiter().GetResult();
#endif
if (!string.IsNullOrWhiteSpace(message))
Console.WriteLine(message);
@@ -67,11 +63,7 @@ namespace MPF.Check
string filepath = Path.GetFullPath(args[i].Trim('"'));
// Now populate an environment
#if NET48
Drive drive = null;
#else
Drive? drive = null;
#endif
if (!string.IsNullOrWhiteSpace(path))
drive = Drive.Create(null, path);
@@ -87,11 +79,7 @@ namespace MPF.Check
/// Display help for MPF.Check
/// </summary>
/// <param name="error">Error string to prefix the help text with</param>
#if NET48
private static void DisplayHelp(string error = null)
#else
private static void DisplayHelp(string? error = null)
#endif
{
if (error != null)
Console.WriteLine(error);

View File

@@ -9,11 +9,7 @@ namespace MPF.Core
/// <summary>
/// Simple process counter to write to console
/// </summary>
#if NET48
public static void ProgressUpdated(object sender, Result value)
#else
public static void ProgressUpdated(object? sender, Result value)
#endif
{
Console.WriteLine(value.Message);
}
@@ -21,11 +17,7 @@ namespace MPF.Core
/// <summary>
/// Simple process counter to write to console
/// </summary>
#if NET48
public static void ProgressUpdated(object sender, ProtectionProgress value)
#else
public static void ProgressUpdated(object? sender, ProtectionProgress value)
#endif
{
Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}");
}

View File

@@ -38,11 +38,7 @@ namespace MPF.Core.Converters
/// <summary>
/// Long name method cache
/// </summary>
#if NET48
private static readonly ConcurrentDictionary<Type, MethodInfo> LongNameMethods = new ConcurrentDictionary<Type, MethodInfo>();
#else
private static readonly ConcurrentDictionary<Type, MethodInfo?> LongNameMethods = new ConcurrentDictionary<Type, MethodInfo?>();
#endif
/// <summary>
/// Get the string representation of a generic enumerable value
@@ -116,7 +112,7 @@ namespace MPF.Core.Converters
}
}
#endregion
#endregion
#region Convert From String
@@ -125,11 +121,7 @@ namespace MPF.Core.Converters
/// </summary>
/// <param name="internalProgram">String value to convert</param>
/// <returns>InternalProgram represented by the string, if possible</returns>
#if NET48
public static InternalProgram ToInternalProgram(string internalProgram)
#else
public static InternalProgram ToInternalProgram(string? internalProgram)
#endif
{
switch (internalProgram?.ToLowerInvariant())
{

View File

@@ -27,20 +27,12 @@ namespace MPF.Core.Data
/// <summary>
/// Drive partition format
/// </summary>
#if NET48
public string DriveFormat { get; private set; } = null;
#else
public string? DriveFormat { get; private set; } = null;
#endif
/// <summary>
/// Windows drive path
/// </summary>
#if NET48
public string Name { get; private set; } = null;
#else
public string? Name { get; private set; } = null;
#endif
/// <summary>
/// Represents if Windows has marked the drive as active
@@ -56,11 +48,7 @@ namespace MPF.Core.Data
/// Media label as read by Windows
/// </summary>
/// <remarks>The try/catch is needed because Windows will throw an exception if the drive is not marked as active</remarks>
#if NET48
public string VolumeLabel { get; private set; } = null;
#else
public string? VolumeLabel { get; private set; } = null;
#endif
#endregion
@@ -69,11 +57,7 @@ namespace MPF.Core.Data
/// <summary>
/// Media label as read by Windows, formatted to avoid odd outputs
/// </summary>
#if NET48
public string FormattedVolumeLabel
#else
public string? FormattedVolumeLabel
#endif
{
get
{
@@ -111,11 +95,7 @@ namespace MPF.Core.Data
/// </summary>
/// <param name="driveType">InternalDriveType value representing the drive type</param>
/// <param name="devicePath">Path to the device according to the local machine</param>
#if NET48
public static Drive Create(InternalDriveType? driveType, string devicePath)
#else
public static Drive? Create(InternalDriveType? driveType, string devicePath)
#endif
{
// Create a new, empty drive object
var drive = new Drive()
@@ -129,11 +109,7 @@ namespace MPF.Core.Data
// Sanitize a Windows-formatted long device path
if (devicePath.StartsWith("\\\\.\\"))
#if NET48
devicePath = devicePath.Substring("\\\\.\\".Length);
#else
devicePath = devicePath["\\\\.\\".Length..];
#endif
// Create and validate the drive info object
var driveInfo = new DriveInfo(devicePath);
@@ -150,11 +126,7 @@ namespace MPF.Core.Data
/// Populate all fields from a DriveInfo object
/// </summary>
/// <param name="driveInfo">DriveInfo object to populate from</param>
#if NET48
private void PopulateFromDriveInfo(DriveInfo driveInfo)
#else
private void PopulateFromDriveInfo(DriveInfo? driveInfo)
#endif
{
// If we have an invalid DriveInfo, just return
if (driveInfo == null || driveInfo == default)
@@ -196,11 +168,7 @@ namespace MPF.Core.Data
/// </summary>
/// <param name="system"></param>
/// <returns></returns>
#if NET48
public (MediaType?, string) GetMediaType(RedumpSystem? system)
#else
public (MediaType?, string?) GetMediaType(RedumpSystem? system)
#endif
{
// Take care of the non-optical stuff first
switch (this.InternalDriveType)

View File

@@ -8,22 +8,13 @@ namespace MPF.Core.Data
{
public class IniFile : IDictionary<string, string>
{
#if NET48
private Dictionary<string, string> _keyValuePairs = new Dictionary<string, string>();
#else
private Dictionary<string, string> _keyValuePairs = new();
#endif
public string this[string key]
{
get
{
#if NET48
if (_keyValuePairs == null)
_keyValuePairs = new Dictionary<string, string>();
#else
_keyValuePairs ??= new Dictionary<string, string>();
#endif
key = key.ToLowerInvariant();
if (_keyValuePairs.ContainsKey(key))
@@ -33,12 +24,7 @@ namespace MPF.Core.Data
}
set
{
#if NET48
if (_keyValuePairs == null)
_keyValuePairs = new Dictionary<string, string>();
#else
_keyValuePairs ??= new Dictionary<string, string>();
#endif
key = key.ToLowerInvariant();
_keyValuePairs[key] = value;
@@ -137,11 +123,7 @@ namespace MPF.Core.Data
}
// Valid INI lines are in the format key=value
#if NET48
else if (line.Contains("="))
#else
else if (line.Contains('='))
#endif
{
// Split the line by '=' for key-value pairs
string[] data = line.Split('=');

View File

@@ -9,11 +9,7 @@ namespace MPF.Core.Data
/// <summary>
/// All settings in the form of a dictionary
/// </summary>
#if NET48
public Dictionary<string, string> Settings { get; private set; }
#else
public Dictionary<string, string?> Settings { get; private set; }
#endif
/// <summary>
/// Indicate if the program is being run with a clean configuration
@@ -29,11 +25,7 @@ namespace MPF.Core.Data
/// <summary>
/// Path to Aaru
/// </summary>
#if NET48
public string AaruPath
#else
public string? AaruPath
#endif
{
get { return GetStringSetting(Settings, "AaruPath", "Programs\\Aaru\\Aaru.exe"); }
set { Settings["AaruPath"] = value; }
@@ -42,11 +34,7 @@ namespace MPF.Core.Data
/// <summary>
/// Path to DiscImageCreator
/// </summary>
#if NET48
public string DiscImageCreatorPath
#else
public string? DiscImageCreatorPath
#endif
{
get { return GetStringSetting(Settings, "DiscImageCreatorPath", "Programs\\Creator\\DiscImageCreator.exe"); }
set { Settings["DiscImageCreatorPath"] = value; }
@@ -55,11 +43,7 @@ namespace MPF.Core.Data
/// <summary>
/// Path to Redumper
/// </summary>
#if NET48
public string RedumperPath
#else
public string? RedumperPath
#endif
{
get { return GetStringSetting(Settings, "RedumperPath", "Programs\\Redumper\\redumper.exe"); }
set { Settings["RedumperPath"] = value; }
@@ -116,11 +100,7 @@ namespace MPF.Core.Data
/// <summary>
/// Default output path for dumps
/// </summary>
#if NET48
public string DefaultOutputPath
#else
public string? DefaultOutputPath
#endif
{
get { return GetStringSetting(Settings, "DefaultOutputPath", "ISO"); }
set { Settings["DefaultOutputPath"] = value; }
@@ -599,22 +579,14 @@ namespace MPF.Core.Data
#region Redump Login Information
#if NET48
public string RedumpUsername
#else
public string? RedumpUsername
#endif
{
get { return GetStringSetting(Settings, "RedumpUsername", ""); }
set { Settings["RedumpUsername"] = value; }
}
// TODO: Figure out a way to keep this encrypted in some way, BASE64 to start?
#if NET48
public string RedumpPassword
#else
public string? RedumpPassword
#endif
{
get
{
@@ -634,44 +606,24 @@ namespace MPF.Core.Data
/// Constructor taking a dictionary for settings
/// </summary>
/// <param name="settings"></param>
#if NET48
public Options(Dictionary<string, string> settings = null)
#else
public Options(Dictionary<string, string?>? settings = null)
#endif
{
#if NET48
this.Settings = settings ?? new Dictionary<string, string>();
#else
this.Settings = settings ?? new Dictionary<string, string?>();
#endif
}
/// <summary>
/// Constructor taking an existing Options object
/// </summary>
/// <param name="source"></param>
#if NET48
public Options(Options source)
#else
public Options(Options? source)
#endif
{
#if NET48
Settings = new Dictionary<string, string>(source?.Settings ?? new Dictionary<string, string>());
#else
Settings = new Dictionary<string, string?>(source?.Settings ?? new Dictionary<string, string?>());
#endif
}
/// <summary>
/// Accessor for the internal dictionary
/// </summary>
#if NET48
public string this[string key]
#else
public string? this[string key]
#endif
{
get => this.Settings[key];
set => this.Settings[key] = value;
@@ -686,11 +638,7 @@ namespace MPF.Core.Data
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
#if NET48
private static bool GetBooleanSetting(Dictionary<string, string> settings, string key, bool defaultValue)
#else
private static bool GetBooleanSetting(Dictionary<string, string?> settings, string key, bool defaultValue)
#endif
{
if (settings.ContainsKey(key))
{
@@ -712,11 +660,7 @@ namespace MPF.Core.Data
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
#if NET48
private static int GetInt32Setting(Dictionary<string, string> settings, string key, int defaultValue)
#else
private static int GetInt32Setting(Dictionary<string, string?> settings, string key, int defaultValue)
#endif
{
if (settings.ContainsKey(key))
{
@@ -738,11 +682,7 @@ namespace MPF.Core.Data
/// <param name="key">Setting key to get a value for</param>
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
#if NET48
private static string GetStringSetting(Dictionary<string, string> settings, string key, string defaultValue)
#else
private static string? GetStringSetting(Dictionary<string, string?> settings, string key, string? defaultValue)
#endif
{
if (settings.ContainsKey(key))
return settings[key];

View File

@@ -30,11 +30,7 @@
/// Create a success result with a custom message
/// </summary>
/// <param name="message">String to add as a message</param>
#if NET48
public static Result Success(string message) => new Result(true, message);
#else
public static Result Success(string? message) => new Result(true, message ?? string.Empty);
#endif
/// <summary>
/// Create a default failure result with no message
@@ -46,11 +42,7 @@
/// Create a failure result with a custom message
/// </summary>
/// <param name="message">String to add as a message</param>
#if NET48
public static Result Failure(string message) => new Result(false, message);
#else
public static Result Failure(string? message) => new Result(false, message ?? string.Empty);
#endif
/// <summary>
/// Results can be compared to boolean values based on the success value

View File

@@ -31,11 +31,7 @@ namespace MPF.Core
/// <summary>
/// Drive object representing the current drive
/// </summary>
#if NET48
public Drive Drive { get; private set; }
#else
public Drive? Drive { get; private set; }
#endif
/// <summary>
/// Currently selected system
@@ -60,11 +56,7 @@ namespace MPF.Core
/// <summary>
/// Parameters object representing what to send to the internal program
/// </summary>
#if NET48
public BaseParameters Parameters { get; private set; }
#else
public BaseParameters? Parameters { get; private set; }
#endif
#endregion
@@ -73,29 +65,17 @@ namespace MPF.Core
/// <summary>
/// Generic way of reporting a message
/// </summary>
#if NET48
public EventHandler<string> ReportStatus;
#else
public EventHandler<string>? ReportStatus;
#endif
/// <summary>
/// Queue of items that need to be logged
/// </summary>
#if NET48
private ProcessingQueue<string> outputQueue;
#else
private ProcessingQueue<string>? outputQueue;
#endif
/// <summary>
/// Event handler for data returned from a process
/// </summary>
#if NET48
private void OutputToLog(object proc, string args) => outputQueue?.Enqueue(args);
#else
private void OutputToLog(object? proc, string args) => outputQueue?.Enqueue(args);
#endif
/// <summary>
/// Process the outputs in the queue
@@ -116,19 +96,11 @@ namespace MPF.Core
/// <param name="parameters"></param>
public DumpEnvironment(Data.Options options,
string outputPath,
#if NET48
Drive drive,
#else
Drive? drive,
#endif
RedumpSystem? system,
MediaType? type,
InternalProgram? internalProgram,
#if NET48
string parameters)
#else
string? parameters)
#endif
{
// Set options object
Options = options;
@@ -152,47 +124,8 @@ namespace MPF.Core
/// Set the parameters object based on the internal program and parameters string
/// </summary>
/// <param name="parameters">String representation of the parameters</param>
#if NET48
public void SetParameters(string parameters)
#else
public void SetParameters(string? parameters)
#endif
{
#if NET48
switch (InternalProgram)
{
// Dumping support
case InternalProgram.Aaru:
Parameters = new Modules.Aaru.Parameters(parameters) { ExecutablePath = Options.AaruPath };
break;
case InternalProgram.DiscImageCreator:
Parameters = new Modules.DiscImageCreator.Parameters(parameters) { ExecutablePath = Options.DiscImageCreatorPath };
break;
case InternalProgram.Redumper:
Parameters = new Modules.Redumper.Parameters(parameters) { ExecutablePath = Options.RedumperPath };
break;
// Verification support only
case InternalProgram.CleanRip:
Parameters = new Modules.CleanRip.Parameters(parameters) { ExecutablePath = null };
break;
case InternalProgram.DCDumper:
Parameters = null; // TODO: Create correct parameter type when supported
break;
case InternalProgram.UmdImageCreator:
Parameters = new Modules.UmdImageCreator.Parameters(parameters) { ExecutablePath = null };
break;
// This should never happen, but it needs a fallback
default:
Parameters = new Modules.DiscImageCreator.Parameters(parameters) { ExecutablePath = Options.DiscImageCreatorPath };
break;
}
#else
Parameters = InternalProgram switch
{
// Dumping support
@@ -208,7 +141,6 @@ namespace MPF.Core
// This should never happen, but it needs a fallback
_ => new Modules.DiscImageCreator.Parameters(parameters) { ExecutablePath = Options.DiscImageCreatorPath },
};
#endif
// Set system and type
if (Parameters != null)
@@ -223,11 +155,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveSpeed">Nullable int representing the drive speed</param>
/// <returns>String representing the params, null on error</returns>
#if NET48
public string GetFullParameters(int? driveSpeed)
#else
public string? GetFullParameters(int? driveSpeed)
#endif
{
// Populate with the correct params for inputs (if we're not on the default option)
if (System != null && Type != MediaType.NONE)
@@ -237,27 +165,6 @@ namespace MPF.Core
return null;
// Set the proper parameters
#if NET48
switch (InternalProgram)
{
case InternalProgram.Aaru:
Parameters = new Modules.Aaru.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options);
break;
case InternalProgram.DiscImageCreator:
Parameters = new Modules.DiscImageCreator.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options);
break;
case InternalProgram.Redumper:
Parameters = new Modules.Redumper.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options);
break;
// This should never happen, but it needs a fallback
default:
Parameters = new Modules.DiscImageCreator.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options);
break;
}
#else
Parameters = InternalProgram switch
{
InternalProgram.Aaru => new Modules.Aaru.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options),
@@ -267,7 +174,6 @@ namespace MPF.Core
// This should never happen, but it needs a fallback
_ => new Modules.DiscImageCreator.Parameters(System, Type, Drive.Name, OutputPath, driveSpeed, Options),
};
#endif
// Generate and return the param string
return Parameters.GenerateParameters();
@@ -288,32 +194,20 @@ namespace MPF.Core
/// <summary>
/// Eject the disc using DiscImageCreator
/// </summary>
#if NET48
public async Task<string> EjectDisc() =>
#else
public async Task<string?> EjectDisc() =>
#endif
await RunStandaloneDiscImageCreatorCommand(Modules.DiscImageCreator.CommandStrings.Eject);
/// <summary>
/// Reset the current drive using DiscImageCreator
/// </summary>
#if NET48
public async Task<string> ResetDrive() =>
#else
public async Task<string?> ResetDrive() =>
#endif
await RunStandaloneDiscImageCreatorCommand(Modules.DiscImageCreator.CommandStrings.Reset);
/// <summary>
/// Execute the initial invocation of the dumping programs
/// </summary>
/// <param name="progress">Optional result progress callback</param>
#if NET48
public async Task<Result> Run(IProgress<Result> progress = null)
#else
public async Task<Result> Run(IProgress<Result>? progress = null)
#endif
{
// If we don't have parameters
if (Parameters == null)
@@ -361,17 +255,10 @@ namespace MPF.Core
/// <param name="seedInfo">A seed SubmissionInfo object that contains user data</param>
/// <returns>Result instance with the outcome</returns>
public async Task<Result> VerifyAndSaveDumpOutput(
#if NET48
IProgress<Result> resultProgress = null,
IProgress<ProtectionProgress> protectionProgress = null,
Func<SubmissionInfo, (bool?, SubmissionInfo)> processUserInfo = null,
SubmissionInfo seedInfo = null)
#else
IProgress<Result>? resultProgress = null,
IProgress<ProtectionProgress>? protectionProgress = null,
Func<SubmissionInfo?, (bool?, SubmissionInfo?)>? processUserInfo = null,
SubmissionInfo? seedInfo = null)
#endif
{
resultProgress?.Report(Result.Success("Gathering submission information... please wait!"));
@@ -620,11 +507,7 @@ namespace MPF.Core
/// </summary>
/// <param name="command">Command string to run</param>
/// <returns>The output of the command on success, null on error</returns>
#if NET48
private async Task<string> RunStandaloneDiscImageCreatorCommand(string command)
#else
private async Task<string?> RunStandaloneDiscImageCreatorCommand(string command)
#endif
{
// Validate that DiscImageCreator is all set
if (!RequiredProgramsExist())

View File

@@ -16,52 +16,28 @@ namespace MPF.Core.Hashing
/// <summary>
/// Hash type associated with the current state
/// </summary>
#if NET48
public Hash HashType { get; private set; }
#else
public Hash HashType { get; init; }
#endif
/// <summary>
/// Current hash in bytes
/// </summary>
#if NET48
public byte[] CurrentHashBytes
#else
public byte[]? CurrentHashBytes
#endif
{
get
{
#if NET48
switch (_hasher)
{
case HashAlgorithm ha:
return ha.Hash;
case NonCryptographicHashAlgorithm ncha:
return ncha.GetCurrentHash().Reverse().ToArray();
default:
return null;
}
#else
return (_hasher) switch
{
HashAlgorithm ha => ha.Hash,
NonCryptographicHashAlgorithm ncha => ncha.GetCurrentHash().Reverse().ToArray(),
_ => null,
};
#endif
}
}
/// <summary>
/// Current hash as a string
/// </summary>
#if NET48
public string CurrentHashString => ByteArrayToString(CurrentHashBytes);
#else
public string? CurrentHashString => ByteArrayToString(CurrentHashBytes);
#endif
#endregion
@@ -71,11 +47,7 @@ namespace MPF.Core.Hashing
/// Internal hasher being used for processing
/// </summary>
/// <remarks>May be either a HashAlgorithm or NonCryptographicHashAlgorithm</remarks>
#if NET48
private object _hasher;
#else
private object? _hasher;
#endif
#endregion
@@ -96,38 +68,6 @@ namespace MPF.Core.Hashing
/// </summary>
private void GetHasher()
{
#if NET48
switch (HashType)
{
case Hash.CRC32:
_hasher = new Crc32();
break;
case Hash.CRC64:
_hasher = new Crc64();
break;
case Hash.MD5:
_hasher = MD5.Create();
break;
case Hash.SHA1:
_hasher = SHA1.Create();
break;
case Hash.SHA256:
_hasher = SHA256.Create();
break;
case Hash.SHA384:
_hasher = SHA384.Create();
break;
case Hash.SHA512:
_hasher = SHA512.Create();
break;
case Hash.XxHash32:
_hasher = new XxHash32();
break;
case Hash.XxHash64:
_hasher = new XxHash64();
break;
}
#else
_hasher = HashType switch
{
Hash.CRC32 => new Crc32(),
@@ -141,7 +81,6 @@ namespace MPF.Core.Hashing
Hash.XxHash64 => new XxHash64(),
_ => null,
};
#endif
}
/// <inheritdoc/>
@@ -160,11 +99,7 @@ namespace MPF.Core.Hashing
/// </summary>
/// <param name="filename">Path to the input file</param>
/// <returns>True if hashing was successful, false otherwise</returns>
#if NET48
public static bool GetFileHashes(string filename, out long size, out string crc32, out string md5, out string sha1)
#else
public static bool GetFileHashes(string filename, out long size, out string? crc32, out string? md5, out string? sha1)
#endif
{
// Set all initial values
crc32 = null; md5 = null; sha1 = null;
@@ -186,11 +121,7 @@ namespace MPF.Core.Hashing
/// </summary>
/// <param name="filename">Path to the input file</param>
/// <returns>Dictionary containing hashes on success, null on error</returns>
#if NET48
public static Dictionary<Hash, string> GetFileHashes(string filename, out long size)
#else
public static Dictionary<Hash, string?>? GetFileHashes(string filename, out long size)
#endif
{
// If the file doesn't exist, we can't do anything
if (!File.Exists(filename))
@@ -203,11 +134,7 @@ namespace MPF.Core.Hashing
size = new FileInfo(filename).Length;
// Create the output dictionary
#if NET48
var hashDict = new Dictionary<Hash, string>();
#else
var hashDict = new Dictionary<Hash, string?>();
#endif
// Open the input file
var input = File.OpenRead(filename);
@@ -221,18 +148,10 @@ namespace MPF.Core.Hashing
/// </summary>
/// <param name="input">Stream to hash</param>
/// <returns>Dictionary containing hashes on success, null on error</returns>
#if NET48
public static Dictionary<Hash, string> GetStreamHashes(Stream input)
#else
public static Dictionary<Hash, string?>? GetStreamHashes(Stream input)
#endif
{
// Create the output dictionary
#if NET48
var hashDict = new Dictionary<Hash, string>();
#else
var hashDict = new Dictionary<Hash, string?>();
#endif
try
{
@@ -375,11 +294,7 @@ namespace MPF.Core.Hashing
/// <param name="bytes">Byte array to convert</param>
/// <returns>Hex string representing the byte array</returns>
/// <link>http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa</link>
#if NET48
private static string ByteArrayToString(byte[] bytes)
#else
private static string? ByteArrayToString(byte[]? bytes)
#endif
{
// If we get null in, we send null out
if (bytes == null)

View File

@@ -11,11 +11,7 @@ namespace MPF.Core.Hashing
private readonly AutoResetEvent _outEvent;
private readonly Thread _tWorker;
#if NET48
private byte[] _buffer;
#else
private byte[]? _buffer;
#endif
private int _size;
private readonly Stream _ds;
private bool _finished;

View File

@@ -33,11 +33,7 @@ namespace MPF.Core
/// <param name="parameters">Parameters object representing what to send to the internal program</param>
/// <param name="preCheck">True if this is a check done before a dump, false if done after</param>
/// <returns>Tuple of true if all required files exist, false otherwise and a list representing missing files</returns>
#if NET48
internal static (bool, List<string>) FoundAllFiles(string outputDirectory, string outputFilename, BaseParameters parameters, bool preCheck)
#else
internal static (bool, List<string>) FoundAllFiles(string? outputDirectory, string outputFilename, BaseParameters? parameters, bool preCheck)
#endif
{
// If there are no parameters set
if (parameters == null)
@@ -62,11 +58,7 @@ namespace MPF.Core
/// </summary>
/// <param name="datafile">.dat file location</param>
/// <returns>Relevant pieces of the datfile, null on error</returns>
#if NET48
internal static string GenerateDatfile(Datafile datafile)
#else
internal static string? GenerateDatfile(Datafile? datafile)
#endif
{
// If we don't have a valid datafile, we can't do anything
if (datafile?.Games == null || datafile.Games.Length == 0)
@@ -110,11 +102,7 @@ namespace MPF.Core
/// <param name="options">Options object that determines what to scan</param>
/// <param name="progress">Optional progress callback</param>
/// <returns>Detected copy protection(s) if possible, null on error</returns>
#if NET48
internal static async Task<(string, Dictionary<string, List<string>>)> GetCopyProtection(Drive drive, Data.Options options, IProgress<ProtectionProgress> progress = null)
#else
internal static async Task<(string?, Dictionary<string, List<string>>?)> GetCopyProtection(Drive? drive, Data.Options options, IProgress<ProtectionProgress>? progress = null)
#endif
{
if (options.ScanForProtection && drive?.Name != null)
{
@@ -130,11 +118,7 @@ namespace MPF.Core
/// </summary>
/// <param name="dat">Path to the DAT file to parse</param>
/// <returns>Filled Datafile on success, null on error</returns>
#if NET48
internal static Datafile GetDatafile(string dat)
#else
internal static Datafile? GetDatafile(string? dat)
#endif
{
// If there's no path, we can't read the file
if (string.IsNullOrWhiteSpace(dat))
@@ -177,11 +161,7 @@ namespace MPF.Core
/// <param name="pic">Path to a PIC.bin file</param>
/// <returns>Filled DiscInformation on success, null on error</returns>
/// <remarks>This omits the emergency brake information, if it exists</remarks>
#if NET48
internal static DiscInformation GetDiscInformation(string pic)
#else
internal static DiscInformation? GetDiscInformation(string pic)
#endif
{
try
{
@@ -199,11 +179,7 @@ namespace MPF.Core
/// </summary>
/// <param name="filename">Path to the input file</param>
/// <returns>Filled DateTime on success, null on failure</returns>
#if NET48
internal static DateTime? GetFileModifiedDate(string filename, bool fallback = false)
#else
internal static DateTime? GetFileModifiedDate(string? filename, bool fallback = false)
#endif
{
if (string.IsNullOrWhiteSpace(filename))
return fallback ? (DateTime?)DateTime.UtcNow : null;
@@ -220,11 +196,7 @@ namespace MPF.Core
/// <param name="filename">file location</param>
/// <param name="binary">True if should read as binary, false otherwise (default)</param>
/// <returns>Full text of the file, null on error</returns>
#if NET48
internal static string GetFullFile(string filename, bool binary = false)
#else
internal static string? GetFullFile(string filename, bool binary = false)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(filename))
@@ -245,11 +217,7 @@ namespace MPF.Core
/// </summary>
/// <param name="datafile">Datafile represenging the hash data</param>
/// <returns>True if extraction was successful, false otherwise</returns>
#if NET48
internal static bool GetISOHashValues(Datafile datafile, out long size, out string crc32, out string md5, out string sha1)
#else
internal static bool GetISOHashValues(Datafile? datafile, out long size, out string? crc32, out string? md5, out string? sha1)
#endif
{
size = -1; crc32 = null; md5 = null; sha1 = null;
@@ -275,11 +243,7 @@ namespace MPF.Core
/// </summary>
/// <param name="hashData">String representing the combined hash data</param>
/// <returns>True if extraction was successful, false otherwise</returns>
#if NET48
internal static bool GetISOHashValues(string hashData, out long size, out string crc32, out string md5, out string sha1)
#else
internal static bool GetISOHashValues(string? hashData, out long size, out string? crc32, out string? md5, out string? sha1)
#endif
{
size = -1; crc32 = null; md5 = null; sha1 = null;
@@ -307,11 +271,7 @@ namespace MPF.Core
/// </summary>
/// <param name="di">Disc information containing unformatted data</param>
/// <returns>True if layerbreak info was set, false otherwise</returns>
#if NET48
internal static bool GetLayerbreaks(DiscInformation di, out long? layerbreak1, out long? layerbreak2, out long? layerbreak3)
#else
internal static bool GetLayerbreaks(DiscInformation? di, out long? layerbreak1, out long? layerbreak2, out long? layerbreak3)
#endif
{
// Set the default values
layerbreak1 = null; layerbreak2 = null; layerbreak3 = null;
@@ -320,11 +280,7 @@ namespace MPF.Core
if (di?.Units == null || di.Units.Length <= 1)
return false;
#if NET48
int ReadFromArrayBigEndian(byte[] bytes, int offset)
#else
static int ReadFromArrayBigEndian(byte[]? bytes, int offset)
#endif
{
if (bytes == null)
return default;
@@ -370,11 +326,7 @@ namespace MPF.Core
/// <returns>Status of the LibCrypt data, if possible</returns>
internal static void GetLibCryptDetected(SubmissionInfo info, string basePath)
{
#if NET48
if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection();
#else
info.CopyProtection ??= new CopyProtectionSection();
#endif
bool? psLibCryptStatus = Protection.GetLibCryptDetected(basePath + ".sub");
if (psLibCryptStatus == true)
@@ -414,11 +366,7 @@ namespace MPF.Core
/// </summary>
/// <param name="di">Disc information containing the data</param>
/// <returns>String representing the PIC identifier, null on error</returns>
#if NET48
internal static string GetPICIdentifier(DiscInformation di)
#else
internal static string? GetPICIdentifier(DiscInformation? di)
#endif
{
// If we don't have valid disc information, we can't do anything
if (di?.Units == null || di.Units.Length <= 1)
@@ -436,11 +384,7 @@ namespace MPF.Core
/// <param name="region">Output region, if possible</param>
/// <param name="date">Output EXE date in "yyyy-mm-dd" format if possible, null on error</param>
/// <returns></returns>
#if NET48
internal static bool GetPlayStationExecutableInfo(char? driveLetter, out string serial, out Region? region, out string date)
#else
internal static bool GetPlayStationExecutableInfo(char? driveLetter, out string? serial, out Region? region, out string? date)
#endif
{
serial = null; region = null; date = null;
@@ -461,11 +405,7 @@ namespace MPF.Core
/// <param name="region">Output region, if possible</param>
/// <param name="date">Output EXE date in "yyyy-mm-dd" format if possible, null on error</param>
/// <returns></returns>
#if NET48
internal static bool GetPlayStationExecutableInfo(string drivePath, out string serial, out Region? region, out string date)
#else
internal static bool GetPlayStationExecutableInfo(string? drivePath, out string? serial, out Region? region, out string? date)
#endif
{
serial = null; region = null; date = null;
@@ -482,11 +422,7 @@ namespace MPF.Core
string systemCnfPath = Path.Combine(drivePath, "SYSTEM.CNF");
// Try both of the common paths that contain information
#if NET48
string exeName = null;
#else
string? exeName = null;
#endif
// Read the CNF file as an INI file
var systemCnf = new IniFile(systemCnfPath);
@@ -552,11 +488,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation2Version(char? driveLetter)
#else
internal static string? GetPlayStation2Version(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -572,11 +504,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation2Version(string drivePath)
#else
internal static string? GetPlayStation2Version(string? drivePath)
#endif
{
// If there's no drive path, we can't do this part
if (string.IsNullOrWhiteSpace(drivePath))
@@ -603,11 +531,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Internal disc serial if possible, null on error</returns>
#if NET48
internal static string GetPlayStation3Serial(char? driveLetter)
#else
internal static string? GetPlayStation3Serial(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -623,11 +547,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Internal disc serial if possible, null on error</returns>
#if NET48
internal static string GetPlayStation3Serial(string drivePath)
#else
internal static string? GetPlayStation3Serial(string? drivePath)
#endif
{
// If there's no drive path, we can't do this part
if (string.IsNullOrWhiteSpace(drivePath))
@@ -683,11 +603,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation3Version(char? driveLetter)
#else
internal static string? GetPlayStation3Version(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -703,11 +619,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation3Version(string drivePath)
#else
internal static string? GetPlayStation3Version(string? drivePath)
#endif
{
// If there's no drive path, we can't do this part
if (string.IsNullOrWhiteSpace(drivePath))
@@ -765,11 +677,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Firmware version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation3FirmwareVersion(char? driveLetter)
#else
internal static string? GetPlayStation3FirmwareVersion(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -785,11 +693,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Firmware version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation3FirmwareVersion(string drivePath)
#else
internal static string? GetPlayStation3FirmwareVersion(string? drivePath)
#endif
{
// If there's no drive path, we can't do this part
if (string.IsNullOrWhiteSpace(drivePath))
@@ -829,11 +733,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Internal disc serial if possible, null on error</returns>
#if NET48
internal static string GetPlayStation4Serial(char? driveLetter)
#else
internal static string? GetPlayStation4Serial(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -849,11 +749,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Internal disc serial if possible, null on error</returns>
#if NET48
internal static string GetPlayStation4Serial(string drivePath)
#else
internal static string? GetPlayStation4Serial(string? drivePath)
#endif
{
// If there's no drive path, we can't do this part
if (string.IsNullOrWhiteSpace(drivePath))
@@ -889,11 +785,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation4Version(char? driveLetter)
#else
internal static string? GetPlayStation4Version(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -909,11 +801,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation4Version(string drivePath)
#else
internal static string? GetPlayStation4Version(string? drivePath)
#endif
{
// If there's no drive path, we can't do this part
if (string.IsNullOrWhiteSpace(drivePath))
@@ -949,11 +837,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Internal disc serial if possible, null on error</returns>
#if NET48
internal static string GetPlayStation5Serial(char? driveLetter)
#else
internal static string? GetPlayStation5Serial(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -969,11 +853,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Internal disc serial if possible, null on error</returns>
#if NET48
internal static string GetPlayStation5Serial(string drivePath)
#else
internal static string? GetPlayStation5Serial(string? drivePath)
#endif
{
// Attempt to get the param.json file
var json = GetPlayStation5ParamsJsonFromDrive(drivePath);
@@ -996,11 +876,7 @@ namespace MPF.Core
/// </summary>
/// <param name="driveLetter">Drive letter to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation5Version(char? driveLetter)
#else
internal static string? GetPlayStation5Version(char? driveLetter)
#endif
{
// If there's no drive letter, we can't do this part
if (driveLetter == null)
@@ -1016,11 +892,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>Game version if possible, null on error</returns>
#if NET48
internal static string GetPlayStation5Version(string drivePath)
#else
internal static string? GetPlayStation5Version(string? drivePath)
#endif
{
// Attempt to get the param.json file
var json = GetPlayStation5ParamsJsonFromDrive(drivePath);
@@ -1043,11 +915,7 @@ namespace MPF.Core
/// </summary>
/// <param name="drivePath">Drive path to use to check</param>
/// <returns>JObject representing the JSON on success, null on error</returns>
#if NET48
private static JObject GetPlayStation5ParamsJsonFromDrive(string drivePath)
#else
private static JObject? GetPlayStation5ParamsJsonFromDrive(string? drivePath)
#endif
{
// If there's no drive path, we can't do this part
if (string.IsNullOrWhiteSpace(drivePath))
@@ -1067,11 +935,7 @@ namespace MPF.Core
/// </summary>
/// <param name="filename">Filename to check</param>
/// <returns>JObject representing the JSON on success, null on error</returns>
#if NET48
private static JObject GetPlayStation5ParamsJsonFromFile(string filename)
#else
private static JObject? GetPlayStation5ParamsJsonFromFile(string? filename)
#endif
{
// If the file doesn't exist
if (string.IsNullOrWhiteSpace(filename) || !File.Exists(filename))
@@ -1103,21 +967,8 @@ namespace MPF.Core
/// </summary>
/// <param name="region">String representing the category</param>
/// <returns>Category, if possible</returns>
#if NET48
internal static DiscCategory? GetUMDCategory(string category)
#else
internal static DiscCategory? GetUMDCategory(string? category)
#endif
{
#if NET48
switch (category)
{
case "GAME": return DiscCategory.Games;
case "VIDEO": return DiscCategory.Video;
case "AUDIO": return DiscCategory.Audio;
default: return null;
}
#else
return category switch
{
"GAME" => DiscCategory.Games,
@@ -1125,7 +976,6 @@ namespace MPF.Core
"AUDIO" => DiscCategory.Audio,
_ => null,
};
#endif
}
#endregion
@@ -1137,11 +987,7 @@ namespace MPF.Core
/// </summary>
/// <param name="serial">PlayStation serial code</param>
/// <returns>Region mapped from name, if possible</returns>
#if NET48
internal static Region? GetPlayStationRegion(string serial)
#else
internal static Region? GetPlayStationRegion(string? serial)
#endif
{
// If we have a fully invalid serial
if (string.IsNullOrWhiteSpace(serial))
@@ -1165,16 +1011,6 @@ namespace MPF.Core
{
case 'S':
// Check first two digits of S_PS serial
#if NET48
switch (serial.Substring(5, 2))
{
case "46": return Region.SouthKorea;
case "51": return Region.Asia;
case "56": return Region.SouthKorea;
case "55": return Region.Asia;
default: return Region.Japan;
}
#else
return serial.Substring(5, 2) switch
{
"46" => Region.SouthKorea,
@@ -1183,18 +1019,8 @@ namespace MPF.Core
"55" => Region.Asia,
_ => Region.Japan,
};
#endif
case 'M':
// Check first three digits of S_PM serial
#if NET48
switch (serial.Substring(5, 3))
{
case "645": return Region.SouthKorea;
case "675": return Region.SouthKorea;
case "885": return Region.SouthKorea;
default: return Region.Japan; // Remaining S_PM serials may be Japan or Asia
}
#else
return serial.Substring(5, 3) switch
{
"645" => Region.SouthKorea,
@@ -1202,7 +1028,6 @@ namespace MPF.Core
"885" => Region.SouthKorea,
_ => Region.Japan, // Remaining S_PM serials may be Japan or Asia
};
#endif
default: return Region.Japan;
}
}
@@ -1275,11 +1100,7 @@ namespace MPF.Core
/// <param name="outputFilename">Output filename to use as the base path</param>
/// <param name="parameters">Parameters object to use to derive log file paths</param>
/// <returns>True if the process succeeded, false otherwise</returns>
#if NET48
public static (bool, string) CompressLogFiles(string outputDirectory, string filenameSuffix, string outputFilename, BaseParameters parameters)
#else
public static (bool, string) CompressLogFiles(string? outputDirectory, string? filenameSuffix, string outputFilename, BaseParameters? parameters)
#endif
{
// If there are no parameters
if (parameters == null)
@@ -1317,11 +1138,7 @@ namespace MPF.Core
}
// Add the log files to the archive and delete the uncompressed file after
#if NET48
ZipArchive zf = null;
#else
ZipArchive? zf = null;
#endif
try
{
zf = ZipFile.Open(archiveName, ZipArchiveMode.Create);
@@ -1333,13 +1150,8 @@ namespace MPF.Core
}
else
{
#if NET48
string entryName = file.Substring(outputDirectory.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
zf.CreateEntryFromFile(file, entryName, CompressionLevel.Optimal);
#else
string entryName = file[outputDirectory.Length..].TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
zf.CreateEntryFromFile(file, entryName, CompressionLevel.SmallestSize);
#endif
}
// If the file is MPF-specific, don't delete
@@ -1372,11 +1184,7 @@ namespace MPF.Core
/// <param name="outputFilename">Output filename to use as the base path</param>
/// <param name="parameters">Parameters object to use to derive log file paths</param>
/// <returns>True if the process succeeded, false otherwise</returns>
#if NET48
public static (bool, string) DeleteUnnecessaryFiles(string outputDirectory, string outputFilename, BaseParameters parameters)
#else
public static (bool, string) DeleteUnnecessaryFiles(string? outputDirectory, string outputFilename, BaseParameters? parameters)
#endif
{
// If there are no parameters
if (parameters == null)
@@ -1422,11 +1230,7 @@ namespace MPF.Core
/// <param name="info">Information object that should contain normalized values</param>
/// <param name="options">Options object representing user-defined options</param>
/// <returns>List of strings representing each line of an output file, null on error</returns>
#if NET48
public static (List<string>, string) FormatOutputData(SubmissionInfo info, Data.Options options)
#else
public static (List<string>?, string?) FormatOutputData(SubmissionInfo? info, Data.Options options)
#endif
{
// Check to see if the inputs are valid
if (info == null)
@@ -1649,11 +1453,7 @@ namespace MPF.Core
AddIfExists(output, Template.ReportedDiscType, info.DumpingInfo?.ReportedDiscType, 1);
// Make sure there aren't any instances of two blank lines in a row
#if NET48
string last = null;
#else
string? last = null;
#endif
for (int i = 0; i < output.Count;)
{
if (output[i] == last && string.IsNullOrWhiteSpace(last))
@@ -1686,11 +1486,7 @@ namespace MPF.Core
/// <param name="layerbreak3">Third layerbreak value, as applicable</param>
/// <returns>String representation of the media, including layer specification</returns>
/// TODO: Figure out why we have this and NormalizeDiscType as well
#if NET48
public static string GetFixedMediaType(MediaType? mediaType, string picIdentifier, long? size, long? layerbreak, long? layerbreak2, long? layerbreak3)
#else
public static string? GetFixedMediaType(MediaType? mediaType, string? picIdentifier, long? size, long? layerbreak, long? layerbreak2, long? layerbreak3)
#endif
{
switch (mediaType)
{
@@ -1733,11 +1529,7 @@ namespace MPF.Core
/// Process any fields that have to be combined
/// </summary>
/// <param name="info">Information object to normalize</param>
#if NET48
public static void ProcessSpecialFields(SubmissionInfo info)
#else
public static void ProcessSpecialFields(SubmissionInfo? info)
#endif
{
// If there is no submission info
if (info == null)
@@ -1801,11 +1593,7 @@ namespace MPF.Core
/// <param name="filenameSuffix">Optional suffix to append to the filename</param>
/// <param name="lines">Preformatted list of lines to write out to the file</param>
/// <returns>True on success, false on error</returns>
#if NET48
public static (bool, string) WriteOutputData(string outputDirectory, string filenameSuffix, List<string> lines)
#else
public static (bool, string) WriteOutputData(string? outputDirectory, string? filenameSuffix, List<string>? lines)
#endif
{
// Check to see if the inputs are valid
if (lines == null)
@@ -1849,11 +1637,7 @@ namespace MPF.Core
/// <param name="info">SubmissionInfo object representing the JSON to write out to the file</param>
/// <param name="includedArtifacts">True if artifacts were included, false otherwise</param>
/// <returns>True on success, false on error</returns>
#if NET48
public static bool WriteOutputData(string outputDirectory, string filenameSuffix, SubmissionInfo info, bool includedArtifacts)
#else
public static bool WriteOutputData(string? outputDirectory, string? filenameSuffix, SubmissionInfo? info, bool includedArtifacts)
#endif
{
// Check to see if the input is valid
if (info == null)
@@ -1920,11 +1704,7 @@ namespace MPF.Core
/// <param name="filenameSuffix">Optional suffix to append to the filename</param>
/// <param name="info">SubmissionInfo object containing the protection information</param>
/// <returns>True on success, false on error</returns>
#if NET48
public static bool WriteProtectionData(string outputDirectory, string filenameSuffix, SubmissionInfo info)
#else
public static bool WriteProtectionData(string? outputDirectory, string? filenameSuffix, SubmissionInfo? info)
#endif
{
// Check to see if the inputs are valid
if (info?.CopyProtection?.FullProtections == null || !info.CopyProtection.FullProtections.Any())
@@ -1970,11 +1750,7 @@ namespace MPF.Core
/// <param name="key">Name of the output key to write</param>
/// <param name="value">Name of the output value to write</param>
/// <param name="indent">Number of tabs to indent the line</param>
#if NET48
private static void AddIfExists(List<string> output, string key, string value, int indent)
#else
private static void AddIfExists(List<string> output, string key, string? value, int indent)
#endif
{
// If there's no valid value to write
if (value == null)
@@ -2000,11 +1776,7 @@ namespace MPF.Core
// If the value contains a newline
value = value.Replace("\r\n", "\n");
#if NET48
if (value.Contains("\n"))
#else
if (value.Contains('\n'))
#endif
{
output.Add(prefix + key + ":"); output.Add("");
string[] values = value.Split('\n');
@@ -2028,11 +1800,7 @@ namespace MPF.Core
/// <param name="key">Name of the output key to write</param>
/// <param name="value">Name of the output value to write</param>
/// <param name="indent">Number of tabs to indent the line</param>
#if NET48
private static void AddIfExists(List<string> output, string key, string[] value, int indent)
#else
private static void AddIfExists(List<string> output, string key, string?[]? value, int indent)
#endif
{
// If there's no valid value to write
if (value == null || value.Length == 0)
@@ -2068,11 +1836,7 @@ namespace MPF.Core
/// <param name="key">Name of the output key to write</param>
/// <param name="value">Name of the output value to write</param>
/// <param name="indent">Number of tabs to indent the line</param>
#if NET48
private static void AddIfExists(List<string> output, string key, List<int> value, int indent)
#else
private static void AddIfExists(List<string> output, string key, List<int>? value, int indent)
#endif
{
// If there's no valid value to write
if (value == null || value.Count == 0)
@@ -2087,11 +1851,7 @@ namespace MPF.Core
/// <param name="outputDirectory">Output folder to write to</param>
/// <param name="filenameSuffix">Optional suffix to append to the filename</param>
/// <returns>List of all log file paths, empty otherwise</returns>
#if NET48
private static List<string> GetGeneratedFilePaths(string outputDirectory, string filenameSuffix)
#else
private static List<string> GetGeneratedFilePaths(string? outputDirectory, string? filenameSuffix)
#endif
{
var files = new List<string>();
@@ -2611,11 +2371,7 @@ namespace MPF.Core
/// Normalize a split set of paths
/// </summary>
/// <param name="path">Path value to normalize</param>
#if NET48
public static string NormalizeOutputPaths(string path, bool getFullPath)
#else
public static string NormalizeOutputPaths(string? path, bool getFullPath)
#endif
{
// The easy way
try
@@ -2687,34 +2443,19 @@ namespace MPF.Core
/// <remarks>TODO: This should move to Extensions at some point</remarks>
private static bool IsBoolean(SiteCode? siteCode)
{
#if NET48
switch (siteCode)
{
case SiteCode.PostgapType:
case SiteCode.VCD:
return true;
default:
return false;
}
#else
return siteCode switch
{
SiteCode.PostgapType => true,
SiteCode.VCD => true,
_ => false,
};
#endif
}
/// <summary>
/// Order comment code tags according to Redump requirements
/// </summary>
/// <returns>Ordered list of KeyValuePairs representing the tags and values</returns>
#if NET48
private static List<KeyValuePair<SiteCode?, string>> OrderCommentTags(Dictionary<SiteCode?, string> tags)
#else
private static List<KeyValuePair<SiteCode?, string>> OrderCommentTags(Dictionary<SiteCode, string> tags)
#endif
{
var sorted = new List<KeyValuePair<SiteCode?, string>>();
@@ -2837,11 +2578,7 @@ namespace MPF.Core
/// Order content code tags according to Redump requirements
/// </summary>
/// <returns>Ordered list of KeyValuePairs representing the tags and values</returns>
#if NET48
private static List<KeyValuePair<SiteCode?, string>> OrderContentTags(Dictionary<SiteCode?, string> tags)
#else
private static List<KeyValuePair<SiteCode?, string>> OrderContentTags(Dictionary<SiteCode, string> tags)
#endif
{
var sorted = new List<KeyValuePair<SiteCode?, string>>();

View File

@@ -27,18 +27,10 @@ namespace MPF.Core.Modules.Aaru
#region Generic Dumping Information
/// <inheritdoc/>
#if NET48
public override string InputPath => InputValue;
#else
public override string? InputPath => InputValue;
#endif
/// <inheritdoc/>
#if NET48
public override string OutputPath => OutputValue;
#else
public override string? OutputPath => OutputValue;
#endif
/// <inheritdoc/>
public override int? Speed
@@ -60,177 +52,69 @@ namespace MPF.Core.Modules.Aaru
public int? BlockSizeValue { get; set; }
#if NET48
public string CommentsValue { get; set; }
#else
public string? CommentsValue { get; set; }
#endif
#if NET48
public string CreatorValue { get; set; }
#else
public string? CreatorValue { get; set; }
#endif
public int? CountValue { get; set; }
#if NET48
public string DriveManufacturerValue { get; set; }
#else
public string? DriveManufacturerValue { get; set; }
#endif
#if NET48
public string DriveModelValue { get; set; }
#else
public string? DriveModelValue { get; set; }
#endif
#if NET48
public string DriveRevisionValue { get; set; }
#else
public string? DriveRevisionValue { get; set; }
#endif
#if NET48
public string DriveSerialValue { get; set; }
#else
public string? DriveSerialValue { get; set; }
#endif
#if NET48
public string EncodingValue { get; set; }
#else
public string? EncodingValue { get; set; }
#endif
#if NET48
public string FormatConvertValue { get; set; }
#else
public string? FormatConvertValue { get; set; }
#endif
#if NET48
public string FormatDumpValue { get; set; }
#else
public string? FormatDumpValue { get; set; }
#endif
#if NET48
public string GeometryValue { get; set; }
#else
public string? GeometryValue { get; set; }
#endif
#if NET48
public string ImgBurnLogValue { get; set; }
#else
public string? ImgBurnLogValue { get; set; }
#endif
#if NET48
public string InputValue { get; set; }
#else
public string? InputValue { get; set; }
#endif
#if NET48
public string Input1Value { get; set; }
#else
public string? Input1Value { get; set; }
#endif
#if NET48
public string Input2Value { get; set; }
#else
public string? Input2Value { get; set; }
#endif
public long? LengthValue { get; set; }
public int? MaxBlocksValue { get; set; }
#if NET48
public string MediaBarcodeValue { get; set; }
#else
public string? MediaBarcodeValue { get; set; }
#endif
public int? MediaLastSequenceValue { get; set; }
#if NET48
public string MediaManufacturerValue { get; set; }
#else
public string? MediaManufacturerValue { get; set; }
#endif
#if NET48
public string MediaModelValue { get; set; }
#else
public string? MediaModelValue { get; set; }
#endif
#if NET48
public string MediaPartNumberValue { get; set; }
#else
public string? MediaPartNumberValue { get; set; }
#endif
public int? MediaSequenceValue { get; set; }
#if NET48
public string MediaSerialValue { get; set; }
#else
public string? MediaSerialValue { get; set; }
#endif
#if NET48
public string MediaTitleValue { get; set; }
#else
public string? MediaTitleValue { get; set; }
#endif
#if NET48
public string MHDDLogValue { get; set; }
#else
public string? MHDDLogValue { get; set; }
#endif
#if NET48
public string NamespaceValue { get; set; }
#else
public string? NamespaceValue { get; set; }
#endif
#if NET48
public string OptionsValue { get; set; }
#else
public string? OptionsValue { get; set; }
#endif
#if NET48
public string OutputValue { get; set; }
#else
public string? OutputValue { get; set; }
#endif
#if NET48
public string OutputPrefixValue { get; set; }
#else
public string? OutputPrefixValue { get; set; }
#endif
#if NET48
public string RemoteHostValue { get; set; }
#else
public string? RemoteHostValue { get; set; }
#endif
#if NET48
public string ResumeFileValue { get; set; }
#else
public string? ResumeFileValue { get; set; }
#endif
public short? RetryPassesValue { get; set; }
@@ -240,35 +124,19 @@ namespace MPF.Core.Modules.Aaru
public long? StartValue { get; set; }
#if NET48
public string SubchannelValue { get; set; }
#else
public string? SubchannelValue { get; set; }
#endif
public short? WidthValue { get; set; }
#if NET48
public string XMLSidecarValue { get; set; }
#else
public string? XMLSidecarValue { get; set; }
#endif
#endregion
/// <inheritdoc/>
#if NET48
public Parameters(string parameters) : base(parameters) { }
#else
public Parameters(string? parameters) : base(parameters) { }
#endif
/// <inheritdoc/>
#if NET48
public Parameters(RedumpSystem? system, MediaType? type, string drivePath, string filename, int? driveSpeed, Options options)
#else
public Parameters(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Options options)
#endif
: base(system, type, drivePath, filename, driveSpeed, options)
{
}
@@ -328,11 +196,7 @@ namespace MPF.Core.Modules.Aaru
}
/// <inheritdoc/>
#if NET48
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive drive, bool includeArtifacts)
#else
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive? drive, bool includeArtifacts)
#endif
{
// TODO: Fill in submission info specifics for Aaru
var outputDirectory = Path.GetDirectoryName(basePath);
@@ -341,11 +205,7 @@ namespace MPF.Core.Modules.Aaru
info = SubmissionInfoTool.EnsureAllSections(info);
// TODO: Determine if there's an Aaru version anywhere
#if NET48
info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram);
#else
info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(this.InternalProgram);
#endif
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(basePath + ".cicm.xml")?.ToString("yyyy-MM-dd HH:mm:ss");
// Deserialize the sidecar, if possible
@@ -377,11 +237,7 @@ namespace MPF.Core.Modules.Aaru
var datafile = GenerateDatafile(sidecar, basePath);
// Fill in the hash data
#if NET48
info.TracksAndWriteOffsets.ClrMameProData = InfoTool.GenerateDatfile(datafile);
#else
info.TracksAndWriteOffsets!.ClrMameProData = InfoTool.GenerateDatfile(datafile);
#endif
switch (this.Type)
{
@@ -395,11 +251,7 @@ namespace MPF.Core.Modules.Aaru
if (File.Exists(basePath + ".resume.xml"))
errorCount = GetErrorCount(basePath + ".resume.xml");
#if NET48
info.CommonDiscInfo.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString());
#else
info.CommonDiscInfo!.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString());
#endif
info.TracksAndWriteOffsets.Cuesheet = GenerateCuesheet(sidecar, basePath) ?? string.Empty;
@@ -415,11 +267,7 @@ namespace MPF.Core.Modules.Aaru
// Get the individual hash data, as per internal
if (InfoTool.GetISOHashValues(datafile, out long size, out var crc32, out var md5, out var sha1))
{
#if NET48
info.SizeAndChecksums.Size = size;
#else
info.SizeAndChecksums!.CRC32 = crc32;
#endif
info.SizeAndChecksums.CRC32 = crc32;
info.SizeAndChecksums.MD5 = md5;
info.SizeAndChecksums.SHA1 = sha1;
@@ -430,19 +278,11 @@ namespace MPF.Core.Modules.Aaru
//info.Extras.PVD = GeneratePVD(sidecar) ?? "Disc has no PVD";
// Deal with the layerbreak
#if NET48
string layerbreak = null;
#else
string? layerbreak = null;
#endif
if (this.Type == MediaType.DVD)
layerbreak = GetLayerbreak(sidecar) ?? string.Empty;
else if (this.Type == MediaType.BluRay)
#if NET48
layerbreak = info.SizeAndChecksums.Size > 25_025_314_816 ? "25025314816" : null;
#else
layerbreak = info.SizeAndChecksums!.Size > 25_025_314_816 ? "25025314816" : null;
#endif
// If we have a single-layer disc
if (string.IsNullOrWhiteSpace(layerbreak))
@@ -452,11 +292,7 @@ namespace MPF.Core.Modules.Aaru
// If we have a dual-layer disc
else
{
#if NET48
info.SizeAndChecksums.Layerbreak = Int64.Parse(layerbreak);
#else
info.SizeAndChecksums!.Layerbreak = Int64.Parse(layerbreak);
#endif
}
// TODO: Investigate XGD disc outputs
@@ -476,60 +312,35 @@ namespace MPF.Core.Modules.Aaru
case RedumpSystem.DVDAudio:
case RedumpSystem.DVDVideo:
#if NET48
info.CopyProtection.Protection = GetDVDProtection(sidecar) ?? string.Empty;
#else
info.CopyProtection!.Protection = GetDVDProtection(sidecar) ?? string.Empty;
#endif
break;
case RedumpSystem.KonamiPython2:
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var pythonTwoSerial, out Region? pythonTwoRegion, out var pythonTwoDate))
{
// Ensure internal serial is pulled from local data
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? pythonTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = pythonTwoDate;
}
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#endif
break;
case RedumpSystem.MicrosoftXbox:
if (GetXgdAuxInfo(sidecar, out var xgd1DMIHash, out var xgd1PFIHash, out var xgd1SSHash, out var ss, out var xgd1SSVer))
{
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty;
#endif
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd1PFIHash ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd1SSVer ?? string.Empty;
#if NET48
info.Extras.SecuritySectorRanges = ss ?? string.Empty;
#else
info.Extras!.SecuritySectorRanges = ss ?? string.Empty;
#endif
}
if (GetXboxDMIInfo(sidecar, out var serial, out var version, out Region? region))
{
#if NET48
info.CommonDiscInfo.Serial = serial ?? string.Empty;
info.VersionAndEditions.Version = version ?? string.Empty;
#else
info.CommonDiscInfo!.Serial = serial ?? string.Empty;
info.VersionAndEditions!.Version = version ?? string.Empty;
#endif
info.CommonDiscInfo.Region = region;
}
@@ -538,30 +349,17 @@ namespace MPF.Core.Modules.Aaru
case RedumpSystem.MicrosoftXbox360:
if (GetXgdAuxInfo(sidecar, out var xgd23DMIHash, out var xgd23PFIHash, out var xgd23SSHash, out var ss360, out var xgd23SSVer))
{
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty;
#endif
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd23PFIHash ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSVersion] = xgd23SSVer ?? string.Empty;
#if NET48
info.Extras.SecuritySectorRanges = ss360 ?? string.Empty;
#else
info.Extras!.SecuritySectorRanges = ss360 ?? string.Empty;
#endif
}
if (GetXbox360DMIInfo(sidecar, out var serial360, out var version360, out Region? region360))
{
#if NET48
info.CommonDiscInfo.Serial = serial360 ?? string.Empty;
info.VersionAndEditions.Version = version360 ?? string.Empty;
#else
info.CommonDiscInfo!.Serial = serial360 ?? string.Empty;
info.VersionAndEditions!.Version = version360 ?? string.Empty;
#endif
info.CommonDiscInfo.Region = region360;
}
break;
@@ -570,11 +368,7 @@ namespace MPF.Core.Modules.Aaru
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var playstationSerial, out Region? playstationRegion, out var playstationDate))
{
// Ensure internal serial is pulled from local data
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationSerial ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationSerial ?? string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationDate;
}
@@ -585,67 +379,37 @@ namespace MPF.Core.Modules.Aaru
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var playstationTwoSerial, out Region? playstationTwoRegion, out var playstationTwoDate))
{
// Ensure internal serial is pulled from local data
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationTwoDate;
}
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#endif
break;
case RedumpSystem.SonyPlayStation3:
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
string firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
if (firmwareVersion != null)
info.CommonDiscInfo.ContentsSpecialFields[SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
string? firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
if (firmwareVersion != null)
info.CommonDiscInfo!.ContentsSpecialFields![SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#endif
break;
case RedumpSystem.SonyPlayStation4:
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation4Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation4Serial(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation4Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation4Serial(drive?.Name) ?? string.Empty;
#endif
break;
case RedumpSystem.SonyPlayStation5:
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation5Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation5Serial(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation5Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation5Serial(drive?.Name) ?? string.Empty;
#endif
break;
}
// Fill in any artifacts that exist, Base64-encoded, if we need to
if (includeArtifacts)
{
#if NET48
if (info.Artifacts == null) info.Artifacts = new Dictionary<string, string>();
#else
info.Artifacts ??= new Dictionary<string, string>();
#endif
if (File.Exists(basePath + ".cicm.xml"))
info.Artifacts["cicm"] = GetBase64(GetFullFile(basePath + ".cicm.xml")) ?? string.Empty;
if (File.Exists(basePath + ".ibg"))
@@ -662,11 +426,7 @@ namespace MPF.Core.Modules.Aaru
}
/// <inheritdoc/>
#if NET48
public override string GenerateParameters()
#else
public override string? GenerateParameters()
#endif
{
var parameters = new List<string>();
@@ -694,12 +454,7 @@ namespace MPF.Core.Modules.Aaru
#endregion
#if NET48
if (BaseCommand == null)
BaseCommand = CommandStrings.NONE;
#else
BaseCommand ??= CommandStrings.NONE;
#endif
if (!string.IsNullOrWhiteSpace(BaseCommand))
parameters.Add(BaseCommand);
@@ -1788,11 +1543,7 @@ namespace MPF.Core.Modules.Aaru
}
/// <inheritdoc/>
#if NET48
protected override void SetDefaultParameters(string drivePath, string filename, int? driveSpeed, Options options)
#else
protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Options options)
#endif
{
BaseCommand = $"{CommandStrings.MediaPrefixLong} {CommandStrings.MediaDump}";
@@ -1869,11 +1620,7 @@ namespace MPF.Core.Modules.Aaru
}
/// <inheritdoc/>
#if NET48
protected override bool ValidateAndSetParameters(string parameters)
#else
protected override bool ValidateAndSetParameters(string? parameters)
#endif
{
BaseCommand = CommandStrings.NONE;
@@ -1938,11 +1685,7 @@ namespace MPF.Core.Modules.Aaru
short? shortValue = null;
int? intValue = null;
long? longValue = null;
#if NET48
string stringValue = null;
#else
string? stringValue = null;
#endif
// Keep a count of keys to determine if we should break out to filename handling or not
int keyCount = Keys.Count();
@@ -2400,11 +2143,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="baseCommand">Command string to normalize</param>
/// <returns>Normalized command</returns>
#if NET48
private static string NormalizeCommand(List<string> parts, ref int start)
#else
private static string? NormalizeCommand(List<string> parts, ref int start)
#endif
{
// Invalid start means invalid command
if (start < 0 || start >= parts.Count)
@@ -2433,11 +2172,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="baseCommand">Command string to normalize</param>
/// <returns>Normalized command</returns>
#if NET48
private static string NormalizeCommand(string baseCommand)
#else
private static string? NormalizeCommand(string baseCommand)
#endif
{
// If the base command is inavlid, just return nulls
if (string.IsNullOrWhiteSpace(baseCommand))
@@ -2445,12 +2180,7 @@ namespace MPF.Core.Modules.Aaru
// Split the command otherwise
string[] splitCommand = baseCommand.Split(' ');
#if NET48
string family, command;
#else
string? family, command;
#endif
// For commands with a family
if (splitCommand.Length > 1)
@@ -2461,72 +2191,28 @@ namespace MPF.Core.Modules.Aaru
case CommandStrings.ArchivePrefixShort:
case CommandStrings.ArchivePrefixLong:
family = CommandStrings.ArchivePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.ArchiveInfo:
command = CommandStrings.ArchiveInfo;
break;
default:
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.ArchiveInfo => CommandStrings.ArchiveInfo,
_ => null,
};
#endif
break;
case CommandStrings.DatabasePrefixShort:
case CommandStrings.DatabasePrefixLong:
family = CommandStrings.DatabasePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.DatabaseStats:
command = CommandStrings.DatabaseStats;
break;
case CommandStrings.DatabaseUpdate:
command = CommandStrings.DatabaseUpdate;
break;
default:
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.DatabaseStats => CommandStrings.DatabaseStats,
CommandStrings.DatabaseUpdate => CommandStrings.DatabaseUpdate,
_ => null,
};
#endif
break;
case CommandStrings.DevicePrefixShort:
case CommandStrings.DevicePrefixLong:
family = CommandStrings.DevicePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.DeviceInfo:
command = CommandStrings.DeviceInfo;
break;
case CommandStrings.DeviceList:
command = CommandStrings.DeviceList;
break;
case CommandStrings.DeviceReport:
command = CommandStrings.DeviceReport;
break;
default:
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.DeviceInfo => CommandStrings.DeviceInfo,
@@ -2534,7 +2220,6 @@ namespace MPF.Core.Modules.Aaru
CommandStrings.DeviceReport => CommandStrings.DeviceReport,
_ => null,
};
#endif
break;
@@ -2542,27 +2227,6 @@ namespace MPF.Core.Modules.Aaru
case CommandStrings.FilesystemPrefixShortAlt:
case CommandStrings.FilesystemPrefixLong:
family = CommandStrings.FilesystemPrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.FilesystemExtract:
command = CommandStrings.FilesystemExtract;
break;
case CommandStrings.FilesystemInfo:
command = CommandStrings.FilesystemInfo;
break;
case CommandStrings.FilesystemListShort:
case CommandStrings.FilesystemListLong:
command = CommandStrings.FilesystemListLong;
break;
case CommandStrings.FilesystemOptions:
command = CommandStrings.FilesystemOptions;
break;
default:
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.FilesystemExtract => CommandStrings.FilesystemExtract,
@@ -2572,53 +2236,12 @@ namespace MPF.Core.Modules.Aaru
CommandStrings.FilesystemOptions => CommandStrings.FilesystemOptions,
_ => null,
};
#endif
break;
case CommandStrings.ImagePrefixShort:
case CommandStrings.ImagePrefixLong:
family = CommandStrings.ImagePrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.ImageChecksumShort:
case CommandStrings.ImageChecksumLong:
command = CommandStrings.ImageChecksumLong;
break;
case CommandStrings.ImageCompareShort:
case CommandStrings.ImageCompareLong:
command = CommandStrings.ImageChecksumLong;
break;
case CommandStrings.ImageConvert:
command = CommandStrings.ImageConvert;
break;
case CommandStrings.ImageCreateSidecar:
command = CommandStrings.ImageCreateSidecar;
break;
case CommandStrings.ImageDecode:
command = CommandStrings.ImageDecode;
break;
case CommandStrings.ImageEntropy:
command = CommandStrings.ImageEntropy;
break;
case CommandStrings.ImageInfo:
command = CommandStrings.ImageInfo;
break;
case CommandStrings.ImageOptions:
command = CommandStrings.ImageOptions;
break;
case CommandStrings.ImagePrint:
command = CommandStrings.ImagePrint;
break;
case CommandStrings.ImageVerify:
command = CommandStrings.ImageVerify;
break;
default:
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.ImageChecksumShort => CommandStrings.ImageChecksumLong,
@@ -2635,30 +2258,12 @@ namespace MPF.Core.Modules.Aaru
CommandStrings.ImageVerify => CommandStrings.ImageVerify,
_ => null,
};
#endif
break;
case CommandStrings.MediaPrefixShort:
case CommandStrings.MediaPrefixLong:
family = CommandStrings.MediaPrefixLong;
#if NET48
switch (splitCommand[1])
{
case CommandStrings.MediaDump:
command = CommandStrings.MediaDump;
break;
case CommandStrings.MediaInfo:
command = CommandStrings.MediaInfo;
break;
case CommandStrings.MediaScan:
command = CommandStrings.MediaScan;
break;
default:
command = null;
break;
}
#else
command = splitCommand[1] switch
{
CommandStrings.MediaDump => CommandStrings.MediaDump,
@@ -2666,7 +2271,6 @@ namespace MPF.Core.Modules.Aaru
CommandStrings.MediaScan => CommandStrings.MediaScan,
_ => null,
};
#endif
break;
@@ -2681,29 +2285,6 @@ namespace MPF.Core.Modules.Aaru
else
{
family = null;
#if NET48
switch (splitCommand[0])
{
case CommandStrings.Configure:
command = CommandStrings.Configure;
break;
case CommandStrings.Formats:
command = CommandStrings.Formats;
break;
case CommandStrings.ListEncodings:
command = CommandStrings.ListEncodings;
break;
case CommandStrings.ListNamespaces:
command = CommandStrings.ListNamespaces;
break;
case CommandStrings.Remote:
command = CommandStrings.Remote;
break;
default:
command = null;
break;
}
#else
command = splitCommand[0] switch
{
CommandStrings.Configure => CommandStrings.Configure,
@@ -2713,7 +2294,6 @@ namespace MPF.Core.Modules.Aaru
CommandStrings.Remote => CommandStrings.Remote,
_ => null,
};
#endif
}
// If the command itself is invalid, then return null
@@ -2793,11 +2373,7 @@ namespace MPF.Core.Modules.Aaru
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <param name="basePath">Base path for determining file names</param>
/// <returns>String containing the cuesheet, null on error</returns>
#if NET48
private static string GenerateCuesheet(CICMMetadataType cicmSidecar, string basePath)
#else
private static string? GenerateCuesheet(CICMMetadataType? cicmSidecar, string basePath)
#endif
{
// If the object is null, we can't get information from it
if (cicmSidecar == null)
@@ -2938,11 +2514,7 @@ namespace MPF.Core.Modules.Aaru
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <param name="basePath">Base path for determining file names</param>
/// <returns>String containing the datfile, null on error</returns>
#if NET48
private static string GenerateDatfile(CICMMetadataType cicmSidecar, string basePath)
#else
private static string? GenerateDatfile(CICMMetadataType? cicmSidecar, string basePath)
#endif
{
// If the object is null, we can't get information from it
if (cicmSidecar == null)
@@ -3050,11 +2622,7 @@ namespace MPF.Core.Modules.Aaru
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <param name="basePath">Base path for determining file names</param>
/// <returns>Datafile containing the hash information, null on error</returns>
#if NET48
private static Datafile GenerateDatafile(CICMMetadataType cicmSidecar, string basePath)
#else
private static Datafile? GenerateDatafile(CICMMetadataType? cicmSidecar, string basePath)
#endif
{
// If the object is null, we can't get information from it
if (cicmSidecar == null)
@@ -3191,11 +2759,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>String containing the PVD, null on error</returns>
#if NET48
private static string GeneratePVD(CICMMetadataType cicmSidecar)
#else
private static string? GeneratePVD(CICMMetadataType? cicmSidecar)
#endif
{
// If the object is null, we can't get information from it
if (cicmSidecar == null)
@@ -3234,11 +2798,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="opticalDisc">OpticalDisc type from CICM Sidecar data</param>
/// <returns>Byte array representing the PVD, null on error</returns>
#if NET48
private static byte[] GeneratePVDData(OpticalDiscType opticalDisc)
#else
private static byte[]? GeneratePVDData(OpticalDiscType? opticalDisc)
#endif
{
// Required variables
DateTime creation = DateTime.MinValue;
@@ -3375,22 +2935,14 @@ namespace MPF.Core.Modules.Aaru
/// <param name="row">Row ID for outputting</param>
/// <param name="bytes">Byte span representing the data to write</param>
/// <returns>Formatted string representing the sector line</returns>
#if NET48
private static string GenerateSectorOutputLine(string row, ReadOnlySpan<byte> bytes)
#else
private static string? GenerateSectorOutputLine(string row, ReadOnlySpan<byte> bytes)
#endif
{
// If the data isn't correct, return null
if (bytes == null || bytes.Length != 16)
return null;
string pvdLine = $"{row} : ";
#if NET48
pvdLine += BitConverter.ToString(bytes.Slice(0, 8).ToArray()).Replace("-", " ");
#else
pvdLine += BitConverter.ToString(bytes[..8].ToArray()).Replace("-", " ");
#endif
pvdLine += " ";
pvdLine += BitConverter.ToString(bytes.Slice(8, 8).ToArray().ToArray()).Replace("-", " ");
pvdLine += " ";
@@ -3405,11 +2957,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>Object containing the data, null on error</returns>
#if NET48
private static CICMMetadataType GenerateSidecar(string cicmSidecar)
#else
private static CICMMetadataType? GenerateSidecar(string cicmSidecar)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(cicmSidecar))
@@ -3439,11 +2987,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>True if disc type info was set, false otherwise</returns>
#if NET48
private static bool GetDiscType(CICMMetadataType cicmSidecar, out string discType, out string discSubType)
#else
private static bool GetDiscType(CICMMetadataType? cicmSidecar, out string? discType, out string? discSubType)
#endif
{
// Set the default values
discType = null; discSubType = null;
@@ -3474,11 +3018,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>Formatted string representing the DVD protection, null on error</returns>
#if NET48
private static string GetDVDProtection(CICMMetadataType cicmSidecar)
#else
private static string? GetDVDProtection(CICMMetadataType? cicmSidecar)
#endif
{
// If the object is null, we can't get information from it
if (cicmSidecar == null)
@@ -3573,11 +3113,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>True if hardware info was set, false otherwise</returns>
#if NET48
private static bool GetHardwareInfo(CICMMetadataType cicmSidecar, out string manufacturer, out string model, out string firmware)
#else
private static bool GetHardwareInfo(CICMMetadataType? cicmSidecar, out string? manufacturer, out string? model, out string? firmware)
#endif
{
// Set the default values
manufacturer = null; model = null; firmware = null;
@@ -3621,11 +3157,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>Layerbreak if possible, null on error</returns>
#if NET48
private static string GetLayerbreak(CICMMetadataType cicmSidecar)
#else
private static string? GetLayerbreak(CICMMetadataType? cicmSidecar)
#endif
{
// If the object is null, we can't get information from it
if (cicmSidecar == null)
@@ -3636,11 +3168,7 @@ namespace MPF.Core.Modules.Aaru
return null;
// Setup the layerbreak
#if NET48
string layerbreak = null;
#else
string? layerbreak = null;
#endif
// Find and return the layerbreak, if possible
foreach (OpticalDiscType opticalDisc in cicmSidecar.OpticalDisc)
@@ -3660,11 +3188,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>Sample write offset if possible, null on error</returns>
#if NET48
private static string GetWriteOffset(CICMMetadataType cicmSidecar)
#else
private static string? GetWriteOffset(CICMMetadataType? cicmSidecar)
#endif
{
// If the object is null, we can't get information from it
if (cicmSidecar == null)
@@ -3692,11 +3216,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>True on successful extraction of info, false otherwise</returns>
#if NET48
private static bool GetXgdAuxInfo(CICMMetadataType cicmSidecar, out string dmihash, out string pfihash, out string sshash, out string ss, out string ssver)
#else
private static bool GetXgdAuxInfo(CICMMetadataType? cicmSidecar, out string? dmihash, out string? pfihash, out string? sshash, out string? ss, out string? ssver)
#endif
{
dmihash = null; pfihash = null; sshash = null; ss = null; ssver = null;
@@ -3791,11 +3311,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>True on successful extraction of info, false otherwise</returns>
#if NET48
private static bool GetXboxDMIInfo(CICMMetadataType cicmSidecar, out string serial, out string version, out Region? region)
#else
private static bool GetXboxDMIInfo(CICMMetadataType? cicmSidecar, out string? serial, out string? version, out Region? region)
#endif
{
serial = null; version = null; region = Region.World;
@@ -3843,11 +3359,7 @@ namespace MPF.Core.Modules.Aaru
/// </summary>
/// <param name="cicmSidecar">CICM Sidecar data generated by Aaru</param>
/// <returns>True on successful extraction of info, false otherwise</returns>
#if NET48
private static bool GetXbox360DMIInfo(CICMMetadataType cicmSidecar, out string serial, out string version, out Region? region)
#else
private static bool GetXbox360DMIInfo(CICMMetadataType? cicmSidecar, out string? serial, out string? version, out Region? region)
#endif
{
serial = null; version = null; region = Region.World;

View File

@@ -18,11 +18,7 @@ namespace MPF.Core.Modules
/// Geneeic way of reporting a message
/// </summary>
/// <param name="message">String value to report</param>
#if NET48
public EventHandler<string> ReportStatus;
#else
public EventHandler<string>? ReportStatus;
#endif
#endregion
@@ -31,20 +27,12 @@ namespace MPF.Core.Modules
/// <summary>
/// Base command to run
/// </summary>
#if NET48
public string BaseCommand { get; set; }
#else
public string? BaseCommand { get; set; }
#endif
/// <summary>
/// Set of flags to pass to the executable
/// </summary>
#if NET48
protected Dictionary<string, bool?> flags = new Dictionary<string, bool?>();
#else
protected Dictionary<string, bool?> flags = new();
#endif
protected internal IEnumerable<string> Keys => flags.Keys;
/// <summary>
@@ -68,11 +56,7 @@ namespace MPF.Core.Modules
/// <summary>
/// Process to track external program
/// </summary>
#if NET48
private Process process;
#else
private Process? process;
#endif
#endregion
@@ -81,30 +65,18 @@ namespace MPF.Core.Modules
/// <summary>
/// Command to flag support mappings
/// </summary>
#if NET48
public Dictionary<string, List<string>> CommandSupport => GetCommandSupport();
#else
public Dictionary<string, List<string>>? CommandSupport => GetCommandSupport();
#endif
/// <summary>
/// Input path for operations
/// </summary>
#if NET48
public virtual string InputPath => null;
#else
public virtual string? InputPath => null;
#endif
/// <summary>
/// Output path for operations
/// </summary>
/// <returns>String representing the path, null on error</returns>
#if NET48
public virtual string OutputPath => null;
#else
public virtual string? OutputPath => null;
#endif
/// <summary>
/// Get the processing speed from the implementation
@@ -118,11 +90,7 @@ namespace MPF.Core.Modules
/// <summary>
/// Path to the executable
/// </summary>
#if NET48
public string ExecutablePath { get; set; }
#else
public string? ExecutablePath { get; set; }
#endif
/// <summary>
/// Program that this set of parameters represents
@@ -145,11 +113,7 @@ namespace MPF.Core.Modules
/// Populate a Parameters object from a param string
/// </summary>
/// <param name="parameters">String possibly representing a set of parameters</param>
#if NET48
public BaseParameters(string parameters)
#else
public BaseParameters(string? parameters)
#endif
{
// If any parameters are not valid, wipe out everything
if (!ValidateAndSetParameters(parameters))
@@ -165,11 +129,7 @@ namespace MPF.Core.Modules
/// <param name="filename">Filename to use</param>
/// <param name="driveSpeed">Drive speed to use</param>
/// <param name="options">Options object containing all settings that may be used for setting parameters</param>
#if NET48
public BaseParameters(RedumpSystem? system, MediaType? type, string drivePath, string filename, int? driveSpeed, Options options)
#else
public BaseParameters(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Options options)
#endif
{
this.System = system;
this.Type = type;
@@ -194,11 +154,7 @@ namespace MPF.Core.Modules
/// <param name="basePath">Base filename and path to use for checking</param>
/// <param name="drive">Drive representing the disc to get information from</param>
/// <param name="includeArtifacts">True to include output files as encoded artifacts, false otherwise</param>
#if NET48
public abstract void GenerateSubmissionInfo(SubmissionInfo submissionInfo, Options options, string basePath, Drive drive, bool includeArtifacts);
#else
public abstract void GenerateSubmissionInfo(SubmissionInfo submissionInfo, Options options, string basePath, Drive? drive, bool includeArtifacts);
#endif
#endregion
@@ -208,54 +164,34 @@ namespace MPF.Core.Modules
/// Get all commands mapped to the supported flags
/// </summary>
/// <returns>Mappings from command to supported flags</returns>
#if NET48
public virtual Dictionary<string, List<string>> GetCommandSupport() => null;
#else
public virtual Dictionary<string, List<string>>? GetCommandSupport() => null;
#endif
/// <summary>
/// Blindly generate a parameter string based on the inputs
/// </summary>
/// <returns>Parameter string for invocation, null on error</returns>
#if NET48
public virtual string GenerateParameters() => null;
#else
public virtual string? GenerateParameters() => null;
#endif
/// <summary>
/// Get the default extension for a given media type
/// </summary>
/// <param name="mediaType">MediaType value to check</param>
/// <returns>String representing the media type, null on error</returns>
#if NET48
public virtual string GetDefaultExtension(MediaType? mediaType) => null;
#else
public virtual string? GetDefaultExtension(MediaType? mediaType) => null;
#endif
/// <summary>
/// Generate a list of all deleteable files generated
/// </summary>
/// <param name="basePath">Base filename and path to use for checking</param>
/// <returns>List of all deleteable file paths, empty otherwise</returns>
#if NET48
public virtual List<string> GetDeleteableFilePaths(string basePath) => new List<string>();
#else
public virtual List<string> GetDeleteableFilePaths(string basePath) => new();
#endif
/// <summary>
/// Generate a list of all log files generated
/// </summary>
/// <param name="basePath">Base filename and path to use for checking</param>
/// <returns>List of all log file paths, empty otherwise</returns>
#if NET48
public virtual List<string> GetLogFilePaths(string basePath) => new List<string>();
#else
public virtual List<string> GetLogFilePaths(string basePath) => new();
#endif
/// <summary>
/// Get the MediaType from the current set of parameters
@@ -303,22 +239,14 @@ namespace MPF.Core.Modules
/// <param name="filename">Filename to use</param>
/// <param name="driveSpeed">Drive speed to use</param>
/// <param name="options">Options object containing all settings that may be used for setting parameters</param>
#if NET48
protected virtual void SetDefaultParameters(string drivePath, string filename, int? driveSpeed, Options options) { }
#else
protected virtual void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Options options) { }
#endif
/// <summary>
/// Scan a possible parameter string and populate whatever possible
/// </summary>
/// <param name="parameters">String possibly representing parameters</param>
/// <returns>True if the parameters were set correctly, false otherwise</returns>
#if NET48
protected virtual bool ValidateAndSetParameters(string parameters) => !string.IsNullOrWhiteSpace(parameters);
#else
protected virtual bool ValidateAndSetParameters(string? parameters) => !string.IsNullOrWhiteSpace(parameters);
#endif
#endregion
@@ -392,11 +320,7 @@ namespace MPF.Core.Modules
/// </summary>
/// <param name="content">String content to encode</param>
/// <returns>Base64-encoded contents, if possible</returns>
#if NET48
protected static string GetBase64(string content)
#else
protected static string? GetBase64(string? content)
#endif
{
if (string.IsNullOrEmpty(content))
return null;
@@ -411,11 +335,7 @@ namespace MPF.Core.Modules
/// <param name="filename">file location</param>
/// <param name="binary">True if should read as binary, false otherwise (default)</param>
/// <returns>Full text of the file, null on error</returns>
#if NET48
protected static string GetFullFile(string filename, bool binary = false)
#else
protected static string? GetFullFile(string filename, bool binary = false)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(filename))
@@ -545,11 +465,7 @@ namespace MPF.Core.Modules
/// <param name="longFlagString">Long flag string, if available</param>
/// <param name="i">Reference to the position in the parts</param>
/// <returns>True if the parameter was processed successfully or skipped, false otherwise</returns>
#if NET48
protected bool ProcessFlagParameter(List<string> parts, string shortFlagString, string longFlagString, ref int i)
#else
protected bool ProcessFlagParameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i)
#endif
{
if (parts == null)
return false;
@@ -585,11 +501,7 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>True if the parameter was processed successfully or skipped, false otherwise</returns>
#if NET48
protected bool ProcessBooleanParameter(List<string> parts, string shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#else
protected bool ProcessBooleanParameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#endif
{
if (parts == null)
return false;
@@ -664,11 +576,7 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>SByte value if success, SByte.MinValue if skipped, null on error/returns>
#if NET48
protected sbyte? ProcessInt8Parameter(List<string> parts, string shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#else
protected sbyte? ProcessInt8Parameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#endif
{
if (parts == null)
return null;
@@ -746,11 +654,7 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>Int16 value if success, Int16.MinValue if skipped, null on error/returns>
#if NET48
protected short? ProcessInt16Parameter(List<string> parts, string shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#else
protected short? ProcessInt16Parameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#endif
{
if (parts == null)
return null;
@@ -827,11 +731,7 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>Int32 value if success, Int32.MinValue if skipped, null on error/returns>
#if NET48
protected int? ProcessInt32Parameter(List<string> parts, string shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#else
protected int? ProcessInt32Parameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#endif
{
if (parts == null)
return null;
@@ -908,11 +808,7 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>Int64 value if success, Int64.MinValue if skipped, null on error/returns>
#if NET48
protected long? ProcessInt64Parameter(List<string> parts, string shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#else
protected long? ProcessInt64Parameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#endif
{
if (parts == null)
return null;
@@ -977,12 +873,8 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>String value if possible, string.Empty on missing, null on error</returns>
#if NET48
protected string ProcessStringParameter(List<string> parts, string flagString, ref int i, bool missingAllowed = false)
#else
protected string? ProcessStringParameter(List<string> parts, string flagString, ref int i, bool missingAllowed = false)
#endif
=> ProcessStringParameter(parts, null, flagString, ref i, missingAllowed);
=> ProcessStringParameter(parts, null, flagString, ref i, missingAllowed);
/// <summary>
/// Process a string parameter
@@ -993,11 +885,7 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>String value if possible, string.Empty on missing, null on error</returns>
#if NET48
protected string ProcessStringParameter(List<string> parts, string shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#else
protected string? ProcessStringParameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#endif
{
if (parts == null)
return null;
@@ -1072,11 +960,7 @@ namespace MPF.Core.Modules
/// <param name="i">Reference to the position in the parts</param>
/// <param name="missingAllowed">True if missing values are allowed, false otherwise</param>
/// <returns>Byte value if success, Byte.MinValue if skipped, null on error/returns>
#if NET48
protected byte? ProcessUInt8Parameter(List<string> parts, string shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#else
protected byte? ProcessUInt8Parameter(List<string> parts, string? shortFlagString, string longFlagString, ref int i, bool missingAllowed = false)
#endif
{
if (parts == null)
return null;
@@ -1207,11 +1091,7 @@ namespace MPF.Core.Modules
/// <param name="trimLength">Number of characters to trim the PIC to, if -1, ignored</param>
/// <returns>PIC data as a hex string if possible, null on error</returns>
/// <remarks>https://stackoverflow.com/questions/9932096/add-separator-to-string-at-every-n-characters</remarks>
#if NET48
protected static string GetPIC(string picPath, int trimLength = -1)
#else
protected static string? GetPIC(string picPath, int trimLength = -1)
#endif
{
// If the file doesn't exist, we can't get the info
if (!File.Exists(picPath))
@@ -1224,11 +1104,7 @@ namespace MPF.Core.Modules
return null;
if (trimLength > -1)
#if NET48
hex = hex.Substring(0, trimLength);
#else
hex = hex[..trimLength];
#endif
return Regex.Replace(hex, ".{32}", "$0\n", RegexOptions.Compiled);
}

View File

@@ -23,18 +23,10 @@ namespace MPF.Core.Modules.CleanRip
#endregion
/// <inheritdoc/>
#if NET48
public Parameters(string parameters) : base(parameters) { }
#else
public Parameters(string? parameters) : base(parameters) { }
#endif
/// <inheritdoc/>
#if NET48
public Parameters(RedumpSystem? system, MediaType? type, string drivePath, string filename, int? driveSpeed, Options options)
#else
public Parameters(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Options options)
#endif
: base(system, type, drivePath, filename, driveSpeed, options)
{
}
@@ -69,21 +61,13 @@ namespace MPF.Core.Modules.CleanRip
}
/// <inheritdoc/>
#if NET48
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive drive, bool includeArtifacts)
#else
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive? drive, bool includeArtifacts)
#endif
{
// Ensure that required sections exist
info = SubmissionInfoTool.EnsureAllSections(info);
// TODO: Determine if there's a CleanRip version anywhere
#if NET48
info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram);
#else
info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(this.InternalProgram);
#endif
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(basePath + "-dumpinfo.txt")?.ToString("yyyy-MM-dd HH:mm:ss");
var datafile = GenerateCleanripDatafile(basePath + ".iso", basePath + "-dumpinfo.txt");
@@ -91,11 +75,7 @@ namespace MPF.Core.Modules.CleanRip
// Get the individual hash data, as per internal
if (InfoTool.GetISOHashValues(datafile, out long size, out var crc32, out var md5, out var sha1))
{
#if NET48
info.SizeAndChecksums.Size = size;
#else
info.SizeAndChecksums!.Size = size;
#endif
info.SizeAndChecksums.CRC32 = crc32;
info.SizeAndChecksums.MD5 = md5;
info.SizeAndChecksums.SHA1 = sha1;
@@ -112,23 +92,13 @@ namespace MPF.Core.Modules.CleanRip
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
if (File.Exists(basePath + ".bca"))
#if NET48
info.Extras.BCA = GetBCA(basePath + ".bca");
#else
info.Extras!.BCA = GetBCA(basePath + ".bca");
#endif
if (GetGameCubeWiiInformation(basePath + "-dumpinfo.txt", out Region? gcRegion, out var gcVersion, out var gcName))
{
#if NET48
info.CommonDiscInfo.Region = gcRegion ?? info.CommonDiscInfo.Region;
info.VersionAndEditions.Version = gcVersion ?? info.VersionAndEditions.Version;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalName] = gcName ?? string.Empty;
#else
info.CommonDiscInfo!.Region = gcRegion ?? info.CommonDiscInfo.Region;
info.VersionAndEditions!.Version = gcVersion ?? info.VersionAndEditions.Version;
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.InternalName] = gcName ?? string.Empty;
#endif
}
break;
@@ -137,11 +107,7 @@ namespace MPF.Core.Modules.CleanRip
// Fill in any artifacts that exist, Base64-encoded, if we need to
if (includeArtifacts)
{
#if NET48
if (info.Artifacts == null) info.Artifacts = new Dictionary<string, string>();
#else
info.Artifacts ??= new Dictionary<string, string>();
#endif
if (File.Exists(basePath + ".bca"))
info.Artifacts["bca"] = GetBase64(GetFullFile(basePath + ".bca", binary: true)) ?? string.Empty;
@@ -180,11 +146,7 @@ namespace MPF.Core.Modules.CleanRip
/// <param name="iso">Path to ISO file</param>
/// <param name="dumpinfo">Path to discinfo file</param>
/// <returns></returns>
#if NET48
private static Datafile GenerateCleanripDatafile(string iso, string dumpinfo)
#else
private static Datafile? GenerateCleanripDatafile(string iso, string dumpinfo)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(dumpinfo))
@@ -209,21 +171,12 @@ namespace MPF.Core.Modules.CleanRip
var line = sr.ReadLine()?.Trim();
if (string.IsNullOrWhiteSpace(line))
continue;
#if NET48
else if (line.StartsWith("CRC32"))
crc = line.Substring(7).ToLowerInvariant();
else if (line.StartsWith("MD5"))
md5 = line.Substring(5);
else if (line.StartsWith("SHA-1"))
sha1 = line.Substring(7);
#else
else if (line.StartsWith("CRC32"))
crc = line[7..].ToLowerInvariant();
else if (line.StartsWith("MD5"))
md5 = line[5..];
else if (line.StartsWith("SHA-1"))
sha1 = line[7..];
#endif
}
return new Datafile
@@ -254,11 +207,7 @@ namespace MPF.Core.Modules.CleanRip
/// <param name="bcaPath">Path to the BCA file associated with the dump</param>
/// <returns>BCA data as a hex string if possible, null on error</returns>
/// <remarks>https://stackoverflow.com/questions/9932096/add-separator-to-string-at-every-n-characters</remarks>
#if NET48
private static string GetBCA(string bcaPath)
#else
private static string? GetBCA(string bcaPath)
#endif
{
// If the file doesn't exist, we can't get the info
if (!File.Exists(bcaPath))
@@ -285,11 +234,7 @@ namespace MPF.Core.Modules.CleanRip
/// <param name="iso">Path to ISO file</param>
/// <param name="dumpinfo">Path to discinfo file</param>
/// <returns></returns>
#if NET48
private static string GetCleanripDatfile(string iso, string dumpinfo)
#else
private static string? GetCleanripDatfile(string iso, string dumpinfo)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(dumpinfo))
@@ -314,21 +259,12 @@ namespace MPF.Core.Modules.CleanRip
var line = sr.ReadLine()?.Trim();
if (string.IsNullOrWhiteSpace(line))
continue;
#if NET48
else if (line.StartsWith("CRC32"))
crc = line.Substring(7).ToLowerInvariant();
else if (line.StartsWith("MD5"))
md5 = line.Substring(5);
else if (line.StartsWith("SHA-1"))
sha1 = line.Substring(7);
#else
else if (line.StartsWith("CRC32"))
crc = line[7..].ToLowerInvariant();
else if (line.StartsWith("MD5"))
md5 = line[5..];
else if (line.StartsWith("SHA-1"))
sha1 = line[7..];
#endif
}
return $"<rom name=\"{Path.GetFileName(iso)}\" size=\"{size}\" crc=\"{crc}\" md5=\"{md5}\" sha1=\"{sha1}\" />";
@@ -349,11 +285,7 @@ namespace MPF.Core.Modules.CleanRip
/// <param name="version">Output internal version of the game</param>
/// <param name="name">Output internal name of the game</param>
/// <returns></returns>
#if NET48
private static bool GetGameCubeWiiInformation(string dumpinfo, out Region? region, out string version, out string name)
#else
private static bool GetGameCubeWiiInformation(string dumpinfo, out Region? region, out string? version, out string? name)
#endif
{
region = null; version = null; name = null;
@@ -379,27 +311,15 @@ namespace MPF.Core.Modules.CleanRip
}
else if (line.StartsWith("Version"))
{
#if NET48
version = line.Substring("Version: ".Length);
#else
version = line["Version: ".Length..];
#endif
}
else if (line.StartsWith("Internal Name"))
{
#if NET48
name = line.Substring("Internal Name: ".Length);
#else
name = line["Internal Name: ".Length..];
#endif
}
else if (line.StartsWith("Filename"))
{
#if NET48
string serial = line.Substring("Filename: ".Length);
#else
string serial = line["Filename: ".Length..];
#endif
// char gameType = serial[0];
// string gameid = serial[1] + serial[2];

View File

@@ -6,139 +6,67 @@ namespace MPF.Core.Modules
public class Datafile
{
[XmlElement("header")]
#if NET48
public Header Header;
#else
public Header? Header;
#endif
[XmlElement("game")]
#if NET48
public Game[] Games;
#else
public Game[]? Games;
#endif
}
public class Header
{
[XmlElement("name")]
#if NET48
public string Name;
#else
public string? Name;
#endif
[XmlElement("description")]
#if NET48
public string Description;
#else
public string? Description;
#endif
[XmlElement("version")]
#if NET48
public string Version;
#else
public string? Version;
#endif
[XmlElement("date")]
#if NET48
public string Date;
#else
public string? Date;
#endif
[XmlElement("author")]
#if NET48
public string Author;
#else
public string? Author;
#endif
[XmlElement("homepage")]
#if NET48
public string Homepage;
#else
public string? Homepage;
#endif
[XmlElement("url")]
#if NET48
public string Url;
#else
public string? Url;
#endif
}
public class Game
{
[XmlAttribute("name")]
#if NET48
public string Name;
#else
public string? Name;
#endif
[XmlElement("category")]
#if NET48
public string Category;
#else
public string? Category;
#endif
[XmlElement("description")]
#if NET48
public string Description;
#else
public string? Description;
#endif
[XmlElement("rom")]
#if NET48
public Rom[] Roms;
#else
public Rom[]? Roms;
#endif
}
public class Rom
{
[XmlAttribute("name")]
#if NET48
public string Name;
#else
public string? Name;
#endif
[XmlAttribute("size")]
#if NET48
public string Size;
#else
public string? Size;
#endif
[XmlAttribute("crc")]
#if NET48
public string Crc;
#else
public string? Crc;
#endif
[XmlAttribute("md5")]
#if NET48
public string Md5;
#else
public string? Md5;
#endif
[XmlAttribute("sha1")]
#if NET48
public string Sha1;
#else
public string? Sha1;
#endif
// TODO: Add extended hashes here
}

View File

@@ -48,11 +48,7 @@ namespace MPF.Core.Modules.DiscImageCreator
/// <param name="baseCommand">Command value to check</param>
/// <returns>MediaType if possible, null on error</returns>
/// <remarks>This takes the "safe" route by assuming the larger of any given format</remarks>
#if NET48
public static MediaType? ToMediaType(string baseCommand)
#else
public static MediaType? ToMediaType(string? baseCommand)
#endif
{
switch (baseCommand)
{
@@ -90,11 +86,7 @@ namespace MPF.Core.Modules.DiscImageCreator
/// </summary>
/// <param name="type">MediaType value to check</param>
/// <returns>Valid extension (with leading '.'), null on error</returns>
#if NET48
public static string Extension(MediaType? type)
#else
public static string? Extension(MediaType? type)
#endif
{
switch (type)
{

File diff suppressed because it is too large Load Diff

View File

@@ -11,24 +11,16 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="type">MediaType value to check</param>
/// <returns>Valid extension (with leading '.'), null on error</returns>
#if NET48
public static string Extension(MediaType? type)
#else
public static string? Extension(MediaType? type)
#endif
{
switch (type)
return type switch
{
case MediaType.CDROM:
return ".bin";
case MediaType.DVD:
case MediaType.HDDVD:
case MediaType.BluRay:
return ".iso";
case MediaType.NONE:
default:
return null;
}
MediaType.CDROM => ".bin",
MediaType.DVD
or MediaType.HDDVD
or MediaType.BluRay => ".iso",
_ => null,
};
}
#endregion

View File

@@ -20,18 +20,10 @@ namespace MPF.Core.Modules.Redumper
#region Generic Dumping Information
/// <inheritdoc/>
#if NET48
public override string InputPath => DriveValue;
#else
public override string? InputPath => DriveValue;
#endif
/// <inheritdoc/>
#if NET48
public override string OutputPath => Path.Combine(ImagePathValue?.Trim('"') ?? string.Empty, ImageNameValue?.Trim('"') ?? string.Empty) + GetDefaultExtension(this.Type);
#else
public override string? OutputPath => Path.Combine(ImagePathValue?.Trim('"') ?? string.Empty, ImageNameValue?.Trim('"') ?? string.Empty) + GetDefaultExtension(this.Type);
#endif
/// <inheritdoc/>
public override int? Speed => SpeedValue;
@@ -50,22 +42,14 @@ namespace MPF.Core.Modules.Redumper
/// <summary>
/// List of all modes being run
/// </summary>
#if NET48
public List<string> ModeValues { get; set; }
#else
public List<string>? ModeValues { get; set; }
#endif
#region General
/// <summary>
/// Drive to use, first available drive with disc, if not provided
/// </summary>
#if NET48
public string DriveValue { get; set; }
#else
public string? DriveValue { get; set; }
#endif
/// <summary>
/// Drive read speed, optimal drive speed will be used if not provided
@@ -80,20 +64,12 @@ namespace MPF.Core.Modules.Redumper
/// <summary>
/// Dump files base directory
/// </summary>
#if NET48
public string ImagePathValue { get; set; }
#else
public string? ImagePathValue { get; set; }
#endif
/// <summary>
/// Dump files prefix, autogenerated in dump mode, if not provided
/// </summary>
#if NET48
public string ImageNameValue { get; set; }
#else
public string? ImageNameValue { get; set; }
#endif
#endregion
@@ -102,11 +78,7 @@ namespace MPF.Core.Modules.Redumper
/// <summary>
/// Override drive type, possible values: GENERIC, PLEXTOR, LG_ASUS
/// </summary>
#if NET48
public string DriveTypeValue { get; set; }
#else
public string? DriveTypeValue { get; set; }
#endif
/// <summary>
/// Override drive read offset
@@ -126,20 +98,12 @@ namespace MPF.Core.Modules.Redumper
/// <summary>
/// Override drive read method, possible values: BE, D8, BE_CDDA
/// </summary>
#if NET48
public string DriveReadMethodValue { get; set; }
#else
public string? DriveReadMethodValue { get; set; }
#endif
/// <summary>
/// Override drive sector order, possible values: DATA_C2_SUB, DATA_SUB_C2
/// </summary>
#if NET48
public string DriveSectorOrderValue { get; set; }
#else
public string? DriveSectorOrderValue { get; set; }
#endif
#endregion
@@ -181,11 +145,7 @@ namespace MPF.Core.Modules.Redumper
/// <summary>
/// LBA ranges of sectors to skip
/// </summary>
#if NET48
public string SkipValue { get; set; }
#else
public string? SkipValue { get; set; }
#endif
/// <summary>
/// Number of sectors to read at once on initial dump, DVD only (Default 32)
@@ -202,18 +162,10 @@ namespace MPF.Core.Modules.Redumper
#endregion
/// <inheritdoc/>
#if NET48
public Parameters(string parameters) : base(parameters) { }
#else
public Parameters(string? parameters) : base(parameters) { }
#endif
/// <inheritdoc/>
#if NET48
public Parameters(RedumpSystem? system, MediaType? type, string drivePath, string filename, int? driveSpeed, Options options)
#else
public Parameters(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Options options)
#endif
: base(system, type, drivePath, filename, driveSpeed, options)
{
}
@@ -300,21 +252,13 @@ namespace MPF.Core.Modules.Redumper
}
/// <inheritdoc/>
#if NET48
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive drive, bool includeArtifacts)
#else
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive? drive, bool includeArtifacts)
#endif
{
// Ensure that required sections exist
info = SubmissionInfoTool.EnsureAllSections(info);
// Get the dumping program and version
#if NET48
info.DumpingInfo.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {GetVersion($"{basePath}.log") ?? "Unknown Version"}";
#else
info.DumpingInfo!.DumpingProgram = $"{EnumConverter.LongName(this.InternalProgram)} {GetVersion($"{basePath}.log") ?? "Unknown Version"}";
#endif
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate($"{basePath}.log")?.ToString("yyyy-MM-dd HH:mm:ss");
// Fill in the hardware data
@@ -332,22 +276,13 @@ namespace MPF.Core.Modules.Redumper
switch (this.Type)
{
case MediaType.CDROM:
#if NET48
info.Extras.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD";
info.TracksAndWriteOffsets.ClrMameProData = GetDatfile($"{basePath}.log");
#else
info.Extras!.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD";
info.TracksAndWriteOffsets!.ClrMameProData = GetDatfile($"{basePath}.log");
#endif
info.TracksAndWriteOffsets.Cuesheet = GetFullFile($"{basePath}.cue") ?? string.Empty;
// Attempt to get the write offset
string cdWriteOffset = GetWriteOffset($"{basePath}.log") ?? string.Empty;
#if NET48
info.CommonDiscInfo.RingWriteOffset = cdWriteOffset;
#else
info.CommonDiscInfo!.RingWriteOffset = cdWriteOffset;
#endif
info.TracksAndWriteOffsets.OtherWriteOffsets = cdWriteOffset;
// Attempt to get the error count
@@ -357,32 +292,20 @@ namespace MPF.Core.Modules.Redumper
// Attempt to get multisession data
string cdMultiSessionInfo = GetMultisessionInformation($"{basePath}.log") ?? string.Empty;
if (!string.IsNullOrWhiteSpace(cdMultiSessionInfo))
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.Multisession] = cdMultiSessionInfo;
#else
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.Multisession] = cdMultiSessionInfo;
#endif
// Attempt to get the universal hash, if it's an audio disc
if (this.System.IsAudio())
{
string universalHash = GetUniversalHash($"{basePath}.log") ?? string.Empty;
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.UniversalHash] = universalHash;
#else
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.UniversalHash] = universalHash;
#endif
}
// Attempt to get the non-zero data start, if it's an audio disc
if (this.System.IsAudio())
{
string ringNonZeroDataStart = GetRingNonZeroDataStart($"{basePath}.log") ?? string.Empty;
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.RingNonZeroDataStart] = ringNonZeroDataStart;
#else
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.RingNonZeroDataStart] = ringNonZeroDataStart;
#endif
}
break;
@@ -390,22 +313,13 @@ namespace MPF.Core.Modules.Redumper
case MediaType.DVD:
case MediaType.HDDVD:
case MediaType.BluRay:
#if NET48
info.Extras.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD";
info.TracksAndWriteOffsets.ClrMameProData = GetDatfile($"{basePath}.log");
#else
info.Extras!.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD";
info.TracksAndWriteOffsets!.ClrMameProData = GetDatfile($"{basePath}.log");
#endif
// Get the individual hash data, as per internal
if (InfoTool.GetISOHashValues(info.TracksAndWriteOffsets.ClrMameProData, out long size, out var crc32, out var md5, out var sha1))
{
#if NET48
info.SizeAndChecksums.Size = size;
#else
info.SizeAndChecksums!.Size = size;
#endif
info.SizeAndChecksums.CRC32 = crc32;
info.SizeAndChecksums.MD5 = md5;
info.SizeAndChecksums.SHA1 = sha1;
@@ -414,15 +328,9 @@ namespace MPF.Core.Modules.Redumper
// Deal with the layerbreaks
if (GetLayerbreaks($"{basePath}.log", out var layerbreak1, out var layerbreak2, out var layerbreak3))
{
#if NET48
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;
#else
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;
#endif
}
// Bluray-specific options
@@ -438,11 +346,7 @@ namespace MPF.Core.Modules.Redumper
break;
}
#if NET48
info.Extras.PIC = GetPIC($"{basePath}.physical", trimLength) ?? string.Empty;
#else
info.Extras!.PIC = GetPIC($"{basePath}.physical", trimLength) ?? string.Empty;
#endif
}
break;
@@ -455,40 +359,24 @@ namespace MPF.Core.Modules.Redumper
case RedumpSystem.IBMPCcompatible:
case RedumpSystem.RainbowDisc:
case RedumpSystem.SonyElectronicBook:
#if NET48
info.CopyProtection.SecuROMData = GetSecuROMData($"{basePath}.log") ?? string.Empty;
#else
info.CopyProtection!.SecuROMData = GetSecuROMData($"{basePath}.log") ?? string.Empty;
#endif
break;
case RedumpSystem.DVDAudio:
case RedumpSystem.DVDVideo:
#if NET48
info.CopyProtection.Protection = GetDVDProtection($"{basePath}.log") ?? string.Empty;
#else
info.CopyProtection!.Protection = GetDVDProtection($"{basePath}.log") ?? string.Empty;
#endif
break;
case RedumpSystem.KonamiPython2:
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var pythonTwoSerial, out Region? pythonTwoRegion, out var pythonTwoDate))
{
// Ensure internal serial is pulled from local data
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? pythonTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = pythonTwoDate;
}
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#endif
break;
case RedumpSystem.MicrosoftXbox:
@@ -504,13 +392,8 @@ namespace MPF.Core.Modules.Redumper
break;
case RedumpSystem.SegaMegaCDSegaCD:
#if NET48
info.Extras.Header = GetSegaCDHeader($"{basePath}.log", out var scdBuildDate, out var scdSerial, out _) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = scdSerial ?? string.Empty;
#else
info.Extras!.Header = GetSegaCDHeader($"{basePath}.log", out var scdBuildDate, out var scdSerial, out _) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = scdSerial ?? string.Empty;
#endif
info.CommonDiscInfo.EXEDateBuildDate = scdBuildDate ?? string.Empty;
// TODO: Support region setting from parsed value
break;
@@ -532,11 +415,7 @@ namespace MPF.Core.Modules.Redumper
break;
case RedumpSystem.SegaSaturn:
#if NET48
info.Extras.Header = GetSaturnHeader($"{basePath}.log") ?? string.Empty;
#else
info.Extras!.Header = GetSaturnHeader($"{basePath}.log") ?? string.Empty;
#endif
// Take only the first 16 lines for Saturn
if (!string.IsNullOrEmpty(info.Extras.Header))
@@ -545,13 +424,8 @@ namespace MPF.Core.Modules.Redumper
if (GetSaturnBuildInfo(info.Extras.Header, out var saturnSerial, out var saturnVersion, out var buildDate))
{
// Ensure internal serial is pulled from local data
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = saturnSerial ?? string.Empty;
info.VersionAndEditions.Version = saturnVersion ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = saturnSerial ?? string.Empty;
info.VersionAndEditions!.Version = saturnVersion ?? string.Empty;
#endif
info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty;
}
@@ -561,22 +435,13 @@ namespace MPF.Core.Modules.Redumper
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var playstationSerial, out Region? playstationRegion, out var playstationDate))
{
// Ensure internal serial is pulled from local data
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationSerial ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationSerial ?? string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationDate;
}
#if NET48
info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}.log").ToYesNo();
info.EDC.EDC = GetPlayStationEDCStatus($"{basePath}.log").ToYesNo();
#else
info.CopyProtection!.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}.log").ToYesNo();
info.EDC!.EDC = GetPlayStationEDCStatus($"{basePath}.log").ToYesNo();
#endif
info.CopyProtection.LibCrypt = GetPlayStationLibCryptStatus($"{basePath}.log").ToYesNo();
info.CopyProtection.LibCryptData = GetPlayStationLibCryptData($"{basePath}.log");
break;
@@ -585,67 +450,37 @@ namespace MPF.Core.Modules.Redumper
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var playstationTwoSerial, out Region? playstationTwoRegion, out var playstationTwoDate))
{
// Ensure internal serial is pulled from local data
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationTwoDate;
}
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
#endif
break;
case RedumpSystem.SonyPlayStation3:
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
string firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
if (firmwareVersion != null)
info.CommonDiscInfo.ContentsSpecialFields[SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
string? firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
if (firmwareVersion != null)
info.CommonDiscInfo!.ContentsSpecialFields![SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#endif
break;
case RedumpSystem.SonyPlayStation4:
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation4Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation4Serial(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation4Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation4Serial(drive?.Name) ?? string.Empty;
#endif
break;
case RedumpSystem.SonyPlayStation5:
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation5Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation5Serial(drive?.Name) ?? string.Empty;
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation5Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation5Serial(drive?.Name) ?? string.Empty;
#endif
break;
}
// Fill in any artifacts that exist, Base64-encoded, if we need to
if (includeArtifacts)
{
#if NET48
if (info.Artifacts == null) info.Artifacts = new Dictionary<string, string>();
#else
info.Artifacts ??= new Dictionary<string, string>();
#endif
if (File.Exists($"{basePath}.cdtext"))
info.Artifacts["cdtext"] = GetBase64(GetFullFile($"{basePath}.cdtext")) ?? string.Empty;
@@ -690,12 +525,7 @@ namespace MPF.Core.Modules.Redumper
{
var parameters = new List<string>();
#if NET48
if (ModeValues == null)
ModeValues = new List<string> { CommandStrings.NONE };
#else
ModeValues ??= new List<string> { CommandStrings.NONE };
#endif
// Modes
parameters.AddRange(ModeValues);
@@ -974,11 +804,7 @@ namespace MPF.Core.Modules.Redumper
}
/// <inheritdoc/>
#if NET48
public override string GetDefaultExtension(MediaType? mediaType) => Converters.Extension(mediaType);
#else
public override string? GetDefaultExtension(MediaType? mediaType) => Converters.Extension(mediaType);
#endif
/// <inheritdoc/>
public override List<string> GetDeleteableFilePaths(string basePath)
@@ -1094,11 +920,7 @@ namespace MPF.Core.Modules.Redumper
}
/// <inheritdoc/>
#if NET48
protected override void SetDefaultParameters(string drivePath, string filename, int? driveSpeed, Options options)
#else
protected override void SetDefaultParameters(string? drivePath, string filename, int? driveSpeed, Options options)
#endif
{
// If we don't have a CD, DVD, HD-DVD, or BD, we can't dump using redumper
if (this.Type != MediaType.CDROM
@@ -1113,23 +935,11 @@ namespace MPF.Core.Modules.Redumper
switch (this.Type)
{
case MediaType.CDROM:
#if NET48
switch (this.System)
{
case RedumpSystem.SuperAudioCD:
ModeValues = new List<string> { CommandStrings.SACD };
break;
default:
ModeValues = new List<string> { CommandStrings.CD };
break;
}
#else
ModeValues = this.System switch
{
RedumpSystem.SuperAudioCD => new List<string> { CommandStrings.SACD },
_ => new List<string> { CommandStrings.CD },
};
#endif
break;
case MediaType.DVD:
ModeValues = new List<string> { CommandStrings.DVD };
@@ -1190,11 +1000,7 @@ namespace MPF.Core.Modules.Redumper
}
/// <inheritdoc/>
#if NET48
protected override bool ValidateAndSetParameters(string parameters)
#else
protected override bool ValidateAndSetParameters(string? parameters)
#endif
{
BaseCommand = CommandStrings.NONE;
@@ -1262,11 +1068,7 @@ namespace MPF.Core.Modules.Redumper
// Flag read-out values
byte? byteValue = null;
int? intValue = null;
#if NET48
string stringValue = null;
#else
string? stringValue = null;
#endif
#region General
@@ -1446,11 +1248,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Newline-delimited cuesheet if possible, null on error</returns>
#if NET48
private static string GetCuesheet(string log)
#else
private static string? GetCuesheet(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -1466,11 +1264,7 @@ namespace MPF.Core.Modules.Redumper
return null;
// Now that we're at the relevant entries, read each line in and concatenate
#if NET48
string cueString = string.Empty, line = sr.ReadLine()?.Trim();
#else
string? cueString = string.Empty, line = sr.ReadLine()?.Trim();
#endif
while (!string.IsNullOrWhiteSpace(line))
{
cueString += line + "\n";
@@ -1492,11 +1286,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Newline-delimited datfile if possible, null on error</returns>
#if NET48
private static string GetDatfile(string log)
#else
private static string? GetDatfile(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -1538,11 +1328,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="drive">_disc.txt file location</param>
/// <returns>True if disc type info was set, false otherwise</returns>
#if NET48
private static bool GetDiscType(string drive, out string discTypeOrBookType)
#else
private static bool GetDiscType(string drive, out string? discTypeOrBookType)
#endif
{
// Set the default values
discTypeOrBookType = null;
@@ -1565,11 +1351,7 @@ namespace MPF.Core.Modules.Redumper
if (line.StartsWith("current profile:"))
{
// current profile: <discType>
#if NET48
discTypeOrBookType = line.Substring("current profile: ".Length);
#else
discTypeOrBookType = line["current profile: ".Length..];
#endif
}
line = sr.ReadLine();
@@ -1591,22 +1373,14 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Formatted string representing the DVD protection, null on error</returns>
#if NET48
private static string GetDVDProtection(string log)
#else
private static string? GetDVDProtection(string log)
#endif
{
// If one of the files doesn't exist, we can't get info from them
if (!File.Exists(log))
return null;
// Setup all of the individual pieces
#if NET48
string region = null, rceProtection = null, copyrightProtectionSystemType = null, vobKeys = null, decryptedDiscKey = null;
#else
string? region = null, rceProtection = null, copyrightProtectionSystemType = null, vobKeys = null, decryptedDiscKey = null;
#endif
using (var sr = File.OpenText(log))
{
try
@@ -1620,29 +1394,17 @@ namespace MPF.Core.Modules.Redumper
{
if (line.StartsWith("protection system type"))
{
#if NET48
copyrightProtectionSystemType = line.Substring("protection system type: ".Length);
#else
copyrightProtectionSystemType = line["protection system type: ".Length..];
#endif
if (copyrightProtectionSystemType == "none" || copyrightProtectionSystemType == "<none>")
copyrightProtectionSystemType = "No";
}
else if (line.StartsWith("region management information:"))
{
#if NET48
region = line.Substring("region management information: ".Length);
#else
region = line["region management information: ".Length..];
#endif
}
else if (line.StartsWith("disc key"))
{
#if NET48
decryptedDiscKey = line.Substring("disc key: ".Length).Replace(':', ' ');
#else
decryptedDiscKey = line["disc key: ".Length..].Replace(':', ' ');
#endif
}
else if (line.StartsWith("title keys"))
{
@@ -1749,11 +1511,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>True if hardware info was set, false otherwise</returns>
#if NET48
private static bool GetHardwareInfo(string log, out string manufacturer, out string model, out string firmware)
#else
private static bool GetHardwareInfo(string log, out string? manufacturer, out string? model, out string? firmware)
#endif
{
// Set the default values
manufacturer = null; model = null; firmware = null;
@@ -1773,11 +1531,7 @@ namespace MPF.Core.Modules.Redumper
// drive: <vendor_id> - <product_id> (revision level: <product_revision_level>, vendor specific: <vendor_specific>)
var regex = new Regex(@"drive: (.+) - (.+) \(revision level: (.+), vendor specific: (.+)\)", RegexOptions.Compiled);
#if NET48
string line;
#else
string? line;
#endif
while ((line = sr.ReadLine()) != null)
{
var match = regex.Match(line.Trim());
@@ -1807,11 +1561,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>True if any layerbreaks were found, false otherwise</returns>
#if NET48
private static bool GetLayerbreaks(string log, out string layerbreak1, out string layerbreak2, out string layerbreak3)
#else
private static bool GetLayerbreaks(string log, out string? layerbreak1, out string? layerbreak2, out string? layerbreak3)
#endif
{
// Set the default values
layerbreak1 = null; layerbreak2 = null; layerbreak3 = null;
@@ -1844,51 +1594,31 @@ namespace MPF.Core.Modules.Redumper
{
// data { LBA: <startLBA> .. <endLBA>, length: <length>, hLBA: <startLBA> .. <endLBA> }
string[] split = line.Split(' ').Where(s => !string.IsNullOrEmpty(s)).ToArray();
#if NET48
layerbreak1 = layerbreak1 ?? split[7].TrimEnd(',');
#else
layerbreak1 ??= split[7].TrimEnd(',');
#endif
}
// Dual-layer discs have a regular layerbreak (new)
else if (line.StartsWith("layer break:"))
{
// layer break: <layerbreak>
#if NET48
layerbreak1 = line.Substring("layer break: ".Length).Trim();
#else
layerbreak1 = line["layer break: ".Length..].Trim();
#endif
}
// Multi-layer discs have the layer in the name
else if (line.StartsWith("layer break (layer: 0):"))
{
// layer break (layer: 0): <layerbreak>
#if NET48
layerbreak1 = line.Substring("layer break (layer: 0): ".Length).Trim();
#else
layerbreak1 = line["layer break (layer: 0): ".Length..].Trim();
#endif
}
else if (line.StartsWith("layer break (layer: 1):"))
{
// layer break (layer: 1): <layerbreak>
#if NET48
layerbreak2 = line.Substring("layer break (layer: 1): ".Length).Trim();
#else
layerbreak2 = line["layer break (layer: 1): ".Length..].Trim();
#endif
}
else if (line.StartsWith("layer break (layer: 2):"))
{
// layer break (layer: 2): <layerbreak>
#if NET48
layerbreak3 = line.Substring("layer break (layer: 2): ".Length).Trim();
#else
layerbreak3 = line["layer break (layer: 2): ".Length..].Trim();
#endif
}
}
@@ -1908,11 +1638,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Formatted multisession information, null on error</returns>
#if NET48
private static string GetMultisessionInformation(string log)
#else
private static string? GetMultisessionInformation(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -1928,11 +1654,7 @@ namespace MPF.Core.Modules.Redumper
return null;
// Now that we're at the relevant lines, find the session info
#if NET48
string firstSession = null, secondSession = null;
#else
string? firstSession = null, secondSession = null;
#endif
while (!sr.EndOfStream)
{
var line = sr.ReadLine()?.Trim();
@@ -1943,19 +1665,11 @@ namespace MPF.Core.Modules.Redumper
// Store the first session range
if (line.Contains("session 1:"))
#if NET48
firstSession = line.Substring("session 1: ".Length).Trim();
#else
firstSession = line["session 1: ".Length..].Trim();
#endif
// Store the secomd session range
else if (line.Contains("session 2:"))
#if NET48
secondSession = line.Substring("session 2: ".Length).Trim();
#else
secondSession = line["session 2: ".Length..].Trim();
#endif
}
// If either is blank, we don't have multisession
@@ -2058,11 +1772,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>PS1 LibCrypt data, if possible</returns>
#if NET48
private static string GetPlayStationLibCryptData(string log)
#else
private static string? GetPlayStationLibCryptData(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -2078,11 +1788,7 @@ namespace MPF.Core.Modules.Redumper
return null;
// Now that we're at the relevant entries, read each line in and concatenate
#if NET48
string libCryptString = "", line = sr.ReadLine()?.Trim();
#else
string? libCryptString = "", line = sr.ReadLine()?.Trim();
#endif
while (line?.StartsWith("MSF:") == true)
{
libCryptString += line + "\n";
@@ -2144,11 +1850,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Newline-delimited PVD if possible, null on error</returns>
#if NET48
private static string GetPVD(string log)
#else
private static string? GetPVD(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -2164,11 +1866,7 @@ namespace MPF.Core.Modules.Redumper
return null;
// Now that we're at the relevant entries, read each line in and concatenate
#if NET48
string pvdString = "", line = sr.ReadLine()?.Trim();
#else
string? pvdString = "", line = sr.ReadLine()?.Trim();
#endif
while (line?.StartsWith("03") == true)
{
pvdString += line + "\n";
@@ -2190,11 +1888,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Non-zero dta start if possible, null on error</returns>
#if NET48
private static string GetRingNonZeroDataStart(string log)
#else
private static string? GetRingNonZeroDataStart(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -2205,20 +1899,12 @@ namespace MPF.Core.Modules.Redumper
try
{
// If we find the sample range, return the start value only
#if NET48
string line;
#else
string? line;
#endif
while (!sr.EndOfStream)
{
line = sr.ReadLine()?.TrimStart();
if (line?.StartsWith("non-zero data sample range") == true)
#if NET48
return line.Substring("non-zero data sample range: [".Length).Trim().Split(' ')[0];
#else
return line["non-zero data sample range: [".Length..].Trim().Split(' ')[0];
#endif
}
// We couldn't detect it then
@@ -2238,11 +1924,7 @@ namespace MPF.Core.Modules.Redumper
/// <<param name="segaHeader">String representing a formatter variant of the Saturn header</param>
/// <returns>True on successful extraction of info, false otherwise</returns>
/// TODO: Remove when Redumper gets native reading support
#if NET48
private static bool GetSaturnBuildInfo(string segaHeader, out string serial, out string version, out string date)
#else
private static bool GetSaturnBuildInfo(string? segaHeader, out string? serial, out string? version, out string? date)
#endif
{
serial = null; version = null; date = null;
@@ -2254,19 +1936,11 @@ namespace MPF.Core.Modules.Redumper
try
{
string[] header = segaHeader.Split('\n');
#if NET48
string serialVersionLine = header[2].Substring(58);
string dateLine = header[3].Substring(58);
serial = serialVersionLine.Substring(0, 10).Trim();
version = serialVersionLine.Substring(10, 6).TrimStart('V', 'v');
date = dateLine.Substring(0, 8);
#else
string serialVersionLine = header[2][58..];
string dateLine = header[3][58..];
serial = serialVersionLine[..10].Trim();
version = serialVersionLine.Substring(10, 6).TrimStart('V', 'v');
date = dateLine[..8];
#endif
date = $"{date[0]}{date[1]}{date[2]}{date[3]}-{date[4]}{date[5]}-{date[6]}{date[7]}";
return true;
}
@@ -2282,11 +1956,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Header as a byte array if possible, null on error</returns>
#if NET48
private static string GetSaturnHeader(string log)
#else
private static string? GetSaturnHeader(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -2301,11 +1971,7 @@ namespace MPF.Core.Modules.Redumper
if (sr.EndOfStream)
return null;
#if NET48
string line, headerString = "";
#else
string? line, headerString = "";
#endif
while (!sr.EndOfStream)
{
line = sr.ReadLine()?.TrimStart();
@@ -2339,11 +2005,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Header as a byte array if possible, null on error</returns>
#if NET48
private static string GetSecuROMData(string log)
#else
private static string? GetSecuROMData(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -2389,11 +2051,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Header as a byte array if possible, null on error</returns>
#if NET48
private static string GetSegaCDHeader(string log, out string buildDate, out string serial, out string region)
#else
private static string? GetSegaCDHeader(string log, out string? buildDate, out string? serial, out string? region)
#endif
{
// Set the default values
buildDate = null; serial = null; region = null;
@@ -2411,11 +2069,7 @@ namespace MPF.Core.Modules.Redumper
if (sr.EndOfStream)
return null;
#if NET48
string line, headerString = string.Empty;
#else
string? line, headerString = string.Empty;
#endif
while (!sr.EndOfStream)
{
line = sr.ReadLine()?.TrimStart();
@@ -2424,35 +2078,19 @@ namespace MPF.Core.Modules.Redumper
if (line.StartsWith("build date:"))
{
#if NET48
buildDate = line.Substring("build date: ".Length).Trim();
#else
buildDate = line["build date: ".Length..].Trim();
#endif
}
else if (line.StartsWith("serial:"))
{
#if NET48
serial = line.Substring("serial: ".Length).Trim();
#else
serial = line["serial: ".Length..].Trim();
#endif
}
else if (line.StartsWith("region:"))
{
#if NET48
region = line.Substring("region: ".Length).Trim();
#else
region = line["region: ".Length..].Trim();
#endif
}
else if (line.StartsWith("regions:"))
{
#if NET48
region = line.Substring("regions: ".Length).Trim();
#else
region = line["regions: ".Length..].Trim();
#endif
}
else if (line.StartsWith("header:"))
{
@@ -2484,11 +2122,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Universal hash if possible, null on error</returns>
#if NET48
private static string GetUniversalHash(string log)
#else
private static string? GetUniversalHash(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -2499,20 +2133,12 @@ namespace MPF.Core.Modules.Redumper
try
{
// If we find the universal hash line, return the hash only
#if NET48
string line;
#else
string? line;
#endif
while (!sr.EndOfStream)
{
line = sr.ReadLine()?.TrimStart();
if (line?.StartsWith("Universal Hash") == true)
#if NET48
return line.Substring("Universal Hash (SHA-1): ".Length).Trim();
#else
return line["Universal Hash (SHA-1): ".Length..].Trim();
#endif
}
// We couldn't detect it then
@@ -2531,11 +2157,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Sample write offset if possible, null on error</returns>
#if NET48
private static string GetWriteOffset(string log)
#else
private static string? GetWriteOffset(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
@@ -2546,20 +2168,12 @@ namespace MPF.Core.Modules.Redumper
try
{
// If we find the disc write offset line, return the offset
#if NET48
string line;
#else
string? line;
#endif
while (!sr.EndOfStream)
{
line = sr.ReadLine()?.TrimStart();
if (line?.StartsWith("disc write offset") == true)
#if NET48
return line.Substring("disc write offset: ".Length).Trim();
#else
return line["disc write offset: ".Length..].Trim();
#endif
}
// We couldn't detect it then
@@ -2578,11 +2192,7 @@ namespace MPF.Core.Modules.Redumper
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Version if possible, null on error</returns>
#if NET48
private static string GetVersion(string log)
#else
private static string? GetVersion(string log)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))

View File

@@ -22,18 +22,10 @@ namespace MPF.Core.Modules.UmdImageCreator
#endregion
/// <inheritdoc/>
#if NET48
public Parameters(string parameters) : base(parameters) { }
#else
public Parameters(string? parameters) : base(parameters) { }
#endif
/// <inheritdoc/>
#if NET48
public Parameters(RedumpSystem? system, MediaType? type, string drivePath, string filename, int? driveSpeed, Options options)
#else
public Parameters(RedumpSystem? system, MediaType? type, string? drivePath, string filename, int? driveSpeed, Options options)
#endif
: base(system, type, drivePath, filename, driveSpeed, options)
{
}
@@ -70,40 +62,24 @@ namespace MPF.Core.Modules.UmdImageCreator
}
/// <inheritdoc/>
#if NET48
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive drive, bool includeArtifacts)
#else
public override void GenerateSubmissionInfo(SubmissionInfo info, Options options, string basePath, Drive? drive, bool includeArtifacts)
#endif
{
// Ensure that required sections exist
info = SubmissionInfoTool.EnsureAllSections(info);
// TODO: Determine if there's a UMDImageCreator version anywhere
#if NET48
info.DumpingInfo.DumpingProgram = EnumConverter.LongName(this.InternalProgram);
#else
info.DumpingInfo!.DumpingProgram = EnumConverter.LongName(this.InternalProgram);
#endif
info.DumpingInfo.DumpingDate = InfoTool.GetFileModifiedDate(basePath + "_disc.txt")?.ToString("yyyy-MM-dd HH:mm:ss");
// Extract info based generically on MediaType
switch (this.Type)
{
case MediaType.UMD:
#if NET48
info.Extras.PVD = GetPVD(basePath + "_mainInfo.txt") ?? string.Empty;
#else
info.Extras!.PVD = GetPVD(basePath + "_mainInfo.txt") ?? string.Empty;
#endif
if (Hasher.GetFileHashes(basePath + ".iso", out long filesize, out var crc32, out var md5, out var sha1))
{
#if NET48
info.SizeAndChecksums.Size = filesize;
#else
info.SizeAndChecksums!.Size = filesize;
#endif
info.SizeAndChecksums.CRC32 = crc32;
info.SizeAndChecksums.MD5 = md5;
info.SizeAndChecksums.SHA1 = sha1;
@@ -111,17 +87,10 @@ namespace MPF.Core.Modules.UmdImageCreator
if (GetUMDAuxInfo(basePath + "_disc.txt", out var title, out DiscCategory? umdcat, out var umdversion, out var umdlayer, out long umdsize))
{
#if NET48
info.CommonDiscInfo.Title = title ?? string.Empty;
info.CommonDiscInfo.Category = umdcat ?? DiscCategory.Games;
info.VersionAndEditions.Version = umdversion ?? string.Empty;
info.SizeAndChecksums.Size = umdsize;
#else
info.CommonDiscInfo!.Title = title ?? string.Empty;
info.CommonDiscInfo.Category = umdcat ?? DiscCategory.Games;
info.VersionAndEditions!.Version = umdversion ?? string.Empty;
info.SizeAndChecksums!.Size = umdsize;
#endif
if (!string.IsNullOrWhiteSpace(umdlayer))
info.SizeAndChecksums.Layerbreak = Int64.Parse(umdlayer ?? "-1");
@@ -133,11 +102,7 @@ namespace MPF.Core.Modules.UmdImageCreator
// Fill in any artifacts that exist, Base64-encoded, if we need to
if (includeArtifacts)
{
#if NET48
if (info.Artifacts == null) info.Artifacts = new Dictionary<string, string>();
#else
info.Artifacts ??= new Dictionary<string, string>();
#endif
if (File.Exists(basePath + "_disc.txt"))
info.Artifacts["disc"] = GetBase64(GetFullFile(basePath + "_disc.txt")) ?? string.Empty;
@@ -185,11 +150,7 @@ namespace MPF.Core.Modules.UmdImageCreator
/// </summary>
/// <param name="mainInfo">_mainInfo.txt file location</param>
/// <returns>Newline-deliminated PVD if possible, null on error</returns>
#if NET48
private static string GetPVD(string mainInfo)
#else
private static string? GetPVD(string mainInfo)
#endif
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(mainInfo))
@@ -225,11 +186,7 @@ namespace MPF.Core.Modules.UmdImageCreator
/// </summary>
/// <param name="disc">_disc.txt file location</param>
/// <returns>True on successful extraction of info, false otherwise</returns>
#if NET48
private static bool GetUMDAuxInfo(string disc, out string title, out DiscCategory? umdcat, out string umdversion, out string umdlayer, out long umdsize)
#else
private static bool GetUMDAuxInfo(string disc, out string? title, out DiscCategory? umdcat, out string? umdversion, out string? umdlayer, out long umdsize)
#endif
{
title = null; umdcat = null; umdversion = null; umdlayer = null; umdsize = -1;
@@ -250,11 +207,7 @@ namespace MPF.Core.Modules.UmdImageCreator
break;
if (line.StartsWith("TITLE") && title == null)
#if NET48
title = line.Substring("TITLE: ".Length);
#else
title = line["TITLE: ".Length..];
#endif
else if (line.StartsWith("DISC_VERSION") && umdversion == null)
umdversion = line.Split(' ')[1];
else if (line.StartsWith("pspUmdTypes"))

View File

@@ -19,11 +19,7 @@ namespace MPF.Core
/// <param name="options">Options object that determines what to scan</param>
/// <param name="progress">Optional progress callback</param>
/// <returns>Set of all detected copy protections with an optional error string</returns>
#if NET48
public static async Task<(Dictionary<string, List<string>>, string)> RunProtectionScanOnPath(string path, Data.Options options, IProgress<ProtectionProgress> progress = null)
#else
public static async Task<(Dictionary<string, List<string>>?, string?)> RunProtectionScanOnPath(string path, Data.Options options, IProgress<ProtectionProgress>? progress = null)
#endif
{
try
{
@@ -66,11 +62,7 @@ namespace MPF.Core
/// </summary>
/// <param name="protections">Dictionary of file to list of protection mappings</param>
/// <returns>Detected protections, if any</returns>
#if NET48
public static string FormatProtections(Dictionary<string, List<string>> protections)
#else
public static string? FormatProtections(Dictionary<string, List<string>>? protections)
#endif
{
// If the filtered list is empty in some way, return
if (protections == null || !protections.Any())
@@ -95,11 +87,7 @@ namespace MPF.Core
/// </summary>
/// <param name="path">Path to scan for anti-modchip strings</param>
/// <returns>Anti-modchip existence if possible, false on error</returns>
#if NET48
public static async Task<bool> GetPlayStationAntiModchipDetected(string path)
#else
public static async Task<bool> GetPlayStationAntiModchipDetected(string? path)
#endif
{
// If there is no valid path
if (string.IsNullOrEmpty(path))

View File

@@ -30,11 +30,7 @@ namespace MPF.Core
/// </summary>
/// <param name="path">Path to the SubmissionInfo JSON</param>
/// <returns>Filled SubmissionInfo on success, null on error</returns>
#if NET48
public static SubmissionInfo CreateFromFile(string path)
#else
public static SubmissionInfo? CreateFromFile(string? path)
#endif
{
// If the path is invalid
if (string.IsNullOrWhiteSpace(path))
@@ -64,11 +60,7 @@ namespace MPF.Core
/// <param name="discData">String containing the HTML disc data</param>
/// <returns>Filled SubmissionInfo object on success, null on error</returns>
/// <remarks>Not currently working</remarks>
#if NET48
public static SubmissionInfo CreateFromID(string discData)
#else
private static SubmissionInfo? CreateFromID(string discData)
#endif
{
var info = new SubmissionInfo()
{
@@ -96,11 +88,7 @@ namespace MPF.Core
return null;
// Loop through and get the main node, if possible
#if NET48
XmlNode mainNode = null;
#else
XmlNode? mainNode = null;
#endif
foreach (XmlNode tempNode in bodyNode.ChildNodes)
{
// We only care about div elements
@@ -251,29 +239,6 @@ namespace MPF.Core
/// Ensure all required sections in a submission info exist
/// </summary>
/// <param name="info">SubmissionInfo object to verify</param>
#if NET48
public static SubmissionInfo EnsureAllSections(SubmissionInfo info)
{
// If there's no info, create one
if (info == null) info = new SubmissionInfo();
// Ensure all sections
if (info.CommonDiscInfo == null) info.CommonDiscInfo = new CommonDiscInfoSection();
if (info.VersionAndEditions == null) info.VersionAndEditions = new VersionAndEditionsSection();
if (info.EDC == null) info.EDC = new EDCSection();
if (info.Extras == null) info.Extras = new ExtrasSection();
if (info.CopyProtection == null) info.CopyProtection = new CopyProtectionSection();
if (info.TracksAndWriteOffsets == null) info.TracksAndWriteOffsets = new TracksAndWriteOffsetsSection();
if (info.SizeAndChecksums == null) info.SizeAndChecksums = new SizeAndChecksumsSection();
if (info.DumpingInfo == null) info.DumpingInfo = new DumpingInfoSection();
// Ensure special dictionaries
if (info.CommonDiscInfo.CommentsSpecialFields == null) info.CommonDiscInfo.CommentsSpecialFields = new Dictionary<SiteCode?, string>();
if (info.CommonDiscInfo.ContentsSpecialFields == null) info.CommonDiscInfo.ContentsSpecialFields = new Dictionary<SiteCode?, string>();
return info;
}
#else
public static SubmissionInfo EnsureAllSections(SubmissionInfo? info)
{
// If there's no info, create one
@@ -297,7 +262,6 @@ namespace MPF.Core
return info;
}
#endif
#endregion
@@ -315,29 +279,15 @@ namespace MPF.Core
/// <param name="resultProgress">Optional result progress callback</param>
/// <param name="protectionProgress">Optional protection progress callback</param>
/// <returns>SubmissionInfo populated based on outputs, null on error</returns>
#if NET48
public static async Task<SubmissionInfo> ExtractOutputInformation(
#else
public static async Task<SubmissionInfo?> ExtractOutputInformation(
#endif
string outputPath,
#if NET48
Drive drive,
#else
Drive? drive,
#endif
RedumpSystem? system,
MediaType? mediaType,
Data.Options options,
#if NET48
BaseParameters parameters,
IProgress<Result> resultProgress = null,
IProgress<ProtectionProgress> protectionProgress = null)
#else
BaseParameters? parameters,
IProgress<Result>? resultProgress = null,
IProgress<ProtectionProgress>? protectionProgress = null)
#endif
{
// Ensure the current disc combination should exist
if (!system.MediaTypes().Contains(mediaType))
@@ -391,19 +341,14 @@ namespace MPF.Core
};
// Ensure that required sections exist
info = SubmissionInfoTool.EnsureAllSections(info);
info = EnsureAllSections(info);
// Get specific tool output handling
parameters?.GenerateSubmissionInfo(info, options, combinedBase, drive, options.IncludeArtifacts);
// Get a list of matching IDs for each line in the DAT
#if NET48
if (!string.IsNullOrEmpty(info.TracksAndWriteOffsets.ClrMameProData) && options.HasRedumpLogin)
SubmissionInfoTool.FillFromRedump(options, info, resultProgress);
#else
if (!string.IsNullOrEmpty(info.TracksAndWriteOffsets!.ClrMameProData) && options.HasRedumpLogin)
_ = await SubmissionInfoTool.FillFromRedump(options, info, resultProgress);
#endif
_ = await FillFromRedump(options, info, resultProgress);
// If we have both ClrMamePro and Size and Checksums data, remove the ClrMamePro
if (!string.IsNullOrWhiteSpace(info.SizeAndChecksums?.CRC32))
@@ -411,22 +356,14 @@ namespace MPF.Core
// Add the volume label to comments, if possible or necessary
if (drive?.VolumeLabel != null && drive.GetRedumpSystemFromVolumeLabel() == null)
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.VolumeLabel] = drive.VolumeLabel;
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.VolumeLabel] = drive.VolumeLabel;
#endif
// Extract info based generically on MediaType
switch (mediaType)
{
case MediaType.CDROM:
case MediaType.GDROM:
#if NET48
info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
@@ -439,17 +376,9 @@ namespace MPF.Core
case MediaType.BluRay:
// If we have a single-layer disc
#if NET48
if (info.SizeAndChecksums.Layerbreak == default)
#else
if (info.SizeAndChecksums!.Layerbreak == default)
#endif
{
#if NET48
info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
@@ -459,11 +388,7 @@ namespace MPF.Core
// If we have a dual-layer disc
else
{
#if NET48
info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
@@ -478,37 +403,21 @@ namespace MPF.Core
break;
case MediaType.NintendoGameCubeGameDisc:
#if NET48
info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer1MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0AdditionalMould = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#if NET48
info.Extras.BCA = info.Extras.BCA ?? (options.AddPlaceholders ? Template.RequiredValue : string.Empty);
#else
info.Extras!.BCA ??= (options.AddPlaceholders ? Template.RequiredValue : string.Empty);
#endif
break;
case MediaType.NintendoWiiOpticalDisc:
// If we have a single-layer disc
#if NET48
if (info.SizeAndChecksums.Layerbreak == default)
#else
if (info.SizeAndChecksums!.Layerbreak == default)
#endif
{
#if NET48
info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
@@ -518,11 +427,7 @@ namespace MPF.Core
// If we have a dual-layer disc
else
{
#if NET48
info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
@@ -534,22 +439,14 @@ namespace MPF.Core
info.CommonDiscInfo.Layer1MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
}
#if NET48
info.Extras.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.Extras!.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
info.Extras.BCA = info.Extras.BCA ?? (options.AddPlaceholders ? Template.RequiredValue : string.Empty);
break;
case MediaType.UMD:
// Both single- and dual-layer discs have two "layers" for the ring
#if NET48
info.CommonDiscInfo.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Layer0MasteringRing = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
info.CommonDiscInfo.Layer0MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer0MouldSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
@@ -558,15 +455,9 @@ namespace MPF.Core
info.CommonDiscInfo.Layer1MasteringSID = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
info.CommonDiscInfo.Layer1ToolstampMasteringCode = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#if NET48
info.SizeAndChecksums.CRC32 = info.SizeAndChecksums.CRC32 ?? (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty);
info.SizeAndChecksums.MD5 = info.SizeAndChecksums.MD5 ?? (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty);
info.SizeAndChecksums.SHA1 = info.SizeAndChecksums.SHA1 ?? (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty);
#else
info.SizeAndChecksums!.CRC32 ??= (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty);
info.SizeAndChecksums.MD5 ??= (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty);
info.SizeAndChecksums.SHA1 ??= (options.AddPlaceholders ? Template.RequiredValue + " [Not automatically generated for UMD]" : string.Empty);
#endif
info.TracksAndWriteOffsets.ClrMameProData = null;
break;
}
@@ -575,11 +466,7 @@ namespace MPF.Core
switch (system)
{
case RedumpSystem.AcornArchimedes:
#if NET48
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.UnitedKingdom;
#else
info.CommonDiscInfo!.Region ??= Region.UnitedKingdom;
#endif
break;
case RedumpSystem.AppleMacintosh:
@@ -592,13 +479,8 @@ namespace MPF.Core
resultProgress?.Report(Result.Success("Running copy protection scan... this might take a while!"));
var (protectionString, fullProtections) = await InfoTool.GetCopyProtection(drive, options, protectionProgress);
#if NET48
info.CopyProtection.Protection = protectionString;
info.CopyProtection.FullProtections = fullProtections ?? new Dictionary<string, List<string>>();
#else
info.CopyProtection!.Protection = protectionString;
info.CopyProtection.FullProtections = fullProtections as Dictionary<string, List<string>?> ?? new Dictionary<string, List<string>?>();
#endif
resultProgress?.Report(Result.Success("Copy protection scan complete!"));
break;
@@ -606,139 +488,72 @@ namespace MPF.Core
case RedumpSystem.AudioCD:
case RedumpSystem.DVDAudio:
case RedumpSystem.SuperAudioCD:
#if NET48
info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.Audio;
#else
info.CommonDiscInfo!.Category ??= DiscCategory.Audio;
#endif
break;
case RedumpSystem.BandaiPlaydiaQuickInteractiveSystem:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
break;
case RedumpSystem.BDVideo:
#if NET48
info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.BonusDiscs;
info.CopyProtection.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CommonDiscInfo!.Category ??= DiscCategory.BonusDiscs;
info.CopyProtection!.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
break;
case RedumpSystem.CommodoreAmigaCD:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.CommodoreAmigaCD32:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Europe;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo.Region ??= Region.Europe;
#endif
break;
case RedumpSystem.CommodoreAmigaCDTV:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Europe;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo.Region ??= Region.Europe;
#endif
break;
case RedumpSystem.DVDVideo:
#if NET48
info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.BonusDiscs;
#else
info.CommonDiscInfo!.Category ??= DiscCategory.BonusDiscs;
#endif
break;
case RedumpSystem.FujitsuFMTownsseries:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
break;
case RedumpSystem.FujitsuFMTownsMarty:
#if NET48
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
#else
info.CommonDiscInfo!.Region ??= Region.Japan;
#endif
break;
case RedumpSystem.IncredibleTechnologiesEagle:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.KonamieAmusement:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.KonamiFireBeat:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.KonamiSystemGV:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.KonamiSystem573:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.KonamiTwinkle:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.MattelHyperScan:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.MicrosoftXboxOne:
@@ -747,11 +562,7 @@ namespace MPF.Core
string xboxOneMsxcPath = Path.Combine(drive.Name, "MSXC");
if (drive != null && Directory.Exists(xboxOneMsxcPath))
{
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.Filename] = string.Join("\n",
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = string.Join("\n",
#endif
Directory.GetFiles(xboxOneMsxcPath, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName));
}
}
@@ -764,11 +575,7 @@ namespace MPF.Core
string xboxSeriesXMsxcPath = Path.Combine(drive.Name, "MSXC");
if (drive != null && Directory.Exists(xboxSeriesXMsxcPath))
{
#if NET48
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.Filename] = string.Join("\n",
#else
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = string.Join("\n",
#endif
Directory.GetFiles(xboxSeriesXMsxcPath, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName));
}
}
@@ -776,112 +583,58 @@ namespace MPF.Core
break;
case RedumpSystem.NamcoSegaNintendoTriforce:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.NavisoftNaviken21:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo.Region ??= Region.Japan;
#endif
break;
case RedumpSystem.NECPC88series:
#if NET48
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
#else
info.CommonDiscInfo!.Region ??= Region.Japan;
#endif
break;
case RedumpSystem.NECPC98series:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
info.CommonDiscInfo!.Region ??= Region.Japan;
#endif
break;
case RedumpSystem.NECPCFXPCFXGA:
#if NET48
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
#else
info.CommonDiscInfo!.Region ??= Region.Japan;
#endif
break;
case RedumpSystem.SegaChihiro:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.SegaDreamcast:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.SegaNaomi:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.SegaNaomi2:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.SegaTitanVideo:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.SharpX68000:
#if NET48
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
#else
info.CommonDiscInfo!.Region ??= Region.Japan;
#endif
break;
case RedumpSystem.SNKNeoGeoCD:
#if NET48
info.CommonDiscInfo.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.CommonDiscInfo!.EXEDateBuildDate = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
break;
case RedumpSystem.SonyPlayStation:
// Only check the disc if the dumping program couldn't detect
#if NET48
if (drive != null && info.CopyProtection.AntiModchip == YesNo.NULL)
#else
if (drive != null && info.CopyProtection!.AntiModchip == YesNo.NULL)
#endif
{
resultProgress?.Report(Result.Success("Checking for anti-modchip strings... this might take a while!"));
info.CopyProtection.AntiModchip = await InfoTool.GetAntiModchipDetected(drive) ? YesNo.Yes : YesNo.No;
@@ -899,45 +652,25 @@ namespace MPF.Core
break;
case RedumpSystem.SonyPlayStation2:
#if NET48
info.CommonDiscInfo.LanguageSelection = new LanguageSelection?[] { LanguageSelection.BiosSettings, LanguageSelection.LanguageSelector, LanguageSelection.OptionsMenu };
#else
info.CommonDiscInfo!.LanguageSelection = new LanguageSelection?[] { LanguageSelection.BiosSettings, LanguageSelection.LanguageSelector, LanguageSelection.OptionsMenu };
#endif
break;
case RedumpSystem.SonyPlayStation3:
#if NET48
info.Extras.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#else
info.Extras!.DiscKey = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
#endif
info.Extras.DiscID = options.AddPlaceholders ? Template.RequiredValue : string.Empty;
break;
case RedumpSystem.TomyKissSite:
#if NET48
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? Region.Japan;
#else
info.CommonDiscInfo!.Region ??= Region.Japan;
#endif
break;
case RedumpSystem.ZAPiTGamesGameWaveFamilyEntertainmentSystem:
#if NET48
info.CopyProtection.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#else
info.CopyProtection!.Protection = options.AddPlaceholders ? Template.RequiredIfExistsValue : string.Empty;
#endif
break;
}
// Set the category if it's not overriden
#if NET48
info.CommonDiscInfo.Category = info.CommonDiscInfo.Category ?? DiscCategory.Games;
#else
info.CommonDiscInfo!.Category ??= DiscCategory.Games;
#endif
// Comments and contents have odd handling
if (string.IsNullOrEmpty(info.CommonDiscInfo.Comments))
@@ -958,16 +691,6 @@ namespace MPF.Core
/// <param name="info">Existing SubmissionInfo object to fill</param>
/// <param name="id">Redump disc ID to retrieve</param>
/// <param name="includeAllData">True to include all pullable information, false to do bare minimum</param>
#if NET48
public static bool FillFromId(RedumpWebClient wc, SubmissionInfo info, int id, bool includeAllData)
{
// Ensure that required sections exist
info = EnsureAllSections(info);
string discData = wc.DownloadSingleSiteID(id);
if (string.IsNullOrEmpty(discData))
return false;
#else
public async static Task<bool> FillFromId(RedumpHttpClient wc, SubmissionInfo info, int id, bool includeAllData)
{
// Ensure that required sections exist
@@ -976,7 +699,6 @@ namespace MPF.Core
var discData = await wc.DownloadSingleSiteID(id);
if (string.IsNullOrEmpty(discData))
return false;
#endif
// Title, Disc Number/Letter, Disc Title
var match = Constants.TitleRegex.Match(discData);
@@ -988,11 +710,7 @@ namespace MPF.Core
int firstParenLocation = title.IndexOf(" (");
if (firstParenLocation >= 0)
{
#if NET48
info.CommonDiscInfo.Title = title.Substring(0, firstParenLocation);
#else
info.CommonDiscInfo!.Title = title[..firstParenLocation];
#endif
var subMatches = Constants.DiscNumberLetterRegex.Matches(title);
foreach (Match subMatch in subMatches.Cast<Match>())
{
@@ -1014,28 +732,16 @@ namespace MPF.Core
// Otherwise, leave the title as-is
else
{
#if NET48
info.CommonDiscInfo.Title = title;
#else
info.CommonDiscInfo!.Title = title;
#endif
}
}
// Foreign Title
match = Constants.ForeignTitleRegex.Match(discData);
if (match.Success)
#if NET48
info.CommonDiscInfo.ForeignTitleNonLatin = WebUtility.HtmlDecode(match.Groups[1].Value);
#else
info.CommonDiscInfo!.ForeignTitleNonLatin = WebUtility.HtmlDecode(match.Groups[1].Value);
#endif
else
#if NET48
info.CommonDiscInfo.ForeignTitleNonLatin = null;
#else
info.CommonDiscInfo!.ForeignTitleNonLatin = null;
#endif
// Category
match = Constants.CategoryRegex.Match(discData);
@@ -1083,11 +789,7 @@ namespace MPF.Core
}
// Version
#if NET48
if (info.VersionAndEditions.Version == null)
#else
if (info.VersionAndEditions!.Version == null)
#endif
{
match = Constants.VersionRegex.Match(discData);
if (match.Success)
@@ -1100,11 +802,7 @@ namespace MPF.Core
{
// Start with any currently listed dumpers
var tempDumpers = new List<string>();
#if NET48
if (info.DumpersAndStatus.Dumpers != null && info.DumpersAndStatus.Dumpers.Length > 0)
#else
if (info.DumpersAndStatus!.Dumpers != null && info.DumpersAndStatus.Dumpers.Length > 0)
#endif
{
foreach (string dumper in info.DumpersAndStatus.Dumpers)
tempDumpers.Add(dumper);
@@ -1213,11 +911,7 @@ namespace MPF.Core
}
// If we don't already have this site code, add it to the dictionary
#if NET48
if (!info.CommonDiscInfo.CommentsSpecialFields.ContainsKey(siteCode.Value))
#else
if (!info.CommonDiscInfo.CommentsSpecialFields!.ContainsKey(siteCode.Value))
#endif
info.CommonDiscInfo.CommentsSpecialFields[siteCode.Value] = $"(VERIFY THIS) {commentLine.Replace(shortName, string.Empty).Trim()}";
// Otherwise, append the value to the existing key
@@ -1232,11 +926,7 @@ namespace MPF.Core
{
if (addToLast && lastSiteCode != null)
{
#if NET48
if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.CommentsSpecialFields[lastSiteCode.Value]))
#else
if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.CommentsSpecialFields![lastSiteCode.Value]))
#endif
info.CommonDiscInfo.CommentsSpecialFields[lastSiteCode.Value] += "\n";
info.CommonDiscInfo.CommentsSpecialFields[lastSiteCode.Value] += commentLine;
@@ -1308,11 +998,7 @@ namespace MPF.Core
lastSiteCode = siteCode;
// If we don't already have this site code, add it to the dictionary
#if NET48
if (!info.CommonDiscInfo.ContentsSpecialFields.ContainsKey(siteCode.Value))
#else
if (!info.CommonDiscInfo.ContentsSpecialFields!.ContainsKey(siteCode.Value))
#endif
info.CommonDiscInfo.ContentsSpecialFields[siteCode.Value] = $"(VERIFY THIS) {contentLine.Replace(shortName, string.Empty).Trim()}";
// A subset of tags can be multiline
@@ -1328,11 +1014,7 @@ namespace MPF.Core
{
if (addToLast && lastSiteCode != null)
{
#if NET48
if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.ContentsSpecialFields[lastSiteCode.Value]))
#else
if (!string.IsNullOrWhiteSpace(info.CommonDiscInfo.ContentsSpecialFields![lastSiteCode.Value]))
#endif
info.CommonDiscInfo.ContentsSpecialFields[lastSiteCode.Value] += "\n";
info.CommonDiscInfo.ContentsSpecialFields[lastSiteCode.Value] += contentLine;
@@ -1378,37 +1060,21 @@ namespace MPF.Core
/// <param name="options">Options object representing user-defined options</param>
/// <param name="info">Existing SubmissionInfo object to fill</param>
/// <param name="resultProgress">Optional result progress callback</param>
#if NET48
public static bool FillFromRedump(Data.Options options, SubmissionInfo info, IProgress<Result> resultProgress = null)
#else
public async static Task<bool> FillFromRedump(Data.Options options, SubmissionInfo info, IProgress<Result>? resultProgress = null)
#endif
{
// If no username is provided
if (string.IsNullOrWhiteSpace(options.RedumpUsername) || string.IsNullOrWhiteSpace(options.RedumpPassword))
return false;
// Set the current dumper based on username
#if NET48
if (info.DumpersAndStatus == null) info.DumpersAndStatus = new DumpersAndStatusSection();
#else
info.DumpersAndStatus ??= new DumpersAndStatusSection();
#endif
info.DumpersAndStatus.Dumpers = new string[] { options.RedumpUsername };
info.PartiallyMatchedIDs = new List<int>();
#if NET48
using (var wc = new RedumpWebClient())
#else
using (var wc = new RedumpHttpClient())
#endif
{
// Login to Redump
#if NET48
bool? loggedIn = wc.Login(options.RedumpUsername, options.RedumpPassword);
#else
bool? loggedIn = await wc.Login(options.RedumpUsername, options.RedumpPassword);
#endif
if (loggedIn == null)
{
resultProgress?.Report(Result.Failure("There was an unknown error connecting to Redump"));
@@ -1422,11 +1088,7 @@ namespace MPF.Core
// Setup the full-track checks
bool allFound = true;
#if NET48
List<int> fullyMatchedIDs = null;
#else
List<int>? fullyMatchedIDs = null;
#endif
// Loop through all of the hashdata to find matching IDs
resultProgress?.Report(Result.Success("Finding disc matches on Redump..."));
@@ -1455,11 +1117,7 @@ namespace MPF.Core
continue;
}
#if NET48
(bool singleFound, List<int> foundIds) = ValidateSingleTrack(wc, info, hashData, resultProgress);
#else
(bool singleFound, var foundIds) = await ValidateSingleTrack(wc, info, hashData, resultProgress);
#endif
// Ensure that all tracks are found
allFound &= singleFound;
@@ -1482,11 +1140,7 @@ namespace MPF.Core
// If we don't have any matches but we have a universal hash
if (!info.PartiallyMatchedIDs.Any() && info.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.UniversalHash) == true)
{
#if NET48
(bool singleFound, List<int> foundIds) = ValidateUniversalHash(wc, info, resultProgress);
#else
(bool singleFound, var foundIds) = await ValidateUniversalHash(wc, info, resultProgress);
#endif
// Ensure that the hash is found
allFound = singleFound;
@@ -1522,21 +1176,12 @@ namespace MPF.Core
for (int i = 0; i < totalMatchedIDsCount; i++)
{
// Skip if the track count doesn't match
#if NET48
if (!ValidateTrackCount(wc, fullyMatchedIDs[i], trackCount))
continue;
#else
if (!await ValidateTrackCount(wc, fullyMatchedIDs[i], trackCount))
continue;
#endif
// Fill in the fields from the existing ID
resultProgress?.Report(Result.Success($"Filling fields from existing ID {fullyMatchedIDs[i]}..."));
#if NET48
FillFromId(wc, info, fullyMatchedIDs[i], options.PullAllInformation);
#else
_ = await FillFromId(wc, info, fullyMatchedIDs[i], options.PullAllInformation);
#endif
resultProgress?.Report(Result.Success("Information filling complete!"));
// Set the fully matched ID to the current
@@ -1562,18 +1207,14 @@ namespace MPF.Core
/// </summary>
/// <param name="info">Existing submission information</param>
/// <param name="seed">User-supplied submission information</param>
#if NET48
public static void InjectSubmissionInformation(SubmissionInfo info, SubmissionInfo seed)
#else
public static void InjectSubmissionInformation(SubmissionInfo? info, SubmissionInfo? seed)
#endif
{
// If we have any invalid info
if (seed == null)
return;
// Ensure that required sections exist
info = SubmissionInfoTool.EnsureAllSections(info);
info = EnsureAllSections(info);
// Otherwise, inject information as necessary
if (info.CommonDiscInfo != null && seed.CommonDiscInfo != null)
@@ -1642,26 +1283,6 @@ namespace MPF.Core
/// <remarks>TODO: This should move to Extensions at some point</remarks>
public static bool IsMultiLine(SiteCode? siteCode)
{
#if NET48
switch (siteCode)
{
case SiteCode.Extras:
case SiteCode.Filename:
case SiteCode.Games:
case SiteCode.GameFootage:
case SiteCode.Multisession:
case SiteCode.NetYarozeGames:
case SiteCode.Patches:
case SiteCode.PlayableDemos:
case SiteCode.RollingDemos:
case SiteCode.Savegames:
case SiteCode.TechDemos:
case SiteCode.Videos:
return true;
default:
return false;
}
#else
return siteCode switch
{
SiteCode.Extras => true,
@@ -1678,7 +1299,6 @@ namespace MPF.Core
SiteCode.Videos => true,
_ => false,
};
#endif
}
/// <summary>
@@ -1723,11 +1343,7 @@ namespace MPF.Core
/// <param name="query">Query string to attempt to search for</param>
/// <param name="filterForwardSlashes">True to filter forward slashes, false otherwise</param>
/// <returns>All disc IDs for the given query, null on error</returns>
#if NET48
private static List<int> ListSearchResults(RedumpWebClient wc, string query, bool filterForwardSlashes = true)
#else
private async static Task<List<int>?> ListSearchResults(RedumpHttpClient wc, string? query, bool filterForwardSlashes = true)
#endif
{
// If there is an invalid query
if (string.IsNullOrWhiteSpace(query))
@@ -1753,11 +1369,7 @@ namespace MPF.Core
int pageNumber = 1;
while (true)
{
#if NET48
List<int> pageIds = wc.CheckSingleSitePage(string.Format(Constants.QuickSearchUrl, query, pageNumber++));
#else
List<int> pageIds = await wc.CheckSingleSitePage(string.Format(Constants.QuickSearchUrl, query, pageNumber++));
#endif
ids.AddRange(pageIds);
if (pageIds.Count <= 1)
break;
@@ -1780,11 +1392,7 @@ namespace MPF.Core
/// <param name="hashData">DAT-formatted hash data to parse out</param>
/// <param name="resultProgress">Optional result progress callback</param>
/// <returns>True if the track was found, false otherwise; List of found values, if possible</returns>
#if NET48
private static (bool, List<int>) ValidateSingleTrack(RedumpWebClient wc, SubmissionInfo info, string hashData, IProgress<Result> resultProgress = null)
#else
private async static Task<(bool, List<int>?)> ValidateSingleTrack(RedumpHttpClient wc, SubmissionInfo info, string hashData, IProgress<Result>? resultProgress = null)
#endif
{
// If the line isn't parseable, we can't validate
if (!InfoTool.GetISOHashValues(hashData, out long _, out var _, out var _, out var sha1))
@@ -1794,11 +1402,7 @@ namespace MPF.Core
}
// Get all matching IDs for the track
#if NET48
List<int> newIds = ListSearchResults(wc, sha1);
#else
var newIds = await ListSearchResults(wc, sha1);
#endif
// If we got null back, there was an error
if (newIds == null)
@@ -1827,11 +1431,7 @@ namespace MPF.Core
/// <param name="info">Existing SubmissionInfo object to fill</param>
/// <param name="resultProgress">Optional result progress callback</param>
/// <returns>True if the track was found, false otherwise; List of found values, if possible</returns>
#if NET48
private static (bool, List<int>) ValidateUniversalHash(RedumpWebClient wc, SubmissionInfo info, IProgress<Result> resultProgress = null)
#else
private async static Task<(bool, List<int>?)> ValidateUniversalHash(RedumpHttpClient wc, SubmissionInfo info, IProgress<Result>? resultProgress = null)
#endif
{
// If we don't have special fields
if (info.CommonDiscInfo?.CommentsSpecialFields == null)
@@ -1849,18 +1449,10 @@ namespace MPF.Core
}
// Format the universal hash for finding within the comments
#if NET48
universalHash = $"{universalHash.Substring(0, universalHash.Length - 1)}/comments/only";
#else
universalHash = $"{universalHash[..^1]}/comments/only";
#endif
// Get all matching IDs for the hash
#if NET48
List<int> newIds = ListSearchResults(wc, universalHash, filterForwardSlashes: false);
#else
var newIds = await ListSearchResults(wc, universalHash, filterForwardSlashes: false);
#endif
// If we got null back, there was an error
if (newIds == null)
@@ -1889,18 +1481,10 @@ namespace MPF.Core
/// <param name="id">Redump disc ID to retrieve</param>
/// <param name="localCount">Local count of tracks for the current disc</param>
/// <returns>True if the track count matches, false otherwise</returns>
#if NET48
private static bool ValidateTrackCount(RedumpWebClient wc, int id, int localCount)
#else
private async static Task<bool> ValidateTrackCount(RedumpHttpClient wc, int id, int localCount)
#endif
{
// If we can't pull the remote data, we can't match
#if NET48
string discData = wc.DownloadSingleSiteID(id);
#else
string? discData = await wc.DownloadSingleSiteID(id);
#endif
if (string.IsNullOrEmpty(discData))
return false;

View File

@@ -49,11 +49,7 @@ namespace MPF.Core.UI.ComboBoxItems
}
/// <inheritdoc/>
#if NET48
public bool Equals(Element<T> other)
#else
public bool Equals(Element<T>? other)
#endif
{
if (other == null)
return false;

View File

@@ -10,11 +10,7 @@ namespace MPF.Core.UI.ComboBoxItems
/// </summary>
public class RedumpSystemComboBoxItem : IEquatable<RedumpSystemComboBoxItem>, IElement
{
#if NET48
private readonly object Data;
#else
private readonly object? Data;
#endif
public RedumpSystemComboBoxItem(RedumpSystem? system) => Data = system;
public RedumpSystemComboBoxItem(SystemCategory? category) => Data = category;
@@ -85,11 +81,7 @@ namespace MPF.Core.UI.ComboBoxItems
}
/// <inheritdoc/>
#if NET48
public bool Equals(RedumpSystemComboBoxItem other)
#else
public bool Equals(RedumpSystemComboBoxItem? other)
#endif
{
if (other == null)
return false;

View File

@@ -38,11 +38,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// List of Redump-supported Regions
/// </summary>
#if NET48
private static readonly List<Region> RedumpRegions = new List<Region>
#else
private static readonly List<Region> RedumpRegions = new()
#endif
{
Region.Argentina,
Region.Asia,
@@ -133,11 +129,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// List of Redump-supported Languages
/// </summary>
#if NET48
private static readonly List<Language> RedumpLanguages = new List<Language>
#else
private static readonly List<Language> RedumpLanguages = new()
#endif
{
Language.Afrikaans,
Language.Albanian,
@@ -199,11 +191,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Constructor
/// </summary>
#if NET48
public DiscInformationViewModel(Options options, SubmissionInfo submissionInfo)
#else
public DiscInformationViewModel(Options options, SubmissionInfo? submissionInfo)
#endif
{
Options = options;
SubmissionInfo = submissionInfo?.Clone() as SubmissionInfo ?? new SubmissionInfo();

View File

@@ -37,20 +37,12 @@ namespace MPF.Core.UI.ViewModels
public bool CanExecuteSelectionChanged { get; private set; } = false;
/// <inheritdoc/>
#if NET48
public event PropertyChangedEventHandler PropertyChanged;
#else
public event PropertyChangedEventHandler? PropertyChanged;
#endif
/// <summary>
/// Action to process logging statements
/// </summary>
#if NET48
private Action<LogLevel, string> _logger;
#else
private Action<LogLevel, string>? _logger;
#endif
/// <summary>
/// Display a message to a user
@@ -62,11 +54,7 @@ namespace MPF.Core.UI.ViewModels
/// T4 - true for inquiry, false otherwise
/// TResult - true for positive, false for negative, null for neutral
/// </remarks>
#if NET48
private Func<string, string, int, bool, bool?> _displayUserMessage;
#else
private Func<string, string, int, bool, bool?>? _displayUserMessage;
#endif
/// <summary>
/// Detected media type, distinct from the selected one
@@ -76,20 +64,12 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Current dumping environment
/// </summary>
#if NET48
private DumpEnvironment _environment;
#else
private DumpEnvironment? _environment;
#endif
/// <summary>
/// Function to process user information
/// </summary>
#if NET48
private Func<SubmissionInfo, (bool?, SubmissionInfo)> _processUserInfo;
#else
private Func<SubmissionInfo?, (bool?, SubmissionInfo?)>? _processUserInfo;
#endif
#endregion
@@ -210,11 +190,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Currently selected drive value
/// </summary>
#if NET48
public Drive CurrentDrive
#else
public Drive? CurrentDrive
#endif
{
get => _currentDrive;
set
@@ -223,11 +199,7 @@ namespace MPF.Core.UI.ViewModels
TriggerPropertyChanged(nameof(CurrentDrive));
}
}
#if NET48
private Drive _currentDrive;
#else
private Drive? _currentDrive;
#endif
/// <summary>
/// Indicates the status of the drive combo box
@@ -474,11 +446,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Current list of supported media types
/// </summary>
#if NET48
public List<Element<MediaType>> MediaTypes
#else
public List<Element<MediaType>>? MediaTypes
#endif
{
get => _mediaTypes;
set
@@ -487,11 +455,7 @@ namespace MPF.Core.UI.ViewModels
TriggerPropertyChanged(nameof(MediaTypes));
}
}
#if NET48
private List<Element<MediaType>> _mediaTypes;
#else
private List<Element<MediaType>>? _mediaTypes;
#endif
/// <summary>
/// Current list of supported system profiles
@@ -564,11 +528,7 @@ namespace MPF.Core.UI.ViewModels
public void Init(
Action<LogLevel, string> loggerAction,
Func<string, string, int, bool, bool?> displayUserMessage,
#if NET48
Func<SubmissionInfo, (bool?, SubmissionInfo)> processUserInfo)
#else
Func<SubmissionInfo?, (bool?, SubmissionInfo?)> processUserInfo)
#endif
{
// Set the callbacks
_logger = loggerAction;
@@ -765,11 +725,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Check for available updates
/// </summary>
#if NET48
public (bool, string, string) CheckForUpdates()
#else
public (bool, string, string?) CheckForUpdates()
#endif
{
(bool different, string message, var url) = Tools.CheckForNewVersion();
@@ -846,20 +802,12 @@ namespace MPF.Core.UI.ViewModels
EXEDateBuildDate = "19xx-xx-xx",
ErrorsCount = "0",
Comments = "Comment data line 1\r\nComment data line 2",
#if NET48
CommentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
CommentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.ISBN] = "ISBN",
},
Contents = "Special contents 1\r\nSpecial contents 2",
#if NET48
ContentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
ContentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.PlayableDemos] = "Game Demo 1",
},
@@ -982,11 +930,7 @@ namespace MPF.Core.UI.ViewModels
/// </summary>
/// <param name="savedSettings">Indicates if the settings were saved or not</param>
/// <param name="newOptions">Options representing the new, saved values</param>
#if NET48
public void UpdateOptions(bool savedSettings, Data.Options newOptions)
#else
public void UpdateOptions(bool savedSettings, Data.Options? newOptions)
#endif
{
// Get which options to save
var optionsToSave = savedSettings ? newOptions : Options;
@@ -1467,19 +1411,10 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Scan and show copy protection for the current disc
/// </summary>
#if NET48
public async Task<(string, string)> ScanAndShowProtection()
#else
public async Task<(string?, string?)> ScanAndShowProtection()
#endif
{
// Determine current environment, just in case
#if NET48
if (_environment == null)
_environment = DetermineEnvironment();
#else
_environment ??= DetermineEnvironment();
#endif
// If we don't have a valid drive
if (this.CurrentDrive?.Name == null)
@@ -1563,30 +1498,6 @@ namespace MPF.Core.UI.ViewModels
VerboseLogLn($"Supported media speeds: {string.Join(", ", this.DriveSpeeds)}");
// Set the selected speed
#if NET48
int speed;
switch (CurrentMediaType)
{
case MediaType.CDROM:
case MediaType.GDROM:
speed = Options.PreferredDumpSpeedCD;
break;
case MediaType.DVD:
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
speed = Options.PreferredDumpSpeedDVD;
break;
case MediaType.HDDVD:
speed = Options.PreferredDumpSpeedHDDVD;
break;
case MediaType.BluRay:
speed = Options.PreferredDumpSpeedBD;
break;
default:
speed = Options.PreferredDumpSpeedCD;
break;
}
#else
int speed = (CurrentMediaType) switch
{
// CD dump speed
@@ -1607,7 +1518,6 @@ namespace MPF.Core.UI.ViewModels
// Default
_ => Options.PreferredDumpSpeedCD,
};
#endif
VerboseLogLn($"Setting drive speed to: {speed}");
this.DriveSpeed = speed;
@@ -1821,26 +1731,18 @@ namespace MPF.Core.UI.ViewModels
return true;
}
#endregion
#endregion
#region Progress Reporting
/// <summary>
/// Handler for Result ProgressChanged event
/// </summary>
#if NET48
private void ProgressUpdated(object sender, string value)
#else
private void ProgressUpdated(object? sender, string value)
#endif
{
try
{
#if NET48
value = value ?? string.Empty;
#else
value ??= string.Empty;
#endif
LogLn(value);
}
catch { }
@@ -1849,20 +1751,12 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Handler for Result ProgressChanged event
/// </summary>
#if NET48
private void ProgressUpdated(object sender, Result value)
#else
private void ProgressUpdated(object? sender, Result value)
#endif
{
var message = value?.Message;
// Update the label with only the first line of output
#if NET48
if (message != null && message.Contains("\n"))
#else
if (message != null && message.Contains('\n'))
#endif
this.Status = value?.Message?.Split('\n')[0] + " (See log output)";
else
this.Status = value?.Message ?? string.Empty;
@@ -1877,17 +1771,13 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Handler for ProtectionProgress ProgressChanged event
/// </summary>
#if NET48
private void ProgressUpdated(object sender, ProtectionProgress value)
#else
private void ProgressUpdated(object? sender, ProtectionProgress value)
#endif
{
string message = $"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}";
this.Status = message;
VerboseLogLn(message);
}
#endregion
#endregion
}
}

View File

@@ -15,11 +15,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Title for the window
/// </summary>
#if NET48
public string Title
#else
public string? Title
#endif
{
get => _title;
set
@@ -28,11 +24,7 @@ namespace MPF.Core.UI.ViewModels
TriggerPropertyChanged(nameof(Title));
}
}
#if NET48
private string _title;
#else
private string? _title;
#endif
/// <summary>
/// Current set of options
@@ -45,13 +37,9 @@ namespace MPF.Core.UI.ViewModels
public bool SavedSettings { get; set; }
/// <inheritdoc/>
#if NET48
public event PropertyChangedEventHandler PropertyChanged;
#else
public event PropertyChangedEventHandler? PropertyChanged;
#endif
#endregion
#endregion
#region Lists
@@ -93,17 +81,9 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Test Redump login credentials
/// </summary>
#if NET48
public (bool?, string) TestRedumpLogin(string username, string password)
#else
public async Task<(bool?, string?)> TestRedumpLogin(string username, string password)
#endif
{
#if NET48
return RedumpWebClient.ValidateCredentials(username, password);
#else
return await RedumpHttpClient.ValidateCredentials(username, password);
#endif
}
#endregion

View File

@@ -14,11 +14,7 @@ namespace MPF.Core.Utilities
/// <param name="reader">TextReader representing the input</param>
/// <param name="baseClass">Invoking class, passed on to the event handler</param>
/// <param name="handler">Event handler to be invoked to write to log</param>
#if NET48
public static async Task OutputToLog(TextReader reader, object baseClass, EventHandler<string> handler)
#else
public static async Task OutputToLog(TextReader reader, object baseClass, EventHandler<string>? handler)
#endif
{
// Initialize the required variables
char[] buffer = new char[256];
@@ -67,11 +63,7 @@ namespace MPF.Core.Utilities
/// <param name="line">Current line to process</param>
/// <param name="baseClass">Invoking class, passed on to the event handler</param>
/// <param name="handler">Event handler to be invoked to write to log</param>
#if NET48
private static void ProcessNewLines(StringBuilder sb, string line, object baseClass, EventHandler<string> handler)
#else
private static void ProcessNewLines(StringBuilder sb, string line, object baseClass, EventHandler<string>? handler)
#endif
{
line = line.Replace("\r\n", "\n");
var split = line.Split('\n');
@@ -113,11 +105,7 @@ namespace MPF.Core.Utilities
/// <param name="line">Current line to process</param>
/// <param name="baseClass">Invoking class, passed on to the event handler</param>
/// <param name="handler">Event handler to be invoked to write to log</param>
#if NET48
private static void ProcessCarriageReturns(StringBuilder sb, string line, object baseClass, EventHandler<string> handler)
#else
private static void ProcessCarriageReturns(StringBuilder sb, string line, object baseClass, EventHandler<string>? handler)
#endif
{
var split = line.Split('\r');

View File

@@ -63,11 +63,7 @@ namespace MPF.Core.Utilities
/// Process common arguments for all functionality
/// </summary>
/// <returns>True if all arguments pass, false otherwise</returns>
#if NET48
public static (bool, MediaType, RedumpSystem?, string) ProcessCommonArguments(string[] args)
#else
public static (bool, MediaType, RedumpSystem?, string?) ProcessCommonArguments(string[] args)
#endif
{
// All other use requires at least 3 arguments
if (args.Length < 3)
@@ -89,11 +85,7 @@ namespace MPF.Core.Utilities
/// <summary>
/// Load the current set of options from application arguments
/// </summary>
#if NET48
public static (Options, SubmissionInfo, string, int) LoadFromArguments(string[] args, int startIndex = 0)
#else
public static (Options, SubmissionInfo?, string?, int) LoadFromArguments(string[] args, int startIndex = 0)
#endif
{
// Create the output values with defaults
var options = new Options()
@@ -108,13 +100,8 @@ namespace MPF.Core.Utilities
};
// Create the submission info to return, if necessary
#if NET48
SubmissionInfo info = null;
string parsedPath = null;
#else
SubmissionInfo? info = null;
string? parsedPath = null;
#endif
// These values require multiple parts to be active
bool scan = false, protectFile = false;
@@ -277,11 +264,7 @@ namespace MPF.Core.Utilities
var serializer = JsonSerializer.Create();
var reader = new StreamReader(ConfigurationPath);
#if NET48
var settings = serializer.Deserialize(reader, typeof(Dictionary<string, string>)) as Dictionary<string, string>;
#else
var settings = serializer.Deserialize(reader, typeof(Dictionary<string, string?>)) as Dictionary<string, string?>;
#endif
return new Options(settings);
}

View File

@@ -84,40 +84,6 @@ namespace MPF.Core.Utilities
return Result.Failure("Please select a valid system");
// If we're on an unsupported type, update the status accordingly
#if NET48
switch (type)
{
// Fully supported types
case MediaType.BluRay:
case MediaType.CDROM:
case MediaType.DVD:
case MediaType.FloppyDisk:
case MediaType.HardDisk:
case MediaType.CompactFlash:
case MediaType.SDCard:
case MediaType.FlashDrive:
case MediaType.HDDVD:
return Result.Success($"{type.LongName()} ready to dump");
// Partially supported types
case MediaType.GDROM:
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
return Result.Success($"{type.LongName()} partially supported for dumping");
// Special case for other supported tools
case MediaType.UMD:
return Result.Failure($"{type.LongName()} supported for submission info parsing");
// Specifically unknown type
case MediaType.NONE:
return Result.Failure($"Please select a valid media type");
// Undumpable but recognized types
default:
return Result.Failure($"{type.LongName()} media are not supported for dumping");
}
#else
return type switch
{
// Fully supported types
@@ -145,9 +111,8 @@ namespace MPF.Core.Utilities
// Undumpable but recognized types
_ => Result.Failure($"{type.LongName()} media are not supported for dumping"),
};
#endif
}
/// <summary>
/// Returns false if a given InternalProgram does not support a given MediaType
/// </summary>
@@ -157,51 +122,6 @@ namespace MPF.Core.Utilities
if (type == null || type == MediaType.NONE)
return false;
#if NET48
switch (program)
{
case InternalProgram.Redumper:
switch (type)
{
// Formats considered at least partially dumpable by Redumper
case MediaType.BluRay:
case MediaType.CDROM:
case MediaType.DVD:
case MediaType.GDROM:
case MediaType.HDDVD:
return true;
// All other formats considered unsupported
default:
return false;
}
case InternalProgram.Aaru:
case InternalProgram.DiscImageCreator:
switch (type)
{
// Formats considered at least partially supported
case MediaType.BluRay:
case MediaType.CDROM:
case MediaType.DVD:
case MediaType.FloppyDisk:
case MediaType.HardDisk:
case MediaType.CompactFlash:
case MediaType.SDCard:
case MediaType.FlashDrive:
case MediaType.HDDVD:
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
return true;
// All other formats considered unsupported
default:
return false;
}
// All other InternalPrograms are not used for dumping
default:
return false;
}
#else
return (program) switch
{
// Aaru
@@ -242,7 +162,6 @@ namespace MPF.Core.Utilities
// Default
_ => false,
};
#endif
}
#endregion
@@ -257,11 +176,7 @@ namespace MPF.Core.Utilities
/// String representing the message to display the the user.
/// String representing the new release URL.
/// </returns>
#if NET48
public static (bool different, string message, string url) CheckForNewVersion()
#else
public static (bool different, string message, string? url) CheckForNewVersion()
#endif
{
try
{
@@ -293,11 +208,7 @@ namespace MPF.Core.Utilities
/// <summary>
/// Get the current informational version formatted as a string
/// </summary>
#if NET48
public static string GetCurrentVersion()
#else
public static string? GetCurrentVersion()
#endif
{
try
{
@@ -317,27 +228,8 @@ namespace MPF.Core.Utilities
/// <summary>
/// Get the latest version of MPF from GitHub and the release URL
/// </summary>
#if NET48
private static (string tag, string url) GetRemoteVersionAndUrl()
#else
private static (string? tag, string? url) GetRemoteVersionAndUrl()
#endif
{
#if NET48
using (var wc = new System.Net.WebClient())
{
wc.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0";
// TODO: Figure out a better way than having this hardcoded...
string url = "https://api.github.com/repos/SabreTools/MPF/releases/latest";
string latestReleaseJsonString = wc.DownloadString(url);
var latestReleaseJson = JObject.Parse(latestReleaseJsonString);
string latestTag = latestReleaseJson["tag_name"].ToString();
string releaseUrl = latestReleaseJson["html_url"].ToString();
return (latestTag, releaseUrl);
}
#else
using (var hc = new System.Net.Http.HttpClient())
{
// TODO: Figure out a better way than having this hardcoded...
@@ -357,7 +249,6 @@ namespace MPF.Core.Utilities
return (latestTag, releaseUrl);
}
#endif
}
#endregion

View File

@@ -43,37 +43,21 @@ namespace MPF.Test.Core.Converters
/// Generate a test set of DriveType values
/// </summary>
/// <returns>MemberData-compatible list of DriveType values</returns>
#if NET48
public static List<object[]> GenerateDriveTypeMappingTestData()
#else
public static List<object?[]> GenerateDriveTypeMappingTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (DriveType driveType in Enum.GetValues(typeof(DriveType)))
{
if (_mappableDriveTypes.Contains(driveType))
#if NET48
testData.Add(new object[] { driveType, false });
#else
testData.Add(new object?[] { driveType, false });
#endif
else
#if NET48
testData.Add(new object[] { driveType, true });
#else
testData.Add(new object?[] { driveType, true });
#endif
}
return testData;
}
#endregion
#endregion
#region Convert to Long Name
@@ -95,30 +79,18 @@ namespace MPF.Test.Core.Converters
/// Generate a test set of InternalProgram values
/// </summary>
/// <returns>MemberData-compatible list of InternalProgram values</returns>
#if NET48
public static List<object[]> GenerateInternalProgramTestData()
#else
public static List<object?[]> GenerateInternalProgramTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null } };
#else
var testData = new List<object?[]>() { new object?[] { null } };
#endif
foreach (InternalProgram? internalProgram in Enum.GetValues(typeof(InternalProgram)))
{
#if NET48
testData.Add(new object[] { internalProgram });
#else
testData.Add(new object?[] { internalProgram });
#endif
}
return testData;
}
#endregion
#endregion
// TODO: Add from-string tests
}

View File

@@ -143,31 +143,15 @@ namespace MPF.Test.Core.Utilities
/// Generate a test set of MediaType values that support drive speeds
/// </summary>
/// <returns>MemberData-compatible list of MediaType values</returns>
#if NET48
public static List<object[]> GenerateSupportDriveSpeedsTestData()
#else
public static List<object?[]> GenerateSupportDriveSpeedsTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, false } };
#else
var testData = new List<object?[]>() { new object?[] { null, false } };
#endif
foreach (MediaType mediaType in Enum.GetValues(typeof(MediaType)))
{
if (_supportDriveSpeeds.Contains(mediaType))
#if NET48
testData.Add(new object[] { mediaType, true });
#else
testData.Add(new object?[] { mediaType, true });
#endif
else
#if NET48
testData.Add(new object[] { mediaType, false });
#else
testData.Add(new object?[] { mediaType, false });
#endif
}
return testData;
@@ -177,31 +161,15 @@ namespace MPF.Test.Core.Utilities
/// Generate a test set of RedumpSystem values that are considered Audio
/// </summary>
/// <returns>MemberData-compatible list of RedumpSystem values</returns>
#if NET48
public static List<object[]> GenerateAudioSystemsTestData()
#else
public static List<object?[]> GenerateAudioSystemsTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, false } };
#else
var testData = new List<object?[]>() { new object?[] { null, false } };
#endif
foreach (RedumpSystem redumpSystem in Enum.GetValues(typeof(RedumpSystem)))
{
if (_audioSystems.Contains(redumpSystem))
#if NET48
testData.Add(new object[] { redumpSystem, true });
#else
testData.Add(new object?[] { redumpSystem, true });
#endif
else
#if NET48
testData.Add(new object[] { redumpSystem, false });
#else
testData.Add(new object?[] { redumpSystem, false });
#endif
}
return testData;
@@ -211,31 +179,15 @@ namespace MPF.Test.Core.Utilities
/// Generate a test set of RedumpSystem values that are considered markers
/// </summary>
/// <returns>MemberData-compatible list of RedumpSystem values</returns>
#if NET48
public static List<object[]> GenerateMarkerSystemsTestData()
#else
public static List<object?[]> GenerateMarkerSystemsTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, false } };
#else
var testData = new List<object?[]>() { new object?[] { null, false } };
#endif
foreach (RedumpSystem redumpSystem in Enum.GetValues(typeof(RedumpSystem)))
{
if (_markerSystems.Contains(redumpSystem))
#if NET48
testData.Add(new object[] { redumpSystem, true });
#else
testData.Add(new object?[] { redumpSystem, true });
#endif
else
#if NET48
testData.Add(new object[] { redumpSystem, false });
#else
testData.Add(new object?[] { redumpSystem, false });
#endif
}
return testData;
@@ -245,31 +197,15 @@ namespace MPF.Test.Core.Utilities
/// Generate a test set of RedumpSystem values that are considered markers
/// </summary>
/// <returns>MemberData-compatible list of RedumpSystem values</returns>
#if NET48
public static List<object[]> GenerateReversedRingcodeSystemsTestData()
#else
public static List<object?[]> GenerateReversedRingcodeSystemsTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, false } };
#else
var testData = new List<object?[]>() { new object?[] { null, false } };
#endif
foreach (RedumpSystem redumpSystem in Enum.GetValues(typeof(RedumpSystem)))
{
if (_reverseRingcodeSystems.Contains(redumpSystem))
#if NET48
testData.Add(new object[] { redumpSystem, true });
#else
testData.Add(new object?[] { redumpSystem, true });
#endif
else
#if NET48
testData.Add(new object[] { redumpSystem, false });
#else
testData.Add(new object?[] { redumpSystem, false });
#endif
}
return testData;
@@ -279,31 +215,15 @@ namespace MPF.Test.Core.Utilities
/// Generate a test set of RedumpSystem values that are considered XGD
/// </summary>
/// <returns>MemberData-compatible list of RedumpSystem values</returns>
#if NET48
public static List<object[]> GenerateXGDSystemsTestData()
#else
public static List<object?[]> GenerateXGDSystemsTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, false } };
#else
var testData = new List<object?[]>() { new object?[] { null, false } };
#endif
foreach (RedumpSystem redumpSystem in Enum.GetValues(typeof(RedumpSystem)))
{
if (_xgdSystems.Contains(redumpSystem))
#if NET48
testData.Add(new object[] { redumpSystem, true });
#else
testData.Add(new object?[] { redumpSystem, true });
#endif
else
#if NET48
testData.Add(new object[] { redumpSystem, false });
#else
testData.Add(new object?[] { redumpSystem, false });
#endif
}
return testData;

View File

@@ -42,11 +42,7 @@ namespace MPF.Test.Library
long layerbreak,
long layerbreak2,
long layerbreak3,
#if NET48
string expected)
#else
string? expected)
#endif
{
// TODO: Add tests around BDU
var actual = InfoTool.GetFixedMediaType(mediaType, null, size, layerbreak, layerbreak2, layerbreak3);
@@ -62,11 +58,7 @@ namespace MPF.Test.Library
[InlineData("superhero\\blah.rev.bin", "superhero\\blah.rev.bin")]
[InlineData("super&hero\\blah.bin", "super&hero\\blah.bin")]
[InlineData("superhero\\blah&foo.bin", "superhero\\blah&foo.bin")]
#if NET48
public void NormalizeOutputPathsTest(string outputPath, string expectedPath)
#else
public void NormalizeOutputPathsTest(string? outputPath, string? expectedPath)
#endif
{
if (!string.IsNullOrWhiteSpace(expectedPath))
expectedPath = Path.GetFullPath(expectedPath);
@@ -84,21 +76,13 @@ namespace MPF.Test.Library
CommonDiscInfo = new CommonDiscInfoSection()
{
Comments = "This is a comments line\n[T:ISBN] ISBN Value",
#if NET48
CommentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
CommentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.VolumeLabel] = "VOLUME_LABEL",
},
Contents = "This is a contents line\n[T:GF] Game Footage",
#if NET48
ContentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
ContentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.Patches] = "1.04 patch",
},
@@ -148,21 +132,13 @@ namespace MPF.Test.Library
CommonDiscInfo = new CommonDiscInfoSection()
{
Comments = null,
#if NET48
CommentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
CommentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.VolumeLabel] = "VOLUME_LABEL",
},
Contents = null,
#if NET48
ContentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
ContentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.Patches] = "1.04 patch",
},

View File

@@ -161,11 +161,7 @@ namespace MPF.Test.Modules
[InlineData(MediaType.FloppyDisk, ".img")]
[InlineData(MediaType.Cassette, ".wav")]
[InlineData(MediaType.NONE, null)]
#if NET48
public void MediaTypeToExtensionTest(MediaType? mediaType, string expected)
#else
public void MediaTypeToExtensionTest(MediaType? mediaType, string? expected)
#endif
{
var actual = Converters.Extension(mediaType);
Assert.Equal(expected, actual);

View File

@@ -95,31 +95,15 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of DiscType values
/// </summary>
/// <returns>MemberData-compatible list of DiscType values</returns>
#if NET48
public static List<object[]> GenerateDiscTypeMappingTestData()
#else
public static List<object?[]> GenerateDiscTypeMappingTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (DiscType? discType in Enum.GetValues(typeof(DiscType)))
{
if (_mappableDiscTypes.Contains(discType))
#if NET48
testData.Add(new object[] { discType, false });
#else
testData.Add(new object?[] { discType, false });
#endif
else
#if NET48
testData.Add(new object[] { discType, true });
#else
testData.Add(new object?[] { discType, true });
#endif
}
return testData;
@@ -129,24 +113,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of RedumpSystem values
/// </summary>
/// <returns>MemberData-compatible list of RedumpSystem values</returns>
#if NET48
public static List<object[]> GenerateRedumpSystemMappingTestData()
#else
public static List<object?[]> GenerateRedumpSystemMappingTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null } };
#else
var testData = new List<object?[]>() { new object?[] { null } };
#endif
foreach (RedumpSystem? redumpSystem in Enum.GetValues(typeof(RedumpSystem)))
{
#if NET48
testData.Add(new object[] { redumpSystem });
#else
testData.Add(new object?[] { redumpSystem });
#endif
}
return testData;
@@ -156,32 +128,16 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of mappable media types
/// </summary>
/// <returns>MemberData-compatible list of MediaTypes</returns>
#if NET48
public static List<object[]> GenerateMediaTypeMappingTestData()
#else
public static List<object?[]> GenerateMediaTypeMappingTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (MediaType? mediaType in Enum.GetValues(typeof(MediaType)))
{
if (_mappableMediaTypes.Contains(mediaType))
#if NET48
testData.Add(new object[] { mediaType, false });
#else
testData.Add(new object?[] { mediaType, false });
#endif
else
#if NET48
testData.Add(new object[] { mediaType, true });
#else
testData.Add(new object?[] { mediaType, true });
#endif
}
return testData;
@@ -212,24 +168,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of DiscCategory values
/// </summary>
/// <returns>MemberData-compatible list of DiscCategory values</returns>
#if NET48
public static List<object[]> GenerateDiscCategoryTestData()
#else
public static List<object?[]> GenerateDiscCategoryTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (DiscCategory? discCategory in Enum.GetValues(typeof(DiscCategory)))
{
#if NET48
testData.Add(new object[] { discCategory, false });
#else
testData.Add(new object?[] { discCategory, false });
#endif
}
return testData;
@@ -260,31 +204,15 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of DiscType values
/// </summary>
/// <returns>MemberData-compatible list of DiscType values</returns>
#if NET48
public static List<object[]> GenerateDiscTypeTestData()
#else
public static List<object?[]> GenerateDiscTypeTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (DiscType? discType in Enum.GetValues(typeof(DiscType)))
{
if (discType == DiscType.NONE)
#if NET48
testData.Add(new object[] { discType, true });
#else
testData.Add(new object?[] { discType, true });
#endif
else
#if NET48
testData.Add(new object[] { discType, false });
#else
testData.Add(new object?[] { discType, false });
#endif
}
return testData;
@@ -413,24 +341,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of Language values
/// </summary>
/// <returns>MemberData-compatible list of Language values</returns>
#if NET48
public static List<object[]> GenerateLanguageTestData()
#else
public static List<object?[]> GenerateLanguageTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (Language? language in Enum.GetValues(typeof(Language)))
{
#if NET48
testData.Add(new object[] { language, false });
#else
testData.Add(new object?[] { language, false });
#endif
}
return testData;
@@ -461,24 +377,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of LanguageSelection values
/// </summary>
/// <returns>MemberData-compatible list of LanguageSelection values</returns>
#if NET48
public static List<object[]> GenerateLanguageSelectionTestData()
#else
public static List<object?[]> GenerateLanguageSelectionTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (LanguageSelection? languageSelection in Enum.GetValues(typeof(LanguageSelection)))
{
#if NET48
testData.Add(new object[] { languageSelection, false });
#else
testData.Add(new object?[] { languageSelection, false });
#endif
}
return testData;
@@ -526,24 +430,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of MediaType values
/// </summary>
/// <returns>MemberData-compatible list of MediaType values</returns>
#if NET48
public static List<object[]> GenerateMediaTypeTestData()
#else
public static List<object?[]> GenerateMediaTypeTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (MediaType? mediaType in Enum.GetValues(typeof(MediaType)))
{
#if NET48
testData.Add(new object[] { mediaType, false });
#else
testData.Add(new object?[] { mediaType, false });
#endif
}
return testData;
@@ -618,24 +510,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of Region values
/// </summary>
/// <returns>MemberData-compatible list of Region values</returns>
#if NET48
public static List<object[]> GenerateRegionTestData()
#else
public static List<object?[]> GenerateRegionTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (Region? region in Enum.GetValues(typeof(Region)))
{
#if NET48
testData.Add(new object[] { region, false });
#else
testData.Add(new object?[] { region, false });
#endif
}
return testData;
@@ -683,24 +563,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of SiteCode values
/// </summary>
/// <returns>MemberData-compatible list of SiteCode values</returns>
#if NET48
public static List<object[]> GenerateSiteCodeTestData()
#else
public static List<object?[]> GenerateSiteCodeTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (SiteCode? siteCode in Enum.GetValues(typeof(SiteCode)))
{
#if NET48
testData.Add(new object[] { siteCode, false });
#else
testData.Add(new object?[] { siteCode, false });
#endif
}
return testData;
@@ -754,28 +622,16 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of RedumpSystem values
/// </summary>
/// <returns>MemberData-compatible list of RedumpSystem values</returns>
#if NET48
public static List<object[]> GenerateRedumpSystemTestData()
#else
public static List<object?[]> GenerateRedumpSystemTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (RedumpSystem? redumpSystem in Enum.GetValues(typeof(RedumpSystem)))
{
// We want to skip all markers for this
if (redumpSystem.IsMarker())
continue;
#if NET48
testData.Add(new object[] { redumpSystem, false });
#else
testData.Add(new object?[] { redumpSystem, false });
#endif
}
return testData;
@@ -806,31 +662,15 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of SystemCategory values
/// </summary>
/// <returns>MemberData-compatible list of SystemCategory values</returns>
#if NET48
public static List<object[]> GenerateSystemCategoryTestData()
#else
public static List<object?[]> GenerateSystemCategoryTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, true } };
#else
var testData = new List<object?[]>() { new object?[] { null, true } };
#endif
foreach (SystemCategory? systemCategory in Enum.GetValues(typeof(SystemCategory)))
{
if (systemCategory == SystemCategory.NONE)
#if NET48
testData.Add(new object[] { systemCategory, true });
#else
testData.Add(new object?[] { systemCategory, true });
#endif
else
#if NET48
testData.Add(new object[] { systemCategory, false });
#else
testData.Add(new object?[] { systemCategory, false });
#endif
}
return testData;
@@ -861,24 +701,12 @@ namespace MPF.Test.RedumpLib
/// Generate a test set of YesNo values
/// </summary>
/// <returns>MemberData-compatible list of YesNo values</returns>
#if NET48
public static List<object[]> GenerateYesNoTestData()
#else
public static List<object?[]> GenerateYesNoTestData()
#endif
{
#if NET48
var testData = new List<object[]>() { new object[] { null, false } };
#else
var testData = new List<object?[]>() { new object?[] { null, false } };
#endif
foreach (YesNo? yesNo in Enum.GetValues(typeof(YesNo)))
{
#if NET48
testData.Add(new object[] { yesNo, false });
#else
testData.Add(new object?[] { yesNo, false });
#endif
}
return testData;

View File

@@ -81,20 +81,12 @@ namespace MPF.Test.RedumpLib
EXEDateBuildDate = "19xx-xx-xx",
ErrorsCount = "0",
Comments = "Comment data line 1\r\nComment data line 2",
#if NET48
CommentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
CommentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.ISBN] = "ISBN",
},
Contents = "Special contents 1\r\nSpecial contents 2",
#if NET48
ContentsSpecialFields = new Dictionary<SiteCode?, string>()
#else
ContentsSpecialFields = new Dictionary<SiteCode, string>()
#endif
{
[SiteCode.PlayableDemos] = "Game Demo 1",
},

View File

@@ -30,18 +30,10 @@ namespace MPF.UI.Core
}
}
#if NET48
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
#else
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
#endif
{
// If it's an IElement but ends up null
#if NET48
if (!(value is IElement element))
#else
if (value is not IElement element)
#endif
return null;
switch (element)

View File

@@ -173,11 +173,7 @@ namespace WPFCustomMessageBox
/// </param>
/// <param name="timeoutResult">If the message box closes automatically due to the <paramref name="timeout"/> being exceeded, this result is returned.</param>
/// <returns>A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.</returns>
#if NET48
public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, int? timeout = null, MessageBoxResult timeoutResult = MessageBoxResult.None)
#else
public static MessageBoxResult Show(Window owner, string? messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, int? timeout = null, MessageBoxResult timeoutResult = MessageBoxResult.None)
#endif
{
switch (button)
{
@@ -519,11 +515,7 @@ namespace WPFCustomMessageBox
/// <param name="timeout">The message box will close automatically after given milliseconds</param>
/// <param name="timeoutResult">If the message box closes automatically due to <paramref name="timeout"/> being exceeded, this result is returned.</param>
/// <returns>A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.</returns>
#if NET48
private static MessageBoxResult ShowOKMessage(Window owner, string messageBoxText, string caption, string okButtonText, string cancelButtonText, MessageBoxImage? icon, int? timeout = null, MessageBoxResult timeoutResult = MessageBoxResult.None)
#else
private static MessageBoxResult ShowOKMessage(Window? owner, string? messageBoxText, string caption, string? okButtonText, string? cancelButtonText, MessageBoxImage? icon, int? timeout = null, MessageBoxResult timeoutResult = MessageBoxResult.None)
#endif
{
MessageBoxButton buttonLayout = string.IsNullOrEmpty(cancelButtonText) ? MessageBoxButton.OK : MessageBoxButton.OKCancel;
@@ -553,11 +545,7 @@ namespace WPFCustomMessageBox
/// <param name="timeout">The message box will close automatically after given milliseconds</param>
/// <param name="timeoutResult">If the message box closes automatically due to <paramref name="timeout"/> being exceeded, this result is returned.</param>
/// <returns>A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.</returns>
#if NET48
private static MessageBoxResult ShowYesNoMessage(Window owner, string messageBoxText, string caption, string yesButtonText, string noButtonText, string cancelButtonText, MessageBoxImage? icon, int? timeout = null, MessageBoxResult timeoutResult = MessageBoxResult.None)
#else
private static MessageBoxResult ShowYesNoMessage(Window? owner, string? messageBoxText, string caption, string? yesButtonText, string? noButtonText, string? cancelButtonText, MessageBoxImage? icon, int? timeout = null, MessageBoxResult timeoutResult = MessageBoxResult.None)
#endif
{
MessageBoxButton buttonLayout = string.IsNullOrEmpty(cancelButtonText) ? MessageBoxButton.YesNo : MessageBoxButton.YesNoCancel;

View File

@@ -12,11 +12,7 @@ namespace WPFCustomMessageBox
{
private readonly bool _removeTitleBarIcon = true;
#if NET48
public string Caption
#else
public string? Caption
#endif
{
get
{
@@ -28,11 +24,7 @@ namespace WPFCustomMessageBox
}
}
#if NET48
public string Message
#else
public string? Message
#endif
{
get
{
@@ -44,11 +36,7 @@ namespace WPFCustomMessageBox
}
}
#if NET48
public string OkButtonText
#else
public string? OkButtonText
#endif
{
get
{
@@ -60,11 +48,7 @@ namespace WPFCustomMessageBox
}
}
#if NET48
public string CancelButtonText
#else
public string? CancelButtonText
#endif
{
get
{
@@ -76,11 +60,7 @@ namespace WPFCustomMessageBox
}
}
#if NET48
public string YesButtonText
#else
public string? YesButtonText
#endif
{
get
{
@@ -92,11 +72,7 @@ namespace WPFCustomMessageBox
}
}
#if NET48
public string NoButtonText
#else
public string? NoButtonText
#endif
{
get
{
@@ -110,11 +86,7 @@ namespace WPFCustomMessageBox
public MessageBoxResult Result { get; set; }
#if NET48
internal CustomMessageBoxWindow(Window owner, string message, string caption = null, MessageBoxButton? button = null, MessageBoxImage? image = null, bool removeTitleBarIcon = true)
#else
internal CustomMessageBoxWindow(Window? owner, string? message, string? caption = null, MessageBoxButton? button = null, MessageBoxImage? image = null, bool removeTitleBarIcon = true)
#endif
{
InitializeComponent();

View File

@@ -60,11 +60,7 @@ namespace WPFCustomMessageBox
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
#if NET48
internal static string TryAddKeyboardAccellerator(this string input)
#else
internal static string? TryAddKeyboardAccellerator(this string? input)
#endif
{
if (input == null)
return input;

View File

@@ -13,56 +13,32 @@ namespace MPF.UI.Core
/// <summary>
/// SolidColorBrush used to paint the active window's border.
/// </summary>
#if NET48
public SolidColorBrush ActiveBorderBrush { get; protected set; }
#else
public SolidColorBrush? ActiveBorderBrush { get; protected set; }
#endif
/// <summary>
/// SolidColorBrush that paints the face of a three-dimensional display element.
/// </summary>
#if NET48
public SolidColorBrush ControlBrush { get; protected set; }
#else
public SolidColorBrush? ControlBrush { get; protected set; }
#endif
/// <summary>
/// SolidColorBrush that paints text in a three-dimensional display element.
/// </summary>
#if NET48
public SolidColorBrush ControlTextBrush { get; protected set; }
#else
public SolidColorBrush? ControlTextBrush { get; protected set; }
#endif
/// <summary>
/// SolidColorBrush that paints disabled text.
/// </summary>
#if NET48
public SolidColorBrush GrayTextBrush { get; protected set; }
#else
public SolidColorBrush? GrayTextBrush { get; protected set; }
#endif
/// <summary>
/// SolidColorBrush that paints the background of a window's client area.
/// </summary>
#if NET48
public SolidColorBrush WindowBrush { get; protected set; }
#else
public SolidColorBrush? WindowBrush { get; protected set; }
#endif
/// <summary>
/// SolidColorBrush that paints the text in the client area of a window.
/// </summary>
#if NET48
public SolidColorBrush WindowTextBrush { get; protected set; }
#else
public SolidColorBrush? WindowTextBrush { get; protected set; }
#endif
#endregion
@@ -71,38 +47,22 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the Button.Disabled.Background resource
/// </summary>
#if NET48
public Brush Button_Disabled_Background { get; protected set; }
#else
public Brush? Button_Disabled_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the Button.MouseOver.Background resource
/// </summary>
#if NET48
public Brush Button_MouseOver_Background { get; protected set; }
#else
public Brush? Button_MouseOver_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the Button.Pressed.Background resource
/// </summary>
#if NET48
public Brush Button_Pressed_Background { get; protected set; }
#else
public Brush? Button_Pressed_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the Button.Static.Background resource
/// </summary>
#if NET48
public Brush Button_Static_Background { get; protected set; }
#else
public Brush? Button_Static_Background { get; protected set; }
#endif
#endregion
@@ -111,110 +71,62 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the ComboBox.Disabled.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Disabled_Background { get; protected set; }
#else
public Brush? ComboBox_Disabled_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Disabled.Editable.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Disabled_Editable_Background { get; protected set; }
#else
public Brush? ComboBox_Disabled_Editable_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Disabled.Editable.Button.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Disabled_Editable_Button_Background { get; protected set; }
#else
public Brush? ComboBox_Disabled_Editable_Button_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.MouseOver.Background resource
/// </summary>
#if NET48
public Brush ComboBox_MouseOver_Background { get; protected set; }
#else
public Brush? ComboBox_MouseOver_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.MouseOver.Editable.Background resource
/// </summary>
#if NET48
public Brush ComboBox_MouseOver_Editable_Background { get; protected set; }
#else
public Brush? ComboBox_MouseOver_Editable_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.MouseOver.Editable.Button.Background resource
/// </summary>
#if NET48
public Brush ComboBox_MouseOver_Editable_Button_Background { get; protected set; }
#else
public Brush? ComboBox_MouseOver_Editable_Button_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Pressed.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Pressed_Background { get; protected set; }
#else
public Brush? ComboBox_Pressed_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Pressed.Editable.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Pressed_Editable_Background { get; protected set; }
#else
public Brush? ComboBox_Pressed_Editable_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Pressed.Editable.Button.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Pressed_Editable_Button_Background { get; protected set; }
#else
public Brush? ComboBox_Pressed_Editable_Button_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Static.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Static_Background { get; protected set; }
#else
public Brush? ComboBox_Static_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Static.Editable.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Static_Editable_Background { get; protected set; }
#else
public Brush? ComboBox_Static_Editable_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the ComboBox.Static.Editable.Button.Background resource
/// </summary>
#if NET48
public Brush ComboBox_Static_Editable_Button_Background { get; protected set; }
#else
public Brush? ComboBox_Static_Editable_Button_Background { get; protected set; }
#endif
#endregion
@@ -223,11 +135,7 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the CustomMessageBox.Static.Background resource
/// </summary>
#if NET48
public Brush CustomMessageBox_Static_Background { get; protected set; }
#else
public Brush? CustomMessageBox_Static_Background { get; protected set; }
#endif
#endregion
@@ -236,20 +144,12 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the MenuItem.SubMenu.Background resource
/// </summary>
#if NET48
public Brush MenuItem_SubMenu_Background { get; protected set; }
#else
public Brush? MenuItem_SubMenu_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the MenuItem.SubMenu.Border resource
/// </summary>
#if NET48
public Brush MenuItem_SubMenu_Border { get; protected set; }
#else
public Brush? MenuItem_SubMenu_Border { get; protected set; }
#endif
#endregion
@@ -258,11 +158,7 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the ProgressBar.Background resource
/// </summary>
#if NET48
public Brush ProgressBar_Background { get; protected set; }
#else
public Brush? ProgressBar_Background { get; protected set; }
#endif
#endregion
@@ -271,11 +167,7 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the ScrollViewer.ScrollBar.Background resource
/// </summary>
#if NET48
public Brush ScrollViewer_ScrollBar_Background { get; protected set; }
#else
public Brush? ScrollViewer_ScrollBar_Background { get; protected set; }
#endif
#endregion
@@ -284,29 +176,17 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the TabItem.Selected.Background resource
/// </summary>
#if NET48
public Brush TabItem_Selected_Background { get; protected set; }
#else
public Brush? TabItem_Selected_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the TabItem.Static.Background resource
/// </summary>
#if NET48
public Brush TabItem_Static_Background { get; protected set; }
#else
public Brush? TabItem_Static_Background { get; protected set; }
#endif
/// <summary>
/// Brush for the TabItem.Static.Border resource
/// </summary>
#if NET48
public Brush TabItem_Static_Border { get; protected set; }
#else
public Brush? TabItem_Static_Border { get; protected set; }
#endif
#endregion
@@ -315,11 +195,7 @@ namespace MPF.UI.Core
/// <summary>
/// Brush for the TextBox.Static.Background resource
/// </summary>
#if NET48
public Brush TextBox_Static_Background { get; protected set; }
#else
public Brush? TextBox_Static_Background { get; protected set; }
#endif
#endregion

View File

@@ -29,11 +29,7 @@ namespace MPF.UI.Core.UserControls
/// <summary>
/// Cached value of the last line written
/// </summary>
#if NET48
private Run lastLine = null;
#else
private Run? lastLine = null;
#endif
public LogOutput()
{
@@ -168,11 +164,7 @@ namespace MPF.UI.Core.UserControls
{
Dispatcher.Invoke(() =>
{
#if NET48
if (lastLine == null) lastLine = new Run();
#else
lastLine ??= new Run();
#endif
lastLine.Text = logLine.Text;
lastLine.Foreground = logLine.GetForegroundColor();
});

View File

@@ -20,11 +20,7 @@ namespace MPF.UI.Core.Windows
/// <summary>
/// Constructor
/// </summary>
#if NET48
public DiscInformationWindow(Options options, SubmissionInfo submissionInfo)
#else
public DiscInformationWindow(Options options, SubmissionInfo? submissionInfo)
#endif
{
InitializeComponent();
DataContext = new DiscInformationViewModel(options, submissionInfo);
@@ -51,11 +47,7 @@ namespace MPF.UI.Core.Windows
/// <summary>
/// Manipulate fields based on the current disc
/// </summary>
#if NET48
private void ManipulateFields(Options options, SubmissionInfo submissionInfo)
#else
private void ManipulateFields(Options options, SubmissionInfo? submissionInfo)
#endif
{
// Enable tabs in all fields, if required
if (options.EnableTabsInInputFields)
@@ -123,11 +115,7 @@ namespace MPF.UI.Core.Windows
/// </summary>
/// TODO: Figure out how to bind the PartiallyMatchedIDs array to a text box
/// TODO: Convert visibility to a binding
#if NET48
private void HideReadOnlyFields(SubmissionInfo submissionInfo)
#else
private void HideReadOnlyFields(SubmissionInfo? submissionInfo)
#endif
{
// If there's no submission information
if (submissionInfo == null)
@@ -195,11 +183,7 @@ namespace MPF.UI.Core.Windows
/// Update visible fields and sections based on the media type
/// </summary>
/// TODO: See if these can be done by binding
#if NET48
private void UpdateFromDiscType(SubmissionInfo submissionInfo)
#else
private void UpdateFromDiscType(SubmissionInfo? submissionInfo)
#endif
{
// Sony-printed discs have layers in the opposite order
var system = submissionInfo?.CommonDiscInfo?.System;
@@ -346,11 +330,7 @@ namespace MPF.UI.Core.Windows
/// Update visible fields and sections based on the system type
/// </summary>
/// TODO: See if these can be done by binding
#if NET48
private void UpdateFromSystemType(SubmissionInfo submissionInfo)
#else
private void UpdateFromSystemType(SubmissionInfo? submissionInfo)
#endif
{
var system = submissionInfo?.CommonDiscInfo?.System;
switch (system)

View File

@@ -210,11 +210,7 @@ namespace MPF.UI.Core.Windows
/// </summary>
/// <param name="submissionInfo">SubmissionInfo object to display and possibly change</param>
/// <returns>Dialog open result</returns>
#if NET48
public (bool?, SubmissionInfo) ShowDiscInformationWindow(SubmissionInfo submissionInfo)
#else
public (bool?, SubmissionInfo?) ShowDiscInformationWindow(SubmissionInfo? submissionInfo)
#endif
{
if (MainViewModel.Options.ShowDiscEjectReminder)
CustomMessageBox.Show(this, "It is now safe to eject the disc", "Eject", MessageBoxButton.OK, MessageBoxImage.Information);
@@ -233,27 +229,15 @@ namespace MPF.UI.Core.Windows
// Copy back the submission info changes, if necessary
if (result == true)
#if NET48
submissionInfo = discInformationWindow.DiscInformationViewModel.SubmissionInfo.Clone() as SubmissionInfo;
#else
submissionInfo = (discInformationWindow.DiscInformationViewModel.SubmissionInfo.Clone() as SubmissionInfo)!;
#endif
#if NET48
return (result, submissionInfo);
#else
return (result, submissionInfo!);
#endif
}
/// <summary>
/// Show the Options window
/// </summary>
#if NET48
public void ShowOptionsWindow(string title = null)
#else
public void ShowOptionsWindow(string? title = null)
#endif
{
var optionsWindow = new OptionsWindow(MainViewModel.Options)
{
@@ -291,11 +275,7 @@ namespace MPF.UI.Core.Windows
/// <summary>
/// Handler for OptionsWindow OnUpdated event
/// </summary>
#if NET48
public void OnOptionsUpdated(object sender, EventArgs e)
#else
public void OnOptionsUpdated(object? sender, EventArgs e)
#endif
{
// Get the options window
var optionsWindow = (sender as OptionsWindow);

View File

@@ -58,22 +58,14 @@ namespace MPF.UI.Core.Windows
/// <summary>
/// Browse and set a path based on the invoking button
/// </summary>
#if NET48
private void BrowseForPath(Window parent, System.Windows.Controls.Button button)
#else
private void BrowseForPath(Window parent, System.Windows.Controls.Button? button)
#endif
{
// If the button is null, we can't do anything
if (button == null)
return;
// Strips button prefix to obtain the setting name
#if NET48
string pathSettingName = button.Name.Substring(0, button.Name.IndexOf("Button"));
#else
string pathSettingName = button.Name[..button.Name.IndexOf("Button")];
#endif
// TODO: hack for now, then we'll see
bool shouldBrowseForPath = pathSettingName == "DefaultOutputPath";
@@ -130,30 +122,18 @@ namespace MPF.UI.Core.Windows
/// </summary>
/// <param name="name">Setting name to find</param>
/// <returns>TextBox for that setting</returns>
#if NET48
private static System.Windows.Controls.TextBox TextBoxForPathSetting(Window parent, string name) =>
#else
private static System.Windows.Controls.TextBox? TextBoxForPathSetting(Window parent, string name) =>
#endif
parent.FindName(name + "TextBox") as System.Windows.Controls.TextBox;
/// <summary>
/// Create an open folder dialog box
/// </summary>
#if NET48
private static FolderBrowserDialog CreateFolderBrowserDialog() => new FolderBrowserDialog();
#else
private static FolderBrowserDialog CreateFolderBrowserDialog() => new();
#endif
/// <summary>
/// Create an open file dialog box
/// </summary>
#if NET48
private static OpenFileDialog CreateOpenFileDialog(string initialDirectory)
#else
private static OpenFileDialog CreateOpenFileDialog(string? initialDirectory)
#endif
{
return new OpenFileDialog()
{
@@ -167,17 +147,9 @@ namespace MPF.UI.Core.Windows
/// <summary>
/// Test Redump credentials for validity
/// </summary>
#if NET48
private void ValidateRedumpCredentials()
#else
private async Task ValidateRedumpCredentials()
#endif
{
#if NET48
(bool? success, string message) = OptionsViewModel.TestRedumpLogin(RedumpUsernameTextBox.Text, RedumpPasswordBox.Password);
#else
(bool? success, string? message) = await OptionsViewModel.TestRedumpLogin(RedumpUsernameTextBox.Text, RedumpPasswordBox.Password);
#endif
if (success == true)
CustomMessageBox.Show(this, message, "Success", MessageBoxButton.OK, MessageBoxImage.Information);
@@ -226,11 +198,7 @@ namespace MPF.UI.Core.Windows
/// <summary>
/// Test Redump credentials for validity
/// </summary>
#if NET48
private void OnRedumpTestClick(object sender, EventArgs e) => ValidateRedumpCredentials();
#else
private async void OnRedumpTestClick(object sender, EventArgs e) => await ValidateRedumpCredentials();
#endif
#endregion
}