コード例 #1
0
        public ConfigGeneral LoadSettings()
        {
            if (MyAPIGateway.Utilities.FileExistsInLocalStorage("InhibitorSettings.xml", typeof(ConfigGeneral)) == true)
            {
                try
                {
                    ConfigGeneral config         = null;
                    var           reader         = MyAPIGateway.Utilities.ReadFileInLocalStorage("InhibitorSettings.xml", typeof(ConfigGeneral));
                    string        configcontents = reader.ReadToEnd();
                    config = MyAPIGateway.Utilities.SerializeFromXML <ConfigGeneral>(configcontents);
                    //MyVisualScriptLogicProvider.SendChatMessage(config.ToString(), "config: ");
                    if (!MyAPIGateway.Session.IsServer)
                    {
                        return(config);
                    }
                    MyLog.Default.WriteLine($"1234 {config.MaxRadius}");
                    MyLog.Default.WriteLine($"12345 {config.MaxPowerDrain}");
                    MyLog.Default.WriteLine($"1234 culture {config.MaxRadius.ToString(CultureInfo.InvariantCulture)}");
                    MyLog.Default.WriteLine($"12345 culture {config.MaxPowerDrain.ToString(CultureInfo.InvariantCulture)}");
                    var msg = $"{config.MaxRadius.ToString(CultureInfo.InvariantCulture)}-{config.MaxPowerDrain.ToString(CultureInfo.InvariantCulture)}";
                    NetworkService.SendPacket(msg);
                    return(config);
                }
                catch (Exception)
                {
                    var defaultSettings = new ConfigGeneral();

                    return(defaultSettings);
                }
            }

            var settings = new ConfigGeneral();

            try
            {
                //MyVisualScriptLogicProvider.SendChatMessage("new config.", "Debug");
                using (var writer = MyAPIGateway.Utilities.WriteFileInLocalStorage("InhibitorSettings.xml", typeof(ConfigGeneral)))
                {
                    writer.Write(MyAPIGateway.Utilities.SerializeToXML(settings));
                    //writer.Write("config");
                    //MyVisualScriptLogicProvider.SendChatMessage(settings.ToString(), "Settings: ");
                    //MyVisualScriptLogicProvider.SendChatMessage("new config made.", "Debug");
                }
            }
            catch (Exception)
            {
            }

            return(settings);
        }
コード例 #2
0
        public string SaveSettings(ConfigGeneral settings)
        {
            try
            {
                using (var writer = MyAPIGateway.Utilities.WriteFileInLocalStorage("InhibitorSettings.xml", typeof(ConfigGeneral)))
                {
                    writer.Write(MyAPIGateway.Utilities.SerializeToXML(settings));
                }



                return("Settings Updated Successfully.");
            }
            catch (Exception)
            {
            }

            return("Settings Changed, But Could Not Be Saved To XML. Changes May Be Lost On Session Reload.");
        }