CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/File/VFS/ZipFileReader.h
Views: 1401
1
#pragma once
2
3
#ifdef SHARED_LIBZIP
4
#include <zip.h>
5
#else
6
#include "ext/libzip/zip.h"
7
#endif
8
9
#include <mutex>
10
#include <set>
11
#include <string>
12
13
#include "Common/File/VFS/VFS.h"
14
#include "Common/File/FileUtil.h"
15
#include "Common/File/Path.h"
16
17
class ZipFileReader : public VFSBackend {
18
public:
19
static ZipFileReader *Create(const Path &zipFile, const char *inZipPath, bool logErrors = true);
20
~ZipFileReader();
21
22
bool IsValid() const { return zip_file_ != nullptr; }
23
24
// use delete[] on the returned value.
25
uint8_t *ReadFile(const char *path, size_t *size) override;
26
27
VFSFileReference *GetFile(const char *path) override;
28
bool GetFileInfo(VFSFileReference *vfsReference, File::FileInfo *fileInfo) override;
29
void ReleaseFile(VFSFileReference *vfsReference) override;
30
31
VFSOpenFile *OpenFileForRead(VFSFileReference *vfsReference, size_t *size) override;
32
void Rewind(VFSOpenFile *vfsOpenFile) override;
33
size_t Read(VFSOpenFile *vfsOpenFile, void *buffer, size_t length) override;
34
void CloseFile(VFSOpenFile *vfsOpenFile) override;
35
36
bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter) override;
37
bool GetFileInfo(const char *path, File::FileInfo *info) override;
38
std::string toString() const override {
39
return inZipPath_;
40
}
41
42
private:
43
ZipFileReader(zip *zip_file, const std::string &inZipPath) : zip_file_(zip_file), inZipPath_(inZipPath) {}
44
// Path has to be either an empty string, or a string ending with a /.
45
bool GetZipListings(const std::string &path, std::set<std::string> &files, std::set<std::string> &directories);
46
47
zip *zip_file_ = nullptr;
48
std::mutex lock_;
49
std::string inZipPath_;
50
};
51
52