/[RomCheater]/trunk/RomCheater/RomCheaterConfigDialog.cs
ViewVC logotype

Diff of /trunk/RomCheater/RomCheaterConfigDialog.cs

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

--- trunk/RomCheater/RomCheaterConfigDialog.cs	2012/05/09 16:14:39	63
+++ trunk/RomCheater/RomCheaterConfigDialog.cs	2014/04/15 18:02:07	817
@@ -1,4 +1,18 @@
-´╗┐using System;
+´╗┐//#region Logging Defines
+//// include this any class or method that required logging, and comment-out what is not needed
+
+//#region Enabled logging levels
+//#define LOGGING_ENABLE_INFO
+//#define LOGGING_ENABLE_WARN
+//#define LOGGING_ENABLE_DEBUG
+//#define LOGGING_ENABLE_VERBOSEDEBUG
+//#define LOGGING_ENABLE_ERROR
+//#define LOGGING_ENABLE_VERBOSEERROR
+//#define LOGGING_ENABLE_PROFILER
+//#endregion
+//#endregion
+//#define DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST //when defined, will not log verbose debug messages (without changeing logging flags)
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
@@ -7,46 +21,153 @@
 using System.Text;
 using System.Windows.Forms;
 using RomCheater.Logging;
+using RomCheater.PluginFramework.Core;
+using RomCheater.Core;
+using RomCheater.UserSettingsSupport;
+using Enterprise.Logging;
+
 
 namespace RomCheater
 {
     public partial class RomCheaterConfigDialog : Form
     {
+#if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
+        private loggerflags lFlags;
+#endif
+
+        SettingSubscriber MainSettingsSubscriber;
+        SettingSubscriber LoggingettingsSubscriber;
+
+        private PluginLoader loader = null;
         public RomCheaterConfigDialog()
         {
             InitializeComponent();
+            //lFlags = logger.GetLoggingFlags();
+            //ushort flags = lFlags.Value;
+            //if (lFlags.HasFlag(loggerflags.VERBOSE_DEBUG))
+            //{
+            //    flags = lFlags.Value;
+            //    flags = (ushort)(lFlags.Value & ~loggerflags.VERBOSE_DEBUG.Value);
+            //    logger.SetLoggingFlags(flags);                
+            //}
+            MainSettingsSubscriber = new SettingSubscriber();
+            LoggingettingsSubscriber = new SettingSubscriber();
+            MainSettingsSubscriber.AddSubscriber(this, RomCheater.Properties.Settings.Default);
+            LoggingettingsSubscriber.AddSubscriber(this, RomCheater.Logging.Properties.Settings.Default);
+        }
+        public RomCheaterConfigDialog(PluginLoader loader)
+            : this()
+        {
+            this.loader = loader;
         }
-
         private void RomCheaterConfigDialog_Load(object sender, EventArgs e)
         {
-            foreach(loggerflags flags in Enum.GetValues(typeof(loggerflags)))
+            gLog.Info.WriteLine("Loading user settings...");
+            load_loggerflags();
+            setup_plugin_entries();
+            gLog.Info.WriteLine("Loaded user settings.");
+        }
+
+        private void setup_plugin_entries()
+        {
+            foreach (IConfigPlugin c in loader.LoadedConfigPlugins) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); }
+            foreach (IInputPlugin c in loader.LoadedInputPlugins) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); }
+            foreach (IWindowPlugin c in loader.LoadedWindowPlugins) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", c.Name, c.ID.ToString())); }
+            if (loader.LoadedConfigPlugins.Count == 0) { comboConfigPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
+            if (loader.LoadedInputPlugins.Count == 0) { comboInputPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
+            if (loader.LoadedWindowPlugins.Count == 0) { comboWindowPlugins.Items.Add(string.Format("{0} [{1}]", "None", new Guid().ToString())); }
+
+            comboConfigPlugins.SelectedIndex = 0;
+            comboInputPlugins.SelectedIndex = 0;
+            comboWindowPlugins.SelectedIndex = 0;
+
+            // select each plugin base on the last plugin
+            foreach (string item in comboConfigPlugins.Items)
             {
-                if (flags == loggerflags.ALL ||
-                    flags == loggerflags.NONE ||
-                    flags == loggerflags.DEFAULT)
-                    continue;
+                if (item == RomCheater.Properties.Settings.Default.LastConfigPlugin)
+                {
+                    gLog.Verbose.Debug.WriteLine("    loading LastConfigPlugin: {0}", MainSettingsSubscriber.GetValue("LastConfigPlugin"));
+                    comboConfigPlugins.SelectedIndex = comboConfigPlugins.Items.IndexOf(item);
+                    break;
+                }
+            }
+            foreach (string item in comboInputPlugins.Items)
+            {
+                if (item == RomCheater.Properties.Settings.Default.LastInputPlugin)
+                {
+                    gLog.Verbose.Debug.WriteLine("    loading LastInputPlugin: {0}", MainSettingsSubscriber.GetValue("LastInputPlugin"));
+                    comboInputPlugins.SelectedIndex = comboInputPlugins.Items.IndexOf(item);
+                    break;
+                }
+            }
+            foreach (string item in comboWindowPlugins.Items)
+            {
+                if (item == RomCheater.Properties.Settings.Default.LastWindowPlugin)
+                {
+                    gLog.Verbose.Debug.WriteLine("    loading LastWindowPlugin: {0}", MainSettingsSubscriber.GetValue("LastWindowPlugin"));
+                    comboWindowPlugins.SelectedIndex = comboWindowPlugins.Items.IndexOf(item);
+                    break;
+                }
+            }
+
+        }
 
-                string name = flags.ToString();
-                int value = (int)flags;
+        private void load_loggerflags()
+        {
+            gLog.Info.WriteLine("  Loading logger flags...");
 
+            bool upgraded_flags = Convert.ToBoolean(LoggingettingsSubscriber.GetValue("UpgradedLogLevel"));
+            object o_flags = null;
+            if (!upgraded_flags)
+            {
+                o_flags = new LoggingFlagsConverter(Logging.Properties.Settings.Default.LoggingFlags).ConvertFlags();
+                LoggingettingsSubscriber.SetValue("UpgradedLogLevel", true);
+                LoggingettingsSubscriber.SetValue("gLogLoggingFlags", Convert.ToUInt32(o_flags));
+                LoggingettingsSubscriber.SaveSettings();
+            }
+            o_flags = LoggingettingsSubscriber.GetValue("gLogLoggingFlags");
+            LogLevel log_level = (LogLevel)o_flags;
+#if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
+      gLog.SetLogLevel(log_level & ~LogLevel.kLogLevel_Verbose);      
+#endif
+            foreach (LogLevel t in Enum.GetValues(typeof(LogLevel)))
+            {
+                if (t == LogLevel.kLogLevel_All ||
+                        t == LogLevel.kLogLevel_Disable ||
+                        t == LogLevel.kLogLevel_None ||
+                        t == LogLevel.kLogLevel_All_NoProgress ||
+                        t == LogLevel.kLogLevel_All_NoProfiler ||
+                        t == LogLevel.kLogLevel_All_NoProfilerOrProgress ||
+                        t == LogLevel.kLogLevel_Default ||
+                        t == LogLevel.kLogLevel_Verbose)
+                {
+                    continue;
+                }
                 CheckBox chkloggerflags = new CheckBox();
+                chkloggerflags.Font = this.Font;
+                string name = Enum.GetName(typeof(LogLevel), t).Replace("kLogLevel_", "");
+                LogLevel value = t;
                 chkloggerflags.Name = name;
                 chkloggerflags.Text = name;
                 chkloggerflags.Tag = value;
+                Graphics g = chkloggerflags.CreateGraphics();
+                Size size = g.MeasureString(chkloggerflags.Text, chkloggerflags.Font).ToSize();
+                chkloggerflags.Width = size.Width + 25;
                 grpLoggingFlags_flow.Controls.Add(chkloggerflags);
-                loggerflags logflags = (loggerflags)Logging.Properties.Settings.Default.LoggingFlags;
-
-                if (logflags.HasFlag((loggerflags)value))
+                if (log_level.HasFlag(t))
                 {
                     chkloggerflags.Checked = true;
+                    gLog.Verbose.Debug.WriteLine("\tTurning on logger flag: {0} value: 0x{1:x4}", name, (uint)value);
                 }
             }
-            grpLoggingFlags.AutoSize = true;
-            grpLoggingFlags.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
-        }
+            //grpLoggingFlags.AutoSize = true;
+            //grpLoggingFlags.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
 
+            gLog.Info.WriteLine("  Loaded logger flags.");
+        }
         private void btnSave_Click(object sender, EventArgs e)
         {
+            gLog.Info.WriteLine("Saving user settings...");
             SaveSettings();
             this.Close();
         }
@@ -54,23 +175,53 @@
         {
             this.Close();
         }
-
         private void SaveSettings()
         {
             SaveLoggingFlags();
-            RomCheater.Properties.Settings.Default.Save();
-            Logging.Properties.Settings.Default.Save();
+            SaveSelectedPlugins();
+            MainSettingsSubscriber.SaveSettings();
+            LoggingettingsSubscriber.SaveSettings();
+            //RomCheater.Properties.Settings.Default.Save();
+            //Logging.Properties.Settings.Default.Save();
+            gLog.Info.WriteLine("Saved user settings.");
+        }
+        private void SaveSelectedPlugins()
+        {
+            gLog.Verbose.Debug.WriteLine("    Setting LastConfigPlugin to {0}", comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
+            MainSettingsSubscriber.SetValue("LastConfigPlugin",comboConfigPlugins.Items[comboConfigPlugins.SelectedIndex].ToString());
+
+            gLog.Verbose.Debug.WriteLine("    Setting LastInputPlugin to {0}", comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString());            
+            MainSettingsSubscriber.SetValue("LastInputPlugin", comboInputPlugins.Items[comboInputPlugins.SelectedIndex].ToString());
+
+            gLog.Verbose.Debug.WriteLine("    Setting LastWindowPlugin to {0}", comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString());            
+            MainSettingsSubscriber.SetValue("LastWindowPlugin", comboWindowPlugins.Items[comboWindowPlugins.SelectedIndex].ToString());
         }
         private void SaveLoggingFlags()
         {
-            loggerflags logflags = loggerflags.NONE;
+            gLog.Debug.WriteLine("Saving Logger flags...");
+            LogLevel logflags = LogLevel.kLogLevel_None;
             foreach (CheckBox cb in grpLoggingFlags_flow.Controls)
             {
                 if (!cb.Checked) continue;
-                int value = Convert.ToInt32(cb.Tag);
-                logflags = logflags | (loggerflags)value;
+                uint value = Convert.ToUInt32(cb.Tag);
+                logflags = logflags | (LogLevel)value;
+                gLog.Verbose.Debug.WriteLine("\tAdding flag: {0} value: 0x{1:x8} LoggingFlags=0x{2:x4}", cb.Text, value, (int)logflags);
             }
-            Logging.Properties.Settings.Default.LoggingFlags = (int)logflags;
+
+            LoggingettingsSubscriber.SetValue("gLogLoggingFlags", (uint)logflags);
+            gLog.Debug.WriteLine("Saved Logger flags.");
+        }
+
+        private void RomCheaterConfigDialog_FormClosing(object sender, FormClosingEventArgs e)
+        {
+
+        }
+
+        private void RomCheaterConfigDialog_FormClosed(object sender, FormClosedEventArgs e)
+        {
+#if DISABLE_VERBOSE_DEBUG_MESSAGES_FOR_SPEED_BOOST
+            logger.SetLoggingFlags(lFlags);
+#endif
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22