mirror of
https://github.com/SabreTools/MPF.git
synced 2026-04-05 22:01:16 +00:00
Replace method already ported to IO
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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("<filename.bin>", false, "filename.bin")]
|
||||
[InlineData("<filename.bin>", 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a split set of paths
|
||||
/// </summary>
|
||||
/// <param name="path">Path value to normalize</param>
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user