"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,235 @@
/*
* 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;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using Greenshot.Drawing;
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.UnmanagedHelpers;
using GreenshotPlugin.Controls;
using GreenshotPlugin.Core;
namespace Greenshot.Configuration {
public enum ScreenshotDestinations {Editor=1, FileDefault=2, FileWithDialog=4, Clipboard=8, Printer=16, EMail=32}
/// <summary>
/// AppConfig is used for loading and saving the configuration. All public fields
/// in this class are serialized with the BinaryFormatter and then saved to the
/// config file. After loading the values from file, SetDefaults iterates over
/// all public fields an sets fields set to null to the default value.
/// </summary>
[Serializable]
public class AppConfig {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(AppConfig));
private static readonly Regex FIXOLD_REGEXP = new Regex(@"%(?<variable>[\w]+)%", RegexOptions.Compiled);
private const string VAR_PREFIX = "${";
private const string VAR_POSTFIX = "}";
//private static string loc = Assembly.GetExecutingAssembly().Location;
//private static string oldFilename = Path.Combine(loc.Substring(0,loc.LastIndexOf(@"\")),"config.dat");
private const string CONFIG_FILE_NAME = "config.dat";
private static string configfilepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),@"Greenshot\");
// the configuration part - all public vars are stored in the config file
// don't use "null" and "0" as default value!
#region general application config
public bool? General_IsFirstLaunch = true;
#endregion
#region capture config
public bool? Capture_Mousepointer = true;
public bool? Capture_Windows_Interactive = false;
public int Capture_Wait_Time = 101;
public bool? fixedWaitTime = false;
#endregion
#region user interface config
public string Ui_Language = "";
public bool? Ui_Effects_CameraSound = true;
#endregion
#region output config
public ScreenshotDestinations Output_Destinations = ScreenshotDestinations.Editor;
public string Output_File_Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
public string Output_File_FilenamePattern = "${capturetime}_${title}";
public string Output_File_Format = ImageFormat.Png.ToString();
public bool? Output_File_CopyPathToClipboard = false;
public int Output_File_JpegQuality = 80;
public bool? Output_File_PromptJpegQuality = false;
public int Output_File_IncrementingNumber = 1;
public string Output_FileAs_Fullpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png");
public bool? Output_Print_PromptOptions = true;
public bool? Output_Print_AllowRotate = true;
public bool? Output_Print_AllowEnlarge = true;
public bool? Output_Print_AllowShrink = true;
public bool? Output_Print_Center = true;
public bool? Output_Print_Timestamp = true;
#endregion
#region editor config
public WindowPlacement Editor_Placement;
public Color[] Editor_RecentColors = new Color[12];
public Font Editor_Font = null;
#endregion
/// <summary>
/// a private constructor because this is a singleton
/// </summary>
private AppConfig() {
}
/// <summary>
/// Remove the old %VAR% syntax
/// </summary>
/// <param name="oldPattern">String with old syntax %VAR%</param>
/// <returns>The fixed pattern</returns>
private static string FixFallback(string oldPattern) {
return FIXOLD_REGEXP.Replace(oldPattern, new MatchEvaluator(delegate(Match m) { return VAR_PREFIX + m.Groups["variable"].Value + VAR_POSTFIX;}));
}
/// <summary>
/// loads the configuration from the config file
/// </summary>
/// <returns>an instance of AppConfig with all values set from the config file</returns>
private static AppConfig Load() {
AppConfig conf = null;
if (File.Exists(Path.Combine(Application.StartupPath, CONFIG_FILE_NAME))) {
configfilepath = Application.StartupPath;
}
string configfilename = Path.Combine(configfilepath, CONFIG_FILE_NAME);
try {
LOG.DebugFormat("Loading configuration from: {0}", configfilename);
using (FileStream fileStream = File.Open(configfilename, FileMode.Open, FileAccess.Read)) {
BinaryFormatter binaryFormatter = new BinaryFormatter();
conf = (AppConfig) binaryFormatter.Deserialize(fileStream);
}
conf.Output_File_FilenamePattern = FixFallback(conf.Output_File_FilenamePattern);
conf.Output_File_Path = FixFallback(conf.Output_File_Path);
} catch (Exception e) {
LOG.Warn("(ignoring) Problem loading configuration from: " + configfilename, e);
}
return conf;
}
public static void UpgradeToIni() {
bool normalIni = File.Exists(Path.Combine(configfilepath, CONFIG_FILE_NAME));
bool startupIni = File.Exists(Path.Combine(Application.StartupPath, CONFIG_FILE_NAME));
if (startupIni || normalIni) {
AppConfig appConfig = Load();
if (appConfig != null) {
LOG.Info("Migrating old configuration");
CoreConfiguration coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
// copy values
try {
coreConfiguration.OutputFileFilenamePattern = appConfig.Output_File_FilenamePattern;
if (appConfig.Output_File_Format != null) {
coreConfiguration.OutputFileFormat = (OutputFormat)Enum.Parse(typeof(OutputFormat), appConfig.Output_File_Format.ToLower());
}
coreConfiguration.OutputFileIncrementingNumber = unchecked((uint)appConfig.Output_File_IncrementingNumber);
coreConfiguration.OutputFileJpegQuality = appConfig.Output_File_JpegQuality;
coreConfiguration.OutputFilePath = appConfig.Output_File_Path;
coreConfiguration.OutputFilePromptJpegQuality = (bool)appConfig.Output_File_PromptJpegQuality;
coreConfiguration.Language = appConfig.Ui_Language;
coreConfiguration.PlayCameraSound = (bool)appConfig.Ui_Effects_CameraSound;
coreConfiguration.CaptureMousepointer = (bool)appConfig.Capture_Mousepointer;
coreConfiguration.OutputFileCopyPathToClipboard = (bool)appConfig.Output_File_CopyPathToClipboard;
coreConfiguration.OutputPrintAllowEnlarge = (bool)appConfig.Output_Print_AllowEnlarge;
coreConfiguration.OutputPrintAllowRotate = (bool)appConfig.Output_Print_AllowRotate;
coreConfiguration.OutputPrintAllowShrink = (bool)appConfig.Output_Print_AllowShrink;
coreConfiguration.OutputPrintCenter = (bool)appConfig.Output_Print_Center;
coreConfiguration.OutputPrintPromptOptions = (bool)appConfig.Output_Print_PromptOptions;
coreConfiguration.OutputPrintTimestamp = (bool)appConfig.Output_Print_Timestamp;
int delay = appConfig.Capture_Wait_Time-1;
if (delay < 0) {
delay = 0;
}
coreConfiguration.CaptureDelay = delay;
if ((appConfig.Output_Destinations & ScreenshotDestinations.Clipboard) == ScreenshotDestinations.Clipboard) {
coreConfiguration.OutputDestinations.Add(Destination.Clipboard);
}
if ((appConfig.Output_Destinations & ScreenshotDestinations.Editor) == ScreenshotDestinations.Editor) {
coreConfiguration.OutputDestinations.Add(Destination.Editor);
}
if ((appConfig.Output_Destinations & ScreenshotDestinations.EMail) == ScreenshotDestinations.EMail) {
coreConfiguration.OutputDestinations.Add(Destination.EMail);
}
if ((appConfig.Output_Destinations & ScreenshotDestinations.Printer) == ScreenshotDestinations.Printer) {
coreConfiguration.OutputDestinations.Add(Destination.Printer);
}
if ((appConfig.Output_Destinations & ScreenshotDestinations.FileDefault) == ScreenshotDestinations.FileDefault) {
coreConfiguration.OutputDestinations.Add(Destination.FileDefault);
}
if ((appConfig.Output_Destinations & ScreenshotDestinations.FileWithDialog) == ScreenshotDestinations.FileWithDialog) {
coreConfiguration.OutputDestinations.Add(Destination.FileWithDialog);
}
IniConfig.Save();
} catch (Exception e) {
LOG.Error(e);
}
}
try {
LOG.Info("Deleting old configuration");
File.Delete(Path.Combine(configfilepath, CONFIG_FILE_NAME));
} catch (Exception e) {
LOG.Error(e);
}
}
}
/// <summary>
/// Checks for the existence of a configuration file.
/// First in greenshot's Applicationdata folder (where it is stored since 0.6),
/// then (if it cannot be found there) in greenshot's program directory (where older
/// versions might have stored it).
/// If the latter is the case, the file is moved to the new location, so that a user does not lose
/// their configuration after upgrading.
/// If there is no file in both locations, a virgin config file is created.
/// </summary>
private static void CheckConfigFile() {
// check if file is in the same location as started from, if this is the case
// we will use this file instead of the ApplicationDate folder
// Done for Feature Request #2741508
if (File.Exists(Path.Combine(Application.StartupPath, CONFIG_FILE_NAME))) {
configfilepath = Application.StartupPath;
}
}
}
}

View file

@ -0,0 +1,135 @@
/*
* 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.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
using Greenshot.Drawing;
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.UnmanagedHelpers;
using GreenshotPlugin.Core;
namespace Greenshot.Configuration {
/// <summary>
/// Description of CoreConfiguration.
/// </summary>
[IniSection("Editor", Description="Greenshot editor configuration")]
public class EditorConfiguration : IniSection {
[IniProperty("RecentColors", Separator="|", Description="Last used colors")]
public List<Color> RecentColors;
[IniProperty("LastFieldValue", Separator="|", Description="Field values, make sure the last used settings are re-used")]
public Dictionary<string, object> LastUsedFieldValues;
[IniProperty("MatchSizeToCapture", Description="Match the editor window size to the capture", DefaultValue="false")]
public bool MatchSizeToCapture;
[IniProperty("WindowPlacementFlags", Description="Placement flags", DefaultValue="0")]
public WindowPlacementFlags WindowPlacementFlags;
[IniProperty("WindowShowCommand", Description="Show command", DefaultValue="Normal")]
public ShowWindowCommand ShowWindowCommand;
[IniProperty("WindowMinPosition", Description="Position of minimized window", DefaultValue="-1,-1")]
public Point WindowMinPosition;
[IniProperty("WindowMaxPosition", Description="Position of maximized window", DefaultValue="-1,-1")]
public Point WindowMaxPosition;
[IniProperty("WindowNormalPosition", Description="Position of normal window", DefaultValue="100,100,400,400")]
public Rectangle WindowNormalPosition;
/// <summary>
/// Supply values we can't put as defaults
/// </summary>
/// <param name="property">The property to return a default for</param>
/// <returns>object with the default value for the supplied property</returns>
public override object GetDefault(string property) {
switch(property) {
case "RecentColors":
return new List<Color>();
}
return null;
}
/// <param name="requestingType">Type of the class for which to create the field</param>
/// <param name="fieldType">FieldType of the field to construct</param>
/// <param name="scope">FieldType of the field to construct</param>
/// <returns>a new Field of the given fieldType, with the scope of it's value being restricted to the Type scope</returns>
public Field CreateField(Type requestingType, FieldType fieldType, object preferredDefaultValue) {
string requestingTypeName = requestingType.Name;
string requestedField = requestingTypeName + "." + fieldType.Name;
object fieldValue = preferredDefaultValue;
// Check if the configuration exists
if (LastUsedFieldValues == null) {
LastUsedFieldValues = new Dictionary<string, object>();
}
// Check if settings for the requesting type exist, if not create!
if (LastUsedFieldValues.ContainsKey(requestedField)) {
// Check if a value is set (not null)!
if (LastUsedFieldValues[requestedField] != null) {
fieldValue = LastUsedFieldValues[requestedField];
} else {
// Overwrite null value
LastUsedFieldValues[requestedField] = fieldValue;
}
} else {
LastUsedFieldValues.Add(requestedField, fieldValue);
}
Field returnField = new Field(fieldType, requestingType);
returnField.Value = fieldValue;
return returnField;
}
public void UpdateLastFieldValue(Field field) {
string requestedField = field.Scope + "." + field.FieldType.Name;
// Check if the configuration exists
if (LastUsedFieldValues == null) {
LastUsedFieldValues = new Dictionary<string, object>();
}
// check if settings for the requesting type exist, if not create!
if (LastUsedFieldValues.ContainsKey(requestedField)) {
LastUsedFieldValues[requestedField] = field.myValue;
} else {
LastUsedFieldValues.Add(requestedField, field.myValue);
}
}
public WindowPlacement GetEditorPlacement() {
WindowPlacement placement = WindowPlacement.Default;
placement.NormalPosition = new RECT(WindowNormalPosition);
placement.MaxPosition = new POINT(WindowMaxPosition);
placement.MinPosition = new POINT(WindowMinPosition);
placement.ShowCmd = ShowWindowCommand;
placement.Flags = WindowPlacementFlags;
return placement;
}
public void SetEditorPlacement(WindowPlacement placement) {
WindowNormalPosition = placement.NormalPosition.ToRectangle();
WindowMaxPosition = placement.MaxPosition.ToPoint();
WindowMinPosition = placement.MinPosition.ToPoint();
ShowWindowCommand = placement.ShowCmd;
WindowPlacementFlags = placement.Flags;
}
}
}

View file

@ -0,0 +1,55 @@
/*
* 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.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using GreenshotPlugin.Core;
namespace Greenshot.Configuration {
/// <summary>
/// Wrapper for the language container for the Greenshot base.
/// </summary>
public class Language : LanguageContainer, ILanguage {
private static ILanguage uniqueInstance;
private const string LANGUAGE_FILENAME_PATTERN = @"language-*.xml";
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
public static ILanguage GetInstance() {
if(uniqueInstance == null) {
uniqueInstance = new LanguageContainer();
uniqueInstance.LanguageFilePattern = LANGUAGE_FILENAME_PATTERN;
uniqueInstance.Load();
if (string.IsNullOrEmpty(conf.Language)) {
uniqueInstance.SynchronizeLanguageToCulture();
} else {
uniqueInstance.SetLanguage(conf.Language);
}
}
return uniqueInstance;
}
}
}

View file

@ -0,0 +1,201 @@
/*
* 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;
namespace Greenshot.Configuration {
public enum LangKey {
about_bugs,
about_donations,
about_host,
about_icons,
about_license,
about_title,
about_translation,
application_title,
bugreport_cancel,
bugreport_info,
bugreport_title,
clipboard_error,
clipboard_inuse,
colorpicker_alpha,
colorpicker_apply,
colorpicker_blue,
colorpicker_green,
colorpicker_htmlcolor,
colorpicker_recentcolors,
colorpicker_red,
colorpicker_title,
colorpicker_transparent,
config_unauthorizedaccess_write,
contextmenu_about,
contextmenu_capturearea,
contextmenu_captureclipboard,
contextmenu_capturefullscreen,
contextmenu_capturelastregion,
contextmenu_capturewindow,
contextmenu_donate,
contextmenu_exit,
contextmenu_help,
contextmenu_openfile,
contextmenu_quicksettings,
contextmenu_settings,
contextmenu_captureie,
contextmenu_openrecentcapture,
editor_arrange,
editor_arrowheads,
editor_arrowheads_both,
editor_arrowheads_end,
editor_arrowheads_none,
editor_arrowheads_start,
editor_backcolor,
editor_blur_radius,
editor_bold,
editor_brightness,
editor_cancel,
editor_clipboardfailed,
editor_close,
editor_close_on_save,
editor_close_on_save_title,
editor_confirm,
editor_copyimagetoclipboard,
editor_copypathtoclipboard,
editor_copytoclipboard,
editor_crop,
editor_cursortool,
editor_cuttoclipboard,
editor_deleteelement,
editor_downonelevel,
editor_downtobottom,
editor_drawarrow,
editor_drawellipse,
editor_drawhighlighter,
editor_drawline,
editor_drawrectangle,
editor_drawtextbox,
editor_duplicate,
editor_edit,
editor_email,
editor_file,
editor_fontsize,
editor_forecolor,
editor_highlight_area,
editor_highlight_grayscale,
editor_highlight_mode,
editor_highlight_text,
editor_highlight_magnify,
editor_pixel_size,
editor_imagesaved,
editor_italic,
editor_load_objects,
editor_magnification_factor,
editor_obfuscate,
editor_obfuscate_blur,
editor_obfuscate_mode,
editor_obfuscate_pixelize,
editor_object,
editor_opendirinexplorer,
editor_pastefromclipboard,
editor_preview_quality,
editor_print,
editor_save,
editor_save_objects,
editor_saveas,
editor_selectall,
editor_senttoprinter,
editor_shadow,
editor_storedtoclipboard,
editor_thickness,
editor_title,
editor_uponelevel,
editor_uptotop,
error,
error_multipleinstances,
error_nowriteaccess,
error_openfile,
error_openlink,
error_save,
help_title,
jpegqualitydialog_choosejpegquality,
jpegqualitydialog_dontaskagain,
jpegqualitydialog_title,
print_error,
printoptions_allowcenter,
printoptions_allowenlarge,
printoptions_allowrotate,
printoptions_allowshrink,
printoptions_dontaskagain,
printoptions_timestamp,
printoptions_inverted,
printoptions_title,
quicksettings_destination_file,
settings_alwaysshowjpegqualitydialog,
settings_alwaysshowprintoptionsdialog,
settings_applicationsettings,
settings_autostartshortcut,
settings_capture,
settings_capture_mousepointer,
settings_capture_windows_interactive,
settings_copypathtoclipboard,
settings_destination,
settings_destination_clipboard,
settings_destination_editor,
settings_destination_email,
settings_destination_file,
settings_destination_fileas,
settings_destination_printer,
settings_filenamepattern,
settings_general,
settings_iecapture,
settings_jpegquality,
settings_jpegsettings,
settings_language,
settings_message_filenamepattern,
settings_output,
settings_playsound,
settings_plugins,
settings_preferredfilesettings,
settings_primaryimageformat,
settings_printer,
settings_printoptions,
settings_registerhotkeys,
settings_showflashlight,
settings_storagelocation,
settings_title,
settings_tooltip_filenamepattern,
settings_tooltip_language,
settings_tooltip_primaryimageformat,
settings_tooltip_registerhotkeys,
settings_tooltip_storagelocation,
settings_visualization,
settings_waittime,
settings_windowscapture,
settings_window_capture_mode,
settings_network,
settings_checkperiod,
settings_usedefaultproxy,
tooltip_firststart,
warning,
warning_hotkeys,
hotkeys,
wait_ie_capture,
update_found
}
}

View file

@ -0,0 +1,36 @@
/*
* 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.Drawing.Imaging;
using System.Drawing;
using System.Windows.Forms;
using System;
namespace Greenshot.Configuration {
/// <summary>
/// Greenshot's runtime configuration
/// abstract, all properties are public and static
/// </summary>
public abstract class RuntimeConfig {
public static string[] SupportedLanguages = {"en-US","de-DE","nl-NL"};
public static string BugTrackerUrl = "https://sourceforge.net/tracker/?func=postadd&group_id=191585&atid=937972&summary=%SUMMARY%&details=%DETAILS%";
public static Rectangle LastCapturedRegion = Rectangle.Empty;
}
}