Suggestions by Robin implemented in Code.

This commit is contained in:
jdavila71 2022-08-16 20:08:22 -04:00
commit b0c340e084
6 changed files with 52 additions and 54 deletions

View file

@ -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 = "";
switch (keyname)
string strKeyName = keyname switch
{
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;
}
"WINWORD.EXE" => "Word",
"EXCEL.EXE" => "Excel",
"POWERPNT.EXE" => "PowerPoint",
"OUTLOOK.EXE" => "Outlook",
"ONENOTE.EXE" => "OneNote",
_ => ""
};
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,31 +77,47 @@ 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();
foreach (string officeVersion in officeVersions)
{
officeVersions = Array.FindAll(officeVersions, r => r.Contains("."));
Array.Reverse(officeVersions);
// string latestOfficeVersion = officeVersions.Where(r => r.Contains(".")).Max();
officeKey = Registry.LocalMachine.OpenSubKey(strRootKey + "\\" + officeVersion);
foreach (string officeVersion in officeVersions)
if (officeKey is null)
continue;
programKey = officeKey.OpenSubKey(strKeyName);
if (programKey is null)
continue;
installRootKey = programKey.OpenSubKey("InstallRoot");
if (installRootKey != null)
{
officeKey = Registry.LocalMachine.OpenSubKey(strRootKey + "\\" + officeVersion);
retValue = installRootKey.GetValue("Path").ToString() + "\\" + keyname;
break;
if (officeKey != null)
{
programKey = officeKey.OpenSubKey(strKeyName);
if (programKey != null)
{
installRootKey = programKey.OpenSubKey("InstallRoot");
if (installRootKey != null)
return installRootKey.GetValue(returnValue).ToString() + "\\" + keyname;
}
}
}
}
}
}
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

View file

@ -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");

View file

@ -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))

View file

@ -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))

View file

@ -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))

View file

@ -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))