Skip to content

Commit 38d0fc4

Browse files
committed
in case of network issues, try to reuse the latest local cache file
1 parent db0d826 commit 38d0fc4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

IrdLibraryClient/RedumpClient.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Net.Http;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -77,16 +78,34 @@ public class RedumpClient
7778
catch (Exception e)
7879
{
7980
Log.Warn(e, $"Failed to download redump snapshot {filename}: {e.Message}");
80-
return LatestSnapshot;
8181
}
8282
}
8383
else
84-
Log.Warn("Returned snapshot was in unexpected format, ignoring");
84+
Log.Warn("Snapshot response was in an unexpected format, ignoring");
8585
}
8686
catch (Exception e)
8787
{
8888
Log.Error(e);
8989
}
90+
91+
Log.Info("Trying to search local cache...");
92+
var latestLocalCache = Directory.GetFiles(localCachePath, "Sony*Disc*Keys*.zip").MaxBy(n => n, StringComparer.OrdinalIgnoreCase);
93+
if (latestLocalCache is not null)
94+
try
95+
{
96+
var fn = Path.GetFileName(latestLocalCache);
97+
Log.Info($"Using latest local redump key cache: {fn}");
98+
await using var file = File.Open(fn, FileMode.Open, FileAccess.Read, FileShare.Read);
99+
var result = new MemoryStream();
100+
await file.CopyToAsync(result, cancellationToken).ConfigureAwait(false);
101+
result.Seek(0, SeekOrigin.Begin);
102+
LatestSnapshot = result;
103+
}
104+
catch (Exception e)
105+
{
106+
Log.Warn(e, "Failed to read local cache file");
107+
}
108+
90109
return LatestSnapshot;
91110
}
92111
}

Ps3DiscDumper/DiscKeyProviders/RedumpProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public async Task<HashSet<DiscKeyInfo>> EnumerateAsync(string discKeyCachePath,
3434
}
3535
else
3636
{
37+
3738
var assembly = Assembly.GetExecutingAssembly();
3839
var embeddedResources = assembly.GetManifestResourceNames().Where(n => n.Contains("Disc_Keys") || n.Contains("Disc Keys")).ToList();
3940
if (embeddedResources is { Count: > 0 })

0 commit comments

Comments
 (0)