public void Remove(LegacyIniFile f, string section, string key) { if (Exists(f, section, key)) { GetIniData(f)[section].RemoveKey(key); } }
/* ********************************************************************************************************************************************* * 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); } }
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); }
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; } }
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); }
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); }
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"); } }
public int GetInt(LegacyIniFile f, string section, string key, int defaultValue) { return(Utils.ToInt(GetString(f, section, key, defaultValue.ToString(enUS)))); }
/* ********************************************************************************************************************************************* * Other stuff ******************************************************************************************************************************************** */ public void Merge(LegacyIniFile f, IniData d) { this.GetIniData(f).Merge(d); }
public string GetString(LegacyIniFile f, string section, string key, string defaultValue) { string value = GetIniData(f)[section][key]; return(value != null ? value : defaultValue); }
public bool GetBool(LegacyIniFile f, string section, string key) { return(GetString(f, section, key) == "1"); }
public void Set(LegacyIniFile f, string section, string key, bool value) { Set(f, section, key, value ? "1" : "0"); }
public void Set(LegacyIniFile f, string section, string key, double value) { Set(f, section, key, Utils.ToString(value)); }
public bool GetBool(LegacyIniFile f, string section, string key, bool defaultValue) { return(GetString(f, section, key, defaultValue ? "1" : "0") == "1"); }
public long GetLong(LegacyIniFile f, string section, string key, int defaultValue) { return(Utils.ToLong(GetString(f, section, key, defaultValue.ToString(enUS)))); }
public long GetLong(LegacyIniFile f, string section, string key) { return(Utils.ToLong(GetString(f, section, key))); }
public bool Exists(LegacyIniFile f, string section, string key) { return(GetIniData(f)[section][key] != null); }
public int GetInt(LegacyIniFile f, string section, string key) { return(Utils.ToInt(GetString(f, section, key))); }
public float GetFloat(LegacyIniFile f, string section, string key, float defaultValue) { return(Utils.ToFloat(GetString(f, section, key, defaultValue.ToString(enUS)))); }
public float GetFloat(LegacyIniFile f, string section, string key) { return(Utils.ToFloat(GetString(f, section, key))); }