Ejemplo n.º 1
0
 public static void Serialize(string filename, Configuration config)
 {
     var serializer = new XmlSerializer(typeof(Configuration));
     try
     {
         using (var writer = new StreamWriter(filename))
         {
             serializer.Serialize(writer, config);
         }
     }
     catch (System.IO.IOException ex1)
     {
         Helper.dbgLog("Filesystem or IO Error: \r\n", ex1, true);
     }
     catch (Exception ex1)
     {
         Helper.dbgLog(ex1.Message.ToString() + "\r\n", ex1, true);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Constrain certain values read in from the config file that will either cause issue or just make no sense. 
 /// </summary>
 /// <param name="tmpConfig"> An instance of an initialized Configuration object (byref)</param>
 public static void ValidateConfig(ref Configuration tmpConfig)
 {
     if (tmpConfig.GuiOpacity > 1.0f | tmpConfig.GuiOpacity < 0.10f) tmpConfig.GuiOpacity = 1.0f;
     if (tmpConfig.AutoRefreshSeconds > 60.0f | tmpConfig.AutoRefreshSeconds < 1.0f) tmpConfig.AutoRefreshSeconds=3.0f;
     if (tmpConfig.StatsCheckEverySeconds > 180.1f | tmpConfig.StatsCheckEverySeconds < 3.00f) tmpConfig.StatsCheckEverySeconds = 60.0f;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Called to either initially load, or force a reload our config file var; called by mod initialization and again at mapload. 
        /// </summary>
        /// <param name="bForceReread">Set to true to flush the old object and create a new one.</param>
        /// <param name="bNoReloadVars">Set this to true to NOT reload the values from the new read of config file to our class level counterpart vars</param>
        public static void ReloadConfigValues(bool bForceReread, bool bNoReloadVars)
        {
            try
             {
                 if(isFirstEnable == true)
                 {return;}

                 if (bForceReread)
                 {
                     config = null;
                     if (DEBUG_LOG_ON & DEBUG_LOG_LEVEL >= 1) { Helper.dbgLog("Config wipe requested."); }
                 }
                 config = Configuration.Deserialize(MOD_CONFIGPATH);
                 if (config == null)
                 {
                     config = new Configuration();
                     config.ConfigVersion = Configuration.CurrentVersion;
                     //reset of setting should pull defaults
                     Helper.dbgLog("Existing config was null. Created new one.");
                     Configuration.Serialize(MOD_CONFIGPATH, config); //let's write it.
                 }
                 if (config != null && bNoReloadVars == false) //set\refresh our vars by default.
                 {
                     config.ConfigVersion = Configuration.CurrentVersion;
                     DEBUG_LOG_ON = config.DebugLogging;
                     DEBUG_LOG_LEVEL = config.DebugLoggingLevel;
                     IsGuiEnabled = config.EnableGui;
                     UseAutoRefreshOption = config.UseAutoRefresh;
                     AutoRefreshSeconds = config.AutoRefreshSeconds;
                     if (DEBUG_LOG_ON & DEBUG_LOG_LEVEL >= 2) { Helper.dbgLog("Vars refreshed"); }
                 }
                 if (DEBUG_LOG_ON & DEBUG_LOG_LEVEL >= 2) { Helper.dbgLog(string.Format("Reloaded Config data ({0}:{1} :{2})", bForceReread.ToString(), bNoReloadVars.ToString(), config.ConfigVersion.ToString())); }
             }
             catch (Exception ex)
             { Helper.dbgLog("Exception while loading config values.", ex, true); }
        }