Esempio n. 1
0
        public static void GetAnnouncement()
        {
            WebHandler web    = new WebHandler();
            string     url    = "https://raw.githubusercontent.com/TDToolbox/BTDToolbox-2019_LiveFIles/master/toolbox%20announcements";
            string     answer = web.WaitOn_URL(url);


            ConsoleHandler.append(answer);
        }
Esempio n. 2
0
        public bool CheckForUpdate(string url, string deleteText, int lineNumber, string currentVersion) //Use this to check for updates
        {
            if (reader == null)
            {
                reader = new WebHandler();
            }

            string processedUrl = reader.processGit_Text(reader.WaitOn_URL(url), deleteText, lineNumber);
            string gitVersion   = reader.Get_GitVersion(processedUrl);

            LatestVersionNumber = gitVersion;

            if (!Guard.IsStringValid(currentVersion))
            {
                return(true);
            }

            if (!Guard.IsStringValid(gitVersion))
            {
                ConsoleHandler.append("Unable to determine latest version");
                return(false);
            }

            int    number         = 0;
            string toolboxVersion = "";

            foreach (char c in currentVersion)
            {
                if (Int32.TryParse(c.ToString(), out number))
                {
                    toolboxVersion = toolboxVersion + c;
                }
            }

            if (Int32.Parse(toolboxVersion) < Int32.Parse(gitVersion))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        private void Download_ModLoader()
        {
            WebHandler web    = new WebHandler();
            WebClient  client = new WebClient();
            string     url    = "https://raw.githubusercontent.com/TDToolbox/BTDToolbox-2019_LiveFIles/master/Version";


            string gitText     = web.WaitOn_URL(url);
            string downloadURL = web.processGit_Text(gitText, "modloader: ", 2);

            client.DownloadFile(downloadURL, "Update");

            if (File.Exists(modloader_zipName))
            {
                File.Delete(modloader_zipName);
            }
            File.Move("Update", modloader_zipName);
            ConsoleHandler.append("Mod Loader successfully downloaded!");
        }
Esempio n. 4
0
        public void DoUpdateTowerPlugin()
        {
            new Thread(() =>
            {
                WebHandler web = new WebHandler();
                string pluginPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\NKHook5\\Plugins\\NewTowerLoader.dll";
                string nkhfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\NKHook5";

                if (!web.CheckForUpdate(versionsURL, "NKHookTowerLoader: ", 4, Serializer.cfg.TowerLoadNKPluginVersion) && File.Exists(pluginPath))
                    return;

                if (File.Exists(pluginPath))
                    File.Delete(pluginPath);

                if (!Directory.Exists(nkhfolder + "\\Plugins"))
                    Directory.CreateDirectory(nkhfolder + "\\Plugins");

                web.DownloadFile("NewTowerLoader.dll", versionsURL, pluginPath, "NKHookTowerLoader: ", 4);
                Serializer.cfg.TowerLoadNKPluginVersion = web.LatestVersionNumber;
                Serializer.SaveSettings();
            }).Start();
        }
Esempio n. 5
0
        /// <summary>
        /// Complete method. Waits on URL then reads and returns text from it
        /// </summary>
        /// <param name="url">url to read text from</param>
        /// <returns>text read off of website</returns>
        public string WaitOn_URL(string url)   //call this one to read the text from the git url
        {
            WebHandler get = new WebHandler();

            get.startURL = url;
            get.TryReadURL_StartThread();

            for (int i = 0; i <= 100; i++)
            {
                GeneralMethods.checkedForExit();
                Thread.Sleep(100);
                if (get.urlAquired)
                {
                    break;
                }
            }

            if (get.readURL == null)
            {
                get.readURL = "";
            }
            return(get.readURL);
        }
Esempio n. 6
0
        public void DoUpdateNKH()
        {
            new Thread(() =>
            {
                WebHandler web = new WebHandler();
                string nkhfolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\NKHook5";
                string savePath = nkhfolder + "\\NKHook5.zip";

                if(!web.CheckForUpdate(versionsURL, "NKHook5: ", 3, Serializer.cfg.NKHookVersion) && Directory.Exists(nkhfolder)
                && File.Exists(nkhfolder + "\\NKHook5.dll") && File.Exists(nkhfolder + "\\NKHook5-CLR.dll"))
                    return;

                if (File.Exists(savePath))
                    File.Delete(savePath);

                if (!Directory.Exists(nkhfolder))
                    Directory.CreateDirectory(nkhfolder);

                web.DownloadFile("NKHook5", versionsURL, savePath, "NKHook5: ", 3);


                string extractPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\NKHook5";
                ZipFile archive = new ZipFile(savePath);
                archive.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently);
                archive.Dispose();

                if (File.Exists(savePath))
                    File.Delete(savePath);

                if (File.Exists(Environment.CurrentDirectory + "\\NKHook5-Injector.exe"))
                    File.Delete(Environment.CurrentDirectory + "\\NKHook5-Injector.exe");

                //File.Copy(nkhEXE, Environment.CurrentDirectory + "\\NKHook5-Injector.exe");
                Serializer.cfg.NKHookVersion = web.LatestVersionNumber;
                Serializer.SaveSettings();
            }).Start();
        }
Esempio n. 7
0
        public static void GetTutorialsList()
        {
            if (tut == null)
            {
                tut = new Tutorials();
            }

            string     url = "https://raw.githubusercontent.com/TDToolbox/BTDToolbox-2019_LiveFIles/master/btd%20modding%20tutorials";
            WebHandler web = new WebHandler();

            new Thread(() =>
            {
                string returnText = web.WaitOn_URL(url);
                if (!Guard.IsStringValid(returnText))
                {
                    if (!File.Exists(tut.tutorialFilePath))
                    {
                        ConsoleHandler.append("Failed to get fresh tutorials list and unable to find the stored list. " +
                                              "If this problem continues please restart BTD Toolbox.");
                        tut = null;
                        return;
                    }
                    ConsoleHandler.append("Failed to get tutorials list. Toolbox will use the stored list instead, please note it may " +
                                          "not be updated. Restart BTD Toolbox if you want to try getting the list again.");
                }
                else
                {
                    ConsoleHandler.append("Aquired tutorials list");
                    tut.CreateTutorialsFile();
                    tut.WriteToTutFile(returnText);
                    ConsoleHandler.append("Finished writing tutorials list to file");
                }
                tut.CreateTutorialsDictionary(tutorials);
                tut.PopulateTutorialsList();
            }).Start();
        }