/
ZipManager.h
117 lines (106 loc) · 3.78 KB
/
ZipManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef ZIP_MANAGER_H_
#define ZIP_MANAGER_H_
/*
* Copyright (C) 2005-2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
// See http://www.pkware.com/documents/casestudies/APPNOTE.TXT
#define ZIP_LOCAL_HEADER 0x04034b50
#define ZIP_CENTRAL_HEADER 0x02014b50
#define ZIP_END_CENTRAL_HEADER 0x06054b50
#define LHDR_SIZE 30
#define CHDR_SIZE 46
#define ECDREC_SIZE 22
#include "utils/StdString.h"
#include <memory.h>
#include <vector>
#include <map>
struct SZipEntry {
unsigned int header;
unsigned short version;
unsigned short flags;
unsigned short method;
unsigned short mod_time;
unsigned short mod_date;
unsigned int crc32;
unsigned int csize; // compressed size
unsigned int usize; // uncompressed size
unsigned short flength; // filename length
unsigned short elength; // extra field length (local file header)
unsigned short eclength; // extra field length (central file header)
unsigned short clength; // file comment length (central file header)
unsigned int lhdrOffset; // Relative offset of local header
int64_t offset; // offset in file to compressed data
char name[255];
SZipEntry()
{
header = 0;
version = 0;
flags = 0;
method = 0;
mod_time = 0;
mod_date = 0;
crc32 = 0;
csize = 0;
usize = 0;
flength = 0;
elength = 0;
eclength = 0;
clength = 0;
lhdrOffset = 0;
offset = 0;
name[0] = '\0';
}
SZipEntry(const SZipEntry& SNewItem)
{
memcpy(&header,&SNewItem.header,sizeof(unsigned int));
memcpy(&version,&SNewItem.version,sizeof(unsigned short));
memcpy(&flags,&SNewItem.flags,sizeof(unsigned short));
memcpy(&method,&SNewItem.method,sizeof(unsigned short));
memcpy(&mod_time,&SNewItem.mod_time,sizeof(unsigned short));
memcpy(&mod_date,&SNewItem.mod_date,sizeof(unsigned short));
memcpy(&crc32,&SNewItem.crc32,sizeof(unsigned int));
memcpy(&csize,&SNewItem.csize,sizeof(unsigned int));
memcpy(&usize,&SNewItem.usize,sizeof(unsigned int));
memcpy(&flength,&SNewItem.flength,sizeof(unsigned short));
memcpy(&elength,&SNewItem.elength,sizeof(unsigned short));
memcpy(&eclength,&SNewItem.eclength,sizeof(unsigned short));
memcpy(&clength,&SNewItem.clength,sizeof(unsigned short));
memcpy(&lhdrOffset,&SNewItem.lhdrOffset,sizeof(unsigned int));
memcpy(&offset,&SNewItem.offset,sizeof(int64_t));
memcpy(name,SNewItem.name,255*sizeof(char));
}
};
class CZipManager
{
public:
CZipManager();
~CZipManager();
bool GetZipList(const CStdString& strPath, std::vector<SZipEntry>& items);
bool GetZipEntry(const CStdString& strPath, SZipEntry& item);
bool ExtractArchive(const CStdString& strArchive, const CStdString& strPath);
void CleanUp(const CStdString& strArchive, const CStdString& strPath); // deletes extracted archive. use with care!
void release(const CStdString& strPath); // release resources used by list zip
static void readHeader(const char* buffer, SZipEntry& info);
static void readCHeader(const char* buffer, SZipEntry& info);
private:
std::map<CStdString,std::vector<SZipEntry> > mZipMap;
std::map<CStdString,int64_t> mZipDate;
};
extern CZipManager g_ZipManager;
#endif