mirror of
https://github.com/4sval/FModel.git
synced 2026-04-07 09:36:29 -05:00
make use of RandomAccess archives
Some checks failed
FModel QA Builder / build (push) Has been cancelled
Some checks failed
FModel QA Builder / build (push) Has been cancelled
This commit is contained in:
parent
bde2ce54ed
commit
cd3a41d18c
|
|
@ -1 +1 @@
|
|||
Subproject commit 76fcf8cca1e5cc0e8949f56eecdf43986235706b
|
||||
Subproject commit f30b4807467a6d91bdb10210ff20db5812160bbf
|
||||
|
|
@ -15,7 +15,7 @@ using CUE4Parse.UE4.Readers;
|
|||
|
||||
using FModel.Framework;
|
||||
using FModel.Settings;
|
||||
|
||||
using OffiUtils;
|
||||
using RestSharp;
|
||||
|
||||
namespace FModel.ViewModels.ApiEndpoints;
|
||||
|
|
@ -117,7 +117,7 @@ public class VManifest
|
|||
return chunkBytes;
|
||||
}
|
||||
|
||||
public Stream GetPakStream(int index) => new VPakStream(this, index);
|
||||
public VPakStream GetPakStream(int index) => new VPakStream(this, index);
|
||||
}
|
||||
|
||||
public readonly struct VHeader
|
||||
|
|
@ -179,7 +179,7 @@ public readonly struct VChunk
|
|||
public string GetUrl() => $"https://fmodel.fortnite-api.com/valorant/v2/chunks/{Id}";
|
||||
}
|
||||
|
||||
public class VPakStream : Stream, ICloneable
|
||||
public class VPakStream : Stream, IRandomAccessStream, ICloneable
|
||||
{
|
||||
private readonly VManifest _manifest;
|
||||
private readonly int _pakIndex;
|
||||
|
|
@ -203,11 +203,22 @@ public class VPakStream : Stream, ICloneable
|
|||
|
||||
public object Clone() => new VPakStream(_manifest, _pakIndex, _position);
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) => ReadAsync(buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
|
||||
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) =>
|
||||
ReadAtAsync(position, buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
|
||||
|
||||
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
var (i, startPos) = GetChunkIndex(_position);
|
||||
var bytesRead = await ReadAtAsync(_position, buffer, offset, count, cancellationToken);
|
||||
_position += bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
public async Task<int> ReadAtAsync(long position, byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
var (i, startPos) = GetChunkIndex(position);
|
||||
if (i == -1) return 0;
|
||||
|
||||
await PrefetchAsync(i, startPos, count, cancellationToken).ConfigureAwait(false);
|
||||
|
|
@ -234,10 +245,14 @@ public class VPakStream : Stream, ICloneable
|
|||
if (++i == _chunks.Length) break;
|
||||
}
|
||||
|
||||
_position += bytesRead;
|
||||
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>();
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ using FModel.Views.Resources.Controls;
|
|||
using FModel.Views.Snooper;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using OffiUtils;
|
||||
using OpenTK.Windowing.Common;
|
||||
using OpenTK.Windowing.Desktop;
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ public class CUE4ParseViewModel : ViewModel
|
|||
continue;
|
||||
}
|
||||
|
||||
p.RegisterVfs(fileManifest.FileName, [fileManifest.GetStream()]
|
||||
p.RegisterVfs(fileManifest.FileName, [(IRandomAccessStream)fileManifest.GetStream()]
|
||||
, it => new FRandomAccessStreamArchive(it, manifest.FileManifestList.First(x => x.FileName.Equals(it)).GetStream(), p.Versions));
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ public class CUE4ParseViewModel : ViewModel
|
|||
|
||||
for (var i = 0; i < manifestInfo.Paks.Length; i++)
|
||||
{
|
||||
p.RegisterVfs(manifestInfo.Paks[i].GetFullName(), [manifestInfo.GetPakStream(i)]);
|
||||
p.RegisterVfs(manifestInfo.Paks[i].GetFullName(), [(IRandomAccessStream)manifestInfo.GetPakStream(i)]);
|
||||
}
|
||||
|
||||
FLogger.Append(ELog.Information, () =>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user