private void InitialiseInstance() { foreach (string file in Directory.GetFiles(kspFolder + "\\GameData", "*.*", SearchOption.AllDirectories)) { string relFile = file.Replace(kspFolder + "\\", ""); bool exists = false; foreach (FileInfo listFile in files) { if (listFile.relativeFilePath == relFile) { exists = true; listFile.kspFolder = kspFolder; break; } } if (!exists) { string modFolder = relFile.Replace("GameData\\", "").Split(new char[] { '\\' })[0]; if (!relFile.Contains("GameData\\") || string.IsNullOrWhiteSpace(modFolder)) { modFolder = "default"; } files.Add(new FileInfo(kspFolder, relFile, MiscFunctions.CleanString(modFolder), modFolder)); } } List <string> modKeys = new List <string>(); foreach (InstalledModInfo mod in installedMods) { modKeys.Add(mod.modKey); } for (int i = 0; i < files.Count; i++) { if (!files[i].FileExists()) { files.RemoveAt(i); i--; continue; } else if (!modKeys.Contains(files[i].currentMod)) { installedMods.Add(new InstalledModInfo(files[i].initValue, files[i].currentMod)); modKeys.Add(files[i].currentMod); } foreach (InstalledModInfo mod in installedMods) { if (mod.modKey == files[i].currentMod || files[i].otherMods.Contains(mod.modKey)) { mod.AddFileRef(files[i]); } } } }
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=\"/ksp-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(currentFileName)) { startCharList = new char[] { '=', '"' }; endCharList = new char[] { '"' }; string linkSection = MiscFunctions.ExtractSection(result, endCharList, startCharList); website = ParseCurseUri("http://kerbal.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(); } }
public void UpdateModValues() { if (!installedOnly) { //Manage local version if (modName == "") { modName = MiscFunctions.CleanString(currentFileName); } versionLocalNumeric = MiscFunctions.RemoveLetters(currentFileName); //Determine site mode if (website == "") { website = "NONE"; } if (website.Contains(kerbstuffIdentifier)) { siteMode = "kerbstuff"; website = ParseKerbstuffUri(website); } else 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[] { 'k', 's', 'p', '-', 'm', 'o', 'd', 's', '/' }; char[] endCharList = new char[] { }; string modBit = MiscFunctions.ExtractSection(website, endCharList, startCharList) + "/"; startCharList = modBit.ToCharArray(); endCharList = new char[] { '"' }; string appendage = MiscFunctions.ExtractSection(versionLatestRaw, endCharList, startCharList); dlSite = website + "/" + appendage; } else if (siteMode == "kerbstuff") { dlSite = website + "/download/" + versionLatestNumeric; } 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"; } } }
public ModInfo(string fileName) { currentFileName = fileName; modName = MiscFunctions.CleanString(fileName); modKey = modName; }