Example #1
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.1f) tmpConfig.GuiOpacity = 1.0f;
     if (tmpConfig.VehicleReserveAmount > 512 | tmpConfig.VehicleReserveAmount < 2) tmpConfig.VehicleReserveAmount = 16;
     if (tmpConfig.AutoRefreshSeconds > 60.0f | tmpConfig.AutoRefreshSeconds < 1.0f) tmpConfig.AutoRefreshSeconds=3.0f;
     if (tmpConfig.RefreshVehicleCounterSeconds > 10.0f | tmpConfig.RefreshVehicleCounterSeconds < 0.05f) tmpConfig.RefreshVehicleCounterSeconds = 0.180f;
     if (tmpConfig.ResetStatsEveryXMin < 1 | tmpConfig.ResetStatsEveryXMin > 10000000) tmpConfig.ResetStatsEveryXMin = 20;
 }
Example #2
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);
     }
 }
Example #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 (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;
                     RESERVEAMOUNT = config.VehicleReserveAmount;
                     IsGuiEnabled = config.EnableGui;
                     UseAutoRefreshOption = config.UseAutoRefresh;
                     AutoRefreshSeconds = config.AutoRefreshSeconds;
                     config.VehicleReserveAmountIndex = GetOptionIndexFromValue(config.VehicleReserveAmount);
                     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); }
        }