/[RomCheater]/trunk/RomCheater.RVAScratchPad/Form1.cs
ViewVC logotype

Contents of /trunk/RomCheater.RVAScratchPad/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 839 - (show annotations) (download)
Tue Sep 16 01:06:04 2014 UTC (6 years ago) by william
File size: 12631 byte(s)
+ fix a crash in RomCheater.RVAScratchPad

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.Docking;
11 using WeifenLuo.WinFormsUI.Docking;
12 using System.IO;
13 using RomCheater.PluginFramework.Core;
14 using RomCheater.Core;
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 IUserControlPlugin RVACalcPlugin = null;
29 IUserControlPlugin ScratchPadPlugin = null;
30
31 private LogLevel logging_level = LogLevel.kLogLevel_All;
32 private DeserializeDockContent m_deserializeDockContent;
33 //private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
34 //private FloatingWebBrowser m_wb = new FloatingWebBrowser();
35
36 //public IWebBrowserProvider WebBrowserProvider
37 //{
38 // get { return new WebBrowserProvider(m_wb); }
39 //}
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 public Form1() : this(false) { }
50 public Form1(bool no_console_redirect)
51 {
52 InitializeComponent();
53 this.Icon = Core.Properties.Resources.romcheater_icon;
54 SettingsSubscriber = new SettingSubscriber();
55 SettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default);
56 //load_loggerflags();
57 SetupDocks();
58 //LoggerInstance = m_LogWindow.Logwriter;
59 LoggerInstance = new LogWriter();
60 load_loggerflags();
61 load_plugins();
62 //if (no_console_redirect)
63 // LoggerInstance.RedirectConsoleOutput = false;
64 }
65 private void load_loggerflags()
66 {
67 bool upgraded_flags = Logging.Properties.Settings.Default.UpgradedLogLevel;
68 if (!upgraded_flags)
69 {
70 logging_level = new LoggingFlagsConverter(Logging.Properties.Settings.Default.LoggingFlags).ConvertFlags();
71 Logging.Properties.Settings.Default.UpgradedLogLevel = true;
72 Logging.Properties.Settings.Default.gLogLoggingFlags = (uint)logging_level;
73 Logging.Properties.Settings.Default.Save();
74 }
75 logging_level = (LogLevel)Logging.Properties.Settings.Default.gLogLoggingFlags;
76 #if FORCE_ALL_LOGGING_FLAGS
77 logging_level = LogLevel.kLogLevel_All;
78 #endif
79 #if FORCE_DISABLE_PROFILER_LOGLEVEL
80 logging_level = logging_level & ~LogLevel.kLogLevel_Profiler;
81 logging_level = logging_level & ~LogLevel.kLogLevel_VerboseProfiler;
82 #endif
83 gLog.CreateLog(LoggingConstants.AppFullLogPath, true, logging_level, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush), LoggerInstance.Log);
84 }
85 private void Log_OnFlush(object sender, LoggerOnFlushEventArgs e)
86 {
87 }
88 private void load_plugins() { load_plugins(false); }
89 private void load_plugins_silent() { load_plugins(true); }
90 private void load_plugins(bool silent)
91 {
92 loader = new PluginLoader();
93 loader.LoadPlugins(silent);
94
95 var LastConfigPlugin = SettingsSubscriber.GetValue("LastConfigPlugin").ToString();
96 if (LastConfigPlugin != null)
97 {
98 ConfigPlugin = loader.GetConfigPlugin(LastConfigPlugin.ToString());
99 }
100 else
101 {
102 var config = PluginCollection.GetPluginByName(PluginNames.GenericConfig);
103 ConfigPlugin = loader.GetPluginByGuid<IConfigPlugin>(config.ID.ToString());
104 }
105
106 // update the Config plugin's reference to the webbrowswer
107 //ConfigPlugin.WebBrowserProvider = this.WebBrowserProvider;
108
109 SettingsSubscriber.SetValue("LastConfigPlugin", ConfigPlugin.ToString());
110
111 var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
112 var rvacalc = PluginCollection.GetPluginByName(PluginNames.RVACalculatorPlugin);
113 ScratchPadPlugin = loader.GetPluginByGuid<IUserControlPlugin>(scratchpad.ID.ToString());
114 RVACalcPlugin = loader.GetPluginByGuid<IUserControlPlugin>(rvacalc.ID.ToString());
115
116 // update config of each plugin
117 ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin);
118 RVACalcPlugin.SetAcceptedConfig(ConfigPlugin);
119 }
120
121
122
123 #region Dock Support
124 private IDockContent GetContentFromPersistString(string persistString)
125 {
126 //if (persistString == typeof(FloatingLogWindow).ToString()) { return m_LogWindow; }
127 //if (persistString == typeof(FloatingWebBrowser).ToString()) { return m_wb; }
128 if (RVACalcPlugin != null) { if (persistString == RVACalcPlugin.IDockContentTypeName) { return RVACalcPlugin.DockContent; } }
129 if (ScratchPadPlugin != null) { if (persistString == ScratchPadPlugin.IDockContentTypeName) { return ScratchPadPlugin.DockContent; } }
130 return null;
131 }
132 public void SetupDocks()
133 {
134 //m_LogWindow = new FloatingLogWindow();
135 //m_LogWindow.CloseButton = false;
136 //m_LogWindow.CloseButtonVisible = false;
137
138 //m_wb = new FloatingWebBrowser();
139 //m_wb.CloseButton = false;
140 //m_wb.CloseButtonVisible = false;
141
142 if (RVACalcPlugin != null)
143 {
144 RVACalcPlugin.DockHandler.CloseButton = false;
145 RVACalcPlugin.DockHandler.CloseButtonVisible = false;
146 RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
147 }
148 if (ScratchPadPlugin != null)
149 {
150 ScratchPadPlugin.DockHandler.CloseButton = false;
151 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
152 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
153 }
154
155 m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
156 }
157 #region SetupDockWindowHandler support
158 public void SetupDockWindowHandler()
159 {
160 //SetupLogWindowHandler();
161 //SetupWebBrowserWindowHandler();
162 SetupPluginWindowHandlers();
163 }
164 private void SetupPluginWindowHandlers()
165 {
166 if (RVACalcPlugin != null)
167 {
168 RVACalcPlugin.DockHandler.CloseButton = false;
169 RVACalcPlugin.DockHandler.CloseButtonVisible = false;
170 RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
171 RVACalcPlugin.Activate();
172 }
173 if (ScratchPadPlugin != null)
174 {
175 ScratchPadPlugin.DockHandler.CloseButton = false;
176 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
177 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
178 ScratchPadPlugin.Activate();
179 }
180 }
181 //private void SetupLogWindowHandler()
182 //{
183 // //if (m_LogWindow == null) return;
184 // ////m_LogWindow.Shown += new EventHandler(AddDockToWindowList);
185 // ////m_LogWindow.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
186 // //m_LogWindow.Activate();
187 //}
188 //private void SetupWebBrowserWindowHandler()
189 //{
190 // //if (m_wb == null) return;
191 // ////m_wb.Shown += new EventHandler(AddDockToWindowList);
192 // ////m_wb.FormClosed += new FormClosedEventHandler(RemoveDockFromWindowList);
193 // //m_wb.Activate();
194 //}
195 #endregion
196 public void ShowDocks()
197 {
198 //ShowLogWindow();
199 //SetupLogWindowHandler();
200 //ShowWebBrowser();
201 //SetupWebBrowserWindowHandler();
202 ShowPluginWindows();
203 SetupPluginWindowHandlers();
204
205 if (RVACalcPlugin != null)
206 RVACalcPlugin.Activate();
207 }
208 public void ShowLogWindow()
209 {
210 //if (m_LogWindow == null || m_LogWindow.IsDisposed) { m_LogWindow = new FloatingLogWindow(); }
211 //if (LoggerInstance == null)
212 //{
213 // LoggerInstance = m_LogWindow.Logwriter;
214 // LoggerInstance.CreateNewLog(false);
215 //}
216 ////m_LogWindow.AllowEndUserDocking = true;
217 ////m_LogWindow.CloseButton = false;
218 ////m_LogWindow.CloseButtonVisible = false;
219 //m_LogWindow.Show(dockPanel, DockState.DockBottom);
220 }
221
222
223 public void ShowWebBrowser()
224 {
225 ////load_plugins_silent();
226 //m_wb = new FloatingWebBrowser();
227 ////m_wb.AllowEndUserDocking = true;
228 ////m_wb.CloseButton = false;
229 ////m_wb.CloseButtonVisible = false;
230 //m_wb.Show(dockPanel, DockState.Document);
231 }
232 public void ShowPluginWindows()
233 {
234 if (RVACalcPlugin != null)
235 {
236 // RVA Calc
237 RVACalcPlugin.DockHandler.CloseButton = false;
238 RVACalcPlugin.DockHandler.CloseButtonVisible = false;
239 RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
240 RVACalcPlugin.Show(dockPanel, DockState.DockLeft);
241 }
242 if (ScratchPadPlugin != null)
243 {
244 // ScratchPad
245 ScratchPadPlugin.DockHandler.CloseButton = false;
246 ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
247 ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
248 ScratchPadPlugin.Show(dockPanel, DockState.Document);
249 }
250 }
251 #endregion
252
253 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
254 {
255 SettingsSubscriber.SaveSettings();
256 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
257 if (m_bSaveLayout)
258 dockPanel.SaveAsXml(configFile);
259 else if (File.Exists(configFile))
260 File.Delete(configFile);
261 // notify any docked windows of formclosing
262 foreach (var t in this.dockPanel.Contents)
263 {
264 t.OnDeactivate<FormClosingEventArgs>(e);
265 }
266 }
267
268 private void Form1_Shown(object sender, EventArgs e)
269 {
270 ////dockPanel.SuspendLayout(true);
271 ////ShowDocks();
272 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
273 if (File.Exists(configFile))
274 {
275 try
276 {
277 dockPanel.LoadFromXml(configFile, m_deserializeDockContent);
278 SetupDockWindowHandler();
279 }
280 catch (Exception)
281 {
282 this.Controls.Remove(dockPanel);
283 dockPanel = new DockPanel();
284 dockPanel.Dock = DockStyle.Fill;
285 dockPanel.DocumentStyle = DocumentStyle.DockingWindow;
286 this.Controls.Add(dockPanel);
287 ShowDocks();
288 }
289 }
290 else
291 {
292 ShowDocks();
293 }
294
295 if (RVACalcPlugin != null)
296 RVACalcPlugin.Activate();
297 ////dockPanel.ResumeLayout(true, true);
298 }
299
300 private void mnuItemExit_Click(object sender, EventArgs e)
301 {
302 this.Close();
303 }
304
305 private void Form1_Load(object sender, EventArgs e) { }
306 }
307 }

  ViewVC Help
Powered by ViewVC 1.1.22