/[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/18 07:47:14	322
+++ branches/mono/EmuXPortal/Form1.cs	2017/12/19 00:10:33	324
@@ -26,20 +26,14 @@
 {
     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 IEmuPlatform CurrentSelectedRom = null;
-		private PlatformControl CurrentPlatformControl = null;
-		private int SavedPlatformIndex= -1;
-		private GameControl CurrentGameControl = null;
-		private List<IEmuPlatform> cache;
-
-		private CustomProgressBar progress_bar;
-
-
+        IEmuConfig CurrentSelectedRom = null;
+        PlatformControl CurrentPlatformControl = null;
+		int SavedPlatformIndex= -1;
+        GameControl CurrentGameControl = null;
 
         #region unhandled exception support
         static void Application_Unhandled_ThreadException(object sender, ThreadExceptionEventArgs e)
@@ -75,7 +69,7 @@
         public Form1()
         {
             InitializeComponent();
-			this.progress_bar = new CustomProgressBar();
+
 			this.KeyPreview = true;
          
             #region logging support
@@ -113,7 +107,6 @@
 
             platform_flow.Dock = DockStyle.Fill;
             rom_flow.Dock = DockStyle.Fill;
-            			
         }
 
        
@@ -130,13 +123,8 @@
         }
 #endregion
 
-		static bool OnAbort()
-        {
-            return bUserAbort;
-        }
         private void Form1_Load(object sender, EventArgs e)
         {
-			cache = RomCache.GetCachedPlatforms();
             Config.LoadConfig();
             Config.InitializePresentationForm(this);
         }
@@ -171,80 +159,78 @@
 				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;
-			#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
+            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
+
+            }
 			if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Left) {
 				if (OSInfo.OSIsUnix) {
 					rom_flow.SuspendLayout ();
@@ -261,87 +247,86 @@
 					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.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)
+            {
+                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);
@@ -486,7 +471,7 @@
             {
                 // load this platform
                 platform_flow.Visible = false;
-                CurrentSelectedRom = c.Tag as IEmuPlatform;
+                CurrentSelectedRom = c.Tag as IEmuConfig;
                 rom_flow.Visible = true;
                 rom_flow.BringToFront();
             }
@@ -730,85 +715,30 @@
         //    //else { this.Update(); }
         //}
         #region gameWorker
-		private static Image DefaultGameImage = Properties.Resources.DefaultGameImage;
+        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!");
+        private void gameWorker_DoWork(object sender, DoWorkEventArgs e)
+        {
+            Stopwatch t = e.Argument as Stopwatch;
+            RomParser parser = new RomParser(CurrentSelectedRom);
 
-			object user_object = event_args.GetUserObject ();
-			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);
-				} else {
-					IEmuPlatform iec = (user_object as IEmuPlatform);
-					if (iec != null) {
-						gLog.Verbose.Debug.WriteLine ("Read Platform[{0}] ({1}%): '{2}'", event_args.GetCount (), progress, iec);
-					}
-				}
-			}
-			if (progress_bar.InvokeRequired) {
-				progress_bar.Invoke (new MethodInvoker (delegate {
-					progress_bar.Message = message;
-					progress_bar.Value = progress;
-					progress_bar.Update();
-				}));
-			} else {
-				progress_bar.Message = message;
-				progress_bar.Value = progress;
-				progress_bar.Update();
-			}
-		}
-        private void gameWorker_DoWork (object sender, DoWorkEventArgs e)
-		{
-			Stopwatch t = e.Argument as Stopwatch;			
-			progress_bar.Font = ResizeFont (GetFormFont (), PROGRESS_BAR_FONT_SIZE);
+            CustomProgressBar bar = new CustomProgressBar();
+            bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
-            progress_bar.ShowPercentageLabel = false;
+            bar.ShowPercentageLabel = false;
 #endif
-			progress_bar.ProgressColor = Color.LimeGreen;
-			progress_bar.Dock = DockStyle.Top;
+            bar.ProgressColor = Color.LimeGreen;
+            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);
-			}));
-
-			//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;
-			}
-				
-
-			double count = 0;
-			double total_count = roms.Count;
-			if (total_count > 0) {
-				progress_bar.Invoke (new MethodInvoker (delegate {
-					progress_bar.Message = string.Format ("Please Wait Adding {0} {1} Roms...", total_count, CurrentSelectedRom.PlatformNameLong);
-				}));
-			}
-
-			foreach (IRomConfig config in roms)
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
+            else { this.Controls.Add(bar); }
+            bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
+            
+            double count = 0;
+            double total_count = parser.Roms.Count;
+            foreach (IRomConfig config in parser.Roms)
             {
-                progress_bar.Invoke(new MethodInvoker(delegate { progress_bar.Value = (int)(100.0 * (count / total_count)); }));
+                bar.Invoke(new MethodInvoker(delegate { bar.Value = (int)(100.0 * (count / total_count)); }));
                 GameControl game_ctrl = new GameControl();
                 game_ctrl.Font = GetFormFont();
                 game_ctrl.Dock = DockStyle.Top;
@@ -818,20 +748,12 @@
                 {
                     lock (gameimage_lock)
                     {
-						//gLog.Debug.WriteLine ("handling rom: {0}", config.ToString ());
-						if(String.IsNullOrEmpty(config.RomImage)) {
-							game_ctrl.GameImage = (Image)DefaultGameImage.Clone ();
-						}
-						else {
-							string path = config.GetFullRomImage();
-							game_ctrl.GameImage = Image.FromFile(path);
-						}
+                        game_ctrl.GameImage = config.RomImage == null ? (Image)DefaultGameImage.Clone() : (Image)config.RomImage.Clone();
+                        config.ReleaseRomImageResource();
                     }
                 }
                 catch (Exception ex)
                 {
-					gLog.Error.WriteLine (ex.Message);
-					gLog.Verbose.Error.WriteLine (ex.ToString());
                     throw ex;
                 }
                 if (CurrentSelectedRom.PlatformNameShort == "Favorites")
@@ -850,25 +772,15 @@
                 else { rom_flow.Controls.Add(game_ctrl); }
                 count++;
             }
-            progress_bar.Invoke(new MethodInvoker(delegate { progress_bar.Value = 0; progress_bar.Update(); }));
-	
-
-            e.Result = t;
+            bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
+            e.Result = t;            
+            parser.Dispose();
         }
         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 { 
-				progress_bar.Message = "";
-				this.Controls.Remove(progress_bar); 
-				this.Refresh();
-
-			}
             if (rom_flow.Controls.Count == 0)
             {
                 GameControl game_ctrl = new GameControl();
@@ -888,68 +800,48 @@
             }
             rom_flow.Controls[0].Select();
             t.Stop();
-            gLog.Profiler.WriteLine("RomParser took: {0}s to parse roms", (int)t.Elapsed.TotalSeconds);
+            //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);
+        private object platformimage_lock = new object();
+        private void platformWorker_DoWork(object sender, DoWorkEventArgs e)
+        {
+            Stopwatch t = e.Argument as Stopwatch;
+            PlatformParser parser = new PlatformParser(Config.RomPath);
+            double count = 0;
+            double total_count = parser.Platforms.Count;
+            CustomProgressBar bar = new CustomProgressBar();
+            bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
 #if DISABLE_PROGRESS_PERCENTAGE_MESSASGE
-            progress_bar.ShowPercentageLabel = false;
+            bar.ShowPercentageLabel = false;
 #endif
-			progress_bar.ProgressColor = Color.LimeGreen;
-			progress_bar.Dock = DockStyle.Top;
+            bar.ProgressColor = Color.LimeGreen;
+            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);
-			}));
-
-			PlatformParser parser = new PlatformParser (Config.RomPath, new ProgressEvent (worker_progress_event));
-
-
-			double count = 0;
-			double total_count = parser.Platforms.Count;
-			if (total_count > 0) {
-				progress_bar.Invoke (new MethodInvoker (delegate {
-					progress_bar.Message = string.Format ("Please Wait Loading {0} Rom Platforms...", total_count);
-				}));
-			}
-			foreach (IEmuConfig config in parser.Platforms) {
-				progress_bar.Invoke (new MethodInvoker (delegate {
-					progress_bar.Value = (int)(100.0 * (count / total_count));
-				}));
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Add(bar); }); }
+            else { this.Controls.Add(bar); }
+            bar.Invoke(new MethodInvoker(delegate { bar.Margin = new System.Windows.Forms.Padding(0); bar.Size = new Size(GetFormWidth() - 25, 100); }));
+            foreach (IEmuConfig config in parser.Platforms)
+            {
+                bar.Invoke(new MethodInvoker(delegate { 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.PlatformImage = (Image)DefaultPlatformImage.Clone ();
-						}
-						else {
-							string path = config.GetFullPlatformImage();
-							platform_ctrl.PlatformImage = Image.FromFile(path);
-						}
-					}
-				} catch (Exception ex) {
-					gLog.Error.WriteLine (ex.Message);
-					gLog.Verbose.Error.WriteLine (ex.ToString());
+                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)
+                    {
+                        platform_ctrl.PlatformImage = config.PlatformImage == null ? (Image)DefaultPlatformImage.Clone() : (Image)config.PlatformImage.Clone();
+                        config.ReleasePlatformImageResource();
+                    }
+                }
+                catch (Exception ex)
+                {
                     throw ex;
                 } 
                 platform_ctrl.PlatformName = config.ToString();
@@ -960,25 +852,14 @@
                 else { platform_flow.Controls.Add(platform_ctrl); }                  
                 count++;
             }
-            progress_bar.Invoke(new MethodInvoker(delegate { 
-            	progress_bar.Value = 0; progress_bar.Update();
-            }));         
-            e.Result = t;
+            bar.Invoke(new MethodInvoker(delegate { bar.Value = 1; bar.Update(); }));
+            if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate() { this.Controls.Remove(bar); }); } else { this.Controls.Remove(bar); }
+            e.Result = t;            
+            parser.Dispose();
         }
         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 {
-				progress_bar.Message = "";
-				this.Controls.Remove(progress_bar); 
-           	}
             Stopwatch t = e.Result as Stopwatch;
             if (platform_flow.Controls.Count == 0)
             {
@@ -1003,8 +884,7 @@
 			} else {
 				platform_flow.Controls[0].Select();
 			}
-			t.Stop();
-           gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
+           //gLog.Profiler.WriteLine("PlatformParser took: {0}s to parse platforms", (int)t.Elapsed.TotalSeconds);
         }
         #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22