Example #1
0
        public static void Write()
        {
            var newSettings = Serialise.SerialiseSettings().Select(s => new Setting {
                Key = s.Key, Value = s.Value
            });

            Settings.Clear();
            Settings.AddRange(newSettings);

            var root = new GenericStructure("Sledge");

            // Settings
            var settings = new GenericStructure("Settings");

            foreach (var setting in Settings)
            {
                settings.AddProperty(setting.Key, setting.Value);
            }
            root.Children.Add(settings);

            // Recent Files
            var recents = new GenericStructure("RecentFiles");
            var i       = 1;

            foreach (var file in RecentFiles.OrderBy(x => x.Order).Select(x => x.Location).Where(File.Exists))
            {
                recents.AddProperty(i.ToString(CultureInfo.InvariantCulture), file);
                i++;
            }
            root.Children.Add(recents);

            // Games > Fgds/Wads
            foreach (var game in Games)
            {
                var g = new GenericStructure("Game");
                game.Write(g);
                root.Children.Add(g);
            }

            // Builds
            foreach (var build in Builds)
            {
                var b = new GenericStructure("Build");
                build.Write(b);
                root.Children.Add(b);
            }

            // Hotkeys
            Hotkeys = Sledge.Settings.Hotkeys.GetHotkeys().ToList();
            var hotkeys = new GenericStructure("Hotkeys");

            foreach (var g in Hotkeys.GroupBy(x => x.ID))
            {
                var count = 0;
                foreach (var hotkey in g)
                {
                    hotkeys.AddProperty(hotkey.ID + ":" + count, hotkey.HotkeyString);
                    count++;
                }
            }
            root.Children.Add(hotkeys);

            // Additional
            var additional = new GenericStructure("AdditionalSettings");

            foreach (var kv in AdditionalSettings)
            {
                var child = new GenericStructure(kv.Key);
                child.Children.Add(kv.Value);
                additional.Children.Add(child);
            }
            root.Children.Add(additional);

            // Favourite textures
            var favTextures = new GenericStructure("FavouriteTextures");

            favTextures.Children.Add(GenericStructure.Serialise(FavouriteTextureFolders));
            root.Children.Add(favTextures);

            File.WriteAllText(SettingsFile, root.ToString());
        }