fixes to upload logic
This commit is contained in:
@@ -106,11 +106,11 @@ public class TransientResourceManager : IDisposable
|
|||||||
var replacedGamePath = gamePath.ToLowerInvariant().Replace("\\", "/", StringComparison.OrdinalIgnoreCase);
|
var replacedGamePath = gamePath.ToLowerInvariant().Replace("\\", "/", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
if (TransientResources[gameObject].Contains(replacedGamePath) ||
|
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))))
|
&& string.Equals(f.ResolvedPath, filePath, StringComparison.OrdinalIgnoreCase))))
|
||||||
{
|
{
|
||||||
Logger.Verbose("Not adding " + replacedGamePath + ":" + filePath);
|
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));
|
&& string.Equals(f.ResolvedPath, filePath, StringComparison.OrdinalIgnoreCase))).ToString() + ", TransientAny: " + TransientResources[gameObject].Contains(replacedGamePath));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -141,6 +141,8 @@ public class TransientResourceManager : IDisposable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SemiTransientResources[objectKind].RemoveWhere(p => !p.Verify());
|
||||||
|
|
||||||
var transientResources = resources.ToList();
|
var transientResources = resources.ToList();
|
||||||
Logger.Debug("Persisting " + transientResources.Count + " transient resources");
|
Logger.Debug("Persisting " + transientResources.Count + " transient resources");
|
||||||
foreach (var gamePath in transientResources)
|
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 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;
|
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()
|
public FileReplacementDto ToFileReplacementDto()
|
||||||
{
|
{
|
||||||
return new FileReplacementDto
|
return new FileReplacementDto
|
||||||
|
|||||||
@@ -187,6 +187,8 @@ public partial class ApiController
|
|||||||
|
|
||||||
if (unverifiedUploadHashes.Any())
|
if (unverifiedUploadHashes.Any())
|
||||||
{
|
{
|
||||||
|
unverifiedUploadHashes = unverifiedUploadHashes.Where(h => _fileDbManager.GetFileCacheByHash(h) != null).ToList();
|
||||||
|
|
||||||
Logger.Debug("Verifying " + unverifiedUploadHashes.Count + " files");
|
Logger.Debug("Verifying " + unverifiedUploadHashes.Count + " files");
|
||||||
var filesToUpload = await FilesSend(unverifiedUploadHashes).ConfigureAwait(false);
|
var filesToUpload = await FilesSend(unverifiedUploadHashes).ConfigureAwait(false);
|
||||||
|
|
||||||
@@ -235,16 +237,24 @@ public partial class ApiController
|
|||||||
{
|
{
|
||||||
var compressedSize = CurrentUploads.Sum(c => c.Total);
|
var compressedSize = CurrentUploads.Sum(c => c.Total);
|
||||||
Logger.Debug($"Compressed {totalSize} to {compressedSize} ({(compressedSize / (double)totalSize):P2})");
|
Logger.Debug($"Compressed {totalSize} to {compressedSize} ({(compressedSize / (double)totalSize):P2})");
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Debug("Upload tasks complete, waiting for server to confirm");
|
Logger.Debug("Upload tasks complete, waiting for server to confirm");
|
||||||
var anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false);
|
var anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false);
|
||||||
Logger.Debug("Uploads open: " + anyUploadsOpen);
|
Logger.Debug("Uploads open: " + anyUploadsOpen);
|
||||||
while (anyUploadsOpen && !uploadToken.IsCancellationRequested)
|
double timeWaited = 0;
|
||||||
{
|
const double waitStep = 1.0d;
|
||||||
anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false);
|
while (anyUploadsOpen && !uploadToken.IsCancellationRequested && timeWaited < 5)
|
||||||
await Task.Delay(TimeSpan.FromSeconds(0.5), uploadToken).ConfigureAwait(false);
|
{
|
||||||
Logger.Debug("Waiting for uploads to finish");
|
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)
|
foreach (var item in unverifiedUploadHashes)
|
||||||
|
|||||||
Reference in New Issue
Block a user