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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 253 - (show annotations) (download)
Tue Aug 5 12:48:58 2014 UTC (5 years, 6 months ago) by william
Original Path: trunk/EmuXPortal/Form1.cs
File size: 33378 byte(s)
Reverse merged revision(s) 248-247 from trunk:
+ current WIP for flowlayout panel

........

........

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.SuspendLayout();
220 rom_flow.Controls[0].Select();
221 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
222 rom_flow.ResumeLayout(false);
223 }
224 if (e.KeyCode == Keys.End)
225 {
226 rom_flow.SuspendLayout();
227 rom_flow.Controls[rom_flow.Controls.Count - 1].Select();
228 rom_flow.ScrollControlIntoView(rom_flow.Controls[rom_flow.Controls.Count - 1]);
229 rom_flow.ResumeLayout(false);
230 }
231 if (e.KeyCode == Keys.PageUp)
232 {
233 rom_flow.SuspendLayout();
234 changeAmount = rom_flow.VerticalScroll.LargeChange;
235 currentPosition = rom_flow.VerticalScroll.Value;
236 if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum)
237 {
238 try
239 {
240 rom_flow.VerticalScroll.Value -= changeAmount;
241 }
242 catch
243 {
244 rom_flow.Controls[0].Select();
245 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
246 rom_flow.PerformLayout();
247 return;
248 }
249 }
250 else
251 {
252 rom_flow.Controls[0].Select();
253 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
254 }
255 GameControl s = game_ctrl_get_last_visible();
256 s.Select();
257 rom_flow.ScrollControlIntoView(s);
258 rom_flow.ResumeLayout(false);
259 }
260 if (e.KeyCode == Keys.PageDown)
261 {
262 rom_flow.SuspendLayout();
263 changeAmount = rom_flow.VerticalScroll.LargeChange;
264 currentPosition = rom_flow.VerticalScroll.Value;
265 if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum)
266 {
267 try
268 {
269 rom_flow.VerticalScroll.Value += changeAmount;
270 }
271 catch
272 {
273 rom_flow.Controls[0].Select();
274 rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
275 rom_flow.PerformLayout();
276 return;
277 }
278 }
279 else
280 {
281 rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
282 }
283 GameControl s = game_ctrl_get_last_visible();
284 s.Select();
285 rom_flow.ScrollControlIntoView(s);
286 rom_flow.ResumeLayout(false);
287 }
288
289 if (e.KeyCode == Keys.Enter)
290 {
291 IRomConfig config = c.Tag as IRomConfig;
292
293 Process p = new Process();
294
295 p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe;
296 p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(config) : config.Config.GameExeArgs;
297 p.Start();
298
299 // minimize EmuXPortal
300 this.WindowState = FormWindowState.Minimized;
301 // wait for exit of game
302 p.WaitForExit();
303 // maximize EmuXPortal
304 this.WindowState = FormWindowState.Maximized;
305 }
306 if (e.KeyCode == Keys.Back)
307 {
308 rom_flow.Visible = false;
309 platform_flow.Visible = true;
310 }
311
312 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
313 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
314 {
315 rom_flow.SuspendLayout();
316 char t = (char)e.KeyCode;
317 GameControl ctrl = (rom_flow.GetNextControl(CurrentGameControl, true) as GameControl);
318 if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); }
319 bool found = false;
320 GameControl pc = CurrentGameControl;
321 bool wrapped = false;
322 bool not_found = true;
323 while (!found)
324 {
325 if (wrapped)
326 {
327 foreach (Control ctl in rom_flow.Controls)
328 {
329 GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
330 }
331 if (not_found) { found = true; }
332 }
333 ctrl = (rom_flow.GetNextControl(pc, true) as GameControl);
334 if (ctrl == null)
335 {
336 ctrl = rom_flow.Controls[0] as GameControl;
337 wrapped = true;
338 }
339 if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower()))
340 {
341 rom_flow.ScrollControlIntoView(ctrl);
342 ctrl.Select();
343 found = true;
344 }
345 pc = ctrl;
346 }
347 rom_flow.ResumeLayout(false);
348 }
349 }
350 void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
351 {
352 PlatformControl c = sender as PlatformControl;
353 int changeAmount = 0;
354 int currentPosition = 0;
355 if (e.KeyCode == Keys.Home)
356 {
357 platform_flow.SuspendLayout();
358 platform_flow.Controls[0].Select();
359 platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
360 platform_flow.ResumeLayout(false);
361 }
362 if (e.KeyCode == Keys.End)
363 {
364 platform_flow.SuspendLayout();
365 platform_flow.Controls[platform_flow.Controls.Count -1].Select();
366 platform_flow.ScrollControlIntoView(platform_flow.Controls[platform_flow.Controls.Count - 1]);
367 platform_flow.ResumeLayout(false);
368 }
369 if (e.KeyCode == Keys.PageUp)
370 {
371 platform_flow.SuspendLayout();
372 changeAmount = platform_flow.VerticalScroll.LargeChange;
373 currentPosition = platform_flow.VerticalScroll.Value;
374 if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum)
375 {
376 platform_flow.VerticalScroll.Value -= changeAmount;
377 }
378 else
379 {
380 platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum;
381 }
382 PlatformControl s = platform_ctrl_get_last_visible();
383 s.Select();
384 platform_flow.ScrollControlIntoView(s);
385 platform_flow.ResumeLayout(false);
386 }
387 if (e.KeyCode == Keys.PageDown)
388 {
389 platform_flow.SuspendLayout();
390 changeAmount = platform_flow.VerticalScroll.LargeChange;
391 currentPosition = platform_flow.VerticalScroll.Value;
392 if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum)
393 {
394 try
395 {
396 platform_flow.VerticalScroll.Value += changeAmount;
397 }
398 catch
399 {
400 platform_flow.Controls[0].Select();
401 platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
402 rom_flow.PerformLayout();
403 return;
404 }
405 }
406 else
407 {
408 platform_flow.Controls[0].Select();
409 platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
410 }
411 PlatformControl s = platform_ctrl_get_last_visible();
412 s.Select();
413 platform_flow.ScrollControlIntoView(s);
414 platform_flow.ResumeLayout(false);
415 }
416 if (e.KeyCode == Keys.Enter)
417 {
418 // load this platform
419 platform_flow.Visible = false;
420 CurrentSelectedRom = c.Tag as IEmuConfig;
421 rom_flow.Visible = true;
422 rom_flow.BringToFront();
423 }
424 if (e.KeyCode == Keys.Back)
425 {
426 this.Close();
427 }
428 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
429 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
430 {
431 platform_flow.SuspendLayout();
432 char t = (char)e.KeyCode;
433 PlatformControl ctrl = (platform_flow.GetNextControl(CurrentPlatformControl, true) as PlatformControl);
434 if (ctrl == null) { ctrl = (platform_flow.GetNextControl(platform_flow.Controls[0], true) as PlatformControl); }
435 bool found = false;
436 PlatformControl pc = CurrentPlatformControl;
437 bool wrapped = false;
438 bool not_found = true;
439 while (!found)
440 {
441 if (wrapped)
442 {
443 foreach (Control ctl in platform_flow.Controls)
444 {
445 PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
446 }
447 if (not_found) { found = true; }
448 }
449 ctrl = (platform_flow.GetNextControl(pc, true) as PlatformControl);
450 if (ctrl == null)
451 {
452 ctrl = platform_flow.Controls[0] as PlatformControl;
453 wrapped = true;
454 }
455 if (ctrl.PlatformName.ToLower().StartsWith(t.ToString().ToLower()))
456 {
457 platform_flow.ScrollControlIntoView(ctrl);
458 ctrl.Select();
459 found = true;
460 }
461 pc = ctrl;
462 }
463 platform_flow.ResumeLayout(false);
464 }
465 }
466
467 private void platform_flow_VisibleChanged(object sender, EventArgs e)
468 {
469 if (!platform_flow.Visible) return;
470 platform_flow.Controls.Clear();
471 platform_flow.BringToFront();
472 Stopwatch t = new Stopwatch();
473 t.Start();
474 platformWorker.RunWorkerAsync(t);
475 }
476
477 private void rom_flow_VisibleChanged(object sender, EventArgs e)
478 {
479 if (!rom_flow.Visible) return;
480 rom_flow.Controls.Clear();
481 rom_flow.BringToFront();
482 Stopwatch t = new Stopwatch();
483 t.Start();
484 gameWorker.RunWorkerAsync(t);
485 }
486
487 void game_ctrl_LostFocus(object sender, EventArgs e)
488 {
489 GameControl c = sender as GameControl;
490 c.BorderStyle = BorderStyle.None;
491 }
492
493 void game_ctrl_GotFocus(object sender, EventArgs e)
494 {
495 GameControl c = sender as GameControl;
496 c.BorderStyle = BorderStyle.FixedSingle;
497 CurrentGameControl = c;
498 }
499
500 private GameControl game_ctrl_get_last_visible()
501 {
502 GameControl s = new GameControl();
503 foreach (GameControl c in rom_flow.Controls)
504 {
505 if (c.Bounds.IntersectsWith(rom_flow.Bounds))
506 s = c;
507 }
508 return s;
509 }
510 private PlatformControl platform_ctrl_get_last_visible()
511 {
512 PlatformControl s = new PlatformControl();
513 foreach (PlatformControl c in platform_flow.Controls)
514 {
515 if (c.Bounds.IntersectsWith(platform_flow.Bounds))
516 s = c;
517 }
518 return s;
519 }
520
521
522 #region Background Workers
523
524 private int GetFormWidth()
525 {
526 if (this.InvokeRequired)
527 {
528 return Convert.ToInt32(this.Invoke((MethodInvoker)delegate() { GetFormWidth(); }));
529 }
530 else
531 {
532 return this.Width;
533 }
534 }
535 private Font GetFormFont()
536 {
537 if (this.InvokeRequired)
538 {
539 return (this.Invoke(new Delegate_GetFormFont(GetFormFont)) as Font);
540 }
541 else
542 {
543 return this.Font;
544 }
545 }
546
547 private Font ResizeFont(Font font, float size)
548 {
549 if (this.InvokeRequired)
550 {
551 return (this.Invoke(new Delegate_ResizeFont(ResizeFont), new object[] { font, size })as Font);
552 }
553 else
554 {
555 return new Font(font.FontFamily, size);
556 }
557 }
558
559 //private void AddPlatformControl(Control c)
560 //{
561 // if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
562 // else
563 // {
564 // platform_flow.Controls.Add(c);
565 // }
566 //}
567 //private void UpdatePlatformControls()
568 //{
569 // //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); }
570 // //else { this.Update(); }
571 //}
572 //private void AddGameControl(Control c)
573 //{
574 // if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); }
575 // else
576 // {
577 // rom_flow.Controls.Add(c);
578 // }
579 //}
580 //private void UpdateGameControls()
581 //{
582 // //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); }
583 // //else { this.Update(); }
584 //}
585 #region gameWorker
586 private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
587 private object gameimage_lock = new object();
588 private void gameWorker_DoWork(object sender, DoWorkEventArgs e)
589 {
590 Stopwatch t = e.Argument as Stopwatch;
591 RomParser parser = new RomParser(CurrentSelectedRom);
592
593 CustomProgressBar bar = new CustomProgressBar();
594 bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
595 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
596 bar.ShowPercentageLabel = false;
597 #endif
598 bar.ProgressColor = Color.LimeGreen;
599 bar.Dock = DockStyle.Top;
600
601 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.SuspendLayout(); }); } else { rom_flow.SuspendLayout(); }
602
603 if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
604 else { this.Controls.Add(bar); }
605 bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
606
607 double count = 0;
608 double total_count = parser.Roms.Count;
609 foreach (IRomConfig config in parser.Roms)
610 {
611 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
612 GameControl game_ctrl = new GameControl();
613 game_ctrl.Font = GetFormFont();
614 game_ctrl.Dock = DockStyle.Top;
615 game_ctrl.Width = this.Width - 10;
616 game_ctrl.Tag = config;
617 try
618 {
619 lock (gameimage_lock)
620 {
621 game_ctrl.GameImage = config.RomImage == null ? (Image)DefaultGameImage.Clone() : (Image)config.RomImage.Clone();
622 config.ReleaseRomImageResource();
623 }
624 }
625 catch (Exception ex)
626 {
627 throw ex;
628 }
629 if (CurrentSelectedRom.PlatformNameShort == "Favorites")
630 {
631 //game_ctrl.GameName = config.RomTitle;
632 game_ctrl.GameName = RomFavorite.GetRomTitleFromConfig(config);
633 }
634 else
635 {
636 game_ctrl.GameName = config.RomTitle;
637 }
638 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
639 game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
640 game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
641 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); }
642 else { rom_flow.Controls.Add(game_ctrl); }
643 count++;
644 }
645 bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
646 if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
647 e.Result = t;
648 if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.ResumeLayout(false); }); } else { rom_flow.ResumeLayout(false); }
649 parser.Dispose();
650 }
651 private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
652 private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
653 {
654 Stopwatch t = e.Result as Stopwatch;
655 if (rom_flow.Controls.Count == 0)
656 {
657 GameControl game_ctrl = new GameControl();
658 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
659 game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
660 game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
661 game_ctrl.Font = GetFormFont();
662 game_ctrl.Dock = DockStyle.Top;
663 game_ctrl.Width = this.Width - 10;
664 game_ctrl.GameName = "You haven't favorited any games, select a game and then press CTRL+F to favorite it";
665 rom_flow.Controls.Add(game_ctrl);
666 }
667 rom_flow.Controls[0].Select();
668 t.Stop();
669 gLog.Profiler.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
670 }
671 #endregion
672 #region platformWorker
673 private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
674 private object platformimage_lock = new object();
675 private void platformWorker_DoWork(object sender, DoWorkEventArgs e)
676 {
677 Stopwatch t = e.Argument as Stopwatch;
678 PlatformParser parser = new PlatformParser(Config.RomPath);
679 double count = 0;
680 double total_count = parser.Platforms.Count;
681 CustomProgressBar bar = new CustomProgressBar();
682 bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
683 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
684 bar.ShowPercentageLabel = false;
685 #endif
686 bar.ProgressColor = Color.LimeGreen;
687 bar.Dock = DockStyle.Top;
688
689 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.SuspendLayout(); }); } else { platform_flow.SuspendLayout(); }
690
691 if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
692 else { this.Controls.Add(bar); }
693 bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
694 foreach (IEmuConfig config in parser.Platforms)
695 {
696 bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
697
698 PlatformControl platform_ctrl = new PlatformControl();
699 platform_ctrl.Font = GetFormFont();
700 platform_ctrl.Dock = DockStyle.Top;
701 platform_ctrl.Width = this.Width - 10;
702 platform_ctrl.Tag = config;
703 try
704 {
705 lock (platformimage_lock)
706 {
707 platform_ctrl.PlatformImage = config.PlatformImage == null ? (Image)DefaultPlatformImage.Clone() : (Image)config.PlatformImage.Clone();
708 config.ReleasePlatformImageResource();
709 }
710 }
711 catch (Exception ex)
712 {
713 throw ex;
714 }
715 platform_ctrl.PlatformName = config.ToString();
716 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
717 platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
718 platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
719 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); }
720 else { platform_flow.Controls.Add(platform_ctrl); }
721 count++;
722 }
723 bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
724 if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
725 e.Result = t;
726 if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.ResumeLayout(false); }); } else { platform_flow.ResumeLayout(false); }
727 parser.Dispose();
728 }
729 private void platformWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
730 private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
731 {
732 Stopwatch t = e.Result as Stopwatch;
733 if (platform_flow.Controls.Count == 0)
734 {
735 PlatformControl platform_ctrl = new PlatformControl();
736 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
737 platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
738 platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
739 platform_ctrl.Font = GetFormFont();
740 platform_ctrl.Dock = DockStyle.Top;
741 platform_ctrl.Width = this.Width - 10;
742 platform_ctrl.PlatformName = string.Format("You don't have any roms in your rompath: '{0}'",Config.RomPath);
743 platform_flow.Controls.Add(platform_ctrl);
744 }
745 platform_flow.Controls[0].Select();
746 gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
747 }
748 #endregion
749
750 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
751 {
752 Cursor.Show();
753 }
754 #endregion
755 }
756 }

  ViewVC Help
Powered by ViewVC 1.1.22