private void LoadPresetItems(bool clearBeforeLoading = true)
 {
     Presets.Clear();
     SelectedPreset = null;
     PresetsProvider.ReloadPresetItems();
     Presets.AddRange(PresetsProvider.PresetItems);
     Presets.IsDirty = false;
     IsDirty         = false;
     SelectedPreset  = Presets.FirstOrDefault();
 }
Esempio n. 2
0
        /// <summary>
        /// Import presets from mod and local presets from disk.
        /// </summary>
        public void LoadPresets()
        {
            if (Presets.Count > 0)
            {
                Presets.Clear();
            }

            // Get presets from mod
            if (mod.HasAsset(presetsFileName))
            {
                List <Preset> modPresets = new List <Preset>();
                if (TryDeserialize(mod, presetsFileName, ref modPresets))
                {
                    Presets.AddRange(modPresets);
                }
            }

            // Local presets (managed from gui)
            Directory.CreateDirectory(mod.ConfigurationDirectory);
            string localPresetsPath = LocalPresetsPath;

            if (File.Exists(LegacyLocalPresetsPath))
            {
                ModManager.MoveOldConfigFile(LegacyLocalPresetsPath, localPresetsPath);
            }
            if (File.Exists(localPresetsPath))
            {
                List <Preset> localPresets = new List <Preset>();
                if (TryDeserialize(localPresetsPath, ref localPresets))
                {
                    foreach (var preset in localPresets)
                    {
                        preset.IsLocal = true;
                    }
                    Presets.AddRange(localPresets);
                }
            }

            // Imported presets (readonly)
            Presets.AddRange(TextAssetReader.ReadAll <Preset>(string.Format("Presets/{0}", mod.FileName), "json"));

            // Legacy imported presets (readonly)
            foreach (string path in Directory.GetFiles(mod.DirPath, string.Format("{0}_presets_*.json", mod.FileName)))
            {
                List <Preset> importedPresets = new List <Preset>();
                if (TryDeserialize(path, ref importedPresets))
                {
                    Presets.AddRange(importedPresets);
                }

                Debug.LogWarningFormat($"Imported legacy preset for {mod}.");
            }

            HasLoadedPresets = true;
        }
Esempio n. 3
0
        /// <summary>
        /// Import presets from path.
        /// </summary>
        public void LoadPresets(string path, bool merge = false)
        {
            if (!merge && Presets.Count > 0)
            {
                Presets.Clear();
            }

            List <Preset> presetData = new List <Preset>();

            if (TryDeserialize(path, ref presetData))
            {
                Presets.AddRange(presetData);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Import presets from mod and local presets from disk.
        /// </summary>
        public void LoadPresets()
        {
            if (Presets.Count > 0)
            {
                Presets.Clear();
            }

            // Get presets from mod
            if (mod.AssetBundle.Contains(presetsFileName))
            {
                List <Preset> modPresets = new List <Preset>();
                if (TryDeserialize(mod, presetsFileName, ref modPresets))
                {
                    Presets.AddRange(modPresets);
                }
            }

            // Local presets (managed from gui)
            string localPresetsPath = LocalPresetsPath;

            if (File.Exists(localPresetsPath))
            {
                List <Preset> localPresets = new List <Preset>();
                if (TryDeserialize(localPresetsPath, ref localPresets))
                {
                    foreach (var preset in localPresets)
                    {
                        preset.IsLocal = true;
                    }
                    Presets.AddRange(localPresets);
                }
            }

            // Other imported presets (readonly)
            foreach (string path in ImportedPresetsPaths)
            {
                List <Preset> importedPresets = new List <Preset>();
                if (TryDeserialize(path, ref importedPresets))
                {
                    Presets.AddRange(importedPresets);
                }
            }

            HasLoadedPresets = true;
        }
        /// <summary>
        /// Import presets from mod and local presets from disk.
        /// </summary>
        public void LoadPresets()
        {
            if (Presets.Count > 0)
            {
                Presets.Clear();
            }

            // Get presets from mod
            if (mod.HasAsset(presetsFileName))
            {
                List <Preset> modPresets = new List <Preset>();
                if (TryDeserialize(mod, presetsFileName, ref modPresets))
                {
                    Presets.AddRange(modPresets);
                }
            }

            // Local presets (managed from gui)
            Directory.CreateDirectory(mod.ConfigurationDirectory);
            string localPresetsPath = LocalPresetsPath;

            if (File.Exists(LegacyLocalPresetsPath))
            {
                ModManager.MoveOldConfigFile(LegacyLocalPresetsPath, localPresetsPath);
            }
            if (File.Exists(localPresetsPath))
            {
                List <Preset> localPresets = new List <Preset>();
                if (TryDeserialize(localPresetsPath, ref localPresets))
                {
                    foreach (var preset in localPresets)
                    {
                        preset.IsLocal = true;
                    }
                    Presets.AddRange(localPresets);
                }
            }

            // Other imported presets (readonly)
            foreach (string path in Directory.GetFiles(mod.DirPath, string.Format("{0}_presets_*.json", mod.FileName)))
            {
                List <Preset> importedPresets = new List <Preset>();
                if (TryDeserialize(path, ref importedPresets))
                {
                    Presets.AddRange(importedPresets);
                }
            }
            string presetsDirectory = Path.Combine(mod.ConfigurationDirectory, "Presets");

            if (Directory.Exists(presetsDirectory))
            {
                foreach (string path in Directory.GetFiles(presetsDirectory, "*.json"))
                {
                    List <Preset> importedPresets = new List <Preset>();
                    if (TryDeserialize(path, ref importedPresets))
                    {
                        Presets.AddRange(importedPresets);
                    }
                }
            }

            HasLoadedPresets = true;
        }