예제 #1
0
 public void Remove(LegacyIniFile f, string section, string key)
 {
     if (Exists(f, section, key))
     {
         GetIniData(f)[section].RemoveKey(key);
     }
 }
예제 #2
0
        /*
         *********************************************************************************************************************************************
         * Fixes for invalid *.ini files:
         ********************************************************************************************************************************************
         */

        protected void MergeLists(LegacyIniFile f, string section, string key)
        {
            string list  = "";
            bool   found = false;
            int    i     = -1;
            IEnumerable <string> lines = File.ReadLines(GetIniPath(f));

            foreach (string line in lines)
            {
                if (line.TrimStart().ToLower().StartsWith(key.ToLower()))
                {
                    i = line.IndexOf("=");
                    if (i > -1)
                    {
                        found = true;
                        list += ", " + line.Substring(i + 1);
                    }
                }
            }
            list = string.Join <string>(",",
                                        list.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                        .Select(s => s.Trim()).Distinct().ToArray()
                                        ).Trim(',').Replace(",,", ",");
            if (found)
            {
                Set(f, section, key, list);
            }
        }
예제 #3
0
        public string GetString(LegacyIniFile f, string section, string key)
        {
            string value = GetIniData(f)[section][key];

            if (value == null)
            {
                throw new KeyNotFoundException($"Couldn't find [{section}] {key} in {GetIniName(f)}");
            }
            return(value);
        }
예제 #4
0
        public void Set(LegacyIniFile f, string section, string key, string value)
        {
            GetIniData(f)[section][key] = value;

            // There's a nasty problem, that bugs me:
            // When you set some value ONLY in Prefs, but the value was also set in Custom by the user,
            // then the value in Custom will overshadow Prefs, when GetString is called.
            // Of course people start to report that their values are reset. Who can blame them?
            // Soooo, we are going to set the same value in Custom if IniFile f is something else but Custom. Great? Great.
            if (fixCustomIniDuplicateValues && (f == LegacyIniFile.F76 || f == LegacyIniFile.F76Prefs) && Exists(LegacyIniFile.F76Custom, section, key))
            {
                this.fo76CustomData[section][key] = value;
            }
        }
예제 #5
0
        public string GetIniPath(LegacyIniFile iniFile, GameEdition edition)
        {
            switch (iniFile)
            {
            case LegacyIniFile.F76:
            case LegacyIniFile.F76Prefs:
            case LegacyIniFile.F76Custom:
                return(Path.Combine(this.iniParentPath, GetIniName(iniFile, edition)));

            case LegacyIniFile.Config:
                return(this.configPath);
            }
            return(null);
        }
예제 #6
0
        protected IniData GetIniData(LegacyIniFile iniFile)
        {
            switch (iniFile)
            {
            case LegacyIniFile.F76:
                return(this.fo76Data);

            case LegacyIniFile.F76Prefs:
                return(this.fo76PrefsData);

            case LegacyIniFile.F76Custom:
                return(this.fo76CustomData);

            case LegacyIniFile.Config:
                return(this.configData);
            }
            return(null);
        }
예제 #7
0
        public string GetIniName(LegacyIniFile iniFile, GameEdition edition = GameEdition.Unknown)
        {
            if (edition == GameEdition.Unknown)
            {
                edition = Shared.GameEdition;
            }
            bool msstore = edition == GameEdition.MSStore;

            switch (iniFile)
            {
            case LegacyIniFile.F76:
                return(msstore ? "Project76.ini" : "Fallout76.ini");

            case LegacyIniFile.F76Prefs:
                return(msstore ? "Project76Prefs.ini" : "Fallout76Prefs.ini");

            case LegacyIniFile.F76Custom:
                return(msstore ? "Project76Custom.ini" : "Fallout76Custom.ini");

            default:
                throw new NotSupportedException("Ini name unknown");
            }
        }
예제 #8
0
 public int GetInt(LegacyIniFile f, string section, string key, int defaultValue)
 {
     return(Utils.ToInt(GetString(f, section, key, defaultValue.ToString(enUS))));
 }
예제 #9
0
        /*
         *********************************************************************************************************************************************
         * Other stuff
         ********************************************************************************************************************************************
         */

        public void Merge(LegacyIniFile f, IniData d)
        {
            this.GetIniData(f).Merge(d);
        }
예제 #10
0
        public string GetString(LegacyIniFile f, string section, string key, string defaultValue)
        {
            string value = GetIniData(f)[section][key];

            return(value != null ? value : defaultValue);
        }
예제 #11
0
 public bool GetBool(LegacyIniFile f, string section, string key)
 {
     return(GetString(f, section, key) == "1");
 }
예제 #12
0
 public void Set(LegacyIniFile f, string section, string key, bool value)
 {
     Set(f, section, key, value ? "1" : "0");
 }
예제 #13
0
 public void Set(LegacyIniFile f, string section, string key, double value)
 {
     Set(f, section, key, Utils.ToString(value));
 }
예제 #14
0
 public bool GetBool(LegacyIniFile f, string section, string key, bool defaultValue)
 {
     return(GetString(f, section, key, defaultValue ? "1" : "0") == "1");
 }
예제 #15
0
 public long GetLong(LegacyIniFile f, string section, string key, int defaultValue)
 {
     return(Utils.ToLong(GetString(f, section, key, defaultValue.ToString(enUS))));
 }
예제 #16
0
 public long GetLong(LegacyIniFile f, string section, string key)
 {
     return(Utils.ToLong(GetString(f, section, key)));
 }
예제 #17
0
 public bool Exists(LegacyIniFile f, string section, string key)
 {
     return(GetIniData(f)[section][key] != null);
 }
예제 #18
0
 public int GetInt(LegacyIniFile f, string section, string key)
 {
     return(Utils.ToInt(GetString(f, section, key)));
 }
예제 #19
0
 public float GetFloat(LegacyIniFile f, string section, string key, float defaultValue)
 {
     return(Utils.ToFloat(GetString(f, section, key, defaultValue.ToString(enUS))));
 }
예제 #20
0
 public float GetFloat(LegacyIniFile f, string section, string key)
 {
     return(Utils.ToFloat(GetString(f, section, key)));
 }