diff --git a/Common/File/VFS/AssetReader.cpp b/Common/File/VFS/AssetReader.cpp index 306cd0c5e0..64116703b9 100644 --- a/Common/File/VFS/AssetReader.cpp +++ b/Common/File/VFS/AssetReader.cpp @@ -3,15 +3,16 @@ #include #include -#ifdef __ANDROID__ +#ifdef SHARED_LIBZIP #include +#else +#include "ext/libzip/zip.h" #endif #include "Common/Common.h" #include "Common/Log.h" #include "Common/File/VFS/AssetReader.h" -#ifdef __ANDROID__ uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size) { // Figure out the file size first. struct zip_stat zstat; @@ -31,10 +32,6 @@ uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size) { return contents; } -#endif - -#ifdef __ANDROID__ - ZipAssetReader::ZipAssetReader(const char *zip_file, const char *in_zip_path) { zip_file_ = zip_open(zip_file, 0, NULL); strcpy(in_zip_path_, in_zip_path); @@ -155,9 +152,8 @@ void ZipAssetReader::GetZipListings(const char *path, std::set &fil bool ZipAssetReader::GetFileInfo(const char *path, File::FileInfo *info) { struct zip_stat zstat; char temp_path[1024]; - strcpy(temp_path, in_zip_path_); - strcat(temp_path, path); - if (0 != zip_stat(zip_file_, temp_path, ZIP_FL_NOCASE|ZIP_FL_UNCHANGED, &zstat)) { + snprintf(temp_path, sizeof(temp_path), "%s%s", in_zip_path_, path); + if (0 != zip_stat(zip_file_, temp_path, ZIP_FL_NOCASE | ZIP_FL_UNCHANGED, &zstat)) { // ZIP files do not have real directories, so we'll end up here if we // try to stat one. For now that's fine. info->exists = false; @@ -173,8 +169,6 @@ bool ZipAssetReader::GetFileInfo(const char *path, File::FileInfo *info) { return true; } -#endif - DirectoryAssetReader::DirectoryAssetReader(const Path &path) { path_ = path; } diff --git a/Common/File/VFS/AssetReader.h b/Common/File/VFS/AssetReader.h index 8352f8eea8..b1ec629725 100644 --- a/Common/File/VFS/AssetReader.h +++ b/Common/File/VFS/AssetReader.h @@ -1,8 +1,9 @@ -// TODO: Move much of this code to vfs.cpp #pragma once -#ifdef __ANDROID__ +#ifdef SHARED_LIBZIP #include +#else +#include "ext/libzip/zip.h" #endif #include @@ -14,24 +15,11 @@ #include "Common/File/FileUtil.h" #include "Common/File/Path.h" -class AssetReader { -public: - virtual ~AssetReader() {} - // use delete[] - virtual uint8_t *ReadAsset(const char *path, size_t *size) = 0; - // Filter support is optional but nice to have - virtual bool GetFileListing(const char *path, std::vector *listing, const char *filter = 0) = 0; - virtual bool GetFileInfo(const char *path, File::FileInfo *info) = 0; - virtual std::string toString() const = 0; -}; - -#ifdef __ANDROID__ -uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size); class ZipAssetReader : public AssetReader { public: ZipAssetReader(const char *zip_file, const char *in_zip_path); ~ZipAssetReader(); - // use delete[] + // use delete[] on the returned value. uint8_t *ReadAsset(const char *path, size_t *size) override; bool GetFileListing(const char *path, std::vector *listing, const char *filter) override; bool GetFileInfo(const char *path, File::FileInfo *info) override; @@ -46,7 +34,6 @@ private: std::mutex lock_; char in_zip_path_[256]; }; -#endif class DirectoryAssetReader : public AssetReader { public: diff --git a/Common/File/VFS/VFS.h b/Common/File/VFS/VFS.h index baaeebf068..c6a2479e80 100644 --- a/Common/File/VFS/VFS.h +++ b/Common/File/VFS/VFS.h @@ -8,7 +8,16 @@ // read them manually out of the APK zipfile, while being able to run on other // platforms as well with the appropriate directory set-up. -class AssetReader; +class AssetReader { +public: + virtual ~AssetReader() {} + // use delete[] + virtual uint8_t *ReadAsset(const char *path, size_t *size) = 0; + // Filter support is optional but nice to have + virtual bool GetFileListing(const char *path, std::vector *listing, const char *filter = 0) = 0; + virtual bool GetFileInfo(const char *path, File::FileInfo *info) = 0; + virtual std::string toString() const = 0; +}; class VFS { public: