Files
ppsspp/Common/File/VFS/ZipFileReader.h

57 lines
1.8 KiB
C
Raw Permalink Normal View History

#pragma once
2012-03-31 11:16:13 +02:00
2023-03-06 14:29:47 +01:00
#ifdef SHARED_LIBZIP
2012-03-24 23:39:19 +01:00
#include <zip.h>
2023-03-06 14:29:47 +01:00
#else
#include "ext/libzip/zip.h"
2012-03-24 23:39:19 +01:00
#endif
#include <mutex>
#include <set>
2012-04-14 07:39:22 +02:00
#include <string>
2012-03-24 23:39:19 +01:00
#include "Common/File/VFS/VFS.h"
#include "Common/File/FileUtil.h"
#include "Common/File/Path.h"
2012-03-24 23:39:19 +01:00
2023-03-06 15:30:39 +01:00
class ZipFileReader : public VFSBackend {
2012-03-24 23:39:19 +01:00
public:
static ZipFileReader *Create(const Path &zipFile, const char *inZipPath, bool logErrors = true);
2023-03-06 15:30:39 +01:00
~ZipFileReader();
bool IsValid() const { return zip_file_ != nullptr; }
2023-03-06 14:29:47 +01:00
// use delete[] on the returned value.
2023-03-06 15:30:39 +01:00
uint8_t *ReadFile(const char *path, size_t *size) override;
2023-03-06 17:30:13 +01:00
VFSFileReference *GetFile(const char *path) override;
bool GetFileInfo(VFSFileReference *vfsReference, File::FileInfo *fileInfo) override;
void ReleaseFile(VFSFileReference *vfsReference) override;
2023-03-06 17:30:13 +01:00
VFSOpenFile *OpenFileForRead(VFSFileReference *vfsReference, size_t *size) override;
void Rewind(VFSOpenFile *vfsOpenFile) override;
size_t Read(VFSOpenFile *vfsOpenFile, void *buffer, size_t length) override;
void CloseFile(VFSOpenFile *vfsOpenFile) override;
2023-03-06 17:30:13 +01:00
bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter) override;
bool GetFileInfo(const char *path, File::FileInfo *info) override;
std::string toString() const override {
std::string retval = zipPath_.ToVisualString();
if (!inZipPath_.empty()) {
retval += ": ";
retval += inZipPath_;
}
return retval;
2012-10-31 13:23:16 +01:00
}
2012-03-24 23:39:19 +01:00
private:
ZipFileReader(zip *zip_file, const Path &zipPath, const std::string &inZipPath) : zip_file_(zip_file), zipPath_(zipPath), inZipPath_(inZipPath) {}
// Path has to be either an empty string, or a string ending with a /.
bool GetZipListings(const std::string &path, std::set<std::string> &files, std::set<std::string> &directories);
zip *zip_file_ = nullptr;
std::mutex lock_;
std::string inZipPath_;
Path zipPath_;
2012-03-24 23:39:19 +01:00
};