/// <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) { }
/// <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 re-read 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; if (DEBUG_LOG_ON & DEBUG_LOG_LEVEL == 0) { DEBUG_LOG_LEVEL = 1; } 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); } }
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); } }