From e6aa9a67a49287f5066d59b46ff380249b09ab14 Mon Sep 17 00:00:00 2001 From: JakubSzczyrk Date: Tue, 5 May 2020 15:49:06 +0200 Subject: [PATCH 1/8] Restriction on saving the app_dat.json file --- Assets/Editor/Tests/LocalMetaDataTest.cs | 6 ++--- .../Scripts/AppData/Local/ILocalMetaData.cs | 4 ++- .../Scripts/AppData/Local/LocalMetaData.cs | 26 +++++++++++++++++-- .../AppUpdater/AppUpdaterRepairStrategy.cs | 11 +++++--- .../Commands/InstallContentCommand.cs | 13 ++++++---- .../AppUpdater/Commands/InstallDiffCommand.cs | 8 ++++-- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Assets/Editor/Tests/LocalMetaDataTest.cs b/Assets/Editor/Tests/LocalMetaDataTest.cs index 2518b636..33cb32b6 100644 --- a/Assets/Editor/Tests/LocalMetaDataTest.cs +++ b/Assets/Editor/Tests/LocalMetaDataTest.cs @@ -31,7 +31,7 @@ public void CreateMetaDataFile() var localMetaData = new LocalMetaData(_filePath, _deprecatedFilePath); - localMetaData.RegisterEntry("test", 1); + localMetaData.RegisterEntry("test", 1, 0, true); Assert.True(File.Exists(_filePath)); } @@ -41,8 +41,8 @@ public void SaveValidFileSinglePass() { var localMetaData = new LocalMetaData(_filePath, _deprecatedFilePath); - localMetaData.RegisterEntry("a", 1); - localMetaData.RegisterEntry("b", 2); + localMetaData.RegisterEntry("a", 1, 0 , true); + localMetaData.RegisterEntry("b", 2, 0 , true); var localMetaData2 = new LocalMetaData(_filePath, _deprecatedFilePath); diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs index 02905a12..04edbe4f 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs @@ -16,7 +16,9 @@ public interface ILocalMetaData /// /// Name of the entry. /// The version id. - void RegisterEntry(string entryName, int versionId); + /// Size of entry. + /// If set to true, it is last entry. + void RegisterEntry(string entryName, int versionId, long entrySize, bool lastEntry); /// /// Unregisters the entry. diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs index 1c130637..6cfb9cc6 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs @@ -20,7 +20,10 @@ namespace PatchKit.Unity.Patcher.AppData.Local public class LocalMetaData : ILocalMetaData { private readonly ILogger _logger; + private long _globalEntriesSize = 0; + private long _numberOfEntries = 0; private const string DeprecatedCachePatchKitKey = "patchkit-key"; + private const long MakeEntryEverySize = 13107200; //100MiB /// /// Data structure stored in file. @@ -73,7 +76,7 @@ public string[] GetRegisteredEntries() return _data.FileVersionIds.Select(pair => pair.Key).ToArray(); } - public void RegisterEntry([NotNull] string entryName, int versionId) + public void RegisterEntry([NotNull] string entryName, int versionId, long entrySize, bool lastEntry) { if (entryName == null) { @@ -97,7 +100,10 @@ public void RegisterEntry([NotNull] string entryName, int versionId) _data.FileVersionIds[entryName] = versionId; - SaveData(); + if (ShouldSaveEntry(entrySize, lastEntry)) + { + SaveData(); + } _logger.LogDebug("Entry registered."); } @@ -108,6 +114,22 @@ public void RegisterEntry([NotNull] string entryName, int versionId) } } + private bool ShouldSaveEntry(long entrySize, bool lastEntry) + { + if (lastEntry) + { + return true; + } + + _globalEntriesSize += entrySize; + if ((_globalEntriesSize / MakeEntryEverySize) > _numberOfEntries) + { + _numberOfEntries++; + return true; + } + return false; + } + public void UnregisterEntry([NotNull] string entryName) { if (entryName == null) diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs index 027ff6db..7fc4911e 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs @@ -84,8 +84,9 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand var contentSummary = _context.App.RemoteMetaData.GetContentSummary(installedVersionId, cancellationToken); - foreach (var invalidVersionIdFile in filesIntegrity.Where(x => - x.Status == FileIntegrityStatus.InvalidVersion).ToArray()) + var filesIntegrityWithInvalidVersion = filesIntegrity.Where(x => + x.Status == FileIntegrityStatus.InvalidVersion).ToArray(); + foreach (var invalidVersionIdFile in filesIntegrityWithInvalidVersion) { var fileName = invalidVersionIdFile.FileName; var file = contentSummary.Files.First(x => x.Path == fileName); @@ -96,12 +97,14 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand if (actualFileHash != file.Hash) { FileOperations.Delete(localPath, cancellationToken); - _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId); + _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId, file.Size, + fileName == filesIntegrityWithInvalidVersion[filesIntegrityWithInvalidVersion.Length -1].FileName); invalidVersionIdFile.Status = FileIntegrityStatus.MissingData; } else { - _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId); + _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId, file.Size, + fileName == filesIntegrityWithInvalidVersion[filesIntegrityWithInvalidVersion.Length -1].FileName); invalidVersionIdFile.Status = FileIntegrityStatus.Ok; } } diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs index 23e986db..37b8074e 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs @@ -135,14 +135,15 @@ public override void Execute(CancellationToken cancellationToken) for (int i = 0; i < _versionContentSummary.Files.Length; i++) { cancellationToken.ThrowIfCancellationRequested(); - var sourceFile = new SourceFile(_versionContentSummary.Files[i].Path, packageDir.Path, usedSuffix); + var sourceFile = new SourceFile(_versionContentSummary.Files[i].Path, packageDir.Path, usedSuffix, + _versionContentSummary.Files[i].Size); if (unarchiver.HasErrors && !sourceFile.Exists()) // allow unexistent file only if does not have errors { DebugLogger.LogWarning("Skipping unexisting file because I've been expecting unpacking errors: " + sourceFile.Name); } else { - InstallFile(sourceFile, cancellationToken); + InstallFile(sourceFile, cancellationToken, i == _versionContentSummary.Files.Length - 1); } _copyFilesStatus.Progress.Value = (i + 1) / (double) _versionContentSummary.Files.Length; @@ -170,7 +171,7 @@ private IUnarchiver CreateUnrachiver(string destinationDir, out string usedSuffi } } - private void InstallFile(SourceFile sourceFile, CancellationToken cancellationToken) + private void InstallFile(SourceFile sourceFile, CancellationToken cancellationToken, bool lastEntry) { DebugLogger.Log(string.Format("Installing file {0}", sourceFile.Name)); @@ -189,20 +190,22 @@ private void InstallFile(SourceFile sourceFile, CancellationToken cancellationTo } FileOperations.Move(sourceFile.FullPath, destinationFilePath, cancellationToken); - _localMetaData.RegisterEntry(sourceFile.Name, _versionId); + _localMetaData.RegisterEntry(sourceFile.Name, _versionId, sourceFile.Size, lastEntry); } struct SourceFile { public string Name { get; private set; } + public long Size { get; private set; } private string _suffix; private string _root; public string FullPath { get { return Path.Combine(_root, Name + _suffix); } } - public SourceFile(string name, string root, string suffix) + public SourceFile(string name, string root, string suffix, long size) { Name = name; + Size = size; _root = root; _suffix = suffix; } diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs index eacef94d..8d781040 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs @@ -484,7 +484,9 @@ private void AddFile(string fileName, string packageDirPath, string suffix, Canc FileOperations.Copy(sourceFilePath, filePath, true, cancellationToken); _logger.LogDebug("File copied to local data."); - _localMetaData.RegisterEntry(fileName, _versionId); + _localMetaData.RegisterEntry(fileName, _versionId, + _contentSummary.Files.First(x => x.Path == fileName).Size, + fileName == _contentSummary.Files[_contentSummary.Files.Length-1].Path); _logger.LogDebug("Add file entry processed."); } @@ -577,7 +579,9 @@ private void PatchFile( _logger.LogDebug("Patching is not necessary. File content is the same as in previous version."); } - _localMetaData.RegisterEntry(fileName, _versionId); + _localMetaData.RegisterEntry(fileName, _versionId, + _contentSummary.Files.First(x => x.Path == fileName).Size, + fileName == _contentSummary.Files[_contentSummary.Files.Length-1].Path); _logger.LogDebug("Patch file entry processed."); } From fa8a7fa79f676be1d988068265abf181eae93e40 Mon Sep 17 00:00:00 2001 From: JakubSzczyrk Date: Tue, 5 May 2020 16:34:11 +0200 Subject: [PATCH 2/8] fixed naming --- .../Scripts/AppData/Local/LocalMetaData.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs index 6cfb9cc6..0c625bac 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs @@ -20,10 +20,9 @@ namespace PatchKit.Unity.Patcher.AppData.Local public class LocalMetaData : ILocalMetaData { private readonly ILogger _logger; - private long _globalEntriesSize = 0; - private long _numberOfEntries = 0; + private long _unsavedEntriesSize = 0; private const string DeprecatedCachePatchKitKey = "patchkit-key"; - private const long MakeEntryEverySize = 13107200; //100MiB + private const long UnsavedEntriesSizeLimit = 104857600; //100MiB /// /// Data structure stored in file. @@ -121,10 +120,10 @@ private bool ShouldSaveEntry(long entrySize, bool lastEntry) return true; } - _globalEntriesSize += entrySize; - if ((_globalEntriesSize / MakeEntryEverySize) > _numberOfEntries) + _unsavedEntriesSize += entrySize; + if (_unsavedEntriesSize > UnsavedEntriesSizeLimit) { - _numberOfEntries++; + _unsavedEntriesSize = 0; return true; } return false; From f17b9330a00e29790312046a3d0b5cfaf5ad9747 Mon Sep 17 00:00:00 2001 From: JakubSzczyrk Date: Tue, 5 May 2020 17:13:37 +0200 Subject: [PATCH 3/8] code refactoring --- .../Scripts/AppUpdater/AppUpdaterRepairStrategy.cs | 4 ++-- .../Scripts/AppUpdater/Commands/InstallContentCommand.cs | 4 ++-- .../Scripts/AppUpdater/Commands/InstallDiffCommand.cs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs index 7fc4911e..b3dc3ad8 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs @@ -98,13 +98,13 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand { FileOperations.Delete(localPath, cancellationToken); _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId, file.Size, - fileName == filesIntegrityWithInvalidVersion[filesIntegrityWithInvalidVersion.Length -1].FileName); + fileName == filesIntegrityWithInvalidVersion.Last().FileName); invalidVersionIdFile.Status = FileIntegrityStatus.MissingData; } else { _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId, file.Size, - fileName == filesIntegrityWithInvalidVersion[filesIntegrityWithInvalidVersion.Length -1].FileName); + fileName == filesIntegrityWithInvalidVersion.Last().FileName); invalidVersionIdFile.Status = FileIntegrityStatus.Ok; } } diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs index 37b8074e..5a1b8db7 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs @@ -135,8 +135,8 @@ public override void Execute(CancellationToken cancellationToken) for (int i = 0; i < _versionContentSummary.Files.Length; i++) { cancellationToken.ThrowIfCancellationRequested(); - var sourceFile = new SourceFile(_versionContentSummary.Files[i].Path, packageDir.Path, usedSuffix, - _versionContentSummary.Files[i].Size); + var file = _versionContentSummary.Files[i]; + var sourceFile = new SourceFile(file.Path, packageDir.Path, usedSuffix, file.Size); if (unarchiver.HasErrors && !sourceFile.Exists()) // allow unexistent file only if does not have errors { diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs index 8d781040..2f57279a 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs @@ -484,9 +484,9 @@ private void AddFile(string fileName, string packageDirPath, string suffix, Canc FileOperations.Copy(sourceFilePath, filePath, true, cancellationToken); _logger.LogDebug("File copied to local data."); + string lastFilePath = _contentSummary.Files[_contentSummary.Files.Length - 1].Path; _localMetaData.RegisterEntry(fileName, _versionId, - _contentSummary.Files.First(x => x.Path == fileName).Size, - fileName == _contentSummary.Files[_contentSummary.Files.Length-1].Path); + _contentSummary.Files.First(x => x.Path == fileName).Size, fileName == lastFilePath); _logger.LogDebug("Add file entry processed."); } @@ -579,9 +579,9 @@ private void PatchFile( _logger.LogDebug("Patching is not necessary. File content is the same as in previous version."); } + string lastFilePath = _contentSummary.Files[_contentSummary.Files.Length - 1].Path; _localMetaData.RegisterEntry(fileName, _versionId, - _contentSummary.Files.First(x => x.Path == fileName).Size, - fileName == _contentSummary.Files[_contentSummary.Files.Length-1].Path); + _contentSummary.Files.First(x => x.Path == fileName).Size, fileName == lastFilePath); _logger.LogDebug("Patch file entry processed."); } From 84391e8085856593f24d603d6feaa282b4885258 Mon Sep 17 00:00:00 2001 From: JakubSzczyrk Date: Wed, 6 May 2020 10:14:45 +0200 Subject: [PATCH 4/8] fix last entry from diff --- .../AppUpdater/AppUpdaterRepairStrategy.cs | 12 +++++------ .../Commands/InstallContentCommand.cs | 4 ++-- .../AppUpdater/Commands/InstallDiffCommand.cs | 21 ++++++++++--------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs index b3dc3ad8..8b070d7e 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs @@ -86,9 +86,9 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand var filesIntegrityWithInvalidVersion = filesIntegrity.Where(x => x.Status == FileIntegrityStatus.InvalidVersion).ToArray(); - foreach (var invalidVersionIdFile in filesIntegrityWithInvalidVersion) + for (int i = 0; i < filesIntegrityWithInvalidVersion.Length; i++) { - var fileName = invalidVersionIdFile.FileName; + var fileName = filesIntegrityWithInvalidVersion[i].FileName; var file = contentSummary.Files.First(x => x.Path == fileName); var localPath = _context.App.LocalDirectory.Path.PathCombine(file.Path); @@ -98,14 +98,14 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand { FileOperations.Delete(localPath, cancellationToken); _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId, file.Size, - fileName == filesIntegrityWithInvalidVersion.Last().FileName); - invalidVersionIdFile.Status = FileIntegrityStatus.MissingData; + i == filesIntegrityWithInvalidVersion.Length - 1); + filesIntegrityWithInvalidVersion[i].Status = FileIntegrityStatus.MissingData; } else { _context.App.LocalMetaData.RegisterEntry(fileName, installedVersionId, file.Size, - fileName == filesIntegrityWithInvalidVersion.Last().FileName); - invalidVersionIdFile.Status = FileIntegrityStatus.Ok; + i == filesIntegrityWithInvalidVersion.Length - 1); + filesIntegrityWithInvalidVersion[i].Status = FileIntegrityStatus.Ok; } } diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs index 5a1b8db7..a79ebe4d 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs @@ -135,8 +135,8 @@ public override void Execute(CancellationToken cancellationToken) for (int i = 0; i < _versionContentSummary.Files.Length; i++) { cancellationToken.ThrowIfCancellationRequested(); - var file = _versionContentSummary.Files[i]; - var sourceFile = new SourceFile(file.Path, packageDir.Path, usedSuffix, file.Size); + var versionContentSummaryFile = _versionContentSummary.Files[i]; + var sourceFile = new SourceFile(versionContentSummaryFile.Path, packageDir.Path, usedSuffix, versionContentSummaryFile.Size); if (unarchiver.HasErrors && !sourceFile.Exists()) // allow unexistent file only if does not have errors { diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs index 2f57279a..975e200e 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs @@ -430,7 +430,7 @@ private void ProcessAddedFiles(string packageDirPath, string suffix, } else { - AddFile(entryName, packageDirPath, suffix, cancellationToken); + AddFile(entryName, packageDirPath, suffix, cancellationToken, i); } _addFilesStatusReporter.Progress.Value = (i + 1) / (double) _diffSummary.AddedFiles.Length; @@ -457,7 +457,8 @@ private void AddDirectory(string dirName, CancellationToken cancellationToken) _logger.LogDebug("Add directory entry processed."); } - private void AddFile(string fileName, string packageDirPath, string suffix, CancellationToken cancellationToken) + private void AddFile(string fileName, string packageDirPath, string suffix, CancellationToken cancellationToken, + int index) { _logger.LogDebug(string.Format("Processing add file entry {0}", fileName)); @@ -483,10 +484,10 @@ private void AddFile(string fileName, string packageDirPath, string suffix, Canc _logger.LogDebug("Copying file to local data (overwriting if needed)..."); FileOperations.Copy(sourceFilePath, filePath, true, cancellationToken); _logger.LogDebug("File copied to local data."); - - string lastFilePath = _contentSummary.Files[_contentSummary.Files.Length - 1].Path; + _localMetaData.RegisterEntry(fileName, _versionId, - _contentSummary.Files.First(x => x.Path == fileName).Size, fileName == lastFilePath); + _contentSummary.Files.First(x => x.Path == fileName).Size, + index == _diffSummary.AddedFiles.Length - 1); _logger.LogDebug("Add file entry processed."); } @@ -507,7 +508,7 @@ private void ProcessModifiedFiles(string packageDirPath, string suffix, Temporar if (!entryName.EndsWith("/")) { - PatchFile(entryName, packageDirPath, suffix, tempDiffDir, cancellationToken); + PatchFile(entryName, packageDirPath, suffix, tempDiffDir, cancellationToken, i); } _modifiedFilesStatusReporter.Progress.Value = (i + 1) / (double) _diffSummary.ModifiedFiles.Length; @@ -523,7 +524,7 @@ private void ProcessModifiedFiles(string packageDirPath, string suffix, Temporar private void PatchFile( string fileName, string packageDirPath, string suffix, - TemporaryDirectory tempDiffDir, CancellationToken cancellationToken) + TemporaryDirectory tempDiffDir, CancellationToken cancellationToken, int index) { _logger.LogDebug(string.Format("Processing patch file entry {0}", fileName)); @@ -578,10 +579,10 @@ private void PatchFile( { _logger.LogDebug("Patching is not necessary. File content is the same as in previous version."); } - - string lastFilePath = _contentSummary.Files[_contentSummary.Files.Length - 1].Path; + _localMetaData.RegisterEntry(fileName, _versionId, - _contentSummary.Files.First(x => x.Path == fileName).Size, fileName == lastFilePath); + _contentSummary.Files.First(x => x.Path == fileName).Size, + index == _diffSummary.ModifiedFiles.Length - 1); _logger.LogDebug("Patch file entry processed."); } From de05e8525a12e20df98d9c0e62fb7e59dcfb94be Mon Sep 17 00:00:00 2001 From: JakubSzczyrk Date: Wed, 6 May 2020 10:40:14 +0200 Subject: [PATCH 5/8] lastEntry to isLastEntry --- .../Scripts/AppData/Local/ILocalMetaData.cs | 4 ++-- .../Scripts/AppData/Local/LocalMetaData.cs | 8 ++++---- .../Scripts/AppUpdater/Commands/InstallDiffCommand.cs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs index 04edbe4f..7a164f2b 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/ILocalMetaData.cs @@ -17,8 +17,8 @@ public interface ILocalMetaData /// Name of the entry. /// The version id. /// Size of entry. - /// If set to true, it is last entry. - void RegisterEntry(string entryName, int versionId, long entrySize, bool lastEntry); + /// If set to true, it is last entry. + void RegisterEntry(string entryName, int versionId, long entrySize, bool isLastEntry); /// /// Unregisters the entry. diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs index 0c625bac..5a609b92 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs @@ -75,7 +75,7 @@ public string[] GetRegisteredEntries() return _data.FileVersionIds.Select(pair => pair.Key).ToArray(); } - public void RegisterEntry([NotNull] string entryName, int versionId, long entrySize, bool lastEntry) + public void RegisterEntry([NotNull] string entryName, int versionId, long entrySize, bool isLastEntry) { if (entryName == null) { @@ -99,7 +99,7 @@ public void RegisterEntry([NotNull] string entryName, int versionId, long entryS _data.FileVersionIds[entryName] = versionId; - if (ShouldSaveEntry(entrySize, lastEntry)) + if (ShouldSaveEntry(entrySize, isLastEntry)) { SaveData(); } @@ -113,9 +113,9 @@ public void RegisterEntry([NotNull] string entryName, int versionId, long entryS } } - private bool ShouldSaveEntry(long entrySize, bool lastEntry) + private bool ShouldSaveEntry(long entrySize, bool isLastEntry) { - if (lastEntry) + if (isLastEntry) { return true; } diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs index 975e200e..787e3f4c 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs @@ -458,7 +458,7 @@ private void AddDirectory(string dirName, CancellationToken cancellationToken) } private void AddFile(string fileName, string packageDirPath, string suffix, CancellationToken cancellationToken, - int index) + int fileIndex) { _logger.LogDebug(string.Format("Processing add file entry {0}", fileName)); @@ -487,7 +487,7 @@ private void AddFile(string fileName, string packageDirPath, string suffix, Canc _localMetaData.RegisterEntry(fileName, _versionId, _contentSummary.Files.First(x => x.Path == fileName).Size, - index == _diffSummary.AddedFiles.Length - 1); + fileIndex == _diffSummary.AddedFiles.Length - 1); _logger.LogDebug("Add file entry processed."); } @@ -524,7 +524,7 @@ private void ProcessModifiedFiles(string packageDirPath, string suffix, Temporar private void PatchFile( string fileName, string packageDirPath, string suffix, - TemporaryDirectory tempDiffDir, CancellationToken cancellationToken, int index) + TemporaryDirectory tempDiffDir, CancellationToken cancellationToken, int fileIndex) { _logger.LogDebug(string.Format("Processing patch file entry {0}", fileName)); @@ -582,7 +582,7 @@ private void PatchFile( _localMetaData.RegisterEntry(fileName, _versionId, _contentSummary.Files.First(x => x.Path == fileName).Size, - index == _diffSummary.ModifiedFiles.Length - 1); + fileIndex == _diffSummary.ModifiedFiles.Length - 1); _logger.LogDebug("Patch file entry processed."); } From 714f79efcb257ec666f0080e65a894cd8bdb049b Mon Sep 17 00:00:00 2001 From: Jakub Szczyrk Date: Wed, 30 Jun 2021 13:29:18 +0200 Subject: [PATCH 6/8] Saving executable name and arguments - only when changed. Update Changelog --- .../Scripts/AppData/Local/LocalMetaData.cs | 10 +++++++--- CHANGELOG.md | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs index 1f0cb260..fc55787b 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs @@ -204,10 +204,14 @@ public string GetProductKey() public void SetMainExecutableAndArgs(string mainExecutable, string mainExecutableArgs) { - _data.MainExecutable = mainExecutable; - _data.MainExecutableArgs = mainExecutableArgs; + if (!_data.MainExecutable.Contains(mainExecutable) || + !_data.MainExecutableArgs.Contains(mainExecutableArgs)) + { + _data.MainExecutable = mainExecutable; + _data.MainExecutableArgs = mainExecutableArgs; - SaveData(); + SaveData(); + } } public string GetMainExecutable() diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e3a69e8..37b7f3d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Paths too long when unpacking (#2156) +- Improved stability of saving app meta data file - caching files every 100MB +- Saving executable name and arguments - only when changed ## [3.17.6.0] ### Fixed From 387d39a8bd9906849eff61cb0741e9dae9fc03da Mon Sep 17 00:00:00 2001 From: Jakub Szczyrk Date: Thu, 1 Jul 2021 12:32:16 +0200 Subject: [PATCH 7/8] Refactoring --- .../PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs | 4 ++-- .../Scripts/AppUpdater/Commands/InstallContentCommand.cs | 4 ++-- CHANGELOG.md | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs index fc55787b..5a45594e 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/LocalMetaData.cs @@ -204,8 +204,8 @@ public string GetProductKey() public void SetMainExecutableAndArgs(string mainExecutable, string mainExecutableArgs) { - if (!_data.MainExecutable.Contains(mainExecutable) || - !_data.MainExecutableArgs.Contains(mainExecutableArgs)) + if (_data.MainExecutable != mainExecutable || + _data.MainExecutableArgs != mainExecutableArgs) { _data.MainExecutable = mainExecutable; _data.MainExecutableArgs = mainExecutableArgs; diff --git a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs index 4b5406b9..04eb8861 100644 --- a/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs +++ b/Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs @@ -186,7 +186,7 @@ private IUnarchiver CreateUnrachiver(string destinationDir, MapHashExtractedFile } } - private void InstallFile(SourceFile sourceFile, CancellationToken cancellationToken, bool lastEntry) + private void InstallFile(SourceFile sourceFile, CancellationToken cancellationToken, bool isLastEntry) { DebugLogger.Log(string.Format("Installing file {0}", sourceFile.Name)); @@ -211,7 +211,7 @@ private void InstallFile(SourceFile sourceFile, CancellationToken cancellationTo } #endif FileOperations.Move(sourceFile.FullHashPath, destinationFilePath, cancellationToken); - _localMetaData.RegisterEntry(sourceFile.Name, _versionId, sourceFile.Size, lastEntry); + _localMetaData.RegisterEntry(sourceFile.Name, _versionId, sourceFile.Size, isLastEntry); } struct SourceFile diff --git a/CHANGELOG.md b/CHANGELOG.md index 37b7f3d2..b1c71a06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Checking path length on Windows - Support for HDPI +### Changed +- Speeding up the installation/patching process due to less frequent meta data saving - caching files every 100MB +- Saving executable name and arguments - only when changed + ### Fixed - Paths too long when unpacking (#2156) -- Improved stability of saving app meta data file - caching files every 100MB -- Saving executable name and arguments - only when changed ## [3.17.6.0] ### Fixed From c79d07a399a255d2f8e4a4c8c36a14dd7cd68bd0 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Thu, 1 Jul 2021 13:14:57 +0200 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1c71a06..d109aaca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Support for HDPI ### Changed -- Speeding up the installation/patching process due to less frequent meta data saving - caching files every 100MB -- Saving executable name and arguments - only when changed +- Speed up the installation/patching process due to less frequent meta data saving ### Fixed - Paths too long when unpacking (#2156)