From b5b5a583027cb864fdf6ad0a3ae2e89577a434a5 Mon Sep 17 00:00:00 2001 From: Dan Lilja Date: Tue, 20 Sep 2022 05:36:34 +0200 Subject: [PATCH] Bugfix/version file creation (#1475) * Added creation of version file to OTRExporter * Removed creation of version file from other places * Made path to version file portable * Changed spaces to tabs in OTRExporter/Main.cpp --- OTRExporter/OTRExporter/Main.cpp | 22 +++++++++++++++++++--- OTRExporter/extract_assets.py | 4 ---- OTRGui/src/game/game.cpp | 1 - OTRGui/src/impl/extractor/extractor.cpp | 4 ++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/OTRExporter/OTRExporter/Main.cpp b/OTRExporter/OTRExporter/Main.cpp index e0a5254c5..a199e1885 100644 --- a/OTRExporter/OTRExporter/Main.cpp +++ b/OTRExporter/OTRExporter/Main.cpp @@ -63,13 +63,29 @@ static void ExporterProgramEnd() { if (Globals::Instance->fileMode == ZFileMode::ExtractDirectory) { + printf("Creating version file...\n"); + + // Get crc from rom + std::string romPath = Globals::Instance->baseRomPath.string(); + std::vector romData = File::ReadAllBytes(romPath); + uint32_t crc = BitConverter::ToUInt32BE(romData, 0x10); + + // Write crc to version file + fs::path versionPath("Extract/version"); + std::ofstream versionFile(versionPath.c_str(), std::ios::out | std::ios::binary); + versionFile.write((char*)&crc, sizeof(crc)); + versionFile.flush(); + versionFile.close(); + + printf("Created version file.\n"); + printf("Generating OTR Archive...\n"); otrArchive = Ship::Archive::CreateArchive(otrFileName, 40000); - for (auto item : files) - { + for (auto item : files) { auto fileData = item.second; - otrArchive->AddFile(item.first, (uintptr_t)fileData.data(), fileData.size()); + otrArchive->AddFile(item.first, (uintptr_t)fileData.data(), + fileData.size()); } // Add any additional files that need to be manually copied... diff --git a/OTRExporter/extract_assets.py b/OTRExporter/extract_assets.py index 7fd05739b..ada474212 100755 --- a/OTRExporter/extract_assets.py +++ b/OTRExporter/extract_assets.py @@ -11,10 +11,6 @@ import argparse def BuildOTR(xmlPath, rom, zapd_exe=None): shutil.copytree("assets", "Extract/assets") - checksum = int(Z64Rom(rom).checksum.value, 16) - with open("Extract/version", "wb") as f: - f.write(struct.pack('