Пример #1
0
        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;
        }
        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"));
            GetStringValue(options, section, out options.m_subscribers, "subscribers", section.GetValue("subscribers"));

            if (Directory.Exists(options.m_subscribers))
                options.m_subscribers = Path.Combine(options.m_subscribers, "subs.txt");

            string fn = options.m_subscribers;
            if (!File.Exists(fn))
            {
                try
                {
                    File.WriteAllText(fn, "");
                    File.Delete(fn);
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Could not write to file {0}.\n\n{1}", fn, e));
                    Environment.Exit(1);
                }
            }

            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;
        }
Пример #3
0
        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);
        }