Skip to content

Commit

Permalink
Remove some ifdefs
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 6, 2023
1 parent 3b39e9e commit 7649794
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
16 changes: 5 additions & 11 deletions Common/File/VFS/AssetReader.cpp
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -173,8 +169,6 @@ bool ZipAssetReader::GetFileInfo(const char *path, File::FileInfo *info) {
return true;
}

#endif

DirectoryAssetReader::DirectoryAssetReader(const Path &path) {
path_ = path;
}
Expand Down
21 changes: 4 additions & 17 deletions 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 <zip.h>
#else
#include "ext/libzip/zip.h"
#endif

#include <mutex>
Expand All @@ -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;
Expand All @@ -46,7 +34,6 @@ class ZipAssetReader : public AssetReader {
std::mutex lock_;
char in_zip_path_[256];
};
#endif

class DirectoryAssetReader : public AssetReader {
public:
Expand Down
11 changes: 10 additions & 1 deletion Common/File/VFS/VFS.h
Expand Up @@ -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:
Expand Down

0 comments on commit 7649794

Please sign in to comment.