Esempio n. 1
0
        public static string ExtractSection(string s, char[] endChars)
        {
            string _s = "##" + s;

            char[] startCharList = new char[] { '#', '#' };
            return(MiscFunctions.ExtractSection(_s, endChars, startCharList));
        }
Esempio n. 2
0
        private void findCurseCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e != null && e.Error == null && !String.IsNullOrEmpty(e.Result))
            {
                using (StringReader sr = new StringReader(e.Result)) {
                    List <string> results = new List <string>();

                    while (true)
                    {
                        try {
                            string currentline = sr.ReadLine().Trim();
                            if (currentline.Contains("<a href=\"/mc-mods/"))
                            {
                                results.Add(currentline);
                            }
                        }
                        catch {
                            break;
                        }
                    }

                    foreach (string result in results)
                    {
                        char[] startCharList = new char[] { '"', '>' };
                        char[] endCharList   = new char[] { '<' };
                        string foundModname  = MiscFunctions.ExtractSection(result, endCharList, startCharList);

                        if (MiscFunctions.CleanString(foundModname) == MiscFunctions.CleanString(modFileName))
                        {
                            startCharList = new char[] { '=', '"' };
                            endCharList   = new char[] { '"' };
                            string linkSection = MiscFunctions.ExtractSection(result, endCharList, startCharList);
                            website = ParseCurseUri("http://minecraft.curseforge.com" + linkSection);
                            break;
                        }
                    }
                }

                UpdateModValues();
                FindWebsiteUri(); //debug
                return;           //debug

                if (siteMode == "NONE")
                {
                    FindWebsiteUri();
                }
                else
                {
                    progress   = 0;
                    findMode   = 0;
                    findQueued = false;
                    findBusy   = false;
                    updateList = true;
                }
            }
            else
            {
                FindWebsiteUri();
            }
        }
Esempio n. 3
0
        private string GetWebsiteFromResults(string webpage, string delim, char[] startChars, char[] endChars)
        {
            List <string> results = new List <string>();

            using (StringReader sr = new StringReader(webpage)) {
                string currentLine = "";
                while (true)
                {
                    currentLine = sr.ReadLine();

                    if (currentLine != null)
                    {
                        if (currentLine.Contains(delim))
                        {
                            string[] delims = new string[] { delim };
                            results.AddRange(currentLine.Split(delims, StringSplitOptions.RemoveEmptyEntries));
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                string curseLink = "NONE";
                string forumLink = "NONE";

                for (int i = 1; i < results.Count; i++)
                {
                    results[i] = MiscFunctions.ExtractSection(results[i], endChars, startChars).Replace("%2f", "/").Replace("%3a", ":");

                    char[] startCharList = new char[] { 'm', 'o', 'd', 's', '/' };
                    char[] endCharList   = new char[] { };
                    string foundModname  = MiscFunctions.ExtractSection(results[i], endCharList, startCharList);

                    if (curseLink == "NONE" && results[i].Contains(curseIdentifier) && MiscFunctions.PartialMatch(modFileName, foundModname))
                    {
                        curseLink = ParseCurseUri(results[i]);
                    }
                    if (forumLink == "NONE" && results[i].Contains(forumIdentifier) && MiscFunctions.PartialMatch(modFileName, foundModname))
                    {
                        forumLink = ParseForumUri(results[i]);
                    }
                }

                if (curseLink != "NONE")
                {
                    return(curseLink);
                }
                else
                {
                    return(forumLink);
                }
            }
        }
Esempio n. 4
0
        public void UpdateModValues()
        {
            cd = Directory.GetCurrentDirectory();

            //Manage local version
            versionLocal = MiscFunctions.RemoveLetters(modFileName);

            //Determine site mode
            if (website == "")
            {
                website = "NONE";
            }

            if (website.Contains(curseIdentifier))
            {
                siteMode = "curse";
                website  = ParseCurseUri(website);
            }
            else if (website.Contains(forumIdentifier))
            {
                siteMode = "forum";
                website  = ParseForumUri(website);
            }
            else if (website.Contains(githubIdentifier))
            {
                siteMode = "github";
                website  = ParseGithubUri(website);
            }
            else
            {
                siteMode = "NONE";
            }

            //Manage download site
            if (siteMode == "curse")
            {
                char[] startCharList = new char[] { 'f', 'i', 'l', 'e', 's', '/' };
                char[] endCharList   = new char[] { '\"' };
                string modBit        = MiscFunctions.ExtractSection(versionLatestRaw, endCharList, startCharList);

                dlSite = website + "/files/" + modBit + "/download";
            }

            else if (siteMode == "github")
            {
                string bit       = website.Replace("https://github.com", "").Replace("/latest", "/download");
                string appendage = versionLatestRaw.Replace("<a href=\"", "").Replace(bit, "").Replace("\" rel=\"nofollow\">", "");
                dlSite = website.Replace("/latest", "/download") + appendage;
            }

            else
            {
                dlSite = "NONE";
            }
        }
Esempio n. 5
0
        private void findLuckyCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e != null && e.Error == null && !String.IsNullOrEmpty(e.Result))
            {
                using (StringReader sr = new StringReader(e.Result)) {
                    try {
                        string currentline = "";
                        while (!currentline.Contains("<a href=\"/mc-mods/"))
                        {
                            currentline = sr.ReadLine().Trim();
                        }

                        char[] startCharList = new char[] { '=', '"' };
                        char[] endCharList   = new char[] { '"' };
                        string linkSection   = MiscFunctions.ExtractSection(currentline, endCharList, startCharList);

                        startCharList = new char[] { '"', '>' };
                        endCharList   = new char[] { '<' };
                        string foundModname = MiscFunctions.ExtractSection(currentline, endCharList, startCharList);

                        if (!MiscFunctions.PartialMatch(modFileName, foundModname))
                        {
                            website = "No Patial Match: "; //debug
                        }
                        website += ParseCurseUri("http://minecraft.curseforge.com" + linkSection);
                    }
                    catch {
                        website = "NONE";
                    }
                }

                UpdateModValues();
                FindWebsiteUri(); //debug
                return;           //debug

                if (siteMode == "NONE")
                {
                    FindWebsiteUri();
                }
                else
                {
                    progress   = 0;
                    findMode   = 0;
                    findQueued = false;
                    findBusy   = false;
                    updateList = true;
                }
            }
            else
            {
                FindWebsiteUri();
            }
        }
Esempio n. 6
0
        private string ParseForumUri(string uri)
        {
            if (!uri.Contains(forumIdentifier) || uri == "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods")
            {
                uri = "NONE";
            }

            if (uri.Contains("?page="))
            {
                char[] endCharList = new char[] { '?' };
                uri = MiscFunctions.ExtractSection(uri, endCharList);
            }

            return(uri);
        }
Esempio n. 7
0
        private string ParseCurseUri(string uri)
        {
            if (!uri.Contains(curseIdentifier) || uri == "http://minecraft.curseforge.com/mc-mods/minecraft")
            {
                uri = "NONE";
            }

            if (uri.EndsWith("/files"))
            {
                uri = uri.Replace("/files", "");
            }
            else if (uri.Contains("/files/"))
            {
                char[] startCharList = new char[] { 'f', 'i', 'l', 'e', 's', '/' };
                char[] endCharList   = new char[] { };
                string garbage       = "/files/" + MiscFunctions.ExtractSection(uri, endCharList, startCharList);
                uri = uri.Replace(garbage, "");
            }

            return(uri);
        }
Esempio n. 8
0
        private void checkDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e != null && e.Error == null && !String.IsNullOrEmpty(e.Result))
            {
                progress = 100;
                using (StringReader sr = new StringReader(e.Result)) {
                    string newVersion = "";
                    string newFile    = "";
                    releaseDate      = "N/A";
                    versionLatestRaw = "N/A";
                    versionLatest    = "N/A";
                    newFileName      = "";

                    if (siteMode == "curse")
                    {
                        while (true)
                        {
                            while (!newVersion.Contains("<h4 class=\"e-sidebar-subheader overflow-tip\">Minecraft"))
                            {
                                newVersion = sr.ReadLine();
                                if (newVersion == null)
                                {
                                    versionLatest = "MC version not found";
                                    progress      = 0;
                                    checkQueued   = false;
                                    checkBusy     = false;
                                    updateList    = true;
                                    return;
                                }
                                newVersion = newVersion.Trim();
                            }

                            char[] startCharList = new char[] { '>', 'm', 'i', 'n', 'e', 'c', 'r', 'a', 'f', 't' };
                            char[] endCharList   = new char[] { '<' };
                            string siteVersion   = MiscFunctions.ExtractSection(newVersion.ToLower(), endCharList, startCharList).Trim();

                            string thisVersion = "";
                            try {
                                char[] delim = new char[] { '.' };
                                thisVersion = mcVersion.Split(delim)[0] + "." + mcVersion.Split(delim)[1];
                            }
                            catch { }

                            if (siteVersion == thisVersion)
                            {
                                while (!newVersion.Contains("<a class=\"overflow-tip\" href=\"/projects/"))
                                {
                                    newVersion = sr.ReadLine().Trim();
                                }

                                startCharList = new char[] { '>' };
                                endCharList   = new char[] { '<' };
                                newFile       = MiscFunctions.ExtractSection(newVersion, endCharList, startCharList).Replace(" ", "").ToLower().Replace("&#x27;", "").Replace("+", "");

                                string[] modNames = new string[] { "reliquary", "carpentersblocks", "hardcoreenderexpansion" };
                                foreach (string mod in modNames)
                                {
                                    if (MiscFunctions.CleanString(website).Contains(mod) && !MiscFunctions.CleanString(newFile).Contains(mod))
                                    {
                                        newFile = mod + "-" + newFile;
                                    }
                                }

                                string dateLine = sr.ReadLine().Trim();
                                startCharList = new char[] { '"', '>' };
                                endCharList   = new char[] { '<' };
                                releaseDate   = MiscFunctions.ExtractSection(dateLine, endCharList, startCharList);
                                break;
                            }
                            else
                            {
                                newVersion = sr.ReadLine().Trim();
                            }
                        }
                    }

                    if (siteMode == "forum")
                    {
                        while (!newVersion.Contains("<title>"))
                        {
                            newVersion = sr.ReadLine().Trim();
                        }
                        newFile = "undefined-" + MiscFunctions.RemoveLetters(newVersion);
                    }

                    if (siteMode == "github")
                    {
                        while (!newVersion.Contains("<a href=\"" + website.Replace("https://github.com", "").Replace("/latest", "/download/")))
                        {
                            newVersion = sr.ReadLine().Trim();
                        }

                        char[] startCharList = new char[] { '/' };
                        char[] endCharList   = new char[] { '"' };
                        newFile = MiscFunctions.ExtractSection(newVersion, endCharList, startCharList).Replace(" ", "").ToLower();
                    }

                    if (!newFile.Contains(".zip") && !newFile.Contains(".jar"))
                    {
                        newFile += ".jar";
                    }
                    if (disabled && !newFile.Contains(".disabled"))
                    {
                        newFile += ".disabled";
                    }

                    versionLatestRaw = newVersion;
                    newFileName      = Path.GetFileName(newFile);
                    versionLatest    = MiscFunctions.RemoveLetters(newFileName);

                    if (versionLatestRaw != versionLocalRaw)
                    {
                        canUpdate = true;
                    }
                    else
                    {
                        canUpdate = false;
                    }
                }

                UpdateModValues();
                progress    = 0;
                checkQueued = false;
                checkBusy   = false;
                updateList  = true;
            }
            else
            {
                progress    = 0;
                checkQueued = false;
                checkBusy   = false;
            }
        }