aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs
diff options
context:
space:
mode:
authorMary <me@thog.eu>2021-11-28 21:24:17 +0100
committerGitHub <noreply@github.com>2021-11-28 21:24:17 +0100
commit57d3296ba4e5c1fc7ca30376c7ca8eb3041ae2f6 (patch)
tree02e17606a847ff11f68bc7bf123e882f87055b52 /Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs
parent7b040e51b078a16e979ad962ba1265f3be4bcb1d (diff)
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 <caianbene@gmail.com>
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs')
-rw-r--r--Ryujinx.Graphics.Gpu/Shader/Cache/CacheHelper.cs38
1 files changed, 26 insertions, 12 deletions
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
/// <param name="entry">The given hash</param>
/// <returns>The cached file if present or null</returns>
[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
/// <param name="archive">The archive to use</param>
/// <param name="entries">The entries in the cache</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void EnsureArchiveUpToDate(string baseCacheDirectory, ZipArchive archive, HashSet<Hash128> entries)
+ public static void EnsureArchiveUpToDate(string baseCacheDirectory, ZipFile archive, HashSet<Hash128> entries)
{
+ List<string> filesToDelete = new List<string>();
+
+ 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)