Also accept a .gz wherever a .pz file is accepted

This commit is contained in:
rdb 2016-04-29 16:54:25 +02:00
parent a2ae62dbda
commit dc09e28ed9
23 changed files with 45 additions and 39 deletions

View File

@ -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))

View File

@ -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)

View File

@ -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('')

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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();
}

View File

@ -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 {

View File

@ -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);

View File

@ -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 {

View File

@ -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<unsigned char> &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) {

View File

@ -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.

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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 (."

View File

@ -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 {

View File

@ -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 {

View File

@ -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";
}
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {