mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Allow variables in output path (#624)
* Allow variables in output path and default output path * Remove angle brackets when normalising path * Add tooltip hover text for default output path * Better tooltip formatting * Use percent sign rather than angle brackets as variable delimiter * Refactor
This commit is contained in:
@@ -70,7 +70,9 @@ namespace MPF.Core.Data
|
||||
return volumeLabel;
|
||||
|
||||
if (!string.IsNullOrEmpty(this.VolumeLabel))
|
||||
{
|
||||
volumeLabel = this.VolumeLabel;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No Volume Label found, fallback to something sensible
|
||||
|
||||
@@ -1876,8 +1876,10 @@ namespace MPF.Core
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return string.Empty;
|
||||
|
||||
// Remove quotes from path
|
||||
// Remove quotes and angle brackets from path
|
||||
path = path!.Replace("\"", string.Empty);
|
||||
path = path!.Replace("<", string.Empty);
|
||||
path = path!.Replace(">", string.Empty);
|
||||
|
||||
// Try getting the combined path and returning that directly
|
||||
string fullPath = getFullPath ? Path.GetFullPath(path) : path;
|
||||
|
||||
@@ -148,6 +148,7 @@ namespace MPF.Core.UI.ViewModels
|
||||
|
||||
/// <summary>
|
||||
/// Currently provided output path
|
||||
/// Not guaranteed to be a valid path
|
||||
/// </summary>
|
||||
public string OutputPath
|
||||
{
|
||||
@@ -1190,7 +1191,7 @@ namespace MPF.Core.UI.ViewModels
|
||||
{
|
||||
return new DumpEnvironment(
|
||||
this.Options,
|
||||
this.OutputPath,
|
||||
EvaluateOutputPath(this.OutputPath),
|
||||
this.CurrentDrive,
|
||||
this.CurrentSystem,
|
||||
this.CurrentMediaType,
|
||||
@@ -1299,6 +1300,49 @@ namespace MPF.Core.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces %-delimited variables inside a path string with their values
|
||||
/// </summary>
|
||||
/// <param name="outputPath">Path to be evaluated</param>
|
||||
/// <returns>String with %-delimited variables evaluated</returns>
|
||||
public string EvaluateOutputPath(string outputPath)
|
||||
{
|
||||
string systemLong = this._currentSystem.LongName() ?? "Unknown System";
|
||||
if (string.IsNullOrEmpty(systemLong))
|
||||
systemLong = "Unknown System";
|
||||
string systemShort = this._currentSystem.ShortName() ?? "unknown";
|
||||
if (string.IsNullOrEmpty(systemShort))
|
||||
systemShort = "unknown";
|
||||
string mediaLong = this._currentMediaType.LongName() ?? "Unknown Media";
|
||||
if (string.IsNullOrEmpty(mediaLong))
|
||||
mediaLong = "Unknown Media";
|
||||
string program = this._currentProgram.ToString() ?? "Unknown Program";
|
||||
if (string.IsNullOrEmpty(program))
|
||||
program = "Unknown Program";
|
||||
string programShort = program == "DiscImageCreator" ? "DIC" : program;
|
||||
if (string.IsNullOrEmpty(programShort))
|
||||
programShort = "Unknown Program";
|
||||
string label = this._currentDrive?.FormattedVolumeLabel ?? "track";
|
||||
if (string.IsNullOrEmpty(label))
|
||||
label = "track";
|
||||
string date = DateTime.Today.ToString("yyyyMMdd");
|
||||
if (string.IsNullOrEmpty(date))
|
||||
date = "UNKNOWN";
|
||||
string datetime = DateTime.Now.ToString("yyyyMMdd-HHmmss");
|
||||
if (string.IsNullOrEmpty(datetime))
|
||||
datetime = "UNKNOWN";
|
||||
|
||||
return outputPath
|
||||
.Replace("%SYSTEM%", systemLong)
|
||||
.Replace("%SYS%", systemShort)
|
||||
.Replace("%MEDIA%", mediaLong)
|
||||
.Replace("%PROGRAM%", program)
|
||||
.Replace("%PROG%", programShort)
|
||||
.Replace("%LABEL%", label)
|
||||
.Replace("%DATE%", date)
|
||||
.Replace("%DATETIME%", datetime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the default output directory name from the currently selected drive
|
||||
/// </summary>
|
||||
|
||||
@@ -181,7 +181,8 @@
|
||||
|
||||
<Label Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Default Output Path" />
|
||||
<TextBox x:Name="DefaultOutputPathTextBox" Grid.Row="4" Grid.Column="1" Height="22" HorizontalAlignment="Stretch"
|
||||
Text="{Binding Options.DefaultOutputPath}" VerticalContentAlignment="Center" />
|
||||
Text="{Binding Options.DefaultOutputPath}" VerticalContentAlignment="Center"
|
||||
ToolTip="Variables allowed:
 %SYSTEM%	(System name, long)
 %SYS%		(System name, short)
 %MEDIA%	(Media type)
 %PROGRAM%	(Program name, long)
 %PROG%	(Program name, short)
 %LABEL%	(Volume label)
 %DATE%	(Current date)
 %DATETIME%	(Current date and time)"/>
|
||||
<Button x:Name="DefaultOutputPathButton" Grid.Row="4" Grid.Column="2" Height="22" Width="22" Content="..."
|
||||
Style="{DynamicResource CustomButtonStyle}" />
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user