diff --git a/CHANGELIST.md b/CHANGELIST.md index 6daee63c..7300819a 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -1,6 +1,7 @@ ### WIP (xxxx-xx-xx) - Display the path being processed in Check since multiple are allowed +- Replace method already ported to IO ### 3.7.0 (2026-03-20) diff --git a/MPF.CLI/Features/BaseFeature.cs b/MPF.CLI/Features/BaseFeature.cs index 7ff7cb67..d94b2313 100644 --- a/MPF.CLI/Features/BaseFeature.cs +++ b/MPF.CLI/Features/BaseFeature.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; #endif using MPF.Frontend; using MPF.Frontend.Tools; +using SabreTools.IO; using SabreTools.RedumpLib.Data; using SabreTools.RedumpLib.Web; using LogCompression = MPF.Processors.LogCompression; @@ -221,7 +222,7 @@ namespace MPF.CLI.Features } if (FilePath is not null) - FilePath = FrontendTool.NormalizeOutputPaths(FilePath, getFullPath: true); + FilePath = PathTool.NormalizeFilePath(FilePath, fullPath: true); // Get the speed from the options int speed = DriveSpeed ?? FrontendTool.GetDefaultSpeedForMediaType(MediaType, Options); diff --git a/MPF.Frontend.Test/Tools/FrontendToolTests.cs b/MPF.Frontend.Test/Tools/FrontendToolTests.cs index b4c53400..2a66dd84 100644 --- a/MPF.Frontend.Test/Tools/FrontendToolTests.cs +++ b/MPF.Frontend.Test/Tools/FrontendToolTests.cs @@ -1,4 +1,3 @@ -using System.IO; using MPF.Frontend.Tools; using SabreTools.RedumpLib.Data; using Xunit; @@ -61,38 +60,5 @@ namespace MPF.Frontend.Test.Tools // TODO: Write NormalizeDiscTitle(string?, Language?) test #endregion - - #region NormalizeOutputPaths - - [Theory] - [InlineData(null, false, "")] - [InlineData(null, true, "")] - [InlineData("", false, "")] - [InlineData("", true, "")] - [InlineData("filename.bin", false, "filename.bin")] - [InlineData("filename.bin", true, "filename.bin")] - [InlineData("\"filename.bin\"", false, "filename.bin")] - [InlineData("\"filename.bin\"", true, "filename.bin")] - [InlineData("", false, "filename.bin")] - [InlineData("", true, "filename.bin")] - [InlineData("1.2.3.4..bin", false, "1.2.3.4..bin")] - [InlineData("1.2.3.4..bin", true, "1.2.3.4..bin")] - [InlineData("dir/filename.bin", false, "dir/filename.bin")] - [InlineData("dir/filename.bin", true, "dir/filename.bin")] - [InlineData(" dir / filename.bin", false, "dir/filename.bin")] - [InlineData(" dir / filename.bin", true, "dir/filename.bin")] - [InlineData("\0dir/\0filename.bin", false, "_dir/_filename.bin")] - [InlineData("\0dir/\0filename.bin", true, "_dir/_filename.bin")] - public void NormalizeOutputPathsTest(string? path, bool getFullPath, string expected) - { - // Modify expected to account for test data if necessary - if (getFullPath && !string.IsNullOrEmpty(expected)) - expected = Path.GetFullPath(expected); - - string actual = FrontendTool.NormalizeOutputPaths(path, getFullPath); - Assert.Equal(expected, actual); - } - - #endregion } } diff --git a/MPF.Frontend/DumpEnvironment.cs b/MPF.Frontend/DumpEnvironment.cs index 05a1bf65..1a7da8bd 100644 --- a/MPF.Frontend/DumpEnvironment.cs +++ b/MPF.Frontend/DumpEnvironment.cs @@ -9,6 +9,7 @@ using MPF.ExecutionContexts; using MPF.Frontend.Tools; using MPF.Processors; using Newtonsoft.Json; +using SabreTools.IO; using SabreTools.RedumpLib; using SabreTools.RedumpLib.Data; using Formatting = Newtonsoft.Json.Formatting; @@ -116,7 +117,7 @@ namespace MPF.Frontend _options = new Options(options); // Output paths - OutputPath = FrontendTool.NormalizeOutputPaths(outputPath, false); + OutputPath = PathTool.NormalizeFilePath(outputPath, fullPath: false); // UI information _drive = drive; @@ -713,7 +714,7 @@ namespace MPF.Frontend return ResultEventArgs.Failure("Error! Current configuration is not supported!"); // Fix the output paths, just in case - OutputPath = FrontendTool.NormalizeOutputPaths(OutputPath, false); + OutputPath = PathTool.NormalizeFilePath(OutputPath, fullPath: false); // Validate that the output path isn't on the dumping drive if (_drive?.Name is not null && OutputPath.StartsWith(_drive.Name)) diff --git a/MPF.Frontend/Tools/FrontendTool.cs b/MPF.Frontend/Tools/FrontendTool.cs index 0dc266cc..158e7d7c 100644 --- a/MPF.Frontend/Tools/FrontendTool.cs +++ b/MPF.Frontend/Tools/FrontendTool.cs @@ -1,8 +1,6 @@ using System; -using System.IO; using System.Reflection; using System.Text; -using System.Text.RegularExpressions; using SabreTools.RedumpLib.Data; namespace MPF.Frontend.Tools @@ -529,52 +527,6 @@ namespace MPF.Frontend.Tools return newTitle; } - /// - /// Normalize a split set of paths - /// - /// Path value to normalize - public static string NormalizeOutputPaths(string? path, bool getFullPath) - { - try - { - // If we have an invalid path - if (string.IsNullOrEmpty(path)) - return string.Empty; - - // Remove quotes and angle brackets from path - path = path!.Trim('\"'); - path = path!.Trim('<'); - path = path!.Trim('>'); - - // Remove invalid path characters - foreach (char c in Path.GetInvalidPathChars()) - { - path = path.Replace(c, '_'); - } - - // Try getting the combined path and returning that directly - string fullPath = getFullPath ? Path.GetFullPath(path) : path; - var fullDirectory = Path.GetDirectoryName(fullPath)?.Trim(); - string fullFile = Path.GetFileName(fullPath).Trim(); - - // Remove invalid filename characters - foreach (char c in Path.GetInvalidFileNameChars()) - { - fullFile = fullFile.Replace(c, '_'); - } - - // Rebuild the path, if necessary - if (!string.IsNullOrEmpty(fullDirectory)) - fullFile = Path.Combine(fullDirectory, fullFile); - - // Remove spaces before and after separators - return Regex.Replace(fullFile, @"\s*([\\|/])\s*", @"$1"); - } - catch { } - - return path ?? string.Empty; - } - #endregion #region Versioning diff --git a/MPF.Frontend/ViewModels/MainViewModel.cs b/MPF.Frontend/ViewModels/MainViewModel.cs index 223035ad..56b0a188 100644 --- a/MPF.Frontend/ViewModels/MainViewModel.cs +++ b/MPF.Frontend/ViewModels/MainViewModel.cs @@ -1463,7 +1463,7 @@ namespace MPF.Frontend.ViewModels } // For all other cases, separate the last path - string lastPath = FrontendTool.NormalizeOutputPaths(OutputPath, false); + string lastPath = PathTool.NormalizeFilePath(OutputPath, fullPath: false); string lastDirectory = Path.GetDirectoryName(lastPath) ?? string.Empty; string lastFilename = Path.GetFileNameWithoutExtension(lastPath); @@ -1918,7 +1918,7 @@ namespace MPF.Frontend.ViewModels // Disable change handling DisableEventHandlers(); - OutputPath = FrontendTool.NormalizeOutputPaths(_environment.ContextOutputPath, false); + OutputPath = PathTool.NormalizeFilePath(_environment.ContextOutputPath, fullPath: false); if (MediaTypes is not null) {