/[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/15 10:47:15	296
+++ branches/mono/EmuXPortal/Form1.cs	2017/12/18 07:47:14	322
@@ -26,19 +26,21 @@
 {
     public partial class Form1 : Form
     {
+		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);
-		private IEmuConfig CurrentSelectedRom = null;
+		private IEmuPlatform CurrentSelectedRom = null;
 		private PlatformControl CurrentPlatformControl = null;
 		private int SavedPlatformIndex= -1;
 		private GameControl CurrentGameControl = null;
-		private RomCache cache;
+		private List<IEmuPlatform> cache;
 
 		private CustomProgressBar progress_bar;
 
 
+
         #region unhandled exception support
         static void Application_Unhandled_ThreadException(object sender, ThreadExceptionEventArgs e)
         {
@@ -111,8 +113,7 @@
 
             platform_flow.Dock = DockStyle.Fill;
             rom_flow.Dock = DockStyle.Fill;
-
-			cache = new RomCache();
+            			
         }
 
        
@@ -129,8 +130,13 @@
         }
 #endregion
 
+		static bool OnAbort()
+        {
+            return bUserAbort;
+        }
         private void Form1_Load(object sender, EventArgs e)
         {
+			cache = RomCache.GetCachedPlatforms();
             Config.LoadConfig();
             Config.InitializePresentationForm(this);
         }
@@ -165,78 +171,80 @@
 				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;
+			#region favorites
+			// TODO: implement refectored favorites system
+//            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
+//
+#endregion
 			if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
 				if (OSInfo.OSIsUnix) {
 					rom_flow.SuspendLayout ();
@@ -253,86 +261,87 @@
 					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.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) {
+				
+
+				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;
+
+				IExternalEmuConfig external_config = c.Tag as IExternalEmuConfig;
+				if (external_config != null) {
+					p.StartInfo.FileName = external_config.GameBinary;
+					p.StartInfo.Arguments = external_config.GameBinaryArgs;
+				} else {
+					IEmuRom rom_config = c.Tag as IEmuRom;
+					if (rom_config != null) {
+						p.StartInfo.FileName = rom_config.PlatformConfig.EmulatorBinaryPath;
+						p.StartInfo.Arguments = EmuConfigLoader.GetEMUOptions(rom_config);
+					}
+
+				}
+
+                
 
-            if (e.KeyCode == Keys.Enter)
-            {
-                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;
 
 				//gLog.Verbose.Debug.WriteLine ("Emulator: {0}", p.StartInfo.FileName);
 				//gLog.Verbose.Debug.WriteLine ("Args: {0}", p.StartInfo.Arguments);
@@ -477,7 +486,7 @@
             {
                 // load this platform
                 platform_flow.Visible = false;
-                CurrentSelectedRom = c.Tag as IEmuConfig;
+                CurrentSelectedRom = c.Tag as IEmuPlatform;
                 rom_flow.Visible = true;
                 rom_flow.BringToFront();
             }
@@ -735,7 +744,7 @@
 				if (irc != null) {
 					gLog.Verbose.Debug.WriteLine ("Read Rom[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, irc);
 				} else {
-					IEmuConfig iec = (user_object as IEmuConfig);
+					IEmuPlatform iec = (user_object as IEmuPlatform);
 					if (iec != null) {
 						gLog.Verbose.Debug.WriteLine ("Read Platform[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, iec);
 					}
@@ -775,12 +784,19 @@
 				progress_bar.Size = new Size (GetFormWidth () - 25, 100);
 			}));
 
-			if (!cache.AreRomsCachedForPlatform(CurrentSelectedRom)) {
-				using (RomParser parser = new RomParser (CurrentSelectedRom, new ProgressEvent (worker_progress_event))) {
-					cache.CacheRoms (parser);
-				}
+			//if (!cache.AreRomsCachedForPlatform(CurrentSelectedRom)) {
+//				using (RomParser parser = new RomParser (CurrentSelectedRom, new ProgressEvent (worker_progress_event))) {
+//					cache.CacheRoms (parser);
+//				}
+//			}
+			List<IExternalEmuConfig> external_configs = new List<IExternalEmuConfig> ();
+			List<IEmuRom> rom_configs = new List<IEmuRom> ();
+			if (CurrentSelectedRom.HasExternalConfigs) {
+				external_configs = CurrentSelectedRom.ExternalConfigs;
+			} else {
+				rom_configs = CurrentSelectedRom.Roms;
 			}
-			HashSet<IRomConfig> roms = cache.GetCachedRomsForPlatform (CurrentSelectedRom);
+				
 
 			double count = 0;
 			double total_count = roms.Count;

 

  ViewVC Help
Powered by ViewVC 1.1.22