public void decryptFSTEntryTo(FSTEntry entry, String outputFolder, bool skipExistingFiles) { decryptFSTEntryTo(false, entry, outputFolder, NUSTitle.skipExistingFiles); }
public void decryptFSTEntryTo(FSTEntry entry, String outputFolder) { decryptFSTEntryTo(false, entry, outputFolder); }
public void decryptFSTEntryTo(bool fullPath, FSTEntry entry, String outputFolder) { decryptFSTEntryTo(fullPath, entry, outputFolder, NUSTitle.skipExistingFiles); }
public void decryptFSTEntryTo(bool useFullPath, FSTEntry entry, String outputPath, bool skipExistingFile) { if (entry.isNotInPackage || entry.content == null) { return; } //MessageBox.Show("Decrypting " + entry.getFilename()); string targetFilePath = new StringBuilder().Append(outputPath).Append("/").Append(entry.filename).ToString(); string fullPath = new StringBuilder().Append(outputPath).ToString(); if (useFullPath) { targetFilePath = new StringBuilder().Append(outputPath).Append(entry.getFullPath()).ToString(); fullPath = new StringBuilder().Append(outputPath).Append(entry.path).ToString(); if (entry.isDir) { // If the entry is a directory. Create it and return. Directory.CreateDirectory(targetFilePath); return; } } else if (entry.isDir) { return; } try { Directory.CreateDirectory(fullPath); } catch (Exception) { return; } FileInfo target = new FileInfo(targetFilePath); if (skipExistingFile) { FileInfo targetFile = new FileInfo(targetFilePath); if (targetFile.Exists) { if (entry.isDir) { return; } if (targetFile.Length == entry.fileSize) { Content c = entry.content; if (c.isHashed()) { //MessageBox.Show("File already exists: " + entry.filename); return; } else { //MessageBox.Show("File already exists"); //if (Arrays.Equals(HashUtil.hashSHA1(target, (int) c.getDecryptedFileSize()), c.SHA2Hash)) { // MessageBox.Show("File already exists: " + entry.filename); // return; //} else { // MessageBox.Show("File already exists with the same filesize, but the hash doesn't match: " + entry.getFilename()); //} } } else { //MessageBox.Show("File already exists but the filesize doesn't match: " + entry.filename); } } } FileStream sr = new FileStream(targetFilePath, FileMode.Create); BinaryWriter outputStream = new BinaryWriter(sr); try { decryptFSTEntryToStream(entry, outputStream); } catch (Exception e) { if (entry.filename.EndsWith(".xml") && Utils.checkXML(new FileInfo(targetFilePath))) { //MessageBox.Show("Hash doesn't match, but it's an XML file and it looks okay."); } else { //MessageBox.Show("Hash doesn't match!"); throw e; } } }