Skip to content

Commit 4ddf887

Browse files
committed
RandomAccessStream changes
1 parent 6285804 commit 4ddf887

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

FModel/ViewModels/ApiEndpoints/ValorantApiEndpoint.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public readonly struct VChunk
179179
public string GetUrl() => $"https://fmodel.fortnite-api.com/valorant/v2/chunks/{Id}";
180180
}
181181

182-
public class VPakStream : Stream, IRandomAccessStream, ICloneable
182+
public class VPakStream : RandomAccessStream, ICloneable
183183
{
184184
private readonly VManifest _manifest;
185185
private readonly int _pakIndex;
@@ -206,7 +206,7 @@ public VPakStream(VManifest manifest, int pakIndex, long position = 0L)
206206
public override int Read(byte[] buffer, int offset, int count) =>
207207
ReadAsync(buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
208208

209-
public int ReadAt(long position, byte[] buffer, int offset, int count) =>
209+
public override int ReadAt(long position, byte[] buffer, int offset, int count) =>
210210
ReadAtAsync(position, buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
211211

212212
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
@@ -216,7 +216,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
216216
return bytesRead;
217217
}
218218

219-
public async Task<int> ReadAtAsync(long position, byte[] buffer, int offset, int count, CancellationToken cancellationToken)
219+
public override async Task<int> ReadAtAsync(long position, byte[] buffer, int offset, int count, CancellationToken cancellationToken = default)
220220
{
221221
var (i, startPos) = GetChunkIndex(position);
222222
if (i == -1) return 0;
@@ -248,11 +248,6 @@ public async Task<int> ReadAtAsync(long position, byte[] buffer, int offset, int
248248
return bytesRead;
249249
}
250250

251-
public Task<int> ReadAtAsync(long position, Memory<byte> memory, CancellationToken cancellationToken)
252-
{
253-
throw new NotSupportedException();
254-
}
255-
256251
private async Task PrefetchAsync(int i, uint startPos, long count, CancellationToken cancellationToken, int concurrentDownloads = 4)
257252
{
258253
var tasks = new List<Task>();
@@ -262,7 +257,7 @@ private async Task PrefetchAsync(int i, uint startPos, long count, CancellationT
262257
await s.WaitAsync(cancellationToken).ConfigureAwait(false);
263258

264259
var chunk = _chunks[i++];
265-
tasks.Add(PrefetchChunkAsync(chunk));
260+
tasks.Add(PrefetchChunkAsync(_manifest, chunk, s, cancellationToken));
266261

267262
if (i == _chunks.Length) break;
268263
count -= chunk.Size - startPos;
@@ -271,11 +266,12 @@ private async Task PrefetchAsync(int i, uint startPos, long count, CancellationT
271266

272267
await Task.WhenAll(tasks).ConfigureAwait(false);
273268
s.Dispose();
269+
return;
274270

275-
async Task PrefetchChunkAsync(VChunk chunk)
271+
static async Task PrefetchChunkAsync(VManifest manifest, VChunk chunk, SemaphoreSlim semaphore, CancellationToken cancellationToken)
276272
{
277-
await _manifest.PrefetchChunk(chunk, cancellationToken).ConfigureAwait(false);
278-
s.Release(); // This is intended
273+
await manifest.PrefetchChunk(chunk, cancellationToken).ConfigureAwait(false);
274+
semaphore.Release();
279275
}
280276
}
281277

0 commit comments

Comments
 (0)