mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Handle invalid characters when changing program
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
- Normalize publish scripts
|
||||
- Update AppVeyor to match scripts
|
||||
- Add release publish scripts
|
||||
- Handle invalid characters when changing program
|
||||
|
||||
### 2.6.4 (2023-09-25)
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace MPF.Library
|
||||
this.Options = options;
|
||||
|
||||
// Output paths
|
||||
this.OutputPath = InfoTool.NormalizeOutputPaths(outputPath);
|
||||
this.OutputPath = InfoTool.NormalizeOutputPaths(outputPath, true);
|
||||
|
||||
// UI information
|
||||
this.Drive = drive;
|
||||
@@ -131,7 +131,7 @@ namespace MPF.Library
|
||||
try
|
||||
{
|
||||
// Normalize the output path
|
||||
string outputPath = InfoTool.NormalizeOutputPaths(this.OutputPath);
|
||||
string outputPath = InfoTool.NormalizeOutputPaths(this.OutputPath, true);
|
||||
|
||||
// Replace all instances in the output directory
|
||||
string outputDirectory = Path.GetDirectoryName(outputPath);
|
||||
@@ -498,7 +498,7 @@ namespace MPF.Library
|
||||
return Result.Failure("Error! Current configuration is not supported!");
|
||||
|
||||
// Fix the output paths, just in case
|
||||
this.OutputPath = InfoTool.NormalizeOutputPaths(this.OutputPath);
|
||||
this.OutputPath = InfoTool.NormalizeOutputPaths(this.OutputPath, true);
|
||||
|
||||
// Validate that the output path isn't on the dumping drive
|
||||
if (this.OutputPath[0] == Drive.Letter)
|
||||
|
||||
@@ -1682,16 +1682,20 @@ namespace MPF.Library
|
||||
/// Normalize a split set of paths
|
||||
/// </summary>
|
||||
/// <param name="path">Path value to normalize</param>
|
||||
public static string NormalizeOutputPaths(string path)
|
||||
public static string NormalizeOutputPaths(string path, bool getFullPath)
|
||||
{
|
||||
// The easy way
|
||||
try
|
||||
{
|
||||
// Trim quotes from the path
|
||||
path = path.Trim('"');
|
||||
// If we have an invalid path
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return string.Empty;
|
||||
|
||||
// Remove quotes from path
|
||||
path = path.Replace("\"", string.Empty);
|
||||
|
||||
// Try getting the combined path and returning that directly
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
string fullPath = getFullPath ? Path.GetFullPath(path) : path;
|
||||
string fullDirectory = Path.GetDirectoryName(fullPath);
|
||||
string fullFile = Path.GetFileName(fullPath);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace MPF.Test.Library
|
||||
if (!string.IsNullOrWhiteSpace(expectedPath))
|
||||
expectedPath = Path.GetFullPath(expectedPath);
|
||||
|
||||
string actualPath = InfoTool.NormalizeOutputPaths(outputPath);
|
||||
string actualPath = InfoTool.NormalizeOutputPaths(outputPath, false);
|
||||
Assert.Equal(expectedPath, actualPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -1033,8 +1033,9 @@ namespace MPF.UI.Core.ViewModels
|
||||
else if (driveChanged)
|
||||
{
|
||||
string label = drive?.FormattedVolumeLabel ?? systemType.LongName();
|
||||
string oldFilename = Path.GetFileNameWithoutExtension(this.Parent.OutputPathTextBox.Text);
|
||||
string directory = Path.GetDirectoryName(this.Parent.OutputPathTextBox.Text);
|
||||
string oldPath = InfoTool.NormalizeOutputPaths(this.Parent.OutputPathTextBox.Text, false);
|
||||
string oldFilename = Path.GetFileNameWithoutExtension(oldPath);
|
||||
string directory = Path.GetDirectoryName(oldPath);
|
||||
string filename = $"{label}{extension ?? ".bin"}";
|
||||
|
||||
// If the previous path included the label
|
||||
@@ -1051,8 +1052,9 @@ namespace MPF.UI.Core.ViewModels
|
||||
// Otherwise, reset the extension of the currently set path
|
||||
else
|
||||
{
|
||||
string filename = Path.GetFileNameWithoutExtension(this.Parent.OutputPathTextBox.Text);
|
||||
string directory = Path.GetDirectoryName(this.Parent.OutputPathTextBox.Text);
|
||||
string oldPath = InfoTool.NormalizeOutputPaths(this.Parent.OutputPathTextBox.Text, false);
|
||||
string filename = Path.GetFileNameWithoutExtension(oldPath);
|
||||
string directory = Path.GetDirectoryName(oldPath);
|
||||
filename = $"{filename}{extension ?? ".bin"}";
|
||||
|
||||
this.Parent.OutputPathTextBox.Text = Path.Combine(directory, filename);
|
||||
@@ -1089,9 +1091,7 @@ namespace MPF.UI.Core.ViewModels
|
||||
// Disable change handling
|
||||
DisableEventHandlers();
|
||||
|
||||
string trimmedPath = Env.Parameters.OutputPath?.Trim('"') ?? string.Empty;
|
||||
trimmedPath = InfoTool.NormalizeOutputPaths(trimmedPath);
|
||||
this.Parent.OutputPathTextBox.Text = trimmedPath;
|
||||
this.Parent.OutputPathTextBox.Text = InfoTool.NormalizeOutputPaths(Env.Parameters.OutputPath, true);
|
||||
|
||||
MediaType? mediaType = Env.Parameters.GetMediaType();
|
||||
int mediaTypeIndex = MediaTypes.FindIndex(m => m == mediaType);
|
||||
|
||||
Reference in New Issue
Block a user