From ffb3350ddc65e8248173716e84e25c7fc5aad271 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 16 Mar 2022 18:33:22 -0400 Subject: [PATCH] Allow specifying an install directory for game --- include/installextract.h | 2 +- src/installextract.cpp | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/installextract.h b/include/installextract.h index 3264e92..36fd16f 100644 --- a/include/installextract.h +++ b/include/installextract.h @@ -2,4 +2,4 @@ #include -void extractBootstrapFiles(const std::string_view installer); \ No newline at end of file +void extractBootstrapFiles(const std::string_view installer, const std::string_view directory); \ No newline at end of file diff --git a/src/installextract.cpp b/src/installextract.cpp index 0d27b49..4268477 100644 --- a/src/installextract.cpp +++ b/src/installextract.cpp @@ -4,6 +4,7 @@ #include #include #include +#include const std::array filesToExtract = {"data1.cab", "data1.hdr", "data2.cab"}; @@ -32,7 +33,7 @@ const std::array gameComponent = { "ffxivgame.ver" }; -void extractBootstrapFiles(const std::string_view installer) { +void extractBootstrapFiles(const std::string_view installer, const std::string_view directory) { FILE* file = fopen(installer.data(), "rb"); if(file == nullptr) { throw std::runtime_error("Failed to open installer {}" + std::string(installer)); @@ -65,6 +66,7 @@ void extractBootstrapFiles(const std::string_view installer) { if(lastNeedle != nullptr) { FILE* newFile = fopen(lastFilename.data(), "wb"); + fmt::print("Wrote {}!\n", lastFilename); if(lastFilename == "data1.hdr") { fwrite(lastNeedle + 30, p - lastNeedle - 42, 1, newFile); @@ -79,6 +81,7 @@ void extractBootstrapFiles(const std::string_view installer) { lastFilename = fileName; lastNeedle = p; fileSize -= (p + 4) - buffer; + buffer = p + realFileName.length(); } // write final file @@ -90,6 +93,21 @@ void extractBootstrapFiles(const std::string_view installer) { fclose(newFile); } + if(!std::filesystem::exists(directory)) { + fmt::print("Game install directory doesn't exist yet, creating...\n"); + std::filesystem::create_directories(directory); + } + + if(!std::filesystem::exists(std::filesystem::path(directory) / "boot")) { + fmt::print("Boot directory doesn't exist yet, creating...\n"); + std::filesystem::create_directory(std::filesystem::path(directory) / "boot"); + } + + if(!std::filesystem::exists(std::filesystem::path(directory) / "game")) { + fmt::print("Game directory doesn't exist yet, creating...\n"); + std::filesystem::create_directory(std::filesystem::path(directory) / "game"); + } + auto unshield = unshield_open("data1.cab"); const int fileCount = unshield_file_count(unshield); @@ -99,15 +117,19 @@ void extractBootstrapFiles(const std::string_view installer) { for(auto bootName : bootComponent) { fmt::print("Extracted {}\n", bootName); - if(strcmp(filename, bootName) == 0) - unshield_file_save(unshield, i, bootName); + if(strcmp(filename, bootName) == 0) { + std::string saveFilename = fmt::format("{}/boot/{}", directory, bootName); + unshield_file_save(unshield, i, saveFilename.data()); + } } for(auto gameName : gameComponent) { fmt::print("Extracted {}\n", gameName); - if(strcmp(filename, gameName) == 0) - unshield_file_save(unshield, i, gameName); + if(strcmp(filename, gameName) == 0) { + std::string saveFilename = fmt::format("{}/game/{}", directory, gameName); + unshield_file_save(unshield, i, saveFilename.data()); + } } }