ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Main.cs
Revision: 152
Committed: Mon May 28 02:01:34 2012 UTC (10 years, 1 month ago) by william
File size: 8691 byte(s)
Log Message:
+ add support to save dock layout

File Contents

# Content
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 Proc = new Process();
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 Proc = Process.GetProcessById(e.ProcessID);
52 }
53
54 #region Dock Support
55 private IDockContent GetContentFromPersistString(string persistString)
56 {
57 if (persistString == typeof(FloatingLogWindow).ToString())
58 {
59 return m_LogWindow;
60 }
61 //if (persistString == typeof(FloatingAboutBox).ToString())
62 //{
63 // return m_AboutBox;
64 //}
65 if (persistString == typeof(FloatingRamDumperDialog).ToString())
66 {
67 return m_RamDump;
68 }
69 if (persistString == typeof(PIDSelector).ToString())
70 {
71 return m_PIDSelector;
72 }
73 else
74 {
75 // not sure if this is appropriate
76 return null;
77 }
78 }
79 public void SetupDocks()
80 {
81 m_LogWindow = new FloatingLogWindow();
82 m_AboutBox = new FloatingAboutBox();
83 m_RamDump = new FloatingRamDumperDialog();
84 m_PIDSelector = new PIDSelector();
85 m_PIDSelector.OnSelectedProcessChanged += new EventHandler<ProcessChangedEventArgs>(OnProcessChanged);
86 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
87 }
88 public void ShowDocks()
89 {
90 ShowLogWindow();
91 //ShowAboutBox();
92 ShowRamDump();
93 ShowPidSelector();
94 }
95 public void ShowLogWindow()
96 {
97 m_LogWindow.Show(dockPanel, DockState.DockBottom);
98 }
99 public void ShowAboutBox()
100 {
101 m_AboutBox.ShowDialog();
102 }
103 public void ShowRamDump()
104 {
105 m_RamDump.Show(dockPanel);
106 }
107 public void ShowPidSelector()
108 {
109 //List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
110 m_PIDSelector = new PIDSelector(ConfigPlugin);
111 m_PIDSelector.OnSelectedProcessChanged += new EventHandler<ProcessChangedEventArgs>(OnProcessChanged);
112 m_PIDSelector.Show(dockPanel);
113 }
114 #endregion
115
116
117 public Main() : this(false) { }
118 public Main(bool no_console_redirect)
119 {
120 InitializeComponent();
121 load_loggerflags();
122 SetupDocks();
123 LoggerInstance = m_LogWindow.Logwriter;
124 LoggerInstance.CreateNewLog(false);
125 logger.ForceLog.Info.WriteLine("LoggingFlags = 0x{0:x4} ({1})", logger.GetLoggingFlags().Value, logger.GetLoggingFlags().Name);
126 load_plugins();
127 if (no_console_redirect)
128 LoggerInstance.RedirectConsoleOutput = false;
129
130 }
131 private void load_loggerflags()
132 {
133 logger.SetLoggingFlags(Logging.Properties.Settings.Default.LoggingFlags);
134 #if FORCE_ALL_LOGGING_FLAGS
135 logger.SetLoggingFlags(loggerflags.ALL);
136 #endif
137 }
138 private void load_plugins()
139 {
140 loader = new PluginLoader();
141 loader.LoadPlugins();
142
143 ConfigPlugin = loader.GetConfigPlugin(RomCheater.Properties.Settings.Default.LastConfigPlugin);
144 if (ConfigPlugin != null)
145 logger.Info.WriteLine("Loaded Config Plugin: {0}", ConfigPlugin.ToString());
146 InputPlugin = loader.GetInputPlugin(RomCheater.Properties.Settings.Default.LastInputPlugin);
147 if (InputPlugin != null)
148 logger.Info.WriteLine("Loaded Input Plugin: {0}", InputPlugin.ToString());
149 WindowPlugin = loader.GetWindowPlugin(RomCheater.Properties.Settings.Default.LastWindowPlugin);
150 if (WindowPlugin != null)
151 logger.Info.WriteLine("Loaded Window Plugin: {0}", WindowPlugin.ToString());
152
153 m_PIDSelector.ConfigPlugin = ConfigPlugin;
154
155 }
156
157 private void mnuItemExit_Click(object sender, EventArgs e)
158 {
159 this.Close();
160 }
161
162 private void btnCopyLogToClipboard_Click(object sender, EventArgs e)
163 {
164
165 }
166
167 private void Main_Load(object sender, EventArgs e)
168 {
169
170 }
171
172 private void mnuItemConfig_Click(object sender, EventArgs e)
173 {
174 RomCheaterConfigDialog dlg = new RomCheaterConfigDialog(loader);
175 dlg.ShowDialog();
176 // reload plugins
177 load_plugins();
178 }
179
180 private void mnuItemOpenProcess_Click(object sender, EventArgs e)
181 {
182 ////List<Process> procs = ConfigPlugin.ValidProcessesForPlugin;
183 //PIDSelector selector = new PIDSelector(ConfigPlugin);
184 //selector.ShowDialog();
185 }
186
187 private void Main_Shown(object sender, EventArgs e)
188 {
189 //dockPanel.SuspendLayout(true);
190 //ShowDocks();
191 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
192 if (File.Exists(configFile))
193 {
194 try
195 {
196 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
197 }
198 catch (Exception ex)
199 {
200 this.Controls.Remove(dockPanel);
201 dockPanel = new DockPanel();
202 dockPanel.Dock = DockStyle.Fill;
203 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
204 this.Controls.Add(dockPanel);
205 ShowDocks();
206 }
207 }
208 else
209 {
210 ShowDocks();
211 }
212
213 //dockPanel.ResumeLayout(true, true);
214 }
215
216 private void mnuItemShowLogWindow_Click(object sender, EventArgs e)
217 {
218 ShowLogWindow();
219 }
220
221 private void mnuItemHelpAbout_Click(object sender, EventArgs e)
222 {
223 ShowAboutBox();
224 }
225
226 private void mnuItemShowRamDumpDialog_Click(object sender, EventArgs e)
227 {
228 ShowRamDump();
229 }
230
231 private void mnuItemShowPIDSelector_Click(object sender, EventArgs e)
232 {
233 ShowPidSelector();
234 }
235
236 private void Main_FormClosing(object sender, FormClosingEventArgs e)
237 {
238 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");
239 if (m_bSaveLayout)
240 dockPanel.SaveAsXml(configFile);
241 else if (File.Exists(configFile))
242 File.Delete(configFile);
243 }
244 }
245 }