Small code refactoring

This commit is contained in:
Jaex 2019-09-20 16:02:51 +03:00
parent 7bbe79218c
commit 223b88aa4b
3 changed files with 10 additions and 9 deletions

View file

@ -101,7 +101,7 @@ public static bool CheckRegistry(string path, string name = null, string value =
return registryValue != null && (value == null || registryValue.Equals(value, StringComparison.InvariantCultureIgnoreCase)); return registryValue != null && (value == null || registryValue.Equals(value, StringComparison.InvariantCultureIgnoreCase));
} }
public static ExternalProgram FindProgram(string name, string filename) public static string SearchProgramPath(string fileName)
{ {
// First method: HKEY_CLASSES_ROOT\Applications\{filename}\shell\{command}\command // First method: HKEY_CLASSES_ROOT\Applications\{filename}\shell\{command}\command
@ -109,7 +109,7 @@ public static ExternalProgram FindProgram(string name, string filename)
foreach (string command in commands) foreach (string command in commands)
{ {
string path = $@"HKEY_CLASSES_ROOT\Applications\{filename}\shell\{command}\command"; string path = $@"HKEY_CLASSES_ROOT\Applications\{fileName}\shell\{command}\command";
string value = Registry.GetValue(path, null, null) as string; string value = Registry.GetValue(path, null, null) as string;
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
@ -119,7 +119,7 @@ public static ExternalProgram FindProgram(string name, string filename)
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
DebugHelper.WriteLine("Found program with first method: " + filePath); DebugHelper.WriteLine("Found program with first method: " + filePath);
return new ExternalProgram(name, filePath); return filePath;
} }
} }
} }
@ -144,10 +144,10 @@ public static ExternalProgram FindProgram(string name, string filename)
} }
} }
if (programPath.EndsWith(filename, StringComparison.OrdinalIgnoreCase) && File.Exists(programPath)) if (programPath.EndsWith(fileName, StringComparison.OrdinalIgnoreCase) && File.Exists(programPath))
{ {
DebugHelper.WriteLine("Found program with second method: " + programPath); DebugHelper.WriteLine("Found program with second method: " + programPath);
return new ExternalProgram(name, programPath); return programPath;
} }
} }
} }

View file

@ -460,7 +460,7 @@
<value>True</value> <value>True</value>
</data> </data>
<data name="cbHiddenWindow.Location" type="System.Drawing.Point, System.Drawing"> <data name="cbHiddenWindow.Location" type="System.Drawing.Point, System.Drawing">
<value>9, 248</value> <value>8, 248</value>
</data> </data>
<data name="cbHiddenWindow.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms"> <data name="cbHiddenWindow.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>2, 2, 2, 2</value> <value>2, 2, 2, 2</value>

View file

@ -610,14 +610,15 @@ public static void AddDefaultExternalPrograms(TaskSettings taskSettings)
AddExternalProgramFromRegistry(taskSettings, "XnView", "xnview.exe"); AddExternalProgramFromRegistry(taskSettings, "XnView", "xnview.exe");
} }
private static void AddExternalProgramFromRegistry(TaskSettings taskSettings, string name, string filename) private static void AddExternalProgramFromRegistry(TaskSettings taskSettings, string name, string fileName)
{ {
if (!taskSettings.ExternalPrograms.Exists(x => x.Name == name)) if (!taskSettings.ExternalPrograms.Exists(x => x.Name == name))
{ {
ExternalProgram externalProgram = RegistryHelpers.FindProgram(name, filename); string filePath = RegistryHelpers.SearchProgramPath(fileName);
if (externalProgram != null) if (!string.IsNullOrEmpty(filePath))
{ {
ExternalProgram externalProgram = new ExternalProgram(name, filePath);
taskSettings.ExternalPrograms.Add(externalProgram); taskSettings.ExternalPrograms.Add(externalProgram);
} }
} }