[videodb] Remove nested transaction when saving state after stopping PVR playback
[xbmc.git] / xbmc / filesystem / ZipManager.h
blob3fba27f481cfce64964f13839b4d846bc2610763
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 // See http://www.pkware.com/documents/casestudies/APPNOTE.TXT
12 #define ZIP_LOCAL_HEADER 0x04034b50
13 #define ZIP_DATA_RECORD_HEADER 0x08074b50
14 #define ZIP_CENTRAL_HEADER 0x02014b50
15 #define ZIP_END_CENTRAL_HEADER 0x06054b50
16 #define ZIP_SPLIT_ARCHIVE_HEADER 0x30304b50
17 #define LHDR_SIZE 30
18 #define DREC_SIZE 16
19 #define CHDR_SIZE 46
20 #define ECDREC_SIZE 22
22 #include <cstring>
23 #include <map>
24 #include <string>
25 #include <vector>
27 class CURL;
29 static const std::string PATH_TRAVERSAL(R"_((^|\/|\\)\.{2}($|\/|\\))_");
31 struct SZipEntry {
32 unsigned int header = 0;
33 unsigned short version = 0;
34 unsigned short flags = 0;
35 unsigned short method = 0;
36 unsigned short mod_time = 0;
37 unsigned short mod_date = 0;
38 unsigned int crc32 = 0;
39 unsigned int csize = 0; // compressed size
40 unsigned int usize = 0; // uncompressed size
41 unsigned short flength = 0; // filename length
42 unsigned short elength = 0; // extra field length (local file header)
43 unsigned short eclength = 0; // extra field length (central file header)
44 unsigned short clength = 0; // file comment length (central file header)
45 unsigned int lhdrOffset = 0; // Relative offset of local header
46 int64_t offset = 0; // offset in file to compressed data
47 char name[255];
49 SZipEntry()
51 name[0] = '\0';
55 class CZipManager
57 public:
58 CZipManager();
59 ~CZipManager();
61 bool GetZipList(const CURL& url, std::vector<SZipEntry>& items);
62 bool GetZipEntry(const CURL& url, SZipEntry& item);
63 bool ExtractArchive(const std::string& strArchive, const std::string& strPath);
64 bool ExtractArchive(const CURL& archive, const std::string& strPath);
65 void release(const std::string& strPath); // release resources used by list zip
66 static void readHeader(const char* buffer, SZipEntry& info);
67 static void readCHeader(const char* buffer, SZipEntry& info);
68 private:
69 std::map<std::string,std::vector<SZipEntry> > mZipMap;
70 std::map<std::string,int64_t> mZipDate;
72 template<typename T>
73 static T ReadUnaligned(const void* mem)
75 T var;
76 std::memcpy(&var, mem, sizeof(T));
77 return var;
81 extern CZipManager g_ZipManager;