mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
close_read_subfile
This commit is contained in:
parent
6f1f888105
commit
9ae42186d1
@ -78,7 +78,7 @@ void Extractor::
|
|||||||
reset() {
|
reset() {
|
||||||
if (_initiated) {
|
if (_initiated) {
|
||||||
if (_read != (istream *)NULL) {
|
if (_read != (istream *)NULL) {
|
||||||
delete _read;
|
Multifile::close_read_subfile(_read);
|
||||||
_read = (istream *)NULL;
|
_read = (istream *)NULL;
|
||||||
}
|
}
|
||||||
_write.close();
|
_write.close();
|
||||||
@ -204,7 +204,7 @@ step() {
|
|||||||
downloader_cat.debug()
|
downloader_cat.debug()
|
||||||
<< "Finished current subfile.\n";
|
<< "Finished current subfile.\n";
|
||||||
}
|
}
|
||||||
delete _read;
|
Multifile::close_read_subfile(_read);
|
||||||
_read = (istream *)NULL;
|
_read = (istream *)NULL;
|
||||||
_write.close();
|
_write.close();
|
||||||
_request_index++;
|
_request_index++;
|
||||||
|
@ -1072,8 +1072,9 @@ get_subfile_internal_length(int index) const {
|
|||||||
// subfile.
|
// subfile.
|
||||||
//
|
//
|
||||||
// The returned istream will have been allocated via
|
// The returned istream will have been allocated via
|
||||||
// new; you should delete it when you are finished
|
// new; you should pass the pointer to
|
||||||
// reading the subfile.
|
// close_read_subfile() when you are finished with it to
|
||||||
|
// delete it and release its resources.
|
||||||
//
|
//
|
||||||
// Any future calls to repack() or close() (or the
|
// Any future calls to repack() or close() (or the
|
||||||
// Multifile destructor) will invalidate all currently
|
// Multifile destructor) will invalidate all currently
|
||||||
@ -1156,6 +1157,31 @@ open_read_subfile(int index) {
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Multifile::close_read_subfile
|
||||||
|
// Access: Published, Static
|
||||||
|
// Description: Closes a file opened by a previous call to
|
||||||
|
// open_read_subfile(). This really just deletes the
|
||||||
|
// istream pointer, but it is recommended to use this
|
||||||
|
// interface instead of deleting it explicitly, to help
|
||||||
|
// work around compiler issues.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void Multifile::
|
||||||
|
close_read_subfile(istream *stream) {
|
||||||
|
if (stream != (istream *)NULL) {
|
||||||
|
// For some reason--compiler bug in gcc 3.2?--explicitly deleting
|
||||||
|
// the stream pointer does not call the appropriate global delete
|
||||||
|
// function; instead apparently calling the system delete
|
||||||
|
// function. So we call the delete function by hand instead.
|
||||||
|
#if !defined(WIN32_VC) && !defined(USE_MEMORY_NOWRAPPERS) && defined(REDEFINE_GLOBAL_OPERATOR_NEW)
|
||||||
|
stream->~istream();
|
||||||
|
(*global_operator_delete)(stream);
|
||||||
|
#else
|
||||||
|
delete stream;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Multifile::extract_subfile
|
// Function: Multifile::extract_subfile
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -1207,7 +1233,7 @@ extract_subfile_to(int index, ostream &out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool failed = (in->fail() && !in->eof());
|
bool failed = (in->fail() && !in->eof());
|
||||||
delete in;
|
close_read_subfile(in);
|
||||||
nassertr(!failed, false);
|
nassertr(!failed, false);
|
||||||
|
|
||||||
return (!out.fail());
|
return (!out.fail());
|
||||||
@ -1251,7 +1277,7 @@ compare_subfile(int index, const Filename &filename) {
|
|||||||
|
|
||||||
if (file_size != (streampos)get_subfile_length(index)) {
|
if (file_size != (streampos)get_subfile_length(index)) {
|
||||||
// The files have different sizes.
|
// The files have different sizes.
|
||||||
delete in1;
|
close_read_subfile(in1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1261,8 +1287,8 @@ compare_subfile(int index, const Filename &filename) {
|
|||||||
int byte2 = in2.get();
|
int byte2 = in2.get();
|
||||||
while (!in1->fail() && !in1->eof() &&
|
while (!in1->fail() && !in1->eof() &&
|
||||||
!in2.fail() && !in2.eof()) {
|
!in2.fail() && !in2.eof()) {
|
||||||
if (byte1 != byte2) {
|
if (byte1 != byte2) {
|
||||||
delete in1;
|
close_read_subfile(in1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
byte1 = in1->get();
|
byte1 = in1->get();
|
||||||
@ -1270,7 +1296,7 @@ compare_subfile(int index, const Filename &filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool failed = (in1->fail() && !in1->eof()) || (in2.fail() && !in2.eof());
|
bool failed = (in1->fail() && !in1->eof()) || (in2.fail() && !in2.eof());
|
||||||
delete in1;
|
close_read_subfile(in1);
|
||||||
|
|
||||||
nassertr(!failed, false);
|
nassertr(!failed, false);
|
||||||
|
|
||||||
@ -1354,7 +1380,7 @@ read_subfile(int index, pvector<unsigned char> &result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool failed = in->fail() && !in->eof();
|
bool failed = in->fail() && !in->eof();
|
||||||
delete in;
|
close_read_subfile(in);
|
||||||
nassertr(!failed, false);
|
nassertr(!failed, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ PUBLISHED:
|
|||||||
|
|
||||||
BLOCKING INLINE string read_subfile(int index);
|
BLOCKING INLINE string read_subfile(int index);
|
||||||
BLOCKING istream *open_read_subfile(int index);
|
BLOCKING istream *open_read_subfile(int index);
|
||||||
|
BLOCKING static void close_read_subfile(istream *stream);
|
||||||
BLOCKING bool extract_subfile(int index, const Filename &filename);
|
BLOCKING bool extract_subfile(int index, const Filename &filename);
|
||||||
BLOCKING bool extract_subfile_to(int index, ostream &out);
|
BLOCKING bool extract_subfile_to(int index, ostream &out);
|
||||||
BLOCKING bool compare_subfile(int index, const Filename &filename);
|
BLOCKING bool compare_subfile(int index, const Filename &filename);
|
||||||
|
@ -77,6 +77,11 @@ open_read_file(const Filename &file) const {
|
|||||||
if (subfile_index < 0) {
|
if (subfile_index < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The caller will eventually pass this pointer to
|
||||||
|
// VirtualFileSystem::close_read_file(), not to
|
||||||
|
// Multifile::close_read_subfile(). Fortunately, these two methods
|
||||||
|
// do the same thing, so that doesn't matter.
|
||||||
return _multifile->open_read_subfile(subfile_index);
|
return _multifile->open_read_subfile(subfile_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user