godot-seek.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. diff --git a/thirdparty/minizip/ioapi.c b/thirdparty/minizip/ioapi.c
  2. index 782d32469a..2e89f5f41a 100644
  3. --- a/thirdparty/minizip/ioapi.c
  4. +++ b/thirdparty/minizip/ioapi.c
  5. @@ -75,8 +75,15 @@ void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef
  6. p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
  7. p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
  8. p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
  9. + /* GODOT start */
  10. + p_filefunc64_32->zfile_func64.alloc_mem = p_filefunc32->alloc_mem;
  11. + p_filefunc64_32->zfile_func64.free_mem = p_filefunc32->free_mem;
  12. + /* GODOT end */
  13. }
  14. +/* GODOT start */
  15. +/*
  16. +// GODOT end
  17. static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char* filename, int mode) {
  18. @@ -229,3 +236,6 @@ void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def) {
  19. pzlib_filefunc_def->zerror_file = ferror_file_func;
  20. pzlib_filefunc_def->opaque = NULL;
  21. }
  22. +// GODOT start
  23. +*/
  24. +/* GODOT end */
  25. diff --git a/thirdparty/minizip/ioapi.h b/thirdparty/minizip/ioapi.h
  26. index a2d2e6e60d..509b52da8a 100644
  27. --- a/thirdparty/minizip/ioapi.h
  28. +++ b/thirdparty/minizip/ioapi.h
  29. @@ -155,6 +155,10 @@ typedef struct zlib_filefunc_def_s
  30. close_file_func zclose_file;
  31. testerror_file_func zerror_file;
  32. voidpf opaque;
  33. + /* GODOT start */
  34. + alloc_func alloc_mem;
  35. + free_func free_mem;
  36. + /* GODOT end */
  37. } zlib_filefunc_def;
  38. typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
  39. @@ -171,6 +175,10 @@ typedef struct zlib_filefunc64_def_s
  40. close_file_func zclose_file;
  41. testerror_file_func zerror_file;
  42. voidpf opaque;
  43. + /* GODOT start */
  44. + alloc_func alloc_mem;
  45. + free_func free_mem;
  46. + /* GODOT end */
  47. } zlib_filefunc64_def;
  48. void fill_fopen64_filefunc(zlib_filefunc64_def* pzlib_filefunc_def);
  49. diff --git a/thirdparty/minizip/unzip.c b/thirdparty/minizip/unzip.c
  50. index ea05b7d62a..981ba3c0cb 100644
  51. --- a/thirdparty/minizip/unzip.c
  52. +++ b/thirdparty/minizip/unzip.c
  53. @@ -152,6 +152,9 @@ typedef struct
  54. uLong compression_method; /* compression method (0==store) */
  55. ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
  56. int raw;
  57. + /* GODOT start */
  58. + int extra_size;
  59. + /* GODOT end */
  60. } file_in_zip64_read_info_s;
  61. @@ -513,9 +516,10 @@ local unzFile unzOpenInternal(const void *path,
  62. us.z_filefunc.zseek32_file = NULL;
  63. us.z_filefunc.ztell32_file = NULL;
  64. if (pzlib_filefunc64_32_def==NULL)
  65. - fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
  66. - else
  67. - us.z_filefunc = *pzlib_filefunc64_32_def;
  68. + /* GODOT start */
  69. + return NULL; // standard i/o not supported
  70. + us.z_filefunc = *pzlib_filefunc64_32_def;
  71. + /* GODOT end */
  72. us.is64bitOpenFunction = is64bitOpenFunction;
  73. @@ -703,6 +707,18 @@ extern unzFile ZEXPORT unzOpen64(const void *path) {
  74. return unzOpenInternal(path, NULL, 1);
  75. }
  76. +/* GODOT start */
  77. +extern void* unzGetOpaque(unzFile file) {
  78. +
  79. + unz64_s* s;
  80. + if (file==NULL)
  81. + return NULL;
  82. + s=(unz64_s*)file;
  83. +
  84. + return s->z_filefunc.zfile_func64.opaque;
  85. +};
  86. +/* GODOT end */
  87. +
  88. /*
  89. Close a ZipFile opened with unzOpen.
  90. If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  91. @@ -905,10 +921,23 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file,
  92. if (lSeek!=0)
  93. {
  94. + /* GODOT start */
  95. + if (lSeek<0) {
  96. + // WORKAROUND for backwards seeking
  97. + ZPOS64_T pos = ZTELL64(s->z_filefunc, s->filestream);
  98. + if (ZSEEK64(s->z_filefunc, s->filestream,pos+(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_SET)==0)
  99. + lSeek=0;
  100. + else
  101. + err=UNZ_ERRNO;
  102. + } else {
  103. + /* GODOT end */
  104. if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  105. lSeek=0;
  106. else
  107. err=UNZ_ERRNO;
  108. + /* GODOT start */
  109. + }
  110. + /* GODOT end */
  111. }
  112. while(acc < file_info.size_file_extra)
  113. @@ -1446,8 +1475,10 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method,
  114. }
  115. else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
  116. {
  117. - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
  118. - pfile_in_zip_read_info->stream.zfree = (free_func)0;
  119. + /* GODOT start */
  120. + pfile_in_zip_read_info->stream.zalloc = s->z_filefunc.zfile_func64.alloc_mem;
  121. + pfile_in_zip_read_info->stream.zfree = s->z_filefunc.zfile_func64.free_mem;
  122. + /* GODOT end */
  123. pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  124. pfile_in_zip_read_info->stream.next_in = 0;
  125. pfile_in_zip_read_info->stream.avail_in = 0;
  126. @@ -1480,6 +1511,9 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method,
  127. iSizeVar;
  128. pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  129. + /* GODOT start */
  130. + pfile_in_zip_read_info->extra_size = iSizeVar;
  131. + /* GODOT end */
  132. s->pfile_in_zip_read = pfile_in_zip_read_info;
  133. s->encrypted = 0;
  134. @@ -1510,6 +1544,85 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method,
  135. return UNZ_OK;
  136. }
  137. +/* GODOT start */
  138. +extern int ZEXPORT unzSeekCurrentFile(unzFile file, int pos) {
  139. +
  140. + unz64_s* s;
  141. + file_in_zip64_read_info_s* pfile_in_zip_read_info;
  142. + if (file==NULL)
  143. + return UNZ_PARAMERROR;
  144. + s=(unz64_s*)file;
  145. + pfile_in_zip_read_info=s->pfile_in_zip_read;
  146. +
  147. + if (pfile_in_zip_read_info==NULL)
  148. + return UNZ_PARAMERROR;
  149. +
  150. + if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) { // don't know how to support bzip
  151. + return UNZ_INTERNALERROR;
  152. + }
  153. +
  154. + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) {
  155. +
  156. + pfile_in_zip_read_info->rest_read_compressed =
  157. + s->cur_file_info.compressed_size - pos;
  158. + pfile_in_zip_read_info->rest_read_uncompressed =
  159. + s->cur_file_info.uncompressed_size - pos;
  160. +
  161. + pfile_in_zip_read_info->pos_in_zipfile =
  162. + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  163. + pfile_in_zip_read_info->extra_size + pos;
  164. +
  165. + pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  166. + pfile_in_zip_read_info->stream.total_out = pos;
  167. +
  168. + return ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  169. + pfile_in_zip_read_info->filestream,
  170. + pfile_in_zip_read_info->byte_before_the_zipfile + pfile_in_zip_read_info->pos_in_zipfile,
  171. + ZLIB_FILEFUNC_SEEK_SET);
  172. +
  173. + } else { // gzip
  174. +
  175. + if (pos < pfile_in_zip_read_info->stream.total_out) { // negative seek, rewind
  176. +
  177. + pfile_in_zip_read_info->rest_read_compressed =
  178. + s->cur_file_info.compressed_size ;
  179. + pfile_in_zip_read_info->rest_read_uncompressed =
  180. + s->cur_file_info.uncompressed_size ;
  181. +
  182. + pfile_in_zip_read_info->pos_in_zipfile =
  183. + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  184. + pfile_in_zip_read_info->extra_size;
  185. +
  186. + (void)inflateReset(&pfile_in_zip_read_info->stream);
  187. +
  188. + pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  189. + pfile_in_zip_read_info->stream.total_out = 0;
  190. + pfile_in_zip_read_info->stream.next_in = 0;
  191. + }
  192. +
  193. + // not sure where to read, so read on the stack
  194. + {
  195. + char buf[512];
  196. + int to_read = pos - pfile_in_zip_read_info->stream.total_out;
  197. + while (to_read) {
  198. +
  199. + int len = to_read > sizeof(buf)?sizeof(buf):to_read;
  200. + int read = unzReadCurrentFile(file, buf, len);
  201. + if (read < 0) {
  202. + return read;
  203. + }
  204. + to_read -= read;
  205. + if (read == UNZ_EOF) {
  206. + return pos;
  207. + }
  208. + }
  209. + }
  210. + }
  211. +
  212. + return pos;
  213. +}
  214. +/* GODOT end */
  215. +
  216. extern int ZEXPORT unzOpenCurrentFile(unzFile file) {
  217. return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
  218. }
  219. diff --git a/thirdparty/minizip/unzip.h b/thirdparty/minizip/unzip.h
  220. index 5cfc9c6274..0639674574 100644
  221. --- a/thirdparty/minizip/unzip.h
  222. +++ b/thirdparty/minizip/unzip.h
  223. @@ -202,6 +202,10 @@ extern int ZEXPORT unzClose(unzFile file);
  224. these files MUST be closed with unzCloseCurrentFile before call unzClose.
  225. return UNZ_OK if there is no problem. */
  226. +/* GODOT start */
  227. +extern void* unzGetOpaque(unzFile file);
  228. +/* GODOT end */
  229. +
  230. extern int ZEXPORT unzGetGlobalInfo(unzFile file,
  231. unz_global_info *pglobal_info);
  232. @@ -390,6 +394,13 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file,
  233. (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  234. */
  235. +/* GODOT start */
  236. +extern int ZEXPORT unzSeekCurrentFile(unzFile file, int pos);
  237. +/*
  238. + Seek to position in uncompressed data
  239. +*/
  240. +/* GODOT end */
  241. +
  242. extern z_off_t ZEXPORT unztell(unzFile file);
  243. extern ZPOS64_T ZEXPORT unztell64(unzFile file);
  244. diff --git a/thirdparty/minizip/zip.c b/thirdparty/minizip/zip.c
  245. index 60bdffac34..1d2d918e72 100644
  246. --- a/thirdparty/minizip/zip.c
  247. +++ b/thirdparty/minizip/zip.c
  248. @@ -820,9 +820,11 @@ extern zipFile ZEXPORT zipOpen3(const void *pathname, int append, zipcharpc* glo
  249. ziinit.z_filefunc.zseek32_file = NULL;
  250. ziinit.z_filefunc.ztell32_file = NULL;
  251. - if (pzlib_filefunc64_32_def==NULL)
  252. - fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
  253. - else
  254. + /* GODOT start */
  255. + if (pzlib_filefunc64_32_def==NULL) {
  256. + //fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
  257. + } else
  258. + /* GODOT end */
  259. ziinit.z_filefunc = *pzlib_filefunc64_32_def;
  260. ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
  261. @@ -1182,8 +1184,10 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
  262. {
  263. if(zi->ci.method == Z_DEFLATED)
  264. {
  265. - zi->ci.stream.zalloc = (alloc_func)0;
  266. - zi->ci.stream.zfree = (free_func)0;
  267. + /* GODOT start */
  268. + zi->ci.stream.zalloc = zi->z_filefunc.zfile_func64.alloc_mem;
  269. + zi->ci.stream.zfree = zi->z_filefunc.zfile_func64.free_mem;
  270. + /* GODOT end */
  271. zi->ci.stream.opaque = (voidpf)0;
  272. if (windowBits>0)