skip decimation for direct pairs and make it a toggle in settings
This commit is contained in:
@@ -89,12 +89,12 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
CurrentOwnerToken = null;
|
||||
}
|
||||
|
||||
public async Task DownloadFiles(GameObjectHandler? gameObject, List<FileReplacementData> fileReplacementDto, CancellationToken ct, bool skipDownscale = false)
|
||||
public async Task DownloadFiles(GameObjectHandler? gameObject, List<FileReplacementData> fileReplacementDto, CancellationToken ct, bool skipDownscale = false, bool skipDecimation = false)
|
||||
{
|
||||
Mediator.Publish(new HaltScanMessage(nameof(DownloadFiles)));
|
||||
try
|
||||
{
|
||||
await DownloadFilesInternal(gameObject, fileReplacementDto, ct, skipDownscale).ConfigureAwait(false);
|
||||
await DownloadFilesInternal(gameObject, fileReplacementDto, ct, skipDownscale, skipDecimation).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -498,7 +498,8 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
IReadOnlyDictionary<string, long> rawSizeLookup,
|
||||
string downloadLabel,
|
||||
CancellationToken ct,
|
||||
bool skipDownscale)
|
||||
bool skipDownscale,
|
||||
bool skipDecimation)
|
||||
{
|
||||
SetStatus(downloadStatusKey, DownloadStatus.Decompressing);
|
||||
MarkTransferredFiles(downloadStatusKey, 1);
|
||||
@@ -552,7 +553,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
}
|
||||
|
||||
await _fileCompactor.WriteAllBytesAsync(filePath, decompressed, ct).ConfigureAwait(false);
|
||||
PersistFileToStorage(fileHash, filePath, repl.GamePath, skipDownscale);
|
||||
PersistFileToStorage(fileHash, filePath, repl.GamePath, skipDownscale, skipDecimation);
|
||||
}
|
||||
catch (EndOfStreamException)
|
||||
{
|
||||
@@ -638,7 +639,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
yield return items.GetRange(i, Math.Min(chunkSize, items.Count - i));
|
||||
}
|
||||
|
||||
private async Task DownloadFilesInternal(GameObjectHandler? gameObjectHandler, List<FileReplacementData> fileReplacement, CancellationToken ct, bool skipDownscale)
|
||||
private async Task DownloadFilesInternal(GameObjectHandler? gameObjectHandler, List<FileReplacementData> fileReplacement, CancellationToken ct, bool skipDownscale, bool skipDecimation)
|
||||
{
|
||||
var objectName = gameObjectHandler?.Name ?? "Unknown";
|
||||
|
||||
@@ -742,13 +743,13 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
Task batchTask = batchChunks.Length == 0
|
||||
? Task.CompletedTask
|
||||
: Parallel.ForEachAsync(batchChunks, new ParallelOptions { MaxDegreeOfParallelism = workerDop, CancellationToken = ct },
|
||||
async (chunk, token) => await ProcessBatchChunkAsync(chunk, replacementLookup, rawSizeLookup, token, skipDownscale).ConfigureAwait(false));
|
||||
async (chunk, token) => await ProcessBatchChunkAsync(chunk, replacementLookup, rawSizeLookup, token, skipDownscale, skipDecimation).ConfigureAwait(false));
|
||||
|
||||
// direct downloads
|
||||
Task directTask = directDownloads.Count == 0
|
||||
? Task.CompletedTask
|
||||
: Parallel.ForEachAsync(directDownloads, new ParallelOptions { MaxDegreeOfParallelism = workerDop, CancellationToken = ct },
|
||||
async (d, token) => await ProcessDirectAsync(d, replacementLookup, rawSizeLookup, token, skipDownscale).ConfigureAwait(false));
|
||||
async (d, token) => await ProcessDirectAsync(d, replacementLookup, rawSizeLookup, token, skipDownscale, skipDecimation).ConfigureAwait(false));
|
||||
|
||||
await Task.WhenAll(batchTask, directTask).ConfigureAwait(false);
|
||||
|
||||
@@ -761,7 +762,8 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
Dictionary<string, (string Extension, string GamePath)> replacementLookup,
|
||||
IReadOnlyDictionary<string, long> rawSizeLookup,
|
||||
CancellationToken ct,
|
||||
bool skipDownscale)
|
||||
bool skipDownscale,
|
||||
bool skipDecimation)
|
||||
{
|
||||
var statusKey = chunk.StatusKey;
|
||||
|
||||
@@ -795,7 +797,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
return;
|
||||
}
|
||||
|
||||
await DecompressBlockFileAsync(statusKey, blockFile, replacementLookup, rawSizeLookup, fi.Name, ct, skipDownscale).ConfigureAwait(false);
|
||||
await DecompressBlockFileAsync(statusKey, blockFile, replacementLookup, rawSizeLookup, fi.Name, ct, skipDownscale, skipDecimation).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -817,7 +819,8 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
Dictionary<string, (string Extension, string GamePath)> replacementLookup,
|
||||
IReadOnlyDictionary<string, long> rawSizeLookup,
|
||||
CancellationToken ct,
|
||||
bool skipDownscale)
|
||||
bool skipDownscale,
|
||||
bool skipDecimation)
|
||||
{
|
||||
var progress = CreateInlineProgress(bytes =>
|
||||
{
|
||||
@@ -827,7 +830,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
|
||||
if (!ShouldUseDirectDownloads() || string.IsNullOrEmpty(directDownload.DirectDownloadUrl))
|
||||
{
|
||||
await ProcessDirectAsQueuedFallbackAsync(directDownload, replacementLookup, rawSizeLookup, progress, ct, skipDownscale).ConfigureAwait(false);
|
||||
await ProcessDirectAsQueuedFallbackAsync(directDownload, replacementLookup, rawSizeLookup, progress, ct, skipDownscale, skipDecimation).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -875,7 +878,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
}
|
||||
|
||||
await _fileCompactor.WriteAllBytesAsync(finalFilename, decompressedBytes, ct).ConfigureAwait(false);
|
||||
PersistFileToStorage(directDownload.Hash, finalFilename, repl.GamePath, skipDownscale);
|
||||
PersistFileToStorage(directDownload.Hash, finalFilename, repl.GamePath, skipDownscale, skipDecimation);
|
||||
|
||||
MarkTransferredFiles(directDownload.DirectDownloadUrl!, 1);
|
||||
SetStatus(directDownload.DirectDownloadUrl!, DownloadStatus.Completed);
|
||||
@@ -902,7 +905,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
|
||||
try
|
||||
{
|
||||
await ProcessDirectAsQueuedFallbackAsync(directDownload, replacementLookup, rawSizeLookup, progress, ct, skipDownscale).ConfigureAwait(false);
|
||||
await ProcessDirectAsQueuedFallbackAsync(directDownload, replacementLookup, rawSizeLookup, progress, ct, skipDownscale, skipDecimation).ConfigureAwait(false);
|
||||
|
||||
if (!expectedDirectDownloadFailure && failureCount >= 3 && !_disableDirectDownloads)
|
||||
{
|
||||
@@ -932,7 +935,8 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
IReadOnlyDictionary<string, long> rawSizeLookup,
|
||||
IProgress<long> progress,
|
||||
CancellationToken ct,
|
||||
bool skipDownscale)
|
||||
bool skipDownscale,
|
||||
bool skipDecimation)
|
||||
{
|
||||
if (string.IsNullOrEmpty(directDownload.DirectDownloadUrl))
|
||||
throw new InvalidOperationException("Direct download fallback requested without a direct download URL.");
|
||||
@@ -957,7 +961,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
if (!File.Exists(blockFile))
|
||||
throw new FileNotFoundException("Block file missing after direct download fallback.", blockFile);
|
||||
|
||||
await DecompressBlockFileAsync(statusKey, blockFile, replacementLookup, rawSizeLookup, $"fallback-{directDownload.Hash}", ct, skipDownscale)
|
||||
await DecompressBlockFileAsync(statusKey, blockFile, replacementLookup, rawSizeLookup, $"fallback-{directDownload.Hash}", ct, skipDownscale, skipDecimation)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
@@ -986,7 +990,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
return await response.Content.ReadFromJsonAsync<List<DownloadFileDto>>(cancellationToken: ct).ConfigureAwait(false) ?? [];
|
||||
}
|
||||
|
||||
private void PersistFileToStorage(string fileHash, string filePath, string gamePath, bool skipDownscale)
|
||||
private void PersistFileToStorage(string fileHash, string filePath, string gamePath, bool skipDownscale, bool skipDecimation)
|
||||
{
|
||||
var fi = new FileInfo(filePath);
|
||||
|
||||
@@ -1014,7 +1018,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
|
||||
() => _textureMetadataHelper.DetermineMapKind(gamePath, filePath));
|
||||
}
|
||||
|
||||
if (!skipDownscale && _modelDecimationService.ShouldScheduleDecimation(fileHash, filePath, gamePath))
|
||||
if (!skipDecimation && _modelDecimationService.ShouldScheduleDecimation(fileHash, filePath, gamePath))
|
||||
{
|
||||
_modelDecimationService.ScheduleDecimation(fileHash, filePath, gamePath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user