moved all sources to trunk directory

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@693 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
JKlingen 2010-07-25 08:48:59 +00:00
commit a22b7578bd
392 changed files with 61489 additions and 0 deletions

View file

@ -0,0 +1,320 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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.Threading;
using System.Windows.Forms;
using Greenshot.Drawing;
using Greenshot.Drawing.Fields;
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 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\");
private static AppConfig instance = null;
public Dictionary<string, object> LastUsedFieldValues = new Dictionary<string, object>();
// 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_RegisterHotkeys = true;
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 = 100;
public bool? Capture_Complete_Window = false;
public bool? Capture_Window_Content = false;
#endregion
#region user interface config
public string Ui_Language = "";
public bool? Ui_Effects_Flashlight = false;
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 = "%title%_%YYYY%-%MM%-%DD%_%hh%-%mm%-%ss%";
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 Size Editor_WindowSize = new Size(540, 380);
public Point Editor_WindowLocation = new Point(100, 100);
public String Editor_WindowState = "Normal";
public Rectangle Editor_Previous_Screenbounds = Rectangle.Empty;
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>
/// get an instance of AppConfig
/// </summary>
/// <returns></returns>
public static AppConfig GetInstance() {
if (instance == null) {
instance = Load();
}
return instance;
}
public static void Reload() {
AppConfig newInstance = Load();
instance.Copy(newInstance);
}
/// <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;
CheckConfigFile();
string configfilename = Path.Combine(configfilepath, CONFIG_FILE_NAME);
try {
LOG.Debug("Loading configuration from: " + configfilename);
using (FileStream fileStream = File.Open(configfilename, FileMode.Open, FileAccess.Read)) {
BinaryFormatter binaryFormatter = new BinaryFormatter();
conf = (AppConfig) binaryFormatter.Deserialize(fileStream);
}
conf.SetDefaults();
return conf;
} catch (SerializationException e) {
LOG.Error("Problem loading configuration from: " + configfilename, e);
AppConfig config = new AppConfig();
config.Store();
return config;
} catch (Exception e) {
LOG.Error("Problem loading configuration from: " + configfilename, e);
MessageBox.Show(String.Format("Could not load Greenshot's configuration file. Please check access permissions for '{0}'.\n",configfilename),"Error");
Process.GetCurrentProcess().Kill();
}
return null;
}
/// <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;
} else if (!File.Exists(Path.Combine(configfilepath, CONFIG_FILE_NAME))) {
Directory.CreateDirectory(configfilepath);
new AppConfig().Store();
}
}
/// <summary>
/// saves the configuration values to the supplied config file
/// </summary>
public void Store() {
Store(configfilepath);
}
/// <summary>
/// saves the configuration values to the config path
/// </summary>
public void Store(string configpath) {
string configfilename = Path.Combine(configpath, CONFIG_FILE_NAME);
try {
LOG.Debug("Saving configuration to: " + configfilename);
using (FileStream fileStream = File.Open(configfilename, FileMode.Create)) {
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fileStream, this);
}
} catch (UnauthorizedAccessException e) {
LOG.Error("Problem saving configuration to: " + configfilename, e);
MessageBox.Show(Language.GetInstance().GetFormattedString(LangKey.config_unauthorizedaccess_write,configfilename),Language.GetInstance().GetString(LangKey.error));
}
}
/// <summary>
/// when new fields are added to this class, they are instanced
/// with null by default. this method iterates over all public
/// fields and uses reflection to set them to the proper default value.
/// </summary>
public void SetDefaults() {
Type type = this.GetType();
FieldInfo[] fieldInfos = type.GetFields();
foreach (FieldInfo fi in fieldInfos) {
object o = fi.GetValue(this);
int i;
if (o == null || (int.TryParse(o.ToString(), out i) && i == 0)) {
// found field with value null. setting to default.
AppConfig tmpConf = new AppConfig();
Type tmpType = tmpConf.GetType();
FieldInfo defaultField = tmpType.GetField(fi.Name);
fi.SetValue(this, defaultField.GetValue(tmpConf));
}
}
}
private void Copy(AppConfig newConfig) {
Type type = this.GetType();
// Copy fields
FieldInfo[] fieldInfos = type.GetFields();
foreach (FieldInfo fi in fieldInfos) {
object newValue = fi.GetValue(newConfig);
fi.SetValue(this, newValue);
}
// Update language
if (newConfig.Ui_Language != null && !newConfig.Ui_Language.Equals(Language.GetInstance().CurrentLanguage)) {
string newLang = Language.GetInstance().SetLanguage(newConfig.Ui_Language);
// check if the language was not wat was supplied (near match)
if (newConfig.Ui_Language.Equals(newLang)) {
// Store change
this.Store();
}
}
}
public static Properties GetAvailableProperties() {
Properties properties = new Properties();
Type type = typeof(AppConfig);
FieldInfo[] fieldInfos = type.GetFields();
foreach (FieldInfo fi in fieldInfos) {
Type fieldType = fi.FieldType;
if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))) {
// We are dealing with a generic type that is nullable
fieldType = Nullable.GetUnderlyingType(fieldType);
}
if (fieldType == typeof(string) || fieldType == typeof(bool) || fieldType == typeof(int)) {
properties.AddProperty(fi.Name, fieldType.Name);
}
}
return properties;
}
public void SetProperties(Properties properties) {
Type type = this.GetType();
FieldInfo[] fieldInfos = type.GetFields();
foreach(string key in properties.Keys) {
FieldInfo currentField = type.GetField(key);
if (currentField != null) {
object currentValue = currentField.GetValue(this);
LOG.Debug("Before: " + currentField.Name + "=" + currentValue);
if (currentField.FieldType == typeof(string)) {
currentField.SetValue(this, properties.GetProperty(key));
} else if (currentField.FieldType == typeof(bool) ||currentField.FieldType == typeof(bool?)) {
currentField.SetValue(this, properties.GetBoolProperty(key));
} else if (currentField.FieldType == typeof(int) || currentField.FieldType == typeof(int?)) {
currentField.SetValue(this, properties.GetIntProperty(key));
}
LOG.Debug("After: " + currentField.Name + "=" + currentField.GetValue(this));
} else {
LOG.Warn("Configuration for " + key + " not found! (Incorrect key?)");
}
}
}
public void UpdateLastUsedFieldValue(Field f) {
if(f.Value != null) {
string key = GetKeyForField(f);
LastUsedFieldValues[key] = f.Value;
}
}
public Field GetLastUsedValueForField(Field f, object preferredDefaultValue) {
string key = GetKeyForField(f);
if(LastUsedFieldValues.ContainsKey(key)) {
f.Value = LastUsedFieldValues[key];
} else if(preferredDefaultValue != null) {
f.Value = preferredDefaultValue;
}else {
f.Value = f.FieldType.DefaultValue;
}
return f;
}
/// <param name="f"></param>
/// <returns></returns>
/// <param name="f"></param>
/// <returns>the key under which last used value for the Field can be stored/retrieved</returns>
private string GetKeyForField(Field f) {
if(f.Scope == null) {
return f.FieldType.Name;
} else {
return f.FieldType.Name + "-" + f.Scope;
}
}
}
}

View file

@ -0,0 +1,51 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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";
public static ILanguage GetInstance() {
if(uniqueInstance == null) {
uniqueInstance = new LanguageContainer();
uniqueInstance.LanguageFilePattern = LANGUAGE_FILENAME_PATTERN;
uniqueInstance.Load();
uniqueInstance.SetLanguage(AppConfig.GetInstance().Ui_Language);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(uniqueInstance.CurrentLanguage);
}
return uniqueInstance;
}
}
}

View file

@ -0,0 +1,191 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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,
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_title,
quicksettings_destination_file,
settings_alwaysshowjpegqualitydialog,
settings_alwaysshowprintoptionsdialog,
settings_applicationsettings,
settings_autostartshortcut,
settings_capture,
settings_capture_mousepointer,
settings_capture_windows_interactive,
settings_capture_window_full,
settings_capture_window_content,
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_jpegquality,
settings_jpegsettings,
settings_language,
settings_message_filenamepattern,
settings_output,
settings_playsound,
settings_preferredfilesettings,
settings_primaryimageformat,
settings_printer,
settings_printoptions,
settings_registerhotkeys,
settings_showflashlight,
settings_skipimageeditor,
settings_storagelocation,
settings_title,
settings_tooltip_filenamepattern,
settings_tooltip_language,
settings_tooltip_primaryimageformat,
settings_tooltip_registerhotkeys,
settings_tooltip_storagelocation,
settings_visualization,
settings_waittime,
tooltip_firststart,
warning,
warning_hotkeys
}
}

View file

@ -0,0 +1,37 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 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"};
public static string[] SupportedImageFormats = {ImageFormat.Jpeg.ToString(),ImageFormat.Gif.ToString(),ImageFormat.Png.ToString(),ImageFormat.Bmp.ToString()};
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;
}
}