file_access_zip.h
1 /*************************************************************************/
2 /* file_access_zip.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifdef MINIZIP_ENABLED
30 
31 #ifndef FILE_ACCESS_Zip_H
32 #define FILE_ACCESS_Zip_H
33 
34 #include <stdlib.h>
35 #include "core/io/file_access_pack.h"
36 #include "unzip.h"
37 #include "map.h"
38 
39 class ZipArchive : public PackSource {
40 
41 public:
42 
43  struct File {
44 
45  int package;
46  unz_file_pos file_pos;
47  File() {
48 
49  package = -1;
50  };
51  };
52 
53 
54 private:
55 
56  struct Package {
57  String filename;
58  unzFile zfile;
59  };
60  Vector<Package> packages;
61 
62  Map<String,File> files;
63 
64  static ZipArchive* instance;
65 
66  FileAccess::CreateFunc fa_create_func;
67 
68 public:
69 
70  void close_handle(unzFile p_file) const;
71  unzFile get_file_handle(String p_file) const;
72 
73  Error add_package(String p_name);
74 
75  bool file_exists(String p_name) const;
76 
77  virtual bool try_open_pack(const String& p_path);
78  FileAccess* get_file(const String& p_path, PackedData::PackedFile* p_file);
79 
80  static ZipArchive* get_singleton();
81 
82  ZipArchive();
83  ~ZipArchive();
84 };
85 
86 
87 class FileAccessZip : public FileAccess {
88 
89  unzFile zfile;
90  unz_file_info64 file_info;
91 
92  mutable bool at_eof;
93 
94  ZipArchive* archive;
95 
96 public:
97 
98  virtual Error _open(const String& p_path, int p_mode_flags);
99  virtual void close();
100  virtual bool is_open() const;
101 
102  virtual void seek(size_t p_position);
103  virtual void seek_end(int64_t p_position=0);
104  virtual size_t get_pos() const;
105  virtual size_t get_len() const;
106 
107  virtual bool eof_reached() const;
108 
109  virtual uint8_t get_8() const;
110  virtual int get_buffer(uint8_t *p_dst,int p_length) const;
111 
112  virtual Error get_error() const;
113 
114  virtual void store_8(uint8_t p_dest);
115  virtual bool file_exists(const String& p_name);
116 
117  virtual uint64_t _get_modified_time(const String& p_file) { return 0; } // todo
118 
119  FileAccessZip(const String& p_path, const PackedData::PackedFile& p_file);
120  ~FileAccessZip();
121 };
122 
123 #endif // FILE_ACCESS_ZIP_H
124 
125 #endif
Definition: file_access_pack.h:46
Definition: unzip.h:111
Definition: file_access_pack.h:119
Definition: map.h:41
Definition: unzip.h:261
Definition: ustring.h:64
Definition: vector.h:43
Definition: file_access.h:40