diff --git a/ShareX.HelpersLib/ExternalProgram.cs b/ShareX.HelpersLib/ExternalProgram.cs index 239e54f05..17deb7220 100644 --- a/ShareX.HelpersLib/ExternalProgram.cs +++ b/ShareX.HelpersLib/ExternalProgram.cs @@ -79,8 +79,6 @@ public string Run(string filePath) } else { - string args = Args.Replace("%filepath%", '"' + filePath + '"').Replace("%input", '"' + filePath + '"'); - if (!string.IsNullOrEmpty(OutputExtension)) { newFilePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filePath), System.IO.Path.GetFileNameWithoutExtension(filePath)); @@ -91,10 +89,9 @@ public string Run(string filePath) } newFilePath += OutputExtension; - args = args.Replace("%output", '"' + newFilePath + '"'); } - psi.Arguments = args; + psi.Arguments = CodeMenuEntryActions.Parse(Args, filePath, newFilePath); } if (HiddenWindow) diff --git a/ShareX.HelpersLib/NameParser/CodeMenuEntryActions.cs b/ShareX.HelpersLib/NameParser/CodeMenuEntryActions.cs index 7c5c94ad3..862c2100d 100644 --- a/ShareX.HelpersLib/NameParser/CodeMenuEntryActions.cs +++ b/ShareX.HelpersLib/NameParser/CodeMenuEntryActions.cs @@ -31,11 +31,23 @@ public class CodeMenuEntryActions : CodeMenuEntry { protected override string Prefix { get; } = "%"; - public static readonly CodeMenuEntryActions FilePath = new CodeMenuEntryActions("input", Resources.ActionsCodeMenuEntry_FilePath_File_path); - public static readonly CodeMenuEntryActions OutputFilePath = new CodeMenuEntryActions("output", Resources.ActionsCodeMenuEntry_OutputFilePath_File_path_without_extension____Output_file_name_extension_); + public static readonly CodeMenuEntryActions input = new CodeMenuEntryActions("input", Resources.ActionsCodeMenuEntry_FilePath_File_path); + public static readonly CodeMenuEntryActions output = new CodeMenuEntryActions("output", Resources.ActionsCodeMenuEntry_OutputFilePath_File_path_without_extension____Output_file_name_extension_); public CodeMenuEntryActions(string value, string description) : base(value, description) { } + + public static string Parse(string pattern, string inputPath, string outputPath) + { + string result = pattern.Replace(input.ToPrefixString(), '"' + inputPath + '"'); + + if (!string.IsNullOrEmpty(outputPath)) + { + result.Replace(output.ToPrefixString(), '"' + outputPath + '"'); + } + + return result; + } } } \ No newline at end of file