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 |
this.Icon = Core.Properties.Resources.romcheater_icon; |
46 |
//lFlags = logger.GetLoggingFlags(); |
47 |
//ushort flags = lFlags.Value; |
48 |
//if (lFlags.HasFlag(loggerflags.VERBOSE_DEBUG)) |
49 |
//{ |
50 |
// flags = lFlags.Value; |
51 |
// flags = (ushort)(lFlags.Value & ~loggerflags.VERBOSE_DEBUG.Value); |
52 |
// logger.SetLoggingFlags(flags); |
53 |
//} |
54 |
MainSettingsSubscriber = new SettingSubscriber(); |
55 |
LoggingettingsSubscriber = new SettingSubscriber(); |
56 |
MainSettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default); |
57 |
LoggingettingsSubscriber.AddSubscriber(this, RomCheater.Logging.Properties.Settings.Default); |
58 |
} |
59 |
public RomCheaterConfigDialog(PluginLoader loader) |
60 |
: this() |
61 |
{ |
62 |
this.loader = loader; |
63 |
} |
64 |
private void RomCheaterConfigDialog_Load(object sender, EventArgs e) |
65 |
{ |
66 |
gLog.Info.WriteLine("Loading user settings..."); |
67 |
load_loggerflags(); |
68 |
setup_plugin_entries(); |
69 |
gLog.Info.WriteLine("Loaded user settings."); |
70 |
} |
71 |
|
72 |
private void setup_plugin_entries() |
73 |
{ |
74 |
foreach (IConfigPlugin c in loader.LoadedConfigPlugins) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); } |
75 |
foreach (IInputPlugin c in loader.LoadedInputPlugins) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); } |
76 |
foreach (IWindowPlugin c in loader.LoadedWindowPlugins) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); } |
77 |
if (loader.LoadedConfigPlugins.Count == 0) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); } |
78 |
if (loader.LoadedInputPlugins.Count == 0) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); } |
79 |
if (loader.LoadedWindowPlugins.Count == 0) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); } |
80 |
|
81 |
comboConfigPlugins.SelectedIndex = 0; |
82 |
comboInputPlugins.SelectedIndex = 0; |
83 |
comboWindowPlugins.SelectedIndex = 0; |
84 |
|
85 |
// select each plugin base on the last plugin |
86 |
foreach (string item in comboConfigPlugins.Items) |
87 |
{ |
88 |
if (item == RomCheater.Properties.Settings.Default.LastConfigPlugin) |
89 |
{ |
90 |
gLog.Verbose.Debug.WriteLine(" loading LastConfigPlugin: {0}", MainSettingsSubscriber.GetValue("LastConfigPlugin")); |
91 |
comboConfigPlugins.SelectedIndex = comboConfigPlugins.Items.IndexOf(item); |
92 |
break; |
93 |
} |
94 |
} |
95 |
foreach (string item in comboInputPlugins.Items) |
96 |
{ |
97 |
if (item == RomCheater.Properties.Settings.Default.LastInputPlugin) |
98 |
{ |
99 |
gLog.Verbose.Debug.WriteLine(" loading LastInputPlugin: {0}", MainSettingsSubscriber.GetValue("LastInputPlugin")); |
100 |
comboInputPlugins.SelectedIndex = comboInputPlugins.Items.IndexOf(item); |
101 |
break; |
102 |
} |
103 |
} |
104 |
foreach (string item in comboWindowPlugins.Items) |
105 |
{ |
106 |
if (item == RomCheater.Properties.Settings.Default.LastWindowPlugin) |
107 |
{ |
108 |
gLog.Verbose.Debug.WriteLine(" loading LastWindowPlugin: {0}", MainSettingsSubscriber.GetValue("LastWindowPlugin")); |
109 |
comboWindowPlugins.SelectedIndex = comboWindowPlugins.Items.IndexOf(item); |
110 |
break; |
111 |
} |
112 |
} |
113 |
|
114 |
} |
115 |
|
116 |
private void load_loggerflags() |
117 |
{ |
118 |
gLog.Info.WriteLine(" Loading logger flags..."); |
119 |
|
120 |
bool upgraded_flags = Convert.ToBoolean(LoggingettingsSubscriber.GetValue("UpgradedLogLevel")); |
121 |
object o_flags = null; |
122 |
if (!upgraded_flags) |
123 |
{ |
124 |
o_flags = new LoggingFlagsConverter(Logging.Properties.Settings.Default.LoggingFlags).ConvertFlags(); |
125 |
LoggingettingsSubscriber.SetValue("UpgradedLogLevel", true); |
126 |
LoggingettingsSubscriber.SetValue("gLogLoggingFlags", Convert.ToUInt32(o_flags)); |
127 |
LoggingettingsSubscriber.SaveSettings(); |
128 |
} |
129 |
o_flags = LoggingettingsSubscriber.GetValue("gLogLoggingFlags"); |
130 |
LogLevel log_level = (LogLevel)o_flags; |
131 |
#if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST |
132 |
gLog.SetLogLevel(log_level & ~LogLevel.kLogLevel_Verbose); |
133 |
#endif |
134 |
foreach (LogLevel t in Enum.GetValues(typeof(LogLevel))) |
135 |
{ |
136 |
if (t == LogLevel.kLogLevel_All || |
137 |
t == LogLevel.kLogLevel_Disable || |
138 |
t == LogLevel.kLogLevel_None || |
139 |
t == LogLevel.kLogLevel_All_NoProgress || |
140 |
t == LogLevel.kLogLevel_All_NoProfiler || |
141 |
t == LogLevel.kLogLevel_All_NoProfilerOrProgress || |
142 |
t == LogLevel.kLogLevel_Default || |
143 |
t == LogLevel.kLogLevel_Verbose) |
144 |
{ |
145 |
continue; |
146 |
} |
147 |
CheckBox chkloggerflags = new CheckBox(); |
148 |
chkloggerflags.Font = this.Font; |
149 |
string name = Enum.GetName(typeof(LogLevel), t).Replace("kLogLevel_", ""); |
150 |
LogLevel value = t; |
151 |
chkloggerflags.Name = name; |
152 |
chkloggerflags.Text = name; |
153 |
chkloggerflags.Tag = value; |
154 |
Graphics g = chkloggerflags.CreateGraphics(); |
155 |
Size size = g.MeasureString(chkloggerflags.Text, chkloggerflags.Font).ToSize(); |
156 |
chkloggerflags.Width = size.Width + 25; |
157 |
grpLoggingFlags_flow.Controls.Add(chkloggerflags); |
158 |
if (log_level.HasFlag(t)) |
159 |
{ |
160 |
chkloggerflags.Checked = true; |
161 |
gLog.Verbose.Debug.WriteLine("\tTurning on logger flag: {0} value: 0x{1:x4}", name, (uint)value); |
162 |
} |
163 |
} |
164 |
//grpLoggingFlags.AutoSize = true; |
165 |
//grpLoggingFlags.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; |
166 |
|
167 |
gLog.Info.WriteLine(" Loaded logger flags."); |
168 |
} |
169 |
private void btnSave_Click(object sender, EventArgs e) |
170 |
{ |
171 |
gLog.Info.WriteLine("Saving user settings..."); |
172 |
SaveSettings(); |
173 |
var o_flags = LoggingettingsSubscriber.GetValue("gLogLoggingFlags"); |
174 |
gLog.SetLogLevel((LogLevel)o_flags); |
175 |
this.Close(); |
176 |
} |
177 |
private void btnCancel_Click(object sender, EventArgs e) |
178 |
{ |
179 |
this.Close(); |
180 |
} |
181 |
private void SaveSettings() |
182 |
{ |
183 |
SaveLoggingFlags(); |
184 |
SaveSelectedPlugins(); |
185 |
MainSettingsSubscriber.SaveSettings(); |
186 |
LoggingettingsSubscriber.SaveSettings(); |
187 |
//RomCheater.Properties.Settings.Default.Save(); |
188 |
//Logging.Properties.Settings.Default.Save(); |
189 |
gLog.Info.WriteLine("Saved user settings."); |
190 |
} |
191 |
private void SaveSelectedPlugins() |
192 |
{ |
193 |
gLog.Verbose.Debug.WriteLine(" Setting LastConfigPlugin to {0}", comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString()); |
194 |
MainSettingsSubscriber.SetValue("LastConfigPlugin",comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString()); |
195 |
|
196 |
gLog.Verbose.Debug.WriteLine(" Setting LastInputPlugin to {0}", comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString()); |
197 |
MainSettingsSubscriber.SetValue("LastInputPlugin", comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString()); |
198 |
|
199 |
gLog.Verbose.Debug.WriteLine(" Setting LastWindowPlugin to {0}", comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString()); |
200 |
MainSettingsSubscriber.SetValue("LastWindowPlugin", comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString()); |
201 |
} |
202 |
private void SaveLoggingFlags() |
203 |
{ |
204 |
gLog.Debug.WriteLine("Saving Logger flags..."); |
205 |
LogLevel logflags = LogLevel.kLogLevel_None; |
206 |
foreach (CheckBox cb in grpLoggingFlags_flow.Controls) |
207 |
{ |
208 |
if (!cb.Checked) continue; |
209 |
uint value = Convert.ToUInt32(cb.Tag); |
210 |
logflags = logflags | (LogLevel)value; |
211 |
gLog.Verbose.Debug.WriteLine("\tAdding flag: {0} value: 0x{1:x8} LoggingFlags=0x{2:x4}", cb.Text, value, (int)logflags); |
212 |
} |
213 |
|
214 |
LoggingettingsSubscriber.SetValue("gLogLoggingFlags", (uint)logflags); |
215 |
gLog.Debug.WriteLine("Saved Logger flags."); |
216 |
} |
217 |
|
218 |
private void RomCheaterConfigDialog_FormClosing(object sender, FormClosingEventArgs e) |
219 |
{ |
220 |
|
221 |
} |
222 |
|
223 |
private void RomCheaterConfigDialog_FormClosed(object sender, FormClosedEventArgs e) |
224 |
{ |
225 |
#if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST |
226 |
logger.SetLoggingFlags(lFlags); |
227 |
#endif |
228 |
} |
229 |
} |
230 |
} |