Пример #1
0
        private void findKerbstuffCompleted(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=\"/mod/"))
                            {
                                results.Add(currentline);
                            }
                        }
                        catch
                        {
                            break;
                        }
                    }

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

                        if (MiscFunctions.PartialMatch(modName, linkSection))
                        {
                            website = ParseKerbstuffUri("https://kerbalstuff.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();
            }
        }
Пример #2
0
        public static string ExtractSection(string s, char[] endChars)
        {
            string _s = "##" + s;

            char[] startCharList = new char[] { '#', '#' };
            return(MiscFunctions.ExtractSection(_s, endChars, startCharList));
        }
Пример #3
0
        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]);
                    }
                }
            }
        }
Пример #4
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);
        }
Пример #5
0
        public void DeinstallMod(string modKey)
        {
//            for (int i = 0; i < files.Count; i++)
//            {
//                if (files[i].RemoveMod(modKey))
//                {
//                    files.RemoveAt(i);
//                    i--;
//                }
//            }

            foreach (FileInfo file in GetInstalledMod(modKey).GetTamperedFiles())
            {
                if (file.RemoveMod(modKey))
                {
                    files.Remove(file);
                }
            }

            for (int i = 0; i < installedMods.Count; i++)
            {
                if (installedMods[i].modKey == modKey)
                {
                    installedMods.RemoveAt(i);
                    i--;
                }
            }

            if (Directory.Exists(kmmFolder + "\\Overrides"))
            {
                foreach (string folder in Directory.GetDirectories(kmmFolder + "\\Overrides"))
                {
                    if (folder.ToLower().EndsWith(modKey))
                    {
                        Directory.Delete(folder, true);
                    }
                }
                MiscFunctions.ProcessDirectory(kmmFolder + "\\Overrides", true);
            }

            MiscFunctions.ProcessDirectory(kspFolder + "\\GameData", false);
        }
Пример #6
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);
        }
Пример #7
0
        public void InstallMod()
        {
            installBusy = true;

            // Extract
            string extractLocation = Main.acces.kspFolder.kmmFolder + "\\temp\\" + windowsModName;

            if (Directory.Exists(extractLocation))
            {
                Directory.Delete(extractLocation, true);
            }

            try
            {
                ZipFile.ExtractToDirectory(modFolder + "\\" + currentFileName, extractLocation);
            }
            catch
            {
                Directory.Delete(extractLocation, true);
                MiscFunctions.ProcessDirectory(Main.acces.kspFolder.kmmFolder + "\\temp", true);
                installQueued = false;
                installBusy   = false;
                return;
            }

            // Find GameData folder
            string copyRoot = "";

            foreach (string folder1 in Directory.GetDirectories(extractLocation))
            {
                if (folder1.ToLower().EndsWith("gamedata"))
                {
                    copyRoot = extractLocation;
                    break;
                }
                else if (copyRoot == "")
                {
                    foreach (string folder2 in Directory.GetDirectories(folder1))
                    {
                        if (folder2.ToLower().EndsWith("gamedata"))
                        {
                            copyRoot = folder1;
                            break;
                        }
                    }
                }
            }

            // Create file list
            List <string> relFiles = new List <string>();
            List <string> absFiles = new List <string>();

            if (copyRoot == "")
            {
                foreach (string file in Directory.GetFiles(extractLocation, "*.*", SearchOption.AllDirectories))
                {
                    relFiles.Add("GameData\\" + file.Replace(extractLocation + "\\", ""));
                    absFiles.Add(file);
                }
            }
            else
            {
                foreach (string file in Directory.GetFiles(copyRoot, "*.*", SearchOption.AllDirectories))
                {
                    relFiles.Add(file.Replace(copyRoot + "\\", ""));
                    absFiles.Add(file);
                }
            }

            // Remove Duplicate ModuleManager
            if (modKey == "modulemanagerv")
            {
                Main.acces.kspFolder.DeleteModuleManager();
            }

            // Copy files
            for (int i = 0; i < relFiles.Count; i++)
            {
                relFiles[i] = relFiles[i].Replace("Gamedata\\", "GameData\\").Replace("gamedata\\", "GameData\\");
                if (Path.GetExtension(relFiles[i]) == ".cs" || !relFiles[i].StartsWith("GameData\\"))
                {
                    relFiles.RemoveAt(i);
                    absFiles.RemoveAt(i);
                    i--;
                    continue;
                }

                string newPath = Main.acces.kspFolder.kspFolder + "\\" + relFiles[i];
                Directory.CreateDirectory(Path.GetDirectoryName(newPath));

                if (File.Exists(newPath))
                {
                    Main.acces.kspFolder.OverwriteFile(relFiles[i], modKey, modName);
                }
                else
                {
                    Main.acces.kspFolder.AddFile(relFiles[i], modKey, modName);
                }

                File.Move(absFiles[i], newPath);
            }

            // Finalise
            Main.acces.kspFolder.AddMod(this);
            Main.acces.kspFolder.SaveInstance();

            if (Directory.Exists(extractLocation))
            {
                Directory.Delete(extractLocation, true);
            }
            MiscFunctions.ProcessDirectory(Main.acces.kspFolder.kmmFolder + "\\temp", true);

            // Done
            UpdateModValues();
            installQueued = false;
            installBusy   = false;
            updateList    = true;
        }
Пример #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 = "";
                    releaseDate          = "N/A";
                    versionLatestRaw     = "N/A";
                    versionLatestNumeric = "N/A";

                    if (siteMode == "kerbstuff")
                    {
                        while (!newVersion.Contains("<h2>Version"))
                        {
                            newVersion = sr.ReadLine().Trim();
                        }

                        char[] endCharList = new char[] { '<' };
                        versionLatestNumeric = MiscFunctions.ExtractSection(newVersion.Replace("<h2>Version", "").Trim(), endCharList).Trim();

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

                    if (siteMode == "curse")
                    {
                        while (!newVersion.Contains("<a class=\"overflow-tip\" href=\"/ksp-mods/"))
                        {
                            newVersion = sr.ReadLine().Trim();
                        }

                        char[] startCharList = new char[] { '"', '>' };
                        char[] endCharList   = new char[] { '<' };
                        versionLatestNumeric = MiscFunctions.RemoveLetters(MiscFunctions.ExtractSection(newVersion, endCharList, startCharList));

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

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

                    if (siteMode == "github")
                    {
                        string identiefier = "<a href=\"" + website.Replace("https://github.com", "").Replace("/latest", "/download/");

                        while (!newVersion.Contains(identiefier))
                        {
                            newVersion = sr.ReadLine().Trim();
                        }

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

                    versionLatestRaw = newVersion;

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

                UpdateModValues();
                progress    = 0;
                checkQueued = false;
                checkBusy   = false;
                updateList  = true;
            }
            else
            {
                progress    = 0;
                checkQueued = false;
                checkBusy   = false;
            }
        }
Пример #9
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 kerbstuffLink = "NONE";
                string curseLink     = "NONE";
                string gitLink       = "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 (kerbstuffLink == "NONE" && results[i].Contains(kerbstuffIdentifier) && MiscFunctions.PartialMatch(modName, results[i]))
                    {
                        kerbstuffLink = ParseKerbstuffUri(results[i]);
                    }
                    if (curseLink == "NONE" && results[i].Contains(curseIdentifier) && MiscFunctions.PartialMatch(modName, results[i]))
                    {
                        curseLink = ParseCurseUri(results[i]);
                    }
                    if (gitLink == "NONE" && results[i].Contains(githubIdentifier) && results.Contains("/releases/latest"))
                    {
                        gitLink = ParseGithubUri(results[i]);
                    }
                    if (forumLink == "NONE" && results[i].Contains(forumIdentifier) && MiscFunctions.PartialMatch(modName, results[i]))
                    {
                        forumLink = ParseForumUri(results[i]);
                    }
                }

                if (kerbstuffLink != "NONE")
                {
                    return(kerbstuffLink);
                }
                else if (curseLink != "NONE")
                {
                    return(curseLink);
                }
                else if (gitLink != "NONE")
                {
                    return(gitLink);
                }
                else
                {
                    return(forumLink);
                }
            }
        }
Пример #10
0
        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";
                }
            }
        }
Пример #11
0
 public ModInfo(string fileName)
 {
     currentFileName = fileName;
     modName         = MiscFunctions.CleanString(fileName);
     modKey          = modName;
 }