Ejemplo n.º 1
0
        public override async Task <bool> CheckForUpdates()
        {
            if (ClientProfile == null)
            {
                return(false);
            }
            if (ServerProfile == null)
            {
                return(false);
            }

            // Should never hit, earlier logic shouldn't even call the function
            if (!ServerProfile.IsOfficial)
            {
                return(false);
            }

            if (ClientProfile.Localization != ClientLocalization.Japan &&
                ClientProfile.Localization != ClientLocalization.JapanHangame)
            {
                return(false);
            }

            PatcherContext.SetPatcherState(true);

            PatcherContext.UpdateMainProgress("Checking for updates...", "", 0, true, true);

            _officialPatchInfo = OfficialPatchInfo.Parse(MabiVersion.Versions
                                                         .Find(version => version.Name == ClientProfile.Localization).PatchUrl);

            if (int.TryParse(_officialPatchInfo["main_version"], out var versionConverted))
            {
                _remoteVersion = versionConverted;
            }

            if (_currentVersion == _remoteVersion)
            {
                PatcherContext.SetPatcherState(false);
                PatcherContext.UpdateMainProgress("", "", 0, false, false);
                return(false);
            }

            try
            {
                await Task.Run(() => _patchSequence = FindPatchSequence());
            }
            catch (PatchSequenceNotFoundException ex)
            {
                Log.Exception(ex);
                PatcherContext.SetPatcherState(false);
                PatcherContext.UpdateMainProgress("", "", 0, false, false);
                return(false);
            }

            PatcherContext.SetPatcherState(false);
            PatcherContext.UpdateMainProgress("", "", 0, false, false);
            return(true);
        }
Ejemplo n.º 2
0
        public override async Task <bool> RepairInstall()
        {
            var shouldUpdate = await CheckForUpdatesInternal(-1, true);

            if (shouldUpdate)
            {
                return(await ApplyUpdates());
            }
            PatcherContext.SetPatcherState(false);
            PatcherContext.UpdateMainProgress("", "", 0, false, false);
            return(true);
        }
Ejemplo n.º 3
0
        public override async Task <bool> ApplyUpdates()
        {
            PatcherContext.SetPatcherState(true);
            PatcherContext.ShowSession();

            var downloader = new PatchDownloader(PatcherContext, _patchSequence, _officialPatchInfo, ClientProfile);
            await Task.Run(() => downloader.Prepare());

            await Task.Run(() => downloader.Patch());

            WriteVersion(_remoteVersion);

            PatcherContext.SetPatcherState(false);
            PatcherContext.HideSession();
            return(true);
        }
Ejemplo n.º 4
0
        public override async Task <bool> CheckForUpdates()
        {
            if (ValidateAction(true))
            {
                return(false);
            }

            PatcherContext.UpdateMainProgress(Properties.Resources.Initialize, "", 0, true, true);

            var completed = "true";

            PatcherContext.SetPatcherState(true);

            PatcherContext.UpdateMainProgress(Properties.Resources.CheckingForUpdates, "", 0, true, true);

            if (!NexonApi.Instance.IsAccessTokenValid(ClientProfile.Guid))
            {
                completed = "";
                PatcherContext.RequestUserLogin(() => completed = "true", () => completed = "false");
            }

            while (completed == "")
            {
                await Task.Delay(100);
            }

            if (completed == "false")
            {
                PatcherContext.SetPatcherState(false);
                PatcherContext.UpdateMainProgress("", "", 0, false, false);
                return(false);
            }

            var result = await CheckForUpdatesInternal(ReadVersion());

            PatcherContext.SetPatcherState(false);
            PatcherContext.UpdateMainProgress("", "", 0, false, false);

            return(result);
        }
Ejemplo n.º 5
0
        public override async Task <bool> ApplyUpdates()
        {
            if (ValidateAction())
            {
                return(false);
            }

            PatcherContext.SetPatcherState(true);
            PatcherContext.ShowSession();
            PatcherContext.UpdateMainProgress(Properties.Resources.ApplyingUpdates, "", 0, true, true);

            var patchDownloader = new PatchDownloader(Patches, ClientProfile, PatcherContext);

            bool result = false;

            try
            {
                await Task.Run(() => patchDownloader.Prepare());

                result = await Task.Run(() => patchDownloader.Patch());

                await Task.Run(() => patchDownloader.Cleanup());
            }
            catch (Exception ex)
            {
                Log.Exception(ex, "Failed to patch!");
            }
            finally
            {
                PatcherContext.UpdateMainProgress(result ? Properties.Resources.PatchComplete : Properties.Resources.PatchFailed);

                PatcherContext.SetPatcherState(false);
                PatcherContext.HideSession();
            }

            return(result);
        }