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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 383 - (show annotations) (download)
Thu May 2 04:43:31 2019 UTC (9 months, 2 weeks ago) by william
File size: 42748 byte(s)
+ update how favorited roms are handled:
  ** when the roms are displayed they are sorted by rom title
  ** when the roms are saved they get sorted by date added, and
       the newest rom will be at the bottom of the list

+ fix a sharing violation that would occur when attempting to
  copy a rom to a local path, if that rom already existed, and
  its image was loaded from the local path.

   Basically, if the rom had an image it attempted to overwrite
   the image file while the program had an open handle to the
   image in the local path. (hence: sharing violation)

     ** this was fixed by creating a bitmap from the source file
        and not maintaining an open-handle to the file.


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 platform_ctrl_LostFocus (object sender, EventArgs e)
292 {
293 PlatformControl c = sender as PlatformControl;
294 if (c != null) {
295 #if !HAVE_X11_BORDERSTYLE_ERROR
296 c.BorderStyle = BorderStyle.None;
297 #endif
298 c.BackColor = this.BackColor;
299 }
300 }
301
302 void platform_ctrl_GotFocus (object sender, EventArgs e)
303 {
304 PlatformControl c = sender as PlatformControl;
305 if (c != null) {
306 #if !HAVE_X11_BORDERSTYLE_ERROR
307 c.BorderStyle = BorderStyle.FixedSingle;
308 #endif
309 c.BackColor = SELECTED_CONTROL_BACKCOLOR;
310 CurrentPlatformControl = c;
311 }
312 }
313
314 void game_ctrl_PreviewKeyDown (object sender, PreviewKeyDownEventArgs e)
315 {
316 //gLog.Verbose.Debug.WriteLine ("game_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
317 GameControl c = sender as GameControl;
318
319 int changeAmount = 0;
320 int currentPosition = 0;
321 IRomConfig config = null;
322 if (e.KeyCode == Keys.C && (e.Modifiers & Keys.Control) == Keys.Control) {
323 config = (c.Tag as IRomConfig);
324 if (config != null) {
325 string platform_short = config.EmuConfig.PlatformNameShort;
326 string rom_file = config.RomFile;
327 string rom_image = config.RomImage;
328
329 string rom_filename = "";
330 string rom_imagefilename = "";
331 FileInfo fi = null;
332 try {
333 if (!string.IsNullOrEmpty (rom_file)) {
334 fi = new FileInfo (rom_file);
335 rom_filename = fi.Name;
336 }
337 } finally {
338 fi = null;
339 }
340 try {
341 if (!string.IsNullOrEmpty (rom_image)) {
342 fi = new FileInfo (rom_image);
343 rom_imagefilename = fi.Name;
344 }
345 } finally {
346 fi = null;
347 }
348
349 string local_path = Config.LocalRomPath.TrimEnd (new char [] { '/' });
350 string local_rom_path = string.Format ("{0}/{1}", local_path, platform_short);
351 string local_romfile = string.IsNullOrEmpty(rom_filename) ? "" : OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_filename));
352 string local_romimage = string.IsNullOrEmpty(rom_imagefilename) ? "" : OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_imagefilename));
353
354 if (string.IsNullOrEmpty (local_romfile)) {
355 gLog.Error.WriteLine ("Local rom file could not be found. [src rom={0}]", rom_file);
356 return;
357 }
358
359 // create the local rom path for this platform
360 DirectoryInfo di = new DirectoryInfo (local_rom_path);
361 if (!di.Exists) {
362 di.Create ();
363 }
364 this.Enabled = false;
365 CopyRomToLocalCache (rom_file, local_romfile, rom_image, local_romimage);
366 this.Enabled = true;
367 }
368 }
369 if (e.KeyCode == Keys.D && (e.Modifiers & Keys.Control) == Keys.Control) {
370 config = (c.Tag as IRomConfig);
371 if (config != null) {
372 string platform_short = config.EmuConfig.PlatformNameShort;
373 string rom_file = config.RomFile;
374 string rom_image = config.RomImage;
375
376 string rom_filename = "";
377 string rom_imagefilename = "";
378 FileInfo fi = null;
379 try {
380 fi = new FileInfo (rom_file);
381 rom_filename = fi.Name;
382 } finally {
383 fi = null;
384 }
385 try {
386 fi = new FileInfo (rom_image);
387 rom_imagefilename = fi.Name;
388 } finally {
389 fi = null;
390 }
391 string local_path = Config.LocalRomPath.TrimEnd (new char [] { '/' });
392 string local_rom_path = string.Format ("{0}/{1}", local_path, platform_short);
393 string local_romfile = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_filename));
394 string local_romimage = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_imagefilename));
395 this.Enabled = false;
396 DeleteRomFromLocalCache (local_romfile, local_romimage);
397 this.Enabled = true;
398 }
399 }
400 if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control) {
401 config = c.Tag as IRomConfig;
402 if (config == null) {
403 gLog.Error.WriteLine ("Unable to add/remove from/to favorites (config) is null");
404 } else {
405 var isFavorite = RomFavorite.IsFavorite (config);
406 if (isFavorite) {
407 // add to favorites
408 //gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
409 if (!RomFavorite.RemoveFavorite (config)) {
410 gLog.Error.WriteLine ("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
411 } else {
412 gLog.Info.WriteLine ("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
413 if (config.EmuConfig.PlatformNameShort == "Favorites") {
414 var parent = c.Parent;
415 if (parent != null) {
416 parent.Controls.Remove (c);
417 if (parent.Controls.Count > 0) {
418 var next_ctrl = parent.Controls [0];
419 if (next_ctrl != null) {
420 next_ctrl.Select ();
421 }
422 }
423 }
424 }
425 }
426 } else {
427 // add to favorites
428 //gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
429 if (!RomFavorite.AddFavorite (config)) {
430 gLog.Error.WriteLine ("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
431 } else {
432 gLog.Info.WriteLine ("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
433 }
434 }
435 //gLog.Debug.WriteLine("Updateing favorites");
436 if (!RomFavorite.UpdateFavorites (cache)) {
437 gLog.Error.WriteLine ("Failed to update favorites");
438 } else {
439 gLog.Info.WriteLine ("Updated favorites");
440 }
441 }
442 return; // stop processing other keys
443
444 }
445 if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
446 if (OSInfo.OSIsUnix) {
447 rom_flow.SuspendLayout ();
448 var ctl = game_ctrl_get_previous_control (true);
449 rom_flow.ScrollControlIntoView (ctl);
450 rom_flow.ResumeLayout (false);
451 }
452 }
453 if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
454 if (OSInfo.OSIsUnix) {
455 rom_flow.SuspendLayout ();
456 var ctl = game_ctrl_get_next_control (true);
457 rom_flow.ScrollControlIntoView (ctl);
458 rom_flow.ResumeLayout (false);
459 }
460 }
461 if (e.KeyCode == Keys.Home) {
462 rom_flow.SuspendLayout ();
463 rom_flow.Controls [0].Select ();
464 rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
465 rom_flow.ResumeLayout (false);
466 }
467 if (e.KeyCode == Keys.End) {
468 rom_flow.SuspendLayout ();
469 rom_flow.Controls [rom_flow.Controls.Count - 1].Select ();
470 rom_flow.ScrollControlIntoView (rom_flow.Controls [rom_flow.Controls.Count - 1]);
471 rom_flow.ResumeLayout (false);
472 }
473 if (e.KeyCode == Keys.PageUp) {
474 rom_flow.SuspendLayout ();
475 changeAmount = rom_flow.VerticalScroll.LargeChange;
476 currentPosition = rom_flow.VerticalScroll.Value;
477 if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum) {
478 try {
479 rom_flow.VerticalScroll.Value -= changeAmount;
480 } catch {
481 rom_flow.Controls [0].Select ();
482 rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
483 rom_flow.PerformLayout ();
484 return;
485 }
486 } else {
487 rom_flow.Controls [0].Select ();
488 rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
489 }
490 GameControl s = game_ctrl_get_last_visible ();
491 s.Select ();
492 rom_flow.ScrollControlIntoView (s);
493 rom_flow.ResumeLayout (false);
494 }
495 if (e.KeyCode == Keys.PageDown) {
496 rom_flow.SuspendLayout ();
497 changeAmount = rom_flow.VerticalScroll.LargeChange;
498 currentPosition = rom_flow.VerticalScroll.Value;
499 if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum) {
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.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
510 }
511 GameControl s = game_ctrl_get_last_visible ();
512 s.Select ();
513 rom_flow.ScrollControlIntoView (s);
514 rom_flow.ResumeLayout (false);
515 }
516
517 if (e.KeyCode == Keys.Enter) {
518 config = c.Tag as IRomConfig;
519 if (config.RomExists) {
520 c.TextForeColor = DEFAULT_TEXTFORECOLOR_LAUNCH;
521 string gamename = c.GameName;
522 c.GameName = string.Format ("{0} (Loading...)", gamename);
523 bool game_launched = true;
524 using (Process p = new Process ()) {
525 string binary = "";
526 string arguments = "";
527 if (!string.IsNullOrEmpty (config.EmuConfig.EmuBinaryPath)) {
528 binary = config.EmuConfig.EmuBinaryPath;
529 arguments = EmuConfigLoader.GetEMUOptions (config);
530 }
531 if (!string.IsNullOrEmpty (config.EmuConfig.GameExe)) {
532 binary = config.EmuConfig.GameExe;
533 arguments = config.EmuConfig.GameExeArgs;
534 }
535 if (string.IsNullOrEmpty (binary)) {
536 gLog.Warn.WriteLine ("Cannot launch this rom file -- missing arguments");
537 game_launched = false;
538 } else {
539 p.StartInfo.FileName = binary;
540 p.StartInfo.Arguments = arguments == null ? "" : arguments;
541 p.Start ();
542 // wait for exit of game
543 p.WaitForExit ();
544 c.TextForeColor = DEFAULT_TEXTFORECOLOR;
545 c.GameName = gamename;
546 }
547 }
548 if (!game_launched) {
549 c.TextForeColor = DEFAULT_TEXTFORECOLOR_ERROR;
550 c.GameName = string.Format ("{0} (Error While Loading...)", gamename);
551 }
552 } else {
553 c.TextForeColor = Color.Red;
554 }
555 }
556 if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
557
558 bAbortRomCopyToLocalCache = true; // this will cancel any copy operations
559 SavedPlatformIndex = platform_flow.Controls.IndexOf (CurrentPlatformControl);
560 rom_flow.Visible = false;
561 platform_flow.Visible = true;
562 }
563
564 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
565 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) {
566 rom_flow.SuspendLayout ();
567 char t = (char)e.KeyCode;
568 GameControl ctrl = (rom_flow.GetNextControl (CurrentGameControl, true) as GameControl);
569 if (ctrl == null) { ctrl = (rom_flow.GetNextControl (rom_flow.Controls [0], true) as GameControl); }
570 bool found = false;
571 GameControl pc = CurrentGameControl;
572 bool wrapped = false;
573 bool not_found = true;
574 while (!found) {
575 if (wrapped) {
576 foreach (Control ctl in rom_flow.Controls) {
577 GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower ().StartsWith (t.ToString ().ToLower ())) { not_found = false; }
578 }
579 if (not_found) { found = true; }
580 }
581 ctrl = (rom_flow.GetNextControl (pc, true) as GameControl);
582 if (ctrl == null) {
583 ctrl = rom_flow.Controls [0] as GameControl;
584 wrapped = true;
585 }
586 if (ctrl.GameName.ToLower ().StartsWith (t.ToString ().ToLower ())) {
587 rom_flow.ScrollControlIntoView (ctrl);
588 ctrl.Select ();
589 found = true;
590 }
591 pc = ctrl;
592 }
593 rom_flow.ResumeLayout (false);
594 }
595 }
596 void platform_ctrl_PreviewKeyDown (object sender, PreviewKeyDownEventArgs e)
597 {
598 //gLog.Verbose.Debug.WriteLine ("platform_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
599 PlatformControl c = sender as PlatformControl;
600 int changeAmount = 0;
601 int currentPosition = 0;
602 if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
603 if (OSInfo.OSIsUnix) {
604 platform_flow.SuspendLayout ();
605 var ctl = platform_ctrl_get_previous_control (true);
606 platform_flow.ScrollControlIntoView (ctl);
607 platform_flow.ResumeLayout (false);
608 }
609 }
610 if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
611 if (OSInfo.OSIsUnix) {
612 platform_flow.SuspendLayout ();
613 var ctl = platform_ctrl_get_next_control (true);
614 platform_flow.ScrollControlIntoView (ctl);
615 platform_flow.ResumeLayout (false);
616 }
617 }
618 if (e.KeyCode == Keys.Home) {
619 platform_flow.SuspendLayout ();
620 platform_flow.Controls [0].Select ();
621 platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
622 platform_flow.ResumeLayout (false);
623 }
624 if (e.KeyCode == Keys.End) {
625 platform_flow.SuspendLayout ();
626 platform_flow.Controls [platform_flow.Controls.Count - 1].Select ();
627 platform_flow.ScrollControlIntoView (platform_flow.Controls [platform_flow.Controls.Count - 1]);
628 platform_flow.ResumeLayout (false);
629 }
630 if (e.KeyCode == Keys.PageUp) {
631 platform_flow.SuspendLayout ();
632 changeAmount = platform_flow.VerticalScroll.LargeChange;
633 currentPosition = platform_flow.VerticalScroll.Value;
634 if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum) {
635 platform_flow.VerticalScroll.Value -= changeAmount;
636 } else {
637 platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum;
638 }
639 PlatformControl s = platform_ctrl_get_last_visible ();
640 s.Select ();
641 platform_flow.ScrollControlIntoView (s);
642 platform_flow.ResumeLayout (false);
643 }
644 if (e.KeyCode == Keys.PageDown) {
645 platform_flow.SuspendLayout ();
646 changeAmount = platform_flow.VerticalScroll.LargeChange;
647 currentPosition = platform_flow.VerticalScroll.Value;
648 if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum) {
649 try {
650 platform_flow.VerticalScroll.Value += changeAmount;
651 } catch {
652 platform_flow.Controls [0].Select ();
653 platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
654 rom_flow.PerformLayout ();
655 return;
656 }
657 } else {
658 platform_flow.Controls [0].Select ();
659 platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
660 }
661 PlatformControl s = platform_ctrl_get_last_visible ();
662 s.Select ();
663 platform_flow.ScrollControlIntoView (s);
664 platform_flow.ResumeLayout (false);
665 }
666 if (e.KeyCode == Keys.Enter) {
667 // load this platform
668 platform_flow.Visible = false;
669 CurrentSelectedRom = c.Tag as IEmuConfig;
670 rom_flow.Visible = true;
671 rom_flow.BringToFront ();
672 }
673 if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
674 bAbortRomCopyToLocalCache = true;
675 this.Close ();
676 }
677 if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
678 (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) {
679 platform_flow.SuspendLayout ();
680 char t = (char)e.KeyCode;
681 PlatformControl ctrl = (platform_flow.GetNextControl (CurrentPlatformControl, true) as PlatformControl);
682 if (ctrl == null) { ctrl = (platform_flow.GetNextControl (platform_flow.Controls [0], true) as PlatformControl); }
683 bool found = false;
684 PlatformControl pc = CurrentPlatformControl;
685 bool wrapped = false;
686 bool not_found = true;
687 while (!found) {
688 if (wrapped) {
689 foreach (Control ctl in platform_flow.Controls) {
690 PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower ().StartsWith (t.ToString ().ToLower ())) { not_found = false; }
691 }
692 if (not_found) { found = true; }
693 }
694 ctrl = (platform_flow.GetNextControl (pc, true) as PlatformControl);
695 if (ctrl == null) {
696 ctrl = platform_flow.Controls [0] as PlatformControl;
697 wrapped = true;
698 }
699 if (ctrl.PlatformName.ToLower ().StartsWith (t.ToString ().ToLower ())) {
700 platform_flow.ScrollControlIntoView (ctrl);
701 ctrl.Select ();
702 found = true;
703 }
704 pc = ctrl;
705 }
706 platform_flow.ResumeLayout (false);
707 }
708 }
709
710 private void platform_flow_VisibleChanged (object sender, EventArgs e)
711 {
712 if (!platform_flow.Visible) return;
713 platform_flow.Controls.Clear ();
714 platform_flow.BringToFront ();
715 Stopwatch t = new Stopwatch ();
716 t.Start ();
717 platformWorker.RunWorkerAsync (t);
718 }
719
720 private void rom_flow_VisibleChanged (object sender, EventArgs e)
721 {
722 if (!rom_flow.Visible) return;
723 rom_flow.Controls.Clear ();
724 rom_flow.BringToFront ();
725 Stopwatch t = new Stopwatch ();
726 t.Start ();
727 gameWorker.RunWorkerAsync (t);
728 }
729
730 void game_ctrl_LostFocus (object sender, EventArgs e)
731 {
732 GameControl c = sender as GameControl;
733 #if !HAVE_X11_BORDERSTYLE_ERROR
734 c.BorderStyle = BorderStyle.None;
735 #endif
736 c.BackColor = this.BackColor;
737 }
738
739 void game_ctrl_GotFocus (object sender, EventArgs e)
740 {
741 GameControl c = sender as GameControl;
742 #if !HAVE_X11_BORDERSTYLE_ERROR
743 c.BorderStyle = BorderStyle.FixedSingle;
744 #endif
745 c.BackColor = SELECTED_CONTROL_BACKCOLOR;
746 CurrentGameControl = c;
747 }
748
749 private GameControl game_ctrl_get_last_visible ()
750 {
751 GameControl s = new GameControl ();
752 foreach (GameControl c in rom_flow.Controls) {
753 if (c.Bounds.IntersectsWith (rom_flow.Bounds))
754 s = c;
755 }
756 return s;
757 }
758 private PlatformControl platform_ctrl_get_last_visible ()
759 {
760 PlatformControl s = new PlatformControl ();
761 foreach (PlatformControl c in platform_flow.Controls) {
762 if (c.Bounds.IntersectsWith (platform_flow.Bounds))
763 s = c;
764 }
765 return s;
766 }
767 private PlatformControl platform_ctrl_get_next_control (bool update_control)
768 {
769 PlatformControl s = new PlatformControl ();
770 int index = platform_flow.Controls.IndexOf (CurrentPlatformControl);
771 index = index + 1;
772 if (index < 0) {
773 index = platform_flow.Controls.Count - 1;
774 }
775 if (index > platform_flow.Controls.Count - 1) {
776 index = 0;
777 }
778 s = platform_flow.Controls [index] as PlatformControl;
779 if (update_control) {
780 CurrentPlatformControl = s;
781 s.Select ();
782 }
783 return s;
784 }
785 private PlatformControl platform_ctrl_get_previous_control (bool update_control)
786 {
787 PlatformControl s = null;
788 int index = platform_flow.Controls.IndexOf (CurrentPlatformControl);
789 index = index - 1;
790 if (index < 0) {
791 index = platform_flow.Controls.Count - 1;
792 }
793 if (index > platform_flow.Controls.Count - 1) {
794 index = 0;
795 }
796 s = platform_flow.Controls [index] as PlatformControl;
797 if (update_control) {
798 CurrentPlatformControl = s;
799 s.Select ();
800 }
801 return s;
802 }
803 private GameControl game_ctrl_get_next_control (bool update_control)
804 {
805 GameControl s = new GameControl ();
806 int index = rom_flow.Controls.IndexOf (CurrentGameControl);
807 index = index + 1;
808 if (index < 0) {
809 index = rom_flow.Controls.Count - 1;
810 }
811 if (index > rom_flow.Controls.Count - 1) {
812 index = 0;
813 }
814 s = rom_flow.Controls [index] as GameControl;
815 if (update_control) {
816 CurrentGameControl = s;
817 s.Select ();
818 }
819 return s;
820 }
821 private GameControl game_ctrl_get_previous_control (bool update_control)
822 {
823 GameControl s = new GameControl ();
824 int index = rom_flow.Controls.IndexOf (CurrentGameControl);
825 index = index - 1;
826 if (index < 0) {
827 index = rom_flow.Controls.Count - 1;
828 }
829 if (index > rom_flow.Controls.Count - 1) {
830 index = 0;
831 }
832 s = rom_flow.Controls [index] as GameControl;
833 if (update_control) {
834 CurrentGameControl = s;
835 s.Select ();
836 }
837 return s;
838 }
839
840
841 #region Background Workers
842
843 private int GetFormWidth ()
844 {
845 if (this.InvokeRequired) {
846 return Convert.ToInt32 (this.Invoke ((MethodInvoker)delegate () { GetFormWidth (); }));
847 } else {
848 return this.Width;
849 }
850 }
851 private Font GetFormFont ()
852 {
853 if (this.InvokeRequired) {
854 return (this.Invoke (new Delegate_GetFormFont (GetFormFont)) as Font);
855 } else {
856 return this.Font;
857 }
858 }
859
860 private Font ResizeFont (Font font, float size)
861 {
862 if (this.InvokeRequired) {
863 return (this.Invoke (new Delegate_ResizeFont (ResizeFont), new object [] { font, size }) as Font);
864 } else {
865 return new Font (font.FontFamily, size);
866 }
867 }
868
869 //private void AddPlatformControl(Control c)
870 //{
871 // if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
872 // else
873 // {
874 // platform_flow.Controls.Add(c);
875 // }
876 //}
877 //private void UpdatePlatformControls()
878 //{
879 // //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); }
880 // //else { this.Update(); }
881 //}
882 //private void AddGameControl(Control c)
883 //{
884 // if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); }
885 // else
886 // {
887 // rom_flow.Controls.Add(c);
888 // }
889 //}
890 //private void UpdateGameControls()
891 //{
892 // //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); }
893 // //else { this.Update(); }
894 //}
895 #region gameWorker
896 private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
897 private object gameimage_lock = new object ();
898 private void worker_progress_event (object event_source, ProgressEventArgs event_args)
899 {
900 //gLog.Debug.WriteLine ("worker_progress_event called!");
901 object user_object = event_args.GetUserObject ();
902 int progress = event_args.GetProgress ();
903 string message = event_args.GetUserMessage () == null ? "" : event_args.GetUserMessage ();
904 if (user_object != null) {
905 IRomConfig irc = (user_object as IRomConfig);
906 if (irc != null) {
907 gLog.Verbose.Debug.WriteLine ("Read Rom[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, irc);
908 } else {
909 IEmuConfig iec = (user_object as IEmuConfig);
910 if (iec != null) {
911 gLog.Verbose.Debug.WriteLine ("Read Platform[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, iec);
912 }
913 }
914 }
915 if (progress_bar.InvokeRequired) {
916 progress_bar.Invoke (new MethodInvoker (delegate {
917 progress_bar.Message = message;
918 progress_bar.Value = progress;
919 progress_bar.Update ();
920 }));
921 } else {
922 progress_bar.Message = message;
923 progress_bar.Value = progress;
924 progress_bar.Update ();
925 }
926 }
927 private void gameWorker_DoWork (object sender, DoWorkEventArgs e)
928 {
929 Stopwatch t = e.Argument as Stopwatch;
930 progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
931 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
932 progress_bar.ShowPercentageLabel = false;
933 #endif
934 progress_bar.ProgressColor = Color.LimeGreen;
935 progress_bar.Dock = DockStyle.Top;
936
937 if (this.InvokeRequired) {
938 this.Invoke ((MethodInvoker)delegate () {
939 this.Controls.Add (progress_bar);
940 });
941 } else {
942 this.Controls.Add (progress_bar);
943 }
944 progress_bar.Invoke (new MethodInvoker (delegate {
945 progress_bar.Margin = new System.Windows.Forms.Padding (0);
946 progress_bar.Size = new Size (GetFormWidth () - 25, 100);
947 }));
948
949 HashSet<IRomConfig> roms = new HashSet<IRomConfig> ();
950 using (RomParser parser = new RomParser (cache, CurrentSelectedRom, new ProgressEvent (worker_progress_event))) {
951 foreach (var rom in parser.Roms) {
952 roms.Add (rom);
953 }
954 }
955
956 double count = 0;
957 double total_count = roms.Count;
958 if (total_count > 0) {
959 progress_bar.Invoke (new MethodInvoker (delegate {
960 progress_bar.Message = string.Format ("Please Wait Adding {0} {1} Roms...", total_count, CurrentSelectedRom.PlatformNameLong);
961 }));
962 }
963
964
965 foreach (IRomConfig config in roms) {
966 progress_bar.Invoke (new MethodInvoker (delegate {
967 progress_bar.Value = (int)(100.0 * (count / total_count));
968 }));
969 GameControl game_ctrl = new GameControl ();
970 game_ctrl.Font = GetFormFont ();
971 game_ctrl.Dock = DockStyle.Top;
972 game_ctrl.Width = this.Width - 10;
973 game_ctrl.Tag = config;
974 try {
975 lock (gameimage_lock) {
976 //gLog.Debug.WriteLine ("handling rom: {0}", config.ToString ());
977 if (String.IsNullOrEmpty (config.RomImage)) {
978 game_ctrl.UpdateGameImage ((Image)DefaultGameImage.Clone ());
979 } else {
980 string path = config.isCachedLocally ? config.GetLocalRomImageOverride() : config.GetFullRomImage ();
981 if (File.Exists (path)) {
982 game_ctrl.UpdateGameImage (path);
983 } else {
984 game_ctrl.UpdateGameImage ((Image)DefaultGameImage.Clone ());
985 }
986 }
987 }
988 } catch (Exception ex) {
989 gLog.Error.WriteLine (ex.Message);
990 gLog.Verbose.Error.WriteLine (ex.ToString ());
991 throw ex;
992 }
993 if (CurrentSelectedRom.PlatformNameShort == "Favorites") {
994 //game_ctrl.GameName = config.RomTitle;
995 var favorite = RomFavorite.GetFavoriteInfoFromRom (config);
996 game_ctrl.GameName = favorite.RomConfig.RomExists ? favorite.RomConfig.RomTitle : string.Format ("{0} - (unavailable)", favorite.RomConfig.RomTitle);
997 //RomFavorite.GetRomTitleFromConfig(config);
998 if (!favorite.RomConfig.RomExists) {
999 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING;
1000 } else {
1001 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR;
1002 }
1003 } else {
1004 game_ctrl.GameName = config.RomExists ? config.RomTitle : string.Format ("{0} - (unavailable)", config.RomTitle);
1005 if (!config.RomExists) {
1006 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING;
1007 } else {
1008 game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR;
1009 }
1010 }
1011 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (game_ctrl_PreviewKeyDown);
1012 game_ctrl.GotFocus += new EventHandler (game_ctrl_GotFocus);
1013 game_ctrl.LostFocus += new EventHandler (game_ctrl_LostFocus);
1014 if (rom_flow.InvokeRequired) { rom_flow.Invoke ((MethodInvoker)delegate () { rom_flow.Controls.Add (game_ctrl); }); } else { rom_flow.Controls.Add (game_ctrl); }
1015 count++;
1016 }
1017 progress_bar.Invoke (new MethodInvoker (delegate { progress_bar.Value = 0; progress_bar.Update (); }));
1018 e.Result = t;
1019 }
1020 private void gameWorker_ProgressChanged (object sender, ProgressChangedEventArgs e) { }
1021 private void gameWorker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
1022 {
1023 Stopwatch t = e.Result as Stopwatch;
1024 if (this.InvokeRequired) {
1025 this.Invoke ((MethodInvoker)delegate () {
1026 progress_bar.Message = "";
1027 this.Controls.Remove (progress_bar);
1028 });
1029 this.Refresh ();
1030 } else {
1031 progress_bar.Message = "";
1032 this.Controls.Remove (progress_bar);
1033 this.Refresh ();
1034
1035 }
1036 if (rom_flow.Controls.Count == 0) {
1037 GameControl game_ctrl = new GameControl ();
1038 game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (game_ctrl_PreviewKeyDown);
1039 game_ctrl.GotFocus += new EventHandler (game_ctrl_GotFocus);
1040 game_ctrl.LostFocus += new EventHandler (game_ctrl_LostFocus);
1041 game_ctrl.Font = GetFormFont ();
1042 game_ctrl.Dock = DockStyle.Top;
1043 game_ctrl.Width = this.Width - 10;
1044 IEmuConfig config = CurrentPlatformControl.Tag as IEmuConfig;
1045 if (config.PlatformNameLong == "Favorites") {
1046 game_ctrl.GameName = "You haven't favorited any games, select a game and then press CTRL+F to favorite it";
1047 } else {
1048 game_ctrl.GameName = string.Format ("No {0} games were found", config.PlatformNameShort);
1049 }
1050 rom_flow.Controls.Add (game_ctrl);
1051 }
1052 rom_flow.Controls [0].Select ();
1053 t.Stop ();
1054 gLog.Profiler.WriteLine ("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
1055 }
1056 #endregion
1057 #region platformWorker
1058 private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
1059 private object platformimage_lock = new object ();
1060 private void platformWorker_DoWork (object sender, DoWorkEventArgs e)
1061 {
1062 Stopwatch t = e.Argument as Stopwatch;
1063 progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
1064 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
1065 progress_bar.ShowPercentageLabel = false;
1066 #endif
1067 progress_bar.ProgressColor = Color.LimeGreen;
1068 progress_bar.Dock = DockStyle.Top;
1069
1070 if (this.InvokeRequired) {
1071 this.Invoke ((MethodInvoker)delegate () {
1072 this.Controls.Add (progress_bar);
1073 });
1074 } else {
1075 this.Controls.Add (progress_bar);
1076 }
1077 progress_bar.Invoke (new MethodInvoker (delegate {
1078 progress_bar.Margin = new System.Windows.Forms.Padding (0);
1079 progress_bar.Size = new Size (GetFormWidth () - 25, 100);
1080 }));
1081
1082 HashSet<IEmuConfig> platforms = new HashSet<IEmuConfig> ();
1083 using (PlatformParser parser = new PlatformParser (cache, Config.LocalRomPath, Config.RomPath, new ProgressEvent (worker_progress_event))) {
1084 foreach (var platform in parser.Platforms) {
1085 platforms.Add (platform);
1086 }
1087 }
1088
1089
1090 double count = 0;
1091 double total_count = platforms.Count;
1092 if (total_count > 0) {
1093 progress_bar.Invoke (new MethodInvoker (delegate {
1094 progress_bar.Message = string.Format ("Please Wait Loading {0} Rom Platforms...", total_count);
1095 }));
1096 }
1097 foreach (IEmuConfig config in platforms) {
1098 progress_bar.Invoke (new MethodInvoker (delegate {
1099 progress_bar.Value = (int)(100.0 * (count / total_count));
1100 }));
1101
1102 PlatformControl platform_ctrl = new PlatformControl ();
1103 platform_ctrl.Font = GetFormFont ();
1104 platform_ctrl.Dock = DockStyle.Top;
1105 platform_ctrl.Width = this.Width - 10;
1106 platform_ctrl.Tag = config;
1107 try {
1108 lock (platformimage_lock) {
1109 //gLog.Debug.WriteLine ("handling platform: {0}", config.ToString ());
1110 if (String.IsNullOrEmpty (config.PlatformImage)) {
1111 platform_ctrl.UpdatePlatformImage ((Image)DefaultPlatformImage.Clone ());
1112 } else {
1113 string path = config.GetFullPlatformImage ();
1114 if (File.Exists (path)) {
1115 platform_ctrl.UpdatePlatformImage (path);
1116 } else {
1117 platform_ctrl.UpdatePlatformImage ((Image)DefaultPlatformImage.Clone ());
1118 }
1119 }
1120 }
1121 } catch (Exception ex) {
1122 gLog.Error.WriteLine (ex.Message);
1123 gLog.Verbose.Error.WriteLine (ex.ToString ());
1124 throw ex;
1125 }
1126 platform_ctrl.PlatformName = config.ToString ();
1127 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (platform_ctrl_PreviewKeyDown);
1128 platform_ctrl.GotFocus += new EventHandler (platform_ctrl_GotFocus);
1129 platform_ctrl.LostFocus += new EventHandler (platform_ctrl_LostFocus);
1130 if (platform_flow.InvokeRequired) { platform_flow.Invoke ((MethodInvoker)delegate () { platform_flow.Controls.Add (platform_ctrl); }); } else { platform_flow.Controls.Add (platform_ctrl); }
1131 count++;
1132 }
1133 progress_bar.Invoke (new MethodInvoker (delegate {
1134 progress_bar.Value = 0; progress_bar.Update ();
1135 }));
1136 e.Result = t;
1137 }
1138 private void platformWorker_ProgressChanged (object sender, ProgressChangedEventArgs e) { }
1139 private void platformWorker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
1140 {
1141 gLog.Debug.WriteLine ("platformWorker_RunWorkerCompleted called");
1142 if (this.InvokeRequired) {
1143 this.Invoke ((MethodInvoker)delegate () {
1144 progress_bar.Message = "";
1145 this.Controls.Remove (progress_bar);
1146 });
1147 } else {
1148 progress_bar.Message = "";
1149 this.Controls.Remove (progress_bar);
1150 }
1151 Stopwatch t = e.Result as Stopwatch;
1152 if (platform_flow.Controls.Count == 0) {
1153 PlatformControl platform_ctrl = new PlatformControl ();
1154 platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (platform_ctrl_PreviewKeyDown);
1155 platform_ctrl.GotFocus += new EventHandler (platform_ctrl_GotFocus);
1156 platform_ctrl.LostFocus += new EventHandler (platform_ctrl_LostFocus);
1157 platform_ctrl.Font = GetFormFont ();
1158 platform_ctrl.Dock = DockStyle.Top;
1159 platform_ctrl.Width = this.Width - 10;
1160 platform_ctrl.PlatformName = string.Format ("You don't have any roms in your rompath: '{0}'", Config.RomPath);
1161 platform_flow.Controls.Add (platform_ctrl);
1162 }
1163 if (SavedPlatformIndex != -1) {
1164 var platform_control = platform_flow.Controls [SavedPlatformIndex] as PlatformControl;
1165 platform_flow.SuspendLayout ();
1166 CurrentPlatformControl = platform_control;
1167 platform_flow.ScrollControlIntoView (CurrentPlatformControl);
1168 CurrentPlatformControl.Select ();
1169 platform_flow.ResumeLayout ();
1170 SavedPlatformIndex = -1;
1171 } else {
1172 platform_flow.Controls [0].Select ();
1173 }
1174 t.Stop ();
1175 gLog.Profiler.WriteLine ("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
1176 }
1177 #endregion
1178
1179 private void Form1_FormClosed (object sender, FormClosedEventArgs e)
1180 {
1181 Cursor.Show ();
1182 }
1183 #endregion
1184 }
1185 }

  ViewVC Help
Powered by ViewVC 1.1.22