blob: 7102116612e3010b3d1f08c3a4b14aeb0830b67a [file] [log] [blame]
Ethan Yonker8373cfe2017-09-08 06:50:54 -05001/*
bigbiffd58ba182020-03-23 10:02:29 -04002 * Copyright (C) TeamWin
Ethan Yonker8373cfe2017-09-08 06:50:54 -05003 * This file is part of TWRP/TeamWin Recovery Project.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef __ZIPWRAP_HPP
19#define __ZIPWRAP_HPP
20
21#include <string>
22#ifdef USE_MINZIP
23#include "minzip/Zip.h"
24#include "minzip/SysUtil.h"
25#else
26#include <ziparchive/zip_archive.h>
bigbiffd58ba182020-03-23 10:02:29 -040027#include "otautil/sysutil.h"
Ethan Yonker8373cfe2017-09-08 06:50:54 -050028#endif
29
30using namespace std;
31
32class ZipWrap {
33 public:
34 ZipWrap();
35 ~ZipWrap();
36
37 bool Open(const char* file, MemMapping* map);
38 void Close();
39 bool EntryExists(const string& filename);
40 bool ExtractEntry(const string& source_file, const string& target_file, mode_t mode);
41
42 long GetUncompressedSize(const string& filename);
43 bool ExtractToBuffer(const string& filename, uint8_t* begin);
44 bool ExtractRecursive(const string& source_dir, const string& target_dir);
45#ifdef USE_MINZIP
46 loff_t GetEntryOffset(const string& filename);
47#else
48 off64_t GetEntryOffset(const string& filename);
49 ZipArchiveHandle GetZipArchiveHandle();
50#endif
51
52 private:
53#ifdef USE_MINZIP
54 ZipArchive Zip;
55#else
56 ZipArchiveHandle Zip;
57#endif
58 string zip_file;
59 bool zip_open;
60};
61
62#endif //__ZIPWRAP_HPP