示例#1
0
    protected virtual IEnumerator _RefreshOnline()
    {
        ModOnlineListGroup.Children.Clear();
        SPreloader preloader = new SPreloader();

        ModOnlineListGroup.Children.Add(preloader);
        yield return(null);

        for (int i = 0; i < Repos.Count; i++)
        {
            IEnumerator mods = Repos[i].GetRemoteMods();
            while (mods.MoveNext())
            {
                if (mods.Current == null || !(mods.Current is RemoteMod))
                {
                    yield return(null);

                    continue;
                }

                RemoteMod mod = (RemoteMod)mods.Current;
                ModOnlineListGroup.Children.Add(NewEntry(mod.Name, IconMod));
                yield return(null);
            }
        }

        preloader.Modifiers.Add(new SFadeOutShrinkSequence());
    }
示例#2
0
    public override IEnumerator GetRemoteMods()
    {
        if (_CurrentThread != null)
        {
            _Alive = false;
            _CurrentThread.Join();
        }

        _CurrentThread = new Thread(_AsyncGetRemoteMods)
        {
            Name         = "Last Bullet mod repo web async thread",
            IsBackground = true
        };
        _Current = null;
        _Alive   = true;
        _CurrentThread.Start();

        while (_Current != null || (_Alive && _CurrentThread.IsAlive))
        {
            yield return(null);

            if (_Current != null)
            {
                yield return(_Current);

                _Current = null;
            }
        }
    }
示例#3
0
    private void _AsyncGetRemoteMods()
    {
        try {
            string html;
            using (WebClient wc = new WebClient()) {
                Console.WriteLine("Downloading " + URL);
                html = wc.DownloadString(URL);
            }

            int i = -1;
            while ((i = html.IndexOfInvariant(DOWNLOAD_START, i + 1)) > 0 && _Alive)
            {
                string   download = html.Substring(i + DOWNLOAD_START.Length, html.IndexOfInvariant(DOWNLOAD_END, i) - i - DOWNLOAD_START.Length).Trim();
                string[] lines    = download.Split('\n');

                RemoteMod mod = new RemoteMod();

                mod.Name = lines[5].Substring(lines[5].IndexOfInvariant("title=\"") + 7);
                mod.Name = mod.Name.Substring(0, mod.Name.IndexOf('"'));
                mod.Name = _UnescapedAttribute(mod.Name);

                mod.Author = lines[6].Substring(lines[6].LastIndexOfInvariant("\">", lines[6].IndexOfInvariant("</a>")) + 2);
                mod.Author = mod.Author.Substring(0, mod.Author.IndexOfInvariant("</a>"));

                mod.URL = lines[2].Substring(lines[2].IndexOfInvariant("<a href=\"") + 9);
                mod.URL = mod.URL.Substring(0, mod.URL.IndexOf('"'));
                mod.URL = _UnescapedAttribute(mod.URL);

                Console.WriteLine($"Found mod: \"{mod.Name}\" by {mod.Author}");
                _Current = mod;
                while (_Current != null && _Alive)
                {
                    Thread.Sleep(16);
                }
            }
        } catch (Exception e) {
            _Current = new RemoteMod {
                Name = e.ToString()
            };
            Console.WriteLine(e);
        }

        _Alive = false;
    }