예제 #1
0
        public void OnSettingsUI(UIHelperBase helper)
        {
            if (!isActive())
            {
                return;
            }
            this.InitConfigFile();
            UIHelperBase group = helper.AddGroup("Format Settings");
            int          num   = Array.IndexOf <string>(ModInfo.DateFormats, ModInfo.ModConf.DateFormat);

            if (num < 0)
            {
                num = 0;
            }
            group.AddDropdown("Date format", ModInfo.DateFormats, num, delegate(int c)
            {
                ModInfo.ModConf.DateFormat = ModInfo.DateFormats[c];
                ModConfiguration.Serialize(ModInfo.configPath, ModInfo.ModConf);
            });
            int num2 = Array.IndexOf <string>(ModInfo.TimeFormats, ModInfo.ModConf.TimeFormat);

            if (num2 < 0)
            {
                num2 = 0;
            }
            group.AddDropdown("Time format", ModInfo.TimeFormats, num2, delegate(int c)
            {
                ModInfo.ModConf.TimeFormat = ModInfo.TimeFormats[c];
                ModConfiguration.Serialize(ModInfo.configPath, ModInfo.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);
                    if (Array.IndexOf <string>(ModInfo.DateFormats, modConfiguration.DateFormat) < 0)
                    {
                        modConfiguration.DateFormat = ModInfo.DateFormats[0];
                    }
                    if (Array.IndexOf <string>(ModInfo.TimeFormats, modConfiguration.TimeFormat) < 0)
                    {
                        modConfiguration.TimeFormat = ModInfo.TimeFormats[0];
                    }
                    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;
 }
        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);
        }
예제 #5
0
 private void InitConfigFile()
 {
     try
     {
         string pathName = GameSettings.FindSettingsFileByName("gameSettings").pathName;
         string str      = "";
         if (pathName != "")
         {
             str = Path.GetDirectoryName(pathName) + Path.DirectorySeparatorChar;
         }
         ModInfo.configPath = str + SETTINGFILENAME;
         ModInfo.ModConf    = ModConfiguration.Deserialize(ModInfo.configPath);
         if (ModInfo.ModConf == null)
         {
             ModInfo.ModConf = ModConfiguration.Deserialize(SETTINGFILENAME);
             if (ModInfo.ModConf != null && ModConfiguration.Serialize(str + SETTINGFILENAME, ModInfo.ModConf))
             {
                 try
                 {
                     File.Delete(SETTINGFILENAME);
                 }
                 catch
                 {
                 }
             }
         }
         if (ModInfo.ModConf == null)
         {
             ModInfo.ModConf = new ModConfiguration();
             if (!ModConfiguration.Serialize(ModInfo.configPath, ModInfo.ModConf))
             {
                 ModInfo.configPath = SETTINGFILENAME;
                 ModConfiguration.Serialize(ModInfo.configPath, ModInfo.ModConf);
             }
         }
     }
     catch
     {
     }
 }
 private void InitConfigFile()
 {
     try
     {
         string pathName = GameSettings.FindSettingsFileByName("gameSettings").pathName;
         string str = "";
         if (pathName != "")
         {
             str = Path.GetDirectoryName(pathName) + Path.DirectorySeparatorChar;
         }
         ModInfo.configPath = str + SETTINGFILENAME;
         ModInfo.ModConf = ModConfiguration.Deserialize(ModInfo.configPath);
         if (ModInfo.ModConf == null)
         {
             ModInfo.ModConf = ModConfiguration.Deserialize(SETTINGFILENAME);
             if (ModInfo.ModConf != null && ModConfiguration.Serialize(str + SETTINGFILENAME, ModInfo.ModConf))
             {
                 try
                 {
                     File.Delete(SETTINGFILENAME);
                 }
                 catch
                 {
                 }
             }
         }
         if (ModInfo.ModConf == null)
         {
             ModInfo.ModConf = new ModConfiguration();
             if (!ModConfiguration.Serialize(ModInfo.configPath, ModInfo.ModConf))
             {
                 ModInfo.configPath = SETTINGFILENAME;
                 ModConfiguration.Serialize(ModInfo.configPath, ModInfo.ModConf);
             }
         }
     }
     catch
     {
     }
 }