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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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     using RomCheater.Docking;
11     using WeifenLuo.WinFormsUI.Docking;
12     using System.IO;
13 william 712 using RomCheater.PluginFramework.Core;
14     using RomCheater.Core;
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     IUserControlPlugin RVACalcPlugin = null;
29 william 730 IUserControlPlugin ScratchPadPlugin = null;
30 william 712
31 william 839 private LogLevel logging_level = LogLevel.kLogLevel_All;
32 william 731 private DeserializeDockContent m_deserializeDockContent;
33 william 728 //private FloatingLogWindow m_LogWindow = new FloatingLogWindow();
34     //private FloatingWebBrowser m_wb = new FloatingWebBrowser();
35 william 708
36 william 728 //public IWebBrowserProvider WebBrowserProvider
37     //{
38     // get { return new WebBrowserProvider(m_wb); }
39     //}
40 william 708 #region LogWriterSupport
41     static LogWriter _LoggerInstance;
42     static LogWriter LoggerInstance
43 william 707 {
44 william 708 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 william 707 InitializeComponent();
53 william 838 this.Icon = Core.Properties.Resources.romcheater_icon;
54 william 722 SettingsSubscriber = new SettingSubscriber();
55     SettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default);
56 william 839 //load_loggerflags();
57 william 717 SetupDocks();
58 william 728 //LoggerInstance = m_LogWindow.Logwriter;
59 william 814 LoggerInstance = new LogWriter();
60 william 839 load_loggerflags();
61 william 708 load_plugins();
62 william 814 //if (no_console_redirect)
63     // LoggerInstance.RedirectConsoleOutput = false;
64 william 707 }
65 william 708 private void load_loggerflags()
66     {
67 william 839 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 william 708 #if FORCE_ALL_LOGGING_FLAGS
77 william 839 logging_level = LogLevel.kLogLevel_All;
78 william 708 #endif
79 william 839 #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 william 708 }
85 william 839 private void Log_OnFlush(object sender, LoggerOnFlushEventArgs e)
86     {
87     }
88 william 708 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 william 712 loader = new PluginLoader();
93     loader.LoadPlugins(silent);
94 william 722
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 william 724 }
105    
106 william 730 // update the Config plugin's reference to the webbrowswer
107     //ConfigPlugin.WebBrowserProvider = this.WebBrowserProvider;
108 william 726
109 william 724 SettingsSubscriber.SetValue("LastConfigPlugin", ConfigPlugin.ToString());
110    
111 william 730 var scratchpad = PluginCollection.GetPluginByName(PluginNames.ScratchPadPlugin);
112 william 728 var rvacalc = PluginCollection.GetPluginByName(PluginNames.RVACalculatorPlugin);
113 william 730 ScratchPadPlugin = loader.GetPluginByGuid<IUserControlPlugin>(scratchpad.ID.ToString());
114 william 715 RVACalcPlugin = loader.GetPluginByGuid<IUserControlPlugin>(rvacalc.ID.ToString());
115 william 726
116     // update config of each plugin
117 william 730 ScratchPadPlugin.SetAcceptedConfig(ConfigPlugin);
118 william 726 RVACalcPlugin.SetAcceptedConfig(ConfigPlugin);
119 william 708 }
120    
121    
122    
123     #region Dock Support
124 william 731 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 william 708 public void SetupDocks()
133     {
134 william 728 //m_LogWindow = new FloatingLogWindow();
135 william 727 //m_LogWindow.CloseButton = false;
136     //m_LogWindow.CloseButtonVisible = false;
137 william 717
138 william 728 //m_wb = new FloatingWebBrowser();
139 william 727 //m_wb.CloseButton = false;
140     //m_wb.CloseButtonVisible = false;
141 william 717
142 william 731 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 william 708 }
157     #region SetupDockWindowHandler support
158     public void SetupDockWindowHandler()
159     {
160 william 728 //SetupLogWindowHandler();
161     //SetupWebBrowserWindowHandler();
162 william 716 SetupPluginWindowHandlers();
163 william 708 }
164 william 716 private void SetupPluginWindowHandlers()
165     {
166 william 717 if (RVACalcPlugin != null)
167     {
168 william 731 RVACalcPlugin.DockHandler.CloseButton = false;
169     RVACalcPlugin.DockHandler.CloseButtonVisible = false;
170     RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
171 william 717 RVACalcPlugin.Activate();
172     }
173 william 730 if (ScratchPadPlugin != null)
174     {
175 william 731 ScratchPadPlugin.DockHandler.CloseButton = false;
176     ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
177     ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
178 william 730 ScratchPadPlugin.Activate();
179     }
180 william 716 }
181 william 728 //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 william 708 #endregion
196     public void ShowDocks()
197     {
198 william 728 //ShowLogWindow();
199     //SetupLogWindowHandler();
200     //ShowWebBrowser();
201     //SetupWebBrowserWindowHandler();
202 william 716 ShowPluginWindows();
203     SetupPluginWindowHandlers();
204 william 722
205 william 730 if (RVACalcPlugin != null)
206     RVACalcPlugin.Activate();
207 william 708 }
208     public void ShowLogWindow()
209     {
210 william 728 //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 william 708 }
221    
222    
223     public void ShowWebBrowser()
224     {
225 william 728 ////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 william 708 }
232 william 716 public void ShowPluginWindows()
233     {
234 william 727 if (RVACalcPlugin != null)
235     {
236     // RVA Calc
237 william 728 RVACalcPlugin.DockHandler.CloseButton = false;
238     RVACalcPlugin.DockHandler.CloseButtonVisible = false;
239     RVACalcPlugin.DockHandler.AllowEndUserDocking = false;
240 william 731 RVACalcPlugin.Show(dockPanel, DockState.DockLeft);
241 william 727 }
242 william 730 if (ScratchPadPlugin != null)
243     {
244     // ScratchPad
245 william 731 ScratchPadPlugin.DockHandler.CloseButton = false;
246     ScratchPadPlugin.DockHandler.CloseButtonVisible = false;
247     ScratchPadPlugin.DockHandler.AllowEndUserDocking = false;
248 william 732 ScratchPadPlugin.Show(dockPanel, DockState.Document);
249 william 730 }
250 william 716 }
251 william 708 #endregion
252    
253     private void Form1_FormClosing(object sender, FormClosingEventArgs e)
254     {
255 william 722 SettingsSubscriber.SaveSettings();
256 william 755 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
257 william 731 if (m_bSaveLayout)
258     dockPanel.SaveAsXml(configFile);
259     else if (File.Exists(configFile))
260     File.Delete(configFile);
261 william 708 // 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 william 728 ////dockPanel.SuspendLayout(true);
271     ////ShowDocks();
272 william 755 string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DockPanelConfig);
273 william 731 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 william 708
295 william 730 if (RVACalcPlugin != null)
296     RVACalcPlugin.Activate();
297 william 728 ////dockPanel.ResumeLayout(true, true);
298 william 708 }
299 william 712
300     private void mnuItemExit_Click(object sender, EventArgs e)
301     {
302     this.Close();
303     }
304 william 719
305 william 725 private void Form1_Load(object sender, EventArgs e) { }
306 william 707 }
307     }

  ViewVC Help
Powered by ViewVC 1.1.22