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

Annotation of /trunk/RomCheater/RomCheaterConfigDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 270 - (hide annotations) (download)
Sun Jun 3 20:57:44 2012 UTC (9 years, 1 month ago) by william
File size: 9206 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22