Example #1
0
        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();
            }
        }
Example #2
0
        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));
        }
Example #3
0
        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>()));
        }
Example #4
0
        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);
        }
Example #5
0
 public PakEntry(PakFile pakFile, string fileName)
 {
     Owner    = pakFile;
     FileName = fileName;
 }