fixes to upload logic
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user