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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 243 - (show 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 //#define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden
2 //#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar
3 #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 using System;
6 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 using EmuXPortal.Api;
14 using System.Diagnostics;
15 using System.Reflection;
16 using System.Threading;
17 using Utilities.TransparentControls;
18 using Enterprise.Logging;
19 using System.IO;
20
21 namespace EmuXPortal
22 {
23 public partial class Form1 : Form
24 {
25 const float PROGRESS_BAR_FONT_SIZE = 24;
26 private delegate Font Delegate_GetFormFont();
27 private delegate Font Delegate_ResizeFont(Font font, float size);
28 IEmuConfig CurrentSelectedRom = null;
29 PlatformControl CurrentPlatformControl = null;
30 GameControl CurrentGameControl = null;
31
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 public Form1()
64 {
65 InitializeComponent();
66
67
68 #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 #region unhandled exception support
97 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
98 Application.ThreadException += Application_Unhandled_ThreadException;
99 #endregion
100
101 platform_flow.Dock = DockStyle.Fill;
102 rom_flow.Dock = DockStyle.Fill;
103 }
104
105
106
107
108 #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
120 private void Form1_Load(object sender, EventArgs e)
121 {
122 Config.LoadConfig();
123 Config.InitializePresentationForm(this);
124 }
125 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 void platform_ctrl_LostFocus(object sender, EventArgs e)
135 {
136 PlatformControl c = sender as PlatformControl;
137 c.BorderStyle = BorderStyle.None;
138 }
139
140 void platform_ctrl_GotFocus(object sender, EventArgs e)
141 {
142 PlatformControl c = sender as PlatformControl;
143 c.BorderStyle = BorderStyle.FixedSingle;
144 CurrentPlatformControl = c;
145 }
146 void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
147 {
148 GameControl c = sender as GameControl;
149
150 int changeAmount = 0;
151 int currentPosition = 0;
152 if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control)
153 {
154 IRomConfig config = c.Tag as IRomConfig;
155 if (config == null)
156 {
157 gLog.Error.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile);
158 }
159 else
160 {
161 var isFavorite = RomFavorite.IsFavorite(config);
162 if (isFavorite)
163 {
164 // add to favorites
165 gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
166 if (!RomFavorite.RemoveFavorite(config))
167 {
168 gLog.Error.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
169 }
170 else
171 {
172 gLog.Info.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
173 if (config.Config.PlatformNameShort == "Favorites")
174 {
175 var parent = c.Parent;
176 if (parent != null)
177 {
178 parent.Controls.Remove(c);
179 if (parent.Controls.Count > 0)
180 {
181 var next_ctrl = parent.Controls[0];
182 if (next_ctrl != null)
183 {
184 next_ctrl.Select();
185 }
186 }
187 }
188 }
189 }
190 }
191 else
192 {
193 // add to favorites
194 gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
195 if (!RomFavorite.AddFavorite(config))
196 {
197 gLog.Error.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
198 }
199 else
200 {
201 gLog.Info.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
202 }
203 }
204 gLog.Debug.WriteLine("Updateing favorites");
205 if (!RomFavorite.UpdateFavorites())
206 {
207 gLog.Error.WriteLine("Failed to update favorites");
208 }
209 else
210 {
211 gLog.Info.WriteLine("Updated favorites");
212 }
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 rom_flow.VerticalScroll.Value -= changeAmount;
236 }
237 catch
238 {
239 rom_flow.Controls[0].Select();
240 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
241 rom_flow.PerformLayout();
242 return;
243 }
244 }
245 else
246 {
247 rom_flow.Controls[0].Select();
248 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
249 }
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 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 }
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 p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(config) : config.Config.GameExeArgs;
291 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 GameControl ctrl = (rom_flow.GetNextControl(CurrentGameControl, true) as GameControl);
311 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 void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
343 {
344 PlatformControl c = sender as PlatformControl;
345 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 {
376 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 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 }
410 if (e.KeyCode == Keys.Back)
411 {
412 this.Close();
413 }
414 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 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 {
426 if (wrapped)
427 {
428 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 }
434 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 }
448 }
449 }
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 Stopwatch t = new Stopwatch();
457 t.Start();
458 platformWorker.RunWorkerAsync(t);
459 }
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 Stopwatch t = new Stopwatch();
467 t.Start();
468 gameWorker.RunWorkerAsync(t);
469 }
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 CurrentGameControl = c;
482 }
483
484 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
505
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 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 //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 #region gameWorker
570 private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
571 private object gameimage_lock = new object();
572 private void gameWorker_DoWork(object sender, DoWorkEventArgs e)
573 {
574 Stopwatch t = e.Argument as Stopwatch;
575 RomParser parser = new RomParser(CurrentSelectedRom);
576
577 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
589 double count = 0;
590 double total_count = parser.Roms.Count;
591 foreach (IRomConfig config in parser.Roms)
592 {
593 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
594 GameControl game_ctrl = new GameControl();
595 game_ctrl.Font = GetFormFont();
596 game_ctrl.Dock = DockStyle.Top;
597 game_ctrl.Width = this.Width - 10;
598 game_ctrl.Tag = config;
599 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 }
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 }
620 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 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); }
624 else { rom_flow.Controls.Add(game_ctrl); }
625 count++;
626 }
627 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 e.Result = t;
630 parser.Dispose();
631 }
632 private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
633 private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
634 {
635 Stopwatch t = e.Result as Stopwatch;
636 if (rom_flow.Controls.Count == 0)
637 {
638 GameControl game_ctrl = new GameControl();
639 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 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 rom_flow.Controls[0].Select();
649 t.Stop();
650 gLog.Profiler.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
651 }
652 #endregion
653 #region platformWorker
654 private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
655 private object platformimage_lock = new object();
656 private void platformWorker_DoWork(object sender, DoWorkEventArgs e)
657 {
658 Stopwatch t = e.Argument as Stopwatch;
659 PlatformParser parser = new PlatformParser(Config.RomPath);
660 double count = 0;
661 double total_count = parser.Platforms.Count;
662 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 foreach (IEmuConfig config in parser.Platforms)
673 {
674 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
675
676 PlatformControl platform_ctrl = new PlatformControl();
677 platform_ctrl.Font = GetFormFont();
678 platform_ctrl.Dock = DockStyle.Top;
679 platform_ctrl.Width = this.Width - 10;
680 platform_ctrl.Tag = config;
681 try
682 {
683 lock (platformimage_lock)
684 {
685 platform_ctrl.PlatformImage = config.PlatformImage == null ? (Image)DefaultPlatformImage.Clone() : (Image)config.PlatformImage.Clone();
686 config.ReleasePlatformImageResource();
687 }
688 }
689 catch (Exception ex)
690 {
691 throw ex;
692 }
693 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 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); }
698 else { platform_flow.Controls.Add(platform_ctrl); }
699 count++;
700 }
701 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 e.Result = t;
704 parser.Dispose();
705 }
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 if (platform_flow.Controls.Count == 0)
711 {
712 PlatformControl platform_ctrl = new PlatformControl();
713 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 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 platform_flow.Controls[0].Select();
723 gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
724 }
725 #endregion
726
727 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
728 {
729 Cursor.Show();
730 }
731 #endregion
732 }
733 }

  ViewVC Help
Powered by ViewVC 1.1.22