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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 377 - (show annotations) (download)
Thu May 2 03:09:26 2019 UTC (9 months, 2 weeks ago) by william
File size: 43399 byte(s)
update emuxportal -- fix empty rom image path errors when copying a rom to local when it has no rom image
1 #define HAVE_X11_BORDERSTYLE_ERROR // indicates that there is an error with Control.set_InternalBorderStyle resulting in an X11 Error BadWindow (invalid Window parameter)
2
3 //#define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden
4 //#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar
5
6 #define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
7 //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
8
9 using System;
10 using System.Collections.Generic;
11 using System.ComponentModel;
12 using System.Data;
13 using System.Drawing;
14 using System.Linq;
15 using System.Text;
16 using System.Windows.Forms;
17 using EmuXPortal.Api;
18 using System.Diagnostics;
19 using System.Reflection;
20 using System.Threading;
21 using Utilities.TransparentControls;
22 using Enterprise.Logging;
23 using System.IO;
24 using Enterprise.CrossPlatform;
25
26 namespace EmuXPortal {
27 public partial class Form1 : Form {
28 static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR = System.Drawing.Color.Lime;
29 static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR_ERROR = System.Drawing.Color.Yellow;
30 static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR_LAUNCH = System.Drawing.Color.Blue;
31 static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR_MISSING = System.Drawing.Color.Red;
32
33
34 static bool bUserAbort = false;
35 static readonly Color SELECTED_CONTROL_BACKCOLOR = Color.SteelBlue;
36 const float PROGRESS_BAR_FONT_SIZE = 24;
37 private delegate Font Delegate_GetFormFont ();
38 private delegate Font Delegate_ResizeFont (Font font, float size);
39 IEmuConfig CurrentSelectedRom = null;
40 PlatformControl CurrentPlatformControl = null;
41 int SavedPlatformIndex = -1;
42 GameControl CurrentGameControl = null;
43 private CustomProgressBar progress_bar;
44 private IPlatformCache cache = null;
45
46 static bool OnAbort ()
47 {
48 return bUserAbort;
49 }
50 #region unhandled exception support
51 static void Application_Unhandled_ThreadException (object sender, ThreadExceptionEventArgs e)
52 {
53 UnhandledExceptionEventArgs uea = new UnhandledExceptionEventArgs (e.Exception, false);
54 UnhandledExceptionEventHandler (sender, uea);
55 }
56 static void UnhandledExceptionEventHandler (object sender, UnhandledExceptionEventArgs args)
57 {
58 Exception ex = (args.ExceptionObject as Exception);
59 if (sender == null) {
60 gLog.Error.WriteLine ("Caught an unhandled exception from an unkown source");
61 } else {
62 gLog.Error.WriteLine ("Caught an unhandled exception from type: {0}", sender.GetType ().Name);
63 }
64
65 if (ex == null) {
66 gLog.Error.WriteLine ("The exception object was null -- it probably is not derived from System.Exception");
67 } else {
68 ex = ex.GetBaseException ();
69 gLog.Error.WriteLine ("{0}:", ex.GetType ().Name);
70 gLog.Verbose.Error.WriteLine (ex.ToString ());
71 }
72
73 }
74 #endregion
75 public Form1 ()
76 {
77 InitializeComponent ();
78 this.progress_bar = new CustomProgressBar ();
79 this.KeyPreview = true;
80
81 #region logging support
82 string log_path = Application.StartupPath;
83 string log_filename = string.Format ("{0}.log", typeof (Form1).Assembly.GetName ().Name);
84 FileInfo log_file = new FileInfo (OSInfo.FormatPath (string.Format (@"{0}\{1}", log_path, log_filename)));
85
86 gLog.CreateLog (log_file.Name, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs> (Log_OnFlush));
87 #if DEBUG
88 LogLevel gLevel = gLog.LogLevel;
89 #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
90 gLevel &= ~LogLevel.kLogLevel_VerboseDebug;
91 #else
92 gLevel |= LogLevel.kLogLevel_VerboseDebug;
93 #endif
94 gLevel |= LogLevel.kLogLevel_Debug;
95 gLog.SetLogLevel (gLevel);
96 #else
97 LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
98 // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
99 #if DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG
100 gLevel &= ~LogLevel.kLogLevel_Debug;
101 #else
102 gLevel |= LogLevel.kLogLevel_Debug;
103 #endif
104 gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode
105 gLog.SetLogLevel(gLevel);
106 #endif
107 #endregion
108
109 #region unhandled exception support
110 // AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
111 // Application.ThreadException += Application_Unhandled_ThreadException;
112 #endregion
113
114 platform_flow.Dock = DockStyle.Fill;
115 rom_flow.Dock = DockStyle.Fill;
116
117 // this.PreviewKeyDown += Form1_PreviewKeyDown;
118 // this.KeyPreview = true;
119 //progress_bar.PreviewKeyDown += Progress_bar_PreviewKeyDown;
120 this.KeyDown += Form1_KeyDown;
121
122 }
123
124 void Form1_KeyDown (object sender, KeyEventArgs e)
125 {
126 if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
127 bAbortRomCopyToLocalCache = true; // this will cancel any copy operations
128 }
129 }
130
131
132
133
134 #region logging support
135 void Log_OnFlush (object sender, LoggerOnFlushEventArgs e) { OnLogFlush (e.Buffer); }
136 void OnLogFlush (string logmessage)
137 {
138 //if (this.IsDisposed) { return; }
139 ////UpdateStatus(logmessage);
140 ////UpdateLogOutput(logmessage);
141 //Application.DoEvents();
142 }
143 #endregion
144
145 private bool bCachedLoaded = false;
146 private bool OnCacheLoaded ()
147 {
148 return bCachedLoaded;
149 }
150
151 private void Form1_Load (object sender, EventArgs e)
152 {
153
154 SplashLoader loader = new SplashLoader (new AbortEvent (OnCacheLoaded));
155 loader.Show ();
156 cache = PlatformCache.Create (new AbortEvent (OnAbort));
157 Config.LoadConfig (cache);
158 Config.InitializePresentationForm (this);
159 bCachedLoaded = true;
160
161 }
162 private void Form1_Shown (object sender, EventArgs e)
163 {
164 platform_flow.Visible = true;
165 #if !DISABLE_CURSOR_HIDE
166 Cursor.Hide ();
167 #else
168 Cursor.Show();
169 #endif
170
171 }
172 private bool bAbortRomCopyToLocalCache = false;
173 private bool OnAbortRomCopyToLocalCache ()
174 {
175 return bAbortRomCopyToLocalCache;
176 }
177
178 private void DeleteRomFromLocalCache (string rom_file, string rom_image)
179 {
180 progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
181 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
182 progress_bar.ShowPercentageLabel = false;
183 #endif
184 progress_bar.ProgressColor = Color.LimeGreen;
185 progress_bar.Dock = DockStyle.Top;
186 if (this.InvokeRequired) {
187 this.Invoke ((MethodInvoker)delegate () {
188 this.Controls.Add (progress_bar);
189 });
190 } else {
191 this.Controls.Add (progress_bar);
192 }
193 progress_bar.Invoke (new MethodInvoker (delegate {
194 progress_bar.Margin = new System.Windows.Forms.Padding (0);
195 progress_bar.Size = new Size (GetFormWidth () - 25, 100);
196 }));
197 Application.DoEvents ();
198 if (!string.IsNullOrEmpty (rom_image)) {
199 if (rom_image.ToLower ().Contains (Config.RomPath.ToLower ())) {
200 gLog.Warn.WriteLine ("Not deleteing rom image in path: {0}", rom_image);
201 return;
202 }
203 progress_bar.Message = string.Format ("Deleting local rom image: {0}", EmuXPortal.Api.Win32.CompactPath (rom_image));
204 File.Delete (rom_image);
205 progress_bar.Value = 50;
206
207 }
208 if (!string.IsNullOrEmpty (rom_file)) {
209 if (rom_image.ToLower ().Contains (Config.RomPath.ToLower ())) {
210 gLog.Warn.WriteLine ("Not deleteing rom file in path: {0}", rom_file);
211 return;
212 }
213 progress_bar.Message = string.Format ("Deleting local rom file: {0}", EmuXPortal.Api.Win32.CompactPath (rom_file));
214 File.Delete (rom_file);
215 progress_bar.Value = 100;
216 }
217 if (this.InvokeRequired) {
218 this.Invoke ((MethodInvoker)delegate () {
219 this.Controls.Remove (progress_bar);
220 });
221 } else {
222 this.Controls.Remove (progress_bar);
223 }
224 Application.DoEvents ();
225 }
226 private void CopyRomToLocalCache (string src_rom_file, string dst_rom_file, string src_rom_image, string dst_rom_image)
227 {
228 bAbortRomCopyToLocalCache = false; // reset the copy abort flag
229 progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
230 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
231 progress_bar.ShowPercentageLabel = false;
232 #endif
233 progress_bar.ProgressColor = Color.LimeGreen;
234 progress_bar.Dock = DockStyle.Top;
235 if (this.InvokeRequired) {
236 this.Invoke ((MethodInvoker)delegate () {
237 this.Controls.Add (progress_bar);
238 });
239 } else {
240 this.Controls.Add (progress_bar);
241 }
242 progress_bar.Invoke (new MethodInvoker (delegate {
243 progress_bar.Margin = new System.Windows.Forms.Padding (0);
244 progress_bar.Size = new Size (GetFormWidth () - 25, 100);
245 }));
246 Application.DoEvents ();
247 FileProgressCopier cp = null;
248 if (!string.IsNullOrEmpty (src_rom_image) && !string.IsNullOrEmpty (dst_rom_image)) {
249 bAbortRomCopyToLocalCache = false;
250 cp = new FileProgressCopier (src_rom_image, dst_rom_image, new CopyProgressEvent (OnFileCopyProgress), new AbortEvent (OnAbortRomCopyToLocalCache));
251 cp.Start ();
252 while (!cp.CopyFinished) {
253 Application.DoEvents ();
254 }
255 }
256 if (!string.IsNullOrEmpty (src_rom_file) && !string.IsNullOrEmpty (dst_rom_file)) {
257 bAbortRomCopyToLocalCache = false;
258 cp = new FileProgressCopier (src_rom_file, dst_rom_file, new CopyProgressEvent (OnFileCopyProgress), new AbortEvent (OnAbortRomCopyToLocalCache));
259 cp.Start ();
260 while (!cp.CopyFinished) {
261 Application.DoEvents ();
262 }
263 }
264 if (this.InvokeRequired) {
265 this.Invoke ((MethodInvoker)delegate () {
266 this.Controls.Remove (progress_bar);
267 });
268 } else {
269 this.Controls.Remove (progress_bar);
270 }
271 Application.DoEvents ();
272 }
273 public void OnFileCopyProgress (object sender, int progress, string message)
274 {
275 //gLog.Debug.WriteLine("{0} [{1}%]", message, progress);
276
277 if (progress_bar.InvokeRequired) {
278 progress_bar.Invoke (new MethodInvoker (delegate {
279 progress_bar.Message = message;
280 progress_bar.Value = progress;
281 progress_bar.Update ();
282 Application.DoEvents ();
283 }));
284 } else {
285 progress_bar.Message = message;
286 progress_bar.Value = progress;
287 progress_bar.Update ();
288 Application.DoEvents ();
289 }
290 }
291 void ReleasePlatformControlStreams ()
292 {
293 foreach (var c in platform_flow.Controls) {
294 if (c.GetType () == typeof (PlatformControl)) {
295 PlatformControl pc = (c as PlatformControl);
296 if (pc != null) {
297 pc.ReleasePlatformStream ();
298 }
299 }
300 }
301 }
302 void ReleaseGameControlStreams ()
303 {
304 foreach (var c in rom_flow.Controls) {
305 if (c.GetType () == typeof (GameControl)) {
306 GameControl gc = (c as GameControl);
307 if (gc != null) {
308 gc.ReleaseGameStream ();
309 }
310 }
311 }
312 }
313 void platform_ctrl_LostFocus (object sender, EventArgs e)
314 {
315 PlatformControl c = sender as PlatformControl;
316 if (c != null) {
317 #if !HAVE_X11_BORDERSTYLE_ERROR
318 c.BorderStyle = BorderStyle.None;
319 #endif
320 c.BackColor = this.BackColor;
321 }
322 }
323
324 void platform_ctrl_GotFocus (object sender, EventArgs e)
325 {
326 PlatformControl c = sender as PlatformControl;
327 if (c != null) {
328 #if !HAVE_X11_BORDERSTYLE_ERROR
329 c.BorderStyle = BorderStyle.FixedSingle;
330 #endif
331 c.BackColor = SELECTED_CONTROL_BACKCOLOR;
332 CurrentPlatformControl = c;
333 }
334 }
335
336 void game_ctrl_PreviewKeyDown (object sender, PreviewKeyDownEventArgs e)
337 {
338 //gLog.Verbose.Debug.WriteLine ("game_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
339 GameControl c = sender as GameControl;
340
341 int changeAmount = 0;
342 int currentPosition = 0;
343 IRomConfig config = null;
344 if (e.KeyCode == Keys.C && (e.Modifiers & Keys.Control) == Keys.Control) {
345 config = (c.Tag as IRomConfig);
346 if (config != null) {
347 string platform_short = config.EmuConfig.PlatformNameShort;
348 string rom_file = config.RomFile;
349 string rom_image = config.RomImage;
350
351 string rom_filename = "";
352 string rom_imagefilename = "";
353 FileInfo fi = null;
354 try {
355 if (!string.IsNullOrEmpty (rom_file)) {
356 fi = new FileInfo (rom_file);
357 rom_filename = fi.Name;
358 }
359 } finally {
360 fi = null;
361 }
362 try {
363 if (!string.IsNullOrEmpty (rom_image)) {
364 fi = new FileInfo (rom_image);
365 rom_imagefilename = fi.Name;
366 }
367 } finally {
368 fi = null;
369 }
370
371 string local_path = Config.LocalRomPath.TrimEnd (new char [] { '/' });
372 string local_rom_path = string.Format ("{0}/{1}", local_path, platform_short);
373 string local_romfile = string.IsNullOrEmpty(rom_filename) ? "" : OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_filename));
374 string local_romimage = string.IsNullOrEmpty(rom_imagefilename) ? "" : OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_imagefilename));
375
376 if (string.IsNullOrEmpty (local_romfile)) {
377 gLog.Error.WriteLine ("Local rom file could not be found. [src rom={0}]", rom_file);
378 return;
379 }
380
381 // create the local rom path for this platform
382 DirectoryInfo di = new DirectoryInfo (local_rom_path);
383 if (!di.Exists) {
384 di.Create ();
385 }
386 this.Enabled = false;
387 CopyRomToLocalCache (rom_file, local_romfile, rom_image, local_romimage);
388 this.Enabled = true;
389 }
390 }
391 if (e.KeyCode == Keys.D && (e.Modifiers & Keys.Control) == Keys.Control) {
392 config = (c.Tag as IRomConfig);
393 if (config != null) {
394 string platform_short = config.EmuConfig.PlatformNameShort;
395 string rom_file = config.RomFile;
396 string rom_image = config.RomImage;
397
398 string rom_filename = "";
399 string rom_imagefilename = "";
400 FileInfo fi = null;
401 try {
402 fi = new FileInfo (rom_file);
403 rom_filename = fi.Name;
404 } finally {
405 fi = null;
406 }
407 try {
408 fi = new FileInfo (rom_image);
409 rom_imagefilename = fi.Name;
410 } finally {
411 fi = null;
412 }
413 string local_path = Config.LocalRomPath.TrimEnd (new char [] { '/' });
414 string local_rom_path = string.Format ("{0}/{1}", local_path, platform_short);
415 string local_romfile = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_filename));
416 string local_romimage = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_imagefilename));
417 this.Enabled = false;
418 DeleteRomFromLocalCache (local_romfile, local_romimage);
419 this.Enabled = true;
420 }
421 }
422 if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control) {
423 config = c.Tag as IRomConfig;
424 if (config == null) {
425 gLog.Error.WriteLine ("Unable to add/remove from/to favorites (config) is null");
426 } else {
427 var isFavorite = RomFavorite.IsFavorite (config);
428 if (isFavorite) {
429 // add to favorites
430 //gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
431 if (!RomFavorite.RemoveFavorite (config)) {
432 gLog.Error.WriteLine ("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
433 } else {
434 gLog.Info.WriteLine ("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
435 if (config.EmuConfig.PlatformNameShort == "Favorites") {
436 var parent = c.Parent;
437 if (parent != null) {
438 parent.Controls.Remove (c);
439 if (parent.Controls.Count > 0) {
440 var next_ctrl = parent.Controls [0];
441 if (next_ctrl != null) {
442 next_ctrl.Select ();
443 }
444 }
445 }
446 }
447 }
448 } else {
449 // add to favorites
450 //gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
451 if (!RomFavorite.AddFavorite (config)) {
452 gLog.Error.WriteLine ("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
453 } else {
454 gLog.Info.WriteLine ("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
455 }
456 }
457 //gLog.Debug.WriteLine("Updateing favorites");
458 if (!RomFavorite.UpdateFavorites (cache)) {
459 gLog.Error.WriteLine ("Failed to update favorites");
460 } else {
461 gLog.Info.WriteLine ("Updated favorites");
462 }
463 }
464 return; // stop processing other keys
465
466 }
467 if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
468 if (OSInfo.OSIsUnix) {
469 rom_flow.SuspendLayout ();
470 var ctl = game_ctrl_get_previous_control (true);
471 rom_flow.ScrollControlIntoView (ctl);
472 rom_flow.ResumeLayout (false);
473 }
474 }
475 if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
476 if (OSInfo.OSIsUnix) {
477 rom_flow.SuspendLayout ();
478 var ctl = game_ctrl_get_next_control (true);
479 rom_flow.ScrollControlIntoView (ctl);
480 rom_flow.ResumeLayout (false);
481 }
482 }
483 if (e.KeyCode == Keys.Home) {
484 rom_flow.SuspendLayout ();
485 rom_flow.Controls [0].Select ();
486 rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
487 rom_flow.ResumeLayout (false);
488 }
489 if (e.KeyCode == Keys.End) {
490 rom_flow.SuspendLayout ();
491 rom_flow.Controls [rom_flow.Controls.Count - 1].Select ();
492 rom_flow.ScrollControlIntoView (rom_flow.Controls [rom_flow.Controls.Count - 1]);
493 rom_flow.ResumeLayout (false);
494 }
495 if (e.KeyCode == Keys.PageUp) {
496 rom_flow.SuspendLayout ();
497 changeAmount = rom_flow.VerticalScroll.LargeChange;
498 currentPosition = rom_flow.VerticalScroll.Value;
499 if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum) {
500 try {
501 rom_flow.VerticalScroll.Value -= changeAmount;
502 } catch {
503 rom_flow.Controls [0].Select ();
504 rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
505 rom_flow.PerformLayout ();
506 return;
507 }
508 } else {
509 rom_flow.Controls [0].Select ();
510 rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
511 }
512 GameControl s = game_ctrl_get_last_visible ();
513 s.Select ();
514 rom_flow.ScrollControlIntoView (s);
515 rom_flow.ResumeLayout (false);
516 }
517 if (e.KeyCode == Keys.PageDown) {
518 rom_flow.SuspendLayout ();
519 changeAmount = rom_flow.VerticalScroll.LargeChange;
520 currentPosition = rom_flow.VerticalScroll.Value;
521 if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum) {
522 try {
523 rom_flow.VerticalScroll.Value += changeAmount;
524 } catch {
525 rom_flow.Controls [0].Select ();
526 rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
527 rom_flow.PerformLayout ();
528 return;
529 }
530 } else {
531 rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
532 }
533 GameControl s = game_ctrl_get_last_visible ();
534 s.Select ();
535 rom_flow.ScrollControlIntoView (s);
536 rom_flow.ResumeLayout (false);
537 }
538
539 if (e.KeyCode == Keys.Enter) {
540 config = c.Tag as IRomConfig;
541 if (config.RomExists) {
542 c.TextForeColor = DEFAULT_TEXTFORECOLOR_LAUNCH;
543 string gamename = c.GameName;
544 c.GameName = string.Format ("{0} (Loading...)", gamename);
545 bool game_launched = true;
546 using (Process p = new Process ()) {
547 string binary = "";
548 string arguments = "";
549 if (!string.IsNullOrEmpty (config.EmuConfig.EmuBinaryPath)) {
550 binary = config.EmuConfig.EmuBinaryPath;
551 arguments = EmuConfigLoader.GetEMUOptions (config);
552 }
553 if (!string.IsNullOrEmpty (config.EmuConfig.GameExe)) {
554 binary = config.EmuConfig.GameExe;
555 arguments = config.EmuConfig.GameExeArgs;
556 }
557 if (string.IsNullOrEmpty (binary)) {
558 gLog.Warn.WriteLine ("Cannot launch this rom file -- missing arguments");
559 game_launched = false;
560 } else {
561 p.StartInfo.FileName = binary;
562 p.StartInfo.Arguments = arguments == null ? "" : arguments;
563 p.Start ();
564 // wait for exit of game
565 p.WaitForExit ();
566 c.TextForeColor = DEFAULT_TEXTFORECOLOR;
567 c.GameName = gamename;
568 }
569 }
570 if (!game_launched) {
571 c.TextForeColor = DEFAULT_TEXTFORECOLOR_ERROR;
572 c.GameName = string.Format ("{0} (Error While Loading...)", gamename);
573 }
574 } else {
575 c.TextForeColor = Color.Red;
576 }
577 }
578 if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
579
580 bAbortRomCopyToLocalCache = true; // this will cancel any copy operations
581 ReleaseGameControlStreams ();
582 SavedPlatformIndex = platform_flow.Controls.IndexOf (CurrentPlatformControl);
583 rom_flow.Visible = false;
584 platform_flow.Visible = true;
585 }
586
587 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
588 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) {
589 rom_flow.SuspendLayout ();
590 char t = (char)e.KeyCode;
591 GameControl ctrl = (rom_flow.GetNextControl (CurrentGameControl, true) as GameControl);
592 if (ctrl == null) { ctrl = (rom_flow.GetNextControl (rom_flow.Controls [0], true) as GameControl); }
593 bool found = false;
594 GameControl pc = CurrentGameControl;
595 bool wrapped = false;
596 bool not_found = true;
597 while (!found) {
598 if (wrapped) {
599 foreach (Control ctl in rom_flow.Controls) {
600 GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower ().StartsWith (t.ToString ().ToLower ())) { not_found = false; }
601 }
602 if (not_found) { found = true; }
603 }
604 ctrl = (rom_flow.GetNextControl (pc, true) as GameControl);
605 if (ctrl == null) {
606 ctrl = rom_flow.Controls [0] as GameControl;
607 wrapped = true;
608 }
609 if (ctrl.GameName.ToLower ().StartsWith (t.ToString ().ToLower ())) {
610 rom_flow.ScrollControlIntoView (ctrl);
611 ctrl.Select ();
612 found = true;
613 }
614 pc = ctrl;
615 }
616 rom_flow.ResumeLayout (false);
617 }
618 }
619 void platform_ctrl_PreviewKeyDown (object sender, PreviewKeyDownEventArgs e)
620 {
621 //gLog.Verbose.Debug.WriteLine ("platform_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
622 PlatformControl c = sender as PlatformControl;
623 int changeAmount = 0;
624 int currentPosition = 0;
625 if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
626 if (OSInfo.OSIsUnix) {
627 platform_flow.SuspendLayout ();
628 var ctl = platform_ctrl_get_previous_control (true);
629 platform_flow.ScrollControlIntoView (ctl);
630 platform_flow.ResumeLayout (false);
631 }
632 }
633 if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
634 if (OSInfo.OSIsUnix) {
635 platform_flow.SuspendLayout ();
636 var ctl = platform_ctrl_get_next_control (true);
637 platform_flow.ScrollControlIntoView (ctl);
638 platform_flow.ResumeLayout (false);
639 }
640 }
641 if (e.KeyCode == Keys.Home) {
642 platform_flow.SuspendLayout ();
643 platform_flow.Controls [0].Select ();
644 platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
645 platform_flow.ResumeLayout (false);
646 }
647 if (e.KeyCode == Keys.End) {
648 platform_flow.SuspendLayout ();
649 platform_flow.Controls [platform_flow.Controls.Count - 1].Select ();
650 platform_flow.ScrollControlIntoView (platform_flow.Controls [platform_flow.Controls.Count - 1]);
651 platform_flow.ResumeLayout (false);
652 }
653 if (e.KeyCode == Keys.PageUp) {
654 platform_flow.SuspendLayout ();
655 changeAmount = platform_flow.VerticalScroll.LargeChange;
656 currentPosition = platform_flow.VerticalScroll.Value;
657 if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum) {
658 platform_flow.VerticalScroll.Value -= changeAmount;
659 } else {
660 platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum;
661 }
662 PlatformControl s = platform_ctrl_get_last_visible ();
663 s.Select ();
664 platform_flow.ScrollControlIntoView (s);
665 platform_flow.ResumeLayout (false);
666 }
667 if (e.KeyCode == Keys.PageDown) {
668 platform_flow.SuspendLayout ();
669 changeAmount = platform_flow.VerticalScroll.LargeChange;
670 currentPosition = platform_flow.VerticalScroll.Value;
671 if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum) {
672 try {
673 platform_flow.VerticalScroll.Value += changeAmount;
674 } catch {
675 platform_flow.Controls [0].Select ();
676 platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
677 rom_flow.PerformLayout ();
678 return;
679 }
680 } else {
681 platform_flow.Controls [0].Select ();
682 platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
683 }
684 PlatformControl s = platform_ctrl_get_last_visible ();
685 s.Select ();
686 platform_flow.ScrollControlIntoView (s);
687 platform_flow.ResumeLayout (false);
688 }
689 if (e.KeyCode == Keys.Enter) {
690 ReleasePlatformControlStreams ();
691 // load this platform
692 platform_flow.Visible = false;
693 CurrentSelectedRom = c.Tag as IEmuConfig;
694 rom_flow.Visible = true;
695 rom_flow.BringToFront ();
696 }
697 if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
698 bAbortRomCopyToLocalCache = true;
699 ReleasePlatformControlStreams ();
700 this.Close ();
701 }
702 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
703 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) {
704 platform_flow.SuspendLayout ();
705 char t = (char)e.KeyCode;
706 PlatformControl ctrl = (platform_flow.GetNextControl (CurrentPlatformControl, true) as PlatformControl);
707 if (ctrl == null) { ctrl = (platform_flow.GetNextControl (platform_flow.Controls [0], true) as PlatformControl); }
708 bool found = false;
709 PlatformControl pc = CurrentPlatformControl;
710 bool wrapped = false;
711 bool not_found = true;
712 while (!found) {
713 if (wrapped) {
714 foreach (Control ctl in platform_flow.Controls) {
715 PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower ().StartsWith (t.ToString ().ToLower ())) { not_found = false; }
716 }
717 if (not_found) { found = true; }
718 }
719 ctrl = (platform_flow.GetNextControl (pc, true) as PlatformControl);
720 if (ctrl == null) {
721 ctrl = platform_flow.Controls [0] as PlatformControl;
722 wrapped = true;
723 }
724 if (ctrl.PlatformName.ToLower ().StartsWith (t.ToString ().ToLower ())) {
725 platform_flow.ScrollControlIntoView (ctrl);
726 ctrl.Select ();
727 found = true;
728 }
729 pc = ctrl;
730 }
731 platform_flow.ResumeLayout (false);
732 }
733 }
734
735 private void platform_flow_VisibleChanged (object sender, EventArgs e)
736 {
737 if (!platform_flow.Visible) return;
738 platform_flow.Controls.Clear ();
739 platform_flow.BringToFront ();
740 Stopwatch t = new Stopwatch ();
741 t.Start ();
742 platformWorker.RunWorkerAsync (t);
743 }
744
745 private void rom_flow_VisibleChanged (object sender, EventArgs e)
746 {
747 if (!rom_flow.Visible) return;
748 rom_flow.Controls.Clear ();
749 rom_flow.BringToFront ();
750 Stopwatch t = new Stopwatch ();
751 t.Start ();
752 gameWorker.RunWorkerAsync (t);
753 }
754
755 void game_ctrl_LostFocus (object sender, EventArgs e)
756 {
757 GameControl c = sender as GameControl;
758 #if !HAVE_X11_BORDERSTYLE_ERROR
759 c.BorderStyle = BorderStyle.None;
760 #endif
761 c.BackColor = this.BackColor;
762 }
763
764 void game_ctrl_GotFocus (object sender, EventArgs e)
765 {
766 GameControl c = sender as GameControl;
767 #if !HAVE_X11_BORDERSTYLE_ERROR
768 c.BorderStyle = BorderStyle.FixedSingle;
769 #endif
770 c.BackColor = SELECTED_CONTROL_BACKCOLOR;
771 CurrentGameControl = c;
772 }
773
774 private GameControl game_ctrl_get_last_visible ()
775 {
776 GameControl s = new GameControl ();
777 foreach (GameControl c in rom_flow.Controls) {
778 if (c.Bounds.IntersectsWith (rom_flow.Bounds))
779 s = c;
780 }
781 return s;
782 }
783 private PlatformControl platform_ctrl_get_last_visible ()
784 {
785 PlatformControl s = new PlatformControl ();
786 foreach (PlatformControl c in platform_flow.Controls) {
787 if (c.Bounds.IntersectsWith (platform_flow.Bounds))
788 s = c;
789 }
790 return s;
791 }
792 private PlatformControl platform_ctrl_get_next_control (bool update_control)
793 {
794 PlatformControl s = new PlatformControl ();
795 int index = platform_flow.Controls.IndexOf (CurrentPlatformControl);
796 index = index + 1;
797 if (index < 0) {
798 index = platform_flow.Controls.Count - 1;
799 }
800 if (index > platform_flow.Controls.Count - 1) {
801 index = 0;
802 }
803 s = platform_flow.Controls [index] as PlatformControl;
804 if (update_control) {
805 CurrentPlatformControl = s;
806 s.Select ();
807 }
808 return s;
809 }
810 private PlatformControl platform_ctrl_get_previous_control (bool update_control)
811 {
812 PlatformControl s = null;
813 int index = platform_flow.Controls.IndexOf (CurrentPlatformControl);
814 index = index - 1;
815 if (index < 0) {
816 index = platform_flow.Controls.Count - 1;
817 }
818 if (index > platform_flow.Controls.Count - 1) {
819 index = 0;
820 }
821 s = platform_flow.Controls [index] as PlatformControl;
822 if (update_control) {
823 CurrentPlatformControl = s;
824 s.Select ();
825 }
826 return s;
827 }
828 private GameControl game_ctrl_get_next_control (bool update_control)
829 {
830 GameControl s = new GameControl ();
831 int index = rom_flow.Controls.IndexOf (CurrentGameControl);
832 index = index + 1;
833 if (index < 0) {
834 index = rom_flow.Controls.Count - 1;
835 }
836 if (index > rom_flow.Controls.Count - 1) {
837 index = 0;
838 }
839 s = rom_flow.Controls [index] as GameControl;
840 if (update_control) {
841 CurrentGameControl = s;
842 s.Select ();
843 }
844 return s;
845 }
846 private GameControl game_ctrl_get_previous_control (bool update_control)
847 {
848 GameControl s = new GameControl ();
849 int index = rom_flow.Controls.IndexOf (CurrentGameControl);
850 index = index - 1;
851 if (index < 0) {
852 index = rom_flow.Controls.Count - 1;
853 }
854 if (index > rom_flow.Controls.Count - 1) {
855 index = 0;
856 }
857 s = rom_flow.Controls [index] as GameControl;
858 if (update_control) {
859 CurrentGameControl = s;
860 s.Select ();
861 }
862 return s;
863 }
864
865
866 #region Background Workers
867
868 private int GetFormWidth ()
869 {
870 if (this.InvokeRequired) {
871 return Convert.ToInt32 (this.Invoke ((MethodInvoker)delegate () { GetFormWidth (); }));
872 } else {
873 return this.Width;
874 }
875 }
876 private Font GetFormFont ()
877 {
878 if (this.InvokeRequired) {
879 return (this.Invoke (new Delegate_GetFormFont (GetFormFont)) as Font);
880 } else {
881 return this.Font;
882 }
883 }
884
885 private Font ResizeFont (Font font, float size)
886 {
887 if (this.InvokeRequired) {
888 return (this.Invoke (new Delegate_ResizeFont (ResizeFont), new object [] { font, size }) as Font);
889 } else {
890 return new Font (font.FontFamily, size);
891 }
892 }
893
894 //private void AddPlatformControl(Control c)
895 //{
896 // if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
897 // else
898 // {
899 // platform_flow.Controls.Add(c);
900 // }
901 //}
902 //private void UpdatePlatformControls()
903 //{
904 // //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); }
905 // //else { this.Update(); }
906 //}
907 //private void AddGameControl(Control c)
908 //{
909 // if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); }
910 // else
911 // {
912 // rom_flow.Controls.Add(c);
913 // }
914 //}
915 //private void UpdateGameControls()
916 //{
917 // //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); }
918 // //else { this.Update(); }
919 //}
920 #region gameWorker
921 private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
922 private object gameimage_lock = new object ();
923 private void worker_progress_event (object event_source, ProgressEventArgs event_args)
924 {
925 //gLog.Debug.WriteLine ("worker_progress_event called!");
926 object user_object = event_args.GetUserObject ();
927 int progress = event_args.GetProgress ();
928 string message = event_args.GetUserMessage () == null ? "" : event_args.GetUserMessage ();
929 if (user_object != null) {
930 IRomConfig irc = (user_object as IRomConfig);
931 if (irc != null) {
932 gLog.Verbose.Debug.WriteLine ("Read Rom[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, irc);
933 } else {
934 IEmuConfig iec = (user_object as IEmuConfig);
935 if (iec != null) {
936 gLog.Verbose.Debug.WriteLine ("Read Platform[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, iec);
937 }
938 }
939 }
940 if (progress_bar.InvokeRequired) {
941 progress_bar.Invoke (new MethodInvoker (delegate {
942 progress_bar.Message = message;
943 progress_bar.Value = progress;
944 progress_bar.Update ();
945 }));
946 } else {
947 progress_bar.Message = message;
948 progress_bar.Value = progress;
949 progress_bar.Update ();
950 }
951 }
952 private void gameWorker_DoWork (object sender, DoWorkEventArgs e)
953 {
954 Stopwatch t = e.Argument as Stopwatch;
955 progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
956 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
957 progress_bar.ShowPercentageLabel = false;
958 #endif
959 progress_bar.ProgressColor = Color.LimeGreen;
960 progress_bar.Dock = DockStyle.Top;
961
962 if (this.InvokeRequired) {
963 this.Invoke ((MethodInvoker)delegate () {
964 this.Controls.Add (progress_bar);
965 });
966 } else {
967 this.Controls.Add (progress_bar);
968 }
969 progress_bar.Invoke (new MethodInvoker (delegate {
970 progress_bar.Margin = new System.Windows.Forms.Padding (0);
971 progress_bar.Size = new Size (GetFormWidth () - 25, 100);
972 }));
973
974 HashSet<IRomConfig> roms = new HashSet<IRomConfig> ();
975 using (RomParser parser = new RomParser (cache, CurrentSelectedRom, new ProgressEvent (worker_progress_event))) {
976 foreach (var rom in parser.Roms) {
977 roms.Add (rom);
978 }
979 }
980
981 double count = 0;
982 double total_count = roms.Count;
983 if (total_count > 0) {
984 progress_bar.Invoke (new MethodInvoker (delegate {
985 progress_bar.Message = string.Format ("Please Wait Adding {0} {1} Roms...", total_count, CurrentSelectedRom.PlatformNameLong);
986 }));
987 }
988
989
990 foreach (IRomConfig config in roms) {
991 progress_bar.Invoke (new MethodInvoker (delegate {
992 progress_bar.Value = (int)(100.0 * (count / total_count));
993 }));
994 GameControl game_ctrl = new GameControl ();
995 game_ctrl.Font = GetFormFont ();
996 game_ctrl.Dock = DockStyle.Top;
997 game_ctrl.Width = this.Width - 10;
998 game_ctrl.Tag = config;
999 try {
1000 lock (gameimage_lock) {
1001 //gLog.Debug.WriteLine ("handling rom: {0}", config.ToString ());
1002 if (String.IsNullOrEmpty (config.RomImage)) {
1003 game_ctrl.UpdateGameImage ((Image)DefaultGameImage.Clone ());
1004 } else {
1005 string path = config.isCachedLocally ? config.GetLocalRomImageOverride() : config.GetFullRomImage ();
1006 if (File.Exists (path)) {
1007 game_ctrl.UpdateGameImage (path);
1008 } else {
1009 game_ctrl.UpdateGameImage ((Image)DefaultGameImage.Clone ());
1010 }
1011 }
1012 }
1013 } catch (Exception ex) {
1014 gLog.Error.WriteLine (ex.Message);
1015 gLog.Verbose.Error.WriteLine (ex.ToString ());
1016 throw ex;
1017 }
1018 if (CurrentSelectedRom.PlatformNameShort == "Favorites") {
1019 //game_ctrl.GameName = config.RomTitle;
1020 var favorite = RomFavorite.GetFavoriteInfoFromRom (config);
1021 game_ctrl.GameName = favorite.RomConfig.RomExists ? favorite.RomConfig.RomTitle : string.Format ("{0} - (unavailable)", favorite.RomConfig.RomTitle);
1022 //RomFavorite.GetRomTitleFromConfig(config);
1023 if (!favorite.RomConfig.RomExists) {
1024 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING;
1025 } else {
1026 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR;
1027 }
1028 } else {
1029 game_ctrl.GameName = config.RomExists ? config.RomTitle : string.Format ("{0} - (unavailable)", config.RomTitle);
1030 if (!config.RomExists) {
1031 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING;
1032 } else {
1033 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR;
1034 }
1035 }
1036 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (game_ctrl_PreviewKeyDown);
1037 game_ctrl.GotFocus += new EventHandler (game_ctrl_GotFocus);
1038 game_ctrl.LostFocus += new EventHandler (game_ctrl_LostFocus);
1039 if (rom_flow.InvokeRequired) { rom_flow.Invoke ((MethodInvoker)delegate () { rom_flow.Controls.Add (game_ctrl); }); } else { rom_flow.Controls.Add (game_ctrl); }
1040 count++;
1041 }
1042 progress_bar.Invoke (new MethodInvoker (delegate { progress_bar.Value = 0; progress_bar.Update (); }));
1043 e.Result = t;
1044 }
1045 private void gameWorker_ProgressChanged (object sender, ProgressChangedEventArgs e) { }
1046 private void gameWorker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
1047 {
1048 Stopwatch t = e.Result as Stopwatch;
1049 if (this.InvokeRequired) {
1050 this.Invoke ((MethodInvoker)delegate () {
1051 progress_bar.Message = "";
1052 this.Controls.Remove (progress_bar);
1053 });
1054 this.Refresh ();
1055 } else {
1056 progress_bar.Message = "";
1057 this.Controls.Remove (progress_bar);
1058 this.Refresh ();
1059
1060 }
1061 if (rom_flow.Controls.Count == 0) {
1062 GameControl game_ctrl = new GameControl ();
1063 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (game_ctrl_PreviewKeyDown);
1064 game_ctrl.GotFocus += new EventHandler (game_ctrl_GotFocus);
1065 game_ctrl.LostFocus += new EventHandler (game_ctrl_LostFocus);
1066 game_ctrl.Font = GetFormFont ();
1067 game_ctrl.Dock = DockStyle.Top;
1068 game_ctrl.Width = this.Width - 10;
1069 IEmuConfig config = CurrentPlatformControl.Tag as IEmuConfig;
1070 if (config.PlatformNameLong == "Favorites") {
1071 game_ctrl.GameName = "You haven't favorited any games, select a game and then press CTRL+F to favorite it";
1072 } else {
1073 game_ctrl.GameName = string.Format ("No {0} games were found", config.PlatformNameShort);
1074 }
1075 rom_flow.Controls.Add (game_ctrl);
1076 }
1077 rom_flow.Controls [0].Select ();
1078 t.Stop ();
1079 gLog.Profiler.WriteLine ("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
1080 }
1081 #endregion
1082 #region platformWorker
1083 private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
1084 private object platformimage_lock = new object ();
1085 private void platformWorker_DoWork (object sender, DoWorkEventArgs e)
1086 {
1087 Stopwatch t = e.Argument as Stopwatch;
1088 progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
1089 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
1090 progress_bar.ShowPercentageLabel = false;
1091 #endif
1092 progress_bar.ProgressColor = Color.LimeGreen;
1093 progress_bar.Dock = DockStyle.Top;
1094
1095 if (this.InvokeRequired) {
1096 this.Invoke ((MethodInvoker)delegate () {
1097 this.Controls.Add (progress_bar);
1098 });
1099 } else {
1100 this.Controls.Add (progress_bar);
1101 }
1102 progress_bar.Invoke (new MethodInvoker (delegate {
1103 progress_bar.Margin = new System.Windows.Forms.Padding (0);
1104 progress_bar.Size = new Size (GetFormWidth () - 25, 100);
1105 }));
1106
1107 HashSet<IEmuConfig> platforms = new HashSet<IEmuConfig> ();
1108 using (PlatformParser parser = new PlatformParser (cache, Config.LocalRomPath, Config.RomPath, new ProgressEvent (worker_progress_event))) {
1109 foreach (var platform in parser.Platforms) {
1110 platforms.Add (platform);
1111 }
1112 }
1113
1114
1115 double count = 0;
1116 double total_count = platforms.Count;
1117 if (total_count > 0) {
1118 progress_bar.Invoke (new MethodInvoker (delegate {
1119 progress_bar.Message = string.Format ("Please Wait Loading {0} Rom Platforms...", total_count);
1120 }));
1121 }
1122 foreach (IEmuConfig config in platforms) {
1123 progress_bar.Invoke (new MethodInvoker (delegate {
1124 progress_bar.Value = (int)(100.0 * (count / total_count));
1125 }));
1126
1127 PlatformControl platform_ctrl = new PlatformControl ();
1128 platform_ctrl.Font = GetFormFont ();
1129 platform_ctrl.Dock = DockStyle.Top;
1130 platform_ctrl.Width = this.Width - 10;
1131 platform_ctrl.Tag = config;
1132 try {
1133 lock (platformimage_lock) {
1134 //gLog.Debug.WriteLine ("handling platform: {0}", config.ToString ());
1135 if (String.IsNullOrEmpty (config.PlatformImage)) {
1136 platform_ctrl.UpdatePlatformImage ((Image)DefaultPlatformImage.Clone ());
1137 } else {
1138 string path = config.GetFullPlatformImage ();
1139 if (File.Exists (path)) {
1140 platform_ctrl.UpdatePlatformImage (path);
1141 } else {
1142 platform_ctrl.UpdatePlatformImage ((Image)DefaultPlatformImage.Clone ());
1143 }
1144 }
1145 }
1146 } catch (Exception ex) {
1147 gLog.Error.WriteLine (ex.Message);
1148 gLog.Verbose.Error.WriteLine (ex.ToString ());
1149 throw ex;
1150 }
1151 platform_ctrl.PlatformName = config.ToString ();
1152 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (platform_ctrl_PreviewKeyDown);
1153 platform_ctrl.GotFocus += new EventHandler (platform_ctrl_GotFocus);
1154 platform_ctrl.LostFocus += new EventHandler (platform_ctrl_LostFocus);
1155 if (platform_flow.InvokeRequired) { platform_flow.Invoke ((MethodInvoker)delegate () { platform_flow.Controls.Add (platform_ctrl); }); } else { platform_flow.Controls.Add (platform_ctrl); }
1156 count++;
1157 }
1158 progress_bar.Invoke (new MethodInvoker (delegate {
1159 progress_bar.Value = 0; progress_bar.Update ();
1160 }));
1161 e.Result = t;
1162 }
1163 private void platformWorker_ProgressChanged (object sender, ProgressChangedEventArgs e) { }
1164 private void platformWorker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
1165 {
1166 gLog.Debug.WriteLine ("platformWorker_RunWorkerCompleted called");
1167 if (this.InvokeRequired) {
1168 this.Invoke ((MethodInvoker)delegate () {
1169 progress_bar.Message = "";
1170 this.Controls.Remove (progress_bar);
1171 });
1172 } else {
1173 progress_bar.Message = "";
1174 this.Controls.Remove (progress_bar);
1175 }
1176 Stopwatch t = e.Result as Stopwatch;
1177 if (platform_flow.Controls.Count == 0) {
1178 PlatformControl platform_ctrl = new PlatformControl ();
1179 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (platform_ctrl_PreviewKeyDown);
1180 platform_ctrl.GotFocus += new EventHandler (platform_ctrl_GotFocus);
1181 platform_ctrl.LostFocus += new EventHandler (platform_ctrl_LostFocus);
1182 platform_ctrl.Font = GetFormFont ();
1183 platform_ctrl.Dock = DockStyle.Top;
1184 platform_ctrl.Width = this.Width - 10;
1185 platform_ctrl.PlatformName = string.Format ("You don't have any roms in your rompath: '{0}'", Config.RomPath);
1186 platform_flow.Controls.Add (platform_ctrl);
1187 }
1188 if (SavedPlatformIndex != -1) {
1189 var platform_control = platform_flow.Controls [SavedPlatformIndex] as PlatformControl;
1190 platform_flow.SuspendLayout ();
1191 CurrentPlatformControl = platform_control;
1192 platform_flow.ScrollControlIntoView (CurrentPlatformControl);
1193 CurrentPlatformControl.Select ();
1194 platform_flow.ResumeLayout ();
1195 SavedPlatformIndex = -1;
1196 } else {
1197 platform_flow.Controls [0].Select ();
1198 }
1199 t.Stop ();
1200 gLog.Profiler.WriteLine ("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
1201 }
1202 #endregion
1203
1204 private void Form1_FormClosed (object sender, FormClosedEventArgs e)
1205 {
1206 Cursor.Show ();
1207 }
1208 #endregion
1209 }
1210 }

  ViewVC Help
Powered by ViewVC 1.1.22