Merge pull request #266 from greenshot/BUG/BUG-2693

BUG-2693: Fix for MAPI detection
This commit is contained in:
Robin Krom 2021-01-27 23:54:58 +01:00 committed by GitHub
commit 57f87751c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 49 deletions

View file

@ -102,11 +102,14 @@
</Tokens>
</ItemGroup>
<ItemGroup>
<PackageReference Include="MSBuildTasks" Version="1.5.0.235" GeneratePathProperty="true"/>
<ItemGroup Condition="$(MSBuildProjectName.Contains('Plugin'))">
<PackageReference Include="MSBuildTasks" Version="1.5.0.235" GeneratePathProperty="true" DevelopmentDependency="true" />
</ItemGroup>
<PropertyGroup Condition="'$(PkgTools_MSBuildTasks)' == ''">
<PkgTools_MSBuildTasks>$(userprofile)\.nuget\packages\msbuildtasks\1.5.0.235\tools\</PkgTools_MSBuildTasks>
</PropertyGroup>
<Import Project="$(PkgTools_MSBuildTasks)MSBuild.Community.Tasks.Targets" Condition="Exists('$(ProjectDir)$(ProjectName).Credentials.template')"/>
<Import Project="$(PkgTools_MSBuildTasks)MSBuild.Community.Tasks.Targets" Condition="$(MSBuildProjectName.Contains('Plugin'))"/>
<Target Name="ProcessTemplates" BeforeTargets="PrepareForBuild" Condition="Exists('$(ProjectDir)$(ProjectName).Credentials.template')">
<Message Text="Processing: $(ProjectDir)$(ProjectName).Credentials.template" Importance="high"/>

View file

@ -46,6 +46,13 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Update="MSBuildTasks" Version="1.5.0.235">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<UsingTask TaskName="SetEnvironmentVariableTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>

View file

@ -174,7 +174,7 @@ namespace Greenshot.Helpers {
/// </summary>
public void ShowDialog() {
// Create the mail message in an STA thread
var thread = new Thread(_ShowMail)
var thread = new Thread(ShowMail)
{
IsBackground = true,
Name = "Create MAPI mail"
@ -202,7 +202,7 @@ namespace Greenshot.Helpers {
/// <summary>
/// Sends the mail message.
/// </summary>
private void _ShowMail() {
private void ShowMail() {
var message = new MapiHelperInterop.MapiMessage();
using var interopRecipients = Recipients.GetInteropRepresentation();
@ -215,7 +215,7 @@ namespace Greenshot.Helpers {
// Check if we need to add attachments
if (Files.Count > 0) {
// Add attachments
message.Files = _AllocAttachments(out message.FileCount);
message.Files = AllocAttachments(out message.FileCount);
}
// Signal the creating thread (make the remaining code async)
@ -227,7 +227,7 @@ namespace Greenshot.Helpers {
if (Files.Count > 0) {
// Deallocate the files
_DeallocFiles(message);
DeallocFiles(message);
}
MAPI_CODES errorCode = (MAPI_CODES)Enum.ToObject(typeof(MAPI_CODES), error);
@ -245,14 +245,14 @@ namespace Greenshot.Helpers {
return;
}
Recipients = new RecipientCollection();
_ShowMail();
ShowMail();
}
/// <summary>
/// Deallocates the files in a message.
/// </summary>
/// <param name="message">The message to deallocate the files from.</param>
private void _DeallocFiles(MapiHelperInterop.MapiMessage message) {
private void DeallocFiles(MapiHelperInterop.MapiMessage message) {
if (message.Files != IntPtr.Zero) {
Type fileDescType = typeof(MapiFileDescriptor);
int fsize = Marshal.SizeOf(fileDescType);
@ -274,7 +274,7 @@ namespace Greenshot.Helpers {
/// </summary>
/// <param name="fileCount"></param>
/// <returns></returns>
private IntPtr _AllocAttachments(out int fileCount) {
private IntPtr AllocAttachments(out int fileCount) {
fileCount = 0;
if (Files == null) {
return IntPtr.Zero;

View file

@ -12,7 +12,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj" />
<PackageReference Include="Dapplo.Jira" version="1.1.21" />
<PackageReference Include="Dapplo.Jira.SvgWinForms" Version="1.1.21" />
<PackageReference Include="Dapplo.Jira" version="1.1.38" />
<PackageReference Include="Dapplo.Jira.SvgWinForms" Version="1.1.38" />
</ItemGroup>
</Project>

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,6 +18,7 @@
* 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;
@ -26,38 +27,17 @@ namespace GreenshotPlugin.Core {
/// 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() => Registry.LocalMachine.ReadKey64Or32(@"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 = Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0");
return "1".Equals(value);
}
public static string GetOutlookExePath() => Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE");
/// <summary>
/// Check if Outlook is installed
@ -65,12 +45,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,67 @@
/*
* 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 RegistryKeyExtensions
{
/// <summary>
/// Retrieve a registry value
/// </summary>
/// <param name="registryKey">RegistryKey like Registry.LocalMachine</param>
/// <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 ReadKey64Or32(this RegistryKey registryKey, string keyName, string value = null, string defaultValue = null)
{
string result = null;
value ??= string.Empty;
if (Environment.Is64BitOperatingSystem)
{
using var key = registryKey.OpenSubKey($@"SOFTWARE\{keyName}", false);
if (key != null)
{
result = (string)key.GetValue(value, defaultValue);
}
}
if (string.IsNullOrEmpty(result))
{
using var key = registryKey.OpenSubKey($@"SOFTWARE\wow6432node\{keyName}", false);
if (key != null)
{
result = (string)key.GetValue(value, defaultValue);
}
}
return result;
}
}
}

View file

@ -13,9 +13,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="1.0.3" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="1.0.8" />
<PackageReference Include="log4net" version="2.0.12" />
<PackageReference Include="Svg" Version="3.1.1" />
<PackageReference Include="Svg" Version="3.2.3" />
<Reference Include="Accessibility" />
<Reference Include="CustomMarshalers" />
</ItemGroup>