/[RomCheater]/trunk/RomCheater/RomCheaterConfigDialog.cs
ViewVC logotype

Contents of /trunk/RomCheater/RomCheaterConfigDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 814 - (show annotations) (download)
Tue Apr 15 15:58:50 2014 UTC (7 years ago) by william
File size: 10428 byte(s)

1 //#region Logging Defines
2 //// include this any class or method that required logging, and comment-out what is not needed
3
4 //#region Enabled logging levels
5 //#define LOGGING_ENABLE_INFO
6 //#define LOGGING_ENABLE_WARN
7 //#define LOGGING_ENABLE_DEBUG
8 //#define LOGGING_ENABLE_VERBOSEDEBUG
9 //#define LOGGING_ENABLE_ERROR
10 //#define LOGGING_ENABLE_VERBOSEERROR
11 //#define LOGGING_ENABLE_PROFILER
12 //#endregion
13 //#endregion
14 //#define DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST //when defined, will not log verbose debug messages (without changeing logging flags)
15 using System;
16 using System.Collections.Generic;
17 using System.ComponentModel;
18 using System.Data;
19 using System.Drawing;
20 using System.Linq;
21 using System.Text;
22 using System.Windows.Forms;
23 using RomCheater.Logging;
24 using RomCheater.PluginFramework.Core;
25 using RomCheater.Core;
26 using RomCheater.UserSettingsSupport;
27 using Enterprise.Logging;
28
29
30 namespace RomCheater
31 {
32 public partial class RomCheaterConfigDialog : Form
33 {
34 #if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
35 private loggerflags lFlags;
36 #endif
37
38 SettingSubscriber MainSettingsSubscriber;
39 SettingSubscriber LoggingettingsSubscriber;
40
41 private PluginLoader loader = null;
42 public RomCheaterConfigDialog()
43 {
44 InitializeComponent();
45 //lFlags = logger.GetLoggingFlags();
46 //ushort flags = lFlags.Value;
47 //if (lFlags.HasFlag(loggerflags.VERBOSE_DEBUG))
48 //{
49 // flags = lFlags.Value;
50 // flags = (ushort)(lFlags.Value & ~loggerflags.VERBOSE_DEBUG.Value);
51 // logger.SetLoggingFlags(flags);
52 //}
53 MainSettingsSubscriber = new SettingSubscriber();
54 LoggingettingsSubscriber = new SettingSubscriber();
55 MainSettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default);
56 LoggingettingsSubscriber.AddSubscriber(this, RomCheater.Logging.Properties.Settings.Default);
57 }
58 public RomCheaterConfigDialog(PluginLoader loader)
59 : this()
60 {
61 this.loader = loader;
62 }
63 private void RomCheaterConfigDialog_Load(object sender, EventArgs e)
64 {
65 gLog.Info.WriteLine("Loading user settings...");
66 load_loggerflags();
67 setup_plugin_entries();
68 gLog.Info.WriteLine("Loaded user settings.");
69 }
70
71 private void setup_plugin_entries()
72 {
73 foreach (IConfigPlugin c in loader.LoadedConfigPlugins) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); }
74 foreach (IInputPlugin c in loader.LoadedInputPlugins) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); }
75 foreach (IWindowPlugin c in loader.LoadedWindowPlugins) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); }
76 if (loader.LoadedConfigPlugins.Count == 0) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
77 if (loader.LoadedInputPlugins.Count == 0) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
78 if (loader.LoadedWindowPlugins.Count == 0) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
79
80 comboConfigPlugins.SelectedIndex = 0;
81 comboInputPlugins.SelectedIndex = 0;
82 comboWindowPlugins.SelectedIndex = 0;
83
84 // select each plugin base on the last plugin
85 foreach (string item in comboConfigPlugins.Items)
86 {
87 if (item == RomCheater.Properties.Settings.Default.LastConfigPlugin)
88 {
89 gLog.Verbose.Debug.WriteLine(" loading LastConfigPlugin: {0}", MainSettingsSubscriber.GetValue("LastConfigPlugin"));
90 comboConfigPlugins.SelectedIndex = comboConfigPlugins.Items.IndexOf(item);
91 break;
92 }
93 }
94 foreach (string item in comboInputPlugins.Items)
95 {
96 if (item == RomCheater.Properties.Settings.Default.LastInputPlugin)
97 {
98 gLog.Verbose.Debug.WriteLine(" loading LastInputPlugin: {0}", MainSettingsSubscriber.GetValue("LastInputPlugin"));
99 comboInputPlugins.SelectedIndex = comboInputPlugins.Items.IndexOf(item);
100 break;
101 }
102 }
103 foreach (string item in comboWindowPlugins.Items)
104 {
105 if (item == RomCheater.Properties.Settings.Default.LastWindowPlugin)
106 {
107 gLog.Verbose.Debug.WriteLine(" loading LastWindowPlugin: {0}", MainSettingsSubscriber.GetValue("LastWindowPlugin"));
108 comboWindowPlugins.SelectedIndex = comboWindowPlugins.Items.IndexOf(item);
109 break;
110 }
111 }
112
113 }
114
115 private void load_loggerflags()
116 {
117 //gLog.Info.WriteLine(" Loading logger flags...");
118 //object o_flags = LoggingettingsSubscriber.GetValue("LoggingFlags");
119 //loggerflags logflags = (ushort)Convert.ChangeType(o_flags, typeof(ushort));
120 //if (logflags != logger.GetLoggingFlags())
121 //{
122 // logflags = logger.GetLoggingFlags(); // we apparently have forced the logging flags (possible for testing)
123 //}
124 #if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
125 //lFlags = logflags;
126 //ushort pflags = lFlags.Value;
127 //if (lFlags.HasFlag(loggerflags.VERBOSE_DEBUG))
128 //{
129 // pflags = lFlags.Value;
130 // pflags = (ushort)(lFlags.Value & ~loggerflags.VERBOSE_DEBUG.Value);
131 // logger.SetLoggingFlags(pflags);
132 //}
133 #endif
134 //var logger_flags = loggerflags.GetValues();
135
136 //foreach (loggerflags flags in logger_flags)
137 //{
138 // if (flags == loggerflags.ALL ||
139 // flags == loggerflags.NONE ||
140 // flags == loggerflags.DEFAULT)
141 // continue;
142 // string name = flags.Name;
143 // ushort value = (ushort)flags;
144 // CheckBox chkloggerflags = new CheckBox();
145 // chkloggerflags.Font = this.Font;
146 // chkloggerflags.Name = name;
147 // chkloggerflags.Text = name;
148 // chkloggerflags.Tag = value;
149 // Graphics g = chkloggerflags.CreateGraphics();
150 // Size size = g.MeasureString(chkloggerflags.Text, chkloggerflags.Font).ToSize();
151 // chkloggerflags.Width = size.Width + 25;
152 // grpLoggingFlags_flow.Controls.Add(chkloggerflags);
153 // logger.VerboseDebug.WriteLine("\tAdding logger flag: {0} value: 0x{1:x4}", name, value);
154 // if (logflags.HasFlag(value))
155 // {
156 // chkloggerflags.Checked = true;
157 // logger.VerboseDebug.WriteLine("\tTurning on logger flag: {0} value: 0x{1:x4}", name, value);
158 // }
159 //}
160 //grpLoggingFlags.AutoSize = true;
161 //grpLoggingFlags.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
162 //gLog.Info.WriteLine(" Loaded logger flags.");
163 }
164 private void btnSave_Click(object sender, EventArgs e)
165 {
166 gLog.Info.WriteLine("Saving user settings...");
167 SaveSettings();
168 this.Close();
169 }
170 private void btnCancel_Click(object sender, EventArgs e)
171 {
172 this.Close();
173 }
174 private void SaveSettings()
175 {
176 SaveLoggingFlags();
177 SaveSelectedPlugins();
178 MainSettingsSubscriber.SaveSettings();
179 LoggingettingsSubscriber.SaveSettings();
180 //RomCheater.Properties.Settings.Default.Save();
181 //Logging.Properties.Settings.Default.Save();
182 gLog.Info.WriteLine("Saved user settings.");
183 }
184 private void SaveSelectedPlugins()
185 {
186 gLog.Verbose.Debug.WriteLine(" Setting LastConfigPlugin to {0}", comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
187 MainSettingsSubscriber.SetValue("LastConfigPlugin",comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
188
189 gLog.Verbose.Debug.WriteLine(" Setting LastInputPlugin to {0}", comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString());
190 MainSettingsSubscriber.SetValue("LastInputPlugin", comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString());
191
192 gLog.Verbose.Debug.WriteLine(" Setting LastWindowPlugin to {0}", comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString());
193 MainSettingsSubscriber.SetValue("LastWindowPlugin", comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString());
194 }
195 private void SaveLoggingFlags()
196 {
197 //gLog.Debug.WriteLine("Saving Logger flags...");
198 //ushort logflags = loggerflags.NONE;
199 //foreach (CheckBox cb in grpLoggingFlags_flow.Controls)
200 //{
201 // if (!cb.Checked) continue;
202 // ushort value = Convert.ToUInt16(cb.Tag);
203 // logflags = (ushort)(logflags | value);
204 // gLog.Verbose.Debug.WriteLine("\tAdding flag: {0} value: 0x{1:x4} LoggingFlags=0x{2:x4}", cb.Text, value, (int)logflags);
205 //}
206
207 //LoggingettingsSubscriber.SetValue("LoggingFlags", (ushort)logflags);
208 //gLog.Debug.WriteLine("Saved Logger flags.");
209 }
210
211 private void RomCheaterConfigDialog_FormClosing(object sender, FormClosingEventArgs e)
212 {
213
214 }
215
216 private void RomCheaterConfigDialog_FormClosed(object sender, FormClosedEventArgs e)
217 {
218 #if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
219 logger.SetLoggingFlags(lFlags);
220 #endif
221 }
222 }
223 }

  ViewVC Help
Powered by ViewVC 1.1.22