public ConfigCustomBlocks LoadSettings() { if (MyAPIGateway.Utilities.FileExistsInWorldStorage("Config-CustomBlocks.xml", typeof(ConfigCustomBlocks)) == true) { try{ ConfigCustomBlocks config = null; var reader = MyAPIGateway.Utilities.ReadFileInWorldStorage("Config-CustomBlocks.xml", typeof(ConfigCustomBlocks)); string configcontents = reader.ReadToEnd(); config = MyAPIGateway.Utilities.SerializeFromXML <ConfigCustomBlocks>(configcontents); Logger.AddMsg("Loaded Existing Settings From Config-CustomBlocks.xml"); return(config); }catch (Exception exc) { Logger.AddMsg("ERROR: Could Not Load Settings From Config-CustomBlocks.xml. Using Default Configuration."); var defaultSettings = new ConfigCustomBlocks(); return(defaultSettings); } } var settings = new ConfigCustomBlocks(); try{ using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-CustomBlocks.xml", typeof(ConfigCustomBlocks))){ writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigCustomBlocks>(settings)); } }catch (Exception exc) { Logger.AddMsg("ERROR: Could Not Create Config-CustomBlocks.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(ConfigCustomBlocks settings) { try{ using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-CustomBlocks.xml", typeof(ConfigCustomBlocks))){ writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigCustomBlocks>(settings)); } Logger.AddMsg("Settings In Config-CustomBlocks.xml Updated Successfully!"); return("Settings Updated Successfully."); }catch (Exception exc) { Logger.AddMsg("ERROR: Could Not Save To Config-CustomBlocks.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."); }