diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index ba06d95d88..2fd57ae3af 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -15,6 +15,8 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include + #include "Common/File/FileUtil.h" #include "Common/File/Path.h" #include "Common/StringUtils.h" @@ -352,6 +354,34 @@ inline char asciitolower(char in) { return in; } +static bool ZipExtractFileToMemory(struct zip *z, int fileIndex, std::string *data) { + struct zip_stat zstat; + zip_stat_index(z, fileIndex, 0, &zstat); + if (zstat.size == 0) { + data->clear(); + return true; + } + + size_t readSize = zstat.size; + data->resize(readSize); + + zip_file *zf = zip_fopen_index(z, fileIndex, 0); + if (!zf) { + ERROR_LOG(Log::HLE, "Failed to zip_fopen_index file %d from zip", fileIndex); + return false; + } + + zip_int64_t retval = zip_fread(zf, data->data(), readSize); + zip_fclose(zf); + + if (retval < 0 || retval < (int)readSize) { + ERROR_LOG(Log::HLE, "Failed to read %d bytes from zip (%d) - archive corrupt?", (int)readSize, (int)retval); + return false; + } else { + return true; + } +} + void DetectZipFileContents(struct zip *z, ZipFileInfo *info) { int numFiles = zip_get_num_files(z); _dbg_assert_(numFiles >= 0); diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index a0972e5f2b..a3cbf82314 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -473,34 +473,6 @@ std::string GameManager::GetISOGameID(FileLoader *loader) const { return sfo.GetValueString("DISC_ID"); } -bool ZipExtractFileToMemory(struct zip *z, int fileIndex, std::string *data) { - struct zip_stat zstat; - zip_stat_index(z, fileIndex, 0, &zstat); - if (zstat.size == 0) { - data->clear(); - return true; - } - - size_t readSize = zstat.size; - data->resize(readSize); - - zip_file *zf = zip_fopen_index(z, fileIndex, 0); - if (!zf) { - ERROR_LOG(Log::HLE, "Failed to zip_fopen_index file %d from zip", fileIndex); - return false; - } - - zip_int64_t retval = zip_fread(zf, data->data(), readSize); - zip_fclose(zf); - - if (retval < 0 || retval < (int)readSize) { - ERROR_LOG(Log::HLE, "Failed to read %d bytes from zip (%d) - archive corrupt?", (int)readSize, (int)retval); - return false; - } else { - return true; - } -} - bool GameManager::ExtractFile(struct zip *z, int file_index, const Path &outFilename, size_t *bytesCopied, size_t allBytes) { struct zip_stat zstat; zip_stat_index(z, file_index, 0, &zstat); diff --git a/Core/Util/GameManager.h b/Core/Util/GameManager.h index 30ebc72a27..7bbb315dc9 100644 --- a/Core/Util/GameManager.h +++ b/Core/Util/GameManager.h @@ -122,8 +122,4 @@ extern GameManager g_GameManager; struct zip *ZipOpenPath(Path fileName); void ZipClose(zip *z); -void DetectZipFileContents(struct zip *z, ZipFileInfo *info); -bool DetectZipFileContents(const Path &fileName, ZipFileInfo *info); - -bool ZipExtractFileToMemory(struct zip *z, int fileIndex, std::string *data); bool CanExtractWithoutOverwrite(struct zip *z, const Path &destination, int maxOkFiles);