mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Merge pull request #266 from greenshot/BUG/BUG-2693
BUG-2693: Fix for MAPI detection
This commit is contained in:
commit
57f87751c5
7 changed files with 105 additions and 49 deletions
|
@ -102,11 +102,14 @@
|
||||||
</Tokens>
|
</Tokens>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup Condition="$(MSBuildProjectName.Contains('Plugin'))">
|
||||||
<PackageReference Include="MSBuildTasks" Version="1.5.0.235" GeneratePathProperty="true"/>
|
<PackageReference Include="MSBuildTasks" Version="1.5.0.235" GeneratePathProperty="true" DevelopmentDependency="true" />
|
||||||
</ItemGroup>
|
</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')">
|
<Target Name="ProcessTemplates" BeforeTargets="PrepareForBuild" Condition="Exists('$(ProjectDir)$(ProjectName).Credentials.template')">
|
||||||
<Message Text="Processing: $(ProjectDir)$(ProjectName).Credentials.template" Importance="high"/>
|
<Message Text="Processing: $(ProjectDir)$(ProjectName).Credentials.template" Importance="high"/>
|
||||||
|
|
|
@ -46,6 +46,13 @@
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</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">
|
<UsingTask TaskName="SetEnvironmentVariableTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
|
||||||
|
|
||||||
<ParameterGroup>
|
<ParameterGroup>
|
||||||
|
|
|
@ -174,7 +174,7 @@ namespace Greenshot.Helpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ShowDialog() {
|
public void ShowDialog() {
|
||||||
// Create the mail message in an STA thread
|
// Create the mail message in an STA thread
|
||||||
var thread = new Thread(_ShowMail)
|
var thread = new Thread(ShowMail)
|
||||||
{
|
{
|
||||||
IsBackground = true,
|
IsBackground = true,
|
||||||
Name = "Create MAPI mail"
|
Name = "Create MAPI mail"
|
||||||
|
@ -202,7 +202,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends the mail message.
|
/// Sends the mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void _ShowMail() {
|
private void ShowMail() {
|
||||||
var message = new MapiHelperInterop.MapiMessage();
|
var message = new MapiHelperInterop.MapiMessage();
|
||||||
|
|
||||||
using var interopRecipients = Recipients.GetInteropRepresentation();
|
using var interopRecipients = Recipients.GetInteropRepresentation();
|
||||||
|
@ -215,7 +215,7 @@ namespace Greenshot.Helpers {
|
||||||
// Check if we need to add attachments
|
// Check if we need to add attachments
|
||||||
if (Files.Count > 0) {
|
if (Files.Count > 0) {
|
||||||
// Add attachments
|
// Add attachments
|
||||||
message.Files = _AllocAttachments(out message.FileCount);
|
message.Files = AllocAttachments(out message.FileCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal the creating thread (make the remaining code async)
|
// Signal the creating thread (make the remaining code async)
|
||||||
|
@ -227,7 +227,7 @@ namespace Greenshot.Helpers {
|
||||||
|
|
||||||
if (Files.Count > 0) {
|
if (Files.Count > 0) {
|
||||||
// Deallocate the files
|
// Deallocate the files
|
||||||
_DeallocFiles(message);
|
DeallocFiles(message);
|
||||||
}
|
}
|
||||||
MAPI_CODES errorCode = (MAPI_CODES)Enum.ToObject(typeof(MAPI_CODES), error);
|
MAPI_CODES errorCode = (MAPI_CODES)Enum.ToObject(typeof(MAPI_CODES), error);
|
||||||
|
|
||||||
|
@ -245,14 +245,14 @@ namespace Greenshot.Helpers {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Recipients = new RecipientCollection();
|
Recipients = new RecipientCollection();
|
||||||
_ShowMail();
|
ShowMail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deallocates the files in a message.
|
/// Deallocates the files in a message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to deallocate the files from.</param>
|
/// <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) {
|
if (message.Files != IntPtr.Zero) {
|
||||||
Type fileDescType = typeof(MapiFileDescriptor);
|
Type fileDescType = typeof(MapiFileDescriptor);
|
||||||
int fsize = Marshal.SizeOf(fileDescType);
|
int fsize = Marshal.SizeOf(fileDescType);
|
||||||
|
@ -274,7 +274,7 @@ namespace Greenshot.Helpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileCount"></param>
|
/// <param name="fileCount"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private IntPtr _AllocAttachments(out int fileCount) {
|
private IntPtr AllocAttachments(out int fileCount) {
|
||||||
fileCount = 0;
|
fileCount = 0;
|
||||||
if (Files == null) {
|
if (Files == null) {
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj" />
|
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj" />
|
||||||
<PackageReference Include="Dapplo.Jira" version="1.1.21" />
|
<PackageReference Include="Dapplo.Jira" version="1.1.38" />
|
||||||
<PackageReference Include="Dapplo.Jira.SvgWinForms" Version="1.1.21" />
|
<PackageReference Include="Dapplo.Jira.SvgWinForms" Version="1.1.38" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Greenshot - a free and open source screenshot tool
|
* 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/
|
* For more information see: http://getgreenshot.org/
|
||||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
|
* 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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
@ -26,38 +27,17 @@ namespace GreenshotPlugin.Core {
|
||||||
/// Description of EmailConfigHelper.
|
/// Description of EmailConfigHelper.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class EmailConfigHelper {
|
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() {
|
public static string GetMapiClient() => Registry.LocalMachine.ReadKey64Or32(@"Clients\Mail");
|
||||||
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 GetOutlookExePath() {
|
public static bool HasMapi()
|
||||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(OutlookPathKey, false)) {
|
{
|
||||||
if (key != null) {
|
var value = Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0");
|
||||||
// "" is the default key, which should point to the outlook location
|
return "1".Equals(value);
|
||||||
return (string)key.GetValue(string.Empty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetOutlookExePath() => Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE");
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if Outlook is installed
|
/// Check if Outlook is installed
|
||||||
|
@ -65,12 +45,11 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <returns>Returns true if outlook is installed</returns>
|
/// <returns>Returns true if outlook is installed</returns>
|
||||||
public static bool HasOutlook() {
|
public static bool HasOutlook() {
|
||||||
string outlookPath = GetOutlookExePath();
|
string outlookPath = GetOutlookExePath();
|
||||||
if (outlookPath != null) {
|
if (outlookPath == null)
|
||||||
if (File.Exists(outlookPath)) {
|
{
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return File.Exists(outlookPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
67
GreenshotPlugin/Core/RegistryKeyExtensions.cs
Normal file
67
GreenshotPlugin/Core/RegistryKeyExtensions.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,9 +13,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<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="log4net" version="2.0.12" />
|
||||||
<PackageReference Include="Svg" Version="3.1.1" />
|
<PackageReference Include="Svg" Version="3.2.3" />
|
||||||
<Reference Include="Accessibility" />
|
<Reference Include="Accessibility" />
|
||||||
<Reference Include="CustomMarshalers" />
|
<Reference Include="CustomMarshalers" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue