Skip to content

Commit

Permalink
Optimized the code to find the office executable even more.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakritzator committed Aug 17, 2022
1 parent 3e88093 commit af3c22c
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/Greenshot.Plugin.Office/OfficeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@ public static string GetOfficeExePath(string exeName)

foreach (string officeVersion in rootKey.GetSubKeyNames().Where(r => r.Contains(".")).Reverse())
{
using RegistryKey officeKey = Registry.LocalMachine.OpenSubKey(strRootKey + "\\" + officeVersion);
if (officeKey is null) continue;

using RegistryKey programKey = officeKey.OpenSubKey(strKeyName);
if (programKey is null) continue;

using RegistryKey installRootKey = programKey.OpenSubKey("InstallRoot");
using RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey($@"{strRootKey}\{officeVersion}\{strKeyName}\InstallRoot");
if (installRootKey == null) continue;

return installRootKey.GetValue("Path") + "\\" + exeName;
return $@"{installRootKey.GetValue("Path")}\{exeName}";
}
}
return string.Empty;
Expand Down

0 comments on commit af3c22c

Please sign in to comment.