/[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 03:35:02	334
+++ branches/mono/EmuXPortal/Form1.cs	2017/12/19 20:15:02	355
@@ -5,6 +5,7 @@
 
 #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
+
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -23,9 +24,16 @@
 using Enterprise.CrossPlatform;
 
 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();
@@ -35,7 +43,12 @@
 		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)
         {
@@ -108,6 +121,19 @@
 
             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
+			}
         }
 
        
@@ -124,10 +150,21 @@
         }
 #endregion
 
+		private bool bCachedLoaded = false;
+		private bool OnCacheLoaded() {
+			return bCachedLoaded;
+		}
+
         private void Form1_Load(object sender, EventArgs e)
         {
-            Config.LoadConfig();
+
+			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)
         {
@@ -137,8 +174,127 @@
 #else 
             Cursor.Show();
 #endif
+			
         }
+		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.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);
+				});
+			} else {
+				this.Controls.Add (progress_bar);
+			}
+			progress_bar.Invoke (new MethodInvoker (delegate {
+				progress_bar.Margin = new System.Windows.Forms.Padding (0);
+				progress_bar.Size = new Size (GetFormWidth () - 25, 100);
+			}));
+			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);
+					return;
+				}
+				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);
+					return;
+				}
+				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.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)
+		{
+			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
+			progress_bar.ProgressColor = Color.LimeGreen;
+			progress_bar.Dock = DockStyle.Top;
+			if (this.InvokeRequired) {
+				this.Invoke ((MethodInvoker)delegate() {
+					this.Controls.Add (progress_bar);
+				});
+			} else {
+				this.Controls.Add (progress_bar);
+			}
+			progress_bar.Invoke (new MethodInvoker (delegate {
+				progress_bar.Margin = new System.Windows.Forms.Padding (0);
+				progress_bar.Size = new Size (GetFormWidth () - 25, 100);
+			}));
+			Application.DoEvents ();
+			FileProgressCopier cp = null;
+			if (!string.IsNullOrEmpty (src_rom_image) && !string.IsNullOrEmpty (dst_rom_image)) {
+				bAbortRomCopyToLocalCache = false;
+				cp = new FileProgressCopier (src_rom_image, dst_rom_image, new CopyProgressEvent (OnFileCopyProgress), new AbortEvent (OnAbortRomCopyToLocalCache));
+				cp.Start ();
+				while (!cp.CopyFinished) {
+					Application.DoEvents();
+				}
+			}
+			if (!string.IsNullOrEmpty (src_rom_file) && !string.IsNullOrEmpty (dst_rom_file)) {
+				bAbortRomCopyToLocalCache = false;
+				cp = new FileProgressCopier (src_rom_file, dst_rom_file, new CopyProgressEvent (OnFileCopyProgress), new AbortEvent (OnAbortRomCopyToLocalCache));
+				cp.Start ();
+				while (!cp.CopyFinished) {
+					Application.DoEvents();
+				}
+			}
+			if (this.InvokeRequired) {
+				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();
+				}
+		}
         void ReleasePlatformControlStreams ()
 		{
 			foreach (var c in platform_flow.Controls) {
@@ -182,78 +338,129 @@
 				CurrentPlatformControl = c;
 			}
         }
-        void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
-        {
+
+        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;
+			GameControl c = sender as GameControl;
 
-            int changeAmount = 0;
-            int currentPosition = 0;
-            if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control)
-            {
-                IRomConfig config = c.Tag as IRomConfig;
-                if (config == null)
-                {
-                    gLog.Error.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile);
-                }
-                else
-                {
-                    var isFavorite = RomFavorite.IsFavorite(config);
-                    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
-                        {
-                            gLog.Info.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
-                            if (config.Config.PlatformNameShort == "Favorites")
-                            {
-                                var parent = c.Parent;
-                                if (parent != null)
-                                {
-                                    parent.Controls.Remove(c);
-                                    if (parent.Controls.Count > 0)
-                                    {
-                                        var next_ctrl = parent.Controls[0];
-                                        if (next_ctrl != null)
-                                        {
-                                            next_ctrl.Select();
-                                        }
-                                    }
-                                }
-                            }                       
-                        }
-                    }
-                    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");
-                    if (!RomFavorite.UpdateFavorites())
-                    {
-                        gLog.Error.WriteLine("Failed to update favorites");
-                    }
-                    else
-                    {
-                        gLog.Info.WriteLine("Updated favorites");
-                    }
-                }
-                return; // stop processing other keys
+			int changeAmount = 0;
+			int currentPosition = 0;
+			IRomConfig config = null;
+			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;
+					string rom_file = config.RomFile;
+					string rom_image = config.RomImage;
+
+					string rom_filename = "";
+					string rom_imagefilename = "";
+					FileInfo fi = null;
+					try {
+						fi = new FileInfo (rom_file);
+						rom_filename = fi.Name;
+					} finally {
+						fi = null;
+					}
+					try {
+						fi = new FileInfo (rom_image);
+						rom_imagefilename = fi.Name;
+					} finally {
+						fi = null;
+					}
 
-            }
+					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));
+
+					// create the local rom path for this platform
+					DirectoryInfo di = new DirectoryInfo (local_rom_path);
+					if (!di.Exists) {
+						di.Create ();
+					}
+					this.Enabled = false;
+					CopyRomToLocalCache (rom_file, local_romfile, rom_image, local_romimage);
+					this.Enabled = true;
+				}
+			}
+			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;
+					string rom_file = config.RomFile;
+					string rom_image = config.RomImage;
+
+					string rom_filename = "";
+					string rom_imagefilename = "";
+					FileInfo fi = null;
+					try {
+						fi = new FileInfo (rom_file);
+						rom_filename = fi.Name;
+					} finally {
+						fi = null;
+					}
+					try {
+						fi = new FileInfo (rom_image);
+						rom_imagefilename = fi.Name;
+					} finally {
+						fi = null;
+					}
+					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));
+					this.Enabled = false;
+					DeleteRomFromLocalCache (local_romfile, local_romimage);
+					this.Enabled = true;
+				}
+			}
+			if (e.KeyCode == Keys.F && (e.Modifiers & Keys.Control) == Keys.Control) {
+				config = c.Tag as IRomConfig;
+				if (config == null) {
+					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 (!RomFavorite.RemoveFavorite (config)) {
+							gLog.Error.WriteLine ("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+						} else {
+							gLog.Info.WriteLine ("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+							if (config.EmuConfig.PlatformNameShort == "Favorites") {
+								var parent = c.Parent;
+								if (parent != null) {
+									parent.Controls.Remove (c);
+									if (parent.Controls.Count > 0) {
+										var next_ctrl = parent.Controls [0];
+										if (next_ctrl != null) {
+											next_ctrl.Select ();
+										}
+									}
+								}
+							}                       
+						}
+					} 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");
+					if (!RomFavorite.UpdateFavorites (cache)) {
+						gLog.Error.WriteLine ("Failed to update favorites");
+					} else {
+						gLog.Info.WriteLine ("Updated favorites");
+					}
+				}
+				return; // stop processing other keys
+
+			}
 			if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
 				if (OSInfo.OSIsUnix) {
 					rom_flow.SuspendLayout ();
@@ -270,101 +477,105 @@
 					rom_flow.ResumeLayout (false);
 				}
 			}		
-            if (e.KeyCode == Keys.Home)
-            {
-                rom_flow.SuspendLayout();
-                rom_flow.Controls[0].Select();
-                rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
-                rom_flow.ResumeLayout(false);
-            }
-            if (e.KeyCode == Keys.End)
-            {
-                rom_flow.SuspendLayout();
-                rom_flow.Controls[rom_flow.Controls.Count - 1].Select();
-                rom_flow.ScrollControlIntoView(rom_flow.Controls[rom_flow.Controls.Count - 1]);
-                rom_flow.ResumeLayout(false);
-            }
-            if (e.KeyCode == Keys.PageUp)
-            {
-                rom_flow.SuspendLayout();
-                changeAmount = rom_flow.VerticalScroll.LargeChange;
-                currentPosition = rom_flow.VerticalScroll.Value;
-                if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum)
-                {
-                    try
-                    {
-                        rom_flow.VerticalScroll.Value -= changeAmount;
-                    }
-                    catch
-                    {
-                        rom_flow.Controls[0].Select();
-                        rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
-                        rom_flow.PerformLayout();
-                        return;
-                    }
-                }
-                else
-                {
-                    rom_flow.Controls[0].Select();
-                    rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
-                }
-                GameControl s = game_ctrl_get_last_visible();
-                s.Select();
-                rom_flow.ScrollControlIntoView(s);
-                rom_flow.ResumeLayout(false);
-            }
-            if (e.KeyCode == Keys.PageDown)
-            {
-                rom_flow.SuspendLayout();
-                changeAmount = rom_flow.VerticalScroll.LargeChange;
-                currentPosition = rom_flow.VerticalScroll.Value;
-                if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum)
-                {
-                    try
-                    {
-                        rom_flow.VerticalScroll.Value += changeAmount;
-                    }
-                    catch
-                    {
-                        rom_flow.Controls[0].Select();
-                        rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
-                        rom_flow.PerformLayout();
-                        return;
-                    }
-                }
-                else
-                {
-                    rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
-                }
-                GameControl s = game_ctrl_get_last_visible();
-                s.Select();
-                rom_flow.ScrollControlIntoView(s);
-                rom_flow.ResumeLayout(false);
-            }
-
-            if (e.KeyCode == Keys.Enter)
-            {
-				ReleaseGameControlStreams();
-                IRomConfig config = c.Tag as IRomConfig;
-
-                Process p = new Process();
-
-                p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe;
-                p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(config) : config.Config.GameExeArgs;
+			if (e.KeyCode == Keys.Home) {
+				rom_flow.SuspendLayout ();
+				rom_flow.Controls [0].Select ();
+				rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
+				rom_flow.ResumeLayout (false);
+			}
+			if (e.KeyCode == Keys.End) {
+				rom_flow.SuspendLayout ();
+				rom_flow.Controls [rom_flow.Controls.Count - 1].Select ();
+				rom_flow.ScrollControlIntoView (rom_flow.Controls [rom_flow.Controls.Count - 1]);
+				rom_flow.ResumeLayout (false);
+			}
+			if (e.KeyCode == Keys.PageUp) {
+				rom_flow.SuspendLayout ();
+				changeAmount = rom_flow.VerticalScroll.LargeChange;
+				currentPosition = rom_flow.VerticalScroll.Value;
+				if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum) {
+					try {
+						rom_flow.VerticalScroll.Value -= changeAmount;
+					} catch {
+						rom_flow.Controls [0].Select ();
+						rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
+						rom_flow.PerformLayout ();
+						return;
+					}
+				} else {
+					rom_flow.Controls [0].Select ();
+					rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
+				}
+				GameControl s = game_ctrl_get_last_visible ();
+				s.Select ();
+				rom_flow.ScrollControlIntoView (s);
+				rom_flow.ResumeLayout (false);
+			}
+			if (e.KeyCode == Keys.PageDown) {
+				rom_flow.SuspendLayout ();
+				changeAmount = rom_flow.VerticalScroll.LargeChange;
+				currentPosition = rom_flow.VerticalScroll.Value;
+				if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum) {
+					try {
+						rom_flow.VerticalScroll.Value += changeAmount;
+					} catch {
+						rom_flow.Controls [0].Select ();
+						rom_flow.ScrollControlIntoView (rom_flow.Controls [0]);
+						rom_flow.PerformLayout ();
+						return;
+					}
+				} else {
+					rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
+				}
+				GameControl s = game_ctrl_get_last_visible ();
+				s.Select ();
+				rom_flow.ScrollControlIntoView (s);
+				rom_flow.ResumeLayout (false);
+			}
 
-				//gLog.Verbose.Debug.WriteLine ("Emulator: {0}", p.StartInfo.FileName);
-				//gLog.Verbose.Debug.WriteLine ("Args: {0}", p.StartInfo.Arguments);
-                p.Start();
-
-                // minimize EmuXPortal
-                this.WindowState = FormWindowState.Minimized;
-                // wait for exit of game
-                p.WaitForExit();
-                // maximize EmuXPortal
-                this.WindowState = FormWindowState.Maximized;
+			if (e.KeyCode == Keys.Enter) {				
+				config = c.Tag as IRomConfig;
+				if (config.RomExists) {
+					c.TextForeColor = DEFAULT_TEXTFORECOLOR_LAUNCH;
+					string gamename = c.GameName;
+					c.GameName = string.Format ("{0} (Loading...)", gamename);
+					bool game_launched = true;
+					using (Process p = new Process ()) {
+						string binary = "";
+						string arguments = "";
+						if (!string.IsNullOrEmpty (config.EmuConfig.EmuBinaryPath)) {
+							binary = config.EmuConfig.EmuBinaryPath;
+							arguments = EmuConfigLoader.GetEMUOptions (config);
+						}
+						if (!string.IsNullOrEmpty (config.EmuConfig.GameExe)) {
+							binary = config.EmuConfig.GameExe;
+							arguments = config.EmuConfig.GameExeArgs;
+						}
+						if (string.IsNullOrEmpty (binary)) {
+							gLog.Warn.WriteLine ("Cannot launch this rom file -- missing arguments");
+							game_launched = false;
+						} else {
+							p.StartInfo.FileName = binary;
+							p.StartInfo.Arguments = arguments == null ? "" : arguments;
+							p.Start ();
+							// wait for exit of game
+							p.WaitForExit ();
+							c.TextForeColor = DEFAULT_TEXTFORECOLOR;
+							c.GameName = gamename;
+						}
+					}
+					if (!game_launched) {
+						c.TextForeColor = DEFAULT_TEXTFORECOLOR_ERROR;
+						c.GameName = string.Format ("{0} (Error While Loading...)", gamename);
+					}
+				} 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;
@@ -503,6 +714,7 @@
             }
 			if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Escape)
             {
+            	bAbortRomCopyToLocalCache = true;
 				ReleasePlatformControlStreams();
                 this.Close();
             }
@@ -747,7 +959,6 @@
 		private void worker_progress_event (object event_source, ProgressEventArgs event_args)
 		{
 			//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();
@@ -797,9 +1008,9 @@
 			}));
 
 			HashSet<IRomConfig> roms = new HashSet<IRomConfig> ();
-			using (RomParser parser = new RomParser (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);
+					roms.Add (rom);
 				}
 			}
 
@@ -812,43 +1023,53 @@
 			}
 
 
-			foreach (IRomConfig config in roms)
-            {
-                progress_bar.Invoke(new MethodInvoker(delegate { progress_bar.Value = (int)(100.0 * (count / total_count)); }));
-                GameControl game_ctrl = new GameControl();
-                game_ctrl.Font = GetFormFont();
-                game_ctrl.Dock = DockStyle.Top;
-                game_ctrl.Width = this.Width - 10;
-                game_ctrl.Tag = config;
-                try
-                {
-                    lock (gameimage_lock)
-                    {
+			foreach (IRomConfig config in roms) {
+				progress_bar.Invoke (new MethodInvoker (delegate {
+					progress_bar.Value = (int)(100.0 * (count / total_count));
+				}));
+				GameControl game_ctrl = new GameControl ();
+				game_ctrl.Font = GetFormFont ();
+				game_ctrl.Dock = DockStyle.Top;
+				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 {
-							string path = config.GetFullRomImage();
-							gLog.Debug.WriteLine("game_ctrl.ControlID = {0}", game_ctrl.ControlID);
-							game_ctrl.UpdateGameImage(path);
+						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)
-                {
+					}
+				} catch (Exception ex) {
 					gLog.Error.WriteLine (ex.Message);
-					gLog.Verbose.Error.WriteLine (ex.ToString());
-                    throw ex;
-                }
-                if (CurrentSelectedRom.PlatformNameShort == "Favorites")
-                {
-                    //game_ctrl.GameName = config.RomTitle;
-                    game_ctrl.GameName = RomFavorite.GetRomTitleFromConfig(config);
+					gLog.Verbose.Error.WriteLine (ex.ToString ());
+					throw ex;
+				}
+				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);
+					if (!favorite.RomConfig.RomExists) {
+						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR_MISSING; 
+					} else {
+						game_ctrl.TextForeColor = DEFAULT_TEXTFORECOLOR; 
+					}
                 }
                 else
                 {
-                    game_ctrl.GameName = config.RomTitle;
+					game_ctrl.GameName = config.RomExists ? config.RomTitle : string.Format("{0} - (unavailable)", config.RomTitle);
+					if (!config.RomExists) {
+						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);
@@ -922,7 +1143,7 @@
 			}));
 
 			HashSet<IEmuConfig> platforms = new HashSet<IEmuConfig>();
-			using (PlatformParser parser = new PlatformParser (Config.RomPath, new ProgressEvent (worker_progress_event))) {
+			using (PlatformParser parser = new PlatformParser (cache, Config.LocalRomPath, Config.RomPath, new ProgressEvent (worker_progress_event))) {
 				foreach (var platform in parser.Platforms) {
 					platforms.Add(platform);
 				}
@@ -954,8 +1175,12 @@
 						}
 						else {
 							string path = config.GetFullPlatformImage();
-							gLog.Debug.WriteLine("platform_ctrl.ControlID = {0}", platform_ctrl.ControlID);
-							platform_ctrl.UpdatePlatformImage(path);
+							if(File.Exists(path)) {
+								platform_ctrl.UpdatePlatformImage(path);
+							}
+							else {
+								platform_ctrl.UpdatePlatformImage((Image)DefaultPlatformImage.Clone ());
+							}
 						}
 					}
 				} catch (Exception ex) {

 

  ViewVC Help
Powered by ViewVC 1.1.22