コード例 #1
0
ファイル: DataModel.cs プロジェクト: kyroskoh/QuestionGrabber
        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;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: DataModel.cs プロジェクト: kyroskoh/QuestionGrabber
        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);
        }