Example #1
0
        public static async Task <bool> Execute()
        {
            await CleanupOldFiles();

            var isLatest = await IsLatest();

            SystemSounds.Asterisk.Play();

            string         zipName          = $"PokemonGoGUI.zip";
            var            downloadLink     = $"{RemoteReleaseUrl}{RemoteVersion}/{zipName}";
            var            baseDir          = Directory.GetCurrentDirectory();
            var            downloadFilePath = Path.Combine(baseDir, zipName);
            var            tempPath         = Path.Combine(baseDir, "tmp");
            var            extractedDir     = Path.Combine(tempPath, "Goman");
            var            destinationDir   = baseDir + Path.DirectorySeparatorChar;
            bool           updated          = false;
            AutoUpdateForm autoUpdateForm   = new AutoUpdateForm()
            {
                DownloadLink   = downloadLink,
                ChangelogLink  = ChangelogUri,
                Destination    = downloadFilePath,
                AutoUpdate     = true,
                CurrentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                LatestVersion  = $"{RemoteVersion}"
            };

            updated = (autoUpdateForm.ShowDialog() == DialogResult.OK);


            if (!updated)
            {
                //Logger.Write("Update Skipped", LogLevel.Update);
                return(false);
            }

            if (!UnpackFile(downloadFilePath, extractedDir))
            {
                return(false);
            }

            if (!MoveAllFiles(extractedDir, destinationDir))
            {
                return(false);
            }

            Process.Start(Assembly.GetEntryAssembly().Location);
            Environment.Exit(-1);
            return(true);
        }
Example #2
0
        public async Task <IState> Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await CleanupOldFiles().ConfigureAwait(false);

            if (!session.LogicSettings.CheckForUpdates)
            {
                session.EventDispatcher.Send(new UpdateEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.CheckForUpdatesDisabled,
                                                                 Assembly.GetExecutingAssembly().GetName().Version.ToString(3))
                });

                return(new LoginState());
            }

            var autoUpdate = session.LogicSettings.AutoUpdate;
            var isLatest   = await IsLatest().ConfigureAwait(false);

            if (isLatest)
            {
                session.EventDispatcher.Send(new UpdateEvent
                {
                    Message =
                        session.Translation.GetTranslation(TranslationString.GotUpToDateVersion, Assembly.GetExecutingAssembly().GetName().Version.ToString(4))
                });
                return(new LoginState());
            }

            SystemSounds.Asterisk.Play();

            var remoteReleaseUrl =
                $"https://github.com/Necrobot-Private/NecroBot/releases/download/v{RemoteVersion}/";
            string zipName = "NecroBot2.Console.zip";

            if (Assembly.GetEntryAssembly().FullName.ToLower().Contains("necrobot2.win"))
            {
                zipName = "NecroBot2.Win.zip";
            }
            var downloadLink = remoteReleaseUrl + zipName;

            var            baseDir          = Directory.GetCurrentDirectory();
            var            downloadFilePath = Path.Combine(baseDir, zipName);
            var            tempPath         = Path.Combine(baseDir, "tmp");
            var            extractedDir     = Path.Combine(tempPath, "NecroBot2");
            var            destinationDir   = baseDir + Path.DirectorySeparatorChar;
            bool           updated          = false;
            AutoUpdateForm autoUpdateForm   = new AutoUpdateForm()
            {
                Session        = session,
                DownloadLink   = downloadLink,
                Destination    = downloadFilePath,
                AutoUpdate     = true,
                CurrentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                LatestVersion  = $"{RemoteVersion}"
            };

            updated = (autoUpdateForm.ShowDialog() == DialogResult.OK);


            if (!updated)
            {
                Logger.Write("Update Skipped", LogLevel.Update);
                return(new LoginState());
            }

            if (!UnpackFile(downloadFilePath, extractedDir))
            {
                return(new LoginState());
            }

            session.EventDispatcher.Send(new UpdateEvent
            {
                Message = session.Translation.GetTranslation(TranslationString.FinishedUnpackingFiles)
            });

            if (!MoveAllFiles(extractedDir, destinationDir))
            {
                return(new LoginState());
            }

            session.EventDispatcher.Send(new UpdateEvent
            {
                Message = session.Translation.GetTranslation(TranslationString.UpdateFinished)
            });

            Process.Start(Assembly.GetEntryAssembly().Location);
            Environment.Exit(-1);
            return(null);
        }