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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22