Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using JetBrains.Annotations;
using Newtonsoft.Json;
Expand All @@ -14,7 +15,7 @@ public static class PatcherManifestCreator
private static void PostProcessBuild(BuildTarget buildTarget, string buildPath)
{
Manifest manifest;

switch (buildTarget)
{
case BuildTarget.StandaloneWindows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -118,7 +119,7 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand
return;
}
_logger.LogDebug(string.Format("Broken files count: {0}", brokenFiles.Length));

IRepairFilesCommand repairCommand = commandFactory.CreateRepairFilesCommand(
installedVersionId,
_context,
Expand Down
11 changes: 10 additions & 1 deletion Assets/PatchKit Patcher/Scripts/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public IReadOnlyReactiveProperty<bool> CanStartApp
get { return _canStartApp; }
}

private readonly BoolReactiveProperty _isAppInstalled = new BoolReactiveProperty(false);

public IReadOnlyReactiveProperty<bool> IsAppInstalled
{
get { return _isAppInstalled; }
}

private readonly BoolReactiveProperty _canInstallApp = new BoolReactiveProperty(false);

public IReadOnlyReactiveProperty<bool> CanInstallApp
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.";
Expand Down
118 changes: 87 additions & 31 deletions Assets/PatchKit Patcher/Scripts/UI/ProgressBar.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -29,60 +35,110 @@ 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)
{
Text.text = "";
SetBar(0, 0);
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);
}


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)
{
SetBar(_idleProgress, _idleProgress + IdleBarWidth);
SetProgressBar(_idleProgress, _idleProgress + IdleBarWidth);

_idleProgress += Time.deltaTime * IdleBarSpeed;

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down