private void newPreset() { //check if saved preset string presetname = null; using (PresetNameForm dlg = new PresetNameForm(_presets)) { if (dlg.ShowDialog() == DialogResult.OK) { presetname = dlg.PresetName; } } if (!string.IsNullOrEmpty(presetname)) { try { using (Utils.DBCon dbcon = new Utils.DBConComSqlite(_presetDatabaseFile)) { initDatabase(dbcon); if (!_presets.Contains(presetname)) { //we need to add the action AddAction(string.Concat("Presets|",presetname)); Framework.Interfaces.IPluginUIMainWindow main = (from Framework.Interfaces.IPluginUIMainWindow a in Core.GetPlugin(Framework.PluginType.UIMainWindow) select a).FirstOrDefault(); main.AddAction(this, "Presets", presetname); _presets.Add(presetname); } dbcon.ExecuteNonQuery(string.Format("delete from forms where preset='{0}'", presetname)); dbcon.ExecuteNonQuery(string.Format("delete from preset where name='{0}'", presetname)); dbcon.ExecuteNonQuery(string.Format("insert into preset (name) values ('{0}')", presetname)); List<Framework.Interfaces.IPlugin> pins = Core.GetPlugins(); foreach (Framework.Interfaces.IPlugin pin in pins) { Framework.Interfaces.IPluginUIChildWindow p = pin as Framework.Interfaces.IPluginUIChildWindow; if (p != null) { if (p.ChildForm != null && p.ChildForm.Visible) { dbcon.ExecuteNonQuery(string.Format("insert into forms (preset, plugintype, x, y, w, h, visible) values ('{0}', '{1}', {2}, {3}, {4}, {5}, 1)", presetname, p.GetType().ToString(), p.ChildForm.Left, p.ChildForm.Top, p.ChildForm.Width, p.ChildForm.Height)); } else { dbcon.ExecuteNonQuery(string.Format("insert into forms (preset, plugintype, x, y, w, h, visible) values ('{0}', '{1}', 0, 0, 100, 100, 0)", presetname, p.GetType().ToString())); } } else if (pin.GetType().ToString() == "GlobalcachingApplication.Plugins.Maps.MapsPlugin") { //special onw try { MethodInfo mi = pin.GetType().GetMethod("GetWindowStateText"); if (mi != null) { string s = mi.Invoke(pin, null) as string; if (s != null) { dbcon.ExecuteNonQuery(string.Format("insert into forms (preset, plugintype, x, y, w, h, visible, customtag) values ('{0}', '{1}', 0, 0, 100, 100, 0, '{2}')", presetname, pin.GetType().ToString(), s.Replace("'", "''"))); } } } catch { } } } } } catch { } } }
private void newPreset() { //check if saved preset string presetname = null; using (PresetNameForm dlg = new PresetNameForm(_presets)) { if (dlg.ShowDialog() == DialogResult.OK) { presetname = dlg.PresetName; } } if (!string.IsNullOrEmpty(presetname)) { try { lock (Core.SettingsProvider) { if (!_presets.Contains(presetname)) { //we need to add the action AddAction(string.Concat("Presets|", presetname)); Framework.Interfaces.IPluginUIMainWindow main = (from Framework.Interfaces.IPluginUIMainWindow a in Core.GetPlugin(Framework.PluginType.UIMainWindow) select a).FirstOrDefault(); main.AddAction(this, "Presets", presetname); _presets.Add(presetname); } Core.SettingsProvider.Database.Execute(string.Format("delete from {1} where preset='{0}'", presetname.Replace("'", "''"), Core.SettingsProvider.GetFullTableName("forms"))); Core.SettingsProvider.Database.Execute(string.Format("delete from {1} where name='{0}'", presetname.Replace("'", "''"), Core.SettingsProvider.GetFullTableName("preset"))); Core.SettingsProvider.Database.Execute(string.Format("insert into {1} (name) values ('{0}')", presetname.Replace("'", "''"), Core.SettingsProvider.GetFullTableName("preset"))); List <Framework.Interfaces.IPlugin> pins = Core.GetPlugins(); foreach (Framework.Interfaces.IPlugin pin in pins) { Framework.Interfaces.IPluginUIChildWindow p = pin as Framework.Interfaces.IPluginUIChildWindow; if (p != null) { if (p.ChildForm != null && p.ChildForm.Visible) { Core.SettingsProvider.Database.Execute(string.Format("insert into {6} (preset, plugintype, x, y, w, h, visible) values ('{0}', '{1}', {2}, {3}, {4}, {5}, 1)", presetname.Replace("'", "''"), p.GetType().ToString(), p.ChildForm.Left, p.ChildForm.Top, p.ChildForm.Width, p.ChildForm.Height, Core.SettingsProvider.GetFullTableName("forms"))); } else { Core.SettingsProvider.Database.Execute(string.Format("insert into {2} (preset, plugintype, x, y, w, h, visible) values ('{0}', '{1}', 0, 0, 100, 100, 0)", presetname.Replace("'", "''"), p.GetType().ToString(), Core.SettingsProvider.GetFullTableName("forms"))); } } else if (pin.GetType().ToString() == "GlobalcachingApplication.Plugins.Maps.MapsPlugin") { //special onw try { MethodInfo mi = pin.GetType().GetMethod("GetWindowStateText"); if (mi != null) { string s = mi.Invoke(pin, null) as string; if (s != null) { Core.SettingsProvider.Database.Execute(string.Format("insert into {3} (preset, plugintype, x, y, w, h, visible, customtag) values ('{0}', '{1}', 0, 0, 100, 100, 0, '{2}')", presetname.Replace("'", "''"), pin.GetType().ToString(), s.Replace("'", "''"), Core.SettingsProvider.GetFullTableName("forms"))); } } } catch { } } } } } catch { } } }