public static PakFile?Open(FileInfo fileInfo, IVersionProvider?versionProvider = null, IAesKeyProvider?keyProvider = null) { if (fileInfo is null) { throw new ArgumentNullException(nameof(fileInfo)); } if (!fileInfo.Exists) { throw new FileNotFoundException(); } var aesProvider = keyProvider is null ? null : new AesPakCryptoProvider(keyProvider); var fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize); if (ReadPakInfo(fileStream, fileStream.Length, aesProvider, out var info)) { var file = new PakFile(fileInfo.Name, fileStream.Length, fileStream, versionProvider, aesProvider); file.Initialize(info); return(file); } else { fileStream.Dispose(); throw new NotPakFileException(); } }
public static PakVFS OpenAt(string path, IVersionProvider?versionProvider = null, IAesKeyProvider?keyProvider = null) { if (path is null) { throw new ArgumentNullException(nameof(path)); } var dir = new DirectoryInfo(path); if (!dir.Exists) { throw new DirectoryNotFoundException(); } var paks = dir.GetFiles(PakExtensionPattern).Select(f => PakFile.Open(f, versionProvider, keyProvider)).OfType <PakFile>(); return(new PakVFS(paks)); }
public async static ValueTask <PakVFS> OpenAtAsync(string path, IVersionProvider?versionProvider = null, IAesKeyProvider?keyProvider = null, CancellationToken cancellationToken = default) { if (path is null) { throw new ArgumentNullException(nameof(path)); } var dir = new DirectoryInfo(path); if (!dir.Exists) { throw new DirectoryNotFoundException(); } var files = dir.GetFiles(PakExtensionPattern); var tasks = files.Select(f => PakFile.OpenAsync(f, versionProvider, cancellationToken: cancellationToken)); var paks = await Task.WhenAll(tasks).ConfigureAwait(false); return(new PakVFS(paks.OfType <PakFile>())); }
public async static Task <PakFile?> OpenAsync(FileInfo fileInfo, IVersionProvider?versionProvider = null, IAesKeyProvider?keyProvider = null, CancellationToken cancellationToken = default) { if (fileInfo is null) { throw new ArgumentNullException(nameof(fileInfo)); } if (!fileInfo.Exists) { throw new FileNotFoundException(); } var aesProvider = keyProvider is null ? null : new AesPakCryptoProvider(keyProvider); var fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize); if (ReadPakInfo(fileStream, fileStream.Length, aesProvider, out var info)) { var file = new PakFile(fileInfo.Name, fileStream.Length, fileStream, versionProvider, aesProvider); await file.InitializeAsync(info, cancellationToken).ConfigureAwait(false); return(file); } return(null); }
public PakEntry(PakFile pakFile, string fileName) { Owner = pakFile; FileName = fileName; }