From 95fa6510747b82684c9a67c84c27457e730bdecf Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 20 Aug 2024 23:26:42 -0400 Subject: [PATCH] Move MSXC parsing to PhysicalTool --- CHANGELIST.md | 1 + MPF.Frontend/Tools/PhysicalTool.cs | 34 +++++++++++++++++++++++ MPF.Frontend/Tools/SubmissionGenerator.cs | 22 ++------------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 0d394d47..8428a090 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -26,6 +26,7 @@ - Include serial for UMD - Remove GD-ROM version fallback method - Preemptively update Redumper Saturn support +- Move MSXC parsing to PhysicalTool ### 3.2.1 (2024-08-05) diff --git a/MPF.Frontend/Tools/PhysicalTool.cs b/MPF.Frontend/Tools/PhysicalTool.cs index 546c96bd..dc52920a 100644 --- a/MPF.Frontend/Tools/PhysicalTool.cs +++ b/MPF.Frontend/Tools/PhysicalTool.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using Newtonsoft.Json; @@ -528,6 +529,39 @@ namespace MPF.Frontend.Tools } } + /// + /// Get all filenames for Xbox One and Xbox Series X + /// + /// Drive to extract information from + /// Filenames if possible, null on error + public static string? GetXboxFilenames(Drive? drive) + { + // If there's no drive path, we can't get BEE flag + if (string.IsNullOrEmpty(drive?.Name)) + return null; + + // If the folder no longer exists, we can't get exe name + if (!Directory.Exists(drive!.Name)) + return null; + + // Get the MSXC directory path + string msxc = Path.Combine(drive.Name, "MSXC"); + if (!Directory.Exists(msxc)) + return null; + + try + { + var files = Directory.GetFiles(msxc, "*", SearchOption.TopDirectoryOnly); + var filenames = files.Select(Path.GetFileName).ToArray(); + return string.Join("\n", filenames); + } + catch + { + // We don't care what the error is right now + return null; + } + } + #endregion } } \ No newline at end of file diff --git a/MPF.Frontend/Tools/SubmissionGenerator.cs b/MPF.Frontend/Tools/SubmissionGenerator.cs index 91dc4c7a..391dae80 100644 --- a/MPF.Frontend/Tools/SubmissionGenerator.cs +++ b/MPF.Frontend/Tools/SubmissionGenerator.cs @@ -728,29 +728,11 @@ namespace MPF.Frontend.Tools break; case RedumpSystem.MicrosoftXboxOne: - if (drive?.Name != null) - { - string xboxOneMsxcPath = Path.Combine(drive.Name, "MSXC"); - if (drive != null && Directory.Exists(xboxOneMsxcPath)) - { - info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = string.Join("\n", - Directory.GetFiles(xboxOneMsxcPath, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName).ToArray()); - } - } - + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = PhysicalTool.GetXboxFilenames(drive) ?? string.Empty; break; case RedumpSystem.MicrosoftXboxSeriesXS: - if (drive?.Name != null) - { - string xboxSeriesXMsxcPath = Path.Combine(drive.Name, "MSXC"); - if (drive != null && Directory.Exists(xboxSeriesXMsxcPath)) - { - info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = string.Join("\n", - Directory.GetFiles(xboxSeriesXMsxcPath, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName).ToArray()); - } - } - + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.Filename] = PhysicalTool.GetXboxFilenames(drive) ?? string.Empty; break; case RedumpSystem.NamcoSegaNintendoTriforce: