Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 private static string DoReplacements(Options options, string value)
 {
     int i = value.IndexOf("$stream");
     while (i != -1)
     {
         value = value.Replace("$stream", options.Stream);
         i = value.IndexOf("$stream");
     }
     return value;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 4
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"));
            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;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Load the options from the option file
 /// </summary>
 private void LoadOptions()
 {
     try
     {
         m_options = Options.Load("options.ini");
     }
     catch (FileNotFoundException)
     {
         MessageBox.Show("Could not find options.ini!", "Error loading options.ini.");
         Environment.Exit(-1);
     }
     catch (Exception e)
     {
         MessageBox.Show("Error loading options.ini:\n" + e.Message, "Error loading options.ini.");
         Environment.Exit(-1);
     }
 }