mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Refactoring some more classes, making easier code in plug-ins possible. Needed this for better testing some problems with the CreateShadow function.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2094 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
017b874de3
commit
9488200886
20 changed files with 128 additions and 190 deletions
|
@ -162,7 +162,6 @@
|
|||
<Compile Include="Forms\PrintOptionsDialog.Designer.cs">
|
||||
<DependentUpon>PrintOptionsDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\SaveImageFileDialog.cs" />
|
||||
<Compile Include="Forms\SettingsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -187,7 +186,6 @@
|
|||
<None Include="App.config" />
|
||||
<None Include="Helpers\AviHelper.cs" />
|
||||
<Compile Include="Helpers\CaptureHelper.cs" />
|
||||
<Compile Include="Helpers\ClipboardHelper.cs" />
|
||||
<Compile Include="Helpers\Colors.cs" />
|
||||
<Compile Include="Helpers\CopyData.cs" />
|
||||
<Compile Include="Helpers\GeometryHelper.cs" />
|
||||
|
@ -216,7 +214,6 @@
|
|||
<Compile Include="Helpers\MailHelper.cs" />
|
||||
<Compile Include="Helpers\PluginHelper.cs" />
|
||||
<Compile Include="Helpers\PrintHelper.cs" />
|
||||
<Compile Include="Helpers\ImageOutput.cs" />
|
||||
<Compile Include="Helpers\ScaleHelper.cs" />
|
||||
<Compile Include="Helpers\SoundHelper.cs" />
|
||||
<Compile Include="Helpers\StartupHelper.cs" />
|
||||
|
@ -370,13 +367,6 @@
|
|||
<None Include="log4net.xml">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Compile Include="Helpers\FilenameHelper.cs" />
|
||||
<Compile Include="Forms\QualityDialog.Designer.cs">
|
||||
<DependentUpon>QualityDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\QualityDialog.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\ColorDialog.Designer.cs">
|
||||
<DependentUpon>ColorDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
|
|
|
@ -301,7 +301,10 @@ namespace Greenshot.Helpers {
|
|||
if (!string.IsNullOrEmpty(filename)) {
|
||||
try {
|
||||
if (filename.EndsWith(".gsf")) {
|
||||
ISurface surface = ImageOutput.LoadGreenshotSurface(filename);
|
||||
|
||||
ISurface surface = new Surface();
|
||||
|
||||
surface = ImageOutput.LoadGreenshotSurface(filename, surface);
|
||||
DestinationHelper.GetDestination(EditorDestination.DESIGNATION).ExportCapture(true, surface, capture.CaptureDetails);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -95,26 +95,6 @@ namespace Greenshot.Helpers {
|
|||
#region Implementation of IGreenshotPluginHost
|
||||
private ContextMenuStrip mainMenu = null;
|
||||
|
||||
public void SaveToStream(Image img, Stream stream, OutputSettings outputSettings) {
|
||||
ImageOutput.SaveToStream(img, stream, outputSettings);
|
||||
}
|
||||
|
||||
public string SaveToTmpFile(Image img, OutputSettings outputSettings, string destinationPath) {
|
||||
return ImageOutput.SaveToTmpFile(img, outputSettings, destinationPath);
|
||||
}
|
||||
|
||||
public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings) {
|
||||
return ImageOutput.SaveNamedTmpFile(image, captureDetails, outputSettings);
|
||||
}
|
||||
|
||||
public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) {
|
||||
string pattern = conf.OutputFileFilenamePattern;
|
||||
if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) {
|
||||
pattern = "greenshot ${capturetime}";
|
||||
}
|
||||
return FilenameHelper.GetFilenameFromPattern(pattern, format, captureDetails);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a Thumbnail
|
||||
/// </summary>
|
||||
|
|
|
@ -123,7 +123,7 @@ namespace GreenshotConfluencePlugin {
|
|||
|
||||
Page selectedPage = page;
|
||||
bool openPage = (page == null) && config.OpenPageAfterUpload;
|
||||
string filename = ConfluencePlugin.Host.GetFilename(config.UploadFormat, captureDetails);
|
||||
string filename = FilenameHelper.GetFilename(config.UploadFormat, captureDetails);
|
||||
if (selectedPage == null) {
|
||||
ConfluenceUpload confluenceUpload = new ConfluenceUpload(filename);
|
||||
Nullable<bool> dialogResult = confluenceUpload.ShowDialog();
|
||||
|
@ -160,7 +160,7 @@ namespace GreenshotConfluencePlugin {
|
|||
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||
byte[] buffer;
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ConfluencePlugin.Host.SaveToStream(image, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(image, stream, outputSettings);
|
||||
// COPY buffer to array
|
||||
buffer = stream.ToArray();
|
||||
}
|
||||
|
|
|
@ -75,12 +75,6 @@ namespace GreenshotConfluencePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public static IGreenshotHost Host {
|
||||
get {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
public ConfluencePlugin() {
|
||||
}
|
||||
|
||||
|
|
|
@ -36,11 +36,9 @@ namespace ExternalCommand {
|
|||
public class ExternalCommandDestination : AbstractDestination {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ExternalCommandDestination));
|
||||
private static ExternalCommandConfiguration config = IniConfig.GetIniSection<ExternalCommandConfiguration>();
|
||||
private IGreenshotHost host;
|
||||
private string presetCommand;
|
||||
|
||||
public ExternalCommandDestination(IGreenshotHost host, string commando) {
|
||||
this.host = host;
|
||||
public ExternalCommandDestination(string commando) {
|
||||
this.presetCommand = commando;
|
||||
}
|
||||
|
||||
|
@ -79,7 +77,7 @@ namespace ExternalCommand {
|
|||
string fullPath = captureDetails.Filename;
|
||||
if (fullPath == null) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
fullPath = host.SaveNamedTmpFile(image, captureDetails, outputSettings);
|
||||
fullPath = ImageOutput.SaveNamedTmpFile(image, captureDetails, outputSettings);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace ExternalCommand {
|
|||
|
||||
public IEnumerable<IDestination> Destinations() {
|
||||
foreach(string command in config.commands) {
|
||||
yield return new ExternalCommandDestination(host, command);
|
||||
yield return new ExternalCommandDestination(command);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,9 +139,9 @@ namespace GreenshotImgurPlugin {
|
|||
public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
|
||||
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
host.SaveToStream(image, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(image, stream, outputSettings);
|
||||
try {
|
||||
string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
|
||||
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
|
||||
ImgurInfo imgurInfo = null;
|
||||
|
||||
// Run upload in the background
|
||||
|
|
|
@ -103,13 +103,13 @@ namespace GreenshotJiraPlugin {
|
|||
|
||||
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
|
||||
string filename = Path.GetFileName(jiraPlugin.Host.GetFilename(config.UploadFormat, captureDetails));
|
||||
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
|
||||
byte[] buffer;
|
||||
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||
if (jira != null) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
jiraPlugin.Host.SaveToStream(image, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(image, stream, outputSettings);
|
||||
}
|
||||
// COPY stream to buffer
|
||||
buffer = stream.ToArray();
|
||||
|
@ -136,7 +136,7 @@ namespace GreenshotJiraPlugin {
|
|||
if (result == DialogResult.OK) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
using (Image image = surface.GetImageForExport()) {
|
||||
jiraPlugin.Host.SaveToStream(image, stream, outputSettings);
|
||||
ImageOutput.SaveToStream(image, stream, outputSettings);
|
||||
}
|
||||
// COPY stream to buffer
|
||||
buffer = stream.ToArray();
|
||||
|
|
|
@ -60,12 +60,6 @@ namespace GreenshotJiraPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public IGreenshotHost Host {
|
||||
get {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IDestination> Destinations() {
|
||||
yield return new JiraDestination(this);
|
||||
}
|
||||
|
|
|
@ -153,10 +153,10 @@ namespace GreenshotOCR {
|
|||
graphics.Clear(Color.White);
|
||||
graphics.DrawImage(capturedImage, Point.Empty);
|
||||
}
|
||||
filePath = host.SaveToTmpFile(tmpImage, outputSettings, null);
|
||||
filePath = ImageOutput.SaveToTmpFile(tmpImage, outputSettings, null);
|
||||
}
|
||||
} else {
|
||||
filePath = host.SaveToTmpFile(capturedImage, outputSettings, null);
|
||||
filePath = ImageOutput.SaveToTmpFile(capturedImage, outputSettings, null);
|
||||
}
|
||||
|
||||
LOG.Debug("Saved tmp file to: " + filePath);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* 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 Greenshot {
|
||||
partial class QualityDialog : System.Windows.Forms.Form {
|
||||
namespace GreenshotPlugin.Controls {
|
||||
partial class QualityDialog {
|
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
|
@ -46,11 +46,11 @@ namespace Greenshot {
|
|||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.label_choosejpegquality = new System.Windows.Forms.Label();
|
||||
this.label_choosejpegquality = new GreenshotPlugin.Controls.GreenshotLabel();
|
||||
this.textBoxJpegQuality = new System.Windows.Forms.TextBox();
|
||||
this.trackBarJpegQuality = new System.Windows.Forms.TrackBar();
|
||||
this.checkbox_dontaskagain = new System.Windows.Forms.CheckBox();
|
||||
this.button_ok = new System.Windows.Forms.Button();
|
||||
this.checkbox_dontaskagain = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||
this.button_ok = new GreenshotPlugin.Controls.GreenshotButton();
|
||||
this.checkBox_reduceColors = new System.Windows.Forms.CheckBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
|
@ -61,7 +61,7 @@ namespace Greenshot {
|
|||
this.label_choosejpegquality.Name = "label_choosejpegquality";
|
||||
this.label_choosejpegquality.Size = new System.Drawing.Size(268, 19);
|
||||
this.label_choosejpegquality.TabIndex = 15;
|
||||
this.label_choosejpegquality.Text = "Choose JPEG Quality";
|
||||
this.label_choosejpegquality.LanguageKey = "jpegqualitydialog_choosejpegquality";
|
||||
//
|
||||
// textBoxJpegQuality
|
||||
//
|
||||
|
@ -89,9 +89,9 @@ namespace Greenshot {
|
|||
this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
|
||||
this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 106);
|
||||
this.checkbox_dontaskagain.Name = "checkbox_dontaskagain";
|
||||
this.checkbox_dontaskagain.LanguageKey = "qualitydialog_dontaskagain";
|
||||
this.checkbox_dontaskagain.Size = new System.Drawing.Size(268, 37);
|
||||
this.checkbox_dontaskagain.TabIndex = 17;
|
||||
this.checkbox_dontaskagain.Text = "Save as default quality and do not ask again.";
|
||||
this.checkbox_dontaskagain.TextAlign = System.Drawing.ContentAlignment.TopLeft;
|
||||
this.checkbox_dontaskagain.UseVisualStyleBackColor = true;
|
||||
//
|
||||
|
@ -102,7 +102,7 @@ namespace Greenshot {
|
|||
this.button_ok.Name = "button_ok";
|
||||
this.button_ok.Size = new System.Drawing.Size(75, 23);
|
||||
this.button_ok.TabIndex = 18;
|
||||
this.button_ok.Text = "OK";
|
||||
this.button_ok.LanguageKey = "OK";
|
||||
this.button_ok.UseVisualStyleBackColor = true;
|
||||
this.button_ok.Click += new System.EventHandler(this.Button_okClick);
|
||||
//
|
||||
|
@ -113,7 +113,7 @@ namespace Greenshot {
|
|||
this.checkBox_reduceColors.Name = "checkBox_reduceColors";
|
||||
this.checkBox_reduceColors.Size = new System.Drawing.Size(95, 17);
|
||||
this.checkBox_reduceColors.TabIndex = 19;
|
||||
this.checkBox_reduceColors.Text = "Reduce colors";
|
||||
this.checkBox_reduceColors.Text = "settings_reducecolors";
|
||||
this.checkBox_reduceColors.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// QualityDialog
|
||||
|
@ -132,17 +132,17 @@ namespace Greenshot {
|
|||
this.MinimizeBox = false;
|
||||
this.Name = "QualityDialog";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.Text = "QualityDialog";
|
||||
this.LanguageKey = "qualitydialog_title";
|
||||
((System.ComponentModel.ISupportInitialize)(this.trackBarJpegQuality)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
private System.Windows.Forms.Button button_ok;
|
||||
private System.Windows.Forms.CheckBox checkbox_dontaskagain;
|
||||
private GreenshotPlugin.Controls.GreenshotButton button_ok;
|
||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_dontaskagain;
|
||||
private System.Windows.Forms.TrackBar trackBarJpegQuality;
|
||||
private System.Windows.Forms.TextBox textBoxJpegQuality;
|
||||
private System.Windows.Forms.Label label_choosejpegquality;
|
||||
private GreenshotPlugin.Controls.GreenshotLabel label_choosejpegquality;
|
||||
private System.Windows.Forms.CheckBox checkBox_reduceColors;
|
||||
}
|
||||
}
|
|
@ -20,21 +20,21 @@
|
|||
*/
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Configuration;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
namespace Greenshot {
|
||||
namespace GreenshotPlugin.Controls {
|
||||
/// <summary>
|
||||
/// Description of JpegQualityDialog.
|
||||
/// </summary>
|
||||
public partial class QualityDialog : Form {
|
||||
public partial class QualityDialog : GreenshotForm {
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
public OutputSettings Settings {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public QualityDialog(OutputSettings outputSettings) {
|
||||
Settings = outputSettings;
|
||||
//
|
||||
|
@ -48,7 +48,6 @@ namespace Greenshot {
|
|||
this.trackBarJpegQuality.Value = Settings.JPGQuality;
|
||||
this.textBoxJpegQuality.Enabled = OutputFormat.jpg.Equals(outputSettings.Format);
|
||||
this.textBoxJpegQuality.Text = Settings.JPGQuality.ToString();
|
||||
UpdateUI();
|
||||
WindowDetails.ToForeground(Handle);
|
||||
}
|
||||
|
||||
|
@ -63,13 +62,6 @@ namespace Greenshot {
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateUI() {
|
||||
this.Text = Language.GetString(LangKey.qualitydialog_title);
|
||||
this.label_choosejpegquality.Text = Language.GetString(LangKey.jpegqualitydialog_choosejpegquality);
|
||||
this.checkbox_dontaskagain.Text = Language.GetString(LangKey.qualitydialog_dontaskagain);
|
||||
this.checkBox_reduceColors.Text = Language.GetString(LangKey.settings_reducecolors);
|
||||
}
|
||||
|
||||
void TrackBarJpegQualityScroll(object sender, System.EventArgs e) {
|
||||
textBoxJpegQuality.Text = trackBarJpegQuality.Value.ToString();
|
||||
}
|
|
@ -22,12 +22,11 @@ using System;
|
|||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
|
||||
namespace Greenshot.Forms {
|
||||
namespace GreenshotPlugin.Controls {
|
||||
/// <summary>
|
||||
/// Custom dialog for saving images, wraps SaveFileDialog.
|
||||
/// For some reason SFD is sealed :(
|
|
@ -28,13 +28,12 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
namespace Greenshot.Helpers {
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
/// Description of ClipboardHelper.
|
||||
/// </summary>
|
||||
|
@ -141,9 +140,9 @@ EndSelection:<<<<<<<4
|
|||
string messageText = null;
|
||||
string clipboardOwner = GetClipboardOwner();
|
||||
if (clipboardOwner != null) {
|
||||
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner);
|
||||
messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
|
||||
} else {
|
||||
messageText = Language.GetString(LangKey.clipboard_error);
|
||||
messageText = Language.GetString("clipboard_error");
|
||||
}
|
||||
LOG.Error(messageText, ee);
|
||||
} else {
|
||||
|
@ -172,9 +171,9 @@ EndSelection:<<<<<<<4
|
|||
string messageText = null;
|
||||
string clipboardOwner = GetClipboardOwner();
|
||||
if (clipboardOwner != null) {
|
||||
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner);
|
||||
messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
|
||||
} else {
|
||||
messageText = Language.GetString(LangKey.clipboard_error);
|
||||
messageText = Language.GetString("clipboard_error");
|
||||
}
|
||||
LOG.Error(messageText, ee);
|
||||
} else {
|
||||
|
@ -204,9 +203,9 @@ EndSelection:<<<<<<<4
|
|||
string messageText = null;
|
||||
string clipboardOwner = GetClipboardOwner();
|
||||
if (clipboardOwner != null) {
|
||||
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner);
|
||||
messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
|
||||
} else {
|
||||
messageText = Language.GetString(LangKey.clipboard_error);
|
||||
messageText = Language.GetString("clipboard_error");
|
||||
}
|
||||
LOG.Error(messageText, ee);
|
||||
} else {
|
||||
|
@ -247,9 +246,9 @@ EndSelection:<<<<<<<4
|
|||
string messageText = null;
|
||||
string clipboardOwner = GetClipboardOwner();
|
||||
if (clipboardOwner != null) {
|
||||
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner);
|
||||
messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
|
||||
} else {
|
||||
messageText = Language.GetString(LangKey.clipboard_error);
|
||||
messageText = Language.GetString("clipboard_error");
|
||||
}
|
||||
LOG.Error(messageText, ee);
|
||||
} else {
|
||||
|
@ -279,9 +278,9 @@ EndSelection:<<<<<<<4
|
|||
string messageText = null;
|
||||
string clipboardOwner = GetClipboardOwner();
|
||||
if (clipboardOwner != null) {
|
||||
messageText = Language.GetFormattedString(LangKey.clipboard_inuse, clipboardOwner);
|
||||
messageText = Language.GetFormattedString("clipboard_inuse", clipboardOwner);
|
||||
} else {
|
||||
messageText = Language.GetString(LangKey.clipboard_error);
|
||||
messageText = Language.GetString("clipboard_error");
|
||||
}
|
||||
LOG.Error(messageText, ee);
|
||||
} else {
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
|
@ -28,7 +28,7 @@ using Greenshot.Plugin;
|
|||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
|
||||
namespace Greenshot.Helpers {
|
||||
namespace GreenshotPlugin.Core {
|
||||
public static class FilenameHelper {
|
||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FilenameHelper));
|
||||
private static readonly Regex VAR_REGEXP = new Regex(@"\${(?<variable>[^:}]+)[:]?(?<parameters>[^}]*)}", RegexOptions.Compiled);
|
||||
|
@ -58,7 +58,7 @@ namespace Greenshot.Helpers {
|
|||
// Make the filename save!
|
||||
if (filename != null) {
|
||||
foreach (char disallowed in Path.GetInvalidFileNameChars()) {
|
||||
filename = filename.Replace( disallowed.ToString(), UNSAFE_REPLACEMENT );
|
||||
filename = filename.Replace(disallowed.ToString(), UNSAFE_REPLACEMENT);
|
||||
}
|
||||
}
|
||||
return filename;
|
||||
|
@ -73,7 +73,7 @@ namespace Greenshot.Helpers {
|
|||
// Make the path save!
|
||||
if (path != null) {
|
||||
foreach (char disallowed in Path.GetInvalidPathChars()) {
|
||||
path = path.Replace( disallowed.ToString(), UNSAFE_REPLACEMENT );
|
||||
path = path.Replace(disallowed.ToString(), UNSAFE_REPLACEMENT);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
|
@ -95,6 +95,21 @@ namespace Greenshot.Helpers {
|
|||
return FillPattern(pattern, captureDetails, true) + "." + imageFormat.ToString().ToLower();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
|
||||
/// that is specified in the configuration
|
||||
/// </summary>
|
||||
/// <param name="format">A string with the format</param>
|
||||
/// <returns>The filename which should be used to save the image</returns>
|
||||
public static string GetFilename(OutputFormat format, ICaptureDetails captureDetails) {
|
||||
string pattern = conf.OutputFileFilenamePattern;
|
||||
if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) {
|
||||
pattern = "greenshot ${capturetime}";
|
||||
}
|
||||
return FilenameHelper.GetFilenameFromPattern(pattern, format, captureDetails);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This method will be called by the regexp.replace as a MatchEvaluator delegate!
|
||||
/// Will delegate this to the MatchVarEvaluatorInternal and catch any exceptions
|
||||
|
@ -132,14 +147,15 @@ namespace Greenshot.Helpers {
|
|||
string parameters = match.Groups["parameters"].Value;
|
||||
|
||||
if (parameters != null && parameters.Length > 0) {
|
||||
string []parms = SPLIT_REGEXP.Split(parameters);
|
||||
foreach(string parameter in parms) {
|
||||
switch (parameter.Substring(0,1)) {
|
||||
string[] parms = SPLIT_REGEXP.Split(parameters);
|
||||
foreach (string parameter in parms) {
|
||||
switch (parameter.Substring(0, 1)) {
|
||||
case "p":
|
||||
string []padParams = parameter.Substring(1).Split(new char[] {','});
|
||||
string[] padParams = parameter.Substring(1).Split(new char[] { ',' });
|
||||
try {
|
||||
padWidth = int.Parse(padParams[0]);
|
||||
} catch {};
|
||||
} catch {
|
||||
};
|
||||
if (padParams.Length > 1) {
|
||||
padChar = padParams[1][0];
|
||||
}
|
||||
|
@ -150,12 +166,12 @@ namespace Greenshot.Helpers {
|
|||
dateFormat = dateFormat.Substring(1);
|
||||
}
|
||||
if (dateFormat.EndsWith("\"")) {
|
||||
dateFormat = dateFormat.Substring(0, dateFormat.Length-1);
|
||||
dateFormat = dateFormat.Substring(0, dateFormat.Length - 1);
|
||||
}
|
||||
break;
|
||||
case "s":
|
||||
string range=parameter.Substring(1);
|
||||
string []rangelist = range.Split(new char[] {','});
|
||||
string range = parameter.Substring(1);
|
||||
string[] rangelist = range.Split(new char[] { ',' });
|
||||
if (rangelist.Length > 0) {
|
||||
try {
|
||||
startIndex = int.Parse(rangelist[0]);
|
||||
|
@ -196,7 +212,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
} else {
|
||||
// Handle other variables
|
||||
// Default use "now" for the capture take´n
|
||||
// Default use "now" for the capture take´n
|
||||
DateTime capturetime = DateTime.Now;
|
||||
// Use default application name for title
|
||||
string title = Application.ProductName;
|
||||
|
@ -211,7 +227,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
}
|
||||
}
|
||||
switch(variable) {
|
||||
switch (variable) {
|
||||
case "domain":
|
||||
replaceValue = Environment.UserDomainName;
|
||||
break;
|
||||
|
@ -277,7 +293,7 @@ namespace Greenshot.Helpers {
|
|||
break;
|
||||
case "NUM":
|
||||
conf.OutputFileIncrementingNumber++;
|
||||
IniConfig.Save();
|
||||
IniConfig.Save();
|
||||
replaceValue = conf.OutputFileIncrementingNumber.ToString();
|
||||
if (padWidth == 0) {
|
||||
padWidth = -6;
|
||||
|
@ -294,7 +310,7 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
}
|
||||
// do padding
|
||||
if (padWidth >0) {
|
||||
if (padWidth > 0) {
|
||||
replaceValue = replaceValue.PadRight(padWidth, padChar);
|
||||
} else if (padWidth < 0) {
|
||||
replaceValue = replaceValue.PadLeft(-padWidth, padChar);
|
||||
|
@ -355,8 +371,10 @@ namespace Greenshot.Helpers {
|
|||
}
|
||||
|
||||
return VAR_REGEXP.Replace(pattern,
|
||||
new MatchEvaluator(delegate(Match m) { return MatchVarEvaluator(m, null, processVars, userVars, machineVars, filenameSafeMode); })
|
||||
);
|
||||
new MatchEvaluator(delegate(Match m) {
|
||||
return MatchVarEvaluator(m, null, processVars, userVars, machineVars, filenameSafeMode);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -390,8 +408,10 @@ namespace Greenshot.Helpers {
|
|||
|
||||
try {
|
||||
return VAR_REGEXP.Replace(pattern,
|
||||
new MatchEvaluator(delegate(Match m) { return MatchVarEvaluator(m, captureDetails, processVars, userVars, machineVars, filenameSafeMode); })
|
||||
);
|
||||
new MatchEvaluator(delegate(Match m) {
|
||||
return MatchVarEvaluator(m, captureDetails, processVars, userVars, machineVars, filenameSafeMode);
|
||||
})
|
||||
);
|
||||
} catch (Exception e) {
|
||||
// adding additional data for bug tracking
|
||||
e.Data.Add("title", captureDetails.Title);
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
|
@ -26,14 +26,12 @@ using System.Reflection;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Drawing;
|
||||
using GreenshotPlugin.Controls;
|
||||
|
||||
namespace Greenshot.Helpers {
|
||||
namespace GreenshotPlugin.Core {
|
||||
/// <summary>
|
||||
/// Description of ImageOutput.
|
||||
/// </summary>
|
||||
|
@ -41,7 +39,7 @@ namespace Greenshot.Helpers {
|
|||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageOutput));
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
private static readonly int PROPERTY_TAG_SOFTWARE_USED = 0x0131;
|
||||
private static Cache<string, string> tmpFileCache = new Cache<string, string>(10*60*60, new Cache<string, string>.CacheObjectExpired(RemoveExpiredTmpFile));
|
||||
private static Cache<string, string> tmpFileCache = new Cache<string, string>(10 * 60 * 60, new Cache<string, string>.CacheObjectExpired(RemoveExpiredTmpFile));
|
||||
|
||||
/// <summary>
|
||||
/// Creates a PropertyItem (Metadata) to store with the image.
|
||||
|
@ -54,16 +52,16 @@ namespace Greenshot.Helpers {
|
|||
private static PropertyItem CreatePropertyItem(int id, string text) {
|
||||
PropertyItem propertyItem = null;
|
||||
try {
|
||||
ConstructorInfo ci = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public , null, new Type[] { }, null);
|
||||
ConstructorInfo ci = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, new Type[] { }, null);
|
||||
propertyItem = (PropertyItem)ci.Invoke(null);
|
||||
// Make sure it's of type string
|
||||
propertyItem.Type =2;
|
||||
propertyItem.Type = 2;
|
||||
// Set the ID
|
||||
propertyItem.Id = id;
|
||||
// Set the text
|
||||
byte [] byteString = System.Text.ASCIIEncoding.ASCII.GetBytes(text + " ");
|
||||
byte[] byteString = System.Text.ASCIIEncoding.ASCII.GetBytes(text + " ");
|
||||
// Set Zero byte for String end.
|
||||
byteString[byteString.Length-1] = 0;
|
||||
byteString[byteString.Length - 1] = 0;
|
||||
propertyItem.Value = byteString;
|
||||
propertyItem.Len = text.Length + 1;
|
||||
} catch (Exception e) {
|
||||
|
@ -167,7 +165,7 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
/// <param name="surface">Surface to save</param>
|
||||
/// <param name="fullPath">Path to file</param>
|
||||
public static void SaveGreenshotSurface(Surface surface, string fullPath) {
|
||||
public static void SaveGreenshotSurface(ISurface surface, string fullPath) {
|
||||
fullPath = FilenameHelper.MakeFQFilenameSafe(fullPath);
|
||||
string path = Path.GetDirectoryName(fullPath);
|
||||
// Get output settings from the configuration
|
||||
|
@ -192,8 +190,7 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <returns></returns>
|
||||
public static Surface LoadGreenshotSurface(string fullPath) {
|
||||
Surface returnSurface = null;
|
||||
public static ISurface LoadGreenshotSurface(string fullPath, ISurface returnSurface) {
|
||||
if (string.IsNullOrEmpty(fullPath)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -210,12 +207,11 @@ namespace Greenshot.Helpers {
|
|||
LOG.DebugFormat("Loaded {0} with Size {1}x{2} and PixelFormat {3}", fullPath, tmpImage.Width, tmpImage.Height, tmpImage.PixelFormat);
|
||||
fileBitmap = ImageHelper.Clone(tmpImage);
|
||||
}
|
||||
returnSurface = new Surface(fileBitmap);
|
||||
imageFileStream.Seek(-8, SeekOrigin.End);
|
||||
long bytesWritten = 0;
|
||||
using (BinaryReader reader = new BinaryReader(imageFileStream)) {
|
||||
bytesWritten = reader.ReadInt64();
|
||||
imageFileStream.Seek(-(bytesWritten+8), SeekOrigin.End);
|
||||
imageFileStream.Seek(-(bytesWritten + 8), SeekOrigin.End);
|
||||
returnSurface.LoadElementsFromStream(imageFileStream);
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +242,7 @@ namespace Greenshot.Helpers {
|
|||
if (extension != null) {
|
||||
format = (OutputFormat)Enum.Parse(typeof(OutputFormat), extension.ToLower());
|
||||
}
|
||||
} catch(ArgumentException ae) {
|
||||
} catch (ArgumentException ae) {
|
||||
LOG.Warn("Couldn't parse extension: " + extension, ae);
|
||||
}
|
||||
if (!allowOverwrite && File.Exists(fullPath)) {
|
||||
|
@ -309,8 +305,8 @@ namespace Greenshot.Helpers {
|
|||
returnValue = fileNameWithExtension;
|
||||
conf.OutputFileAsFullpath = fileNameWithExtension;
|
||||
IniConfig.Save();
|
||||
} catch(System.Runtime.InteropServices.ExternalException) {
|
||||
MessageBox.Show(Language.GetFormattedString(LangKey.error_nowriteaccess,saveImageFileDialog.FileName).Replace(@"\\",@"\"), Language.GetString(LangKey.error));
|
||||
} catch (System.Runtime.InteropServices.ExternalException) {
|
||||
MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
|
@ -327,7 +323,7 @@ namespace Greenshot.Helpers {
|
|||
filename = Regex.Replace(filename, @"[^\d\w\.]", "_");
|
||||
// Remove multiple "_"
|
||||
filename = Regex.Replace(filename, @"_+", "_");
|
||||
string tmpFile = Path.Combine(Path.GetTempPath(),filename);
|
||||
string tmpFile = Path.Combine(Path.GetTempPath(), filename);
|
||||
|
||||
LOG.Debug("Creating TMP File: " + tmpFile);
|
||||
|
||||
|
@ -345,7 +341,7 @@ namespace Greenshot.Helpers {
|
|||
return tmpFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Helper method to create a temp image file
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
|
@ -373,7 +369,7 @@ namespace Greenshot.Helpers {
|
|||
/// Cleanup all created tmpfiles
|
||||
/// </summary>
|
||||
public static void RemoveTmpFiles() {
|
||||
foreach(string tmpFile in tmpFileCache.Elements) {
|
||||
foreach (string tmpFile in tmpFileCache.Elements) {
|
||||
if (File.Exists(tmpFile)) {
|
||||
LOG.DebugFormat("Removing old temp file {0}", tmpFile);
|
||||
File.Delete(tmpFile);
|
|
@ -215,6 +215,13 @@
|
|||
<Compile Include="Controls\PleaseWaitForm.Designer.cs">
|
||||
<DependentUpon>PleaseWaitForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\QualityDialog.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\QualityDialog.Designer.cs">
|
||||
<DependentUpon>QualityDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\SaveImageFileDialog.cs" />
|
||||
<Compile Include="Controls\ThumbnailForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -223,9 +230,12 @@
|
|||
<Compile Include="Core\AccessibleHelper.cs" />
|
||||
<Compile Include="Core\BitmapBuffer.cs" />
|
||||
<Compile Include="Core\Cache.cs" />
|
||||
<Compile Include="Core\ClipboardHelper.cs" />
|
||||
<Compile Include="Core\CoreConfiguration.cs" />
|
||||
<Compile Include="Core\CredentialsHelper.cs" />
|
||||
<Compile Include="Core\EncryptionHelper.cs" />
|
||||
<Compile Include="Core\FilenameHelper.cs" />
|
||||
<Compile Include="Core\ImageOutput.cs" />
|
||||
<Compile Include="Core\InterfaceUtils.cs" />
|
||||
<Compile Include="Core\DisplayKeyAttribute.cs" />
|
||||
<Compile Include="Core\EmailConfigHelper.cs" />
|
||||
|
@ -275,15 +285,7 @@
|
|||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="IniFile" />
|
||||
<Folder Include="Interfaces\Drawing" />
|
||||
<Folder Include="Interfaces\Drawing\Filters" />
|
||||
<Folder Include="Interfaces\Forms" />
|
||||
<Folder Include="Interfaces" />
|
||||
<Folder Include="Core" />
|
||||
<Folder Include="Interfaces\Plugin" />
|
||||
<Folder Include="Controls" />
|
||||
<Folder Include="UnmanagedHelpers" />
|
||||
<Folder Include="Interfaces\Drawing\Filters\" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>rmdir /S /Q "$(SolutionDir)bin\$(Configuration)\Plugins"
|
||||
|
|
|
@ -24,6 +24,7 @@ using System.Drawing.Imaging;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Plugin.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace Greenshot.Plugin {
|
||||
/// <summary>
|
||||
|
@ -111,6 +112,8 @@ namespace Greenshot.Plugin {
|
|||
ICursorContainer AddCursorContainer(string filename, int x, int y);
|
||||
IIconContainer AddIconContainer(string filename, int x, int y);
|
||||
IMetafileContainer AddMetafileContainer(string filename, int x, int y);
|
||||
long SaveElementsToStream(Stream stream);
|
||||
void LoadElementsFromStream(Stream stream);
|
||||
|
||||
bool HasSelectedElements();
|
||||
void RemoveSelectedElements();
|
||||
|
|
|
@ -129,38 +129,6 @@ namespace Greenshot.Plugin {
|
|||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the image to the supplied stream using the specified extension as the format
|
||||
/// </summary>
|
||||
/// <param name="image">The Image to save</param>
|
||||
/// <param name="stream">The Stream to save to</param>
|
||||
/// <param name="outputSettings">OutputSettings</param>
|
||||
void SaveToStream(Image image, Stream stream, OutputSettings outputSettings);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the image to a temp file (random name) using the specified outputformat
|
||||
/// </summary>
|
||||
/// <param name="image">The Image to save</param>
|
||||
/// <param name="outputSettings">OutputSettings</param>
|
||||
/// <param name="destinationPath">destination path, can be empty</param>
|
||||
string SaveToTmpFile(Image image, OutputSettings outputSettings, string destinationPath);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the image to a temp file, but the name is build with the capture details & pattern
|
||||
/// </summary>
|
||||
/// <param name="image">The Image to save</param>
|
||||
/// <param name="captureDetails">captureDetails with the information to build the filename</param>
|
||||
/// <param name="outputSettings">OutputSettings</param>
|
||||
string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputSettings outputSettings);
|
||||
|
||||
/// <summary>
|
||||
/// Return a filename for the current image format (png,jpg etc) with the default file pattern
|
||||
/// that is specified in the configuration
|
||||
/// </summary>
|
||||
/// <param name="format">A string with the format</param>
|
||||
/// <returns>The filename which should be used to save the image</returns>
|
||||
string GetFilename(OutputFormat format, ICaptureDetails captureDetails);
|
||||
|
||||
/// <summary>
|
||||
/// Create a Thumbnail
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue