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

Contents of /trunk/RomCheater/RomCheaterConfigDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22