#include "ZWrapper.h" #include #include #include #include "spdlog/spdlog.h" #include #include namespace fs = std::filesystem; ZWrapper::ZWrapper(const std::string& path) { this->mPath = path; this->mZip = new miniz_cpp::zip_file; } int32_t ZWrapper::CreateArchive() { SPDLOG_INFO("Loaded ZIP (O2R) archive: {}", mPath.c_str()); return 0; } bool ZWrapper::AddFile(const std::string& path, std::vector data) { char* fileData = data.data(); size_t fileSize = data.size(); if (Companion::Instance != nullptr && Companion::Instance->IsDebug()) { SPDLOG_INFO("Creating debug file: debug/{}", path); std::string dpath = "debug/" + path; if (!fs::exists(fs::path(dpath).parent_path())) { fs::create_directories(fs::path(dpath).parent_path()); } std::ofstream stream(dpath, std::ios::binary); stream.write(fileData, fileSize); stream.close(); } try { this->mZip->writebytes(path, data); } catch (const std::exception& e) { // miniz's own error says nothing useful, so log which entry blew up and how big. SPDLOG_ERROR("[ZWrapper] Failed to add '{}' ({} bytes): {}", path, fileSize, e.what()); throw; } return true; } int32_t ZWrapper::Close(void) { this->mZip->save(this->mPath); return 0; }