Made things work with .NET 5, there will still be issues. [skip ci]

This commit is contained in:
Robin Krom 2020-09-03 00:02:09 +02:00
commit 5571410483
34 changed files with 95 additions and 405 deletions

View file

@ -31,20 +31,20 @@ This repository is work in progress for the next Greenshot (2.0?).
Quick start for developers
----------------------------
* Download the latest (!!!) dotnet core SDK from here: https://github.com/dotnet/core-sdk ([quick-link to download](https://dotnetcli.blob.core.windows.net/dotnet/Sdk/master/dotnet-sdk-latest-win-x64.exe))
* Make sure you only have the latest dotnet core 3.1 installed!
* Make sure you have the latest Visual Studio 2019, and enable "Use previews of the dotnet core SDK", as is shown here: https://stackoverflow.com/a/55033763
* Make sure you only have the latest dotnet core 5 installed!
* Make sure you have the latest Visual Studio 2019 Preview, and enable "Use previews of the dotnet core SDK", as is shown here: https://stackoverflow.com/a/55033763
* Clone the [repository](https://github.com/greenshot/greenshot/tree/develop), branch develop
* Open the solution from the src directory in Visual Studio
* Rebuild and start...
If you can't use Visual Studio 2019, Rider from Jetbrains is also supported and you can also work with the commandline:
If you can't use Visual Studio 2019, Rider from Jetbrains might also work and you can also work with the commandline:
* Open a powershell / shell in the directory where you cloned this repo
* run dotnet build src/Greenshot.sln
For users the major changes since 1.2.x are:
* dotnet core 3.1 support (why, read here: https://blogs.msdn.microsoft.com/dotnet/2018/10/04/update-on-net-core-3-0-and-net-framework-4-8/ )
* .NET 5 support (why, read here: https://blogs.msdn.microsoft.com/dotnet/2018/10/04/update-on-net-core-3-0-and-net-framework-4-8/ )
* A newer and more modern configuration UI, using [MahApps.Metro](https://github.com/MahApps/MahApps.Metro "MahApps.Metro")
* Due to the update of .NET 2.0 to .NET 4.7.2 a lot of bugs are solved
* Due to the update of .NET 2.0 to .NET 4.7.2, and later to dotnet core 3.1, and now .NET 5, a lot of bugs are solved
* Added Windows 10 destinations, OCR & share
* Better DPI support
* Simplified code should make development easier and quicker

View file

@ -7,7 +7,7 @@
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/greenshot/greenshot</PackageProjectUrl>
<PackageLicenseUrl>https://www.gnu.org/licenses/gpl.html</PackageLicenseUrl>
<LangVersion>latest</LangVersion>
<LangVersion>8</LangVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
@ -58,10 +58,10 @@
</PropertyGroup>
<ItemGroup Condition="!$(MSBuildProjectName.Contains('Tests')) And $(MSBuildProjectName.StartsWith('Greenshot'))">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.91">
<!--PackageReference Include="Nerdbank.GitVersioning" Version="3.1.91">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</PackageReference-->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Box</RootNamespace>
<AssemblyName>Greenshot.Addon.Box</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Confluence</RootNamespace>
<AssemblyName>Greenshot.Addon.Confluence</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Dropbox</RootNamespace>
<AssemblyName>Greenshot.Addon.Dropbox</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.ExternalCommand</RootNamespace>
<AssemblyName>Greenshot.Addon.ExternalCommand</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Flickr</RootNamespace>
<AssemblyName>Greenshot.Addon.Flickr</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.GooglePhotos</RootNamespace>
<AssemblyName>Greenshot.Addon.GooglePhotos</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Imgur</RootNamespace>
<AssemblyName>Greenshot.Addon.Imgur</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Jira</RootNamespace>
<AssemblyName>Greenshot.Addon.Jira</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -20,7 +20,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dapplo.Jira" Version="0.9.28" />
<PackageReference Include="DynamicData" Version="6.16.1" />
<PackageReference Include="Dapplo.Jira" Version="1.0.5" />
<PackageReference Include="Dapplo.Jira.SvgWinForms" Version="1.0.5" />
<PackageReference Include="DynamicData" Version="6.16.8" />
</ItemGroup>
</Project>

View file

@ -29,8 +29,8 @@ using System.Windows.Media.Imaging;
using Dapplo.HttpExtensions;
using Dapplo.HttpExtensions.Extensions;
using Dapplo.Jira;
using Dapplo.Jira.Converters;
using Dapplo.Jira.Entities;
using Dapplo.Jira.SvgWinForms.Converters;
using Dapplo.Log;
using DynamicData;
using Greenshot.Addon.Jira.Configuration;

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.LegacyEditor</RootNamespace>
<AssemblyName>Greenshot.Addon.LegacyEditor</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Lutim</RootNamespace>
<AssemblyName>Greenshot.Addon.Lutim</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Office</RootNamespace>
<AssemblyName>Greenshot.Addon.Office</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.OneDrive</RootNamespace>
<AssemblyName>Greenshot.Addon.OneDrive</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Photobucket</RootNamespace>
<AssemblyName>Greenshot.Addon.Photobucket</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Tfs</RootNamespace>
<AssemblyName>Greenshot.Addon.Tfs</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.Addon.Win10</RootNamespace>
<AssemblyName>Greenshot.Addon.Win10</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -18,8 +18,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.18362.2005" />
<TrimmerRootAssembly Include="Microsoft.Windows.SDK.Contracts" />
<TrimmerRootAssembly Include="System.Runtime.WindowsRuntime" />
<PackageReference Include="Microsoft.Windows.SDK.NET" Version="10.0.18362.3-preview" />
<PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" />
<TrimmerRootAssembly Include="Microsoft.Windows.SDK.Contracts" />
<TrimmerRootAssembly Include="System.Runtime.WindowsRuntime" />
</ItemGroup>
</Project>

View file

@ -1,19 +1,19 @@
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2020 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/>.
@ -57,11 +57,11 @@ namespace Greenshot.Addon.Win10.Native
_dataTransferManagerInterOp = (IDataTransferManagerInterOp)activationFactory;
_windowHandle = handle;
var riid = new Guid(DataTransferManagerId);
var hresult = _dataTransferManagerInterOp.GetForWindow(_windowHandle, riid, out var dataTransferManager);
if (hresult.Failed())
var guid = new Guid(DataTransferManagerId);
var hResult = _dataTransferManagerInterOp.GetForWindow(_windowHandle, guid, out var dataTransferManager);
if (hResult.Failed())
{
Log.Warn().WriteLine("HResult for GetForWindow: {0}", hresult);
Log.Warn().WriteLine("HResult for GetForWindow: {0}", hResult);
}
DataTransferManager = dataTransferManager;
}

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

View file

@ -1,60 +0,0 @@
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2020 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/>.
#if !NETCOREAPP3_1
using System.ServiceModel;
namespace Greenshot.Addons.Interfaces
{
/// <summary>
/// This interface specifies the functional interface that Greenshot provides
/// </summary>
[ServiceContract]
public interface IGreenshotContract
{
/// <summary>
/// Start a capture
/// </summary>
/// <param name="parameters"></param>
[OperationContract]
void Capture(string parameters);
/// <summary>
/// Exit the instance
/// </summary>
[OperationContract]
void Exit();
/// <summary>
/// Reload configuration
/// </summary>
[OperationContract]
void ReloadConfig();
/// <summary>
/// Open a file
/// </summary>
/// <param name="filename"></param>
[OperationContract]
void OpenFile(string filename);
}
}
#endif

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

View file

@ -1,19 +1,19 @@
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2020 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/>.
@ -23,6 +23,7 @@ using System.Drawing.Imaging;
using Dapplo.Log;
using Dapplo.Windows.Common.Extensions;
using Dapplo.Windows.Common.Structs;
using Greenshot.Gfx.Structs;
namespace Greenshot.Gfx
{
@ -47,7 +48,7 @@ namespace Greenshot.Gfx
}
return CreateEmpty(sourceImage.Width, sourceImage.Height, pixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
}
/// <summary>
/// A generic way to create an empty image
/// </summary>
@ -137,7 +138,7 @@ namespace Greenshot.Gfx
sourceRect = sourceRect.Intersect(bitmapRect);
}
// If no pixelformat is supplied
// If no pixelformat is supplied
if (PixelFormat.DontCare == targetFormat || PixelFormat.Undefined == targetFormat)
{
if (sourceBitmap.PixelFormat.IsPixelFormatSupported())
@ -206,7 +207,7 @@ namespace Greenshot.Gfx
Log.Warn().WriteLine(ex, "Problem cloning a propertyItem.");
}
}
return BitmapWrapper.FromBitmap(newImage);
}

View file

@ -1,19 +1,19 @@
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2020 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/>.
@ -86,7 +86,7 @@ namespace Greenshot.Gfx
/// <inheritdoc />
public Size Size => new Size(Width, Height);
/// <summary>
/// Factory method
/// </summary>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

View file

@ -103,7 +103,10 @@ namespace Greenshot.Gfx.Structs
/// <returns>Color</returns>
public static Color ToColor(this uint color)
{
return Color.FromArgb((int)color);
unchecked
{
return Color.FromArgb((int)color);
}
}
}
}

View file

@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Greenshot.PerformanceTests</RootNamespace>
<AssemblyName>Greenshot.PerformanceTests</AssemblyName>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

View file

@ -1,19 +1,19 @@
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2020 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/>.

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
@ -32,15 +32,16 @@
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Dapplo.Log.XUnit" Version="1.3.26" />
<PackageReference Include="Dapplo.Windows" Version="0.11.17" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Xunit.StaFact" Version="0.3.18" />
<PackageReference Include="Xunit.StaFact" Version="1.0.37" />
</ItemGroup>
<ItemGroup>

View file

@ -1,79 +0,0 @@
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2020 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/>.
#if !NETCOREAPP3_1
using System.Collections.Generic;
using System.ServiceModel;
using Greenshot.Addons.Interfaces;
namespace Greenshot.Components
{
/// <summary>
/// A simple helper to talk to an already running Greenshot instance
/// </summary>
public static class GreenshotClient
{
private static ChannelFactory<IGreenshotContract> ChannelFactory => new ChannelFactory<IGreenshotContract>(new NetNamedPipeBinding(), new EndpointAddress(GreenshotServerAction.EndPoint));
public static void Capture(string parameters)
{
using (var factory = ChannelFactory)
{
var client = factory.CreateChannel();
client.Capture(parameters);
}
}
public static void OpenFiles(List<string> filesToOpen)
{
if (filesToOpen == null || filesToOpen.Count == 0)
{
return;
}
using (var factory = ChannelFactory)
{
var client = factory.CreateChannel();
foreach (string filename in filesToOpen)
{
client.OpenFile(filename);
}
}
}
public static void Exit()
{
using (var factory = ChannelFactory)
{
var client = factory.CreateChannel();
client.Exit();
}
}
public static void ReloadConfig()
{
using (var factory = ChannelFactory)
{
var client = factory.CreateChannel();
client.ReloadConfig();
}
}
}
}
#endif

View file

@ -1,178 +0,0 @@
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2020 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/>.
#if !NETCOREAPP3_1
using System;
using System.IO;
using System.Linq;
using System.Security.Principal;
using System.ServiceModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dapplo.Addons;
using Dapplo.Log;
using Greenshot.Addons.Components;
using Greenshot.Addons.Core;
using Greenshot.Addons.Interfaces;
using Greenshot.Core.Enums;
using Greenshot.Forms;
using Greenshot.Helpers;
using Application = System.Windows.Application;
namespace Greenshot.Components
{
/// <summary>
/// This startup action starts the Greenshot "server", which allows to open files etc.
/// </summary>
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[Service(nameof(GreenshotServerAction), nameof(MainFormStartup))]
public class GreenshotServerAction : IGreenshotContract, IStartupAsync, IShutdownAsync
{
private static readonly LogSource Log = new LogSource();
private readonly ICoreConfiguration _coreConfiguration;
private readonly MainForm _mainForm;
private readonly HotkeyService _hotkeyService;
private readonly DestinationHolder _destinationHolder;
private ServiceHost _host;
private CaptureSupportInfo _captureSupportInfo;
public static string Identity
{
get
{
var windowsIdentity = WindowsIdentity.GetCurrent();
return windowsIdentity.User?.ToString();
}
}
public static string EndPoint => $"net.pipe://localhost/Greenshot/Greenshot_{Identity}";
public GreenshotServerAction(
ICoreConfiguration coreConfiguration,
MainForm mainForm,
HotkeyService hotkeyService,
DestinationHolder destinationHolder,
CaptureSupportInfo captureSupportInfo)
{
_captureSupportInfo = captureSupportInfo;
_coreConfiguration = coreConfiguration;
_mainForm = mainForm;
_hotkeyService = hotkeyService;
_destinationHolder = destinationHolder;
}
/// <inheritdoc />
public Task StartupAsync(CancellationToken cancellationToken = default)
{
// TODO: Test performance with Startup without async
Log.Debug().WriteLine("Starting Greenshot server");
return Task.Run(() => {
_host = new ServiceHost(this, new Uri("net.pipe://localhost/Greenshot"));
_host.AddServiceEndpoint(typeof(IGreenshotContract), new NetNamedPipeBinding(), "Greenshot_" + Identity);
_host.Open();
Log.Debug().WriteLine("Started Greenshot server");
}, cancellationToken);
}
public Task ShutdownAsync(CancellationToken cancellationToken = default)
{
Log.Debug().WriteLine("Stopping Greenshot server");
return Task.Factory.FromAsync((callback, stateObject) => _host.BeginClose(callback, stateObject), asyncResult => _host.EndClose(asyncResult), null);
}
/// <inheritdoc />
public void Exit()
{
Application.Current.Shutdown();
}
/// <inheritdoc />
public void ReloadConfig()
{
Log.Info().WriteLine("Reload requested");
try
{
// TODO: Fix
//IniConfig.Current?.ReloadAsync().Wait();
_mainForm.Invoke((MethodInvoker)(() =>
{
// Even update language when needed, this should be done automatically :)
_mainForm.UpdateUi();
}));
}
catch (Exception ex)
{
Log.Warn().WriteLine(ex, "Exception while reloading configuration: ");
}
}
/// <inheritdoc />
public void OpenFile(string filename)
{
Log.Debug().WriteLine("Open file requested: {0}", filename);
if (File.Exists(filename))
{
CaptureHelper.CaptureFile(_captureSupportInfo, filename);
}
else
{
Log.Warn().WriteLine("No such file: {0}", filename);
}
}
/// <inheritdoc />
public void Capture(string parameters)
{
if (MainForm.Instance.InvokeRequired)
{
MainForm.Instance.Invoke((MethodInvoker)(() => Capture(parameters)));
return;
}
Log.Info().WriteLine("Capture requested: {0}", parameters);
string[] optionsArray = parameters.Split(',');
string captureMode = optionsArray[0];
// Fallback-Destination
var designation = _coreConfiguration.OutputDestinations.FirstOrDefault();
var destination = _destinationHolder.SortedActiveDestinations.FirstOrDefault(d => d.Designation == designation);
switch (captureMode.ToLower())
{
case "region":
CaptureHelper.CaptureRegion(_captureSupportInfo, false, destination);
break;
case "window":
CaptureHelper.CaptureWindow(_captureSupportInfo, false, destination);
break;
case "fullscreen":
CaptureHelper.CaptureFullscreen(_captureSupportInfo, false, ScreenCaptureMode.FullScreen, destination);
break;
default:
Log.Warn().WriteLine("Unknown capture option");
break;
}
}
}
}
#endif

View file

@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<LangVersion>latest</LangVersion>
<ApplicationIcon>icons\applicationIcon\icon.ico</ApplicationIcon>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
@ -42,8 +42,8 @@
<PackageReference Include="gong-wpf-dragdrop" Version="2.2.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.7.335" />
<PackageReference Include="Svg" Version="3.1.1" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="3.3.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="3.3.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="3.4.1" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="3.4.1" />
<TrimmerRootAssembly Include="System.Diagnostics.Debug" />
</ItemGroup>

View file

@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.100",
"version": "5.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}