public ConfigSpaceCargoShips LoadSettings() { if (MyAPIGateway.Utilities.FileExistsInWorldStorage("Config-SpaceCargoShips.xml", typeof(ConfigSpaceCargoShips)) == true) { try{ ConfigSpaceCargoShips config = null; var reader = MyAPIGateway.Utilities.ReadFileInWorldStorage("Config-SpaceCargoShips.xml", typeof(ConfigSpaceCargoShips)); string configcontents = reader.ReadToEnd(); config = MyAPIGateway.Utilities.SerializeFromXML <ConfigSpaceCargoShips>(configcontents); Logger.AddMsg("Loaded Existing Settings From Config-SpaceCargoShips.xml"); return(config); }catch (Exception exc) { Logger.AddMsg("ERROR: Could Not Load Settings From Config-SpaceCargoShips.xml. Using Default Configuration."); var defaultSettings = new ConfigSpaceCargoShips(); return(defaultSettings); } } var settings = new ConfigSpaceCargoShips(); try{ using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-SpaceCargoShips.xml", typeof(ConfigSpaceCargoShips))){ writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigSpaceCargoShips>(settings)); } }catch (Exception exc) { Logger.AddMsg("ERROR: Could Not Create Config-SpaceCargoShips.xml. Default Settings Will Be Used."); } return(settings); }
public static void InitSettings() { General = General.LoadSettings(); SpaceCargoShips = SpaceCargoShips.LoadSettings(); PlanetaryCargoShips = PlanetaryCargoShips.LoadSettings(); RandomEncounters = RandomEncounters.LoadSettings(); PlanetaryInstallations = PlanetaryInstallations.LoadSettings(); BossEncounters = BossEncounters.LoadSettings(); OtherNPCs = OtherNPCs.LoadSettings(); CustomBlocks = CustomBlocks.LoadSettings(); CheckGlobalEvents(); }
public string SaveSettings(ConfigSpaceCargoShips settings) { try{ using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-SpaceCargoShips.xml", typeof(ConfigSpaceCargoShips))){ writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigSpaceCargoShips>(settings)); } Logger.AddMsg("Settings In Config-SpaceCargoShips.xml Updated Successfully!"); return("Settings Updated Successfully."); }catch (Exception exc) { Logger.AddMsg("ERROR: Could Not Save To Config-SpaceCargoShips.xml. Changes Will Be Lost On World Reload."); } return("Settings Changed, But Could Not Be Saved To XML. Changes May Be Lost On Session Reload."); }