ppsspp/ext/native/file/zip_read.h

82 lines
2.2 KiB
C
Raw Normal View History

2012-03-31 09:16:13 +00:00
// TODO: Move much of this code to vfs.cpp
#pragma once
2012-03-31 09:16:13 +00:00
2012-11-27 15:38:24 +00:00
#ifdef ANDROID
2012-03-24 22:39:19 +00:00
#include <zip.h>
#endif
#include <string.h>
2012-04-14 05:39:22 +00:00
#include <string>
2012-03-24 22:39:19 +00:00
#include "base/basictypes.h"
#include "file/vfs.h"
2012-11-27 15:38:24 +00:00
#include "file/file_util.h"
2012-03-24 22:39:19 +00:00
// Direct readers. deallocate using delete [].
uint8_t *ReadLocalFile(const char *filename, size_t *size);
class AssetReader {
public:
2012-10-31 12:23:16 +00:00
virtual ~AssetReader() {}
// use delete[]
virtual uint8_t *ReadAsset(const char *path, size_t *size) = 0;
2012-11-27 15:38:24 +00:00
// Filter support is optional but nice to have
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter = 0) = 0;
virtual bool GetFileInfo(const char *path, FileInfo *info) = 0;
2012-10-31 12:23:16 +00:00
virtual std::string toString() const = 0;
2012-03-24 22:39:19 +00:00
};
#ifdef USING_QT_UI
class AssetsAssetReader : public AssetReader {
public:
AssetsAssetReader() {}
~AssetsAssetReader() {}
// use delete[]
virtual uint8_t *ReadAsset(const char *path, size_t *size);
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter);
virtual bool GetFileInfo(const char *path, FileInfo *info);
virtual std::string toString() const {
return ":assets/";
}
};
#endif
2012-11-27 15:38:24 +00:00
#ifdef ANDROID
2012-03-24 22:39:19 +00:00
uint8_t *ReadFromZip(zip *archive, const char* filename, size_t *size);
class ZipAssetReader : public AssetReader {
public:
2012-10-31 12:23:16 +00:00
ZipAssetReader(const char *zip_file, const char *in_zip_path);
~ZipAssetReader();
// use delete[]
virtual uint8_t *ReadAsset(const char *path, size_t *size);
2012-11-27 15:38:24 +00:00
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter);
virtual bool GetFileInfo(const char *path, FileInfo *info);
2012-10-31 12:23:16 +00:00
virtual std::string toString() const {
return in_zip_path_;
}
2012-03-24 22:39:19 +00:00
private:
2012-10-31 12:23:16 +00:00
zip *zip_file_;
char in_zip_path_[256];
2012-03-24 22:39:19 +00:00
};
#endif
class DirectoryAssetReader : public AssetReader {
public:
2012-10-31 12:23:16 +00:00
DirectoryAssetReader(const char *path) {
2015-01-18 21:15:18 +00:00
strncpy(path_, path, ARRAY_SIZE(path_));
path_[ARRAY_SIZE(path_) - 1] = '\0';
2012-10-31 12:23:16 +00:00
}
// use delete[]
virtual uint8_t *ReadAsset(const char *path, size_t *size);
2012-11-27 15:38:24 +00:00
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter);
virtual bool GetFileInfo(const char *path, FileInfo *info);
2012-10-31 12:23:16 +00:00
virtual std::string toString() const {
return path_;
}
2012-03-24 22:39:19 +00:00
private:
2012-10-31 12:23:16 +00:00
char path_[512];
2012-03-24 22:39:19 +00:00
};