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