1 |
#define FORCE_DISABLE_PROFILER_LOGLEVEL // when define will forcibly disable the profiler loglevel |
2 |
using System; |
3 |
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 |
using RomCheater.Logging; |
10 |
using RomCheater.Core.Docking; |
11 |
using WeifenLuo.WinFormsUI.Docking; |
12 |
using System.IO; |
13 |
using RomCheater.PluginFramework.Core; |
14 |
using RomCheater.Interfaces; |
15 |
using RomCheater.UserSettingsSupport; |
16 |
using Enterprise.Logging; |
17 |
|
18 |
namespace RomCheater.RVAScratchPad |
19 |
{ |
20 |
public partial class Form1 : Form |
21 |
{ |
22 |
const string DockPanelConfig = "RVAScratchPad-DockPanel.conf"; |
23 |
private SettingSubscriber SettingsSubscriber = null; |
24 |
private bool m_bSaveLayout = true; |
25 |
PluginLoader loader = null; |
26 |
IConfigPlugin ConfigPlugin = null; |
27 |
|
28 |
private FloatingLogWindow m_LogWindow = new FloatingLogWindow(); |
29 |
private FloatingDataTypeConverter m_typeconverter = new FloatingDataTypeConverter(); |
30 |
|
31 |
IUserControlPlugin RVACheatListPlugin = null; |
32 |
IUserControlPlugin ScratchPadPlugin = null; |
33 |
IUserControlPlugin EmuMMAPPlugin = null; |
34 |
|
35 |
private LogLevel logging_level = LogLevel.kLogLevel_All; |
36 |
private DeserializeDockContent m_deserializeDockContent; |
37 |
//private FloatingLogWindow m_LogWindow = new FloatingLogWindow(); |
38 |
//private FloatingWebBrowser m_wb = new FloatingWebBrowser(); |
39 |
|
40 |
//public IWebBrowserProvider WebBrowserProvider |
41 |
//{ |
42 |
// get { return new WebBrowserProvider(m_wb); } |
43 |
//} |
44 |
#region LogWriterSupport |
45 |
static LogWriter _LoggerInstance; |
46 |
static LogWriter LoggerInstance |
47 |
{ |
48 |
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 |
InitializeComponent(); |
57 |
SettingsSubscriber = new SettingSubscriber(); |
58 |
SettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default); |
59 |
//load_loggerflags(); |
60 |
SetupDocks(); |
61 |
LoggerInstance = m_LogWindow.Logwriter; |
62 |
load_loggerflags(); |
63 |
load_plugins(); |
64 |
//if (no_console_redirect) |
65 |
// LoggerInstance.RedirectConsoleOutput = false; |
66 |
} |
67 |
private void load_loggerflags() |
68 |
{ |
69 |
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 |
#if FORCE_ALL_LOGGING_FLAGS |
79 |
logging_level = LogLevel.kLogLevel_All; |
80 |
#endif |
81 |
#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 |
} |
87 |
private void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) |
88 |
{ |
89 |
} |
90 |
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 |
loader = new PluginLoader(); |
95 |
loader.LoadPlugins(silent); |
96 |
|
97 |
var LastConfigPlugin = SettingsSubscriber.GetValue("LastConfigPlugin").ToString(); |
98 |
if (LastConfigPlugin != null) |
99 |
{ |
100 |
ConfigPlugin = loader.GetConfigPlugin(LastConfigPlugin.ToString()); |
101 |
} |
102 |
else |
103 |
{ |
104 |
var config = PluginCollection.GetPluginByName(PluginNames.GenericConfig); |
105 |
ConfigPlugin = loader.GetPluginByGuid<IConfigPlugin>(config.ID.ToString()); |
106 |
} |
107 |
|
108 |
// update the Config plugin's reference to the webbrowswer |
109 |
//ConfigPlugin.WebBrowserProvider = this.WebBrowserProvider; |
110 |
|
111 |
SettingsSubscriber.SetValue("LastConfigPlugin", ConfigPlugin.ToString()); |
112 |
|
113 |
var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin); |
114 |
var rvacheatlist = PluginCollection.GetPluginByName(PluginNames.RVACheatListPlugin); |
115 |
var emumapplugin = PluginCollection.GetPluginByName(PluginNames.EmuMemoryMapPlugin); |
116 |
|
117 |
ScratchPadPlugin = loader.GetPluginByGuid<IUserControlPlugin>(scratchpad.ID.ToString()); |
118 |
RVACheatListPlugin = loader.GetPluginByGuid<IUserControlPlugin>(rvacheatlist.ID.ToString()); |
119 |
|
120 |
EmuMMAPPlugin = loader.GetPluginByGuid<IUserControlPlugin>(emumapplugin.ID.ToString()); |
121 |
// update config of each plugin |
122 |
ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin); |
123 |
RVACheatListPlugin.SetAcceptedConfig(ConfigPlugin); |
124 |
EmuMMAPPlugin.SetAcceptedConfig(ConfigPlugin); |
125 |
} |
126 |
|
127 |
|
128 |
|
129 |
#region Dock Support |
130 |
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 |
if (RVACheatListPlugin != null) { if (persistString == RVACheatListPlugin.IDockContentTypeName) { return RVACheatListPlugin.DockContent; } } |
135 |
if (ScratchPadPlugin != null) { if (persistString == ScratchPadPlugin.IDockContentTypeName) { return ScratchPadPlugin.DockContent; } } |
136 |
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 |
return null; |
140 |
} |
141 |
public void SetupDocks() |
142 |
{ |
143 |
m_LogWindow = new FloatingLogWindow(); |
144 |
LoggerInstance = m_LogWindow.Logwriter; |
145 |
|
146 |
m_typeconverter = new FloatingDataTypeConverter(); |
147 |
|
148 |
//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 |
m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString); |
167 |
} |
168 |
#region SetupDockWindowHandler support |
169 |
public void SetupDockWindowHandler() |
170 |
{ |
171 |
//SetupLogWindowHandler(); |
172 |
//SetupWebBrowserWindowHandler(); |
173 |
SetupPluginWindowHandlers(); |
174 |
} |
175 |
private void SetupPluginWindowHandlers() |
176 |
{ |
177 |
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 |
m_LogWindow.Activate(); |
184 |
} |
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 |
m_typeconverter.Activate(); |
192 |
} |
193 |
if (RVACheatListPlugin != null) |
194 |
{ |
195 |
//RVACheatListPlugin.DockHandler.CloseButton = false; |
196 |
//RVACheatListPlugin.DockHandler.CloseButtonVisible = false; |
197 |
//RVACheatListPlugin.DockHandler.AllowEndUserDocking = false; |
198 |
RVACheatListPlugin.SetIcon(Core.Properties.Resources.romcheater_icon); |
199 |
RVACheatListPlugin.Activate(); |
200 |
} |
201 |
|
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 |
EmuMMAPPlugin.Activate(); |
209 |
} |
210 |
|
211 |
if (ScratchPadPlugin != null) |
212 |
{ |
213 |
//ScratchPadPlugin.DockHandler.CloseButton = false; |
214 |
//ScratchPadPlugin.DockHandler.CloseButtonVisible = false; |
215 |
//ScratchPadPlugin.DockHandler.AllowEndUserDocking = false; |
216 |
ScratchPadPlugin.SetIcon(Core.Properties.Resources.romcheater_icon); |
217 |
ScratchPadPlugin.Activate(); |
218 |
} |
219 |
} |
220 |
//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 |
#endregion |
235 |
public void ShowDocks() |
236 |
{ |
237 |
ShowLogWindow(); |
238 |
|
239 |
ShowPluginWindows(); |
240 |
SetupPluginWindowHandlers(); |
241 |
ShowDataTypeConverter(); |
242 |
|
243 |
if (ScratchPadPlugin != null) |
244 |
ScratchPadPlugin.Activate(); |
245 |
} |
246 |
public void ShowLogWindow() |
247 |
{ |
248 |
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 |
} |
253 |
public void ShowDataTypeConverter() |
254 |
{ |
255 |
if (m_typeconverter == null || m_typeconverter.IsDisposed) { m_typeconverter = new FloatingDataTypeConverter(); } |
256 |
m_typeconverter.Show(dockPanel, DockState.DockRightAutoHide); |
257 |
} |
258 |
|
259 |
public void ShowPluginWindows() |
260 |
{ |
261 |
if (RVACheatListPlugin != null) |
262 |
{ |
263 |
// RVA Calc |
264 |
//RVACheatListPlugin.DockHandler.CloseButton = false; |
265 |
//RVACheatListPlugin.DockHandler.CloseButtonVisible = false; |
266 |
//RVACheatListPlugin.DockHandler.AllowEndUserDocking = false; |
267 |
RVACheatListPlugin.Show(dockPanel, DockState.DockLeft); |
268 |
} |
269 |
if (ScratchPadPlugin != null) |
270 |
{ |
271 |
// ScratchPad |
272 |
//ScratchPadPlugin.DockHandler.CloseButton = false; |
273 |
//ScratchPadPlugin.DockHandler.CloseButtonVisible = false; |
274 |
//ScratchPadPlugin.DockHandler.AllowEndUserDocking = false; |
275 |
ScratchPadPlugin.Show(dockPanel, DockState.Document); |
276 |
} |
277 |
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 |
} |
286 |
#endregion |
287 |
|
288 |
private void Form1_FormClosing(object sender, FormClosingEventArgs e) |
289 |
{ |
290 |
SettingsSubscriber.SaveSettings(); |
291 |
string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig); |
292 |
if (m_bSaveLayout) |
293 |
dockPanel.SaveAsXml(configFile); |
294 |
else if (File.Exists(configFile)) |
295 |
File.Delete(configFile); |
296 |
// 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 |
dockPanel.SuspendLayout(true); |
306 |
////ShowDocks(); |
307 |
string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig); |
308 |
if (File.Exists(configFile)) |
309 |
{ |
310 |
try |
311 |
{ |
312 |
dockPanel.LoadFromXml(configFile, m_deserializeDockContent); |
313 |
SetupDockWindowHandler(); |
314 |
} |
315 |
catch (Exception) |
316 |
{ |
317 |
//this.Controls.Remove(dockPanel); |
318 |
//dockPanel = new DockPanel(); |
319 |
//dockPanel.Dock = DockStyle.Fill; |
320 |
//dockPanel.DocumentStyle = DocumentStyle.DockingWindow; |
321 |
//this.Controls.Add(dockPanel); |
322 |
ShowDocks(); |
323 |
} |
324 |
} |
325 |
else |
326 |
{ |
327 |
ShowDocks(); |
328 |
} |
329 |
|
330 |
if (RVACheatListPlugin != null) |
331 |
RVACheatListPlugin.Activate(); |
332 |
dockPanel.ResumeLayout(true, true); |
333 |
} |
334 |
|
335 |
private void mnuItemExit_Click(object sender, EventArgs e) |
336 |
{ |
337 |
this.Close(); |
338 |
} |
339 |
|
340 |
private void Form1_Load(object sender, EventArgs e) { } |
341 |
} |
342 |
} |