示例#1
0
        public void OnSettingsUI(UIHelperBase helper)
        {
            this.InitConfigFile();
            UIHelperBase group = helper.AddGroup(Translation.GetString("Settings"));

            group.AddCheckbox(Translation.GetString("PrioritizeTargetsWithRedSigns"), ModConf.PrioritizeTargetWithRedSigns, delegate(bool isChecked)
            {
                Identity.ModConf.PrioritizeTargetWithRedSigns = isChecked;
                ModConfiguration.Serialize(Identity.configPath, Identity.ModConf);
            });
            group.AddCheckbox(Translation.GetString("MinimizeHearses"), ModConf.MinimizeHearses, delegate(bool isChecked)
            {
                Identity.ModConf.MinimizeHearses = isChecked;
                ModConfiguration.Serialize(Identity.configPath, Identity.ModConf);
            });
        }
        public static ModConfiguration Deserialize(string filename)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ModConfiguration));

            try
            {
                using (StreamReader streamReader = new StreamReader(filename))
                {
                    ModConfiguration modConfiguration = (ModConfiguration)xmlSerializer.Deserialize(streamReader);
                    return(modConfiguration);
                }
            }
            catch
            {
            }
            return(null);
        }
        public static bool Serialize(string filename, ModConfiguration config)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ModConfiguration));

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(filename))
                {
                    xmlSerializer.Serialize(streamWriter, config);
                    return(true);
                }
            }
            catch
            {
            }
            return(false);
        }
示例#4
0
 private void InitConfigFile()
 {
     try
     {
         string pathName = GameSettings.FindSettingsFileByName("gameSettings").pathName;
         string str      = "";
         if (pathName != "")
         {
             str = Path.GetDirectoryName(pathName) + Path.DirectorySeparatorChar;
         }
         Identity.configPath = str + SETTINGFILENAME;
         Identity.ModConf    = ModConfiguration.Deserialize(Identity.configPath);
         if (Identity.ModConf == null)
         {
             Identity.ModConf = ModConfiguration.Deserialize(SETTINGFILENAME);
             if (Identity.ModConf != null && ModConfiguration.Serialize(str + SETTINGFILENAME, Identity.ModConf))
             {
                 try
                 {
                     File.Delete(SETTINGFILENAME);
                 }
                 catch
                 {
                 }
             }
         }
         if (Identity.ModConf == null)
         {
             Identity.ModConf = new ModConfiguration();
             if (!ModConfiguration.Serialize(Identity.configPath, Identity.ModConf))
             {
                 Identity.configPath = SETTINGFILENAME;
                 ModConfiguration.Serialize(Identity.configPath, Identity.ModConf);
             }
         }
     }
     catch
     {
     }
 }