sigma update
This commit is contained in:
@@ -2,6 +2,7 @@ using LightlessSync.Interop.Ipc;
|
||||
using LightlessSync.FileCache;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Penumbra.Api.Enums;
|
||||
using System.Globalization;
|
||||
|
||||
namespace LightlessSync.Services.TextureCompression;
|
||||
|
||||
@@ -27,7 +28,9 @@ public sealed class TextureCompressionService
|
||||
public async Task ConvertTexturesAsync(
|
||||
IReadOnlyList<TextureCompressionRequest> requests,
|
||||
IProgress<TextureConversionProgress>? progress,
|
||||
CancellationToken token)
|
||||
CancellationToken token,
|
||||
bool requestRedraw = true,
|
||||
bool includeMipMaps = true)
|
||||
{
|
||||
if (requests.Count == 0)
|
||||
{
|
||||
@@ -48,7 +51,7 @@ public sealed class TextureCompressionService
|
||||
continue;
|
||||
}
|
||||
|
||||
await RunPenumbraConversionAsync(request, textureType, total, completed, progress, token).ConfigureAwait(false);
|
||||
await RunPenumbraConversionAsync(request, textureType, total, completed, progress, token, requestRedraw, includeMipMaps).ConfigureAwait(false);
|
||||
|
||||
completed++;
|
||||
}
|
||||
@@ -65,14 +68,16 @@ public sealed class TextureCompressionService
|
||||
int total,
|
||||
int completedBefore,
|
||||
IProgress<TextureConversionProgress>? progress,
|
||||
CancellationToken token)
|
||||
CancellationToken token,
|
||||
bool requestRedraw,
|
||||
bool includeMipMaps)
|
||||
{
|
||||
var primaryPath = request.PrimaryFilePath;
|
||||
var displayJob = new TextureConversionJob(
|
||||
primaryPath,
|
||||
primaryPath,
|
||||
targetType,
|
||||
IncludeMipMaps: true,
|
||||
IncludeMipMaps: includeMipMaps,
|
||||
request.DuplicateFilePaths);
|
||||
|
||||
var backupPath = CreateBackupCopy(primaryPath);
|
||||
@@ -83,7 +88,7 @@ public sealed class TextureCompressionService
|
||||
try
|
||||
{
|
||||
WaitForAccess(primaryPath);
|
||||
await _ipcManager.Penumbra.ConvertTextureFiles(_logger, new[] { conversionJob }, null, token).ConfigureAwait(false);
|
||||
await _ipcManager.Penumbra.ConvertTextureFiles(_logger, new[] { conversionJob }, null, token, requestRedraw).ConfigureAwait(false);
|
||||
|
||||
if (!IsValidConversionResult(displayJob.OutputFile))
|
||||
{
|
||||
@@ -128,19 +133,46 @@ public sealed class TextureCompressionService
|
||||
var cacheEntries = _fileCacheManager.GetFileCachesByPaths(paths.ToArray());
|
||||
foreach (var path in paths)
|
||||
{
|
||||
var hasExpectedHash = TryGetExpectedHashFromPath(path, out var expectedHash);
|
||||
if (!cacheEntries.TryGetValue(path, out var entry) || entry is null)
|
||||
{
|
||||
entry = _fileCacheManager.CreateFileEntry(path);
|
||||
if (hasExpectedHash)
|
||||
{
|
||||
entry = _fileCacheManager.CreateCacheEntryWithKnownHash(path, expectedHash);
|
||||
}
|
||||
|
||||
entry ??= _fileCacheManager.CreateFileEntry(path);
|
||||
if (entry is null)
|
||||
{
|
||||
_logger.LogWarning("Unable to locate cache entry for {Path}; skipping hash refresh", path);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (hasExpectedHash && entry.IsCacheEntry && !string.Equals(entry.Hash, expectedHash, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_logger.LogDebug("Fixing cache hash mismatch for {Path}: {Current} -> {Expected}", path, entry.Hash, expectedHash);
|
||||
_fileCacheManager.RemoveHashedFile(entry.Hash, entry.PrefixedFilePath, removeDerivedFiles: false);
|
||||
var corrected = _fileCacheManager.CreateCacheEntryWithKnownHash(path, expectedHash);
|
||||
if (corrected is not null)
|
||||
{
|
||||
entry = corrected;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_fileCacheManager.UpdateHashedFile(entry);
|
||||
if (entry.IsCacheEntry)
|
||||
{
|
||||
var info = new FileInfo(path);
|
||||
entry.Size = info.Length;
|
||||
entry.CompressedSize = null;
|
||||
entry.LastModifiedDateTicks = info.LastWriteTimeUtc.Ticks.ToString(CultureInfo.InvariantCulture);
|
||||
_fileCacheManager.UpdateHashedFile(entry, computeProperties: false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileCacheManager.UpdateHashedFile(entry);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -149,6 +181,35 @@ public sealed class TextureCompressionService
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetExpectedHashFromPath(string path, out string hash)
|
||||
{
|
||||
hash = Path.GetFileNameWithoutExtension(path);
|
||||
if (string.IsNullOrWhiteSpace(hash))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hash.Length is not (40 or 64))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < hash.Length; i++)
|
||||
{
|
||||
var c = hash[i];
|
||||
var isHex = (c >= '0' && c <= '9')
|
||||
|| (c >= 'a' && c <= 'f')
|
||||
|| (c >= 'A' && c <= 'F');
|
||||
if (!isHex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
hash = hash.ToUpperInvariant();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static readonly string WorkingDirectory =
|
||||
Path.Combine(Path.GetTempPath(), "LightlessSync.TextureCompression");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user