Skip to content

Commit 2ccfbb0

Browse files
committed
CDN fixes
1 parent 79740e7 commit 2ccfbb0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

TACTSharp/CDN.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,22 +319,21 @@ public unsafe bool TryGetLocalFile(string eKey, out ReadOnlySpan<byte> data)
319319
if (!string.IsNullOrEmpty(Settings.CDNDir))
320320
{
321321
var cdnPath = Path.Combine(Settings.CDNDir, ProductDirectory, "data", $"{archive[0]}{archive[1]}", $"{archive[2]}{archive[3]}", archive);
322+
FileLocks.TryAdd(cdnPath, new Lock());
322323
if (File.Exists(cdnPath))
323324
{
324-
if (new FileInfo(cdnPath).Length != (offset + size))
325-
Console.WriteLine("Warning! Found " + archive + " in CDN dir but size is lower than offset+size " + offset + size + " != " + new FileInfo(cachePath).Length + ", continuing to download.");
325+
if (new FileInfo(cdnPath).Length < (offset + size))
326+
Console.WriteLine("Warning! Found " + archive + " in CDN dir but size is lower than offset+size " + offset + size + " != " + new FileInfo(cdnPath).Length + ", continuing to download.");
326327
else
327328
{
328329
lock (FileLocks[cdnPath])
329330
{
330-
using (var ms = new MemoryStream())
331+
using (var fs = new FileStream(cdnPath, FileMode.Open, FileAccess.Read))
331332
{
332-
using (var fs = new FileStream(cdnPath, FileMode.Open, FileAccess.Read))
333-
{
334-
var buffer = new byte[size];
335-
fs.ReadExactly(buffer, offset, size);
336-
return buffer;
337-
}
333+
var buffer = new byte[size];
334+
fs.Seek(offset, SeekOrigin.Begin);
335+
fs.ReadExactly(buffer);
336+
return buffer;
338337
}
339338
}
340339
}

0 commit comments

Comments
 (0)