2013-11-22 01:59:18 +01:00
|
|
|
#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
|
|
|
|
|
|
2022-12-30 20:34:52 -08:00
|
|
|
#include <mutex>
|
|
|
|
|
#include <set>
|
2012-04-14 07:39:22 +02:00
|
|
|
#include <string>
|
2012-03-24 23:39:19 +01:00
|
|
|
|
2020-10-04 00:25:21 +02:00
|
|
|
#include "Common/File/VFS/VFS.h"
|
2021-04-25 20:38:22 +02:00
|
|
|
#include "Common/File/FileUtil.h"
|
2021-05-15 09:54:28 -07:00
|
|
|
#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:
|
2023-03-16 22:59:26 +01:00
|
|
|
static ZipFileReader *Create(const Path &zipFile, const char *inZipPath, bool logErrors = true);
|
2023-03-06 15:30:39 +01:00
|
|
|
~ZipFileReader();
|
2023-03-06 22:46:05 +01:00
|
|
|
|
|
|
|
|
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;
|
2023-03-06 22:46:05 +01:00
|
|
|
bool GetFileInfo(VFSFileReference *vfsReference, File::FileInfo *fileInfo) override;
|
|
|
|
|
void ReleaseFile(VFSFileReference *vfsReference) override;
|
2023-03-06 17:30:13 +01:00
|
|
|
|
2023-03-08 09:11:25 +01:00
|
|
|
VFSOpenFile *OpenFileForRead(VFSFileReference *vfsReference, size_t *size) override;
|
2023-03-06 22:46:05 +01:00
|
|
|
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
|
|
|
|
2022-12-30 20:34:52 -08: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 {
|
2024-11-30 01:28:53 +01:00
|
|
|
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:
|
2024-11-30 01:28:53 +01:00
|
|
|
ZipFileReader(zip *zip_file, const Path &zipPath, const std::string &inZipPath) : zip_file_(zip_file), zipPath_(zipPath), inZipPath_(inZipPath) {}
|
2023-05-02 11:35:45 +02:00
|
|
|
// 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);
|
2022-12-30 20:34:52 -08:00
|
|
|
|
2023-03-06 22:46:05 +01:00
|
|
|
zip *zip_file_ = nullptr;
|
2022-12-30 20:34:52 -08:00
|
|
|
std::mutex lock_;
|
2023-05-02 11:35:45 +02:00
|
|
|
std::string inZipPath_;
|
2024-11-30 01:28:53 +01:00
|
|
|
Path zipPath_;
|
2012-03-24 23:39:19 +01:00
|
|
|
};
|