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

            var settings = new ConfigGeneral();

            try{
                using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-General.xml", typeof(ConfigGeneral))){
                    writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigGeneral>(settings));
                }
            }catch (Exception exc) {
                Logger.AddMsg("ERROR: Could Not Create Config-General.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();
 }
Пример #3
0
        public string SaveSettings(ConfigGeneral settings)
        {
            try{
                using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage("Config-General.xml", typeof(ConfigGeneral))){
                    writer.Write(MyAPIGateway.Utilities.SerializeToXML <ConfigGeneral>(settings));
                }

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