mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 06:23:24 -07:00
Suggestions by Robin implemented in Code.
This commit is contained in:
parent
fb9a0c2a24
commit
b0c340e084
6 changed files with 52 additions and 54 deletions
|
@ -52,41 +52,23 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public static string GetOfficeExePath(string keyname, string returnValue)
|
||||
public static string GetOfficeExePath(string keyname)
|
||||
{
|
||||
string strKeyName = "";
|
||||
string strKeyName = keyname switch
|
||||
{
|
||||
"WINWORD.EXE" => "Word",
|
||||
"EXCEL.EXE" => "Excel",
|
||||
"POWERPNT.EXE" => "PowerPoint",
|
||||
"OUTLOOK.EXE" => "Outlook",
|
||||
"ONENOTE.EXE" => "OneNote",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
switch (keyname)
|
||||
{
|
||||
case "WINWORD.EXE":
|
||||
strKeyName = "Word";
|
||||
break;
|
||||
case "EXCEL.EXE":
|
||||
strKeyName = "Excel";
|
||||
break;
|
||||
case "MSACCESS.EXE":
|
||||
strKeyName = "Access";
|
||||
break;
|
||||
case "POWERPNT.EXE":
|
||||
strKeyName = "PowerPoint";
|
||||
break;
|
||||
case "OUTLOOK.EXE":
|
||||
strKeyName = "Outlook";
|
||||
break;
|
||||
case "ONENOTE.EXE":
|
||||
strKeyName = "OneNote";
|
||||
break;
|
||||
case "MSPUB.EXE":
|
||||
strKeyName = "Publisher";
|
||||
break;
|
||||
default:
|
||||
strKeyName = "";
|
||||
break;
|
||||
}
|
||||
RegistryKey rootKey = null;
|
||||
RegistryKey officeKey;
|
||||
RegistryKey programKey;
|
||||
RegistryKey installRootKey;
|
||||
RegistryKey officeKey = null;
|
||||
RegistryKey programKey = null;
|
||||
RegistryKey installRootKey = null;
|
||||
string retValue = string.Empty;
|
||||
|
||||
foreach (string strRootKey in strRootKeys)
|
||||
{
|
||||
|
@ -95,8 +77,8 @@ namespace Greenshot.Base.Core
|
|||
if (rootKey != null)
|
||||
{
|
||||
string[] officeVersions = rootKey.GetSubKeyNames();
|
||||
if (officeVersions != null)
|
||||
{
|
||||
if (officeVersions is null)
|
||||
continue;
|
||||
officeVersions = Array.FindAll(officeVersions, r => r.Contains("."));
|
||||
Array.Reverse(officeVersions);
|
||||
// string latestOfficeVersion = officeVersions.Where(r => r.Contains(".")).Max();
|
||||
|
@ -105,21 +87,37 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
officeKey = Registry.LocalMachine.OpenSubKey(strRootKey + "\\" + officeVersion);
|
||||
|
||||
if (officeKey != null)
|
||||
{
|
||||
if (officeKey is null)
|
||||
continue;
|
||||
|
||||
programKey = officeKey.OpenSubKey(strKeyName);
|
||||
if (programKey != null)
|
||||
{
|
||||
|
||||
if (programKey is null)
|
||||
continue;
|
||||
|
||||
installRootKey = programKey.OpenSubKey("InstallRoot");
|
||||
|
||||
if (installRootKey != null)
|
||||
return installRootKey.GetValue(returnValue).ToString() + "\\" + keyname;
|
||||
{
|
||||
retValue = installRootKey.GetValue("Path").ToString() + "\\" + keyname;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
if (rootKey != null)
|
||||
rootKey.Dispose();
|
||||
if (officeKey != null)
|
||||
officeKey.Dispose();
|
||||
if (programKey != null)
|
||||
programKey.Dispose();
|
||||
if (installRootKey != null)
|
||||
installRootKey.Dispose();
|
||||
return retValue;
|
||||
}
|
||||
/// <summary>
|
||||
/// Clear icon cache
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static ExcelDestination()
|
||||
{
|
||||
ExePath = PluginUtils.GetOfficeExePath("EXCEL.EXE", "Path");
|
||||
ExePath = PluginUtils.GetOfficeExePath("EXCEL.EXE");
|
||||
if (ExePath == null)
|
||||
ExePath = PluginUtils.GetExePath("EXCEL.EXE");
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static OneNoteDestination()
|
||||
{
|
||||
exePath = PluginUtils.GetOfficeExePath("ONENOTE.EXE", "Path");
|
||||
exePath = PluginUtils.GetOfficeExePath("ONENOTE.EXE");
|
||||
if (exePath == null)
|
||||
exePath = PluginUtils.GetExePath("ONENOTE.EXE");
|
||||
if (exePath != null && File.Exists(exePath))
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
{
|
||||
IsActiveFlag = true;
|
||||
}
|
||||
ExePath = PluginUtils.GetOfficeExePath("OUTLOOK.EXE", "Path");
|
||||
ExePath = PluginUtils.GetOfficeExePath("OUTLOOK.EXE");
|
||||
if (ExePath == null)
|
||||
ExePath = PluginUtils.GetExePath("OUTLOOK.EXE");
|
||||
if (ExePath != null && File.Exists(ExePath))
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static PowerpointDestination()
|
||||
{
|
||||
ExePath = PluginUtils.GetOfficeExePath("POWERPNT.EXE", "Path");
|
||||
ExePath = PluginUtils.GetOfficeExePath("POWERPNT.EXE");
|
||||
if (ExePath == null)
|
||||
ExePath = PluginUtils.GetExePath("POWERPNT.EXE");
|
||||
if (ExePath != null && File.Exists(ExePath))
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static WordDestination()
|
||||
{
|
||||
ExePath = PluginUtils.GetOfficeExePath("WINWORD.EXE", "Path");
|
||||
ExePath = PluginUtils.GetOfficeExePath("WINWORD.EXE");
|
||||
if (ExePath == null)
|
||||
ExePath = PluginUtils.GetExePath("WINWORD.EXE");
|
||||
if (ExePath != null && !File.Exists(ExePath))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue