Moving back to trunk!

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1602 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-01-24 19:24:36 +00:00
commit 8d458998a1
332 changed files with 17647 additions and 9466 deletions

View file

@ -1,4 +1,5 @@
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{C82A0286-4172-4C61-9460-9E14A70C7F08}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -15,13 +16,6 @@
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
@ -29,14 +23,24 @@
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>x86</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
@ -53,7 +57,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RemoteConfiguration.cs" />
<Compile Include="RemotePlugin.cs" />
<Compile Include="WindowsHelper.cs" />
<None Include="Properties\AssemblyInfo.cs.template" />
</ItemGroup>
<ItemGroup>

View file

@ -20,6 +20,7 @@
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
@ -28,16 +29,19 @@ using System.Threading;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using GreenshotPlugin.UnmanagedHelpers;
using IniFile;
namespace GreenshotRemotePlugin {
class Server {
public class Server {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Server));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private string url;
private string accessKey;
private volatile bool keepGoing = true;
private HttpListener listener = null;
private ICaptureHost captureHost;
private IGreenshotPluginHost host;
private IGreenshotHost host;
public Server(string url, string accessKey) {
this.url = url;
this.accessKey = accessKey;
@ -49,23 +53,23 @@ namespace GreenshotRemotePlugin {
}
public void StopListening() {
keepGoing = false;
Close();
}
public void SetCaptureHost(ICaptureHost captureHost) {
this.captureHost = captureHost;
}
public void SetGreenshotPluginHost(IGreenshotPluginHost host) {
public void SetGreenshotPluginHost(IGreenshotHost host) {
this.host = host;
}
private void Listen() {
listener = new HttpListener();
//listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm;
listener.Prefixes.Add(url);
if (!listener.Prefixes.Contains(url)) {
listener.Prefixes.Add(url);
}
listener.Start();
LOG.DebugFormat("Listening on: {0}", url);
while (true) {
while (true) {
IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
while(!result.AsyncWaitHandle.WaitOne(1000)) {
if (!keepGoing) {
@ -77,15 +81,17 @@ namespace GreenshotRemotePlugin {
Close();
return;
}
}
}
}
private void Close() {
LOG.Debug("Cleaning up HttpListener");
listener.Stop();
listener.Prefixes.Remove(url);
listener.Close();
listener = null;
if (listener != null) {
LOG.Debug("Cleaning up HttpListener");
listener.Stop();
listener.Prefixes.Remove(url);
listener.Close();
listener = null;
}
}
private void ListenerCallback(IAsyncResult result) {
@ -134,11 +140,13 @@ namespace GreenshotRemotePlugin {
restored = true;
}
LOG.DebugFormat("Capturing window of class: {0}", captureWindow.ClassName);
using (Bitmap image = captureWindow.PrintWindow()) {
if (image != null) {
ICapture capture = null;
try {
capture = CaptureWindow(captureWindow, null, conf.WindowCaptureMode);
if (capture.Image != null) {
using (MemoryStream stream = new MemoryStream()) {
host.SaveToStream(image, stream, OutputFormat.png, 100);
host.SaveToStream(capture.Image, stream, OutputFormat.png, 100);
byte [] buffer = stream.GetBuffer();
response.ContentType = "image/png";
response.ContentLength64 = buffer.Length;
@ -149,12 +157,18 @@ namespace GreenshotRemotePlugin {
} else {
LOG.Debug("null image??");
}
} finally {
if (capture != null) {
capture.Dispose();
capture = null;
}
}
if (restored) {
captureWindow.Iconic = true;
}
} catch (Exception e) {
byte[] errorBuffer = Encoding.UTF8.GetBytes(e.StackTrace);
LOG.Error(e);
byte[] errorBuffer = Encoding.UTF8.GetBytes("An error occured...");
response.ContentLength64 = errorBuffer.Length;
response.OutputStream.Write(errorBuffer, 0, errorBuffer.Length);
response.OutputStream.Close();
@ -169,14 +183,12 @@ namespace GreenshotRemotePlugin {
if (user != null) {
sb.Append("Hello " + user + " ");
}
List<WindowDetails>windows = WindowDetails.GetAllWindows();
List<WindowDetails>windows = WindowDetails.GetVisibleWindows();
foreach(WindowDetails window in windows) {
if (window.Text.Length > 0 && window.Visible && !window.ClassName.StartsWith("Progman")) {
sb.Append("<A HREF=\"capture?handle=" + window.Handle +"&key="+ request.QueryString["key"] + "\">");
sb.Append(window.Text);
sb.Append("</A>");
sb.AppendLine("<br/>");
}
sb.Append("<A HREF=\"capture?handle=" + window.Handle +"&key="+ request.QueryString["key"] + "\">");
sb.Append(window.Text);
sb.Append("</A>");
sb.AppendLine("<br/>");
}
sb.Append("</body>");
sb.Append("</html>");
@ -185,5 +197,112 @@ namespace GreenshotRemotePlugin {
response.OutputStream.Write(b, 0, b.Length);
response.OutputStream.Close();
}
/// <summary>
/// Capture the supplied Window
/// </summary>
/// <param name="windowToCapture">Window to capture</param>
/// <param name="captureForWindow">The capture to store the details</param>
/// <param name="windowCaptureMode">What WindowCaptureMode to use</param>
/// <returns></returns>
public static ICapture CaptureWindow(WindowDetails windowToCapture, ICapture captureForWindow, WindowCaptureMode windowCaptureMode) {
if (captureForWindow == null) {
captureForWindow = new Capture();
}
Rectangle windowRectangle = windowToCapture.WindowRectangle;
if (windowToCapture.Iconic) {
// Restore the window making sure it's visible!
windowToCapture.Restore();
}
// When Vista & DWM (Aero) enabled
bool dwmEnabled = DWM.isDWMEnabled();
// get process name to be able to exclude certain processes from certain capture modes
Process process = windowToCapture.Process;
bool isAutoMode = windowCaptureMode == WindowCaptureMode.Auto;
// For WindowCaptureMode.Auto we check:
// 1) Is window IE, use IE Capture
// 2) Is Windows >= Vista & DWM enabled: use DWM
// 3) Otherwise use GDI (Screen might be also okay but might lose content)
if (isAutoMode) {
// Take default screen
windowCaptureMode = WindowCaptureMode.Screen;
// Change to GDI, if allowed
if (conf.isGDIAllowed(process)) {
windowCaptureMode = WindowCaptureMode.GDI;
}
// Change to DWM, if enabled and allowed
if (dwmEnabled) {
if (conf.isDWMAllowed(process)) {
windowCaptureMode = WindowCaptureMode.Aero;
}
}
} else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent) {
if (!dwmEnabled || !conf.isDWMAllowed(process)) {
// Take default screen
windowCaptureMode = WindowCaptureMode.Screen;
// Change to GDI, if allowed
if (conf.isGDIAllowed(process)) {
windowCaptureMode = WindowCaptureMode.GDI;
}
}
} else if (windowCaptureMode == WindowCaptureMode.GDI && !conf.isGDIAllowed(process)) {
// GDI not allowed, take screen
windowCaptureMode = WindowCaptureMode.Screen;
}
LOG.DebugFormat("Capturing window with mode {0}", windowCaptureMode);
bool captureTaken = false;
// Try to capture
while (!captureTaken) {
if (windowCaptureMode == WindowCaptureMode.GDI) {
ICapture tmpCapture = null;
if (conf.isGDIAllowed(process)) {
tmpCapture = windowToCapture.CaptureWindow(captureForWindow);
}
if (tmpCapture != null) {
captureForWindow = tmpCapture;
captureTaken = true;
} else {
// A problem, try Screen
windowCaptureMode = WindowCaptureMode.Screen;
}
} else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent) {
ICapture tmpCapture = null;
if (conf.isDWMAllowed(process)) {
tmpCapture = windowToCapture.CaptureDWMWindow(captureForWindow, windowCaptureMode, isAutoMode);
}
if (tmpCapture != null) {
captureForWindow = tmpCapture;
captureTaken = true;
} else {
// A problem, try GDI
windowCaptureMode = WindowCaptureMode.GDI;
}
} else {
// Screen capture
windowRectangle.Intersect(captureForWindow.ScreenBounds);
try {
captureForWindow = WindowCapture.CaptureRectangle(captureForWindow, windowRectangle);
captureTaken = true;
} catch (Exception e) {
LOG.Error("Problem capturing", e);
return null;
}
}
}
if (captureForWindow != null && windowToCapture != null && captureForWindow.Image != null) {
captureForWindow.CaptureDetails.Title = windowToCapture.Text;
using (Graphics graphics = Graphics.FromHwnd(windowToCapture.Handle)) {
((Bitmap)captureForWindow.Image).SetResolution(graphics.DpiX, graphics.DpiY);
}
}
return captureForWindow;
}
}
}

View file

@ -21,10 +21,11 @@
using System;
using GreenshotPlugin.Core;
using IniFile;
namespace GreenshotRemotePlugin {
/// <summary>
/// Description of CoreConfiguration.
/// Description of RemoteConfiguration.
/// </summary>
[IniSection("Remote", Description="Greenshot Remote Plugin configuration")]
public class RemoteConfiguration : IniSection {

View file

@ -19,11 +19,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using IniFile;
namespace GreenshotRemotePlugin {
/// <summary>
@ -31,24 +33,29 @@ namespace GreenshotRemotePlugin {
/// </summary>
public class RemotePlugin : IGreenshotPlugin {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(RemotePlugin));
private IGreenshotPluginHost host;
private ICaptureHost captureHost = null;
private IGreenshotHost host;
private PluginAttribute myAttributes;
private Server httpServer = null;
private RemoteConfiguration config;
public RemotePlugin() { }
public IEnumerable<IDestination> Destinations() {
yield break;
}
public IEnumerable<IProcessor> Processors() {
yield break;
}
/// <summary>
/// Implementation of the IGreenshotPlugin.Initialize
/// </summary>
/// <param name="host">Use the IGreenshotPluginHost interface to register events</param>
/// <param name="captureHost">Use the ICaptureHost interface to register in the MainContextMenu</param>
/// <param name="pluginAttribute">My own attributes</param>
public void Initialize(IGreenshotPluginHost host, ICaptureHost captureHost, PluginAttribute myAttributes) {
public bool Initialize(IGreenshotHost host, PluginAttribute myAttributes) {
LOG.Debug("Initialize called of " + myAttributes.Name);
this.host = (IGreenshotPluginHost)host;
this.captureHost = captureHost;
this.host = (IGreenshotHost)host;
this.myAttributes = myAttributes;
// Load configuration
@ -63,6 +70,7 @@ namespace GreenshotRemotePlugin {
IniConfig.IniChanged += new FileSystemEventHandler(ReloadConfiguration);
ReloadConfiguration(null, null);
return true;
}
private void ReloadConfiguration(object source, FileSystemEventArgs e) {
@ -72,7 +80,6 @@ namespace GreenshotRemotePlugin {
}
if (config.RemoteEnabled) {
httpServer = new Server(config.ListenerURL, config.AccessKey);
httpServer.SetCaptureHost(captureHost);
httpServer.SetGreenshotPluginHost(host);
httpServer.StartListening();
}
@ -96,6 +103,5 @@ namespace GreenshotRemotePlugin {
public virtual void Configure() {
return;
}
}
}

File diff suppressed because it is too large Load diff