mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-29 03:30:43 +12:00
Small code refactoring
This commit is contained in:
parent
7bbe79218c
commit
223b88aa4b
|
@ -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));
|
||||
}
|
||||
|
||||
public static ExternalProgram FindProgram(string name, string filename)
|
||||
public static string SearchProgramPath(string fileName)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
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;
|
||||
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
|
@ -119,7 +119,7 @@ public static ExternalProgram FindProgram(string name, string filename)
|
|||
if (File.Exists(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);
|
||||
return new ExternalProgram(name, programPath);
|
||||
return programPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -460,7 +460,7 @@
|
|||
<value>True</value>
|
||||
</data>
|
||||
<data name="cbHiddenWindow.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>9, 248</value>
|
||||
<value>8, 248</value>
|
||||
</data>
|
||||
<data name="cbHiddenWindow.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
|
||||
<value>2, 2, 2, 2</value>
|
||||
|
|
|
@ -610,14 +610,15 @@ public static void AddDefaultExternalPrograms(TaskSettings taskSettings)
|
|||
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))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue