ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/EmuXPortal/branches/mono/EmuXPortal/Form1.cs
(Generate patch)

Comparing branches/mono/EmuXPortal/Form1.cs (file contents):
Revision 611 by william, Fri Apr 22 01:21:20 2022 UTC vs.
Revision 612 by william, Fri Apr 22 21:30:03 2022 UTC

--- branches/mono/EmuXPortal/Form1.cs	2022/04/22 21:28:02	611
+++ branches/mono/EmuXPortal/Form1.cs	2022/04/22 21:30:03	612
@@ -1,19 +1,20 @@
-//#define DEV_DEBUG
-
-#if DEV_DEBUG
-#define USE_WINDOWED_MODE // when defined will use windowed mode instead of fullscreen
+//#define DEV_DEBUG
+
+
+#if DEV_DEBUG
+#define FORCE_CACHE_REBULD // when defined will force rebuilding of cache
 #endif
-//#define DISABLE_PLUGINS // when defined plugin loading an their use will be disabled
-
-//#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_WORKER_PROGRESS_EVENT // when defined will disable worker progress events
-//#define DISAGLE_LOAD_SPLASH // when defined will not display a splash at loading (e.g. during cache building)
+//#define DISABLE_PLUGINS // when defined plugin loading an their use will be disabled
+
+//#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_WORKER_PROGRESS_EVENT // when defined will disable worker progress events
+//#define DISABLE_SPLASH // when defined will not show a splash (e.g. during cache building)
 
 //#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
 
-
+
 #if DEV_DEBUG
 #warning DEV_DEBUG is enabled
 #endif
@@ -49,7 +50,6 @@ namespace EmuXPortal {
 		//const string irexec = "/usr/bin/irexec";
 		const string irexec = "irexec";
 		const string irexec_lircrc = "emuxportal.lircrc";
-		static int irexec_pid = 0;
 
 		Thread irexec_thread_monitor = null;
 
@@ -57,10 +57,15 @@ namespace EmuXPortal {
 
 		private const int WINDOW_MODE_WIDTH = 900;
 		private const int WINDOW_MODE_HEIGHT = 500;
-		private const int INPUT_POLLING_FREQUENCY = 100;
-		
-
-		private bool bRebuildCache = false;
+		private const int INPUT_POLLING_FREQUENCY = 100;
+
+
+#if DEV_DEBUG && FORCE_CACHE_REBULD
+		private const bool bRebuildCache = false;
+#else
+		private bool bRebuildCache = false;
+#endif
+
 		private CustomProgressBar progress_bar;
 		private IPlatformCache cache = null;
 		private bool bConfigLoaded = false;
@@ -72,6 +77,7 @@ namespace EmuXPortal {
 
 		private Queue<KeyArrayArgs> event_queue;
 		private readonly object event_queue_lock = new object ();
+
 
 		private void do_irexec_monitor ()
 		{
@@ -93,34 +99,12 @@ namespace EmuXPortal {
 
 		private void HookIRExec ()
 		{
-			//if (!OSInfo.OSIsUnix) { return; }
-			//KillDanglingIRExecProcesses ();
-			//gLog.Info.WriteLine ("Hooking Irexec...");
-			//using (Process p = new Process ()) {
-			//	p.StartInfo.FileName = irexec;
-			//	p.StartInfo.Arguments = Enterprise.CrossPlatform.OSInfo.FormatPath (string.Format ("{0}/{1}", Application.StartupPath, irexec_lircrc));
-			//	p.Start ();
-			//	irexec_pid = p.Id;
-			//	gLog.Info.WriteLine ("Irexec Hooked [pid=0x{0:x8}]", irexec_pid);
-			//}
 			irexec_thread_monitor = new Thread (new ThreadStart (do_irexec_monitor));
 			irexec_thread_monitor.SetApartmentState (ApartmentState.STA);
 			irexec_thread_monitor.Start ();
 		}
 		private void UnHookIRExec ()
 		{
-			//if (!OSInfo.OSIsUnix) { return; }
-			//if (irexec_pid != 0) {
-			//	gLog.Info.WriteLine ("UnHooking Irexec [pid=0x{0:x8}]", irexec_pid);
-			//	try {
-			//		using (Process p = Process.GetProcessById (irexec_pid)) {
-			//			p.Kill ();
-			//			gLog.Info.WriteLine ("UnHooked Irexec...");
-			//		}
-			//	} catch {
-			//		gLog.Error.WriteLine ("Failed to UnHook Irexec...");
-			//	}
-			//}
 			if (irexec_thread_monitor != null && irexec_thread_monitor.IsAlive) {
 				irexec_thread_monitor.Abort ();
 				irexec_thread_monitor = null;
@@ -159,10 +143,7 @@ namespace EmuXPortal {
 		public Form1 ()
 		{
 			InitializeComponent ();
-			this.BackColor = Color.Black;
-			this.ForeColor = Color.LimeGreen;
 			this.progress_bar = new CustomProgressBar ();
-			this.KeyPreview = true;
 
 			#region logging support
 			string log_path = Application.StartupPath;
@@ -208,7 +189,6 @@ namespace EmuXPortal {
 			if (bInputQueueDisabled) {
 				return;
 			}
-			//gLog.Verbose.Debug.WriteLine ("Input_Queue_Handler_Tick -- running");
 			if (bInputQueuHandlerRunning) { return; }
 			if (event_queue.Count > 0) {
 				bInputQueuHandlerRunning = true;
@@ -219,10 +199,8 @@ namespace EmuXPortal {
 				var keys = key_event.GetKeys ();
 				string key_string = KeyConverter.getSendKeysString (keys);
 				StringBuilder sb = new StringBuilder ();
-				keys.ToList ().ForEach ((Keys obj) => sb.AppendFormat (" {0}", obj));
-				//gLog.Verbose.Debug.WriteLine ("Sending keys: {0}", sb.ToString());
+				keys.ToList ().ForEach ((Keys obj) => sb.AppendFormat (" {0}", obj));
 				SendKeys.Send (key_string);
-				// process key_event
 				bInputQueuHandlerRunning = false;
 			}
 		}
@@ -230,22 +208,6 @@ namespace EmuXPortal {
 
 		void Handle_InputPoll (object sender, KeyArrayArgs e)
 		{
-			/*if (bInputQueueDisabled) {
-				// drop this input event
-				var keys = e.GetKeys ();
-				StringBuilder sb = new StringBuilder ();
-				if (keys.Length > 0) {
-					sb.AppendFormat ("{0}", keys [0]);
-				}
-				for (int i = 1; i < keys.Length; i++) {
-					sb.AppendFormat (", {0}", keys [i]);
-				}
-				gLog.Verbose.Warn.WriteLine ("Input Queue temporairly disabled....dropped key event ({0})!", sb.ToString());
-				return;
-			}
-			lock (event_queue_lock) {
-				event_queue.Enqueue (e);				
-			}*/
 			if (!bInputQueueDisabled) {
 				lock (event_queue_lock) {
 					event_queue.Enqueue (e);
@@ -281,22 +243,18 @@ namespace EmuXPortal {
 		{
 			var cargs = new List<String> (System.Environment.GetCommandLineArgs ());
 			if (cargs.Contains ("--rebuild")) {
+#if !DEV_DEBUG
 				bRebuildCache = true;
+#endif
 			}
 		}
 
 
 		private void Form1_Load (object sender, EventArgs e)
 		{
-			HandleCommandLine ();
-			Config.InitializePresentationForm (this);
-			this.Show ();
-
-		}
-
-		private void Form1_Shown (object sender, EventArgs e)
-		{
-			this.Activated += Handle_Activated;
+			HandleCommandLine ();
+			Config.InitializePresentationForm (this);
+			this.Activated += Handle_Activated;
 
 		}
 
@@ -304,91 +262,7 @@ namespace EmuXPortal {
 		void Handle_Activated (object sender, EventArgs e)
 		{
 			this.Activated -= Handle_Activated;
-
-#if DEV_DEBUG && USE_WINDOWED_MODE
-			this.Width = WINDOW_MODE_WIDTH;
-			this.Height = WINDOW_MODE_HEIGHT;
-			this.FormBorderStyle = FormBorderStyle.Sizable;
-#endif
-
-#if !DISAGLE_LOAD_SPLASH
-			SplashLoader loader = new SplashLoader (new AbortEvent (OnCacheLoaded));
-			loader.Show (this);
-#endif
-			Stopwatch t = new Stopwatch ();
-			t.Start ();
-			try {
-				cache = PlatformCache.Create (new AbortEvent (OnAbort), bRebuildCache);
-				bCachedLoaded = true;
-			} catch (Exception ex) {
-				gLog.Error.WriteLine (ex.ToString ());
-			}
-			t.Stop ();
-			gLog.Profiler.WriteLine ("Cache generate/load took: {0}", TimeUtils.getTimeString (t));
-
-			t = new Stopwatch ();
-			t.Start ();
-			bConfigLoaded = Config.LoadConfig (cache);
-			t.Stop ();
-			gLog.Profiler.WriteLine ("Config load took: {0}", TimeUtils.getTimeString (t));
-
-			if (!bConfigLoaded) {
-				input_queue_handler.Stop ();
-				input_queue_handler.Enabled = false;
-				return;
-			}
-
-			/* initialize the container controls */			
-			platform_flow.setCache (cache);
-			rom_flow.setCache (cache);
-
-
-
-			platform_flow.Font = this.Font;
-			rom_flow.Font = this.Font;
-
-			//platform_flow.setDefaultPlatformImage ((Bitmap)Properties.Resources.DefaultPlatformImage);
-			//rom_flow.setDefaultGameImage ((Bitmap)Properties.Resources.DefaultGameImage);
-
-			platform_flow.BackColor = this.BackColor;
-			platform_flow.ForeColor = this.ForeColor;
-
-			rom_flow.BackColor = this.BackColor;
-			rom_flow.ForeColor = this.ForeColor;
-
-
-			platform_flow.controlsRendered += ControlsRendered;
-			rom_flow.controlsRendered += ControlsRendered;
-
-			platform_flow.switchControls += SwitchControls;
-			rom_flow.switchControls += SwitchControls;
-
-			platform_flow.Parent = this;
-			rom_flow.Parent = this;
-
-
-			platform_flow.Width = this.Width - 10;
-			rom_flow.Width = this.Width - 10;
-
-			rom_flow.RomLaunched += Rom_Flow_RomLaunched;
-
-
-			if (!bConfigLoaded) {
-				gLog.Warn.WriteLine ("Terminating application...");
-				Application.Exit ();
-				return;
-			}
-			platform_flow.Visible = true;
-#if !DISABLE_CURSOR_HIDE
-			Cursor.Hide ();
-#else
-            Cursor.Show();
-#endif
-
-#if !DISABLE_PLUGINS
-			PluginLoader.StartInputPolling (bInputQueueDisabled, Handle_InputPoll);
-#endif
-
+			this.cache_worker.RunWorkerAsync ();
 		}
 
 		void Rom_Flow_RomLaunched (object sender, RomLaunchArgs e)
@@ -444,20 +318,17 @@ namespace EmuXPortal {
 			}
 		}
 
-		
-
 		private void platform_flow_VisibleChanged (object sender, EventArgs e)
 		{
 			if (!platform_flow.Visible) return;
-			
+			platform_flow.Width = this.Width - 10;
 			platform_flow.renderControls ();
 		}
 
-
-
 		private void rom_flow_VisibleChanged (object sender, EventArgs e)
 		{
-			if (!rom_flow.Visible) return;
+			if (!rom_flow.Visible) return;
+			rom_flow.Width = this.Width - 10;
 		}
 
 
@@ -469,6 +340,79 @@ namespace EmuXPortal {
 		{
 			Cursor.Show ();
 			PluginLoader.EndInputPolling ();
+		}
+
+		private void Cache_Worker_DoWork (object sender, DoWorkEventArgs e)
+		{
+
+#if !DISABLE_SPLASH
+			this.Controls.Add (splash);
+			this.splash.Width = this.Width;
+#endif
+			Stopwatch t = new Stopwatch ();
+			t.Start ();
+			try {
+				cache = PlatformCache.Create (new AbortEvent (OnAbort), bRebuildCache);
+				bCachedLoaded = true;
+			} catch (Exception ex) {
+				gLog.Error.WriteLine (ex.ToString ());
+			}
+			t.Stop ();
+
+			if (bCachedLoaded) {
+				gLog.Profiler.WriteLine ("Cache generate/load took: {0}", TimeUtils.getTimeString (t));
+			}
+		}
+		private void Cache_Worker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
+		{
+			if (!bCachedLoaded) {
+				gLog.Warn.WriteLine ("Failed to generate cache...");
+				Application.Exit ();
+				return;
+			}
+#if !DISABLE_SPLASH
+			this.Controls.Remove (splash);
+#endif
+			config_worker.RunWorkerAsync ();
+		}
+		private void Config_Worker_DoWork (object sender, DoWorkEventArgs e)
+		{
+			Stopwatch t = new Stopwatch ();
+			t.Start ();
+			try {
+				bConfigLoaded = Config.LoadConfig (cache);
+			} catch (Exception ex) {
+				bConfigLoaded = false;
+				gLog.Error.WriteLine (ex.ToString ());
+				return;
+			}
+			t.Stop ();
+			gLog.Profiler.WriteLine ("Config load took: {0}", TimeUtils.getTimeString (t));
+
+
+
+		}
+		private void Config_Worker_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e)
+		{
+			if (!bConfigLoaded) {
+				gLog.Warn.WriteLine ("Failed to load config...");
+				Application.Exit ();
+				return;
+			}
+			/* set the container control's cache */
+			platform_flow.setCache (cache);
+			rom_flow.setCache (cache);
+			platform_flow.Visible = true;
+			platform_flow.Focus ();
+#if !DISABLE_CURSOR_HIDE
+			Cursor.Hide ();
+#else
+            Cursor.Show();
+#endif
+
+#if !DISABLE_PLUGINS
+			PluginLoader.StartInputPolling (bInputQueueDisabled, Handle_InputPoll);
+#endif
 		}
 	}
 }