1 |
william |
839 |
#define FORCE_DISABLE_PROFILER_LOGLEVEL // when define will forcibly disable the profiler loglevel |
2 |
|
|
using System; |
3 |
william |
707 |
using System.Collections.Generic; |
4 |
|
|
using System.ComponentModel; |
5 |
|
|
using System.Data; |
6 |
|
|
using System.Drawing; |
7 |
|
|
using System.Text; |
8 |
|
|
using System.Windows.Forms; |
9 |
william |
708 |
using RomCheater.Logging; |
10 |
william |
889 |
using RomCheater.Core.Docking; |
11 |
william |
708 |
using WeifenLuo.WinFormsUI.Docking; |
12 |
|
|
using System.IO; |
13 |
william |
712 |
using RomCheater.PluginFramework.Core; |
14 |
william |
889 |
using RomCheater.Interfaces; |
15 |
william |
719 |
using RomCheater.UserSettingsSupport; |
16 |
william |
814 |
using Enterprise.Logging; |
17 |
william |
707 |
|
18 |
|
|
namespace RomCheater.RVAScratchPad |
19 |
|
|
{ |
20 |
|
|
public partial class Form1 : Form |
21 |
|
|
{ |
22 |
william |
755 |
const string DockPanelConfig = "RVAScratchPad-DockPanel.conf"; |
23 |
william |
722 |
private SettingSubscriber SettingsSubscriber = null; |
24 |
william |
731 |
private bool m_bSaveLayout = true; |
25 |
william |
712 |
PluginLoader loader = null; |
26 |
|
|
IConfigPlugin ConfigPlugin = null; |
27 |
|
|
|
28 |
william |
893 |
private FloatingLogWindow m_LogWindow = new FloatingLogWindow(); |
29 |
|
|
private FloatingDataTypeConverter m_typeconverter = new FloatingDataTypeConverter(); |
30 |
|
|
|
31 |
william |
868 |
IUserControlPlugin RVACheatListPlugin = null; |
32 |
william |
893 |
IUserControlPlugin ScratchPadPlugin = null; |
33 |
|
|
IUserControlPlugin EmuMMAPPlugin = null; |
34 |
william |
712 |
|
35 |
william |
839 |
private LogLevel logging_level = LogLevel.kLogLevel_All; |
36 |
william |
731 |
private DeserializeDockContent m_deserializeDockContent; |
37 |
william |
728 |
//private FloatingLogWindow m_LogWindow = new FloatingLogWindow(); |
38 |
|
|
//private FloatingWebBrowser m_wb = new FloatingWebBrowser(); |
39 |
william |
708 |
|
40 |
william |
728 |
//public IWebBrowserProvider WebBrowserProvider |
41 |
|
|
//{ |
42 |
|
|
// get { return new WebBrowserProvider(m_wb); } |
43 |
|
|
//} |
44 |
william |
708 |
#region LogWriterSupport |
45 |
|
|
static LogWriter _LoggerInstance; |
46 |
|
|
static LogWriter LoggerInstance |
47 |
william |
707 |
{ |
48 |
william |
708 |
get { return _LoggerInstance; } |
49 |
|
|
set { _LoggerInstance = value; } |
50 |
|
|
} |
51 |
|
|
#endregion |
52 |
|
|
|
53 |
|
|
public Form1() : this(false) { } |
54 |
|
|
public Form1(bool no_console_redirect) |
55 |
|
|
{ |
56 |
william |
892 |
InitializeComponent(); |
57 |
william |
722 |
SettingsSubscriber = new SettingSubscriber(); |
58 |
|
|
SettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default); |
59 |
william |
839 |
//load_loggerflags(); |
60 |
william |
717 |
SetupDocks(); |
61 |
william |
893 |
LoggerInstance = m_LogWindow.Logwriter; |
62 |
william |
839 |
load_loggerflags(); |
63 |
william |
708 |
load_plugins(); |
64 |
william |
814 |
//if (no_console_redirect) |
65 |
|
|
// LoggerInstance.RedirectConsoleOutput = false; |
66 |
william |
707 |
} |
67 |
william |
708 |
private void load_loggerflags() |
68 |
|
|
{ |
69 |
william |
839 |
bool upgraded_flags = Logging.Properties.Settings.Default.UpgradedLogLevel; |
70 |
|
|
if (!upgraded_flags) |
71 |
|
|
{ |
72 |
|
|
logging_level = new LoggingFlagsConverter(Logging.Properties.Settings.Default.LoggingFlags).ConvertFlags(); |
73 |
|
|
Logging.Properties.Settings.Default.UpgradedLogLevel = true; |
74 |
|
|
Logging.Properties.Settings.Default.gLogLoggingFlags = (uint)logging_level; |
75 |
|
|
Logging.Properties.Settings.Default.Save(); |
76 |
|
|
} |
77 |
|
|
logging_level = (LogLevel)Logging.Properties.Settings.Default.gLogLoggingFlags; |
78 |
william |
708 |
#if FORCE_ALL_LOGGING_FLAGS |
79 |
william |
839 |
logging_level = LogLevel.kLogLevel_All; |
80 |
william |
708 |
#endif |
81 |
william |
839 |
#if FORCE_DISABLE_PROFILER_LOGLEVEL |
82 |
|
|
logging_level = logging_level & ~LogLevel.kLogLevel_Profiler; |
83 |
|
|
logging_level = logging_level & ~LogLevel.kLogLevel_VerboseProfiler; |
84 |
|
|
#endif |
85 |
|
|
gLog.CreateLog(LoggingConstants.AppFullLogPath, true, logging_level, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush), LoggerInstance.Log); |
86 |
william |
708 |
} |
87 |
william |
839 |
private void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) |
88 |
|
|
{ |
89 |
|
|
} |
90 |
william |
708 |
private void load_plugins() { load_plugins(false); } |
91 |
|
|
private void load_plugins_silent() { load_plugins(true); } |
92 |
|
|
private void load_plugins(bool silent) |
93 |
|
|
{ |
94 |
william |
712 |
loader = new PluginLoader(); |
95 |
|
|
loader.LoadPlugins(silent); |
96 |
william |
722 |
|
97 |
|
|
var LastConfigPlugin = SettingsSubscriber.GetValue("LastConfigPlugin").ToString(); |
98 |
|
|
if (LastConfigPlugin != null) |
99 |
|
|
{ |
100 |
|
|
ConfigPlugin = loader.GetConfigPlugin(LastConfigPlugin.ToString()); |
101 |
william |
868 |
} |
102 |
william |
722 |
else |
103 |
|
|
{ |
104 |
|
|
var config = PluginCollection.GetPluginByName(PluginNames.GenericConfig); |
105 |
|
|
ConfigPlugin = loader.GetPluginByGuid<IConfigPlugin>(config.ID.ToString()); |
106 |
william |
724 |
} |
107 |
|
|
|
108 |
william |
730 |
// update the Config plugin's reference to the webbrowswer |
109 |
|
|
//ConfigPlugin.WebBrowserProvider = this.WebBrowserProvider; |
110 |
william |
726 |
|
111 |
william |
724 |
SettingsSubscriber.SetValue("LastConfigPlugin", ConfigPlugin.ToString()); |
112 |
|
|
|
113 |
william |
730 |
var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin); |
114 |
william |
868 |
var rvacheatlist = PluginCollection.GetPluginByName(PluginNames.RVACheatListPlugin); |
115 |
william |
893 |
var emumapplugin = PluginCollection.GetPluginByName(PluginNames.EmuMemoryMapPlugin); |
116 |
|
|
|
117 |
william |
730 |
ScratchPadPlugin = loader.GetPluginByGuid<IUserControlPlugin>(scratchpad.ID.ToString()); |
118 |
william |
868 |
RVACheatListPlugin = loader.GetPluginByGuid<IUserControlPlugin>(rvacheatlist.ID.ToString()); |
119 |
william |
726 |
|
120 |
william |
893 |
EmuMMAPPlugin = loader.GetPluginByGuid<IUserControlPlugin>(emumapplugin.ID.ToString()); |
121 |
william |
726 |
// update config of each plugin |
122 |
william |
730 |
ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin); |
123 |
william |
868 |
RVACheatListPlugin.SetAcceptedConfig(ConfigPlugin); |
124 |
william |
893 |
EmuMMAPPlugin.SetAcceptedConfig(ConfigPlugin); |
125 |
william |
708 |
} |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
#region Dock Support |
130 |
william |
731 |
private IDockContent GetContentFromPersistString(string persistString) |
131 |
|
|
{ |
132 |
|
|
//if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; } |
133 |
|
|
//if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; } |
134 |
william |
868 |
if (RVACheatListPlugin != null) { if (persistString == RVACheatListPlugin.IDockContentTypeName) { return RVACheatListPlugin.DockContent; } } |
135 |
william |
731 |
if (ScratchPadPlugin != null) { if (persistString == ScratchPadPlugin.IDockContentTypeName) { return ScratchPadPlugin.DockContent; } } |
136 |
william |
893 |
if (EmuMMAPPlugin != null) { if (persistString == EmuMMAPPlugin.IDockContentTypeName) { return EmuMMAPPlugin.DockContent; } } |
137 |
|
|
if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; } |
138 |
|
|
if (persistString == typeof(FloatingDataTypeConverter).ToString()) { return m_typeconverter; } |
139 |
william |
731 |
return null; |
140 |
|
|
} |
141 |
william |
708 |
public void SetupDocks() |
142 |
|
|
{ |
143 |
william |
893 |
m_LogWindow = new FloatingLogWindow(); |
144 |
|
|
LoggerInstance = m_LogWindow.Logwriter; |
145 |
william |
717 |
|
146 |
william |
893 |
m_typeconverter = new FloatingDataTypeConverter(); |
147 |
william |
717 |
|
148 |
william |
893 |
//if (RVACheatListPlugin != null) |
149 |
|
|
//{ |
150 |
|
|
// RVACheatListPlugin.DockHandler.CloseButton = false; |
151 |
|
|
// RVACheatListPlugin.DockHandler.CloseButtonVisible = false; |
152 |
|
|
// RVACheatListPlugin.DockHandler.AllowEndUserDocking = false; |
153 |
|
|
//} |
154 |
|
|
//if (ScratchPadPlugin != null) |
155 |
|
|
//{ |
156 |
|
|
// ScratchPadPlugin.DockHandler.CloseButton = false; |
157 |
|
|
// ScratchPadPlugin.DockHandler.CloseButtonVisible = false; |
158 |
|
|
// ScratchPadPlugin.DockHandler.AllowEndUserDocking = false; |
159 |
|
|
//} |
160 |
|
|
//if (EmuMMAPPlugin != null) |
161 |
|
|
//{ |
162 |
|
|
// EmuMMAPPlugin.DockHandler.CloseButton = false; |
163 |
|
|
// EmuMMAPPlugin.DockHandler.CloseButtonVisible = false; |
164 |
|
|
// EmuMMAPPlugin.DockHandler.AllowEndUserDocking = false; |
165 |
|
|
//} |
166 |
william |
731 |
m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString); |
167 |
william |
708 |
} |
168 |
|
|
#region SetupDockWindowHandler support |
169 |
|
|
public void SetupDockWindowHandler() |
170 |
|
|
{ |
171 |
william |
728 |
//SetupLogWindowHandler(); |
172 |
|
|
//SetupWebBrowserWindowHandler(); |
173 |
william |
716 |
SetupPluginWindowHandlers(); |
174 |
william |
708 |
} |
175 |
william |
716 |
private void SetupPluginWindowHandlers() |
176 |
|
|
{ |
177 |
william |
893 |
if (m_LogWindow != null) |
178 |
|
|
{ |
179 |
|
|
//m_LogWindow.DockHandler.CloseButton = false; |
180 |
|
|
//m_LogWindow.DockHandler.CloseButtonVisible = false; |
181 |
|
|
//m_LogWindow.DockHandler.AllowEndUserDocking = false; |
182 |
|
|
m_LogWindow.Icon = Core.Properties.Resources.romcheater_icon; |
183 |
william |
905 |
//m_LogWindow.Activate(); |
184 |
william |
893 |
} |
185 |
|
|
if (m_typeconverter != null) |
186 |
|
|
{ |
187 |
|
|
//m_typeconverter.DockHandler.CloseButton = false; |
188 |
|
|
//m_typeconverter.DockHandler.CloseButtonVisible = false; |
189 |
|
|
//m_typeconverter.DockHandler.AllowEndUserDocking = false; |
190 |
|
|
m_typeconverter.Icon = Core.Properties.Resources.romcheater_icon; |
191 |
william |
905 |
//m_typeconverter.Activate(); |
192 |
william |
893 |
} |
193 |
william |
868 |
if (RVACheatListPlugin != null) |
194 |
william |
717 |
{ |
195 |
william |
893 |
//RVACheatListPlugin.DockHandler.CloseButton = false; |
196 |
|
|
//RVACheatListPlugin.DockHandler.CloseButtonVisible = false; |
197 |
|
|
//RVACheatListPlugin.DockHandler.AllowEndUserDocking = false; |
198 |
william |
892 |
RVACheatListPlugin.SetIcon(Core.Properties.Resources.romcheater_icon); |
199 |
william |
905 |
//RVACheatListPlugin.Activate(); |
200 |
william |
717 |
} |
201 |
william |
893 |
|
202 |
|
|
if (EmuMMAPPlugin != null) |
203 |
|
|
{ |
204 |
|
|
//EmuMMAPPlugin.DockHandler.CloseButton = false; |
205 |
|
|
//EmuMMAPPlugin.DockHandler.CloseButtonVisible = false; |
206 |
|
|
//EmuMMAPPlugin.DockHandler.AllowEndUserDocking = false; |
207 |
|
|
EmuMMAPPlugin.SetIcon(Core.Properties.Resources.romcheater_icon); |
208 |
william |
905 |
//EmuMMAPPlugin.Activate(); |
209 |
william |
893 |
} |
210 |
|
|
|
211 |
william |
730 |
if (ScratchPadPlugin != null) |
212 |
|
|
{ |
213 |
william |
893 |
//ScratchPadPlugin.DockHandler.CloseButton = false; |
214 |
|
|
//ScratchPadPlugin.DockHandler.CloseButtonVisible = false; |
215 |
|
|
//ScratchPadPlugin.DockHandler.AllowEndUserDocking = false; |
216 |
william |
892 |
ScratchPadPlugin.SetIcon(Core.Properties.Resources.romcheater_icon); |
217 |
william |
905 |
//ScratchPadPlugin.Activate(); |
218 |
william |
730 |
} |
219 |
william |
716 |
} |
220 |
william |
728 |
//private void SetupLogWindowHandler() |
221 |
|
|
//{ |
222 |
|
|
// //if (m_LogWindow == null) return; |
223 |
|
|
// ////m_LogWindow.Shown += new EventHandler(AddDockToWindowList); |
224 |
|
|
// ////m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList); |
225 |
|
|
// //m_LogWindow.Activate(); |
226 |
|
|
//} |
227 |
|
|
//private void SetupWebBrowserWindowHandler() |
228 |
|
|
//{ |
229 |
|
|
// //if (m_wb == null) return; |
230 |
|
|
// ////m_wb.Shown += new EventHandler(AddDockToWindowList); |
231 |
|
|
// ////m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList); |
232 |
|
|
// //m_wb.Activate(); |
233 |
|
|
//} |
234 |
william |
708 |
#endregion |
235 |
|
|
public void ShowDocks() |
236 |
|
|
{ |
237 |
william |
893 |
ShowLogWindow(); |
238 |
|
|
|
239 |
william |
716 |
ShowPluginWindows(); |
240 |
|
|
SetupPluginWindowHandlers(); |
241 |
william |
893 |
ShowDataTypeConverter(); |
242 |
william |
722 |
|
243 |
william |
893 |
if (ScratchPadPlugin != null) |
244 |
|
|
ScratchPadPlugin.Activate(); |
245 |
william |
708 |
} |
246 |
|
|
public void ShowLogWindow() |
247 |
|
|
{ |
248 |
william |
893 |
if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); } |
249 |
|
|
LoggerInstance = m_LogWindow.Logwriter; |
250 |
|
|
//LoggerInstance.CreateNewLog(false); |
251 |
|
|
m_LogWindow.Show(dockPanel, DockState.DockBottom); |
252 |
william |
708 |
} |
253 |
william |
893 |
public void ShowDataTypeConverter() |
254 |
william |
708 |
{ |
255 |
william |
893 |
if (m_typeconverter == null || m_typeconverter.IsDisposed) { m_typeconverter = new FloatingDataTypeConverter(); } |
256 |
|
|
m_typeconverter.Show(dockPanel, DockState.DockRightAutoHide); |
257 |
william |
708 |
} |
258 |
william |
893 |
|
259 |
william |
716 |
public void ShowPluginWindows() |
260 |
|
|
{ |
261 |
william |
868 |
if (RVACheatListPlugin != null) |
262 |
william |
727 |
{ |
263 |
|
|
// RVA Calc |
264 |
william |
893 |
//RVACheatListPlugin.DockHandler.CloseButton = false; |
265 |
|
|
//RVACheatListPlugin.DockHandler.CloseButtonVisible = false; |
266 |
|
|
//RVACheatListPlugin.DockHandler.AllowEndUserDocking = false; |
267 |
william |
868 |
RVACheatListPlugin.Show(dockPanel, DockState.DockLeft); |
268 |
william |
727 |
} |
269 |
william |
730 |
if (ScratchPadPlugin != null) |
270 |
|
|
{ |
271 |
|
|
// ScratchPad |
272 |
william |
893 |
//ScratchPadPlugin.DockHandler.CloseButton = false; |
273 |
|
|
//ScratchPadPlugin.DockHandler.CloseButtonVisible = false; |
274 |
|
|
//ScratchPadPlugin.DockHandler.AllowEndUserDocking = false; |
275 |
william |
732 |
ScratchPadPlugin.Show(dockPanel, DockState.Document); |
276 |
william |
730 |
} |
277 |
william |
893 |
if (EmuMMAPPlugin != null) |
278 |
|
|
{ |
279 |
|
|
// ScratchPad |
280 |
|
|
//EmuMMAPPlugin.DockHandler.CloseButton = false; |
281 |
|
|
//EmuMMAPPlugin.DockHandler.CloseButtonVisible = false; |
282 |
|
|
//EmuMMAPPlugin.DockHandler.AllowEndUserDocking = false; |
283 |
|
|
EmuMMAPPlugin.Show(dockPanel, DockState.DockRightAutoHide); |
284 |
|
|
} |
285 |
william |
716 |
} |
286 |
william |
708 |
#endregion |
287 |
|
|
|
288 |
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e) |
289 |
|
|
{ |
290 |
william |
722 |
SettingsSubscriber.SaveSettings(); |
291 |
william |
755 |
string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig); |
292 |
william |
731 |
if (m_bSaveLayout) |
293 |
|
|
dockPanel.SaveAsXml(configFile); |
294 |
|
|
else if (File.Exists(configFile)) |
295 |
|
|
File.Delete(configFile); |
296 |
william |
708 |
// notify any docked windows of formclosing |
297 |
|
|
foreach (var t in this.dockPanel.Contents) |
298 |
|
|
{ |
299 |
|
|
t.OnDeactivate<FormClosingEventArgs>(e); |
300 |
|
|
} |
301 |
|
|
} |
302 |
|
|
|
303 |
|
|
private void Form1_Shown(object sender, EventArgs e) |
304 |
|
|
{ |
305 |
william |
853 |
dockPanel.SuspendLayout(true); |
306 |
william |
728 |
////ShowDocks(); |
307 |
william |
755 |
string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig); |
308 |
william |
731 |
if (File.Exists(configFile)) |
309 |
|
|
{ |
310 |
|
|
try |
311 |
|
|
{ |
312 |
|
|
dockPanel.LoadFromXml(configFile, m_deserializeDockContent); |
313 |
|
|
SetupDockWindowHandler(); |
314 |
|
|
} |
315 |
|
|
catch (Exception) |
316 |
|
|
{ |
317 |
william |
853 |
//this.Controls.Remove(dockPanel); |
318 |
|
|
//dockPanel = new DockPanel(); |
319 |
|
|
//dockPanel.Dock = DockStyle.Fill; |
320 |
|
|
//dockPanel.DocumentStyle = DocumentStyle.DockingWindow; |
321 |
|
|
//this.Controls.Add(dockPanel); |
322 |
william |
731 |
ShowDocks(); |
323 |
|
|
} |
324 |
|
|
} |
325 |
|
|
else |
326 |
|
|
{ |
327 |
|
|
ShowDocks(); |
328 |
|
|
} |
329 |
william |
708 |
|
330 |
william |
905 |
if (ScratchPadPlugin != null) |
331 |
|
|
ScratchPadPlugin.Activate(); |
332 |
william |
853 |
dockPanel.ResumeLayout(true, true); |
333 |
william |
708 |
} |
334 |
william |
712 |
|
335 |
|
|
private void mnuItemExit_Click(object sender, EventArgs e) |
336 |
|
|
{ |
337 |
|
|
this.Close(); |
338 |
|
|
} |
339 |
william |
719 |
|
340 |
william |
725 |
private void Form1_Load(object sender, EventArgs e) { } |
341 |
william |
707 |
} |
342 |
|
|
} |