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

Contents of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 158 - (show annotations) (download)
Mon May 28 04:29:30 2012 UTC (8 years, 5 months ago) by william
File size: 9316 byte(s)
add debug menu

1 #define FORCE_ALL_LOGGING_FLAGS // when defined will force logging flags to ALL
2 #define SHOW_DEBUG_MENU // when defined will show the debug menu or else it will be hidden
3 using System;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Data;
7 using System.Drawing;
8 using System.Linq;
9 using System.Text;
10 using System.Windows.Forms;
11 using RomCheater.Logging;
12 using RomCheater.Properties;
13 using RomCheater.UserSettingsSupport;
14 using RomCheater.PluginFramework.Core;
15 using System.Diagnostics;
16 using RomCheater.PluginFramework.Interfaces;
17 using WeifenLuo.WinFormsUI.Docking;
18 using RomCheater.Docking;
19 using System.IO;
20
21 namespace RomCheater
22 {
23 public partial class Main : Form
24 {
25 private bool m_bSaveLayout = true;
26 private Process SelectedProcess = null;
27 private DeserializeDockContent m_deserializeDockContent;
28 private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
29 private FloatingAboutBox m_AboutBox = new FloatingAboutBox();
30 private FloatingRamDumperDialog m_RamDump = new FloatingRamDumperDialog();
31 private PIDSelector m_PIDSelector = new PIDSelector();
32 //private bool log_window_expanded = false;
33 //private double log_window_splitter_default_position = 1.4045;
34 PluginLoader loader = null;
35 IConfigPlugin ConfigPlugin = null;
36 IInputPlugin InputPlugin = null;
37 IWindowPlugin WindowPlugin = null;
38 static Main() { SettingSubscriber.AddSubscriber(new Main(), Settings.Default); }
39 private const string t = "RomCheater";
40 #region LogWriterSupport
41 static LogWriter _LoggerInstance;
42 static LogWriter LoggerInstance
43 {
44 get { return _LoggerInstance; }
45 set { _LoggerInstance = value; }
46 }
47 #endregion
48
49
50 private void OnProcessChanged(object sender, ProcessChangedEventArgs e)
51 {
52 SelectedProcess = Process.GetProcessById(e.ProcessID);
53 m_RamDump.AcceptedProcess = SelectedProcess;
54 }
55
56 #region Dock Support
57 private IDockContent GetContentFromPersistString(string persistString)
58 {
59 if (persistString == typeof(FloatingLogWindow).ToString())
60 {
61 return m_LogWindow;
62 }
63 //if (persistString == typeof(FloatingAboutBox).ToString())
64 //{
65 // return m_AboutBox;
66 //}
67 if (persistString == typeof(FloatingRamDumperDialog).ToString())
68 {
69 return m_RamDump;
70 }
71 if (persistString == typeof(PIDSelector).ToString())
72 {
73 return m_PIDSelector;
74 }
75 else
76 {
77 // not sure if this is appropriate
78 return null;
79 }
80 }
81 public void SetupDocks()
82 {
83 m_LogWindow = new FloatingLogWindow();
84 m_AboutBox = new FloatingAboutBox();
85 m_RamDump = new FloatingRamDumperDialog();
86 m_PIDSelector = new PIDSelector();
87 m_PIDSelector.OnSelectedProcessChanged += new EventHandler<ProcessChangedEventArgs>(OnProcessChanged);
88 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
89 }
90 public void ShowDocks()
91 {
92 ShowLogWindow();
93 //ShowAboutBox();
94 ShowRamDump();
95 ShowPidSelector();
96 }
97 public void ShowLogWindow()
98 {
99 m_LogWindow.Show(dockPanel, DockState.DockBottom);
100 }
101 public void ShowAboutBox()
102 {
103 m_AboutBox.ShowDialog();
104 }
105 public void ShowRamDump()
106 {
107 m_RamDump = new FloatingRamDumperDialog(ConfigPlugin);
108 m_RamDump.Show(dockPanel);
109
110 }
111 public void ShowPidSelector()
112 {
113 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
114 m_PIDSelector = new PIDSelector(ConfigPlugin);
115 m_PIDSelector.OnSelectedProcessChanged += new EventHandler<ProcessChangedEventArgs>(OnProcessChanged);
116 m_PIDSelector.Show(dockPanel);
117 }
118 #endregion
119
120
121 public Main() : this(false) { }
122 public Main(bool no_console_redirect)
123 {
124 InitializeComponent();
125 #if SHOW_DEBUG_MENU
126 mnuDebug.Visible = true;
127 #else
128 mnuDebug.Visible = false;
129 #endif
130 load_loggerflags();
131 SetupDocks();
132 LoggerInstance = m_LogWindow.Logwriter;
133 LoggerInstance.CreateNewLog(false);
134 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
135 load_plugins();
136 if (no_console_redirect)
137 LoggerInstance.RedirectConsoleOutput = false;
138
139
140
141 }
142 private void load_loggerflags()
143 {
144 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
145 #if FORCE_ALL_LOGGING_FLAGS
146 logger.SetLoggingFlags(loggerflags.ALL);
147 #endif
148 }
149 private void load_plugins()
150 {
151 loader = new PluginLoader();
152 loader.LoadPlugins();
153
154 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
155 if (ConfigPlugin != null)
156 logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
157 InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
158 if (InputPlugin != null)
159 logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
160 WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
161 if (WindowPlugin != null)
162 logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
163
164 m_PIDSelector.AcceptedPlugin = ConfigPlugin;
165 m_RamDump.AcceptedPlugin = ConfigPlugin;
166 if (this.SelectedProcess != null)
167 m_RamDump.AcceptedProcess = SelectedProcess;
168
169 }
170
171 private void mnuItemExit_Click(object sender, EventArgs e)
172 {
173 this.Close();
174 }
175
176 private void btnCopyLogToClipboard_Click(object sender, EventArgs e)
177 {
178
179 }
180
181 private void Main_Load(object sender, EventArgs e)
182 {
183
184 }
185
186 private void mnuItemConfig_Click(object sender, EventArgs e)
187 {
188 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
189 dlg.ShowDialog();
190 // reload plugins
191 load_plugins();
192 }
193
194 private void mnuItemOpenProcess_Click(object sender, EventArgs e)
195 {
196 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
197 //PIDSelector selector = new PIDSelector(ConfigPlugin);
198 //selector.ShowDialog();
199 }
200
201 private void Main_Shown(object sender, EventArgs e)
202 {
203 //dockPanel.SuspendLayout(true);
204 //ShowDocks();
205 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
206 if (File.Exists(configFile))
207 {
208 try
209 {
210 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
211 }
212 catch (Exception ex)
213 {
214 this.Controls.Remove(dockPanel);
215 dockPanel = new DockPanel();
216 dockPanel.Dock = DockStyle.Fill;
217 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
218 this.Controls.Add(dockPanel);
219 ShowDocks();
220 }
221 }
222 else
223 {
224 ShowDocks();
225 }
226
227 //dockPanel.ResumeLayout(true, true);
228 }
229
230 private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
231 {
232 ShowLogWindow();
233 }
234
235 private void mnuItemHelpAbout_Click(object sender, EventArgs e)
236 {
237 ShowAboutBox();
238 }
239
240 private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
241 {
242 ShowRamDump();
243 }
244
245 private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
246 {
247 ShowPidSelector();
248 }
249
250 private void Main_FormClosing(object sender, FormClosingEventArgs e)
251 {
252 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
253 if (m_bSaveLayout)
254 dockPanel.SaveAsXml(configFile);
255 else if (File.Exists(configFile))
256 File.Delete(configFile);
257 }
258
259 private void mnuTestExeParse_Click(object sender, EventArgs e)
260 {
261
262 }
263 }
264 }

  ViewVC Help
Powered by ViewVC 1.1.22