From 57d3296ba4e5c1fc7ca30376c7ca8eb3041ae2f6 Mon Sep 17 00:00:00 2001 From: Mary Date: Sun, 28 Nov 2021 21:24:17 +0100 Subject: infra: Migrate to .NET 6 (#2829) * infra: Migrate to .NET 6 * Rollback version naming change * Workaround .NET 6 ZipArchive API issues * ci: Switch to VS 2022 for AppVeyor CI is now ready for .NET 6 * Suppress WebClient warning in DoUpdateWithMultipleThreads * Attempt to workaround System.Drawing.Common changes on 6.0.0 * Change keyboard rendering from System.Drawing to ImageSharp * Make the software keyboard renderer multithreaded * Bump ImageSharp version to 1.0.4 to fix a bug in Image.Load * Add fallback fonts to the keyboard renderer * Fix warnings * Address caian's comment * Clean up linux workaround as it's uneeded now * Update readme Co-authored-by: Caian Benedicto --- Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs | 38 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs') diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs index 09107346..ee4e1265 100644 --- a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs +++ b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs @@ -1,4 +1,5 @@ -using Ryujinx.Common; +using ICSharpCode.SharpZipLib.Zip; +using Ryujinx.Common; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; @@ -9,7 +10,6 @@ using Ryujinx.Graphics.Shader.Translation; using System; using System.Collections.Generic; using System.IO; -using System.IO.Compression; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -192,19 +192,19 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// The given hash /// The cached file if present or null [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static byte[] ReadFromArchive(ZipArchive archive, Hash128 entry) + public static byte[] ReadFromArchive(ZipFile archive, Hash128 entry) { if (archive != null) { - ZipArchiveEntry archiveEntry = archive.GetEntry($"{entry}"); + ZipEntry archiveEntry = archive.GetEntry($"{entry}"); if (archiveEntry != null) { try { - byte[] result = new byte[archiveEntry.Length]; + byte[] result = new byte[archiveEntry.Size]; - using (Stream archiveStream = archiveEntry.Open()) + using (Stream archiveStream = archive.GetInputStream(archiveEntry)) { archiveStream.Read(result); @@ -538,8 +538,12 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// The archive to use /// The entries in the cache [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void EnsureArchiveUpToDate(string baseCacheDirectory, ZipArchive archive, HashSet entries) + public static void EnsureArchiveUpToDate(string baseCacheDirectory, ZipFile archive, HashSet entries) { + List filesToDelete = new List(); + + archive.BeginUpdate(); + foreach (Hash128 hash in entries) { string cacheTempFilePath = GenCacheTempFilePath(baseCacheDirectory, hash); @@ -548,15 +552,25 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache { string cacheHash = $"{hash}"; - ZipArchiveEntry entry = archive.GetEntry(cacheHash); - - entry?.Delete(); + ZipEntry entry = archive.GetEntry(cacheHash); - archive.CreateEntryFromFile(cacheTempFilePath, cacheHash); + if (entry != null) + { + archive.Delete(entry); + } - File.Delete(cacheTempFilePath); + // We enforce deflate compression here to avoid possible incompatibilities on older version of Ryujinx that use System.IO.Compression. + archive.Add(new StaticDiskDataSource(cacheTempFilePath), cacheHash, CompressionMethod.Deflated); + filesToDelete.Add(cacheTempFilePath); } } + + archive.CommitUpdate(); + + foreach (string filePath in filesToDelete) + { + File.Delete(filePath); + } } public static bool IsArchiveReadOnly(string archivePath) -- cgit v1.2.3