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

Annotation of /trunk/RomCheater/RomCheaterConfigDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 722 - (hide annotations) (download)
Tue Jun 18 19:18:05 2013 UTC (8 years, 3 months ago) by william
File size: 10304 byte(s)

1 william 414 #region Logging Defines
2     // include this any class or method that required logging, and comment-out what is not needed
3 william 415
4 william 414 #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 william 270 using System;
16 william 63 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 william 86 using RomCheater.PluginFramework.Core;
25 william 686 using RomCheater.Core;
26 william 722 using RomCheater.UserSettingsSupport;
27 william 63
28 william 686
29 william 63 namespace RomCheater
30     {
31     public partial class RomCheaterConfigDialog : Form
32     {
33 william 270 #if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
34 william 269 private loggerflags lFlags;
35 william 270 #endif
36 william 269
37 william 722 SettingSubscriber MainSettingsSubscriber;
38     SettingSubscriber LoggingettingsSubscriber;
39    
40 william 86 private PluginLoader loader = null;
41 william 63 public RomCheaterConfigDialog()
42     {
43     InitializeComponent();
44 william 270 //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 william 722 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 william 63 }
57 william 270 public RomCheaterConfigDialog(PluginLoader loader)
58     : this()
59 william 86 {
60     this.loader = loader;
61     }
62 william 63 private void RomCheaterConfigDialog_Load(object sender, EventArgs e)
63     {
64 william 64 logger.Info.WriteLine("Loading user settings...");
65     load_loggerflags();
66 william 86 setup_plugin_entries();
67 william 64 logger.Info.WriteLine("Loaded user settings.");
68     }
69 william 86
70     private void setup_plugin_entries()
71     {
72 william 94 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 william 86 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 william 722 logger.VerboseDebug.WriteLine(" loading LastConfigPlugin: {0}", MainSettingsSubscriber.GetValue("LastConfigPlugin"));
89 william 86 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 william 722 logger.VerboseDebug.WriteLine(" loading LastInputPlugin: {0}", MainSettingsSubscriber.GetValue("LastInputPlugin"));
98 william 86 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 william 722 logger.VerboseDebug.WriteLine(" loading LastWindowPlugin: {0}", MainSettingsSubscriber.GetValue("LastWindowPlugin"));
107 william 86 comboWindowPlugins.SelectedIndex = comboWindowPlugins.Items.IndexOf(item);
108     break;
109     }
110     }
111    
112     }
113    
114 william 64 private void load_loggerflags()
115     {
116 william 270 logger.Info.WriteLine(" Loading logger flags...");
117 william 722 object o_flags = LoggingettingsSubscriber.GetValue("LoggingFlags");
118     loggerflags logflags = (ushort)Convert.ChangeType(o_flags, typeof(ushort));
119 william 114 if (logflags != logger.GetLoggingFlags())
120     {
121     logflags = logger.GetLoggingFlags(); // we apparently have forced the logging flags (possible for testing)
122     }
123 william 270 #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 william 692 var logger_flags = loggerflags.GetValues();
134    
135     foreach (loggerflags flags in logger_flags)
136 william 63 {
137     if (flags == loggerflags.ALL ||
138     flags == loggerflags.NONE ||
139     flags == loggerflags.DEFAULT)
140     continue;
141    
142 william 692 string name = flags.Name;
143 william 111 ushort value = (ushort)flags;
144 william 63
145     CheckBox chkloggerflags = new CheckBox();
146 william 99 chkloggerflags.Font = this.Font;
147 william 63 chkloggerflags.Name = name;
148     chkloggerflags.Text = name;
149     chkloggerflags.Tag = value;
150 william 99 Graphics g = chkloggerflags.CreateGraphics();
151    
152     Size size = g.MeasureString(chkloggerflags.Text, chkloggerflags.Font).ToSize();
153     chkloggerflags.Width = size.Width + 25;
154    
155 william 63 grpLoggingFlags_flow.Controls.Add(chkloggerflags);
156 william 266 logger.VerboseDebug.WriteLine("\tAdding logger flag: {0} value: 0x{1:x4}", name, value);
157 william 111 if (logflags.HasFlag(value))
158 william 63 {
159     chkloggerflags.Checked = true;
160 william 266 logger.VerboseDebug.WriteLine("\tTurning on logger flag: {0} value: 0x{1:x4}", name, value);
161 william 63 }
162     }
163 william 112 //grpLoggingFlags.AutoSize = true;
164     //grpLoggingFlags.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
165 william 270 logger.Info.WriteLine(" Loaded logger flags.");
166 william 63 }
167     private void btnSave_Click(object sender, EventArgs e)
168     {
169 william 64 logger.Info.WriteLine("Saving user settings...");
170 william 63 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 william 86 SaveSelectedPlugins();
181 william 722 MainSettingsSubscriber.SaveSettings();
182     LoggingettingsSubscriber.SaveSettings();
183     //RomCheater.Properties.Settings.Default.Save();
184     //Logging.Properties.Settings.Default.Save();
185 william 64 logger.Info.WriteLine("Saved user settings.");
186 william 63 }
187 william 86 private void SaveSelectedPlugins()
188     {
189 william 266 logger.VerboseDebug.WriteLine(" Setting LastConfigPlugin to {0}", comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
190 william 722 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 william 86 }
198 william 63 private void SaveLoggingFlags()
199     {
200 william 64 logger.Debug.WriteLine("Saving Logger flags...");
201 william 114 ushort logflags = loggerflags.NONE;
202 william 63 foreach (CheckBox cb in grpLoggingFlags_flow.Controls)
203     {
204     if (!cb.Checked) continue;
205 william 111 ushort value = Convert.ToUInt16(cb.Tag);
206     logflags = (ushort)(logflags | value);
207 william 266 logger.VerboseDebug.WriteLine("\tAdding flag: {0} value: 0x{1:x4} LoggingFlags=0x{2:x4}", cb.Text, value, (int)logflags);
208 william 63 }
209 william 722
210     LoggingettingsSubscriber.SetValue("LoggingFlags", (ushort)logflags);
211 william 64 logger.Debug.WriteLine("Saved Logger flags.");
212 william 63 }
213 william 269
214     private void RomCheaterConfigDialog_FormClosing(object sender, FormClosingEventArgs e)
215     {
216 william 270
217     }
218    
219     private void RomCheaterConfigDialog_FormClosed(object sender, FormClosedEventArgs e)
220     {
221     #if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
222 william 269 logger.SetLoggingFlags(lFlags);
223 william 270 #endif
224 william 269 }
225 william 63 }
226     }

  ViewVC Help
Powered by ViewVC 1.1.22