From 28915c266f6e9c4eb539d78142a45c650a18a872 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Tue, 30 Oct 2018 10:31:49 +0100 Subject: [PATCH 1/3] Patcher will not clear the progress bar after updating --- Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs | 7 +++---- CHANGELOG.md | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs b/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs index f0d15bce..5b4fab25 100644 --- a/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs +++ b/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs @@ -33,10 +33,9 @@ private void SetProgress(UpdateData data) { _isIdle = data.State == PatcherState.Connecting; - if (data.State == PatcherState.None) + if (data.State == PatcherState.None || data.Progress < 0) { - Text.text = ""; - SetBar(0, 0); + // do nothing return; } @@ -73,11 +72,11 @@ private void Start() .AddTo(this); } - private bool _isIdle = false; private const float IdleBarWidth = 0.2f; private const float IdleBarSpeed = 1.2f; private float _idleProgress = -IdleBarWidth; + private void Update() { if (_isIdle) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f0fa3c..1d2725b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Linux launch script - Download speed will now be displayed based on the average of download speeds in the last 2 seconds +- Patcher will no longer clear the progress bar after updating ### Fixed - Invalid display of progress value when unarchiving From b9719b118d958673c5486cf25845b29dd809711f Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Mon, 12 Nov 2018 18:18:52 +0100 Subject: [PATCH 2/3] Post merge cleanup --- .../Editor/PatcherManifestCreator.cs | 3 ++- .../Scripts/AppUpdater/AppUpdaterRepairStrategy.cs | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs index 7e446b36..24ead1d7 100644 --- a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs +++ b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using JetBrains.Annotations; using Newtonsoft.Json; @@ -14,7 +15,7 @@ public static class PatcherManifestCreator private static void PostProcessBuild(BuildTarget buildTarget, string buildPath) { Manifest manifest; - + switch (buildTarget) { case BuildTarget.StandaloneWindows: diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs index 3708650f..1c1f9851 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs @@ -6,6 +6,7 @@ using PatchKit.Unity.Patcher.Cancellation; using PatchKit.Unity.Patcher.Debug; using PatchKit.Unity.Patcher.AppData.Local; +using PatchKit.Unity.Patcher.AppData.FileSystem; using PatchKit.Unity.Patcher.AppData.Remote.Downloaders; using PatchKit.Unity.Patcher.AppUpdater.Commands; using PatchKit.Unity.Patcher.AppUpdater.Status; @@ -54,8 +55,8 @@ public void Update(CancellationToken cancellationToken) geolocateCommand.Execute(cancellationToken); var resource = _context.App.RemoteData.GetContentPackageResource( - installedVersionId, - validateLicense.KeySecret, + installedVersionId, + validateLicense.KeySecret, geolocateCommand.CountryCode); if (!resource.HasMetaUrls()) @@ -67,7 +68,7 @@ public void Update(CancellationToken cancellationToken) var downloader = new HttpDownloader(metaDestination, resource.GetMetaUrls()); downloader.Download(cancellationToken); - ICheckVersionIntegrityCommand checkVersionIntegrityCommand + ICheckVersionIntegrityCommand checkVersionIntegrityCommand = commandFactory.CreateCheckVersionIntegrityCommand(installedVersionId, _context); checkVersionIntegrityCommand.Prepare(_status); @@ -90,7 +91,7 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand string actualFileHash = HashCalculator.ComputeFileHash(localPath); if (actualFileHash != file.Hash) { - FileOperations.Delete(localPath); + FileOperations.Delete(localPath, cancellationToken); _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId); invalidVersionIdFile.Status = FileIntegrityStatus.MissingData; } @@ -103,7 +104,7 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand Pack1Meta.FileEntry[] brokenFiles = filesIntegrity // Filter only files with invalid size, hash or missing entirely - .Where(f => f.Status == FileIntegrityStatus.InvalidHash + .Where(f => f.Status == FileIntegrityStatus.InvalidHash || f.Status == FileIntegrityStatus.InvalidSize || f.Status == FileIntegrityStatus.MissingData) // Map to file entires from meta @@ -118,7 +119,7 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand return; } _logger.LogDebug(string.Format("Broken files count: {0}", brokenFiles.Length)); - + IRepairFilesCommand repairCommand = commandFactory.CreateRepairFilesCommand( installedVersionId, _context, From 41d0918d6fc990419b0834f631de423e4d858a46 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Mon, 12 Nov 2018 18:19:13 +0100 Subject: [PATCH 3/3] PR update --- Assets/PatchKit Patcher/Scripts/Patcher.cs | 11 +- .../Scripts/UI/ProgressBar.cs | 115 +++++++++++++----- 2 files changed, 96 insertions(+), 30 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/Patcher.cs b/Assets/PatchKit Patcher/Scripts/Patcher.cs index a3282f48..3d1f20e8 100644 --- a/Assets/PatchKit Patcher/Scripts/Patcher.cs +++ b/Assets/PatchKit Patcher/Scripts/Patcher.cs @@ -116,6 +116,13 @@ public IReadOnlyReactiveProperty CanStartApp get { return _canStartApp; } } + private readonly BoolReactiveProperty _isAppInstalled = new BoolReactiveProperty(false); + + public IReadOnlyReactiveProperty IsAppInstalled + { + get { return _isAppInstalled; } + } + private readonly BoolReactiveProperty _canInstallApp = new BoolReactiveProperty(false); public IReadOnlyReactiveProperty CanInstallApp @@ -583,6 +590,8 @@ private void ThreadWaitForUserDecision(CancellationToken cancellationToken) bool canCheckForAppUpdates = isInstalled; bool canStartApp = isInstalled; + _isAppInstalled.Value = isInstalled; + _canRepairApp.Value = false; _canInstallApp.Value = false; _canCheckForAppUpdates.Value = false; @@ -721,7 +730,7 @@ private void ThreadExecuteUserDecision(CancellationToken cancellationToken) DebugLogger.LogException(e); PatcherStatistics.DispatchSendEvent(PatcherStatistics.Event.PatcherFailed); - + if (displayWarningInsteadOfError) { _warning.Value = "Unable to check for updates. Please check your internet connection."; diff --git a/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs b/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs index 5b4fab25..41975527 100644 --- a/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs +++ b/Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs @@ -1,4 +1,7 @@ -using PatchKit.Unity.Utilities; +using System; +using System.Collections.Generic; +using PatchKit.Unity.Patcher.AppUpdater.Status; +using PatchKit.Unity.Utilities; using UniRx; using UnityEngine; using UnityEngine.UI; @@ -14,10 +17,13 @@ public class ProgressBar : MonoBehaviour private struct UpdateData { public double Progress; + public PatcherState State; + + public bool IsAppInstalled; } - private void SetBar(float start, float end) + private void SetProgressBar(float start, float end) { var anchorMax = Image.rectTransform.anchorMax; var anchorMin = Image.rectTransform.anchorMin; @@ -29,46 +35,97 @@ private void SetBar(float start, float end) Image.rectTransform.anchorMin = anchorMin; } - private void SetProgress(UpdateData data) + private void SetProgressBarLinear(float progress) { - _isIdle = data.State == PatcherState.Connecting; + SetProgressBar(0, progress); + } - if (data.State == PatcherState.None || data.Progress < 0) - { - // do nothing - return; - } + private void SetProgressBarText(string text) + { + Text.text = text; + } - if (data.State == PatcherState.DisplayingError) - { - Text.text = "Error!"; - SetBar(0, 0); - return; - } + private void SetProgress(UpdateData data) + { + } - if (data.State == PatcherState.Connecting) - { - Text.text = "Connecting..."; - return; - } + private void SetIdle() + { + SetProgressBarText("Connecting..."); + _isIdle = true; + } - double progress = data.Progress; + private string FormatProgressForDisplay(double progress) + { + return string.Format("{0:0.0}", progress * 100.0) + "%"; + } - Text.text = progress >= 0.0 ? progress.ToString("0.0%") : ""; - float visualProgress = progress >= 0.0 ? (float) progress : 0.0f; + private void OnUpdate(UpdateData data) + { + _isIdle = false; - SetBar(0, visualProgress); + switch (data.State) + { + case PatcherState.LoadingPatcherData: + case PatcherState.LoadingPatcherConfiguration: + case PatcherState.Connecting: + SetIdle(); + return; + + case PatcherState.UpdatingApp: + if (data.Progress <= 0) + { + SetIdle(); + return; + } + + SetProgressBarText(FormatProgressForDisplay(data.Progress)); + SetProgressBarLinear((float) data.Progress); + break; + + case PatcherState.WaitingForUserDecision: + if (data.IsAppInstalled) + { + SetProgressBarText(FormatProgressForDisplay(1.0)); + SetProgressBarLinear(1); + } + else + { + SetProgressBarText(FormatProgressForDisplay(0.0)); + SetProgressBarLinear(0); + } + break; + + case PatcherState.DisplayingError: + SetProgressBarText("Error..."); + SetProgressBarLinear(0); + break; + + case PatcherState.StartingApp: + SetProgressBarText(FormatProgressForDisplay(1.0)); + SetProgressBarLinear(1); + break; + + case PatcherState.None: + default: + _isIdle = false; + break; + } } private void Start() { - var progress = Patcher.Instance.UpdaterStatus - .SelectSwitchOrDefault(s => s.Progress, -1.0); + var progress = Patcher.Instance.UpdaterStatus.SelectSwitchOrDefault(p => p.Progress, -1.0); Patcher.Instance.State - .CombineLatest(progress, (state, d) => new UpdateData { Progress = d, State = state }) + .CombineLatest(progress, Patcher.Instance.IsAppInstalled, + (state, progressValue, isAppInstalled) => new UpdateData { + Progress = progressValue, + State = state, + IsAppInstalled = isAppInstalled + }) .ObserveOnMainThread() - .Subscribe(SetProgress) + .Subscribe(OnUpdate) .AddTo(this); } @@ -81,7 +138,7 @@ private void Update() { if (_isIdle) { - SetBar(_idleProgress, _idleProgress + IdleBarWidth); + SetProgressBar(_idleProgress, _idleProgress + IdleBarWidth); _idleProgress += Time.deltaTime * IdleBarSpeed;