mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Add unused command filename parser
This commit is contained in:
@@ -130,6 +130,7 @@
|
||||
- Possibly fix PIC parsing
|
||||
- Add PS3 folder/file checks for detection
|
||||
- Use default directory for folder browsing, if possible
|
||||
- Add unused command filename parser
|
||||
|
||||
### 2.3 (2022-02-05)
|
||||
- Start overhauling Redump information pulling, again
|
||||
|
||||
@@ -2402,6 +2402,34 @@ namespace MPF.Modules.DiscImageCreator
|
||||
|
||||
#region Private Extra Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get the command file path and extract the version from it
|
||||
/// </summary>
|
||||
/// <param name="basePath">Base filename and path to use for checking</param>
|
||||
/// <returns>Tuple of file path and version as strings, both null on error</returns>
|
||||
private static (string, string) GetCommandFilePathAndVersion(string basePath)
|
||||
{
|
||||
// If we have an invalid base path, we can do nothing
|
||||
if (string.IsNullOrWhiteSpace(basePath))
|
||||
return (null, null);
|
||||
|
||||
// Generate the matching regex based on the base path
|
||||
string basePathFileName = Path.GetFileName(basePath);
|
||||
Regex cmdFilenameRegex = new Regex(Regex.Escape(basePathFileName) + @"_(\d{8})T\d{6}\.txt");
|
||||
|
||||
// Find the first match for the command file
|
||||
string parentDirectory = Path.GetDirectoryName(basePath);
|
||||
var currentFiles = Directory.GetFiles(parentDirectory);
|
||||
string commandPath = currentFiles.FirstOrDefault(f => cmdFilenameRegex.IsMatch(f));
|
||||
if (string.IsNullOrWhiteSpace(commandPath))
|
||||
return (null, null);
|
||||
|
||||
// Extract the version string
|
||||
var match = cmdFilenameRegex.Match(commandPath);
|
||||
string version = match.Groups[1].Value;
|
||||
return (commandPath, version);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the DIC command to be used for a given system and media type
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user