/[EmuXPortal]/trunk/EmuXPortal/Form1.cs
ViewVC logotype

Diff of /trunk/EmuXPortal/Form1.cs

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

--- trunk/EmuXPortal/Form1.cs	2014/08/05 04:13:36	237
+++ trunk/EmuXPortal/Form1.cs	2014/08/05 04:50:39	238
@@ -9,11 +9,12 @@
 using System.Text;
 using System.Windows.Forms;
 using EmuXPortal.Api;
-using EmuXPortal.Logging;
 using System.Diagnostics;
 using System.Reflection;
 using System.Threading;
 using Utilities.TransparentControls;
+using Enterprise.Logging;
+using System.IO;
 
 namespace EmuXPortal
 {
@@ -25,20 +26,56 @@
         IEmuConfig CurrentSelectedRom = null;
         PlatformControl CurrentPlatformControl = null;
         GameControl CurrentGameControl = null;
-        logger log = new logger();
         public Form1()
         {
-            InitializeComponent();
+            InitializeComponent();           
+            #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(string.Format(@"{0}\{1}", log_path, log_filename));
+
+            gLog.CreateLog(log_file.FullName, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+#if DEBUG
+            LogLevel gLevel = gLog.LogLevel;
+#if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
+            gLevel &= ~LogLevel.kLogLevel_VerboseDebug;
+#else
+            gLevel |= LogLevel.kLogLevel_VerboseDebug;
+#endif
+            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
+#if DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG
+            gLevel &= ~LogLevel.kLogLevel_Debug;
+#else
+            gLevel |= LogLevel.kLogLevel_Debug;
+#endif
+            gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode         
+            gLog.SetLogLevel(gLevel);
+#endif
+            #endregion
+
             platform_flow.Dock = DockStyle.Fill;
             rom_flow.Dock = DockStyle.Fill;
-
-            log.OpenLog();          
         }
-     
+#region logging support
+        StringBuilder log_flusher = new StringBuilder();
+        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 void Form1_Load(object sender, EventArgs e)
         {
-            Config.LoadConfig(log);
-            Config.InitializePresentationForm(log,this);
+            Config.LoadConfig();
+            Config.InitializePresentationForm(this);
         }
         private void Form1_Shown(object sender, EventArgs e)
         {
@@ -72,22 +109,22 @@
                 IRomConfig config = c.Tag as IRomConfig;
                 if (config == null)
                 {
-                    log.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile);
+                    gLog.Debug.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile);
                 }
                 else
                 {
-                    var isFavorite = RomFavorite.IsFavorite(log, config);
+                    var isFavorite = RomFavorite.IsFavorite(config);
                     if (isFavorite)
                     {
                         // add to favorites
-                        log.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
-                        if (!RomFavorite.RemoveFavorite(log, config))
+                        gLog.Debug.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        if (!RomFavorite.RemoveFavorite(config))
                         {
-                            log.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                            gLog.Debug.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
                         }
                         else
                         {
-                            log.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                            gLog.Debug.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
                             if (config.Config.PlatformNameShort == "Favorites")
                             {
                                 var parent = c.Parent;
@@ -109,24 +146,24 @@
                     else
                     {
                         // add to favorites
-                        log.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
-                        if (!RomFavorite.AddFavorite(log,config))
+                        gLog.Debug.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        if (!RomFavorite.AddFavorite(config))
                         {
-                            log.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                            gLog.Debug.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
                         }
                         else
                         {
-                            log.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                            gLog.Debug.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
                         }
                     }
-                    log.WriteLine("Updateing favorites");
-                    if (!RomFavorite.UpdateFavorites(log))
+                    gLog.Debug.WriteLine("Updateing favorites");
+                    if (!RomFavorite.UpdateFavorites())
                     {
-                        log.WriteLine("Failed to update favorites");
+                        gLog.Debug.WriteLine("Failed to update favorites");
                     }
                     else
                     {
-                        log.WriteLine("Updated favorites");
+                        gLog.Debug.WriteLine("Updated favorites");
                     }
                 }
                 return; // stop processing other keys
@@ -205,7 +242,7 @@
                 Process p = new Process();
 
                 p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe;
-                p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(log, config) : config.Config.GameExeArgs;
+                p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(config) : config.Config.GameExeArgs;
                 p.Start();
 
                 // minimize EmuXPortal
@@ -490,7 +527,7 @@
         private void gameWorker_DoWork(object sender, DoWorkEventArgs e)
         {
             Stopwatch t = e.Argument as Stopwatch;
-            RomParser parser = new RomParser(log, CurrentSelectedRom);
+            RomParser parser = new RomParser(CurrentSelectedRom);
 
             CustomProgressBar bar = new CustomProgressBar();
             bar.Font = ResizeFont(GetFormFont(), PROGRESS_BAR_FONT_SIZE);
@@ -565,7 +602,7 @@
             }
             rom_flow.Controls[0].Select();
             t.Stop();
-            log.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
@@ -574,7 +611,7 @@
         private void platformWorker_DoWork(object sender, DoWorkEventArgs e)
         {
             Stopwatch t = e.Argument as Stopwatch;
-            PlatformParser parser = new PlatformParser(log, Config.RomPath);
+            PlatformParser parser = new PlatformParser(Config.RomPath);
             double count = 0;
             double total_count = parser.Platforms.Count;
             CustomProgressBar bar = new CustomProgressBar();
@@ -638,14 +675,13 @@
                 platform_flow.Controls.Add(platform_ctrl);
             }
             platform_flow.Controls[0].Select();
-            log.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
 
         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
         {
             Cursor.Show();
-            log.CloseLog();
         }
         #endregion
     }

 

  ViewVC Help
Powered by ViewVC 1.1.22