Fixed language loading issues

Removed System.Reactive as package, by using code that was already there
Fixed an issue loading the confluence plugin, and finding the icon
This commit is contained in:
Robin Krom 2020-02-09 23:11:09 +01:00
commit f8f203b7b8
35 changed files with 902 additions and 964 deletions

View file

@ -72,6 +72,8 @@
mkdir "$(SolutionDir)$(SolutionName)\$(OutDir)Languages"

)

xcopy /q /y /d "$(TargetDir)Languages\*.xml" "$(SolutionDir)$(SolutionName)\$(OutDir)Languages"

del "$(SolutionDir)$(SolutionName)\$(OutDir)Languages\language-installer*.xml";

del "$(SolutionDir)$(SolutionName)\$(OutDir)Languages\language-website*.xml";

)" />
</Target>
</Project>

View file

@ -72,4 +72,9 @@
<SetEnvironmentVariableTask Name="AssemblyInformationalVersion" Value="$(AssemblyInformationalVersion)" />
<Exec Command="$(PkgTools_InnoSetup)\tools\ISCC.exe $(SolutionDir)\greenshot\releases\innosetup\setup.iss" />
</Target>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<PreBuildEvent>
copy "$(SolutionDir)Greenshot\log4net-debug.xml" "$(SolutionDir)Greenshot\bin\$(Configuration)\net471\log4net.xml"
</PreBuildEvent>
</PropertyGroup>
</Project>

View file

@ -12,6 +12,16 @@
</None>
</ItemGroup>
<ItemGroup>
<None Remove="Images\Confluence.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Confluence.ico">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<WebReferences Include="Web References\" />
<WebReferenceUrl Include="http://confluence/rpc/soap-axis/confluenceservice-v1%3fwsdl">

View file

@ -21,7 +21,6 @@
using Greenshot.Plugin;
using System.Runtime.InteropServices;
using System.Security;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@ -32,6 +31,3 @@ using System.Security;
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// Solve Link-Demand issues
[assembly: SecurityTransparent]

View file

@ -1,50 +0,0 @@
/*
* dapplo - building blocks for desktop applications
* Copyright (C) Dapplo 2015-2016
*
* For more information see: http://dapplo.net/
* dapplo repositories are hosted on GitHub: https://github.com/dapplo
*
* 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;
namespace GreenshotJiraPlugin.Hooking
{
/// <summary>
/// Event arguments for the TitleChangeEvent
/// </summary>
public class TitleChangeEventArgs : EventArgs
{
/// <summary>
/// HWnd of the window which has a changed title
/// </summary>
public IntPtr HWnd
{
get;
set;
}
/// <summary>
/// Title which is changed
/// </summary>
public string Title
{
get;
set;
}
}
}

View file

@ -1,29 +0,0 @@
/*
* dapplo - building blocks for desktop applications
* Copyright (C) Dapplo 2015-2016
*
* For more information see: http://dapplo.net/
* dapplo repositories are hosted on GitHub: https://github.com/dapplo
*
* 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/>.
*/
namespace GreenshotJiraPlugin.Hooking
{
/// <summary>
/// Delegate for the title change event
/// </summary>
/// <param name="eventArgs"></param>
public delegate void TitleChangeEventDelegate(TitleChangeEventArgs eventArgs);
}

View file

@ -27,7 +27,7 @@ using System.Threading;
using System.Threading.Tasks;
using Dapplo.Jira;
using Dapplo.Log;
using GreenshotJiraPlugin.Hooking;
using GreenshotPlugin.Hooking;
namespace GreenshotJiraPlugin
{

View file

@ -24,7 +24,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using GreenshotPlugin.UnmanagedHelpers;
namespace GreenshotJiraPlugin.Hooking
namespace GreenshotPlugin.Hooking
{
/// <summary>
/// The WinEventHook can register handlers to become important windows events

View file

@ -0,0 +1,171 @@
/*
* dapplo - building blocks for desktop applications
* Copyright (C) Dapplo 2015-2016
*
* For more information see: http://dapplo.net/
* dapplo repositories are hosted on GitHub: https://github.com/dapplo
*
* 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 GreenshotPlugin.Core;
using GreenshotPlugin.UnmanagedHelpers;
namespace GreenshotPlugin.Hooking
{
/// <summary>
/// Event arguments for the WindowOpenCloseEvent
/// </summary>
public class WindowOpenCloseEventArgs : EventArgs
{
public bool IsOpen { get; set; }
/// <summary>
/// HWnd of the window which has a changed title
/// </summary>
public IntPtr HWnd
{
get;
set;
}
/// <summary>
/// Title which is changed
/// </summary>
public string Title
{
get;
set;
}
public string ClassName { get; set; }
}
/// <summary>
/// Delegate for the title change event
/// </summary>
/// <param name="eventArgs"></param>
public delegate void WindowOpenCloseEventDelegate(WindowOpenCloseEventArgs eventArgs);
/// <summary>
/// Monitor all title changes
/// </summary>
public sealed class WindowsOpenCloseMonitor : IDisposable
{
private WindowsEventHook _hook;
private readonly object _lockObject = new object();
// ReSharper disable once InconsistentNaming
private event WindowOpenCloseEventDelegate _windowOpenCloseEvent;
/// <summary>
/// Add / remove event handler to the title monitor
/// </summary>
public event WindowOpenCloseEventDelegate WindowOpenCloseChangeEvent
{
add
{
lock (_lockObject)
{
if (_hook == null)
{
_hook = new WindowsEventHook();
_hook.Hook(WinEvent.EVENT_OBJECT_CREATE, WinEvent.EVENT_OBJECT_DESTROY, WinEventHandler);
}
_windowOpenCloseEvent += value;
}
}
remove
{
lock (_lockObject)
{
_windowOpenCloseEvent -= value;
if (_windowOpenCloseEvent == null || _windowOpenCloseEvent.GetInvocationList().Length == 0)
{
if (_hook != null)
{
_hook.Dispose();
_hook = null;
}
}
}
}
}
/// <summary>
/// WinEventDelegate for the creation & destruction
/// </summary>
/// <param name="eventType"></param>
/// <param name="hWnd"></param>
/// <param name="idObject"></param>
/// <param name="idChild"></param>
/// <param name="dwEventThread"></param>
/// <param name="dwmsEventTime"></param>
private void WinEventHandler(WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
if (hWnd == IntPtr.Zero || idObject != EventObjects.OBJID_WINDOW)
{
return;
}
if (eventType == WinEvent.EVENT_OBJECT_CREATE)
{
if (_windowOpenCloseEvent != null)
{
var windowsDetails = new WindowDetails(hWnd);
_windowOpenCloseEvent(new WindowOpenCloseEventArgs { HWnd = hWnd, IsOpen = true, Title = windowsDetails.Text, ClassName = windowsDetails.ClassName });
}
}
if (eventType == WinEvent.EVENT_OBJECT_DESTROY)
{
_windowOpenCloseEvent?.Invoke(new WindowOpenCloseEventArgs { HWnd = hWnd, IsOpen = false });
}
}
private bool _disposedValue; // To detect redundant calls
/// <summary>
/// Dispose the underlying hook
/// </summary>
public void Dispose(bool disposing)
{
if (_disposedValue)
{
return;
}
lock (_lockObject)
{
_hook?.Dispose();
}
_disposedValue = true;
}
/// <summary>
/// Make sure the finalizer disposes the underlying hook
/// </summary>
~WindowsOpenCloseMonitor()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(false);
}
/// <summary>
/// Dispose the underlying hook
/// </summary>
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

View file

@ -23,8 +23,37 @@ using System;
using GreenshotPlugin.Core;
using GreenshotPlugin.UnmanagedHelpers;
namespace GreenshotJiraPlugin.Hooking
namespace GreenshotPlugin.Hooking
{
/// <summary>
/// Event arguments for the TitleChangeEvent
/// </summary>
public class TitleChangeEventArgs : EventArgs
{
/// <summary>
/// HWnd of the window which has a changed title
/// </summary>
public IntPtr HWnd
{
get;
set;
}
/// <summary>
/// Title which is changed
/// </summary>
public string Title
{
get;
set;
}
}
/// <summary>
/// Delegate for the title change event
/// </summary>
/// <param name="eventArgs"></param>
public delegate void TitleChangeEventDelegate(TitleChangeEventArgs eventArgs);
/// <summary>
/// Monitor all title changes
/// </summary>

View file

@ -14,7 +14,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" version="10.0.18362.2005" />
<PackageReference Include="System.Reactive" Version="4.3.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj" />

View file

@ -1,70 +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/>.
using GreenshotPlugin.UnmanagedHelpers;
using System;
namespace Greenshot.Addon.Win10.Native
{
/// <summary>
/// Container for the windows messages
/// </summary>
public class WindowMessageInfo
{
/// <summary>
/// IntPtr with the Handle of the window
/// </summary>
public IntPtr Handle { get; private set; }
/// <summary>
/// WindowsMessages which is the actual message
/// </summary>
public WindowsMessages Message { get; private set; }
/// <summary>
/// IntPtr with the word-param
/// </summary>
public IntPtr WordParam { get; private set; }
/// <summary>
/// IntPtr with the long-param
/// </summary>
public IntPtr LongParam { get; private set; }
/// <summary>
/// Factory method for the Window Message Info
/// </summary>
/// <param name="hwnd">IntPtr with the Handle of the window</param>
/// <param name="msg">WindowsMessages which is the actual message</param>
/// <param name="wParam">IntPtr with the word-param</param>
/// <param name="lParam">IntPtr with the long-param</param>
/// <param name="handled"></param>
/// <returns>WindowMessageInfo</returns>
public static WindowMessageInfo Create(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
return new WindowMessageInfo
{
Handle = hwnd,
Message = (WindowsMessages)msg,
WordParam = wParam,
LongParam = lParam
};
}
}
}

View file

@ -1,137 +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/>.
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Interop;
namespace Greenshot.Addon.Win10.Native
{
/// <summary>
/// A monitor for window messages
/// </summary>
public static class WindowMessageMonitor
{
/// <summary>
/// Create a HwndSource for the specified Window
/// </summary>
/// <param name="window">Window</param>
/// <returns>HwndSource</returns>
private static HwndSource ToHwndSource(this Window window)
{
IntPtr windowHandle = new WindowInteropHelper(window).Handle;
if (windowHandle == IntPtr.Zero)
{
return null;
}
return HwndSource.FromHwnd(windowHandle);
}
/// <summary>
/// Create an observable for the specified window
/// </summary>
public static IObservable<WindowMessageInfo> WindowMessages(this Window window)
{
return WindowMessages(window, null);
}
/// <summary>
/// Create an observable for the specified HwndSource
/// </summary>
public static IObservable<WindowMessageInfo> WindowMessages(this HwndSource hwndSource)
{
return WindowMessages(null, hwndSource);
}
/// <summary>
/// Create an observable for the specified window or HwndSource
/// </summary>
/// <param name="window">Window</param>
/// <param name="hwndSource">HwndSource</param>
/// <returns>IObservable</returns>
private static IObservable<WindowMessageInfo> WindowMessages(Window window, HwndSource hwndSource)
{
if (window == null && hwndSource == null)
{
throw new NotSupportedException("One of Window or HwndSource must be supplied");
}
if (window != null && hwndSource != null)
{
throw new NotSupportedException("Either Window or HwndSource must be supplied");
}
return Observable.Create<WindowMessageInfo>(observer =>
{
// This handles the message, and generates the observable OnNext
IntPtr WindowMessageHandler(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
observer.OnNext(WindowMessageInfo.Create(hwnd, msg, wParam, lParam, ref handled));
// ReSharper disable once AccessToDisposedClosure
if (hwndSource.IsDisposed)
{
observer.OnCompleted();
}
return IntPtr.Zero;
}
void HwndSourceDisposedHandle(object sender, EventArgs e)
{
observer.OnCompleted();
}
void RegisterHwndSource()
{
hwndSource.Disposed += HwndSourceDisposedHandle;
hwndSource.AddHook(WindowMessageHandler);
}
if (window != null)
{
hwndSource = window.ToHwndSource();
}
if (hwndSource != null)
{
RegisterHwndSource();
}
else
{
// No, try to get it later
window.SourceInitialized += (sender, args) =>
{
hwndSource = window.ToHwndSource();
RegisterHwndSource();
};
}
return Disposable.Create(() =>
{
hwndSource.Disposed -= HwndSourceDisposedHandle;
hwndSource.RemoveHook(WindowMessageHandler);
hwndSource.Dispose();
});
})
// Make sure there is always a value produced when connecting
.Publish()
.RefCount();
}
}
}

View file

@ -28,15 +28,13 @@ using System.Windows.Interop;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.Storage.Streams;
using Greenshot.Addon.Win10.Native;
using Color = Windows.UI.Color;
using System.Reactive.Linq;
using GreenshotPlugin.UnmanagedHelpers;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using System.Drawing;
using GreenshotWin10Plugin.Native;
using System.Windows.Media;
using GreenshotPlugin.Hooking;
namespace GreenshotWin10Plugin
{
@ -67,6 +65,8 @@ namespace GreenshotWin10Plugin
public TaskCompletionSource<bool> ShareTask { get; } = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
public bool IsDataRequested { get; set; }
public IntPtr SharingHwnd { get; set; }
}
/// <summary>
@ -92,28 +92,42 @@ namespace GreenshotWin10Plugin
AllowsTransparency = true,
Background = new SolidColorBrush(Colors.Transparent)
};
var shareInfo = new ShareInfo();
triggerWindow.Show();
var shareInfo = new ShareInfo();
var focusMonitor = new WindowsOpenCloseMonitor();
var windowHandle = new WindowInteropHelper(triggerWindow).Handle;
// This is a bad trick, but don't know how else to do it.
// Wait for the focus to return, and depending on the state close the window!
triggerWindow.WindowMessages()
.Where(m => m.Message == WindowsMessages.WM_SETFOCUS).Delay(TimeSpan.FromSeconds(1))
.Subscribe(info =>
focusMonitor.WindowOpenCloseChangeEvent += e => {
if (e.IsOpen)
{
if ("Windows Shell Experience Host" == e.Title)
{
shareInfo.SharingHwnd = e.HWnd;
}
return;
}
else
{
if (e.HWnd == shareInfo.SharingHwnd)
{
if (shareInfo.ApplicationName != null)
{
return;
}
shareInfo.ShareTask.TrySetResult(false);
});
var windowHandle = new WindowInteropHelper(triggerWindow).Handle;
}
}
};
Share(shareInfo, windowHandle, surface, captureDetails).GetAwaiter().GetResult();
Log.Debug("Sharing finished, closing window.");
triggerWindow.Close();
focusMonitor.Dispose();
if (string.IsNullOrWhiteSpace(shareInfo.ApplicationName))
{
exportInformation.ExportMade = false;
@ -144,10 +158,9 @@ namespace GreenshotWin10Plugin
/// <returns>Task with string, which describes the application which was used to share with</returns>
private async Task Share(ShareInfo shareInfo, IntPtr handle, ISurface surface, ICaptureDetails captureDetails)
{
using (var imageStream = new MemoryRandomAccessStream())
using (var logoStream = new MemoryRandomAccessStream())
using (var thumbnailStream = new MemoryRandomAccessStream())
{
using var imageStream = new MemoryRandomAccessStream();
using var logoStream = new MemoryRandomAccessStream();
using var thumbnailStream = new MemoryRandomAccessStream();
var outputSettings = new SurfaceOutputSettings();
outputSettings.PreventGreenshotFormat();
@ -248,7 +261,7 @@ namespace GreenshotWin10Plugin
dataPackage.Properties.Thumbnail = thumbnailRandomAccessStreamReference;
dataPackage.Properties.Square30x30Logo = logoRandomAccessStreamReference;
dataPackage.Properties.LogoBackgroundColor = Color.FromArgb(0xff, 0x3d, 0x3d, 0x3d);
dataPackage.SetStorageItems(new[] {storageFile});
dataPackage.SetStorageItems(new[] { storageFile });
dataPackage.SetBitmap(imageRandomAccessStreamReference);
}
finally
@ -262,5 +275,4 @@ namespace GreenshotWin10Plugin
await shareInfo.ShareTask.Task.ConfigureAwait(false);
}
}
}
}