From dcaa7211c5732550cbeb31a0afcb59ce6949835c Mon Sep 17 00:00:00 2001 From: emkael Date: Sun, 27 Oct 2019 17:43:13 +0100 Subject: Saving selected DBs/send options between program runs --- spedytor/Form1.cs | 25 +++++++++++++ spedytor/Properties/OptionSettings.Designer.cs | 49 ++++++++++++++++++++++++++ spedytor/Properties/OptionSettings.settings | 12 +++++++ spedytor/app.config | 6 ++++ spedytor/spedytor.csproj | 9 +++++ 5 files changed, 101 insertions(+) create mode 100644 spedytor/Properties/OptionSettings.Designer.cs create mode 100644 spedytor/Properties/OptionSettings.settings diff --git a/spedytor/Form1.cs b/spedytor/Form1.cs index 093455b..1b2afe2 100644 --- a/spedytor/Form1.cs +++ b/spedytor/Form1.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; @@ -33,7 +34,9 @@ namespace spedytor tInterval_Tick(null, null); } } + this.tLogger.Enabled = false; Logger.getLogger(this.tbLog, LOG_FILENAME).cleanup(); + this.saveSettings(); this.Dispose(); } @@ -41,6 +44,7 @@ namespace spedytor { if (!MySQL.getConfigured()) (new MysqlSettings()).ShowDialog(); if (!MySQL.getConfigured()) this.Dispose(); + this.restoreSettings(); this.refreshDatabaseList(); this.checkS3Options(); } @@ -69,9 +73,11 @@ namespace spedytor MySQL c = new MySQL(""); MySqlDataReader dbs = c.select("SELECT TABLE_SCHEMA FROM information_schema.COLUMNS GROUP BY TABLE_SCHEMA;"); int index = 0; + List dbNames = new List(); while (dbs.Read()) { string dbName = dbs.GetString(0); + dbNames.Add(dbName); this.dbSelectionWindow.lbDatabases.Items.Add(dbName); if (this.selectedDBs.IndexOf(dbName) > -1) { @@ -80,6 +86,7 @@ namespace spedytor index++; } dbs.Close(); + this.setSelectedDBs(this.selectedDBs.Intersect(dbNames).ToList()); } private string getBucketID() @@ -323,5 +330,23 @@ namespace spedytor } } + private void restoreSettings() + { + this.setSelectedDBs(Properties.OptionSettings.Default.dbNames.Cast().ToList()); + this.cSend.Checked = Properties.OptionSettings.Default.send; + } + + private void saveSettings() + { + Properties.OptionSettings.Default.send = this.cSend.Checked; + if (Properties.OptionSettings.Default.dbNames == null) + { + Properties.OptionSettings.Default.dbNames = new System.Collections.Specialized.StringCollection(); + } + Properties.OptionSettings.Default.dbNames.Clear(); + Properties.OptionSettings.Default.dbNames.AddRange(this.selectedDBs.ToArray()); + Properties.OptionSettings.Default.Save(); + } + } } diff --git a/spedytor/Properties/OptionSettings.Designer.cs b/spedytor/Properties/OptionSettings.Designer.cs new file mode 100644 index 0000000..73cd018 --- /dev/null +++ b/spedytor/Properties/OptionSettings.Designer.cs @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace spedytor.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class OptionSettings : global::System.Configuration.ApplicationSettingsBase { + + private static OptionSettings defaultInstance = ((OptionSettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new OptionSettings()))); + + public static OptionSettings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.Collections.Specialized.StringCollection dbNames { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["dbNames"])); + } + set { + this["dbNames"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool send { + get { + return ((bool)(this["send"])); + } + set { + this["send"] = value; + } + } + } +} diff --git a/spedytor/Properties/OptionSettings.settings b/spedytor/Properties/OptionSettings.settings new file mode 100644 index 0000000..3e33106 --- /dev/null +++ b/spedytor/Properties/OptionSettings.settings @@ -0,0 +1,12 @@ + + + + + + + + + False + + + \ No newline at end of file diff --git a/spedytor/app.config b/spedytor/app.config index fe805a1..bf774e4 100644 --- a/spedytor/app.config +++ b/spedytor/app.config @@ -2,12 +2,18 @@ +
+ + + False + + diff --git a/spedytor/spedytor.csproj b/spedytor/spedytor.csproj index 91afa2e..1804199 100644 --- a/spedytor/spedytor.csproj +++ b/spedytor/spedytor.csproj @@ -97,6 +97,11 @@ MysqlSettings.cs + + True + True + OptionSettings.settings + @@ -122,6 +127,10 @@ Designer + + SettingsSingleFileGenerator + OptionSettings.Designer.cs + SettingsSingleFileGenerator Settings.Designer.cs -- cgit v1.2.3