Add unused command filename parser

This commit is contained in:
Matt Nadareski
2022-10-05 12:08:11 -07:00
parent 60605d7d00
commit a9e7b6f5b3
2 changed files with 29 additions and 0 deletions

View File

@@ -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

View File

@@ -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>