Fix of BUG2951

This commit is contained in:
jdavila71 2022-08-15 21:55:07 -04:00
commit fb9a0c2a24
6 changed files with 91 additions and 7 deletions

View file

@ -40,13 +40,87 @@ namespace Greenshot.Base.Core
private static readonly ILog Log = LogManager.GetLogger(typeof(PluginUtils));
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
private const string PathKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\";
private static string[] strRootKeys = { @"SOFTWARE\Microsoft\Office", @"SOFTWARE\WOW6432Node\Microsoft\Office" };
private static readonly IDictionary<string, Image> ExeIconCache = new Dictionary<string, Image>();
static PluginUtils()
{
CoreConfig.PropertyChanged += OnIconSizeChanged;
}
/// <summary>
/// Clear icon cache
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public static string GetOfficeExePath(string keyname, string returnValue)
{
string strKeyName = "";
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;
foreach (string strRootKey in strRootKeys)
{
rootKey = Registry.LocalMachine.OpenSubKey(strRootKey);
if (rootKey != null)
{
string[] officeVersions = rootKey.GetSubKeyNames();
if (officeVersions != null)
{
officeVersions = Array.FindAll(officeVersions, r => r.Contains("."));
Array.Reverse(officeVersions);
// string latestOfficeVersion = officeVersions.Where(r => r.Contains(".")).Max();
foreach (string officeVersion in officeVersions)
{
officeKey = Registry.LocalMachine.OpenSubKey(strRootKey + "\\" + officeVersion);
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;
}
/// <summary>
/// Clear icon cache
/// </summary>
@ -84,7 +158,7 @@ namespace Greenshot.Base.Core
if (key != null)
{
// "" is the default key, which should point to the requested location
return (string) key.GetValue(string.Empty);
return (string)key.GetValue(string.Empty);
}
}

View file

@ -42,7 +42,10 @@ namespace Greenshot.Plugin.Office.Destinations
static ExcelDestination()
{
ExePath = PluginUtils.GetExePath("EXCEL.EXE");
ExePath = PluginUtils.GetOfficeExePath("EXCEL.EXE", "Path");
if (ExePath == null)
ExePath = PluginUtils.GetExePath("EXCEL.EXE");
if (ExePath != null && File.Exists(ExePath))
{
WindowDetails.AddProcessToExcludeFromFreeze("excel");

View file

@ -41,7 +41,9 @@ namespace Greenshot.Plugin.Office.Destinations
static OneNoteDestination()
{
exePath = PluginUtils.GetExePath("ONENOTE.EXE");
exePath = PluginUtils.GetOfficeExePath("ONENOTE.EXE", "Path");
if (exePath == null)
exePath = PluginUtils.GetExePath("ONENOTE.EXE");
if (exePath != null && File.Exists(exePath))
{
WindowDetails.AddProcessToExcludeFromFreeze("onenote");

View file

@ -58,8 +58,9 @@ namespace Greenshot.Plugin.Office.Destinations
{
IsActiveFlag = true;
}
ExePath = PluginUtils.GetExePath("OUTLOOK.EXE");
ExePath = PluginUtils.GetOfficeExePath("OUTLOOK.EXE", "Path");
if (ExePath == null)
ExePath = PluginUtils.GetExePath("OUTLOOK.EXE");
if (ExePath != null && File.Exists(ExePath))
{
WindowDetails.AddProcessToExcludeFromFreeze("outlook");

View file

@ -45,7 +45,9 @@ namespace Greenshot.Plugin.Office.Destinations
static PowerpointDestination()
{
ExePath = PluginUtils.GetExePath("POWERPNT.EXE");
ExePath = PluginUtils.GetOfficeExePath("POWERPNT.EXE", "Path");
if (ExePath == null)
ExePath = PluginUtils.GetExePath("POWERPNT.EXE");
if (ExePath != null && File.Exists(ExePath))
{
WindowDetails.AddProcessToExcludeFromFreeze("powerpnt");

View file

@ -46,7 +46,9 @@ namespace Greenshot.Plugin.Office.Destinations
static WordDestination()
{
ExePath = PluginUtils.GetExePath("WINWORD.EXE");
ExePath = PluginUtils.GetOfficeExePath("WINWORD.EXE", "Path");
if (ExePath == null)
ExePath = PluginUtils.GetExePath("WINWORD.EXE");
if (ExePath != null && !File.Exists(ExePath))
{
ExePath = null;