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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22