/[EmuXPortal]/branches/mono/EmuXPortal/Form1.cs
ViewVC logotype

Annotation of /branches/mono/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 243 - (hide annotations) (download)
Tue Aug 5 05:57:55 2014 UTC (5 years, 6 months ago) by william
Original Path: trunk/EmuXPortal/Form1.cs
File size: 31958 byte(s)
+ catch unhandled exceptions in Form1

1 william 191 //#define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden
2 william 183 //#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar
3 william 241 #define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
4     //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
5 william 181 using System;
6 william 4 using System.Collections.Generic;
7     using System.ComponentModel;
8     using System.Data;
9     using System.Drawing;
10     using System.Linq;
11     using System.Text;
12     using System.Windows.Forms;
13 william 12 using EmuXPortal.Api;
14 william 23 using System.Diagnostics;
15 william 60 using System.Reflection;
16     using System.Threading;
17 william 183 using Utilities.TransparentControls;
18 william 238 using Enterprise.Logging;
19     using System.IO;
20 william 4
21     namespace EmuXPortal
22     {
23     public partial class Form1 : Form
24     {
25 william 183 const float PROGRESS_BAR_FONT_SIZE = 24;
26     private delegate Font Delegate_GetFormFont();
27     private delegate Font Delegate_ResizeFont(Font font, float size);
28 william 17 IEmuConfig CurrentSelectedRom = null;
29 william 31 PlatformControl CurrentPlatformControl = null;
30     GameControl CurrentGameControl = null;
31 william 243
32     #region unhandled exception support
33     static void Application_Unhandled_ThreadException(object sender, ThreadExceptionEventArgs e)
34     {
35     UnhandledExceptionEventArgs uea = new UnhandledExceptionEventArgs(e.Exception, false);
36     UnhandledExceptionEventHandler(sender, uea);
37     }
38     static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs args)
39     {
40     Exception ex = (args.ExceptionObject as Exception);
41     if (sender == null)
42     {
43     gLog.Error.WriteLine("Caught an unhandled exception from an unkown source");
44     }
45     else
46     {
47     gLog.Error.WriteLine("Caught an unhandled exception from type: {0}", sender.GetType().Name);
48     }
49    
50     if (ex == null)
51     {
52     gLog.Error.WriteLine("The exception object was null -- it probably is not derived from System.Exception");
53     }
54     else
55     {
56     ex = ex.GetBaseException();
57     gLog.Error.WriteLine("{0}:", ex.GetType().Name);
58     gLog.Verbose.Error.WriteLine(ex.ToString());
59     }
60    
61     }
62     #endregion
63 william 4 public Form1()
64     {
65 william 243 InitializeComponent();
66    
67    
68 william 238 #region logging support
69     string log_path = Application.StartupPath;
70     string log_filename = string.Format("{0}.log", typeof(Form1).Assembly.GetName().Name);
71     FileInfo log_file = new FileInfo(string.Format(@"{0}\{1}", log_path, log_filename));
72    
73     gLog.CreateLog(log_file.FullName, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
74     #if DEBUG
75     LogLevel gLevel = gLog.LogLevel;
76     #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
77     gLevel &= ~LogLevel.kLogLevel_VerboseDebug;
78     #else
79     gLevel |= LogLevel.kLogLevel_VerboseDebug;
80     #endif
81     gLevel |= LogLevel.kLogLevel_Debug;
82     gLog.SetLogLevel(gLevel);
83     #else
84     LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
85     // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
86     #if DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG
87     gLevel &= ~LogLevel.kLogLevel_Debug;
88     #else
89     gLevel |= LogLevel.kLogLevel_Debug;
90     #endif
91     gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode
92     gLog.SetLogLevel(gLevel);
93     #endif
94     #endregion
95    
96 william 243 #region unhandled exception support
97     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
98     Application.ThreadException += Application_Unhandled_ThreadException;
99     #endregion
100    
101 william 17 platform_flow.Dock = DockStyle.Fill;
102     rom_flow.Dock = DockStyle.Fill;
103 william 238 }
104 william 243
105    
106    
107    
108 william 238 #region logging support
109     StringBuilder log_flusher = new StringBuilder();
110     void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) { OnLogFlush(e.Buffer); }
111     void OnLogFlush(string logmessage)
112     {
113     //if (this.IsDisposed) { return; }
114     ////UpdateStatus(logmessage);
115     ////UpdateLogOutput(logmessage);
116     //Application.DoEvents();
117     }
118     #endregion
119 william 184
120 william 17 private void Form1_Load(object sender, EventArgs e)
121     {
122 william 238 Config.LoadConfig();
123     Config.InitializePresentationForm(this);
124 william 17 }
125 william 181 private void Form1_Shown(object sender, EventArgs e)
126     {
127     platform_flow.Visible = true;
128     #if !DISABLE_CURSOR_HIDE
129     Cursor.Hide();
130     #else
131     Cursor.Show();
132     #endif
133     }
134 william 17 void platform_ctrl_LostFocus(object sender, EventArgs e)
135     {
136     PlatformControl c = sender as PlatformControl;
137     c.BorderStyle = BorderStyle.None;
138     }
139 william 13
140 william 17 void platform_ctrl_GotFocus(object sender, EventArgs e)
141 william 13 {
142 william 17 PlatformControl c = sender as PlatformControl;
143     c.BorderStyle = BorderStyle.FixedSingle;
144 william 31 CurrentPlatformControl = c;
145 william 13 }
146 william 168 void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
147     {
148     GameControl c = sender as GameControl;
149 william 17
150 william 168 int changeAmount = 0;
151     int currentPosition = 0;
152 william 183 if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control)
153 william 168 {
154     IRomConfig config = c.Tag as IRomConfig;
155     if (config == null)
156     {
157 william 241 gLog.Error.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile);
158 william 168 }
159     else
160     {
161 william 238 var isFavorite = RomFavorite.IsFavorite(config);
162 william 168 if (isFavorite)
163     {
164     // add to favorites
165 william 238 gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
166     if (!RomFavorite.RemoveFavorite(config))
167 william 168 {
168 william 241 gLog.Error.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
169 william 168 }
170     else
171     {
172 william 241 gLog.Info.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
173 william 177 if (config.Config.PlatformNameShort == "Favorites")
174 william 176 {
175 william 177 var parent = c.Parent;
176     if (parent != null)
177 william 176 {
178 william 177 parent.Controls.Remove(c);
179     if (parent.Controls.Count > 0)
180 william 176 {
181 william 177 var next_ctrl = parent.Controls[0];
182     if (next_ctrl != null)
183     {
184     next_ctrl.Select();
185     }
186 william 176 }
187     }
188 william 177 }
189 william 168 }
190     }
191     else
192     {
193     // add to favorites
194 william 238 gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
195     if (!RomFavorite.AddFavorite(config))
196 william 168 {
197 william 241 gLog.Error.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
198 william 168 }
199     else
200     {
201 william 241 gLog.Info.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
202 william 168 }
203     }
204 william 238 gLog.Debug.WriteLine("Updateing favorites");
205     if (!RomFavorite.UpdateFavorites())
206 william 168 {
207 william 241 gLog.Error.WriteLine("Failed to update favorites");
208 william 168 }
209     else
210     {
211 william 241 gLog.Info.WriteLine("Updated favorites");
212 william 168 }
213     }
214     return; // stop processing other keys
215    
216     }
217     if (e.KeyCode == Keys.Home)
218     {
219     rom_flow.Controls[0].Select();
220     rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
221     }
222     if (e.KeyCode == Keys.End)
223     {
224     rom_flow.Controls[rom_flow.Controls.Count - 1].Select();
225     rom_flow.ScrollControlIntoView(rom_flow.Controls[rom_flow.Controls.Count - 1]);
226     }
227     if (e.KeyCode == Keys.PageUp)
228     {
229     changeAmount = rom_flow.VerticalScroll.LargeChange;
230     currentPosition = rom_flow.VerticalScroll.Value;
231     if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum)
232     {
233     try
234     {
235 william 179 rom_flow.VerticalScroll.Value -= changeAmount;
236 william 168 }
237     catch
238     {
239     rom_flow.Controls[0].Select();
240 william 179 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
241 william 168 rom_flow.PerformLayout();
242     return;
243     }
244     }
245     else
246     {
247     rom_flow.Controls[0].Select();
248 william 179 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
249 william 168 }
250     GameControl s = game_ctrl_get_last_visible();
251     s.Select();
252     rom_flow.ScrollControlIntoView(s);
253     rom_flow.PerformLayout();
254     }
255     if (e.KeyCode == Keys.PageDown)
256     {
257     changeAmount = rom_flow.VerticalScroll.LargeChange;
258     currentPosition = rom_flow.VerticalScroll.Value;
259     if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum)
260     {
261 william 208 try
262     {
263     rom_flow.VerticalScroll.Value += changeAmount;
264     }
265     catch
266     {
267     rom_flow.Controls[0].Select();
268     rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
269     rom_flow.PerformLayout();
270     return;
271     }
272 william 168 }
273     else
274     {
275     rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
276     }
277     GameControl s = game_ctrl_get_last_visible();
278     s.Select();
279     rom_flow.ScrollControlIntoView(s);
280     rom_flow.PerformLayout();
281     }
282    
283     if (e.KeyCode == Keys.Enter)
284     {
285     IRomConfig config = c.Tag as IRomConfig;
286    
287     Process p = new Process();
288    
289     p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe;
290 william 238 p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(config) : config.Config.GameExeArgs;
291 william 168 p.Start();
292    
293     // minimize EmuXPortal
294     this.WindowState = FormWindowState.Minimized;
295     // wait for exit of game
296     p.WaitForExit();
297     // maximize EmuXPortal
298     this.WindowState = FormWindowState.Maximized;
299     }
300     if (e.KeyCode == Keys.Back)
301     {
302     rom_flow.Visible = false;
303     platform_flow.Visible = true;
304     }
305    
306     if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
307     (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
308     {
309     char t = (char)e.KeyCode;
310 william 181 GameControl ctrl = (rom_flow.GetNextControl(CurrentGameControl, true) as GameControl);
311 william 168 if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); }
312     bool found = false;
313     GameControl pc = CurrentGameControl;
314     bool wrapped = false;
315     bool not_found = true;
316     while (!found)
317     {
318     if (wrapped)
319     {
320     foreach (Control ctl in rom_flow.Controls)
321     {
322     GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
323     }
324     if (not_found) { found = true; }
325     }
326     ctrl = (rom_flow.GetNextControl(pc, true) as GameControl);
327     if (ctrl == null)
328     {
329     ctrl = rom_flow.Controls[0] as GameControl;
330     wrapped = true;
331     }
332     if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower()))
333     {
334     rom_flow.ScrollControlIntoView(ctrl);
335     ctrl.Select();
336     found = true;
337     }
338     pc = ctrl;
339     }
340     }
341     }
342 william 17 void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
343     {
344     PlatformControl c = sender as PlatformControl;
345 william 60 int changeAmount = 0;
346     int currentPosition = 0;
347     if (e.KeyCode == Keys.Home)
348     {
349     platform_flow.Controls[0].Select();
350     platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
351     }
352     if (e.KeyCode == Keys.End)
353     {
354     platform_flow.Controls[platform_flow.Controls.Count -1].Select();
355     platform_flow.ScrollControlIntoView(platform_flow.Controls[platform_flow.Controls.Count - 1]);
356     }
357     if (e.KeyCode == Keys.PageUp)
358     {
359     changeAmount = platform_flow.VerticalScroll.LargeChange;
360     currentPosition = platform_flow.VerticalScroll.Value;
361     if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum)
362     {
363     platform_flow.VerticalScroll.Value -= changeAmount;
364     }
365     else
366     {
367     platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum;
368     }
369     PlatformControl s = platform_ctrl_get_last_visible();
370     s.Select();
371     platform_flow.ScrollControlIntoView(s);
372     platform_flow.PerformLayout();
373     }
374     if (e.KeyCode == Keys.PageDown)
375 william 180 {
376 william 60 changeAmount = platform_flow.VerticalScroll.LargeChange;
377     currentPosition = platform_flow.VerticalScroll.Value;
378     if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum)
379     {
380     try
381     {
382     platform_flow.VerticalScroll.Value += changeAmount;
383     }
384     catch
385     {
386     platform_flow.Controls[0].Select();
387     platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
388     rom_flow.PerformLayout();
389     return;
390     }
391     }
392     else
393     {
394     platform_flow.Controls[0].Select();
395     platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
396     }
397     PlatformControl s = platform_ctrl_get_last_visible();
398     s.Select();
399     platform_flow.ScrollControlIntoView(s);
400     platform_flow.PerformLayout();
401     }
402 william 17 if (e.KeyCode == Keys.Enter)
403     {
404     // load this platform
405     platform_flow.Visible = false;
406     CurrentSelectedRom = c.Tag as IEmuConfig;
407     rom_flow.Visible = true;
408     rom_flow.BringToFront();
409 william 25 }
410     if (e.KeyCode == Keys.Back)
411     {
412     this.Close();
413     }
414 william 30 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
415     (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
416     {
417     char t = (char)e.KeyCode;
418 william 31 PlatformControl ctrl = (platform_flow.GetNextControl(CurrentPlatformControl, true) as PlatformControl);
419     if (ctrl == null) { ctrl = (platform_flow.GetNextControl(platform_flow.Controls[0], true) as PlatformControl); }
420     bool found = false;
421     PlatformControl pc = CurrentPlatformControl;
422     bool wrapped = false;
423     bool not_found = true;
424     while (!found)
425 william 30 {
426 william 31 if (wrapped)
427 william 30 {
428 william 31 foreach (Control ctl in platform_flow.Controls)
429     {
430     PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
431     }
432     if (not_found) { found = true; }
433 william 30 }
434 william 31 ctrl = (platform_flow.GetNextControl(pc, true) as PlatformControl);
435     if (ctrl == null)
436     {
437     ctrl = platform_flow.Controls[0] as PlatformControl;
438     wrapped = true;
439     }
440     if (ctrl.PlatformName.ToLower().StartsWith(t.ToString().ToLower()))
441     {
442     platform_flow.ScrollControlIntoView(ctrl);
443     ctrl.Select();
444     found = true;
445     }
446     pc = ctrl;
447 william 30 }
448     }
449 william 17 }
450    
451     private void platform_flow_VisibleChanged(object sender, EventArgs e)
452     {
453     if (!platform_flow.Visible) return;
454     platform_flow.Controls.Clear();
455     platform_flow.BringToFront();
456 william 37 Stopwatch t = new Stopwatch();
457     t.Start();
458 william 60 platformWorker.RunWorkerAsync(t);
459 william 17 }
460    
461     private void rom_flow_VisibleChanged(object sender, EventArgs e)
462     {
463     if (!rom_flow.Visible) return;
464     rom_flow.Controls.Clear();
465     rom_flow.BringToFront();
466 william 37 Stopwatch t = new Stopwatch();
467     t.Start();
468 william 60 gameWorker.RunWorkerAsync(t);
469 william 17 }
470    
471     void game_ctrl_LostFocus(object sender, EventArgs e)
472     {
473     GameControl c = sender as GameControl;
474     c.BorderStyle = BorderStyle.None;
475     }
476    
477     void game_ctrl_GotFocus(object sender, EventArgs e)
478     {
479     GameControl c = sender as GameControl;
480     c.BorderStyle = BorderStyle.FixedSingle;
481 william 31 CurrentGameControl = c;
482 william 17 }
483    
484 william 60 private GameControl game_ctrl_get_last_visible()
485     {
486     GameControl s = new GameControl();
487     foreach (GameControl c in rom_flow.Controls)
488     {
489     if (c.Bounds.IntersectsWith(rom_flow.Bounds))
490     s = c;
491     }
492     return s;
493     }
494     private PlatformControl platform_ctrl_get_last_visible()
495     {
496     PlatformControl s = new PlatformControl();
497     foreach (PlatformControl c in platform_flow.Controls)
498     {
499     if (c.Bounds.IntersectsWith(platform_flow.Bounds))
500     s = c;
501     }
502     return s;
503     }
504 william 168
505 william 60
506     #region Background Workers
507    
508     private int GetFormWidth()
509     {
510     if (this.InvokeRequired)
511     {
512     return Convert.ToInt32(this.Invoke((MethodInvoker)delegate() { GetFormWidth(); }));
513     }
514     else
515     {
516     return this.Width;
517     }
518     }
519 william 183 private Font GetFormFont()
520     {
521     if (this.InvokeRequired)
522     {
523     return (this.Invoke(new Delegate_GetFormFont(GetFormFont)) as Font);
524     }
525     else
526     {
527     return this.Font;
528     }
529     }
530    
531     private Font ResizeFont(Font font, float size)
532     {
533     if (this.InvokeRequired)
534     {
535     return (this.Invoke(new Delegate_ResizeFont(ResizeFont), new object[] { font, size })as Font);
536     }
537     else
538     {
539     return new Font(font.FontFamily, size);
540     }
541     }
542    
543 william 113 //private void AddPlatformControl(Control c)
544     //{
545     // if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
546     // else
547     // {
548     // platform_flow.Controls.Add(c);
549     // }
550     //}
551     //private void UpdatePlatformControls()
552     //{
553     // //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); }
554     // //else { this.Update(); }
555     //}
556     //private void AddGameControl(Control c)
557     //{
558     // if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); }
559     // else
560     // {
561     // rom_flow.Controls.Add(c);
562     // }
563     //}
564     //private void UpdateGameControls()
565     //{
566     // //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); }
567     // //else { this.Update(); }
568     //}
569 william 60 #region gameWorker
570 william 110 private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
571 william 137 private object gameimage_lock = new object();
572 william 60 private void gameWorker_DoWork(object sender, DoWorkEventArgs e)
573     {
574     Stopwatch t = e.Argument as Stopwatch;
575 william 238 RomParser parser = new RomParser(CurrentSelectedRom);
576 william 60
577 william 183 CustomProgressBar bar = new CustomProgressBar();
578     bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
579     #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
580     bar.ShowPercentageLabel = false;
581     #endif
582     bar.ProgressColor = Color.LimeGreen;
583     bar.Dock = DockStyle.Top;
584    
585     if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
586     else { this.Controls.Add(bar); }
587     bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
588 william 60
589     double count = 0;
590     double total_count = parser.Roms.Count;
591     foreach (IRomConfig config in parser.Roms)
592     {
593 william 183 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
594 william 60 GameControl game_ctrl = new GameControl();
595 william 183 game_ctrl.Font = GetFormFont();
596 william 60 game_ctrl.Dock = DockStyle.Top;
597     game_ctrl.Width = this.Width - 10;
598     game_ctrl.Tag = config;
599 william 137 try
600     {
601     lock (gameimage_lock)
602     {
603     game_ctrl.GameImage = config.RomImage == null ? (Image)DefaultGameImage.Clone() : (Image)config.RomImage.Clone();
604     config.ReleaseRomImageResource();
605     }
606     }
607     catch (Exception ex)
608     {
609     throw ex;
610 william 178 }
611     if (CurrentSelectedRom.PlatformNameShort == "Favorites")
612     {
613     //game_ctrl.GameName = config.RomTitle;
614     game_ctrl.GameName = RomFavorite.GetRomTitleFromConfig(config);
615     }
616     else
617     {
618     game_ctrl.GameName = config.RomTitle;
619 william 183 }
620 william 60 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
621     game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
622     game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
623 william 113 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); }
624     else { rom_flow.Controls.Add(game_ctrl); }
625 william 60 count++;
626     }
627 william 183 bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
628     if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
629 william 60 e.Result = t;
630 william 105 parser.Dispose();
631 william 60 }
632     private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
633     private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
634     {
635 william 197 Stopwatch t = e.Result as Stopwatch;
636 william 198 if (rom_flow.Controls.Count == 0)
637 william 197 {
638     GameControl game_ctrl = new GameControl();
639 william 198 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
640     game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
641     game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
642 william 197 game_ctrl.Font = GetFormFont();
643     game_ctrl.Dock = DockStyle.Top;
644     game_ctrl.Width = this.Width - 10;
645     game_ctrl.GameName = "You haven't favorited any games, select a game and then press CTRL+F to favorite it";
646     rom_flow.Controls.Add(game_ctrl);
647     }
648 william 198 rom_flow.Controls[0].Select();
649 william 60 t.Stop();
650 william 238 gLog.Profiler.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
651 william 60 }
652     #endregion
653     #region platformWorker
654 william 110 private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
655 william 137 private object platformimage_lock = new object();
656 william 60 private void platformWorker_DoWork(object sender, DoWorkEventArgs e)
657     {
658     Stopwatch t = e.Argument as Stopwatch;
659 william 238 PlatformParser parser = new PlatformParser(Config.RomPath);
660 william 60 double count = 0;
661     double total_count = parser.Platforms.Count;
662 william 183 CustomProgressBar bar = new CustomProgressBar();
663     bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
664     #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
665     bar.ShowPercentageLabel = false;
666     #endif
667     bar.ProgressColor = Color.LimeGreen;
668     bar.Dock = DockStyle.Top;
669     if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
670     else { this.Controls.Add(bar); }
671     bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
672 william 60 foreach (IEmuConfig config in parser.Platforms)
673     {
674 william 183 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
675    
676 william 60 PlatformControl platform_ctrl = new PlatformControl();
677 william 183 platform_ctrl.Font = GetFormFont();
678 william 60 platform_ctrl.Dock = DockStyle.Top;
679     platform_ctrl.Width = this.Width - 10;
680     platform_ctrl.Tag = config;
681 william 137 try
682     {
683     lock (platformimage_lock)
684     {
685 william 138 platform_ctrl.PlatformImage = config.PlatformImage == null ? (Image)DefaultPlatformImage.Clone() : (Image)config.PlatformImage.Clone();
686 william 137 config.ReleasePlatformImageResource();
687     }
688     }
689     catch (Exception ex)
690     {
691     throw ex;
692     }
693 william 60 platform_ctrl.PlatformName = config.ToString();
694     platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
695     platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
696     platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
697 william 113 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); }
698 william 183 else { platform_flow.Controls.Add(platform_ctrl); }
699 william 60 count++;
700     }
701 william 183 bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
702     if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
703 william 60 e.Result = t;
704 william 105 parser.Dispose();
705 william 60 }
706     private void platformWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
707     private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
708     {
709     Stopwatch t = e.Result as Stopwatch;
710 william 198 if (platform_flow.Controls.Count == 0)
711 william 197 {
712     PlatformControl platform_ctrl = new PlatformControl();
713 william 198 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
714     platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
715     platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
716 william 197 platform_ctrl.Font = GetFormFont();
717     platform_ctrl.Dock = DockStyle.Top;
718     platform_ctrl.Width = this.Width - 10;
719     platform_ctrl.PlatformName = string.Format("You don't have any roms in your rompath: '{0}'",Config.RomPath);
720     platform_flow.Controls.Add(platform_ctrl);
721     }
722 william 198 platform_flow.Controls[0].Select();
723 william 238 gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
724 william 60 }
725     #endregion
726    
727     private void Form1_FormClosed(object sender, FormClosedEventArgs e)
728     {
729     Cursor.Show();
730     }
731     #endregion
732 william 4 }
733     }

  ViewVC Help
Powered by ViewVC 1.1.22