"Merged" 0.8 with HEAD, so we can continue developing

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1282 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2011-07-17 12:05:59 +00:00
commit f3b0878b02
539 changed files with 86855 additions and 0 deletions

View file

@ -0,0 +1,70 @@
<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>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>GreenshotRemotePlugin</RootNamespace>
<AssemblyName>GreenshotRemotePlugin</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SourceAnalysisOverrideSettingsFile>C:\Dokumente und Einstellungen\05018085\Anwendungsdaten\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<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>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="HttpServer.cs" />
<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>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"</PostBuildEvent>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,189 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/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.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
namespace GreenshotRemotePlugin {
class Server {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Server));
private string url;
private string accessKey;
private volatile bool keepGoing = true;
private HttpListener listener = null;
private ICaptureHost captureHost;
private IGreenshotPluginHost host;
public Server(string url, string accessKey) {
this.url = url;
this.accessKey = accessKey;
}
public void StartListening() {
Thread serverThread = new Thread(Listen);
serverThread.SetApartmentState(ApartmentState.STA);
serverThread.Start();
}
public void StopListening() {
keepGoing = false;
}
public void SetCaptureHost(ICaptureHost captureHost) {
this.captureHost = captureHost;
}
public void SetGreenshotPluginHost(IGreenshotPluginHost host) {
this.host = host;
}
private void Listen() {
listener = new HttpListener();
//listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm;
listener.Prefixes.Add(url);
listener.Start();
LOG.DebugFormat("Listening on: {0}", url);
while (true) {
IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
while(!result.AsyncWaitHandle.WaitOne(1000)) {
if (!keepGoing) {
Close();
return;
}
}
if (!keepGoing) {
Close();
return;
}
}
}
private void Close() {
LOG.Debug("Cleaning up HttpListener");
listener.Stop();
listener.Prefixes.Remove(url);
listener.Close();
listener = null;
}
private void ListenerCallback(IAsyncResult result) {
if (listener == null) {
return;
}
try {
HttpListenerContext context = listener.EndGetContext(result);
new Thread(ProcessRequest).Start(context);
} catch (HttpListenerException httpE) {
LOG.Warn("Got error in ListenerCallback", httpE);
}
}
private void ProcessRequest(object data) {
HttpListenerContext context = data as HttpListenerContext;
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
LOG.DebugFormat("Processing request: {0} {1}", request.HttpMethod, request.Url);
string user = null;
if (context.User != null && context.User.Identity != null) {
user = context.User.Identity.Name;
}
string localPath = request.Url.LocalPath.Substring(1);
LOG.DebugFormat("Path: {0}", localPath);
if (request.QueryString["key"] == null || !request.QueryString["key"].Equals(accessKey)) {
LOG.Debug("Unauthorized");
response.StatusCode = (int)HttpStatusCode.Unauthorized;
byte[] content = Encoding.UTF8.GetBytes("Unauthorized");
response.ContentLength64 = content.Length;
response.OutputStream.Write(content, 0, content.Length);
response.OutputStream.Close();
return;
}
WindowDetails captureWindow = null;
string handle = request.QueryString["handle"];
if (handle != null) {
captureWindow = new WindowDetails(new IntPtr(long.Parse(handle)));
}
if (captureWindow != null) {
try {
bool restored = captureWindow.Iconic;
if (restored) {
captureWindow.Restore();
restored = true;
}
LOG.DebugFormat("Capturing window of class: {0}", captureWindow.ClassName);
using (Bitmap image = captureWindow.PrintWindow()) {
if (image != null) {
using (MemoryStream stream = new MemoryStream()) {
host.SaveToStream(image, stream, OutputFormat.png, 100);
byte [] buffer = stream.GetBuffer();
response.ContentType = "image/png";
response.ContentLength64 = buffer.Length;
response.OutputStream.Write(buffer, 0, buffer.Length);
response.OutputStream.Close();
return;
}
} else {
LOG.Debug("null image??");
}
}
if (restored) {
captureWindow.Iconic = true;
}
} catch (Exception e) {
byte[] errorBuffer = Encoding.UTF8.GetBytes(e.StackTrace);
response.ContentLength64 = errorBuffer.Length;
response.OutputStream.Write(errorBuffer, 0, errorBuffer.Length);
response.OutputStream.Close();
return;
}
}
StringBuilder sb = new StringBuilder();
sb.Append("<html>");
sb.Append("<body>");
sb.Append("<h1>").Append("Active windows").Append("</h1>");
sb.AppendLine("<br/>");
if (user != null) {
sb.Append("Hello " + user + " ");
}
List<WindowDetails>windows = WindowDetails.GetAllWindows();
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("</body>");
sb.Append("</html>");
byte[] b = Encoding.UTF8.GetBytes(sb.ToString());
response.ContentLength64 = b.Length;
response.OutputStream.Write(b, 0, b.Length);
response.OutputStream.Close();
}
}
}

View file

@ -0,0 +1,53 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/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/>.
*/
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using Greenshot.Plugin;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("GreenshotRemotePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GreenshotRemotePlugin")]
[assembly: AssemblyCopyright("Copyright (C) 2007-2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: PluginAttribute("GreenshotRemotePlugin.RemotePlugin", false)]
// 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)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.$WCREV$")]

View file

@ -0,0 +1,38 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/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 GreenshotPlugin.Core;
namespace GreenshotRemotePlugin {
/// <summary>
/// Description of CoreConfiguration.
/// </summary>
[IniSection("Remote", Description="Greenshot Remote Plugin configuration")]
public class RemoteConfiguration : IniSection {
[IniProperty("RemoteEnabled", Description="Is remote access enabled", DefaultValue="False")]
public bool RemoteEnabled;
[IniProperty("ListenerURL", Description="The URL to listen on", DefaultValue="http://localhost:11234/")]
public string ListenerURL;
[IniProperty("AccessKey", Description="The key allowing access", DefaultValue="GreenShot")]
public string AccessKey;
}
}

View file

@ -0,0 +1,101 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2011 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/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.IO;
using System.Threading;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
namespace GreenshotRemotePlugin {
/// <summary>
/// Remote Plugin Greenshot
/// </summary>
public class RemotePlugin : IGreenshotPlugin {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(RemotePlugin));
private IGreenshotPluginHost host;
private ICaptureHost captureHost = null;
private PluginAttribute myAttributes;
private Server httpServer = null;
private RemoteConfiguration config;
public RemotePlugin() { }
/// <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) {
LOG.Debug("Initialize called of " + myAttributes.Name);
this.host = (IGreenshotPluginHost)host;
this.captureHost = captureHost;
this.myAttributes = myAttributes;
// Load configuration
config = IniConfig.GetIniSection<RemoteConfiguration>();
// check validity
if (!config.ListenerURL.EndsWith("/")) {
config.ListenerURL = config.ListenerURL + "/";
config.IsDirty = true;
IniConfig.Save();
}
IniConfig.IniChanged += new FileSystemEventHandler(ReloadConfiguration);
ReloadConfiguration(null, null);
}
private void ReloadConfiguration(object source, FileSystemEventArgs e) {
if (httpServer != null) {
httpServer.StopListening();
httpServer = null;
}
if (config.RemoteEnabled) {
httpServer = new Server(config.ListenerURL, config.AccessKey);
httpServer.SetCaptureHost(captureHost);
httpServer.SetGreenshotPluginHost(host);
httpServer.StartListening();
}
}
/// <summary>
/// Implementation of the IGreenshotPlugin.Shutdown
/// </summary>
public void Shutdown() {
LOG.Debug("Shutdown of " + myAttributes.Name);
if (httpServer != null) {
httpServer.StopListening();
httpServer = null;
}
IniConfig.IniChanged -= new FileSystemEventHandler(ReloadConfiguration);
}
/// <summary>
/// Implementation of the IPlugin.Configure
/// </summary>
public virtual void Configure() {
return;
}
}
}

File diff suppressed because it is too large Load diff