mirror of
https://github.com/greenshot/greenshot
synced 2025-07-06 04:52:16 -07:00
Fix of BUG-2951, issues with finding Office installations (#431)
This commit is contained in:
parent
2b5e45e33e
commit
ba8ed074c8
6 changed files with 89 additions and 7 deletions
|
@ -40,13 +40,85 @@ 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 strKeyName = keyname switch
|
||||
{
|
||||
"WINWORD.EXE" => "Word",
|
||||
"EXCEL.EXE" => "Excel",
|
||||
"POWERPNT.EXE" => "PowerPoint",
|
||||
"OUTLOOK.EXE" => "Outlook",
|
||||
"ONENOTE.EXE" => "OneNote",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
RegistryKey rootKey = null;
|
||||
RegistryKey officeKey = null;
|
||||
RegistryKey programKey = null;
|
||||
RegistryKey installRootKey = null;
|
||||
string retValue = string.Empty;
|
||||
|
||||
foreach (string strRootKey in strRootKeys)
|
||||
{
|
||||
rootKey = Registry.LocalMachine.OpenSubKey(strRootKey);
|
||||
|
||||
if (rootKey != null)
|
||||
{
|
||||
string[] officeVersions = rootKey.GetSubKeyNames();
|
||||
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)
|
||||
{
|
||||
officeKey = Registry.LocalMachine.OpenSubKey(strRootKey + "\\" + officeVersion);
|
||||
|
||||
if (officeKey is null)
|
||||
continue;
|
||||
|
||||
programKey = officeKey.OpenSubKey(strKeyName);
|
||||
|
||||
if (programKey is null)
|
||||
continue;
|
||||
|
||||
installRootKey = programKey.OpenSubKey("InstallRoot");
|
||||
|
||||
if (installRootKey != null)
|
||||
{
|
||||
retValue = installRootKey.GetValue("Path").ToString() + "\\" + keyname;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
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
|
||||
/// </summary>
|
||||
|
|
|
@ -42,7 +42,10 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static ExcelDestination()
|
||||
{
|
||||
ExePath = PluginUtils.GetOfficeExePath("EXCEL.EXE");
|
||||
if (ExePath == null)
|
||||
ExePath = PluginUtils.GetExePath("EXCEL.EXE");
|
||||
|
||||
if (ExePath != null && File.Exists(ExePath))
|
||||
{
|
||||
WindowDetails.AddProcessToExcludeFromFreeze("excel");
|
||||
|
|
|
@ -41,6 +41,8 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static OneNoteDestination()
|
||||
{
|
||||
exePath = PluginUtils.GetOfficeExePath("ONENOTE.EXE");
|
||||
if (exePath == null)
|
||||
exePath = PluginUtils.GetExePath("ONENOTE.EXE");
|
||||
if (exePath != null && File.Exists(exePath))
|
||||
{
|
||||
|
|
|
@ -58,7 +58,8 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
{
|
||||
IsActiveFlag = true;
|
||||
}
|
||||
|
||||
ExePath = PluginUtils.GetOfficeExePath("OUTLOOK.EXE");
|
||||
if (ExePath == null)
|
||||
ExePath = PluginUtils.GetExePath("OUTLOOK.EXE");
|
||||
if (ExePath != null && File.Exists(ExePath))
|
||||
{
|
||||
|
|
|
@ -45,6 +45,8 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static PowerpointDestination()
|
||||
{
|
||||
ExePath = PluginUtils.GetOfficeExePath("POWERPNT.EXE");
|
||||
if (ExePath == null)
|
||||
ExePath = PluginUtils.GetExePath("POWERPNT.EXE");
|
||||
if (ExePath != null && File.Exists(ExePath))
|
||||
{
|
||||
|
|
|
@ -46,6 +46,8 @@ namespace Greenshot.Plugin.Office.Destinations
|
|||
|
||||
static WordDestination()
|
||||
{
|
||||
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