mirror of
https://github.com/4sval/FModel.git
synced 2026-04-24 23:10:44 -05:00
RandomAccessStream changes
This commit is contained in:
parent
6285804cc9
commit
4ddf887ba3
|
|
@ -179,7 +179,7 @@ public readonly struct VChunk
|
|||
public string GetUrl() => $"https://fmodel.fortnite-api.com/valorant/v2/chunks/{Id}";
|
||||
}
|
||||
|
||||
public class VPakStream : Stream, IRandomAccessStream, ICloneable
|
||||
public class VPakStream : RandomAccessStream, ICloneable
|
||||
{
|
||||
private readonly VManifest _manifest;
|
||||
private readonly int _pakIndex;
|
||||
|
|
@ -206,7 +206,7 @@ public class VPakStream : Stream, IRandomAccessStream, ICloneable
|
|||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
ReadAsync(buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
|
||||
|
||||
public int ReadAt(long position, byte[] buffer, int offset, int count) =>
|
||||
public override int ReadAt(long position, byte[] buffer, int offset, int count) =>
|
||||
ReadAtAsync(position, buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
|
||||
|
||||
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
|
|
@ -216,7 +216,7 @@ public class VPakStream : Stream, IRandomAccessStream, ICloneable
|
|||
return bytesRead;
|
||||
}
|
||||
|
||||
public async Task<int> ReadAtAsync(long position, byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
public override async Task<int> ReadAtAsync(long position, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var (i, startPos) = GetChunkIndex(position);
|
||||
if (i == -1) return 0;
|
||||
|
|
@ -248,11 +248,6 @@ public class VPakStream : Stream, IRandomAccessStream, ICloneable
|
|||
return bytesRead;
|
||||
}
|
||||
|
||||
public Task<int> ReadAtAsync(long position, Memory<byte> memory, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
private async Task PrefetchAsync(int i, uint startPos, long count, CancellationToken cancellationToken, int concurrentDownloads = 4)
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
|
|
@ -262,7 +257,7 @@ public class VPakStream : Stream, IRandomAccessStream, ICloneable
|
|||
await s.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var chunk = _chunks[i++];
|
||||
tasks.Add(PrefetchChunkAsync(chunk));
|
||||
tasks.Add(PrefetchChunkAsync(_manifest, chunk, s, cancellationToken));
|
||||
|
||||
if (i == _chunks.Length) break;
|
||||
count -= chunk.Size - startPos;
|
||||
|
|
@ -271,11 +266,12 @@ public class VPakStream : Stream, IRandomAccessStream, ICloneable
|
|||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
s.Dispose();
|
||||
return;
|
||||
|
||||
async Task PrefetchChunkAsync(VChunk chunk)
|
||||
static async Task PrefetchChunkAsync(VManifest manifest, VChunk chunk, SemaphoreSlim semaphore, CancellationToken cancellationToken)
|
||||
{
|
||||
await _manifest.PrefetchChunk(chunk, cancellationToken).ConfigureAwait(false);
|
||||
s.Release(); // This is intended
|
||||
await manifest.PrefetchChunk(chunk, cancellationToken).ConfigureAwait(false);
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user