Unverified Commit fa9e3afb authored by Robin Krom's avatar Robin Krom Committed by GitHub
Browse files

Merge pull request #64 from wookiefriseur/feature/cmdLineCapture

Feature: start capture from command line
parents a6a5277a dd6aa1a1
......@@ -131,6 +131,10 @@ namespace Greenshot {
helpOutput.AppendLine();
helpOutput.AppendLine("\t[filename]");
helpOutput.AppendLine("\t\tOpen the bitmap files in the running Greenshot instance or start a new instance");
helpOutput.AppendLine();
helpOutput.AppendLine();
helpOutput.AppendLine("\t/capture <region|window|fullscreen>[,Destination]");
helpOutput.AppendLine("\t\tStart capture from command line. Use /capture without arguments for more info. Greenshot must be running");
Console.WriteLine(helpOutput.ToString());
// If attach didn't work, wait for key otherwise the console will close to quickly
......@@ -183,6 +187,70 @@ namespace Greenshot {
IniConfig.IniDirectory = arguments[++argumentNr];
continue;
}
// Capture from command line, only accept as first argument
if (arguments.Length > 0 && arguments[0].ToLower().Equals("/capture")) {
// Try to attach to the console
bool attachedToConsole = Kernel32.AttachConsole(Kernel32.ATTACHCONSOLE_ATTACHPARENTPROCESS);
// If attach didn't work, open a console
if (!attachedToConsole) {
Kernel32.AllocConsole();
}
// Display help for /capture command if not enough arguments
if (arguments.Length < 2) {
PluginHelper.Instance.LoadPlugins(); // list plugins when using GetAllDestinations
var helpOutput = new StringBuilder();
helpOutput.AppendLine();
helpOutput.AppendLine();
helpOutput.AppendLine("Usage for /capture:");
helpOutput.AppendLine("\t/capture <region|window|fullscreen>[,Destination]");
helpOutput.AppendLine();
helpOutput.AppendLine("\tDestinations: (CaseSensitive!)");
helpOutput.AppendFormat(
"\t\t{0,-16}\t==>\t{1}{2}",
"\"External CmdName\"",
"External Command like MS Paint",
Environment.NewLine
);
foreach (var destination in DestinationHelper.GetAllDestinations()) {
helpOutput.AppendFormat(
"\t\t{0,-16}\t==>\t{1}{2}",
destination.Designation,
destination.Description,
Environment.NewLine
);
}
helpOutput.AppendLine();
helpOutput.AppendLine();
helpOutput.AppendLine("\tUsage examples:");
helpOutput.AppendLine("\t\t/capture window,FileNoDialog\t\t(capture window, save in default screenshot folder)");
helpOutput.AppendLine("\t\t/capture fullscreen\t\t\t(capture fullscreen, use destination from settings)");
helpOutput.AppendLine("\t\t/capture region,Clipboard\t\t(capture region directly to clipboard)");
helpOutput.AppendLine("\t\t/capture fullscreen,Picker\t\t(capture fullscreen, ask what to do)");
helpOutput.AppendLine("\t\t/capture region,\"External MS Paint\"\t(capture region and send to external command 'MS Paint')");
helpOutput.AppendLine();
helpOutput.AppendLine("\tShortcut path examples for Windows:");
helpOutput.AppendLine("\t\t\"C:\\Program Files\\Greenshot\\Greenshot.exe\" /capture region,\"External MS Paint\"");
helpOutput.AppendLine("\t\tD:\\Programme\\Greenshot\\Greenshot.exe /capture fullscreen,FileNoDialog");
helpOutput.AppendLine();
Console.WriteLine(helpOutput.ToString());
// If attach didn't work, wait for key otherwise the console will close to quickly
if (!attachedToConsole) {
Console.ReadKey();
}
} else if(!isAlreadyRunning) {
Console.WriteLine("{0}{0}Please start Greenshot first", Environment.NewLine);
// If attach didn't work, wait for key otherwise the console will close to quickly
if (!attachedToConsole) {
Console.ReadKey();
}
} else {
SendData(new CopyDataTransport(CommandEnum.Capture, arguments[1]));
}
FreeMutex();
return;
}
// Files to open
filesToOpen.Add(argument);
......@@ -465,6 +533,38 @@ namespace Greenshot {
LOG.Warn("No such file: " + filename);
}
break;
// Capture from command line
case CommandEnum.Capture:
string parameters = command.Value;
LOG.InfoFormat("Capture requested: {0}", parameters);
string[] optionsArray = parameters.Split(',');
string captureMode = optionsArray[0];
// Fallback-Destination
IDestination destination = DestinationHelper.GetDestination(_conf.OutputDestinations.FirstOrDefault());
if (optionsArray.Length > 1
&& DestinationHelper.GetDestination(optionsArray[1]) != null
&& DestinationHelper.GetDestination(optionsArray[1]).IsActive) {
destination = DestinationHelper.GetDestination(optionsArray[1]);
}
switch (captureMode.ToLower()) {
case "region":
CaptureHelper.CaptureRegion(destination);
break;
case "window":
CaptureHelper.CaptureWindow(destination);
break;
case "fullscreen":
CaptureHelper.CaptureFullscreen(destination);
break;
default:
LOG.Warn("Unknown capture option");
break;
}
break;
default:
LOG.Error("Unknown command!");
break;
......@@ -1465,4 +1565,4 @@ namespace Greenshot {
}
}
}
}
\ No newline at end of file
}
......@@ -87,6 +87,12 @@ namespace Greenshot.Helpers {
captureHelper.MakeCapture();
}
}
public static void CaptureClipboard(IDestination destination){
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard)) {
captureHelper.AddDestination(destination);
captureHelper.MakeCapture();
}
}
public static void CaptureRegion(bool captureMouse) {
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region, captureMouse)) {
captureHelper.MakeCapture();
......@@ -102,12 +108,24 @@ namespace Greenshot.Helpers {
captureHelper.MakeCapture(region);
}
}
public static void CaptureRegion(IDestination destination) {
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region)) {
captureHelper.AddDestination(destination);
captureHelper.MakeCapture();
}
}
public static void CaptureFullscreen(bool captureMouse, ScreenCaptureMode screenCaptureMode) {
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen, captureMouse)) {
captureHelper._screenCaptureMode = screenCaptureMode;
captureHelper.MakeCapture();
}
}
public static void CaptureFullscreen(IDestination destination) {
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen)) {
captureHelper.AddDestination(destination);
captureHelper.MakeCapture();
}
}
public static void CaptureLastRegion(bool captureMouse) {
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.LastRegion, captureMouse)) {
captureHelper.MakeCapture();
......@@ -133,7 +151,12 @@ namespace Greenshot.Helpers {
captureHelper.MakeCapture();
}
}
public static void CaptureWindow(IDestination destination) {
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Window)) {
captureHelper.AddDestination(destination);
captureHelper.MakeCapture();
}
}
public static void CaptureWindowInteractive(bool captureMouse) {
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Window)) {
captureHelper.MakeCapture();
......
......@@ -30,7 +30,7 @@ using System.Windows.Forms;
using GreenshotPlugin.Core;
namespace Greenshot.Helpers {
public enum CommandEnum { OpenFile, Exit, FirstLaunch, ReloadConfig };
public enum CommandEnum { OpenFile, Exit, FirstLaunch, ReloadConfig, Capture };
/// <summary>
/// Code from vbAccelerator, location:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment