public ConfigRandomEncounters LoadSettings()
        {
            if (MyAPIGateway.Utilities.FileExistsInWorldStorage("Config-RandomEncounters.xml", typeof(ConfigRandomEncounters)) == true)
            {
                try{
                    ConfigRandomEncounters config = null;
                    var    reader         = MyAPIGateway.Utilities.ReadFileInWorldStorage("Config-RandomEncounters.xml", typeof(ConfigRandomEncounters));
                    string configcontents = reader.ReadToEnd();
                    config = MyAPIGateway.Utilities.SerializeFromXML <ConfigRandomEncounters>(configcontents);
                    Logger.AddMsg("Loaded Existing Settings From Config-RandomEncounters.xml");
                    return(config);
                }catch (Exception exc) {
                    Logger.AddMsg("ERROR: Could Not Load Settings From Config-RandomEncounters.xml. Using Default Configuration.");
                    var defaultSettings = new ConfigRandomEncounters();
                    return(defaultSettings);
                }
            }

            var settings = new ConfigRandomEncounters();

            try{
                using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-RandomEncounters.xml", typeof(ConfigRandomEncounters))){
                    writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigRandomEncounters>(settings));
                }
            }catch (Exception exc) {
                Logger.AddMsg("ERROR: Could Not Create Config-RandomEncounters.xml. Default Settings Will Be Used.");
            }

            return(settings);
        }
Пример #2
0
 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(ConfigRandomEncounters settings)
        {
            try{
                using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-RandomEncounters.xml", typeof(ConfigRandomEncounters))){
                    writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigRandomEncounters>(settings));
                }

                Logger.AddMsg("Settings In Config-RandomEncounters.xml Updated Successfully!");
                return("Settings Updated Successfully.");
            }catch (Exception exc) {
                Logger.AddMsg("ERROR: Could Not Save To Config-RandomEncounters.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.");
        }