From dc09e28ed9dc3143cb49e1bad6921607b4001a84 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 29 Apr 2016 16:54:25 +0200 Subject: [PATCH] Also accept a .gz wherever a .pz file is accepted --- direct/src/directscripts/eggcacher.py | 2 +- direct/src/directscripts/packpanda.py | 2 +- direct/src/p3d/Packager.py | 4 ++-- direct/src/p3d/PatchMaker.py | 2 +- direct/src/plugin/p3dPackage.cxx | 5 +++-- dtool/src/parser-inc/zlib.h | 4 ++-- panda/src/audiotraits/milesAudioManager.cxx | 2 +- panda/src/collada/loaderFileTypeDae.cxx | 2 +- panda/src/downloader/decompressor.cxx | 2 +- panda/src/egg2pg/loaderFileTypeEgg.cxx | 2 +- panda/src/express/virtualFileSimple.cxx | 10 +++++++--- panda/src/express/virtualFileSystem.I | 6 +++--- panda/src/express/zStreamBuf.cxx | 4 ++-- panda/src/framework/windowFramework.cxx | 2 +- panda/src/gobj/texture.I | 4 ++-- panda/src/pgraph/loader.cxx | 16 ++++++++-------- panda/src/pgraph/loaderFileType.cxx | 2 +- panda/src/pgraph/loaderFileTypeBam.cxx | 2 +- panda/src/pnmimage/pnmImageHeader.cxx | 3 ++- panda/src/speedtree/loaderFileTypeSrt.cxx | 2 +- panda/src/speedtree/loaderFileTypeStf.cxx | 2 +- pandatool/src/assimp/loaderFileTypeAssimp.cxx | 2 +- .../src/ptloader/loaderFileTypePandatool.cxx | 2 +- 23 files changed, 45 insertions(+), 39 deletions(-) diff --git a/direct/src/directscripts/eggcacher.py b/direct/src/directscripts/eggcacher.py index ebef394890..78070df2ec 100644 --- a/direct/src/directscripts/eggcacher.py +++ b/direct/src/directscripts/eggcacher.py @@ -55,7 +55,7 @@ class EggCacher: size = os.path.getsize(path) eggs.append((path,size)) return - if (path.endswith(".egg.pz")): + if (path.endswith(".egg.pz") or path.endswith(".egg.gz")): size = os.path.getsize(path) if (self.pzkeep): eggs.append((path,size)) else: eggs.append((path[:-3],size)) diff --git a/direct/src/directscripts/packpanda.py b/direct/src/directscripts/packpanda.py index b8dec72610..6d89a9a0d0 100755 --- a/direct/src/directscripts/packpanda.py +++ b/direct/src/directscripts/packpanda.py @@ -274,7 +274,7 @@ def CompileFiles(file): if (os.path.isfile(file)): if (file.endswith(".egg")): egg2bam(file, file[:-4]+'.bam') - elif (file.endswith(".egg.pz")): + elif (file.endswith(".egg.pz") or file.endswith(".egg.gz")): egg2bam(file, file[:-7]+'.bam') elif (file.endswith(".py")): py2pyc(file) diff --git a/direct/src/p3d/Packager.py b/direct/src/p3d/Packager.py index b46cda30b7..122a4ed206 100644 --- a/direct/src/p3d/Packager.py +++ b/direct/src/p3d/Packager.py @@ -61,7 +61,7 @@ class Packager: self.newName = str(self.filename) ext = Filename(self.newName).getExtension() - if ext == 'pz': + if ext == 'pz' or ext == 'gz': # Strip off a .pz extension; we can compress files # within the Multifile without it. filename = Filename(self.newName) @@ -3772,7 +3772,7 @@ class Packager: self.currentPackage.addFile(filename, newName = newName, explicit = False, unprocessed = unprocessed) else: - if ext == 'pz': + if ext == 'pz' or ext == 'gz': # Strip off an implicit .pz extension. newFilename = Filename(filename) newFilename.setExtension('') diff --git a/direct/src/p3d/PatchMaker.py b/direct/src/p3d/PatchMaker.py index b48ad80f24..c1624b3cc1 100644 --- a/direct/src/p3d/PatchMaker.py +++ b/direct/src/p3d/PatchMaker.py @@ -137,7 +137,7 @@ class PatchMaker: startFile, startPv, plan = self.getRecreateFilePlan() - if startFile.getExtension() == 'pz': + if startFile.getExtension() in ('pz', 'gz'): # If the starting file is compressed, we have to # decompress it first. assert startPv.tempFile is None diff --git a/direct/src/plugin/p3dPackage.cxx b/direct/src/plugin/p3dPackage.cxx index 7646a8c602..0560c0f6da 100644 --- a/direct/src/plugin/p3dPackage.cxx +++ b/direct/src/plugin/p3dPackage.cxx @@ -998,7 +998,8 @@ build_install_plans(TiXmlDocument *doc) { FileSpec new_file = patchfile->_file; string new_filename = new_file.get_filename(); size_t dot = new_filename.rfind('.'); - assert(new_filename.substr(dot) == ".pz"); + string extension = new_filename.substr(dot); + assert(extension == ".pz" || extension == ".gz"); new_filename = new_filename.substr(0, dot); new_file.set_filename(new_filename); step = new InstallStepUncompressFile @@ -1834,7 +1835,7 @@ thread_step() { z.next_in = (Bytef *)decompress_buffer; z.avail_in = (size_t)read_count; - int result = inflateInit(&z); + int result = inflateInit2(&z, 32 + 15); if (result < 0) { nout << z.msg << "\n"; return IT_step_failed; diff --git a/dtool/src/parser-inc/zlib.h b/dtool/src/parser-inc/zlib.h index 74b373394a..925d60eb1a 100644 --- a/dtool/src/parser-inc/zlib.h +++ b/dtool/src/parser-inc/zlib.h @@ -21,8 +21,8 @@ #include "zconf.h" -class z_stream { -}; +typedef struct z_stream_s z_stream; +typedef struct gz_header_s gz_header; #endif diff --git a/panda/src/audiotraits/milesAudioManager.cxx b/panda/src/audiotraits/milesAudioManager.cxx index 5414d49574..750475dee1 100644 --- a/panda/src/audiotraits/milesAudioManager.cxx +++ b/panda/src/audiotraits/milesAudioManager.cxx @@ -893,7 +893,7 @@ load(const Filename &file_name) { sd->_basename = file_name.get_basename(); string extension = sd->_basename.get_extension(); - if (extension == "pz") { + if (extension == "pz" || extension == "gz") { extension = Filename(sd->_basename.get_basename_wo_extension()).get_extension(); } diff --git a/panda/src/collada/loaderFileTypeDae.cxx b/panda/src/collada/loaderFileTypeDae.cxx index d6474fb3ed..9fc5785514 100644 --- a/panda/src/collada/loaderFileTypeDae.cxx +++ b/panda/src/collada/loaderFileTypeDae.cxx @@ -56,7 +56,7 @@ get_additional_extensions() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileTypeDae:: supports_compressed() const { diff --git a/panda/src/downloader/decompressor.cxx b/panda/src/downloader/decompressor.cxx index 61b564a9eb..da78e19fa3 100644 --- a/panda/src/downloader/decompressor.cxx +++ b/panda/src/downloader/decompressor.cxx @@ -55,7 +55,7 @@ Decompressor:: int Decompressor:: initiate(const Filename &source_file) { string extension = source_file.get_extension(); - if (extension == "pz") { + if (extension == "pz" || extension == "gz") { Filename dest_file = source_file; dest_file = source_file.get_fullpath_wo_extension(); return initiate(source_file, dest_file); diff --git a/panda/src/egg2pg/loaderFileTypeEgg.cxx b/panda/src/egg2pg/loaderFileTypeEgg.cxx index be2af1dfe1..a5bbd96210 100644 --- a/panda/src/egg2pg/loaderFileTypeEgg.cxx +++ b/panda/src/egg2pg/loaderFileTypeEgg.cxx @@ -44,7 +44,7 @@ get_extension() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileTypeEgg:: supports_compressed() const { diff --git a/panda/src/express/virtualFileSimple.cxx b/panda/src/express/virtualFileSimple.cxx index a900dd514f..a036c0df4b 100644 --- a/panda/src/express/virtualFileSimple.cxx +++ b/panda/src/express/virtualFileSimple.cxx @@ -186,7 +186,7 @@ copy_file(VirtualFile *new_file) { * (which you should eventually delete when you are done reading). Returns * NULL on failure. * - * If auto_unwrap is true, an explicitly-named .pz file is automatically + * If auto_unwrap is true, an explicitly-named .pz/.gz file is automatically * decompressed and the decompressed contents are returned. This is different * than vfs-implicit-pz, which will automatically decompress a file if the * extension .pz is *not* given. @@ -195,7 +195,9 @@ istream *VirtualFileSimple:: open_read_file(bool auto_unwrap) const { // Will we be automatically unwrapping a .pz file? - bool do_uncompress = (_implicit_pz_file || (auto_unwrap && _local_filename.get_extension() == "pz")); + bool do_uncompress = (_implicit_pz_file || + (auto_unwrap && (_local_filename.get_extension() == "pz" || + _local_filename.get_extension() == "gz"))); Filename local_filename(_local_filename); if (do_uncompress) { @@ -364,7 +366,9 @@ bool VirtualFileSimple:: read_file(pvector &result, bool auto_unwrap) const { // Will we be automatically unwrapping a .pz file? - bool do_uncompress = (_implicit_pz_file || (auto_unwrap && _local_filename.get_extension() == "pz")); + bool do_uncompress = (_implicit_pz_file || + (auto_unwrap && (_local_filename.get_extension() == "pz" || + _local_filename.get_extension() == "gz"))); Filename local_filename(_local_filename); if (do_uncompress) { diff --git a/panda/src/express/virtualFileSystem.I b/panda/src/express/virtualFileSystem.I index 53b259c821..3a33e3df9c 100644 --- a/panda/src/express/virtualFileSystem.I +++ b/panda/src/express/virtualFileSystem.I @@ -88,7 +88,7 @@ ls_all(const Filename &filename) const { * Convenience function; returns the entire contents of the indicated file as * a string. * - * If auto_unwrap is true, an explicitly-named .pz file is automatically + * If auto_unwrap is true, an explicitly-named .pz/.gz file is automatically * decompressed and the decompressed contents are returned. This is different * than vfs-implicit-pz, which will automatically decompress a file if the * extension .pz is *not* given. @@ -118,7 +118,7 @@ write_file(const Filename &filename, const string &data, bool auto_wrap) { * file, if it exists and can be read. Returns true on success, false * otherwise. * - * If auto_unwrap is true, an explicitly-named .pz file is automatically + * If auto_unwrap is true, an explicitly-named .pz/.gz file is automatically * decompressed and the decompressed contents are returned. This is different * than vfs-implicit-pz, which will automatically decompress a file if the * extension .pz is *not* given. @@ -134,7 +134,7 @@ read_file(const Filename &filename, string &result, bool auto_unwrap) const { * file, if it exists and can be read. Returns true on success, false * otherwise. * - * If auto_unwrap is true, an explicitly-named .pz file is automatically + * If auto_unwrap is true, an explicitly-named .pz/.gz file is automatically * decompressed and the decompressed contents are returned. This is different * than vfs-implicit-pz, which will automatically decompress a file if the * extension .pz is *not* given. diff --git a/panda/src/express/zStreamBuf.cxx b/panda/src/express/zStreamBuf.cxx index c16caf8211..2662478e16 100644 --- a/panda/src/express/zStreamBuf.cxx +++ b/panda/src/express/zStreamBuf.cxx @@ -87,9 +87,9 @@ open_read(istream *source, bool owns_source) { _z_source.opaque = Z_NULL; _z_source.msg = (char *)"no error message"; - int result = inflateInit(&_z_source); + int result = inflateInit2(&_z_source, 32 + 15); if (result < 0) { - show_zlib_error("inflateInit", result, _z_source); + show_zlib_error("inflateInit2", result, _z_source); close_read(); } thread_consider_yield(); diff --git a/panda/src/framework/windowFramework.cxx b/panda/src/framework/windowFramework.cxx index a66963ca06..7ac9e89fa2 100644 --- a/panda/src/framework/windowFramework.cxx +++ b/panda/src/framework/windowFramework.cxx @@ -591,7 +591,7 @@ load_model(const NodePath &parent, Filename filename) { bool is_image = false; string extension = filename.get_extension(); #ifdef HAVE_ZLIB - if (extension == "pz") { + if (extension == "pz" || extension == "gz") { extension = Filename(filename.get_basename_wo_extension()).get_extension(); } #endif // HAVE_ZLIB diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index 25244367a8..b608a39c00 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -2325,7 +2325,7 @@ INLINE bool Texture:: is_txo_filename(const Filename &fullpath) { string extension = fullpath.get_extension(); #ifdef HAVE_ZLIB - if (extension == "pz") { + if (extension == "pz" || extension == "gz") { extension = Filename(fullpath.get_basename_wo_extension()).get_extension(); } #endif // HAVE_ZLIB @@ -2340,7 +2340,7 @@ INLINE bool Texture:: is_dds_filename(const Filename &fullpath) { string extension = fullpath.get_extension(); #ifdef HAVE_ZLIB - if (extension == "pz") { + if (extension == "pz" || extension == "gz") { extension = Filename(fullpath.get_basename_wo_extension()).get_extension(); } #endif // HAVE_ZLIB diff --git a/panda/src/pgraph/loader.cxx b/panda/src/pgraph/loader.cxx index 3b3042ba48..671a40c638 100644 --- a/panda/src/pgraph/loader.cxx +++ b/panda/src/pgraph/loader.cxx @@ -140,10 +140,10 @@ load_file(const Filename &filename, const LoaderOptions &options) const { extension = this_filename.get_extension(); } - bool pz_file = false; + bool compressed = false; #ifdef HAVE_ZLIB - if (extension == "pz") { - pz_file = true; + if (extension == "pz" || extension == "gz") { + compressed = true; extension = Filename(this_filename.get_basename_wo_extension()).get_extension(); } #endif // HAVE_ZLIB @@ -182,7 +182,7 @@ load_file(const Filename &filename, const LoaderOptions &options) const { << extension << ") does not support loading.\n"; } return NULL; - } else if (pz_file && !requested_type->supports_compressed()) { + } else if (compressed && !requested_type->supports_compressed()) { if (report_errors) { loader_cat.error() << requested_type->get_name() << " file type (." @@ -382,10 +382,10 @@ save_file(const Filename &filename, const LoaderOptions &options, extension = this_filename.get_extension(); } - bool pz_file = false; + bool compressed = false; #ifdef HAVE_ZLIB - if (extension == "pz") { - pz_file = true; + if (extension == "pz" || extension == "gz") { + compressed = true; extension = Filename(this_filename.get_basename_wo_extension()).get_extension(); } #endif // HAVE_ZLIB @@ -422,7 +422,7 @@ save_file(const Filename &filename, const LoaderOptions &options, } return false; - } else if (pz_file && !requested_type->supports_compressed()) { + } else if (compressed && !requested_type->supports_compressed()) { if (report_errors) { loader_cat.error() << requested_type->get_name() << " file type (." diff --git a/panda/src/pgraph/loaderFileType.cxx b/panda/src/pgraph/loaderFileType.cxx index c064361a68..326dce8720 100644 --- a/panda/src/pgraph/loaderFileType.cxx +++ b/panda/src/pgraph/loaderFileType.cxx @@ -48,7 +48,7 @@ get_additional_extensions() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileType:: supports_compressed() const { diff --git a/panda/src/pgraph/loaderFileTypeBam.cxx b/panda/src/pgraph/loaderFileTypeBam.cxx index 6859ff9306..9394c69357 100644 --- a/panda/src/pgraph/loaderFileTypeBam.cxx +++ b/panda/src/pgraph/loaderFileTypeBam.cxx @@ -47,7 +47,7 @@ get_extension() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileTypeBam:: supports_compressed() const { diff --git a/panda/src/pnmimage/pnmImageHeader.cxx b/panda/src/pnmimage/pnmImageHeader.cxx index a73c11d297..ae7c3ef3b5 100644 --- a/panda/src/pnmimage/pnmImageHeader.cxx +++ b/panda/src/pnmimage/pnmImageHeader.cxx @@ -181,7 +181,8 @@ make_reader(istream *file, bool owns_file, const Filename &filename, << type->get_name() << ".\n"; } else { pnmimage_cat.debug() - << "Unable to guess image file type from its extension.\n"; + << "Unable to guess image file type from its extension (" + << filename.get_extension() << ").\n"; } } } diff --git a/panda/src/speedtree/loaderFileTypeSrt.cxx b/panda/src/speedtree/loaderFileTypeSrt.cxx index 594267ec26..6589e28c10 100644 --- a/panda/src/speedtree/loaderFileTypeSrt.cxx +++ b/panda/src/speedtree/loaderFileTypeSrt.cxx @@ -42,7 +42,7 @@ get_extension() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileTypeSrt:: supports_compressed() const { diff --git a/panda/src/speedtree/loaderFileTypeStf.cxx b/panda/src/speedtree/loaderFileTypeStf.cxx index 7a8f71631d..8e1e15a2e8 100644 --- a/panda/src/speedtree/loaderFileTypeStf.cxx +++ b/panda/src/speedtree/loaderFileTypeStf.cxx @@ -41,7 +41,7 @@ get_extension() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileTypeStf:: supports_compressed() const { diff --git a/pandatool/src/assimp/loaderFileTypeAssimp.cxx b/pandatool/src/assimp/loaderFileTypeAssimp.cxx index cdfc9a8a22..b4a667d5fe 100644 --- a/pandatool/src/assimp/loaderFileTypeAssimp.cxx +++ b/pandatool/src/assimp/loaderFileTypeAssimp.cxx @@ -63,7 +63,7 @@ get_additional_extensions() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileTypeAssimp:: supports_compressed() const { diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.cxx b/pandatool/src/ptloader/loaderFileTypePandatool.cxx index b3bbdca822..48625154f2 100644 --- a/pandatool/src/ptloader/loaderFileTypePandatool.cxx +++ b/pandatool/src/ptloader/loaderFileTypePandatool.cxx @@ -80,7 +80,7 @@ get_additional_extensions() const { /** * Returns true if this file type can transparently load compressed files - * (with a .pz extension), false otherwise. + * (with a .pz or .gz extension), false otherwise. */ bool LoaderFileTypePandatool:: supports_compressed() const {