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