Archived
1
Fork 0

Allow specifying an install directory for game

This commit is contained in:
Joshua Goins 2022-03-16 18:33:22 -04:00
parent 970931f048
commit ffb3350ddc
2 changed files with 28 additions and 6 deletions

View file

@ -2,4 +2,4 @@
#include <string_view> #include <string_view>
void extractBootstrapFiles(const std::string_view installer); void extractBootstrapFiles(const std::string_view installer, const std::string_view directory);

View file

@ -4,6 +4,7 @@
#include <stdexcept> #include <stdexcept>
#include <libunshield.h> #include <libunshield.h>
#include <fmt/format.h> #include <fmt/format.h>
#include <filesystem>
const std::array filesToExtract = {"data1.cab", "data1.hdr", "data2.cab"}; const std::array filesToExtract = {"data1.cab", "data1.hdr", "data2.cab"};
@ -32,7 +33,7 @@ const std::array gameComponent = {
"ffxivgame.ver" "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"); FILE* file = fopen(installer.data(), "rb");
if(file == nullptr) { if(file == nullptr) {
throw std::runtime_error("Failed to open installer {}" + std::string(installer)); 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) { if(lastNeedle != nullptr) {
FILE* newFile = fopen(lastFilename.data(), "wb"); FILE* newFile = fopen(lastFilename.data(), "wb");
fmt::print("Wrote {}!\n", lastFilename);
if(lastFilename == "data1.hdr") { if(lastFilename == "data1.hdr") {
fwrite(lastNeedle + 30, p - lastNeedle - 42, 1, newFile); fwrite(lastNeedle + 30, p - lastNeedle - 42, 1, newFile);
@ -79,6 +81,7 @@ void extractBootstrapFiles(const std::string_view installer) {
lastFilename = fileName; lastFilename = fileName;
lastNeedle = p; lastNeedle = p;
fileSize -= (p + 4) - buffer; fileSize -= (p + 4) - buffer;
buffer = p + realFileName.length();
} }
// write final file // write final file
@ -90,6 +93,21 @@ void extractBootstrapFiles(const std::string_view installer) {
fclose(newFile); 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"); auto unshield = unshield_open("data1.cab");
const int fileCount = unshield_file_count(unshield); const int fileCount = unshield_file_count(unshield);
@ -99,15 +117,19 @@ void extractBootstrapFiles(const std::string_view installer) {
for(auto bootName : bootComponent) { for(auto bootName : bootComponent) {
fmt::print("Extracted {}\n", bootName); fmt::print("Extracted {}\n", bootName);
if(strcmp(filename, bootName) == 0) if(strcmp(filename, bootName) == 0) {
unshield_file_save(unshield, i, bootName); std::string saveFilename = fmt::format("{}/boot/{}", directory, bootName);
unshield_file_save(unshield, i, saveFilename.data());
}
} }
for(auto gameName : gameComponent) { for(auto gameName : gameComponent) {
fmt::print("Extracted {}\n", gameName); fmt::print("Extracted {}\n", gameName);
if(strcmp(filename, gameName) == 0) if(strcmp(filename, gameName) == 0) {
unshield_file_save(unshield, i, gameName); std::string saveFilename = fmt::format("{}/game/{}", directory, gameName);
unshield_file_save(unshield, i, saveFilename.data());
}
} }
} }