ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/RomCheaterConfigDialog.cs
Revision: 89
Committed: Wed May 9 21:00:02 2012 UTC (11 years, 4 months ago) by william
File size: 7326 byte(s)
Log Message:

File Contents

# Content
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 PluginLoader loader = null;
18 public RomCheaterConfigDialog()
19 {
20 InitializeComponent();
21 }
22 public RomCheaterConfigDialog(PluginLoader loader) : this()
23 {
24 this.loader = loader;
25 }
26 private void RomCheaterConfigDialog_Load(object sender, EventArgs e)
27 {
28 logger.Info.WriteLine("Loading user settings...");
29 load_loggerflags();
30 setup_plugin_entries();
31 logger.Info.WriteLine("Loaded user settings.");
32 }
33
34 private void setup_plugin_entries()
35 {
36 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 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 logger.Debug.WriteLine(" loading LastConfigPlugin: {0}", RomCheater.Properties.Settings.Default.LastConfigPlugin);
53 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 logger.Debug.WriteLine(" loading LastInputPlugin: {0}", RomCheater.Properties.Settings.Default.LastInputPlugin);
62 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 logger.Debug.WriteLine(" loading LastWindowPlugin: {0}", RomCheater.Properties.Settings.Default.LastWindowPlugin);
71 comboWindowPlugins.SelectedIndex = comboWindowPlugins.Items.IndexOf(item);
72 break;
73 }
74 }
75
76 }
77
78 private void load_loggerflags()
79 {
80 logger.Debug.WriteLine("Loading logger flags...");
81 loggerflags logflags = (loggerflags)Logging.Properties.Settings.Default.LoggingFlags;
82 foreach (loggerflags flags in Enum.GetValues(typeof(loggerflags)))
83 {
84 if (flags == loggerflags.ALL ||
85 flags == loggerflags.NONE ||
86 flags == loggerflags.DEFAULT)
87 continue;
88
89 string name = flags.ToString();
90 int value = (int)flags;
91
92 CheckBox chkloggerflags = new CheckBox();
93 chkloggerflags.Name = name;
94 chkloggerflags.Text = name;
95 chkloggerflags.Tag = value;
96 grpLoggingFlags_flow.Controls.Add(chkloggerflags);
97 logger.Debug.WriteLine("\tAdding logger flag: {0} value: 0x{1:x4}", name, value);
98
99 if (logflags.HasFlag((loggerflags)value))
100 {
101 chkloggerflags.Checked = true;
102 logger.Debug.WriteLine("\tTurning on logger flag: {0} value: 0x{1:x4}", name, value);
103 }
104 }
105 grpLoggingFlags.AutoSize = true;
106 grpLoggingFlags.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
107 logger.Debug.WriteLine("Loaded logger flags.");
108 }
109 private void btnSave_Click(object sender, EventArgs e)
110 {
111 logger.Info.WriteLine("Saving user settings...");
112 SaveSettings();
113 this.Close();
114 }
115 private void btnCancel_Click(object sender, EventArgs e)
116 {
117 this.Close();
118 }
119 private void SaveSettings()
120 {
121 SaveLoggingFlags();
122 SaveSelectedPlugins();
123 RomCheater.Properties.Settings.Default.Save();
124 Logging.Properties.Settings.Default.Save();
125 logger.Info.WriteLine("Saved user settings.");
126 }
127 private void SaveSelectedPlugins()
128 {
129 logger.Debug.WriteLine(" Setting LastConfigPlugin to {0}", comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
130 RomCheater.Properties.Settings.Default.LastConfigPlugin = comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString();
131 logger.Debug.WriteLine(" Setting LastInputPlugin to {0}", comboInputPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
132 RomCheater.Properties.Settings.Default.LastInputPlugin = comboInputPlugins.Items[comboConfigPlugins.SelectedIndex].ToString();
133 logger.Debug.WriteLine(" Setting LastWindowPlugin to {0}", comboWindowPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
134 RomCheater.Properties.Settings.Default.LastWindowPlugin = comboWindowPlugins.Items[comboConfigPlugins.SelectedIndex].ToString();
135 }
136 private void SaveLoggingFlags()
137 {
138 logger.Debug.WriteLine("Saving Logger flags...");
139 loggerflags logflags = loggerflags.NONE;
140 foreach (CheckBox cb in grpLoggingFlags_flow.Controls)
141 {
142 if (!cb.Checked) continue;
143 int value = Convert.ToInt32(cb.Tag);
144 logflags = logflags | (loggerflags)value;
145 logger.Debug.WriteLine("\tAdding flag: {0} value: 0x{1:x4} LoggingFlags=0x{2:x4}", cb.Text, value, (int)logflags);
146 }
147 Logging.Properties.Settings.Default.LoggingFlags = (int)logflags;
148 logger.Debug.WriteLine("Saved Logger flags.");
149 }
150 }
151 }