diff --git a/ShareX.HelpersLib/Helpers/RegistryHelpers.cs b/ShareX.HelpersLib/Helpers/RegistryHelpers.cs index a959e501b..a73d2ce44 100644 --- a/ShareX.HelpersLib/Helpers/RegistryHelpers.cs +++ b/ShareX.HelpersLib/Helpers/RegistryHelpers.cs @@ -109,7 +109,7 @@ public static ExternalProgram FindProgram(string name, string filename) foreach (string command in commands) { - string path = string.Format(@"HKEY_CLASSES_ROOT\Applications\{0}\shell\{1}\command", filename, command); + string path = $@"HKEY_CLASSES_ROOT\Applications\{filename}\shell\{command}\command"; string value = Registry.GetValue(path, null, null) as string; if (!string.IsNullOrEmpty(value)) @@ -132,14 +132,22 @@ public static ExternalProgram FindProgram(string name, string filename) { foreach (string filePath in programs.GetValueNames()) { - if (!string.IsNullOrEmpty(filePath) && programs.GetValueKind(filePath) == RegistryValueKind.String) - { - string programName = programs.GetValue(filePath, null) as string; + string programPath = filePath; - if (!string.IsNullOrEmpty(programName) && programName.Equals(name, StringComparison.InvariantCultureIgnoreCase) && File.Exists(filePath)) + if (!string.IsNullOrEmpty(programPath)) + { + foreach (string trim in new string[] { ".ApplicationCompany", ".FriendlyAppName" }) { - DebugHelper.WriteLine("Found program with second method: " + filePath); - return new ExternalProgram(name, filePath); + if (programPath.EndsWith(trim, StringComparison.OrdinalIgnoreCase)) + { + programPath = programPath.Remove(programPath.Length - trim.Length); + } + } + + if (programPath.EndsWith(filename, StringComparison.OrdinalIgnoreCase) && File.Exists(programPath)) + { + DebugHelper.WriteLine("Found program with second method: " + programPath); + return new ExternalProgram(name, programPath); } } } diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 787260c8c..9cc5ddf14 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -608,20 +608,6 @@ public static void AddDefaultExternalPrograms(TaskSettings taskSettings) AddExternalProgramFromRegistry(taskSettings, "Adobe Photoshop", "Photoshop.exe"); AddExternalProgramFromRegistry(taskSettings, "IrfanView", "i_view32.exe"); AddExternalProgramFromRegistry(taskSettings, "XnView", "xnview.exe"); - AddExternalProgramFromFile(taskSettings, "OptiPNG", "optipng.exe"); - } - - private static void AddExternalProgramFromFile(TaskSettings taskSettings, string name, string filename, string args = "") - { - if (!taskSettings.ExternalPrograms.Exists(x => x.Name == name)) - { - if (File.Exists(filename)) - { - DebugHelper.WriteLine("Found program: " + filename); - - taskSettings.ExternalPrograms.Add(new ExternalProgram(name, filename, args)); - } - } } private static void AddExternalProgramFromRegistry(TaskSettings taskSettings, string name, string filename)