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

Contents of /trunk/RomCheater/RomCheaterConfigDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 692 - (show annotations) (download)
Mon Jun 17 10:29:30 2013 UTC (7 years, 5 months ago) by william
File size: 9633 byte(s)
+ re-enable configured logging flags, removed conditional flags

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

  ViewVC Help
Powered by ViewVC 1.1.22