Пример #1
0
        /// <summary>
        /// Fetches update file size.
        /// </summary>
        /// <param name="uriPath"></param>
        /// <returns></returns>
        private static string GetFileSize()
        {
            var webRequest = HttpWebRequest.Create(UpdateData.DownloadURL);

            webRequest.Method = "HEAD";

            try
            {
                using (var webResponse = webRequest.GetResponse())
                {
                    var fileSize           = webResponse.Headers.Get("Content-Length");
                    var fileSizeInMegaByte = Math.Round(Convert.ToDouble(fileSize) / 1024.0 / 1024.0, 2);
                    return(fileSizeInMegaByte + " MB");
                }
            }
            catch (WebException ex)
            {
                ConsoleWrapper.PrintMessage("Could not fetch update filesize from the server. Try again later. ERROR CODE: " + ex.Message, ConsoleWrapper.PrintStatus.Error);
            }

            return("");
        }
Пример #2
0
        static void Main(string[] args)
        {
            string broadCastMsg = GetFileViaHttpString("https://vanilla-remastered.com/files/broad.cast");

            ConsoleWrapper.PrintAsciiSignature();

            Console.WriteLine(broadCastMsg);

            ConsoleWrapper.PrintMessage("Starting GTA Client updater ...", ConsoleWrapper.PrintStatus.Normal);

            if (!isWorkSpaceValid())
            {
                ConsoleWrapper.PrintMessage("Updater is not placed in the right directory. \n" +
                                            "Updater can't find 'VanillaUpdater.exe' in the current directory. Stopping ...", ConsoleWrapper.PrintStatus.Error);
                Console.ReadKey();
                return;
            }

            ConsoleWrapper.PrintMessage("Fetching application data ...", ConsoleWrapper.PrintStatus.Normal);
            Console.WriteLine("--------------");

            if (isNewVersionAvailable())
            {
                ConsoleWrapper.PrintMessage("New version is available for installation! ", ConsoleWrapper.PrintStatus.GreenNotif);
                ListChanges();

                if (UpdateData.IsManditory)
                {
                    ConsoleWrapper.PrintMessage("This update is manditory!", ConsoleWrapper.PrintStatus.Warning);

                    ConsoleWrapper.PrintMessage("Installing the update ... ", ConsoleWrapper.PrintStatus.Normal);

                    DownloadUpdate();
                    InstallUpdate();
                    CleanupUpdate();
                    DisplayFinishedUI();

                    return;
                }

                if (IsClientRunning())
                {
                    ConsoleWrapper.PrintMessage("You first must close the client before updating.", ConsoleWrapper.PrintStatus.Error);
                    return;
                }

                var fileSize = GetFileSize();

                if (fileSize == "")
                {
                    Console.ReadKey();
                }

                Console.Write("\nFile contains " + fileSize +
                              "\nAre you ready to update now? [Y/N]?");

                var key = Console.ReadKey(false).Key;

                if (key.Equals(ConsoleKey.N))
                {
                    return;
                }

                if (key.Equals(ConsoleKey.Y))
                {
                    ConsoleWrapper.PrintMessage("\nDownloading the update ... ", ConsoleWrapper.PrintStatus.Normal);
                    DownloadUpdate();

                    if (IsClientRunning())
                    {
                        ConsoleWrapper.PrintMessage("You first must close the client before updating.", ConsoleWrapper.PrintStatus.Error);
                        Console.ReadKey();
                        return;
                    }

                    ConsoleWrapper.PrintMessage("Installing the update ... ", ConsoleWrapper.PrintStatus.Normal);
                    InstallUpdate();

                    ConsoleWrapper.PrintMessage("Cleaning up ... ", ConsoleWrapper.PrintStatus.Normal);
                    CleanupUpdate();

                    DisplayFinishedUI();
                    Console.ReadKey();
                    return;
                }
            }

            else
            {
                ConsoleWrapper.PrintMessage("No update available. You're up to date. ", ConsoleWrapper.PrintStatus.Normal);
            }

            Console.ReadKey();
        }