Added embedded libzip
Prefixed all libzip zip_ funcs to fs_zip_ to avoid clashes and link errors due to assimp Zip pack and zip writer work with libzip now
This commit was merged in pull request #2.
This commit is contained in:
+50
-27
@@ -3,18 +3,40 @@
|
||||
#include "tl/result.h"
|
||||
#include "tl/string.h"
|
||||
#include "tl/vector_map.h"
|
||||
#include "fs/IStreamSource.h"
|
||||
|
||||
#include "fs/IPack.h"
|
||||
#include "fs/AbsPath.h"
|
||||
#include "fs/zip/ZipReader.h"
|
||||
|
||||
#include "fs/Api.h"
|
||||
|
||||
struct zip;
|
||||
struct zip_source;
|
||||
struct zip_file;
|
||||
namespace tl
|
||||
{
|
||||
template<> struct ptr_traits<zip>
|
||||
{
|
||||
static constexpr inline bool custom_deleter = true;
|
||||
static constexpr inline bool requires_virtual_destructor_check = false;
|
||||
};
|
||||
//template<> struct ptr_traits<zip_source>
|
||||
//{
|
||||
// static constexpr inline bool custom_deleter = true;
|
||||
// static constexpr inline bool requires_virtual_destructor_check = false;
|
||||
//};
|
||||
template<> struct ptr_traits<zip_file>
|
||||
{
|
||||
static constexpr inline bool custom_deleter = true;
|
||||
static constexpr inline bool requires_virtual_destructor_check = false;
|
||||
};
|
||||
}
|
||||
|
||||
namespace fs
|
||||
{
|
||||
class MapSourceView;
|
||||
|
||||
class FS_API ZipPack final : virtual public IPack
|
||||
class FS_API ZipPack final : public IPack
|
||||
{
|
||||
public:
|
||||
ZipPack() = default;
|
||||
@@ -22,10 +44,10 @@ public:
|
||||
|
||||
typedef tl::result<tl::unique_ref<ZipPack>, Error> CreateResult;
|
||||
|
||||
static CreateResult create(tl::unique_ref<IMapSource> zipFileSource);
|
||||
static CreateResult create(tl::lent_ref<const IFilesystem> filesystem, AbsPathView zipFileLocation);
|
||||
static CreateResult create(tl::unique_ref<IMapSource> source);
|
||||
static CreateResult create(tl::lent_ref<const IFilesystem> filesystem, AbsPathView path);
|
||||
|
||||
virtual void setEncryptionData(const tl::string& key, uint32_t rounds);
|
||||
void setEncryptionData(const tl::string& key, uint32_t rounds);
|
||||
|
||||
OpenSourceResult openSource(AbsPathView path, SourceFlags flags = SourceFlags()) const override;
|
||||
OpenStreamSourceResult openStreamSource(AbsPathView path, SourceFlags flags = SourceFlags()) const override;
|
||||
@@ -42,46 +64,51 @@ public:
|
||||
|
||||
tl::result<AbsPath, Error> convertToNativePath(AbsPathView path) const override;
|
||||
|
||||
struct ZipData
|
||||
{
|
||||
tl::unique_ptr<IMapSource> fsMapSource;
|
||||
|
||||
tl::lent_ptr<const IFilesystem> filesystem;
|
||||
AbsPath path;
|
||||
tl::unique_ptr<ISource> fsSource;
|
||||
uint64_t cachedSize = uint64_t(-1);
|
||||
|
||||
//tl::unique_ptr<zip_source> zipSource;
|
||||
tl::unique_ptr<zip> zipArchive;
|
||||
};
|
||||
|
||||
protected:
|
||||
struct File;
|
||||
struct Folder;
|
||||
struct EntryIndex;
|
||||
|
||||
ZipPack(tl::unique_ref<IMapSource> zipFileSource, ZipReader zipReader);
|
||||
ZipPack(tl::lent_ref<const IFilesystem> filesystem, AbsPathView zipFileLocation, ZipReader zipReader);
|
||||
ZipPack(tl::shared_ptr<ZipData> data);
|
||||
|
||||
OpenMapSourceResult openRawMapSource(const File& file, MapView mapView) const;
|
||||
OpenSourceResult openRawSource(const File& file) const;
|
||||
//OpenMapSourceResult openRawMapSource(const File& file, MapView mapView) const;
|
||||
//OpenSourceResult openRawSource(const File& file) const;
|
||||
|
||||
OpenSourceResult openZipSource(const File& file) const;
|
||||
OpenMapSourceResult openZipMapSource(const File& file) const;
|
||||
OpenStreamSourceResult openZipStreamSource(const File& file) const;
|
||||
OpenSourceResult _openSource(const File& file) const;
|
||||
OpenMapSourceResult _openMapSource(const File& file) const;
|
||||
OpenStreamSourceResult _openStreamSource(const File& file) const;
|
||||
|
||||
uint16_t getOrAddFolder(AbsPathView folderPath, tl::vector<tl::vector<EntryIndex>>& io_childrenIndices);
|
||||
void createEntries(ZipReader zipReader);
|
||||
void createEntries(zip& archive);
|
||||
|
||||
struct File
|
||||
{
|
||||
uint16_t zipIndex = 0; //index inside the zip archive
|
||||
tl::string name;
|
||||
uint8_t isCompressed : 1;
|
||||
uint8_t uncompressedSizeH = 0;
|
||||
uint8_t compressedSizeH = 0;
|
||||
uint8_t dataOffsetH = 0;
|
||||
uint16_t parentIndex = 0;
|
||||
uint32_t lastModTimePoint = 0;
|
||||
uint32_t uncompressedSizeL = 0;
|
||||
uint32_t compressedSizeL = 0;
|
||||
uint32_t dataOffsetL = 0;
|
||||
};
|
||||
static_assert(sizeof(File) <= sizeof(tl::string) + 40, "Check your sizes!!!");
|
||||
|
||||
struct Folder
|
||||
{
|
||||
uint16_t zipIndex = 0; //index inside the zip archive
|
||||
tl::string name;
|
||||
uint16_t parentIndex = 0;
|
||||
uint16_t childrenStartIndex = 0; // this is an index inside m_childrenIndices
|
||||
uint16_t childrenCount = 0;
|
||||
uint32_t lastModTimePoint = 0;
|
||||
};
|
||||
static_assert(sizeof(Folder) <= sizeof(tl::string) + 20, "Check your sizes!!!");
|
||||
|
||||
@@ -99,12 +126,8 @@ protected:
|
||||
static_assert(sizeof(EntryIndex) == 4, "Check your sizes!!!");
|
||||
|
||||
private:
|
||||
tl::lent_ptr<const IFilesystem> m_filesystem;
|
||||
|
||||
mutable std::mutex m_zipMapSourceLock;
|
||||
tl::unique_ptr<IMapSource> m_zipMapSource;
|
||||
|
||||
AbsPath m_zipFileLocation;
|
||||
tl::shared_ptr<ZipData> m_zipData;
|
||||
|
||||
tl::string m_encryptionKey;
|
||||
uint32_t m_encryptionRounds = 32;
|
||||
|
||||
Reference in New Issue
Block a user