public void CompressNSP(string nspFile) { var nspFileNoExtension = Path.GetFileNameWithoutExtension(nspFile); Out.Event($"Task CompressNSP \"{nspFileNoExtension}\" started\r\n"); var keyset = ProcessKeyset.OpenKeyset(); using (var inputFile = new FileStream(nspFile, FileMode.Open, FileAccess.Read)) using (var inputFileStorage = inputFile.AsStorage()) { var pfs = new PartitionFileSystem(inputFileStorage); ProcessNsp.Decrypt(pfs, decryptedDir, VerifyHashes, keyset, Out); TrimDeltaNCA.Process(decryptedDir, keyset, Out); CompressFolder.Compress(Out, decryptedDir, compressedDir, BlockSize, ZstdLevel, MaxDegreeOfParallelism); if (VerifyHashes) { var dirDecryptedReal = new DirectoryInfo(decryptedDir); var dirDecryptedRealCount = dirDecryptedReal.GetFiles().Length; cleanFolder(decryptedDir); var compressedFs = new LocalFileSystem(compressedDir); var decryptedFs = new LocalFileSystem(decryptedDir); DecompressFs.ProcessFs(compressedFs, decryptedFs, Out); UntrimDeltaNCA.Process(decryptedDir, pfs, keyset, Out); var dirDecrypted = new DirectoryInfo(decryptedDir); var dirDecryptedCount = dirDecrypted.GetFiles().Length; if (dirDecryptedRealCount != dirDecryptedCount) { throw new FileNotFoundException(); } EncryptNCA.Encrypt(compressedFs, null, true, keyset, Out); } } var compressedDirFs = new LocalFileSystem(compressedDir); var OutputFolderPathFs = new LocalFileSystem(OutputFolderPath); using (var outFile = FolderTools.CreateOrOverwriteFileOpen(OutputFolderPathFs, $"{nspFileNoExtension}.nspz")) { FolderTools.FolderToNSP(compressedDirFs, outFile); } Out.Event($"Task CompressNSP \"{nspFileNoExtension}\" completed!\r\n"); }
public void DecompressNSPZ(string nspzFile) { var nspzFileNoExtension = Path.GetFileNameWithoutExtension(nspzFile); Out.Event($"Task DecompressNSPZ \"{nspzFileNoExtension}\" started\r\n"); var keyset = ProcessKeyset.OpenKeyset(); ProcessNsp.Decompress(nspzFile, decryptedDir, Out); UntrimAndEncrypt(keyset); var nspOutPath = Path.Combine(OutputFolderPath, nspzFileNoExtension); var encryptedDirFs = new LocalFileSystem(encryptedDir); var OutputFolderPathFs = new LocalFileSystem(OutputFolderPath); using (var outFile = FolderTools.CreateOrOverwriteFileOpen(OutputFolderPathFs, $"{nspzFileNoExtension}.nsp")) { FolderTools.FolderToNSP(encryptedDirFs, outFile); } Out.Event($"Task DecompressNSPZ \"{nspzFileNoExtension}\" completed!\r\n"); }