diff --git a/MareSynchronos/Managers/TransientResourceManager.cs b/MareSynchronos/Managers/TransientResourceManager.cs index d82c61a..620f620 100644 --- a/MareSynchronos/Managers/TransientResourceManager.cs +++ b/MareSynchronos/Managers/TransientResourceManager.cs @@ -106,11 +106,11 @@ public class TransientResourceManager : IDisposable var replacedGamePath = gamePath.ToLowerInvariant().Replace("\\", "/", StringComparison.OrdinalIgnoreCase); if (TransientResources[gameObject].Contains(replacedGamePath) || - SemiTransientResources.Any(r => r.Value.Any(f => string.Equals(f.GamePaths.First(), replacedGamePath , StringComparison.OrdinalIgnoreCase) + SemiTransientResources.Any(r => r.Value.Any(f => string.Equals(f.GamePaths.First(), replacedGamePath, StringComparison.OrdinalIgnoreCase) && string.Equals(f.ResolvedPath, filePath, StringComparison.OrdinalIgnoreCase)))) { Logger.Verbose("Not adding " + replacedGamePath + ":" + filePath); - Logger.Verbose("SemiTransientAny: " + SemiTransientResources.Any(r => r.Value.Any(f => string.Equals(f.GamePaths.First(), replacedGamePath, StringComparison.OrdinalIgnoreCase) + Logger.Verbose("SemiTransientAny: " + SemiTransientResources.Any(r => r.Value.Any(f => string.Equals(f.GamePaths.First(), replacedGamePath, StringComparison.OrdinalIgnoreCase) && string.Equals(f.ResolvedPath, filePath, StringComparison.OrdinalIgnoreCase))).ToString() + ", TransientAny: " + TransientResources[gameObject].Contains(replacedGamePath)); } else @@ -141,6 +141,8 @@ public class TransientResourceManager : IDisposable return; } + SemiTransientResources[objectKind].RemoveWhere(p => !p.Verify()); + var transientResources = resources.ToList(); Logger.Debug("Persisting " + transientResources.Count + " transient resources"); foreach (var gamePath in transientResources) diff --git a/MareSynchronos/Models/FileReplacement.cs b/MareSynchronos/Models/FileReplacement.cs index 238bdc1..4dcb8c7 100644 --- a/MareSynchronos/Models/FileReplacement.cs +++ b/MareSynchronos/Models/FileReplacement.cs @@ -25,7 +25,7 @@ public class FileReplacement public bool IsFileSwap => !Regex.IsMatch(ResolvedPath, @"^[a-zA-Z]:(/|\\)", RegexOptions.ECMAScript) && !string.Equals(GamePaths.First(), ResolvedPath, System.StringComparison.Ordinal); - public string Hash { get; set; } = string.Empty; + public string Hash { get; private set; } = string.Empty; public string ResolvedPath { get; set; } = string.Empty; @@ -41,6 +41,14 @@ public class FileReplacement }); } + public bool Verify() + { + var cache = fileDbManager.GetFileCacheByPath(ResolvedPath); + if (cache == null) return false; + Hash = cache.Hash; + return true; + } + public FileReplacementDto ToFileReplacementDto() { return new FileReplacementDto diff --git a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs index 5ac17b8..f78a562 100644 --- a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs +++ b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs @@ -187,6 +187,8 @@ public partial class ApiController if (unverifiedUploadHashes.Any()) { + unverifiedUploadHashes = unverifiedUploadHashes.Where(h => _fileDbManager.GetFileCacheByHash(h) != null).ToList(); + Logger.Debug("Verifying " + unverifiedUploadHashes.Count + " files"); var filesToUpload = await FilesSend(unverifiedUploadHashes).ConfigureAwait(false); @@ -235,16 +237,24 @@ public partial class ApiController { var compressedSize = CurrentUploads.Sum(c => c.Total); Logger.Debug($"Compressed {totalSize} to {compressedSize} ({(compressedSize / (double)totalSize):P2})"); - } - Logger.Debug("Upload tasks complete, waiting for server to confirm"); - var anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false); - Logger.Debug("Uploads open: " + anyUploadsOpen); - while (anyUploadsOpen && !uploadToken.IsCancellationRequested) - { - anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false); - await Task.Delay(TimeSpan.FromSeconds(0.5), uploadToken).ConfigureAwait(false); - Logger.Debug("Waiting for uploads to finish"); + Logger.Debug("Upload tasks complete, waiting for server to confirm"); + var anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false); + Logger.Debug("Uploads open: " + anyUploadsOpen); + double timeWaited = 0; + const double waitStep = 1.0d; + while (anyUploadsOpen && !uploadToken.IsCancellationRequested && timeWaited < 5) + { + anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false); + timeWaited += waitStep; + await Task.Delay(TimeSpan.FromSeconds(waitStep), uploadToken).ConfigureAwait(false); + Logger.Debug("Waiting for uploads to finish"); + } + + if(timeWaited > waitStep) + { + await FilesAbortUpload().ConfigureAwait(false); + } } foreach (var item in unverifiedUploadHashes)