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

Annotation of /trunk/RomCheater/RomCheaterConfigDialog.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 266 - (hide annotations) (download)
Sun Jun 3 19:51:54 2012 UTC (9 years, 1 month ago) by william
File size: 7838 byte(s)
+ move some logging calls to VERBOSE_DEBUG instead of DEBUG

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

  ViewVC Help
Powered by ViewVC 1.1.22