Oxygine
1
2g game engine
oxygine
src
core
ZipFileSystem.h
1
#pragma once
2
#include "oxygine-include.h"
3
#include <vector>
4
#include "FileSystem.h"
5
#include "minizip/unzip.h"
6
#include "core/file.h"
7
#include "core/Mutex.h"
8
#include <unordered_map>
9
10
namespace
oxygine
11
{
12
namespace
file
13
{
14
struct
file_entry
15
{
16
unzFile zp;
17
char
name[128];
18
unz_file_pos pos;
19
int
refs;
20
};
21
22
class
Zips
23
{
24
public
:
25
Zips
();
26
~
Zips
();
27
28
void
reset();
29
30
void
add(
const
char
* name);
31
void
add(
const
unsigned
char
* data,
unsigned
int
size);
32
void
add(std::vector<char>& data);
33
void
remove
(
const
char
* name);
34
35
bool
read(
const
char
* name,
file::buffer
& bf);
36
bool
read(
const
file_entry
* entry,
file::buffer
& bf);
37
bool
isExists(
const
char
* name);
38
39
file_entry
* getEntryByName(
const
char
* name);
40
const
char
* getZipFileName(
int
i)
const
{
return
_zps[i].name; }
41
Mutex
& getMutex() {
return
_lock; }
42
43
private
:
44
friend
class
ZipFileSystem
;
45
void
read(unzFile zp);
46
47
typedef
std::unordered_map<std::string, file_entry> files;
48
files _files;
49
50
struct
zpitem
51
{
52
unzFile
handle
;
53
std::vector<char> data;
54
char
name[255];
55
56
zpitem() :
handle
(0) { name[0] = 0; }
57
};
58
typedef
std::vector<zpitem> zips;
59
zips _zps;
60
61
Mutex
_lock;
62
};
63
64
bool
read(
file_entry
* entry,
file::buffer
& bf);
65
66
67
class
ZipFileSystem
:
public
FileSystem
68
{
69
public
:
70
ZipFileSystem
():
FileSystem
(
true
) {}
71
73
void
add
(
const
char
* zip);
74
void
remove
(
const
char
* zip);
75
//add zip from memory, data should not be deleted
76
void
add
(
const
unsigned
char
* data,
unsigned
int
size);
77
//add zip from memory, vector would be swapped (emptied)
78
void
add
(std::vector<char>& data);
79
void
reset();
80
81
protected
:
82
83
friend
class
fileHandleZip;
84
friend
class
fileHandleZipStreaming;
85
86
Zips
_zips;
87
88
status _read(
const
char
* file,
file::buffer
&, error_policy ep);
89
status _open(
const
char
* file,
const
char
* mode, error_policy ep,
file::fileHandle
*& fh);
90
status _deleteFile(
const
char
* file);
91
status _makeDirectory(
const
char
* file);
92
status _deleteDirectory(
const
char
* file);
93
status _renameFile(
const
char
* src,
const
char
* dest);
94
bool
_isExists(
const
char
* file);
95
96
};
97
}
98
}
oxygine::Mutex
Definition:
Mutex.h:12
oxygine::file::fileHandle
Definition:
FileSystem.h:12
oxygine::file::ZipFileSystem::add
void add(const char *zip)
oxygine::file::Zips
Definition:
ZipFileSystem.h:22
oxygine
–oxgl-end–!
Definition:
Actor.h:14
oxygine::file::file_entry
Definition:
ZipFileSystem.h:14
oxygine::file::buffer
Definition:
file.h:18
oxygine::file::ZipFileSystem
Definition:
ZipFileSystem.h:67
oxygine::file::FileSystem
Definition:
FileSystem.h:27
Generated on Tue Feb 13 2018 05:01:17 for Oxygine by
1.8.14