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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22