Fixed an issue with the build, where MSBuild.Community.Tasks.Targets wasn't found. Also improved the registry reading for the MAPI control.

This commit is contained in:
Robin Krom 2021-01-27 23:50:22 +01:00
commit 2733c6cf26
7 changed files with 33 additions and 21 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

@ -20,6 +20,7 @@
*/
using System.IO;
using Microsoft.Win32;
namespace GreenshotPlugin.Core {
/// <summary>
@ -27,16 +28,16 @@ namespace GreenshotPlugin.Core {
/// </summary>
public static class EmailConfigHelper {
public static string GetMapiClient() => RegistryHelper.ReadLocalMachineSoftwareKey(@"Clients\Mail");
public static string GetMapiClient() => Registry.LocalMachine.ReadKey64Or32(@"Clients\Mail");
public static bool HasMapi()
{
var value = RegistryHelper.ReadLocalMachineSoftwareKey(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0");
var value = Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0");
return "1".Equals(value);
}
public static string GetOutlookExePath() => RegistryHelper.ReadLocalMachineSoftwareKey(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE");
public static string GetOutlookExePath() => Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE");
/// <summary>
/// Check if Outlook is installed

View file

@ -27,22 +27,23 @@ namespace GreenshotPlugin.Core
/// <summary>
/// A helper class for accessing the registry
/// </summary>
public static class RegistryHelper
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 ReadLocalMachineSoftwareKey(string keyName, string value = null, string defaultValue = null)
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 = Registry.LocalMachine.OpenSubKey($@"SOFTWARE\{keyName}", false);
using var key = registryKey.OpenSubKey($@"SOFTWARE\{keyName}", false);
if (key != null)
{
@ -52,7 +53,7 @@ namespace GreenshotPlugin.Core
if (string.IsNullOrEmpty(result))
{
using var key = Registry.LocalMachine.OpenSubKey($@"SOFTWARE\wow6432node\{keyName}", false);
using var key = registryKey.OpenSubKey($@"SOFTWARE\wow6432node\{keyName}", false);
if (key != null)
{

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>