mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 21:43:24 -07:00
Configuration refactoring, using the new IniConfiguration
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@851 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
d3fc983efd
commit
5a7258b9f2
1 changed files with 44 additions and 47 deletions
|
@ -47,9 +47,8 @@ namespace Greenshot {
|
||||||
public partial class MainForm : Form {
|
public partial class MainForm : Form {
|
||||||
private const string LOG4NET_FILE = "log4net.xml";
|
private const string LOG4NET_FILE = "log4net.xml";
|
||||||
private static log4net.ILog LOG = null;
|
private static log4net.ILog LOG = null;
|
||||||
private static AppConfig conf;
|
|
||||||
private static Mutex applicationMutex = null;
|
private static Mutex applicationMutex = null;
|
||||||
private static CoreConfiguration coreConfiguration;
|
private static CoreConfiguration conf;
|
||||||
|
|
||||||
private static void InitializeLog4NET() {
|
private static void InitializeLog4NET() {
|
||||||
// Setup log4j, currently the file is called log4net.xml
|
// Setup log4j, currently the file is called log4net.xml
|
||||||
|
@ -82,14 +81,14 @@ namespace Greenshot {
|
||||||
Thread.CurrentThread.Name = Application.ProductName;
|
Thread.CurrentThread.Name = Application.ProductName;
|
||||||
|
|
||||||
// Read configuration
|
// Read configuration
|
||||||
coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
|
conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
if (coreConfiguration.IsDirty) {
|
if (conf.IsDirty) {
|
||||||
IniConfig.Save();
|
IniConfig.Save();
|
||||||
}
|
}
|
||||||
LOG.Info("Firstlaunch: " + coreConfiguration.IsFirstLaunch);
|
LOG.Info("Firstlaunch: " + conf.IsFirstLaunch);
|
||||||
LOG.Info("Destinations:");
|
LOG.Info("Destinations:");
|
||||||
if (coreConfiguration.OutputDestinations != null) {
|
if (conf.OutputDestinations != null) {
|
||||||
foreach(Destination destination in coreConfiguration.OutputDestinations) {
|
foreach(Destination destination in conf.OutputDestinations) {
|
||||||
LOG.Info("\t" + destination);
|
LOG.Info("\t" + destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +201,6 @@ namespace Greenshot {
|
||||||
// Modify configuration
|
// Modify configuration
|
||||||
if (argument.ToLower().Equals("/configure")) {
|
if (argument.ToLower().Equals("/configure")) {
|
||||||
LOG.Debug("Setting configuration!");
|
LOG.Debug("Setting configuration!");
|
||||||
conf = AppConfig.GetInstance();
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
int propertyNr = argumentNr + 1;
|
int propertyNr = argumentNr + 1;
|
||||||
while(propertyNr < args.Length && args[propertyNr].Contains("=")) {
|
while(propertyNr < args.Length && args[propertyNr].Contains("=")) {
|
||||||
|
@ -214,8 +212,9 @@ namespace Greenshot {
|
||||||
propertyNr++;
|
propertyNr++;
|
||||||
}
|
}
|
||||||
if (properties.Count > 0) {
|
if (properties.Count > 0) {
|
||||||
conf.SetProperties(properties);
|
// TODO: Check properties!
|
||||||
conf.Store();
|
//conf.SetProperties(properties);
|
||||||
|
//conf.Store();
|
||||||
// Update running instances
|
// Update running instances
|
||||||
SendData(new CopyDataTransport(CommandEnum.ReloadConfig));
|
SendData(new CopyDataTransport(CommandEnum.ReloadConfig));
|
||||||
LOG.Debug("Configuration modified!");
|
LOG.Debug("Configuration modified!");
|
||||||
|
@ -247,7 +246,6 @@ namespace Greenshot {
|
||||||
if (filesToOpen.Count > 0) {
|
if (filesToOpen.Count > 0) {
|
||||||
SendData(transport);
|
SendData(transport);
|
||||||
} else {
|
} else {
|
||||||
conf = AppConfig.GetInstance();
|
|
||||||
ILanguage lang = Language.GetInstance();
|
ILanguage lang = Language.GetInstance();
|
||||||
MessageBox.Show(lang.GetString(LangKey.error_multipleinstances), lang.GetString(LangKey.error));
|
MessageBox.Show(lang.GetString(LangKey.error_multipleinstances), lang.GetString(LangKey.error));
|
||||||
}
|
}
|
||||||
|
@ -260,21 +258,18 @@ namespace Greenshot {
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
|
||||||
conf = AppConfig.GetInstance();
|
|
||||||
|
|
||||||
// if language is not set, show language dialog
|
// if language is not set, show language dialog
|
||||||
if(conf.Ui_Language.Equals("")) {
|
if(conf.Language.Equals("")) {
|
||||||
LanguageDialog ld = LanguageDialog.GetInstance();
|
LanguageDialog ld = LanguageDialog.GetInstance();
|
||||||
ld.ShowDialog();
|
ld.ShowDialog();
|
||||||
conf.Ui_Language = ld.Language;
|
conf.Language = ld.Language;
|
||||||
conf.Store();
|
IniConfig.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it's the first time launch?
|
// Check if it's the first time launch?
|
||||||
bool firstLaunch = (bool)conf.General_IsFirstLaunch;
|
if(conf.IsFirstLaunch) {
|
||||||
if(firstLaunch) {
|
conf.IsFirstLaunch = false;
|
||||||
conf.General_IsFirstLaunch = false;
|
IniConfig.Save();
|
||||||
conf.Store();
|
|
||||||
transport.AddCommand(CommandEnum.FirstLaunch);
|
transport.AddCommand(CommandEnum.FirstLaunch);
|
||||||
}
|
}
|
||||||
MainForm mainForm = new MainForm(transport);
|
MainForm mainForm = new MainForm(transport);
|
||||||
|
@ -323,7 +318,7 @@ namespace Greenshot {
|
||||||
//
|
//
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
lang = Language.GetInstance();
|
lang = Language.GetInstance();
|
||||||
if((bool)conf.General_RegisterHotkeys) {
|
if(conf.RegisterHotkeys) {
|
||||||
RegisterHotkeys();
|
RegisterHotkeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +465,7 @@ namespace Greenshot {
|
||||||
}
|
}
|
||||||
void CaptureWindow() {
|
void CaptureWindow() {
|
||||||
CaptureMode captureMode = CaptureMode.None;
|
CaptureMode captureMode = CaptureMode.None;
|
||||||
if ((conf.Capture_Windows_Interactive.HasValue && conf.Capture_Windows_Interactive.Value)) {
|
if (conf.CaptureWindowsInteractive) {
|
||||||
captureMode = CaptureMode.Window;
|
captureMode = CaptureMode.Window;
|
||||||
} else {
|
} else {
|
||||||
captureMode = CaptureMode.ActiveWindow;
|
captureMode = CaptureMode.ActiveWindow;
|
||||||
|
@ -530,7 +525,7 @@ namespace Greenshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Contextmenu_helpClick(object sender, System.EventArgs e) {
|
void Contextmenu_helpClick(object sender, System.EventArgs e) {
|
||||||
HelpBrowserForm hpf = new HelpBrowserForm(conf.Ui_Language);
|
HelpBrowserForm hpf = new HelpBrowserForm(conf.Language);
|
||||||
hpf.Show();
|
hpf.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,27 +538,28 @@ namespace Greenshot {
|
||||||
// screenshot destination
|
// screenshot destination
|
||||||
ToolStripMenuSelectList sel = new ToolStripMenuSelectList("destination",true);
|
ToolStripMenuSelectList sel = new ToolStripMenuSelectList("destination",true);
|
||||||
sel.Text = lang.GetString(LangKey.settings_destination);
|
sel.Text = lang.GetString(LangKey.settings_destination);
|
||||||
sel.AddItem(lang.GetString(LangKey.settings_destination_editor), ScreenshotDestinations.Editor, (conf.Output_Destinations&ScreenshotDestinations.Editor)==ScreenshotDestinations.Editor);
|
sel.AddItem(lang.GetString(LangKey.settings_destination_editor), Destination.Editor, conf.OutputDestinations.Contains(Destination.Editor));
|
||||||
sel.AddItem(lang.GetString(LangKey.settings_destination_clipboard), ScreenshotDestinations.Clipboard, (conf.Output_Destinations&ScreenshotDestinations.Clipboard)==ScreenshotDestinations.Clipboard);
|
sel.AddItem(lang.GetString(LangKey.settings_destination_clipboard), Destination.Clipboard, conf.OutputDestinations.Contains(Destination.Clipboard));
|
||||||
sel.AddItem(lang.GetString(LangKey.quicksettings_destination_file), ScreenshotDestinations.FileDefault, (conf.Output_Destinations&ScreenshotDestinations.FileDefault)==ScreenshotDestinations.FileDefault);
|
sel.AddItem(lang.GetString(LangKey.quicksettings_destination_file), Destination.FileDefault, conf.OutputDestinations.Contains(Destination.FileDefault));
|
||||||
sel.AddItem(lang.GetString(LangKey.settings_destination_fileas), ScreenshotDestinations.FileWithDialog, (conf.Output_Destinations&ScreenshotDestinations.FileWithDialog)==ScreenshotDestinations.FileWithDialog);
|
sel.AddItem(lang.GetString(LangKey.settings_destination_fileas), Destination.FileWithDialog, conf.OutputDestinations.Contains(Destination.FileWithDialog));
|
||||||
sel.AddItem(lang.GetString(LangKey.settings_destination_printer), ScreenshotDestinations.Printer, (conf.Output_Destinations&ScreenshotDestinations.Printer)==ScreenshotDestinations.Printer);
|
sel.AddItem(lang.GetString(LangKey.settings_destination_printer), Destination.Printer, conf.OutputDestinations.Contains(Destination.Printer));
|
||||||
|
sel.AddItem(lang.GetString(LangKey.settings_destination_email), Destination.EMail, conf.OutputDestinations.Contains(Destination.EMail));
|
||||||
sel.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
sel.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
||||||
this.contextmenu_quicksettings.DropDownItems.Add(sel);
|
this.contextmenu_quicksettings.DropDownItems.Add(sel);
|
||||||
// print options
|
// print options
|
||||||
sel = new ToolStripMenuSelectList("printoptions",true);
|
sel = new ToolStripMenuSelectList("printoptions",true);
|
||||||
sel.Text = lang.GetString(LangKey.settings_printoptions);
|
sel.Text = lang.GetString(LangKey.settings_printoptions);
|
||||||
sel.AddItem(lang.GetString(LangKey.printoptions_allowshrink), "AllowPrintShrink", (bool)conf.Output_Print_AllowShrink);
|
sel.AddItem(lang.GetString(LangKey.printoptions_allowshrink), "AllowPrintShrink", conf.OutputPrintAllowShrink);
|
||||||
sel.AddItem(lang.GetString(LangKey.printoptions_allowenlarge), "AllowPrintEnlarge", (bool)conf.Output_Print_AllowEnlarge);
|
sel.AddItem(lang.GetString(LangKey.printoptions_allowenlarge), "AllowPrintEnlarge", conf.OutputPrintAllowEnlarge);
|
||||||
sel.AddItem(lang.GetString(LangKey.printoptions_allowrotate), "AllowPrintRotate", (bool)conf.Output_Print_AllowRotate);
|
sel.AddItem(lang.GetString(LangKey.printoptions_allowrotate), "AllowPrintRotate", conf.OutputPrintAllowRotate);
|
||||||
sel.AddItem(lang.GetString(LangKey.printoptions_allowcenter), "AllowPrintCenter", (bool)conf.Output_Print_Center);
|
sel.AddItem(lang.GetString(LangKey.printoptions_allowcenter), "AllowPrintCenter", conf.OutputPrintCenter);
|
||||||
sel.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
sel.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
||||||
this.contextmenu_quicksettings.DropDownItems.Add(sel);
|
this.contextmenu_quicksettings.DropDownItems.Add(sel);
|
||||||
// effects
|
// effects
|
||||||
sel = new ToolStripMenuSelectList("effects",true);
|
sel = new ToolStripMenuSelectList("effects",true);
|
||||||
sel.Text = lang.GetString(LangKey.settings_visualization);
|
sel.Text = lang.GetString(LangKey.settings_visualization);
|
||||||
sel.AddItem(lang.GetString(LangKey.settings_playsound), "PlaySound", (bool)conf.Ui_Effects_CameraSound);
|
sel.AddItem(lang.GetString(LangKey.settings_playsound), "PlaySound", conf.PlayCameraSound);
|
||||||
sel.AddItem(lang.GetString(LangKey.settings_showflashlight), "ShowFlashlight", (bool)conf.Ui_Effects_Flashlight);
|
sel.AddItem(lang.GetString(LangKey.settings_showflashlight), "ShowFlashlight", conf.ShowFlash);
|
||||||
sel.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
sel.CheckedChanged += new EventHandler(this.QuickSettingItemChanged);
|
||||||
this.contextmenu_quicksettings.DropDownItems.Add(sel);
|
this.contextmenu_quicksettings.DropDownItems.Add(sel);
|
||||||
}
|
}
|
||||||
|
@ -573,23 +569,24 @@ namespace Greenshot {
|
||||||
ToolStripMenuSelectListItem item = ((ItemCheckedChangedEventArgs)e).Item;;
|
ToolStripMenuSelectListItem item = ((ItemCheckedChangedEventArgs)e).Item;;
|
||||||
if(selectList.Identifier.Equals("destination")) {
|
if(selectList.Identifier.Equals("destination")) {
|
||||||
IEnumerator en = selectList.DropDownItems.GetEnumerator();
|
IEnumerator en = selectList.DropDownItems.GetEnumerator();
|
||||||
ScreenshotDestinations dest = 0;
|
List<Destination> destinations = new List<Destination>();;
|
||||||
while(en.MoveNext()) {
|
while(en.MoveNext()) {
|
||||||
ToolStripMenuSelectListItem i = (ToolStripMenuSelectListItem)en.Current;
|
ToolStripMenuSelectListItem i = (ToolStripMenuSelectListItem)en.Current;
|
||||||
if(i.Checked) dest |= (ScreenshotDestinations)i.Data;
|
destinations.Add((Destination)i.Data);
|
||||||
}
|
}
|
||||||
conf.Output_Destinations = dest;
|
conf.OutputDestinations = destinations;
|
||||||
conf.Store();
|
IniConfig.Save();
|
||||||
} else if(selectList.Identifier.Equals("printoptions")) {
|
} else if(selectList.Identifier.Equals("printoptions")) {
|
||||||
if(item.Data.Equals("AllowPrintShrink")) conf.Output_Print_AllowShrink = (bool?)item.Checked;
|
if(item.Data.Equals("AllowPrintShrink")) conf.OutputPrintAllowShrink = item.Checked;
|
||||||
else if(item.Data.Equals("AllowPrintEnlarge")) conf.Output_Print_AllowEnlarge = (bool?)item.Checked;
|
else if(item.Data.Equals("AllowPrintEnlarge")) conf.OutputPrintAllowEnlarge = item.Checked;
|
||||||
else if(item.Data.Equals("AllowPrintRotate")) conf.Output_Print_AllowRotate = (bool?)item.Checked;
|
else if(item.Data.Equals("AllowPrintRotate")) conf.OutputPrintAllowRotate = item.Checked;
|
||||||
else if(item.Data.Equals("AllowPrintCenter")) conf.Output_Print_Center = (bool?)item.Checked;
|
else if(item.Data.Equals("AllowPrintCenter")) conf.OutputPrintCenter = item.Checked;
|
||||||
conf.Store();
|
IniConfig.Save();
|
||||||
} else if(selectList.Identifier.Equals("effects")) {
|
} else if(selectList.Identifier.Equals("effects")) {
|
||||||
if(item.Data.Equals("PlaySound")) conf.Ui_Effects_CameraSound = (bool?)item.Checked;
|
if(item.Data.Equals("PlaySound")) conf.PlayCameraSound = item.Checked;
|
||||||
else if(item.Data.Equals("ShowFlashlight")) conf.Ui_Effects_Flashlight = (bool?)item.Checked;
|
else if(item.Data.Equals("ShowFlashlight")) conf.ShowFlash = item.Checked;
|
||||||
conf.Store();
|
IniConfig.Save();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -671,7 +668,7 @@ namespace Greenshot {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Store any open configuration changes
|
// Store any open configuration changes
|
||||||
conf.Store();
|
IniConfig.Save();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.Error("Error storing configuration!", e);
|
LOG.Error("Error storing configuration!", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue