private static void SaveUnmodifiedFile(Filesystem.File file, string filesystemOutputDir, string outputSubfolder, string fileExtension) { string directoryPath = $"{filesystemOutputDir}{RAW_SUBDIR}{outputSubfolder}/"; Directory.CreateDirectory(directoryPath); string extraNameInfo = ""; if (file.fileTypeFromFileTable == "UVMO") { byte[] mdbgSection = file.Sections.Single(tuple => tuple.Item1 == "MDBG").Item2; string name = Encoding.ASCII.GetString(mdbgSection).Replace("\0", ""); extraNameInfo = " " + name; } string outputName = $"[0x{file.formLocationInROM:x6}]{extraNameInfo}"; AsyncWriteHelper.WriteAllBytes($"{directoryPath}{outputName}.{fileExtension}", file.bytes); }
private static void SaveFileSections(Filesystem.File file, string filesystemOutputDir, string outputSubfolder, string fileExtension) { string directoryPath = $"{filesystemOutputDir}{UNPACKED_SUBDIR}{outputSubfolder}/"; Directory.CreateDirectory(directoryPath); string extraNameInfo = ""; if (file.fileTypeFromFileTable == "UVMO") { byte[] mdbgSection = file.Sections.Single(tuple => tuple.Item1 == "MDBG").Item2; string name = Encoding.ASCII.GetString(mdbgSection).Replace("\0", ""); extraNameInfo = " " + name; } string outputName = $"[0x{file.formLocationInROM:x6}]{extraNameInfo}"; if (file.fileTypeFromFileHeader == null) // This is a UVRW file with no header { // Save file as-is AsyncWriteHelper.WriteAllBytes($"{directoryPath}{outputName}.{fileExtension}", file.bytes); } else { if (file.Sections.Count == 1) { AsyncWriteHelper.WriteAllBytes($"{directoryPath}{outputName}.{fileExtension}", file.Sections[0].Item2); } else { string unpackDir = directoryPath + outputName + "/"; Directory.CreateDirectory(unpackDir); for (int i = 0; i < file.Sections.Count; i++) { (string sectionType, byte[] sectionData) = file.Sections[i]; sectionType = sectionType.Replace('.', '_'); AsyncWriteHelper.WriteAllBytes($"{unpackDir}{i + 1:d3}.{sectionType}", sectionData); } } } }