/// <summary> /// Load the specified configuration if one can be found at the specified location, otherwise create a default one there. /// </summary> /// <param name="fileName">Path to the configuration file</param> /// <returns>The loaded or created configuration</returns> public static Configuration LoadOrCreateDefault(string fileName) { if (Directory.Exists(Application.dataPath + "/Mods/Config") && File.Exists(fileName)) { return LoadConfig(fileName); } else { Configuration config = new Configuration(); Directory.CreateDirectory(Application.dataPath + "/Mods/Config"); SaveConfig(fileName, config); return config; } }
/// <summary> /// Save the specified configuration to the specified path, using XML serialization. /// </summary> /// <param name="fileName">Path to configuration file</param> /// <param name="c">Configuration to save</param> public static void SaveConfig(string fileName, Configuration c) { XmlSerializer xs = new XmlSerializer(c.GetType()); StreamWriter writer = File.CreateText(fileName); xs.Serialize(writer, c); writer.Flush(); writer.Close(); }