add support for text/binary distinction within p3d

This commit is contained in:
David Rose 2011-07-27 18:18:25 +00:00
parent 5055403995
commit 74557c5c72
4 changed files with 29 additions and 3 deletions

View File

@ -101,6 +101,11 @@ class Packager:
if basename.resolveFilename(packager.executablePath): if basename.resolveFilename(packager.executablePath):
self.filename = basename self.filename = basename
if ext in packager.textExtensions and not self.executable:
self.filename.setText()
else:
self.filename.setBinary()
# Convert the filename to an unambiguous filename for # Convert the filename to an unambiguous filename for
# searching. # searching.
self.filename.makeTrueCase() self.filename.makeTrueCase()
@ -1434,6 +1439,14 @@ class Packager:
# Write the xml file to a temporary file on disk, so we # Write the xml file to a temporary file on disk, so we
# can add it to the multifile. # can add it to the multifile.
filename = Filename.temporary('', 'p3d_', '.xml') filename = Filename.temporary('', 'p3d_', '.xml')
# This should really be setText() for an xml file, but it
# doesn't really matter that much since tinyxml can read
# it either way; and if we use setBinary() it will remain
# compatible with older versions of the core API that
# didn't understand the SF_text flag.
filename.setBinary()
doc.SaveFile(filename.toOsSpecific()) doc.SaveFile(filename.toOsSpecific())
# It's important not to compress this file: the core API # It's important not to compress this file: the core API
@ -1940,6 +1953,7 @@ class Packager:
# Then write it out again, without the comments. # Then write it out again, without the comments.
tempFilename = Filename.temporary('', 'p3d_', '.prc') tempFilename = Filename.temporary('', 'p3d_', '.prc')
tempFilename.setBinary() # Binary is more reliable for signing.
temp = open(tempFilename.toOsSpecific(), 'w') temp = open(tempFilename.toOsSpecific(), 'w')
for line in textLines: for line in textLines:
line = line.strip() line = line.strip()
@ -1964,6 +1978,7 @@ class Packager:
file.newName = file.newName[:-1] + 'e' file.newName = file.newName[:-1] + 'e'
preFilename = Filename.temporary('', 'p3d_', '.pre') preFilename = Filename.temporary('', 'p3d_', '.pre')
preFilename.setBinary()
tempFilename.setText() tempFilename.setText()
encryptFile(tempFilename, preFilename, self.packager.prcEncryptionKey) encryptFile(tempFilename, preFilename, self.packager.prcEncryptionKey)
tempFilename.unlink() tempFilename.unlink()
@ -2233,7 +2248,7 @@ class Packager:
self.modelExtensions = [ 'egg', 'bam' ] self.modelExtensions = [ 'egg', 'bam' ]
# Text files that are copied (and compressed) to the package # Text files that are copied (and compressed) to the package
# without processing. # with end-of-line conversion.
self.textExtensions = [ 'prc', 'ptf', 'txt', 'cg', 'sha', 'dc', 'xml' ] self.textExtensions = [ 'prc', 'ptf', 'txt', 'cg', 'sha', 'dc', 'xml' ]
# Binary files that are copied (and compressed) without # Binary files that are copied (and compressed) without
@ -3495,6 +3510,10 @@ class Packager:
ext = newFilename.getExtension() ext = newFilename.getExtension()
if ext in self.knownExtensions: if ext in self.knownExtensions:
if ext in self.textExtensions:
filename.setText()
else:
filename.setBinary()
self.currentPackage.addFile(filename, newName = newName, self.currentPackage.addFile(filename, newName = newName,
explicit = False, unprocessed = unprocessed) explicit = False, unprocessed = unprocessed)

View File

@ -2136,6 +2136,9 @@ scan_app_desc_file(TiXmlDocument *doc) {
void P3DInstance:: void P3DInstance::
add_packages() { add_packages() {
assert(!_packages_specified); assert(!_packages_specified);
if (_xpackage == NULL) {
return;
}
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();

View File

@ -332,8 +332,8 @@ read_index() {
// Otherwise, it's a regular file. // Otherwise, it's a regular file.
_last_data_byte = max(_last_data_byte, s.get_last_byte_pos()); _last_data_byte = max(_last_data_byte, s.get_last_byte_pos());
if (flags == 0) { if ((flags & SF_ignore) == 0) {
// We can only support subfiles with no particular flags set. // We can only support subfiles with none of SF_ignore set.
_subfiles.push_back(s); _subfiles.push_back(s);
} }
} }

View File

@ -63,6 +63,10 @@ private:
inline unsigned int read_uint32(); inline unsigned int read_uint32();
enum SubfileFlags { enum SubfileFlags {
// If any of these bits are set, we can't read the subfile.
SF_ignore = 0x003f,
// These bits are also relevant, and specifically so.
SF_compressed = 0x0008, SF_compressed = 0x0008,
SF_encrypted = 0x0010, SF_encrypted = 0x0010,
SF_signature = 0x0020, SF_signature = 0x0020,