Small enhancements to some off the class documentation. Working on performance tests for the screen capture. Updated Dapplo.Windows.

This commit is contained in:
Robin 2019-01-14 10:35:14 +01:00
commit e1c5ebdba8
38 changed files with 314 additions and 66 deletions

View file

@ -49,8 +49,8 @@
<PackageReference Include="Dapplo.HttpExtensions" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -55,7 +55,7 @@
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Dapplo.Confluence" Version="0.8.16" />
<PackageReference Include="Fody" Version="3.3.5">
<PrivateAssets>all</PrivateAssets>

View file

@ -51,8 +51,8 @@
<PackageReference Include="Dapplo.HttpExtensions" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -40,9 +40,9 @@
<PackageReference Include="AutoProperties.Fody" Version="1.19.0" />
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="CliWrap" Version="2.2.0" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -49,8 +49,8 @@
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -49,8 +49,8 @@
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -50,8 +50,8 @@
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -30,10 +30,10 @@
<ItemGroup>
<PackageReference Include="Dapplo.Windows">
<Version>0.8.3</Version>
<Version>0.8.7</Version>
</PackageReference>
<PackageReference Include="Dapplo.Windows.Com">
<Version>0.8.3</Version>
<Version>0.8.7</Version>
</PackageReference>
<PackageReference Include="Unofficial.Microsoft.mshtml" Version="7.0.3300" />
</ItemGroup>

View file

@ -53,7 +53,7 @@
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Utils" Version="1.1.9" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Dapplo.Jira" Version="0.8.9" />
<PackageReference Include="Fody" Version="3.3.5">
<PrivateAssets>all</PrivateAssets>

View file

@ -136,9 +136,9 @@
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Icons" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Dapplo.Windows.Icons" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -50,7 +50,7 @@
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="MahApps.Metro" Version="2.0.0-alpha0170" />
<PackageReference Include="Fody" Version="3.3.5">
<PrivateAssets>all</PrivateAssets>

View file

@ -40,8 +40,8 @@
<PackageReference Include="AutoProperties.Fody" Version="1.19.0" />
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -40,7 +40,7 @@
<PackageReference Include="AutoProperties.Fody" Version="1.19.0" />
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Interop.Microsoft.Office.Interop.OneNote" Version="1.1.0" />
<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1000" />
<PackageReference Include="Microsoft.Office.Interop.Outlook" Version="15.0.4797.1003" />

View file

@ -28,8 +28,13 @@ using Dapplo.Config.Language;
#endregion
#pragma warning disable 1591
namespace Greenshot.Addon.OneDrive.Configuration
{
/// <summary>
/// This interface contains all the translations for the OneDrive addon
/// </summary>
[Language("OneDrive")]
public interface IOneDriveLanguage : ILanguage, INotifyPropertyChanged
{
@ -50,3 +55,5 @@ namespace Greenshot.Addon.OneDrive.Configuration
string ResetCredentialsButton { get; }
}
}
#pragma warning restore 1591

View file

@ -25,11 +25,20 @@ using Newtonsoft.Json;
namespace Greenshot.Addon.OneDrive.Entities
{
/// <summary>
/// The request to get a link
/// </summary>
public class OneDriveGetLinkRequest
{
/// <summary>
/// The type of the link which is requested
/// </summary>
[JsonProperty("type")]
public string Type;
/// <summary>
/// Scope of the link
/// </summary>
[JsonProperty("scope")]
public string Scope;
}

View file

@ -25,18 +25,21 @@ using Newtonsoft.Json;
namespace Greenshot.Addon.OneDrive.Entities
{
/// <summary>
/// This is the response for the "get link" API
/// </summary>
public class OneDriveGetLinkResponse
{
/// <summary>
/// The ID for the response
/// </summary>
[JsonProperty("id")]
public string Id;
/// <summary>
/// The property for the actual link
/// </summary>
[JsonProperty("link")]
public OneDriveGetLinkResponseLink Link;
public class OneDriveGetLinkResponseLink
{
[JsonProperty("webUrl")]
public string WebUrl;
}
}
}

View file

@ -0,0 +1,39 @@
#region Greenshot GNU General Public License
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2018 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/>.
#endregion
using Newtonsoft.Json;
namespace Greenshot.Addon.OneDrive.Entities
{
/// <summary>
/// The actual link
/// </summary>
public class OneDriveGetLinkResponseLink
{
/// <summary>
/// This is the value of the link
/// </summary>
[JsonProperty("webUrl")]
public string WebUrl;
}
}

View file

@ -25,11 +25,20 @@ using Newtonsoft.Json;
namespace Greenshot.Addon.OneDrive.Entities
{
/// <summary>
/// The response for the upload, only what we need is defined here
/// </summary>
public class OneDriveUploadResponse
{
/// <summary>
/// Id of the response
/// </summary>
[JsonProperty("id")]
public string Id;
/// <summary>
/// The url
/// </summary>
[JsonProperty("webUrl")]
public string WebUrl;
}

View file

@ -50,7 +50,7 @@
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="MahApps.Metro" Version="2.0.0-alpha0170" />
<PackageReference Include="Fody" Version="3.3.5">
<PrivateAssets>all</PrivateAssets>

View file

@ -34,6 +34,7 @@ using Greenshot.Addons.ViewModels;
namespace Greenshot.Addon.OneDrive.ViewModels
{
/// <inherit />
public sealed class OneDriveConfigViewModel : SimpleConfigScreen
{
/// <summary>
@ -41,11 +42,33 @@ namespace Greenshot.Addon.OneDrive.ViewModels
/// </summary>
private CompositeDisposable _disposables;
/// <summary>
/// Used in the view to change the configuration
/// </summary>
public IOneDriveConfiguration OneDriveConfiguration { get; }
/// <summary>
/// Used in the view for the translations
/// </summary>
public IOneDriveLanguage OneDriveLanguage { get; }
/// <summary>
/// Used in the view for the translations
/// </summary>
public IGreenshotLanguage GreenshotLanguage { get; }
/// <summary>
/// Used in the view to change the file configuration
/// </summary>
public FileConfigPartViewModel FileConfigPartViewModel { get; }
/// <summary>
/// Constructor used for dependency injection
/// </summary>
/// <param name="oneDriveConfiguration">IOneDriveConfiguration</param>
/// <param name="oneDriveLanguage">IOneDriveLanguage</param>
/// <param name="greenshotLanguage">IGreenshotLanguage</param>
/// <param name="fileConfigPartViewModel"><FileConfigPartViewModel/param>
public OneDriveConfigViewModel(
IOneDriveConfiguration oneDriveConfiguration,
IOneDriveLanguage oneDriveLanguage,
@ -58,6 +81,8 @@ namespace Greenshot.Addon.OneDrive.ViewModels
GreenshotLanguage = greenshotLanguage;
FileConfigPartViewModel = fileConfigPartViewModel;
}
/// <inherit />
public override void Initialize(IConfig config)
{
FileConfigPartViewModel.DestinationFileConfiguration = OneDriveConfiguration;
@ -78,6 +103,7 @@ namespace Greenshot.Addon.OneDrive.ViewModels
base.Initialize(config);
}
/// <inherit />
protected override void OnDeactivate(bool close)
{
_disposables.Dispose();
@ -98,6 +124,9 @@ namespace Greenshot.Addon.OneDrive.ViewModels
public bool CanResetCredentials => OneDriveConfiguration.HasToken();
/// <summary>
/// Used to reset/clear the OAuth credentials
/// </summary>
public void ResetCredentials()
{
OneDriveConfiguration.ResetToken();

View file

@ -49,8 +49,8 @@
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

View file

@ -50,7 +50,7 @@
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.9.18" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="MahApps.Metro" Version="2.0.0-alpha0170" />
<PackageReference Include="Fody" Version="3.3.5">
<PrivateAssets>all</PrivateAssets>

View file

@ -61,6 +61,6 @@
<ItemGroup>
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="1.2.19" />
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="1.2.19" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
</ItemGroup>
</Project>

View file

@ -3,17 +3,28 @@ using Windows.Storage.Streams;
namespace Greenshot.Addon.Win10
{
/// <summary>
/// This is an IRandomAccessStream implementation which uses a MemoryStream
/// </summary>
public sealed class MemoryRandomAccessStream : MemoryStream, IRandomAccessStream
{
/// <summary>
/// Default constructor
/// </summary>
public MemoryRandomAccessStream()
{
}
/// <summary>
/// Constructor where also bytes are already passed
/// </summary>
/// <param name="bytes">byte array</param>
public MemoryRandomAccessStream(byte[] bytes)
{
Write(bytes, 0, bytes.Length);
}
/// <inheritdoc />
public IInputStream GetInputStreamAt(ulong position)
{
Seek((long)position, SeekOrigin.Begin);
@ -21,6 +32,7 @@ namespace Greenshot.Addon.Win10
return this.AsInputStream();
}
/// <inheritdoc />
public IOutputStream GetOutputStreamAt(ulong position)
{
Seek((long)position, SeekOrigin.Begin);
@ -28,14 +40,17 @@ namespace Greenshot.Addon.Win10
return this.AsOutputStream();
}
/// <inheritdoc />
ulong IRandomAccessStream.Position => (ulong)Position;
/// <inheritdoc />
public ulong Size
{
get { return (ulong)Length; }
set { SetLength((long)value); }
}
/// <inheritdoc />
public IRandomAccessStream CloneStream()
{
var cloned = new MemoryRandomAccessStream();
@ -43,23 +58,27 @@ namespace Greenshot.Addon.Win10
return cloned;
}
/// <inheritdoc />
public void Seek(ulong position)
{
Seek((long)position, SeekOrigin.Begin);
}
/// <inheritdoc />
public Windows.Foundation.IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
{
var inputStream = GetInputStreamAt(0);
return inputStream.ReadAsync(buffer, count, options);
}
/// <inheritdoc />
Windows.Foundation.IAsyncOperation<bool> IOutputStream.FlushAsync()
{
var outputStream = GetOutputStreamAt(0);
return outputStream.FlushAsync();
}
/// <inheritdoc />
public Windows.Foundation.IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)
{
var outputStream = GetOutputStreamAt(0);

View file

@ -38,12 +38,18 @@ namespace Greenshot.Addon.Win10.Native
private readonly IDataTransferManagerInterOp _dataTransferManagerInterOp;
private readonly IntPtr _windowHandle;
/// <summary>
/// The DataTransferManager
/// </summary>
public DataTransferManager DataTransferManager
{
get;
private set;
}
/// <summary>
/// Constructor which takes a handle to initialize
/// </summary>
/// <param name="handle"></param>
public DataTransferManagerHelper(IntPtr handle)
{
//TODO: Add a check for failure here. This will fail for versions of Windows below Windows 10

View file

@ -30,6 +30,7 @@ namespace Greenshot.Addon.Win10
/// <inheritdoc />
public class Win10AddonModule : AddonModule
{
/// <inheritdoc />
protected override void Load(ContainerBuilder builder)
{
if (WindowsVersion.IsWindows10OrLater)

View file

@ -44,6 +44,7 @@ namespace Greenshot.Addon.Win10
private readonly ExportNotification _exportNotification;
private static readonly LogSource Log = new LogSource();
/// <inheritdoc />
public override string Description { get; } = "Windows 10 OCR";
/// <summary>

View file

@ -54,6 +54,12 @@ namespace Greenshot.Addon.Win10
private readonly ExportNotification _exportNotification;
private static readonly LogSource Log = new LogSource();
/// <summary>
/// Default constructor used for dependency injection
/// </summary>
/// <param name="coreConfiguration">ICoreConfiguration</param>
/// <param name="greenshotLanguage">IGreenshotLanguage</param>
/// <param name="exportNotification">ExportNotification</param>
public Win10ShareDestination(
ICoreConfiguration coreConfiguration,
IGreenshotLanguage greenshotLanguage,
@ -62,6 +68,7 @@ namespace Greenshot.Addon.Win10
_exportNotification = exportNotification;
}
/// <inheritdoc />
public override string Description { get; } = "Windows 10 share";
/// <summary>

View file

@ -62,10 +62,10 @@
<Version>0.9.18</Version>
</PackageReference>
<PackageReference Include="Dapplo.Windows.Clipboard">
<Version>0.8.3</Version>
<Version>0.8.7</Version>
</PackageReference>
<PackageReference Include="Dapplo.Windows.Icons">
<Version>0.8.3</Version>
<Version>0.8.7</Version>
</PackageReference>
<PackageReference Include="Fody" Version="3.3.5">
<PrivateAssets>all</PrivateAssets>
@ -75,7 +75,7 @@
<Version>3.0.0-alpha0096</Version>
</PackageReference>
<PackageReference Include="Svg">
<Version>2.3.0</Version>
<Version>2.4.0</Version>
</PackageReference>
</ItemGroup>

View file

@ -29,7 +29,7 @@
<ItemGroup>
<PackageReference Include="Dapplo.Windows.Icons">
<Version>0.8.3</Version>
<Version>0.8.7</Version>
</PackageReference>
</ItemGroup>

View file

@ -36,7 +36,7 @@
<Version>4.5.0</Version>
</PackageReference>
<PackageReference Include="System.Memory">
<Version>4.5.1</Version>
<Version>4.5.2</Version>
</PackageReference>
<PackageReference Include="System.Numerics.Vectors">
<Version>4.5.0</Version>

View file

@ -32,7 +32,7 @@
<Version>1.2.19</Version>
</PackageReference>
<PackageReference Include="Svg">
<Version>2.3.0</Version>
<Version>2.4.0</Version>
</PackageReference>
</ItemGroup>
</Project>

View file

@ -0,0 +1,103 @@
#region Greenshot GNU General Public License
// Greenshot - a free and open source screenshot tool
// Copyright (C) 2007-2018 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/>.
#endregion
#region Usings
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using Dapplo.Log;
using Dapplo.Windows.Common;
using Dapplo.Windows.Common.Extensions;
using Dapplo.Windows.Common.Structs;
using Dapplo.Windows.Gdi32;
using Dapplo.Windows.Gdi32.Enums;
using Dapplo.Windows.Gdi32.SafeHandles;
using Dapplo.Windows.Gdi32.Structs;
using Dapplo.Windows.Icons;
using Dapplo.Windows.User32;
using Dapplo.Windows.User32.Enums;
using Dapplo.Windows.User32.Structs;
using Greenshot.Addons.Config.Impl;
using Greenshot.Addons.Interfaces;
using Greenshot.Gfx;
#endregion
namespace Greenshot.Addons.Core
{
/// <summary>
/// The screen Capture code
/// </summary>
public class ScreenCapture : IDisposable
{
private static readonly LogSource Log = new LogSource();
private readonly ICoreConfiguration _coreConfiguration;
private readonly NativeRect _captureBounds;
private readonly SafeWindowDcHandle _desktopDcHandle;
private readonly SafeCompatibleDcHandle _safeCompatibleDcHandle;
private readonly BitmapInfoHeader _bitmapInfoHeader;
private readonly SafeDibSectionHandle _safeDibSectionHandle;
private readonly SafeSelectObjectHandle _safeSelectObjectHandle;
public ScreenCapture(ICoreConfiguration coreConfiguration, NativeRect captureBounds)
{
_coreConfiguration = coreConfiguration;
_captureBounds = captureBounds;
_desktopDcHandle = SafeWindowDcHandle.FromDesktop();
_safeCompatibleDcHandle = Gdi32Api.CreateCompatibleDC(_desktopDcHandle);
// Create BitmapInfoHeader for CreateDIBSection
_bitmapInfoHeader = BitmapInfoHeader.Create(captureBounds.Width, captureBounds.Height, 24);
_safeDibSectionHandle = Gdi32Api.CreateDIBSection(_desktopDcHandle, ref _bitmapInfoHeader, DibColors.PalColors, out _, IntPtr.Zero, 0);
// select the bitmap object and store the old handle
_safeSelectObjectHandle = _safeCompatibleDcHandle.SelectObject(_safeDibSectionHandle);
}
public void CaptureFrame()
{
// bit-blt over (make copy)
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
Gdi32Api.BitBlt(_safeCompatibleDcHandle, 0, 0, _captureBounds.Width, _captureBounds.Height, _desktopDcHandle, _captureBounds.X, _captureBounds.Y,
RasterOperations.SourceCopy | RasterOperations.CaptureBlt);
//return Imaging.CreateBitmapSourceFromHBitmap(_safeDibSectionHandle.DangerousGetHandle(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
public void Dispose()
{
_safeSelectObjectHandle.Dispose();
_safeDibSectionHandle.Dispose();
_safeCompatibleDcHandle.Dispose();
_desktopDcHandle.Dispose();
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using BenchmarkDotNet.Attributes;
using Dapplo.Windows.User32;
using Greenshot.Addons.Core;
namespace Greenshot.PerformanceTests
@ -10,7 +11,9 @@ namespace Greenshot.PerformanceTests
[MinColumn, MaxColumn, MemoryDiagnoser]
public class CapturePerformance
{
[Benchmark]
private readonly ScreenCapture _screenCapture = new ScreenCapture(null, DisplayInfo.ScreenBounds);
//[Benchmark]
public void Capture()
{
using (var capture = WindowCapture.CaptureScreen())
@ -25,5 +28,18 @@ namespace Greenshot.PerformanceTests
}
}
}
[Benchmark]
public void CaptureBuffered()
{
_screenCapture.CaptureFrame();
}
[GlobalCleanup]
public void Cleanup()
{
_screenCapture.Dispose();
}
}
}

View file

@ -66,7 +66,8 @@
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
<PackageReference Include="System.Memory" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.2" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
</ItemGroup>
</Project>

View file

@ -78,6 +78,7 @@
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />

View file

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
# Visual Studio Version 16
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Greenshot", "Greenshot\Greenshot.csproj", "{CD642BF4-D815-4D67-A0B5-C69F0B8231AF}"
EndProject

View file

@ -9,9 +9,6 @@
<ApplicationManifest>greenshot.manifest</ApplicationManifest>
<AssemblyTitle>Greenshot</AssemblyTitle>
<AssemblyName>Greenshot</AssemblyName>
<!--RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained-->
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
<ItemGroup>
@ -91,16 +88,16 @@
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.9.18" />
<PackageReference Include="Dapplo.Log.LogFile" Version="1.3.11" />
<PackageReference Include="Dapplo.Log.Loggers" Version="1.3.11" />
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Icons" Version="0.8.3" />
<PackageReference Include="Dapplo.Windows.Multimedia" Version="0.8.3" />
<PackageReference Include="Fody" Version="3.3.5">
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.8.7" />
<PackageReference Include="Dapplo.Windows.Icons" Version="0.8.7" />
<PackageReference Include="Dapplo.Windows.Multimedia" Version="0.8.7" />
<PackageReference Include="Fody" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="gong-wpf-dragdrop" Version="2.0.0-alpha0106" />
<PackageReference Include="MahApps.Metro.IconPacks" Version="3.0.0-alpha0096" />
<PackageReference Include="Svg" Version="2.3.0" />
<PackageReference Include="Svg" Version="2.4.0" />
</ItemGroup>
<ItemGroup>