Skip to content

Bugfix/v3.17.x.x/repair cost and decision , restriction of hash repair #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: dev/v3.17.x.x
Choose a base branch
from
12 changes: 3 additions & 9 deletions Assets/PatchKit Patcher/Scripts/AppUpdater/AppRepairer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Collections.Generic;
using PatchKit.Unity.Patcher.Cancellation;
using PatchKit.Unity.Patcher.Debug;
using PatchKit.Unity.Patcher.AppUpdater.Commands;
using PatchKit.Unity.Patcher.AppUpdater.Status;
Expand Down Expand Up @@ -34,7 +30,6 @@ public class AppRepairer

private const double IncreaseRepairCost = 1.5d;


public AppRepairer(AppUpdaterContext context, UpdaterStatus status)
{
DebugLogger.LogConstructor();
Expand Down Expand Up @@ -162,17 +157,16 @@ int installedVersionId

private IEnumerable<FileIntegrity> FilesNeedFixing(VersionIntegrity results)
{
var missingFiles = results.Files.Where(f => f.Status == FileIntegrityStatus.MissingData);
var invalidSizeFiles = results.Files.Where(f => f.Status == FileIntegrityStatus.InvalidSize);
var invalidFiles = results.Files.Where(f => f.Status != FileIntegrityStatus.Ok);

return missingFiles.Concat(invalidSizeFiles);
return invalidFiles;
}

private long CalculateRepairCost(AppContentSummary contentSummary, IEnumerable<FileIntegrity> filesToRepair)
{
return filesToRepair
.Select(f => contentSummary.Files.FirstOrDefault(e => e.Path == f.FileName))
.Sum(f => f.Size);
.Sum(f => Math.Max(contentSummary.Chunks.Size, f.Size));
}

private void ReinstallContent(PatchKit.Unity.Patcher.Cancellation.CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class AppUpdaterContentStrategy: IAppUpdaterStrategy

private readonly UpdaterStatus _status;

private const int RepairCheckHashesMaxFilesCount = 10000;

private bool _updateHasBeenCalled;

public bool RepairOnError { get; set; }
Expand Down Expand Up @@ -119,7 +121,15 @@ public void Update(CancellationToken cancellationToken)
DebugLogger.Log("Content installed with errors, requesting repair");

var appRepairer = new AppRepairer(_context, _status);
appRepairer.CheckHashes = true;
if (_context.App.RemoteMetaData.GetContentSummary(latestVersionId, cancellationToken).Files.Length < RepairCheckHashesMaxFilesCount)
{
appRepairer.CheckHashes = true;
}
else
{
appRepairer.CheckHashes = false;
}


if (!appRepairer.Perform(cancellationToken))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void Execute(CancellationToken cancellationToken)
_status.IsActive.Value = true;
_status.IsIdle.Value = true;

DebugLogger.Log("Check Disk Space Command Execute...");
try
{
long availableDiskSpace = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ public void Execute(CancellationToken cancellationToken)
{
_status.IsActive.Value = true;
_status.IsIdle.Value = true;

DebugLogger.Log("Check Path Length Command Execute...");
try
{
string pathFile;
foreach (AppContentSummaryFile contentSummaryFile in _contentSummary.Value.Files)
{
pathFile = Path.Combine(_localDirectoryPath, contentSummaryFile.Path);
string pathFile = Path.Combine(_localDirectoryPath, contentSummaryFile.Path);

if (pathFile.Length > 259)
{
Expand Down
11 changes: 6 additions & 5 deletions Assets/PatchKit Patcher/Scripts/Debug/DebugMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class DebugMenu : MonoBehaviour
private GraphicRaycaster _graphicRaycaster;
private PlatformType _platformType;
private bool _wasInitialized;

private Vector2 _pivotCenterScreen;

void Start()
{
_graphicRaycaster = FindObjectOfType<GraphicRaycaster>();
_platformType = Platform.GetPlatformType();
_pivotCenterScreen = new Vector2(Screen.width / 2, Screen.height / 2);
}

void OnGUI()
Expand All @@ -48,17 +49,17 @@ void OnGUI()
if (!_wasInitialized)
{
_wasInitialized = true;
float scale = ScreenScale.Value;
float windowWidth = 250 * scale;
float windowHeight = 200 * scale;
float windowWidth = 250;
float windowHeight = 200;
float x = (Screen.width - windowWidth) / 2;
float y = (Screen.height - windowHeight) / 2;
float popupRectY = (Screen.height - 120) / 2;
_rect = new Rect(x, y, windowWidth, windowHeight);
_popupRect = new Rect(x, popupRectY, windowWidth, 120);
_texturePopupRect = new Rect(0, popupRectY - y, windowWidth, 120);
}


GUIUtility.ScaleAroundPivot(Vector2.one * ScreenScale.Value, _pivotCenterScreen);
GUI.DrawTexture(_rect, Texture2D.whiteTexture);
GUI.Window(0, _rect, Draw, "Debug Menu");
if (_showPopup)
Expand Down
2 changes: 1 addition & 1 deletion Assets/PatchKit Patcher/Scripts/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class Version
{
public const int Major = 3;
public const int Minor = 17;
public const int Patch = 11;
public const int Patch = 12;
public const int Hotfix = 0;

public static string Value
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.17.12.0]
### Changed
- Disable checking hashes for repairing after failed installation if files count is over 10000

### Fixed
- Wrong cost calculation of repairing while making installation decision
- Support HDPI for debug menu

## [3.17.11.0]
### Fixed
- Minimize and close buttons invisible with popup
Expand Down