예제 #1
0
        /// <summary>
        /// Load the mod settings. Loads the settings from {ModManager.PathSettings}/{Metadata.Name}.yaml by default.
        /// </summary>
        public virtual void LoadSettings()
        {
            if (SettingsType == null)
            {
                return;
            }

            _Settings = (ModSettings)SettingsType.GetConstructor(ModManager._EmptyTypeArray).Invoke(ModManager._EmptyObjectArray);

            string extension = ".yaml";

            string path = Path.Combine(ModManager.PathSettings, Metadata.Name + extension);

            if (!File.Exists(path))
            {
                return;
            }

            try {
                using (Stream stream = File.OpenRead(path))
                    using (StreamReader reader = new StreamReader(path))
                        _Settings = (ModSettings)YamlHelper.Deserializer.Deserialize(reader, SettingsType);
            } catch {
            }
        }
예제 #2
0
        /// <summary>
        /// Load the mod settings. Loads the settings from {UserIO.GetSavePath("Saves")}/modsettings-{Metadata.Name}.celeste by default.
        /// </summary>
        public virtual void LoadSettings()
        {
            if (SettingsType == null)
            {
                return;
            }

            _Settings = (EverestModuleSettings)SettingsType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray);

            string path = patch_UserIO.GetSaveFilePath("modsettings-" + Metadata.Name);

            // Temporary fallback to help migrate settings from their old location.
            if (!File.Exists(path))
            {
                path = Path.Combine(Everest.PathEverest, "ModSettings-OBSOLETE", Metadata.Name + ".yaml");
            }

            if (!File.Exists(path))
            {
                return;
            }

            try {
                using (Stream stream = File.OpenRead(path)) {
                    if (_Settings is EverestModuleBinarySettings)
                    {
                        using (BinaryReader reader = new BinaryReader(stream))
                            ((EverestModuleBinarySettings)_Settings).Read(reader);
                    }
                    else
                    {
                        IDeserializer deserializer = new DeserializerBuilder()
                                                     .IgnoreUnmatchedProperties()
                                                     .WithObjectFactory(t => _Settings)
                                                     .Build();
                        using (StreamReader reader = new StreamReader(path))
                            _Settings = (EverestModuleSettings)deserializer.Deserialize(reader, SettingsType);
                    }
                }
            } catch {
            }

            if (_Settings == null)
            {
                _Settings = (EverestModuleSettings)SettingsType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray);
            }
        }
예제 #3
0
        /// <summary>
        /// Load the mod settings. Loads the settings from {Everest.PathSettings}/{Metadata.Name}.yaml by default.
        /// </summary>
        public virtual void LoadSettings()
        {
            if (SettingsType == null)
            {
                return;
            }

            _Settings = (EverestModuleSettings)SettingsType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray);

            string extension = ".yaml";

            if (_Settings is EverestModuleBinarySettings)
            {
                extension = ".bin";
            }

            string path = Path.Combine(Everest.PathSettings, Metadata.Name + extension);

            if (!File.Exists(path))
            {
                return;
            }

            try {
                using (Stream stream = File.OpenRead(path)) {
                    if (_Settings is EverestModuleBinarySettings)
                    {
                        // .bin
                        using (BinaryReader reader = new BinaryReader(stream))
                            ((EverestModuleBinarySettings)_Settings).Read(reader);
                    }
                    else
                    {
                        // .yaml
                        using (StreamReader reader = new StreamReader(path)) {
                            _Settings = (EverestModuleSettings)YamlHelper.Deserializer.Deserialize(reader, SettingsType);
                        }
                    }
                }
            } catch {
            }

            if (_Settings == null)
            {
                _Settings = (EverestModuleSettings)SettingsType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray);
            }
        }
예제 #4
0
        /// <summary>
        /// Load the mod settings. Loads the settings from {Everest.PathSettings}/{Metadata.Name}.yaml by default.
        /// </summary>
        public virtual void LoadSettings()
        {
            if (SettingsType == null)
            {
                return;
            }
            string path = Path.Combine(Everest.PathSettings, Metadata.Name + ".yaml");

            if (!File.Exists(path))
            {
                _Settings = (EverestModuleSettings)SettingsType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray);
                return;
            }
            using (Stream stream = File.OpenRead(path))
                using (StreamReader reader = new StreamReader(path))
                    _Settings = (EverestModuleSettings)YamlHelper.Deserializer.Deserialize(reader, SettingsType);
        }
예제 #5
0
        /// <summary>
        /// Load the mod settings. Loads the settings from {UserIO.GetSavePath("Saves")}/modsettings-{Metadata.Name}.celeste by default.
        /// </summary>
        public virtual void LoadSettings()
        {
            if (SettingsType == null)
            {
                return;
            }

            _Settings = (EverestModuleSettings)SettingsType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray);

            string path = patch_UserIO.GetSaveFilePath("modsettings-" + Metadata.Name);

            // Temporary fallback to help migrate settings from their old location.
            if (!File.Exists(path))
            {
                path = Path.Combine(Everest.PathEverest, "ModSettings-OBSOLETE", Metadata.Name + ".yaml");
            }

            if (!File.Exists(path))
            {
                return;
            }

            try {
                using (Stream stream = File.OpenRead(path)) {
                    if (_Settings is EverestModuleBinarySettings)
                    {
                        using (BinaryReader reader = new BinaryReader(stream))
                            ((EverestModuleBinarySettings)_Settings).Read(reader);
                    }
                    else
                    {
                        using (StreamReader reader = new StreamReader(stream))
                            YamlHelper.DeserializerUsing(_Settings).Deserialize(reader, SettingsType);
                    }
                }
            } catch (Exception e) {
                Logger.Log(LogLevel.Warn, "EverestModule", $"Failed to load the settings of {Metadata.Name}!");
                Logger.LogDetailed(e);
            }

            if (_Settings == null)
            {
                _Settings = (EverestModuleSettings)SettingsType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray);
            }
        }