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

Contents of /trunk/RomCheater/Main.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations) (download)
Mon May 28 02:20:29 2012 UTC (9 years, 6 months ago) by william
File size: 9009 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22