コード例 #1
0
        public static void Serialize(string filename, Configuration config)
        {
            var xmlSerializer = new XmlSerializer(typeof(Configuration));
            try
            {
                using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(filename))
                {
                    var configCopy = new Configuration();

                    configCopy.UnlockPolicyPanel = config.UnlockPolicyPanel;
                    configCopy.CreateBuildingDuplicates = config.CreateBuildingDuplicates;
                    configCopy.ThemeValidityWarning = config.ThemeValidityWarning;

                    foreach (var theme in config.themes)
                    {
                        var newTheme = new Theme(theme.name);

                        foreach (var building in theme.buildings.Where(building =>
                            // a user-added building has to be included, or we don't need it in the config
                            (building.builtInBuilding == null && building.include)

                            // a built-in building that was modified by the user: Only add it to the config if the modification differs
                            || (building.builtInBuilding != null && !building.Equals(building.builtInBuilding))))
                        {
                            newTheme.buildings.Add(building);
                        }

                        if (!theme.isBuiltIn || newTheme.buildings.Count > 0)
                        {
                            configCopy.themes.Add(newTheme);
                        }
                    }

                    xmlSerializer.Serialize(streamWriter, configCopy);
                }
            }
            catch (Exception e)
            {
                Debugger.Log("Couldn't create configuration file at \"" + Directory.GetCurrentDirectory() + "\"");
                throw e;
            }
        }
コード例 #2
0
        public static void Serialize(string filename, Configuration config)
        {
            var xmlSerializer = new XmlSerializer(typeof(Configuration));
            try
            {
                using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(filename))
                {
                    var configCopy = new Configuration();

                    configCopy.UnlockPolicyPanel = config.UnlockPolicyPanel;
                    configCopy.CreateBuildingDuplicates = config.CreateBuildingDuplicates;

                    foreach (var theme in config.themes)
                    {
                        var newTheme = new Theme(theme.name);

                        foreach (var building in theme.buildings.Where(building => !building.isBuiltIn || !building.include))
                        {
                            newTheme.buildings.Add(building);
                        }

                        if (!theme.isBuiltIn || newTheme.buildings.Count > 0)
                        {
                            configCopy.themes.Add(newTheme);
                        }
                    }

                    xmlSerializer.Serialize(streamWriter, configCopy);
                }
            }
            catch (Exception e)
            {
                Debugger.Log("Couldn't create configuration file at \"" + Directory.GetCurrentDirectory() + "\"");
                throw e;
            }
        }