add get_file_size() for an unopened file
This commit is contained in:
parent
77ec202484
commit
b0eb06c4cb
|
|
@ -1201,6 +1201,33 @@ get_timestamp() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Filename::get_file_size
|
||||
// Access: Published
|
||||
// Description: Returns the size of the file in bytes, or 0 if there
|
||||
// is an error.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
off_t Filename::
|
||||
get_file_size() const {
|
||||
string os_specific = get_filename_index(0).to_os_specific();
|
||||
|
||||
#ifdef WIN32_VC
|
||||
struct _stat this_buf;
|
||||
|
||||
if (_stat(os_specific.c_str(), &this_buf) == 0) {
|
||||
return this_buf.st_size;
|
||||
}
|
||||
#else // WIN32_VC
|
||||
struct stat this_buf;
|
||||
|
||||
if (stat(os_specific.c_str(), &this_buf) == 0) {
|
||||
return this_buf.st_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Filename::resolve_filename
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -160,6 +160,7 @@ PUBLISHED:
|
|||
bool this_missing_is_old = true,
|
||||
bool other_missing_is_old = true) const;
|
||||
time_t get_timestamp() const;
|
||||
off_t get_file_size() const;
|
||||
|
||||
bool resolve_filename(const DSearchPath &searchpath,
|
||||
const string &default_extension = string());
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ get_header_value(const string &key) const {
|
|||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: HTTPChannel::get_file_size
|
||||
// Access: Published
|
||||
// Access: Published, Virtual
|
||||
// Description: Returns the size of the file, if it is known.
|
||||
// Returns the value set by set_expected_file_size() if
|
||||
// the file size is not known, or 0 if this value was
|
||||
|
|
@ -296,7 +296,7 @@ get_header_value(const string &key) const {
|
|||
// their minds midstream about how much data they're
|
||||
// sending you.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
size_t HTTPChannel::
|
||||
off_t HTTPChannel::
|
||||
get_file_size() const {
|
||||
if (_got_file_size) {
|
||||
return _file_size;
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ PUBLISHED:
|
|||
INLINE double get_max_updates_per_second() const;
|
||||
|
||||
INLINE void set_expected_file_size(size_t file_size);
|
||||
size_t get_file_size() const;
|
||||
virtual off_t get_file_size() const;
|
||||
INLINE bool is_file_size_known() const;
|
||||
|
||||
void write_headers(ostream &out) const;
|
||||
|
|
|
|||
|
|
@ -172,11 +172,22 @@ open_read_file(bool auto_unwrap) const {
|
|||
// implementations may require this stream to determine
|
||||
// the size.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
streampos VirtualFile::
|
||||
off_t VirtualFile::
|
||||
get_file_size(istream *stream) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFile::get_file_size
|
||||
// Access: Published, Virtual
|
||||
// Description: Returns the current size on disk (or wherever it is)
|
||||
// of the file before it has been opened.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
off_t VirtualFile::
|
||||
get_file_size() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFile::get_timestamp
|
||||
// Access: Published, Virtual
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ PUBLISHED:
|
|||
INLINE string read_file(bool auto_unwrap) const;
|
||||
virtual istream *open_read_file(bool auto_unwrap) const;
|
||||
void close_read_file(istream *stream) const;
|
||||
virtual streampos get_file_size(istream *stream) const;
|
||||
virtual off_t get_file_size(istream *stream) const;
|
||||
virtual off_t get_file_size() const;
|
||||
virtual time_t get_timestamp() const;
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ public:
|
|||
|
||||
virtual istream *open_read_file(const Filename &file) const=0;
|
||||
void close_read_file(istream *stream) const;
|
||||
virtual streampos get_file_size(const Filename &file, istream *stream) const=0;
|
||||
virtual off_t get_file_size(const Filename &file, istream *stream) const=0;
|
||||
virtual off_t get_file_size(const Filename &file) const=0;
|
||||
virtual time_t get_timestamp(const Filename &file) const=0;
|
||||
|
||||
virtual bool scan_directory(vector_string &contents,
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ open_read_file(const Filename &file) const {
|
|||
// implementations may require this stream to determine
|
||||
// the size.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
streampos VirtualFileMountMultifile::
|
||||
off_t VirtualFileMountMultifile::
|
||||
get_file_size(const Filename &file, istream *) const {
|
||||
int subfile_index = _multifile->find_subfile(file);
|
||||
if (subfile_index < 0) {
|
||||
|
|
@ -102,6 +102,21 @@ get_file_size(const Filename &file, istream *) const {
|
|||
return _multifile->get_subfile_length(subfile_index);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFileMountMultifile::get_file_size
|
||||
// Access: Published, Virtual
|
||||
// Description: Returns the current size on disk (or wherever it is)
|
||||
// of the file before it has been opened.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
off_t VirtualFileMountMultifile::
|
||||
get_file_size(const Filename &file) const {
|
||||
int subfile_index = _multifile->find_subfile(file);
|
||||
if (subfile_index < 0) {
|
||||
return 0;
|
||||
}
|
||||
return _multifile->get_subfile_length(subfile_index);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFileMountMultifile::get_timestamp
|
||||
// Access: Published, Virtual
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ public:
|
|||
virtual bool is_regular_file(const Filename &file) const;
|
||||
|
||||
virtual istream *open_read_file(const Filename &file) const;
|
||||
virtual streampos get_file_size(const Filename &file, istream *stream) const;
|
||||
virtual off_t get_file_size(const Filename &file, istream *stream) const;
|
||||
virtual off_t get_file_size(const Filename &file) const;
|
||||
virtual time_t get_timestamp(const Filename &file) const;
|
||||
|
||||
virtual bool scan_directory(vector_string &contents,
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ open_read_file(const Filename &file) const {
|
|||
// implementations may require this stream to determine
|
||||
// the size.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
streampos VirtualFileMountSystem::
|
||||
off_t VirtualFileMountSystem::
|
||||
get_file_size(const Filename &, istream *stream) const {
|
||||
// First, save the original stream position.
|
||||
streampos orig = stream->tellg();
|
||||
|
|
@ -141,6 +141,18 @@ get_file_size(const Filename &, istream *stream) const {
|
|||
return size;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFileMountSystem::get_file_size
|
||||
// Access: Published, Virtual
|
||||
// Description: Returns the current size on disk (or wherever it is)
|
||||
// of the file before it has been opened.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
off_t VirtualFileMountSystem::
|
||||
get_file_size(const Filename &file) const {
|
||||
Filename pathname(_physical_filename, file);
|
||||
return pathname.get_file_size();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFileMountSystem::get_timestamp
|
||||
// Access: Published, Virtual
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ public:
|
|||
virtual bool is_regular_file(const Filename &file) const;
|
||||
|
||||
virtual istream *open_read_file(const Filename &file) const;
|
||||
virtual streampos get_file_size(const Filename &file, istream *stream) const;
|
||||
virtual off_t get_file_size(const Filename &file, istream *stream) const;
|
||||
virtual off_t get_file_size(const Filename &file) const;
|
||||
virtual time_t get_timestamp(const Filename &file) const;
|
||||
|
||||
virtual bool scan_directory(vector_string &contents,
|
||||
|
|
|
|||
|
|
@ -119,11 +119,22 @@ open_read_file(bool auto_unwrap) const {
|
|||
// implementations may require this stream to determine
|
||||
// the size.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
streampos VirtualFileSimple::
|
||||
off_t VirtualFileSimple::
|
||||
get_file_size(istream *stream) const {
|
||||
return _mount->get_file_size(_local_filename, stream);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFileSimple::get_file_size
|
||||
// Access: Published, Virtual
|
||||
// Description: Returns the current size on disk (or wherever it is)
|
||||
// of the file before it has been opened.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
off_t VirtualFileSimple::
|
||||
get_file_size() const {
|
||||
return _mount->get_file_size(_local_filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: VirtualFileSimple::get_timestamp
|
||||
// Access: Published, Virtual
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ public:
|
|||
INLINE bool is_implicit_pz_file() const;
|
||||
|
||||
virtual istream *open_read_file(bool auto_unwrap) const;
|
||||
virtual streampos get_file_size(istream *stream) const;
|
||||
virtual off_t get_file_size(istream *stream) const;
|
||||
virtual off_t get_file_size() const;
|
||||
virtual time_t get_timestamp() const;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Reference in New Issue