ppsspp/file/zip_read.h

65 lines
1.7 KiB
C
Raw Normal View History

2012-03-31 09:16:13 +00:00
// TODO: Move much of this code to vfs.cpp
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
};
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) {
strcpy(path_, path);
}
// 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
};