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