private static void GetBoolValue(IniSection section, string sectionName, ref bool result, bool defaultResult) { bool? res = null; string value = section.GetValue(sectionName); if (value != null) res = TryParseBool(value); result = res ?? defaultResult; }
private static void GetStringValue(Options options, IniSection section, out string key, string name, string value) { if (string.IsNullOrWhiteSpace(value)) { MessageBox.Show(string.Format("Section [{0}] is missing value '{1}'.", section.Name, name), "Error in options.ini!"); Environment.Exit(1); } key = value; }
public static Options Load(string path) { Options options = new Options(); IniReader reader = new IniReader(FileName); IniSection section = reader.GetSectionByName("stream"); if (section == null) { throw new InvalidOperationException("Options file missing [Stream] section."); } GetStringValue(options, section, out options.m_stream, "stream", section.GetValue("stream")); GetStringValue(options, section, out options.m_twitchName, "twitchname", section.GetValue("twitchname") ?? section.GetValue("user") ?? section.GetValue("username")); GetStringValue(options, section, out options.m_oauthPass, "oauth", section.GetValue("oauth") ?? section.GetValue("pass") ?? section.GetValue("password")); if (!options.m_oauthPass.StartsWith("oauth:")) { throw new FormatException("The 'oauth' field in the [Stream] section must start with 'oauth:'.\n\nThis is not your twitch password, please get your api key from www.twitchapps.com/tmi."); } section = reader.GetSectionByName("grab"); if (section != null) { foreach (string line in section.EnumerateRawStrings()) { options.GrabList.Add(DoReplacements(options, line)); } } section = reader.GetSectionByName("highlight"); if (section != null) { foreach (string line in section.EnumerateRawStrings()) { options.HighlightList.Add(DoReplacements(options, line)); } } section = reader.GetSectionByName("ignoreusers"); if (section != null) { foreach (string line in section.EnumerateRawStrings()) { options.UserIgnoreList.Add(DoReplacements(options, line)); } } section = reader.GetSectionByName("ignoretext"); if (section != null) { foreach (string line in section.EnumerateRawStrings()) { options.TextIgnoreList.Add(DoReplacements(options, line)); } } section = reader.GetSectionByName("settings"); if (section != null) { GetBoolValue(section, "CheckForUpdates", ref options.m_checkUpdates, true); GetBoolValue(section, "PreventDuplicates", ref options.m_preventDuplicates, true); } return(options); }