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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- branches/mono/EmuXPortal/Form1.cs	2017/12/19 20:15:02	355
+++ branches/mono/EmuXPortal/Form1.cs	2019/05/02 03:09:26	377
@@ -1,11 +1,11 @@
 #define HAVE_X11_BORDERSTYLE_ERROR // indicates that there is an error with Control.set_InternalBorderStyle resulting in an X11 Error BadWindow (invalid Window parameter)
-
-//#define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden
-//#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar
-
+
+//#define DISABLE_CURSOR_HIDE // when this is present, the cursor will not be hidden
+//#define DISABLE_PROGRESS_PERCENTAGE_MESSASGE // when this is present, no progress percent message will be shown on any progressbar
+
 #define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
-//#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
-
+//#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
+
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -23,84 +23,76 @@
 using System.IO;
 using Enterprise.CrossPlatform;
 
-namespace EmuXPortal
-{	
-    public partial class Form1 : Form
-    {
+namespace EmuXPortal {
+	public partial class Form1 : Form {
 		static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR = System.Drawing.Color.Lime;
 		static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR_ERROR = System.Drawing.Color.Yellow;
 		static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR_LAUNCH = System.Drawing.Color.Blue;
 		static readonly System.Drawing.Color DEFAULT_TEXTFORECOLOR_MISSING = System.Drawing.Color.Red;
 
 
-		static bool bUserAbort =false;
-        static readonly Color SELECTED_CONTROL_BACKCOLOR = Color.SteelBlue;
-        const float PROGRESS_BAR_FONT_SIZE = 24;
-        private delegate Font Delegate_GetFormFont();
-        private delegate Font Delegate_ResizeFont(Font font, float size);
-        IEmuConfig CurrentSelectedRom = null;
-        PlatformControl CurrentPlatformControl = null;
-		int SavedPlatformIndex= -1;
-        GameControl CurrentGameControl = null;
+		static bool bUserAbort = false;
+		static readonly Color SELECTED_CONTROL_BACKCOLOR = Color.SteelBlue;
+		const float PROGRESS_BAR_FONT_SIZE = 24;
+		private delegate Font Delegate_GetFormFont ();
+		private delegate Font Delegate_ResizeFont (Font font, float size);
+		IEmuConfig CurrentSelectedRom = null;
+		PlatformControl CurrentPlatformControl = null;
+		int SavedPlatformIndex = -1;
+		GameControl CurrentGameControl = null;
 		private CustomProgressBar progress_bar;
 		private IPlatformCache cache = null;
 
-		static bool OnAbort()
-        {
-            return bUserAbort;
-        }
-        #region unhandled exception support
-        static void Application_Unhandled_ThreadException(object sender, ThreadExceptionEventArgs e)
-        {
-            UnhandledExceptionEventArgs uea = new UnhandledExceptionEventArgs(e.Exception, false);
-            UnhandledExceptionEventHandler(sender, uea);
-        }
-        static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs args)
-        {            
-            Exception ex = (args.ExceptionObject as Exception);
-            if (sender == null)
-            {
-                gLog.Error.WriteLine("Caught an unhandled exception from an unkown source");
-            }
-            else
-            {
-                gLog.Error.WriteLine("Caught an unhandled exception from type: {0}", sender.GetType().Name);
-            }
-
-            if (ex == null)
-            {
-                gLog.Error.WriteLine("The exception object was null -- it probably is not derived from System.Exception");
-            }
-            else
-            {
-                ex = ex.GetBaseException();
-                gLog.Error.WriteLine("{0}:", ex.GetType().Name);
-                gLog.Verbose.Error.WriteLine(ex.ToString());
-            }            
-            
-        }
-        #endregion
-        public Form1()
-        {
-            InitializeComponent();
-			this.progress_bar = new CustomProgressBar();
-			this.KeyPreview = true;
-         
-            #region logging support
-            string log_path = Application.StartupPath;
-            string log_filename = string.Format("{0}.log", typeof(Form1).Assembly.GetName().Name);
-			FileInfo log_file = new FileInfo(OSInfo.FormatPath(string.Format(@"{0}\{1}", log_path, log_filename)));
-
-            gLog.CreateLog(log_file.Name, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+		static bool OnAbort ()
+		{
+			return bUserAbort;
+		}
+		#region unhandled exception support
+		static void Application_Unhandled_ThreadException (object sender, ThreadExceptionEventArgs e)
+		{
+			UnhandledExceptionEventArgs uea = new UnhandledExceptionEventArgs (e.Exception, false);
+			UnhandledExceptionEventHandler (sender, uea);
+		}
+		static void UnhandledExceptionEventHandler (object sender, UnhandledExceptionEventArgs args)
+		{
+			Exception ex = (args.ExceptionObject as Exception);
+			if (sender == null) {
+				gLog.Error.WriteLine ("Caught an unhandled exception from an unkown source");
+			} else {
+				gLog.Error.WriteLine ("Caught an unhandled exception from type: {0}", sender.GetType ().Name);
+			}
+
+			if (ex == null) {
+				gLog.Error.WriteLine ("The exception object was null -- it probably is not derived from System.Exception");
+			} else {
+				ex = ex.GetBaseException ();
+				gLog.Error.WriteLine ("{0}:", ex.GetType ().Name);
+				gLog.Verbose.Error.WriteLine (ex.ToString ());
+			}
+
+		}
+		#endregion
+		public Form1 ()
+		{
+			InitializeComponent ();
+			this.progress_bar = new CustomProgressBar ();
+			this.KeyPreview = true;
+
+			#region logging support
+			string log_path = Application.StartupPath;
+			string log_filename = string.Format ("{0}.log", typeof (Form1).Assembly.GetName ().Name);
+			FileInfo log_file = new FileInfo (OSInfo.FormatPath (string.Format (@"{0}\{1}", log_path, log_filename)));
+
+			gLog.CreateLog (log_file.Name, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs> (Log_OnFlush));
 #if DEBUG
-            LogLevel gLevel = gLog.LogLevel;
+			LogLevel gLevel = gLog.LogLevel;
 #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
             gLevel &= ~LogLevel.kLogLevel_VerboseDebug;
 #else
-            gLevel |= LogLevel.kLogLevel_VerboseDebug;
+			gLevel |= LogLevel.kLogLevel_VerboseDebug;
 #endif
-            gLevel |= LogLevel.kLogLevel_Debug;
-            gLog.SetLogLevel(gLevel);
+			gLevel |= LogLevel.kLogLevel_Debug;
+			gLog.SetLogLevel (gLevel);
 #else
             LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
             // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
@@ -112,86 +104,87 @@
             gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode         
             gLog.SetLogLevel(gLevel);
 #endif
-            #endregion
-
-            #region unhandled exception support
-//            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
-//            Application.ThreadException += Application_Unhandled_ThreadException;
-            #endregion
-
-            platform_flow.Dock = DockStyle.Fill;
-            rom_flow.Dock = DockStyle.Fill;
-
-//            this.PreviewKeyDown += Form1_PreviewKeyDown;
-//            this.KeyPreview = true;
-			//progress_bar.PreviewKeyDown += Progress_bar_PreviewKeyDown;
-			this.KeyDown += Form1_KeyDown;
-			
-        }
-
-        void Form1_KeyDown (object sender, KeyEventArgs e)
+			#endregion
+
+			#region unhandled exception support
+			//            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
+			//            Application.ThreadException += Application_Unhandled_ThreadException;
+			#endregion
+
+			platform_flow.Dock = DockStyle.Fill;
+			rom_flow.Dock = DockStyle.Fill;
+
+			//            this.PreviewKeyDown += Form1_PreviewKeyDown;
+			//            this.KeyPreview = true;
+			//progress_bar.PreviewKeyDown += Progress_bar_PreviewKeyDown;
+			this.KeyDown += Form1_KeyDown;
+
+		}
+
+		void Form1_KeyDown (object sender, KeyEventArgs e)
 		{
-			if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {				
-				bAbortRomCopyToLocalCache = true; // this will cancel any copy operations
-			}
-        }
-
-       
-
-      
-#region logging support
-        void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) { OnLogFlush(e.Buffer); }
-        void OnLogFlush(string logmessage)
-        {
-            //if (this.IsDisposed) { return; }
-            ////UpdateStatus(logmessage);
-            ////UpdateLogOutput(logmessage);
-            //Application.DoEvents();
-        }
-#endregion
-
+			if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
+				bAbortRomCopyToLocalCache = true; // this will cancel any copy operations
+			}
+		}
+
+
+
+
+		#region logging support
+		void Log_OnFlush (object sender, LoggerOnFlushEventArgs e) { OnLogFlush (e.Buffer); }
+		void OnLogFlush (string logmessage)
+		{
+			//if (this.IsDisposed) { return; }
+			////UpdateStatus(logmessage);
+			////UpdateLogOutput(logmessage);
+			//Application.DoEvents();
+		}
+		#endregion
+
 		private bool bCachedLoaded = false;
-		private bool OnCacheLoaded() {
+		private bool OnCacheLoaded ()
+		{
 			return bCachedLoaded;
-		}
-
-        private void Form1_Load(object sender, EventArgs e)
-        {
+		}
+
+		private void Form1_Load (object sender, EventArgs e)
+		{
 
-			SplashLoader loader = new SplashLoader(new AbortEvent(OnCacheLoaded));
-			loader.Show();
-			cache = PlatformCache.Create (new AbortEvent (OnAbort));
-            Config.LoadConfig(cache);
-            Config.InitializePresentationForm(this);
-			bCachedLoaded = true;
-
-        }
-        private void Form1_Shown(object sender, EventArgs e)
-        {
-            platform_flow.Visible = true;
+			SplashLoader loader = new SplashLoader (new AbortEvent (OnCacheLoaded));
+			loader.Show ();
+			cache = PlatformCache.Create (new AbortEvent (OnAbort));
+			Config.LoadConfig (cache);
+			Config.InitializePresentationForm (this);
+			bCachedLoaded = true;
+
+		}
+		private void Form1_Shown (object sender, EventArgs e)
+		{
+			platform_flow.Visible = true;
 #if !DISABLE_CURSOR_HIDE
-            Cursor.Hide();
-#else 
+			Cursor.Hide ();
+#else
             Cursor.Show();
 #endif
-			
-        }
-		private bool bAbortRomCopyToLocalCache = false;
-        private bool OnAbortRomCopyToLocalCache ()
+
+		}
+		private bool bAbortRomCopyToLocalCache = false;
+		private bool OnAbortRomCopyToLocalCache ()
 		{
 			return bAbortRomCopyToLocalCache;
 		}
 
 		private void DeleteRomFromLocalCache (string rom_file, string rom_image)
-		{			
-			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
-			#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
+		{
+			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
+#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
 				progress_bar.ShowPercentageLabel = false;
-			#endif
+#endif
 			progress_bar.ProgressColor = Color.LimeGreen;
 			progress_bar.Dock = DockStyle.Top;
 			if (this.InvokeRequired) {
-				this.Invoke ((MethodInvoker)delegate() {
+				this.Invoke ((MethodInvoker)delegate () {
 					this.Controls.Add (progress_bar);
 				});
 			} else {
@@ -204,43 +197,43 @@
 			Application.DoEvents ();
 			if (!string.IsNullOrEmpty (rom_image)) {
 				if (rom_image.ToLower ().Contains (Config.RomPath.ToLower ())) {
-					gLog.Warn.WriteLine("Not deleteing rom image in path: {0}", rom_image);
+					gLog.Warn.WriteLine ("Not deleteing rom image in path: {0}", rom_image);
 					return;
 				}
-				progress_bar.Message = string.Format("Deleting local rom image: {0}", EmuXPortal.Api.Win32.CompactPath(rom_image));
-				File.Delete(rom_image);
+				progress_bar.Message = string.Format ("Deleting local rom image: {0}", EmuXPortal.Api.Win32.CompactPath (rom_image));
+				File.Delete (rom_image);
 				progress_bar.Value = 50;
 
 			}
 			if (!string.IsNullOrEmpty (rom_file)) {
 				if (rom_image.ToLower ().Contains (Config.RomPath.ToLower ())) {
-					gLog.Warn.WriteLine("Not deleteing rom file in path: {0}", rom_file);
+					gLog.Warn.WriteLine ("Not deleteing rom file in path: {0}", rom_file);
 					return;
 				}
-				progress_bar.Message = string.Format("Deleting local rom file: {0}", EmuXPortal.Api.Win32.CompactPath(rom_file));
-				File.Delete(rom_file);
+				progress_bar.Message = string.Format ("Deleting local rom file: {0}", EmuXPortal.Api.Win32.CompactPath (rom_file));
+				File.Delete (rom_file);
 				progress_bar.Value = 100;
 			}
 			if (this.InvokeRequired) {
-				this.Invoke ((MethodInvoker)delegate() {
+				this.Invoke ((MethodInvoker)delegate () {
 					this.Controls.Remove (progress_bar);
 				});
 			} else {
 				this.Controls.Remove (progress_bar);
 			}
 			Application.DoEvents ();
-		}
-        private void CopyRomToLocalCache (string src_rom_file, string dst_rom_file, string src_rom_image, string dst_rom_image)
+		}
+		private void CopyRomToLocalCache (string src_rom_file, string dst_rom_file, string src_rom_image, string dst_rom_image)
 		{
-			bAbortRomCopyToLocalCache = false; // reset the copy abort flag
-			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
-			#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
+			bAbortRomCopyToLocalCache = false; // reset the copy abort flag
+			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
+#if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
 				progress_bar.ShowPercentageLabel = false;
-			#endif
+#endif
 			progress_bar.ProgressColor = Color.LimeGreen;
 			progress_bar.Dock = DockStyle.Top;
 			if (this.InvokeRequired) {
-				this.Invoke ((MethodInvoker)delegate() {
+				this.Invoke ((MethodInvoker)delegate () {
 					this.Controls.Add (progress_bar);
 				});
 			} else {
@@ -257,7 +250,7 @@
 				cp = new FileProgressCopier (src_rom_image, dst_rom_image, new CopyProgressEvent (OnFileCopyProgress), new AbortEvent (OnAbortRomCopyToLocalCache));
 				cp.Start ();
 				while (!cp.CopyFinished) {
-					Application.DoEvents();
+					Application.DoEvents ();
 				}
 			}
 			if (!string.IsNullOrEmpty (src_rom_file) && !string.IsNullOrEmpty (dst_rom_file)) {
@@ -265,89 +258,90 @@
 				cp = new FileProgressCopier (src_rom_file, dst_rom_file, new CopyProgressEvent (OnFileCopyProgress), new AbortEvent (OnAbortRomCopyToLocalCache));
 				cp.Start ();
 				while (!cp.CopyFinished) {
-					Application.DoEvents();
+					Application.DoEvents ();
 				}
 			}
 			if (this.InvokeRequired) {
-				this.Invoke ((MethodInvoker)delegate() {
+				this.Invoke ((MethodInvoker)delegate () {
 					this.Controls.Remove (progress_bar);
 				});
 			} else {
 				this.Controls.Remove (progress_bar);
 			}
-			Application.DoEvents ();
-        }
-		public void OnFileCopyProgress (object sender, int progress, string message)
-		{
-			//gLog.Debug.WriteLine("{0} [{1}%]", message, progress);
-
-			if (progress_bar.InvokeRequired) {
-					progress_bar.Invoke (new MethodInvoker (delegate {
-						progress_bar.Message = message;
-						progress_bar.Value = progress;
-						progress_bar.Update ();
-						Application.DoEvents();
-					}));
-				} else {
-					progress_bar.Message = message;
-					progress_bar.Value = progress;
-					progress_bar.Update ();
-					Application.DoEvents();
-				}
+			Application.DoEvents ();
 		}
-        void ReleasePlatformControlStreams ()
+		public void OnFileCopyProgress (object sender, int progress, string message)
+		{
+			//gLog.Debug.WriteLine("{0} [{1}%]", message, progress);
+
+			if (progress_bar.InvokeRequired) {
+				progress_bar.Invoke (new MethodInvoker (delegate {
+					progress_bar.Message = message;
+					progress_bar.Value = progress;
+					progress_bar.Update ();
+					Application.DoEvents ();
+				}));
+			} else {
+				progress_bar.Message = message;
+				progress_bar.Value = progress;
+				progress_bar.Update ();
+				Application.DoEvents ();
+			}
+		}
+		void ReleasePlatformControlStreams ()
 		{
 			foreach (var c in platform_flow.Controls) {
-				if (c.GetType () == typeof(PlatformControl)) {
+				if (c.GetType () == typeof (PlatformControl)) {
 					PlatformControl pc = (c as PlatformControl);
 					if (pc != null) {
-						pc.ReleasePlatformStream();
+						pc.ReleasePlatformStream ();
 					}
 				}
-			}
-        }
-		void ReleaseGameControlStreams() {
+			}
+		}
+		void ReleaseGameControlStreams ()
+		{
 			foreach (var c in rom_flow.Controls) {
-				if (c.GetType () == typeof(GameControl)) {
+				if (c.GetType () == typeof (GameControl)) {
 					GameControl gc = (c as GameControl);
 					if (gc != null) {
-						gc.ReleaseGameStream();
+						gc.ReleaseGameStream ();
 					}
 				}
-			}
-        }
-        void platform_ctrl_LostFocus(object sender, EventArgs e)
-        {
-            PlatformControl c = sender as PlatformControl;
-			if (c != null) {
-				#if !HAVE_X11_BORDERSTYLE_ERROR
+			}
+		}
+		void platform_ctrl_LostFocus (object sender, EventArgs e)
+		{
+			PlatformControl c = sender as PlatformControl;
+			if (c != null) {
+#if !HAVE_X11_BORDERSTYLE_ERROR
 				c.BorderStyle = BorderStyle.None;
-				#endif
+#endif
 				c.BackColor = this.BackColor;
-			}
-        }
-
-        void platform_ctrl_GotFocus(object sender, EventArgs e)
-        {			
-            PlatformControl c = sender as PlatformControl;
-			if (c != null) {
-				#if !HAVE_X11_BORDERSTYLE_ERROR
+			}
+		}
+
+		void platform_ctrl_GotFocus (object sender, EventArgs e)
+		{
+			PlatformControl c = sender as PlatformControl;
+			if (c != null) {
+#if !HAVE_X11_BORDERSTYLE_ERROR
 				c.BorderStyle = BorderStyle.FixedSingle;
-				#endif
-				c.BackColor = SELECTED_CONTROL_BACKCOLOR; 
+#endif
+				c.BackColor = SELECTED_CONTROL_BACKCOLOR;
 				CurrentPlatformControl = c;
-			}
-        }
-
-        void game_ctrl_PreviewKeyDown (object sender, PreviewKeyDownEventArgs e)
-		{
-			//gLog.Verbose.Debug.WriteLine ("game_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
+			}
+		}
+
+		void game_ctrl_PreviewKeyDown (object sender, PreviewKeyDownEventArgs e)
+		{
+			//gLog.Verbose.Debug.WriteLine ("game_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
 			GameControl c = sender as GameControl;
 
 			int changeAmount = 0;
 			int currentPosition = 0;
 			IRomConfig config = null;
-			if (e.KeyCode == Keys.C && (e.Modifiers & Keys.Control) == Keys.Control) {				
+			if (e.KeyCode == Keys.C && (e.Modifiers & Keys.Control) == Keys.Control) {
 				config = (c.Tag as IRomConfig);
 				if (config != null) {
 					string platform_short = config.EmuConfig.PlatformNameShort;
@@ -358,24 +352,33 @@
 					string rom_imagefilename = "";
 					FileInfo fi = null;
 					try {
-						fi = new FileInfo (rom_file);
-						rom_filename = fi.Name;
+						if (!string.IsNullOrEmpty (rom_file)) {
+							fi = new FileInfo (rom_file);
+							rom_filename = fi.Name;
+						}
 					} finally {
 						fi = null;
 					}
 					try {
-						fi = new FileInfo (rom_image);
-						rom_imagefilename = fi.Name;
+						if (!string.IsNullOrEmpty (rom_image)) {
+							fi = new FileInfo (rom_image);
+							rom_imagefilename = fi.Name;
+						}
 					} finally {
 						fi = null;
 					}
 
-					string local_path = Config.LocalRomPath.TrimEnd (new char[]{ '/' });
+					string local_path = Config.LocalRomPath.TrimEnd (new char [] { '/' });
 					string local_rom_path = string.Format ("{0}/{1}", local_path, platform_short);
-					string local_romfile = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_filename));
-					string local_romimage = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_imagefilename));
+					string local_romfile = string.IsNullOrEmpty(rom_filename) ? "" : OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_filename));
+					string local_romimage = string.IsNullOrEmpty(rom_imagefilename) ? "" : OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_imagefilename));
 
-					// create the local rom path for this platform
+					if (string.IsNullOrEmpty (local_romfile)) {
+						gLog.Error.WriteLine ("Local rom file could not be found. [src rom={0}]", rom_file);
+						return;
+					}
+
+					// create the local rom path for this platform
 					DirectoryInfo di = new DirectoryInfo (local_rom_path);
 					if (!di.Exists) {
 						di.Create ();
@@ -385,7 +388,7 @@
 					this.Enabled = true;
 				}
 			}
-			if (e.KeyCode == Keys.D && (e.Modifiers & Keys.Control) == Keys.Control) {								
+			if (e.KeyCode == Keys.D && (e.Modifiers & Keys.Control) == Keys.Control) {
 				config = (c.Tag as IRomConfig);
 				if (config != null) {
 					string platform_short = config.EmuConfig.PlatformNameShort;
@@ -407,7 +410,7 @@
 					} finally {
 						fi = null;
 					}
-					string local_path = Config.LocalRomPath.TrimEnd (new char[]{ '/' });
+					string local_path = Config.LocalRomPath.TrimEnd (new char [] { '/' });
 					string local_rom_path = string.Format ("{0}/{1}", local_path, platform_short);
 					string local_romfile = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_filename));
 					string local_romimage = OSInfo.FormatPath (string.Format ("{0}/{1}", local_rom_path, rom_imagefilename));
@@ -422,9 +425,9 @@
 					gLog.Error.WriteLine ("Unable to add/remove from/to favorites (config) is null");
 				} else {
 					var isFavorite = RomFavorite.IsFavorite (config);
-					if (isFavorite) {
-						// add to favorites
-						//gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+					if (isFavorite) {
+						// add to favorites
+						//gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
 						if (!RomFavorite.RemoveFavorite (config)) {
 							gLog.Error.WriteLine ("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
 						} else {
@@ -440,26 +443,26 @@
 										}
 									}
 								}
-							}                       
+							}
 						}
-					} else {
-						// add to favorites
-						//gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+					} else {
+						// add to favorites
+						//gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
 						if (!RomFavorite.AddFavorite (config)) {
 							gLog.Error.WriteLine ("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
 						} else {
 							gLog.Info.WriteLine ("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
 						}
-					}
-					//gLog.Debug.WriteLine("Updateing favorites");
+					}
+					//gLog.Debug.WriteLine("Updateing favorites");
 					if (!RomFavorite.UpdateFavorites (cache)) {
 						gLog.Error.WriteLine ("Failed to update favorites");
 					} else {
 						gLog.Info.WriteLine ("Updated favorites");
 					}
 				}
-				return; // stop processing other keys
-
+				return; // stop processing other keys
+
 			}
 			if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
 				if (OSInfo.OSIsUnix) {
@@ -476,7 +479,7 @@
 					rom_flow.ScrollControlIntoView (ctl);
 					rom_flow.ResumeLayout (false);
 				}
-			}		
+			}
 			if (e.KeyCode == Keys.Home) {
 				rom_flow.SuspendLayout ();
 				rom_flow.Controls [0].Select ();
@@ -533,7 +536,7 @@
 				rom_flow.ResumeLayout (false);
 			}
 
-			if (e.KeyCode == Keys.Enter) {				
+			if (e.KeyCode == Keys.Enter) {
 				config = c.Tag as IRomConfig;
 				if (config.RomExists) {
 					c.TextForeColor = DEFAULT_TEXTFORECOLOR_LAUNCH;
@@ -557,8 +560,8 @@
 						} else {
 							p.StartInfo.FileName = binary;
 							p.StartInfo.Arguments = arguments == null ? "" : arguments;
-							p.Start ();
-							// wait for exit of game
+							p.Start ();
+							// wait for exit of game
 							p.WaitForExit ();
 							c.TextForeColor = DEFAULT_TEXTFORECOLOR;
 							c.GameName = gamename;
@@ -570,62 +573,55 @@
 					}
 				} else {
 					c.TextForeColor = Color.Red;
-				}
-            }
-			if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape)
-            {		
-            		
-            	bAbortRomCopyToLocalCache = true; // this will cancel any copy operations
-				ReleaseGameControlStreams();
-				SavedPlatformIndex = platform_flow.Controls.IndexOf (CurrentPlatformControl);
-                rom_flow.Visible = false;
-                platform_flow.Visible = true;
-            }
-
-            if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
-                (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
-            {
-                rom_flow.SuspendLayout();
-                char t = (char)e.KeyCode;
-                GameControl ctrl = (rom_flow.GetNextControl(CurrentGameControl, true) as GameControl);
-                if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); }
-                bool found = false;
-                GameControl pc = CurrentGameControl;
-                bool wrapped = false;
-                bool not_found = true;
-                while (!found)
-                {
-                    if (wrapped)
-                    {
-                        foreach (Control ctl in rom_flow.Controls)
-                        {
-                            GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
-                        }
-                        if (not_found) { found = true; }
-                    }
-                    ctrl = (rom_flow.GetNextControl(pc, true) as GameControl);
-                    if (ctrl == null)
-                    {
-                        ctrl = rom_flow.Controls[0] as GameControl;
-                        wrapped = true;
-                    }
-                    if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower()))
-                    {
-                        rom_flow.ScrollControlIntoView(ctrl);
-                        ctrl.Select();
-                        found = true;
-                    }
-                    pc = ctrl;
-                }
-                rom_flow.ResumeLayout(false);
-            }
-        }
-        void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
-        {
-			//gLog.Verbose.Debug.WriteLine ("platform_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
-            PlatformControl c = sender as PlatformControl;
-            int changeAmount = 0;
-            int currentPosition = 0;
+				}
+			}
+			if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
+
+				bAbortRomCopyToLocalCache = true; // this will cancel any copy operations
+				ReleaseGameControlStreams ();
+				SavedPlatformIndex = platform_flow.Controls.IndexOf (CurrentPlatformControl);
+				rom_flow.Visible = false;
+				platform_flow.Visible = true;
+			}
+
+			if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
+			    (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) {
+				rom_flow.SuspendLayout ();
+				char t = (char)e.KeyCode;
+				GameControl ctrl = (rom_flow.GetNextControl (CurrentGameControl, true) as GameControl);
+				if (ctrl == null) { ctrl = (rom_flow.GetNextControl (rom_flow.Controls [0], true) as GameControl); }
+				bool found = false;
+				GameControl pc = CurrentGameControl;
+				bool wrapped = false;
+				bool not_found = true;
+				while (!found) {
+					if (wrapped) {
+						foreach (Control ctl in rom_flow.Controls) {
+							GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower ().StartsWith (t.ToString ().ToLower ())) { not_found = false; }
+						}
+						if (not_found) { found = true; }
+					}
+					ctrl = (rom_flow.GetNextControl (pc, true) as GameControl);
+					if (ctrl == null) {
+						ctrl = rom_flow.Controls [0] as GameControl;
+						wrapped = true;
+					}
+					if (ctrl.GameName.ToLower ().StartsWith (t.ToString ().ToLower ())) {
+						rom_flow.ScrollControlIntoView (ctrl);
+						ctrl.Select ();
+						found = true;
+					}
+					pc = ctrl;
+				}
+				rom_flow.ResumeLayout (false);
+			}
+		}
+		void platform_ctrl_PreviewKeyDown (object sender, PreviewKeyDownEventArgs e)
+		{
+			//gLog.Verbose.Debug.WriteLine ("platform_ctrl_PreviewKeyDown() fired -- keycode [{0}]", e.KeyCode);
+			PlatformControl c = sender as PlatformControl;
+			int changeAmount = 0;
+			int currentPosition = 0;
 			if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
 				if (OSInfo.OSIsUnix) {
 					platform_flow.SuspendLayout ();
@@ -641,190 +637,167 @@
 					platform_flow.ScrollControlIntoView (ctl);
 					platform_flow.ResumeLayout (false);
 				}
-			}
-            if (e.KeyCode == Keys.Home)
-            {
-                platform_flow.SuspendLayout();
-                platform_flow.Controls[0].Select();
-                platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
-                platform_flow.ResumeLayout(false);
-            }
-            if (e.KeyCode == Keys.End)
-            {
-                platform_flow.SuspendLayout();
-                platform_flow.Controls[platform_flow.Controls.Count -1].Select();
-                platform_flow.ScrollControlIntoView(platform_flow.Controls[platform_flow.Controls.Count - 1]);
-                platform_flow.ResumeLayout(false);
-            }
-            if (e.KeyCode == Keys.PageUp)
-            {
-                platform_flow.SuspendLayout();
-                changeAmount = platform_flow.VerticalScroll.LargeChange;
-                currentPosition = platform_flow.VerticalScroll.Value;
-                if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum)
-                {
-                    platform_flow.VerticalScroll.Value -= changeAmount;
-                }
-                else
-                {
-                    platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum;
-                }
-                PlatformControl s = platform_ctrl_get_last_visible();
-                s.Select();
-                platform_flow.ScrollControlIntoView(s);
-                platform_flow.ResumeLayout(false);
-            }
-            if (e.KeyCode == Keys.PageDown)
-            {
-                platform_flow.SuspendLayout();
-                changeAmount = platform_flow.VerticalScroll.LargeChange;
-                currentPosition = platform_flow.VerticalScroll.Value;
-                if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum)
-                {
-                    try
-                    {
-                        platform_flow.VerticalScroll.Value += changeAmount;
-                    }
-                    catch
-                    {
-                        platform_flow.Controls[0].Select();
-                        platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
-                        rom_flow.PerformLayout();
-                        return;
-                    }
-                }
-                else
-                {
-                    platform_flow.Controls[0].Select();
-                    platform_flow.ScrollControlIntoView(platform_flow.Controls[0]);
-                }
-                PlatformControl s = platform_ctrl_get_last_visible();
-                s.Select();
-                platform_flow.ScrollControlIntoView(s);
-                platform_flow.ResumeLayout(false);
-            }
-            if (e.KeyCode == Keys.Enter)
-            {
-				ReleasePlatformControlStreams();
-                // load this platform				
-                platform_flow.Visible = false;
-                CurrentSelectedRom = c.Tag as IEmuConfig;				
-                rom_flow.Visible = true;
-                rom_flow.BringToFront();
-            }
-			if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape)
-            {
-            	bAbortRomCopyToLocalCache = true;
-				ReleasePlatformControlStreams();
-                this.Close();
-            }
-            if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
-                (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
-            {
-                platform_flow.SuspendLayout();
-                char t = (char)e.KeyCode;
-                PlatformControl ctrl = (platform_flow.GetNextControl(CurrentPlatformControl, true) as PlatformControl);
-                if (ctrl == null) { ctrl = (platform_flow.GetNextControl(platform_flow.Controls[0], true) as PlatformControl); }
-                bool found = false;
-                PlatformControl pc = CurrentPlatformControl;
-                bool wrapped = false;
-                bool not_found = true;
-                while (!found)
-                {
-                    if (wrapped)
-                    {
-                        foreach (Control ctl in platform_flow.Controls) 
-                        { 
-                            PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; } 
-                        }
-                        if (not_found) { found = true; }
-                    }
-                    ctrl = (platform_flow.GetNextControl(pc, true) as PlatformControl);
-                    if (ctrl == null)
-                    {
-                        ctrl = platform_flow.Controls[0] as PlatformControl;
-                        wrapped = true;
-                    }
-                    if (ctrl.PlatformName.ToLower().StartsWith(t.ToString().ToLower()))
-                    {
-                        platform_flow.ScrollControlIntoView(ctrl);
-                        ctrl.Select();
-                        found = true;
-                    }
-                    pc = ctrl;
-                }
-                platform_flow.ResumeLayout(false);
-            }
-        }
-
-        private void platform_flow_VisibleChanged(object sender, EventArgs e)
-        {
-            if (!platform_flow.Visible) return;
-            platform_flow.Controls.Clear();
-            platform_flow.BringToFront();
-            Stopwatch t = new Stopwatch();
-            t.Start();
-            platformWorker.RunWorkerAsync(t);
-        }
-
-        private void rom_flow_VisibleChanged(object sender, EventArgs e)
-        {
-            if (!rom_flow.Visible) return;
-            rom_flow.Controls.Clear();
-            rom_flow.BringToFront();
-            Stopwatch t = new Stopwatch();
-            t.Start();
-            gameWorker.RunWorkerAsync(t);
-        }
-
-        void game_ctrl_LostFocus(object sender, EventArgs e)
-        {
-            GameControl c = sender as GameControl;
-			#if !HAVE_X11_BORDERSTYLE_ERROR
+			}
+			if (e.KeyCode == Keys.Home) {
+				platform_flow.SuspendLayout ();
+				platform_flow.Controls [0].Select ();
+				platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
+				platform_flow.ResumeLayout (false);
+			}
+			if (e.KeyCode == Keys.End) {
+				platform_flow.SuspendLayout ();
+				platform_flow.Controls [platform_flow.Controls.Count - 1].Select ();
+				platform_flow.ScrollControlIntoView (platform_flow.Controls [platform_flow.Controls.Count - 1]);
+				platform_flow.ResumeLayout (false);
+			}
+			if (e.KeyCode == Keys.PageUp) {
+				platform_flow.SuspendLayout ();
+				changeAmount = platform_flow.VerticalScroll.LargeChange;
+				currentPosition = platform_flow.VerticalScroll.Value;
+				if ((currentPosition - changeAmount) > platform_flow.VerticalScroll.Minimum) {
+					platform_flow.VerticalScroll.Value -= changeAmount;
+				} else {
+					platform_flow.VerticalScroll.Value = platform_flow.VerticalScroll.Minimum;
+				}
+				PlatformControl s = platform_ctrl_get_last_visible ();
+				s.Select ();
+				platform_flow.ScrollControlIntoView (s);
+				platform_flow.ResumeLayout (false);
+			}
+			if (e.KeyCode == Keys.PageDown) {
+				platform_flow.SuspendLayout ();
+				changeAmount = platform_flow.VerticalScroll.LargeChange;
+				currentPosition = platform_flow.VerticalScroll.Value;
+				if ((currentPosition - changeAmount) < platform_flow.VerticalScroll.Maximum) {
+					try {
+						platform_flow.VerticalScroll.Value += changeAmount;
+					} catch {
+						platform_flow.Controls [0].Select ();
+						platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
+						rom_flow.PerformLayout ();
+						return;
+					}
+				} else {
+					platform_flow.Controls [0].Select ();
+					platform_flow.ScrollControlIntoView (platform_flow.Controls [0]);
+				}
+				PlatformControl s = platform_ctrl_get_last_visible ();
+				s.Select ();
+				platform_flow.ScrollControlIntoView (s);
+				platform_flow.ResumeLayout (false);
+			}
+			if (e.KeyCode == Keys.Enter) {
+				ReleasePlatformControlStreams ();
+				// load this platform				
+				platform_flow.Visible = false;
+				CurrentSelectedRom = c.Tag as IEmuConfig;
+				rom_flow.Visible = true;
+				rom_flow.BringToFront ();
+			}
+			if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape) {
+				bAbortRomCopyToLocalCache = true;
+				ReleasePlatformControlStreams ();
+				this.Close ();
+			}
+			if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
+			    (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)) {
+				platform_flow.SuspendLayout ();
+				char t = (char)e.KeyCode;
+				PlatformControl ctrl = (platform_flow.GetNextControl (CurrentPlatformControl, true) as PlatformControl);
+				if (ctrl == null) { ctrl = (platform_flow.GetNextControl (platform_flow.Controls [0], true) as PlatformControl); }
+				bool found = false;
+				PlatformControl pc = CurrentPlatformControl;
+				bool wrapped = false;
+				bool not_found = true;
+				while (!found) {
+					if (wrapped) {
+						foreach (Control ctl in platform_flow.Controls) {
+							PlatformControl p_ctl = ctl as PlatformControl; if (p_ctl.PlatformName.ToLower ().StartsWith (t.ToString ().ToLower ())) { not_found = false; }
+						}
+						if (not_found) { found = true; }
+					}
+					ctrl = (platform_flow.GetNextControl (pc, true) as PlatformControl);
+					if (ctrl == null) {
+						ctrl = platform_flow.Controls [0] as PlatformControl;
+						wrapped = true;
+					}
+					if (ctrl.PlatformName.ToLower ().StartsWith (t.ToString ().ToLower ())) {
+						platform_flow.ScrollControlIntoView (ctrl);
+						ctrl.Select ();
+						found = true;
+					}
+					pc = ctrl;
+				}
+				platform_flow.ResumeLayout (false);
+			}
+		}
+
+		private void platform_flow_VisibleChanged (object sender, EventArgs e)
+		{
+			if (!platform_flow.Visible) return;
+			platform_flow.Controls.Clear ();
+			platform_flow.BringToFront ();
+			Stopwatch t = new Stopwatch ();
+			t.Start ();
+			platformWorker.RunWorkerAsync (t);
+		}
+
+		private void rom_flow_VisibleChanged (object sender, EventArgs e)
+		{
+			if (!rom_flow.Visible) return;
+			rom_flow.Controls.Clear ();
+			rom_flow.BringToFront ();
+			Stopwatch t = new Stopwatch ();
+			t.Start ();
+			gameWorker.RunWorkerAsync (t);
+		}
+
+		void game_ctrl_LostFocus (object sender, EventArgs e)
+		{
+			GameControl c = sender as GameControl;
+#if !HAVE_X11_BORDERSTYLE_ERROR
             c.BorderStyle = BorderStyle.None;
-			#endif
-            c.BackColor = this.BackColor;
-        }
-
-        void game_ctrl_GotFocus(object sender, EventArgs e)
-        {
-            GameControl c = sender as GameControl;
-			#if !HAVE_X11_BORDERSTYLE_ERROR
+#endif
+			c.BackColor = this.BackColor;
+		}
+
+		void game_ctrl_GotFocus (object sender, EventArgs e)
+		{
+			GameControl c = sender as GameControl;
+#if !HAVE_X11_BORDERSTYLE_ERROR
             c.BorderStyle = BorderStyle.FixedSingle;
-			#endif
-            c.BackColor = SELECTED_CONTROL_BACKCOLOR;
-            CurrentGameControl = c;
-        }
-
-        private GameControl game_ctrl_get_last_visible()
-        {
-            GameControl s = new GameControl();
-            foreach (GameControl c in rom_flow.Controls)
-            {
-                if (c.Bounds.IntersectsWith(rom_flow.Bounds))
-                    s = c;
-            }
-            return s;
-        }
-        private PlatformControl platform_ctrl_get_last_visible()
-        {
-            PlatformControl s = new PlatformControl();
-            foreach (PlatformControl c in platform_flow.Controls)
-            {
-                if (c.Bounds.IntersectsWith(platform_flow.Bounds))
-                    s = c;
-            }
-            return s;
-        }
-		private PlatformControl platform_ctrl_get_next_control(bool update_control)
+#endif
+			c.BackColor = SELECTED_CONTROL_BACKCOLOR;
+			CurrentGameControl = c;
+		}
+
+		private GameControl game_ctrl_get_last_visible ()
+		{
+			GameControl s = new GameControl ();
+			foreach (GameControl c in rom_flow.Controls) {
+				if (c.Bounds.IntersectsWith (rom_flow.Bounds))
+					s = c;
+			}
+			return s;
+		}
+		private PlatformControl platform_ctrl_get_last_visible ()
+		{
+			PlatformControl s = new PlatformControl ();
+			foreach (PlatformControl c in platform_flow.Controls) {
+				if (c.Bounds.IntersectsWith (platform_flow.Bounds))
+					s = c;
+			}
+			return s;
+		}
+		private PlatformControl platform_ctrl_get_next_control (bool update_control)
 		{
-			PlatformControl s = new PlatformControl();
+			PlatformControl s = new PlatformControl ();
 			int index = platform_flow.Controls.IndexOf (CurrentPlatformControl);
 			index = index + 1;
 			if (index < 0) {
-				index = platform_flow.Controls.Count-1;
+				index = platform_flow.Controls.Count - 1;
 			}
-			if (index > platform_flow.Controls.Count-1) {
+			if (index > platform_flow.Controls.Count - 1) {
 				index = 0;
 			}
 			s = platform_flow.Controls [index] as PlatformControl;
@@ -834,15 +807,15 @@
 			}
 			return s;
 		}
-		private PlatformControl platform_ctrl_get_previous_control(bool update_control)
+		private PlatformControl platform_ctrl_get_previous_control (bool update_control)
 		{
 			PlatformControl s = null;
 			int index = platform_flow.Controls.IndexOf (CurrentPlatformControl);
 			index = index - 1;
 			if (index < 0) {
-				index = platform_flow.Controls.Count-1;
+				index = platform_flow.Controls.Count - 1;
 			}
-			if (index > platform_flow.Controls.Count-1) {
+			if (index > platform_flow.Controls.Count - 1) {
 				index = 0;
 			}
 			s = platform_flow.Controls [index] as PlatformControl;
@@ -852,15 +825,15 @@
 			}
 			return s;
 		}
-		private GameControl game_ctrl_get_next_control(bool update_control)
+		private GameControl game_ctrl_get_next_control (bool update_control)
 		{
-			GameControl s = new GameControl();
+			GameControl s = new GameControl ();
 			int index = rom_flow.Controls.IndexOf (CurrentGameControl);
 			index = index + 1;
 			if (index < 0) {
-				index = rom_flow.Controls.Count-1;
+				index = rom_flow.Controls.Count - 1;
 			}
-			if (index > rom_flow.Controls.Count-1) {
+			if (index > rom_flow.Controls.Count - 1) {
 				index = 0;
 			}
 			s = rom_flow.Controls [index] as GameControl;
@@ -870,15 +843,15 @@
 			}
 			return s;
 		}
-		private GameControl game_ctrl_get_previous_control(bool update_control)
+		private GameControl game_ctrl_get_previous_control (bool update_control)
 		{
-			GameControl s = new GameControl();
+			GameControl s = new GameControl ();
 			int index = rom_flow.Controls.IndexOf (CurrentGameControl);
 			index = index - 1;
 			if (index < 0) {
-				index = rom_flow.Controls.Count-1;
+				index = rom_flow.Controls.Count - 1;
 			}
-			if (index > rom_flow.Controls.Count-1) {
+			if (index > rom_flow.Controls.Count - 1) {
 				index = 0;
 			}
 			s = rom_flow.Controls [index] as GameControl;
@@ -887,82 +860,73 @@
 				s.Select ();
 			}
 			return s;
-		}
-      
-
-        #region Background Workers
-
-        private int GetFormWidth()
-        {
-            if (this.InvokeRequired)
-            {
-                return Convert.ToInt32(this.Invoke((MethodInvoker)delegate() { GetFormWidth(); }));
-            }
-            else
-            {
-                return this.Width;
-            }
-        }
-        private Font GetFormFont()
-        {
-            if (this.InvokeRequired)
-            {
-                return (this.Invoke(new Delegate_GetFormFont(GetFormFont)) as Font);
-            }
-            else
-            {
-                return this.Font;
-            }
-        }
-
-        private Font ResizeFont(Font font, float size)
-        {
-            if (this.InvokeRequired)
-            {
-                 return (this.Invoke(new Delegate_ResizeFont(ResizeFont), new object[] { font, size })as Font);
-            }
-            else
-            {
-                return new Font(font.FontFamily, size);
-            }
-        }
-
-        //private void AddPlatformControl(Control c)
-        //{          
-        //    if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
-        //    else 
-        //    {
-        //        platform_flow.Controls.Add(c);            
-        //    }            
-        //}
-        //private void UpdatePlatformControls() 
-        //{
-        //    //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); }
-        //    //else { this.Update(); }
-        //}
-        //private void AddGameControl(Control c)
-        //{
-        //    if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); }
-        //    else
-        //    {              
-        //        rom_flow.Controls.Add(c);
-        //    }
-        //}
-        //private void UpdateGameControls()
-        //{
-        //    //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); }
-        //    //else { this.Update(); }
-        //}
-        #region gameWorker
-        private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
-        private object gameimage_lock = new object();
+		}
+
+
+		#region Background Workers
+
+		private int GetFormWidth ()
+		{
+			if (this.InvokeRequired) {
+				return Convert.ToInt32 (this.Invoke ((MethodInvoker)delegate () { GetFormWidth (); }));
+			} else {
+				return this.Width;
+			}
+		}
+		private Font GetFormFont ()
+		{
+			if (this.InvokeRequired) {
+				return (this.Invoke (new Delegate_GetFormFont (GetFormFont)) as Font);
+			} else {
+				return this.Font;
+			}
+		}
+
+		private Font ResizeFont (Font font, float size)
+		{
+			if (this.InvokeRequired) {
+				return (this.Invoke (new Delegate_ResizeFont (ResizeFont), new object [] { font, size }) as Font);
+			} else {
+				return new Font (font.FontFamily, size);
+			}
+		}
+
+		//private void AddPlatformControl(Control c)
+		//{          
+		//    if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { AddPlatformControl(c); }); }
+		//    else 
+		//    {
+		//        platform_flow.Controls.Add(c);            
+		//    }            
+		//}
+		//private void UpdatePlatformControls() 
+		//{
+		//    //if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { UpdatePlatformControls(); }); }
+		//    //else { this.Update(); }
+		//}
+		//private void AddGameControl(Control c)
+		//{
+		//    if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { AddGameControl(c); }); }
+		//    else
+		//    {              
+		//        rom_flow.Controls.Add(c);
+		//    }
+		//}
+		//private void UpdateGameControls()
+		//{
+		//    //if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { UpdateGameControls(); }); }
+		//    //else { this.Update(); }
+		//}
+		#region gameWorker
+		private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
+		private object gameimage_lock = new object ();
 		private void worker_progress_event (object event_source, ProgressEventArgs event_args)
-		{
-			//gLog.Debug.WriteLine ("worker_progress_event called!");
+		{
+			//gLog.Debug.WriteLine ("worker_progress_event called!");
 			object user_object = event_args.GetUserObject ();
-			int progress = event_args.GetProgress();
-			string message = event_args.GetUserMessage() == null ? "" : event_args.GetUserMessage();
-			if (user_object != null) {				
+			int progress = event_args.GetProgress ();
+			string message = event_args.GetUserMessage () == null ? "" : event_args.GetUserMessage ();
+			if (user_object != null) {
 				IRomConfig irc = (user_object as IRomConfig);
 				if (irc != null) {
 					gLog.Verbose.Debug.WriteLine ("Read Rom[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, irc);
@@ -977,18 +941,18 @@
 				progress_bar.Invoke (new MethodInvoker (delegate {
 					progress_bar.Message = message;
 					progress_bar.Value = progress;
-					progress_bar.Update();
+					progress_bar.Update ();
 				}));
 			} else {
 				progress_bar.Message = message;
 				progress_bar.Value = progress;
-				progress_bar.Update();
+				progress_bar.Update ();
 			}
-		}
-        private void gameWorker_DoWork (object sender, DoWorkEventArgs e)
+		}
+		private void gameWorker_DoWork (object sender, DoWorkEventArgs e)
 		{
 			Stopwatch t = e.Argument as Stopwatch;
-			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
+			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
             progress_bar.ShowPercentageLabel = false;
 #endif
@@ -996,7 +960,7 @@
 			progress_bar.Dock = DockStyle.Top;
 
 			if (this.InvokeRequired) {
-				this.Invoke ((MethodInvoker)delegate() {
+				this.Invoke ((MethodInvoker)delegate () {
 					this.Controls.Add (progress_bar);
 				});
 			} else {
@@ -1008,7 +972,7 @@
 			}));
 
 			HashSet<IRomConfig> roms = new HashSet<IRomConfig> ();
-			using (RomParser parser = new RomParser (cache, CurrentSelectedRom, new ProgressEvent (worker_progress_event))) {				
+			using (RomParser parser = new RomParser (cache, CurrentSelectedRom, new ProgressEvent (worker_progress_event))) {
 				foreach (var rom in parser.Roms) {
 					roms.Add (rom);
 				}
@@ -1033,17 +997,17 @@
 				game_ctrl.Width = this.Width - 10;
 				game_ctrl.Tag = config;
 				try {
-					lock (gameimage_lock) {
-						//gLog.Debug.WriteLine ("handling rom: {0}", config.ToString ());
-						if (String.IsNullOrEmpty (config.RomImage)) {
-							game_ctrl.UpdateGameImage ((Image)DefaultGameImage.Clone ());
-						} else {
+					lock (gameimage_lock) {
+						//gLog.Debug.WriteLine ("handling rom: {0}", config.ToString ());
+						if (String.IsNullOrEmpty (config.RomImage)) {
+							game_ctrl.UpdateGameImage ((Image)DefaultGameImage.Clone ());
+						} else {
 							string path = config.isCachedLocally ? config.GetLocalRomImageOverride() : config.GetFullRomImage ();
 							if (File.Exists (path)) {
 								game_ctrl.UpdateGameImage (path);
 							} else {
 								game_ctrl.UpdateGameImage ((Image)DefaultGameImage.Clone ());
-							}
+							}
 						}
 					}
 				} catch (Exception ex) {
@@ -1051,89 +1015,87 @@
 					gLog.Verbose.Error.WriteLine (ex.ToString ());
 					throw ex;
 				}
-				if (CurrentSelectedRom.PlatformNameShort == "Favorites") {
-					//game_ctrl.GameName = config.RomTitle;
+				if (CurrentSelectedRom.PlatformNameShort == "Favorites") {
+					//game_ctrl.GameName = config.RomTitle;
 					var favorite = RomFavorite.GetFavoriteInfoFromRom (config);
-					game_ctrl.GameName = favorite.RomConfig.RomExists ? favorite.RomConfig.RomTitle : string.Format ("{0} - (unavailable)", favorite.RomConfig.RomTitle);
-					//RomFavorite.GetRomTitleFromConfig(config);
+					game_ctrl.GameName = favorite.RomConfig.RomExists ? favorite.RomConfig.RomTitle : string.Format ("{0} - (unavailable)", favorite.RomConfig.RomTitle);
+					//RomFavorite.GetRomTitleFromConfig(config);
 					if (!favorite.RomConfig.RomExists) {
-						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING; 
+						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING;
 					} else {
-						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR; 
-					}
-                }
-                else
-                {
-					game_ctrl.GameName = config.RomExists ? config.RomTitle : string.Format("{0} - (unavailable)", config.RomTitle);
+						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR;
+					}
+				} else {
+					game_ctrl.GameName = config.RomExists ? config.RomTitle : string.Format ("{0} - (unavailable)", config.RomTitle);
 					if (!config.RomExists) {
-						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING; 
+						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING;
 					} else {
-						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR; 
-					}
-                }      
-                game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
-                game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
-                game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
-                if (rom_flow.InvokeRequired) { rom_flow.Invoke((MethodInvoker)delegate() { rom_flow.Controls.Add(game_ctrl); }); }
-                else { rom_flow.Controls.Add(game_ctrl); }
-                count++;
-            }
-            progress_bar.Invoke(new MethodInvoker(delegate { progress_bar.Value = 0; progress_bar.Update(); }));
-            e.Result = t;          
-        }
-        private void gameWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
-        private void gameWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
-        {
+						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR;
+					}
+				}
+				game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (game_ctrl_PreviewKeyDown);
+				game_ctrl.GotFocus += new EventHandler (game_ctrl_GotFocus);
+				game_ctrl.LostFocus += new EventHandler (game_ctrl_LostFocus);
+				if (rom_flow.InvokeRequired) { rom_flow.Invoke ((MethodInvoker)delegate () { rom_flow.Controls.Add (game_ctrl); }); } else { rom_flow.Controls.Add (game_ctrl); }
+				count++;
+			}
+			progress_bar.Invoke (new MethodInvoker (delegate { progress_bar.Value = 0; progress_bar.Update (); }));
+			e.Result = t;
+		}
+		private void gameWorker_ProgressChanged (object sender, ProgressChangedEventArgs e) { }
+		private void gameWorker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
+		{
 			Stopwatch t = e.Result as Stopwatch;
-			if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { 
-				progress_bar.Message = ""; 
-				this.Controls.Remove(progress_bar); });
-				this.Refresh();
-			} else { 
+			if (this.InvokeRequired) {
+				this.Invoke ((MethodInvoker)delegate () {
+					progress_bar.Message = "";
+					this.Controls.Remove (progress_bar);
+				});
+				this.Refresh ();
+			} else {
 				progress_bar.Message = "";
-				this.Controls.Remove(progress_bar); 
-				this.Refresh();
+				this.Controls.Remove (progress_bar);
+				this.Refresh ();
 
-			}
-            if (rom_flow.Controls.Count == 0)
-            {
-                GameControl game_ctrl = new GameControl();
-                game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(game_ctrl_PreviewKeyDown);
-                game_ctrl.GotFocus += new EventHandler(game_ctrl_GotFocus);
-                game_ctrl.LostFocus += new EventHandler(game_ctrl_LostFocus);
-                game_ctrl.Font = GetFormFont();
-                game_ctrl.Dock = DockStyle.Top;
-                game_ctrl.Width = this.Width - 10;
+			}
+			if (rom_flow.Controls.Count == 0) {
+				GameControl game_ctrl = new GameControl ();
+				game_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (game_ctrl_PreviewKeyDown);
+				game_ctrl.GotFocus += new EventHandler (game_ctrl_GotFocus);
+				game_ctrl.LostFocus += new EventHandler (game_ctrl_LostFocus);
+				game_ctrl.Font = GetFormFont ();
+				game_ctrl.Dock = DockStyle.Top;
+				game_ctrl.Width = this.Width - 10;
 				IEmuConfig config = CurrentPlatformControl.Tag as IEmuConfig;
 				if (config.PlatformNameLong == "Favorites") {
 					game_ctrl.GameName = "You haven't favorited any games, select a game and then press CTRL+F to favorite it";
 				} else {
 					game_ctrl.GameName = string.Format ("No {0} games were found", config.PlatformNameShort);
-				}                
-                rom_flow.Controls.Add(game_ctrl);
-            }
-            rom_flow.Controls[0].Select();
-            t.Stop();
-            gLog.Profiler.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
-        }
-        #endregion
-        #region platformWorker
-        private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
-        private object platformimage_lock = new object();
-        private void platformWorker_DoWork (object sender, DoWorkEventArgs e)
+				}
+				rom_flow.Controls.Add (game_ctrl);
+			}
+			rom_flow.Controls [0].Select ();
+			t.Stop ();
+			gLog.Profiler.WriteLine ("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
+		}
+		#endregion
+		#region platformWorker
+		private static Image DefaultPlatformImage = Properties.Resources.DefaultPlatformImage;
+		private object platformimage_lock = new object ();
+		private void platformWorker_DoWork (object sender, DoWorkEventArgs e)
 		{
 			Stopwatch t = e.Argument as Stopwatch;
-			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
+			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
             progress_bar.ShowPercentageLabel = false;
 #endif
 			progress_bar.ProgressColor = Color.LimeGreen;
-			progress_bar.Dock = DockStyle.Top;
-            
-			if (this.InvokeRequired) { 
-				this.Invoke ((MethodInvoker)delegate() {
-					this.Controls.Add (progress_bar); 
-				}); 
+			progress_bar.Dock = DockStyle.Top;
+
+			if (this.InvokeRequired) {
+				this.Invoke ((MethodInvoker)delegate () {
+					this.Controls.Add (progress_bar);
+				});
 			} else {
 				this.Controls.Add (progress_bar);
 			}
@@ -1142,10 +1104,10 @@
 				progress_bar.Size = new Size (GetFormWidth () - 25, 100);
 			}));
 
-			HashSet<IEmuConfig> platforms = new HashSet<IEmuConfig>();
+			HashSet<IEmuConfig> platforms = new HashSet<IEmuConfig> ();
 			using (PlatformParser parser = new PlatformParser (cache, Config.LocalRomPath, Config.RomPath, new ProgressEvent (worker_progress_event))) {
 				foreach (var platform in parser.Platforms) {
-					platforms.Add(platform);
+					platforms.Add (platform);
 				}
 			}
 
@@ -1160,74 +1122,69 @@
 			foreach (IEmuConfig config in platforms) {
 				progress_bar.Invoke (new MethodInvoker (delegate {
 					progress_bar.Value = (int)(100.0 * (count / total_count));
-				}));
-                
+				}));
+
 				PlatformControl platform_ctrl = new PlatformControl ();
 				platform_ctrl.Font = GetFormFont ();
 				platform_ctrl.Dock = DockStyle.Top;
 				platform_ctrl.Width = this.Width - 10;
 				platform_ctrl.Tag = config;
 				try {
-					lock (platformimage_lock) {
-						//gLog.Debug.WriteLine ("handling platform: {0}", config.ToString ());
-						if(String.IsNullOrEmpty(config.PlatformImage)) {
-							platform_ctrl.UpdatePlatformImage((Image)DefaultPlatformImage.Clone ());
-						}
-						else {
-							string path = config.GetFullPlatformImage();
-							if(File.Exists(path)) {
-								platform_ctrl.UpdatePlatformImage(path);
-							}
-							else {
-								platform_ctrl.UpdatePlatformImage((Image)DefaultPlatformImage.Clone ());
+					lock (platformimage_lock) {
+						//gLog.Debug.WriteLine ("handling platform: {0}", config.ToString ());
+						if (String.IsNullOrEmpty (config.PlatformImage)) {
+							platform_ctrl.UpdatePlatformImage ((Image)DefaultPlatformImage.Clone ());
+						} else {
+							string path = config.GetFullPlatformImage ();
+							if (File.Exists (path)) {
+								platform_ctrl.UpdatePlatformImage (path);
+							} else {
+								platform_ctrl.UpdatePlatformImage ((Image)DefaultPlatformImage.Clone ());
 							}
 						}
 					}
 				} catch (Exception ex) {
 					gLog.Error.WriteLine (ex.Message);
-					gLog.Verbose.Error.WriteLine (ex.ToString());
-                    throw ex;
-                } 
-                platform_ctrl.PlatformName = config.ToString();
-                platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
-                platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
-                platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
-                if (platform_flow.InvokeRequired) { platform_flow.Invoke((MethodInvoker)delegate() { platform_flow.Controls.Add(platform_ctrl); }); }
-                else { platform_flow.Controls.Add(platform_ctrl); }                  
-                count++;
-            }
-            progress_bar.Invoke(new MethodInvoker(delegate { 
-            	progress_bar.Value = 0; progress_bar.Update();
-            }));         
-            e.Result = t;
-        }
-        private void platformWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { }
-        private void platformWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
-        {
-			gLog.Debug.WriteLine("platformWorker_RunWorkerCompleted called");
-			if (this.InvokeRequired) {
-             this.Invoke((MethodInvoker)delegate() { 
+					gLog.Verbose.Error.WriteLine (ex.ToString ());
+					throw ex;
+				}
+				platform_ctrl.PlatformName = config.ToString ();
+				platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (platform_ctrl_PreviewKeyDown);
+				platform_ctrl.GotFocus += new EventHandler (platform_ctrl_GotFocus);
+				platform_ctrl.LostFocus += new EventHandler (platform_ctrl_LostFocus);
+				if (platform_flow.InvokeRequired) { platform_flow.Invoke ((MethodInvoker)delegate () { platform_flow.Controls.Add (platform_ctrl); }); } else { platform_flow.Controls.Add (platform_ctrl); }
+				count++;
+			}
+			progress_bar.Invoke (new MethodInvoker (delegate {
+				progress_bar.Value = 0; progress_bar.Update ();
+			}));
+			e.Result = t;
+		}
+		private void platformWorker_ProgressChanged (object sender, ProgressChangedEventArgs e) { }
+		private void platformWorker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
+		{
+			gLog.Debug.WriteLine ("platformWorker_RunWorkerCompleted called");
+			if (this.InvokeRequired) {
+				this.Invoke ((MethodInvoker)delegate () {
 					progress_bar.Message = "";
-					this.Controls.Remove(progress_bar); 
-             	}); 
-            } 
-            else {
+					this.Controls.Remove (progress_bar);
+				});
+			} else {
 				progress_bar.Message = "";
-				this.Controls.Remove(progress_bar); 
-           	}
-            Stopwatch t = e.Result as Stopwatch;
-            if (platform_flow.Controls.Count == 0)
-            {
-                PlatformControl platform_ctrl = new PlatformControl();
-                platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler(platform_ctrl_PreviewKeyDown);
-                platform_ctrl.GotFocus += new EventHandler(platform_ctrl_GotFocus);
-                platform_ctrl.LostFocus += new EventHandler(platform_ctrl_LostFocus);
-                platform_ctrl.Font = GetFormFont();
-                platform_ctrl.Dock = DockStyle.Top;
-                platform_ctrl.Width = this.Width - 10;
-                platform_ctrl.PlatformName = string.Format("You don't have any roms in your rompath: '{0}'",Config.RomPath);
-                platform_flow.Controls.Add(platform_ctrl);
-            }            
+				this.Controls.Remove (progress_bar);
+			}
+			Stopwatch t = e.Result as Stopwatch;
+			if (platform_flow.Controls.Count == 0) {
+				PlatformControl platform_ctrl = new PlatformControl ();
+				platform_ctrl.PreviewKeyDown += new PreviewKeyDownEventHandler (platform_ctrl_PreviewKeyDown);
+				platform_ctrl.GotFocus += new EventHandler (platform_ctrl_GotFocus);
+				platform_ctrl.LostFocus += new EventHandler (platform_ctrl_LostFocus);
+				platform_ctrl.Font = GetFormFont ();
+				platform_ctrl.Dock = DockStyle.Top;
+				platform_ctrl.Width = this.Width - 10;
+				platform_ctrl.PlatformName = string.Format ("You don't have any roms in your rompath: '{0}'", Config.RomPath);
+				platform_flow.Controls.Add (platform_ctrl);
+			}
 			if (SavedPlatformIndex != -1) {
 				var platform_control = platform_flow.Controls [SavedPlatformIndex] as PlatformControl;
 				platform_flow.SuspendLayout ();
@@ -1237,17 +1194,17 @@
 				platform_flow.ResumeLayout ();
 				SavedPlatformIndex = -1;
 			} else {
-				platform_flow.Controls[0].Select();
+				platform_flow.Controls [0].Select ();
 			}
-			t.Stop();
-           gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
-        }
-        #endregion
-
-        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
-        {
-            Cursor.Show();
-        }
-        #endregion
-    }
+			t.Stop ();
+			gLog.Profiler.WriteLine ("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
+		}
+		#endregion
+
+		private void Form1_FormClosed (object sender, FormClosedEventArgs e)
+		{
+			Cursor.Show ();
+		}
+		#endregion
+	}
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22