Remove some ifdefs

This commit is contained in:
Henrik Rydgård 2023-03-06 14:29:47 +01:00
parent 3b39e9e068
commit 7649794164
3 changed files with 19 additions and 29 deletions

View File

@ -3,15 +3,16 @@
#include <set>
#include <stdio.h>
#ifdef __ANDROID__
#ifdef SHARED_LIBZIP
#include <zip.h>
#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<std::string> &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;
}

View File

@ -1,8 +1,9 @@
// TODO: Move much of this code to vfs.cpp
#pragma once
#ifdef __ANDROID__
#ifdef SHARED_LIBZIP
#include <zip.h>
#else
#include "ext/libzip/zip.h"
#endif
#include <mutex>
@ -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<File::FileInfo> *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<File::FileInfo> *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:

View File

@ -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<File::FileInfo> *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: