Example #1
0
        public void CompressXCI(string xciFile)
        {
            var xciFileNoExtension = Path.GetFileNameWithoutExtension(xciFile);

            Out.Event($"Task CompressXCI \"{xciFileNoExtension}\" started\r\n");
            var keyset = ProcessKeyset.OpenKeyset();

            ProcessXci.Decrypt(xciFile, decryptedDir, VerifyHashes, keyset, Out);
            CompressFolder.Compress(Out, decryptedDir, compressedDir, BlockSize, ZstdLevel, MaxDegreeOfParallelism);

            if (VerifyHashes)
            {
                var decryptedFs           = new LocalFileSystem(decryptedDir);
                var dirDecryptedRealCount = decryptedFs.GetEntryCount(OpenDirectoryMode.Files);
                cleanFolder(decryptedDir);
                var compressedFs = new LocalFileSystem(compressedDir);
                DecompressFs.ProcessFs(compressedFs, decryptedFs, Out);

                var dirDecryptedCount = decryptedFs.GetEntryCount(OpenDirectoryMode.Files);
                if (dirDecryptedRealCount != dirDecryptedCount)
                {
                    throw new FileNotFoundException();
                }

                EncryptNCA.Encrypt(decryptedFs, null, true, keyset, Out);
            }

            var compressedDirFs = new LocalFileSystem(compressedDir);
            var xciOutPath      = Path.Combine(OutputFolderPath, xciFileNoExtension);

            FolderTools.FolderToXCI(compressedDirFs, $"{xciOutPath}.xciz", keyset);
            Out.Event($"Task CompressXCI \"{xciFileNoExtension}\" completed!\r\n");
        }