BUG-2693: This should fix an issue where Greenshot doesn't detect a MAPI client, we weren't looking at the 32 bit location.

This commit is contained in:
Robin Krom 2021-01-23 23:41:22 +01:00
commit 328e7e569d
2 changed files with 80 additions and 36 deletions

View file

@ -1,6 +1,6 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
@ -18,46 +18,25 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System.IO;
using Microsoft.Win32;
namespace GreenshotPlugin.Core {
/// <summary>
/// Description of EmailConfigHelper.
/// </summary>
public static class EmailConfigHelper {
private const string OutlookPathKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE";
private const string MapiClientKey = @"SOFTWARE\Clients\Mail";
private const string MapiLocationKey = @"SOFTWARE\Microsoft\Windows Messaging Subsystem";
private const string MapiKey = @"MAPI";
public static string GetMapiClient() {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(MapiClientKey, false)) {
if (key != null) {
return (string)key.GetValue(string.Empty);
}
}
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(MapiClientKey, false))
{
return (string) key?.GetValue(string.Empty);
}
}
public static bool HasMapi()
{
using RegistryKey key = Registry.LocalMachine.OpenSubKey(MapiLocationKey, false);
return key != null && "1".Equals(key.GetValue(MapiKey, "0"));
}
public static string GetMapiClient() => RegistryHelper.ReadLocalMachineSoftwareKey(@"Clients\Mail");
public static string GetOutlookExePath() {
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(OutlookPathKey, false)) {
if (key != null) {
// "" is the default key, which should point to the outlook location
return (string)key.GetValue(string.Empty);
}
}
return null;
public static bool HasMapi()
{
var value = RegistryHelper.ReadLocalMachineSoftwareKey(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0");
return "1".Equals(value);
}
public static string GetOutlookExePath() => RegistryHelper.ReadLocalMachineSoftwareKey(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE");
/// <summary>
/// Check if Outlook is installed
@ -65,12 +44,11 @@ namespace GreenshotPlugin.Core {
/// <returns>Returns true if outlook is installed</returns>
public static bool HasOutlook() {
string outlookPath = GetOutlookExePath();
if (outlookPath != null) {
if (File.Exists(outlookPath)) {
return true;
}
if (outlookPath == null)
{
return false;
}
return false;
return File.Exists(outlookPath);
}
}
}

View file

@ -0,0 +1,66 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using Microsoft.Win32;
namespace GreenshotPlugin.Core
{
/// <summary>
/// A helper class for accessing the registry
/// </summary>
public static class RegistryHelper
{
/// <summary>
/// Retrieve a registry value
/// </summary>
/// <param name="keyName">string with the name of the key</param>
/// <param name="value">string with the name of the value below the key, null will retrieve the default</param>
/// <param name="defaultValue">string with the default value to return</param>
/// <returns>string with the value</returns>
public static string ReadLocalMachineSoftwareKey(string keyName, string value = null, string defaultValue = null)
{
string result = null;
value ??= string.Empty;
if (Environment.Is64BitOperatingSystem)
{
using var key = Registry.LocalMachine.OpenSubKey($@"SOFTWARE\{keyName}", false);
if (key != null)
{
result = (string)key.GetValue(value, defaultValue);
}
}
if (string.IsNullOrEmpty(result))
{
using var key = Registry.LocalMachine.OpenSubKey($@"SOFTWARE\wow6432node\{keyName}", false);
if (key != null)
{
result = (string)key.GetValue(value, defaultValue);
}
}
return result;
}
}
}