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"; } }
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("'", "").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; } }