/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "ExeAppendedZipLoader.hpp" #include "Base/Logger.hpp" #include "IO/Archive/ArchiveReader.hpp" #include #include namespace OpenVulkano { std::string ExeAppendedZipLoader::GetResourcePath(const std::string& resourceName) { return GetCurrentExecutablePath(); } Array ExeAppendedZipLoader::GetResource(const std::string& exeName) { std::string ext = std::filesystem::path(exeName).extension().string(); if (ext != ".exe" && ext != "") { Logger::DATA->debug("Given file {} is not a valid executable", exeName); return {}; } std::ifstream ifs(exeName, std::ios::in | std::ios::binary); if (!ifs.is_open()) { Logger::DATA->debug("Could not open file {}.", exeName); return {}; } ifs.seekg(0, std::ios_base::end); size_t zipSize = ifs.tellg(); ifs.seekg(0, std::ios_base::beg); Array zipData(zipSize); ifs.read(zipData.Data(), zipSize); ifs.close(); return zipData; } std::vector>> ExeAppendedZipLoader::GetZipArchiveFiles(const std::string& exePath) { Array zipData = GetResource(exePath); ArchiveReader reader(zipData.Data(), zipData.Size(), nullptr, ArchiveType::ZIP); std::vector>> filesFromZip; while (reader.HasNext()) { filesFromZip.push_back(*reader.GetNextFile()); } return filesFromZip; } }