41 if (_local_filename.empty()) {
42 if (mount_point.empty()) {
45 return string(
"/") + mount_point;
49 if (mount_point.empty()) {
52 return string(
"/") + mount_point + string(
"/") + _local_filename.
get_fullpath();
62 return _mount->has_file(_local_filename);
71 return _mount->is_directory(_local_filename);
80 return _mount->is_regular_file(_local_filename);
115 if (new_file->
is_of_type(VirtualFileSimple::get_class_type())) {
117 if (new_file_simple->_mount == _mount) {
119 if (_mount->
rename_file(_local_filename, new_file_simple->_local_filename)) {
145 if (new_file->
is_of_type(VirtualFileSimple::get_class_type())) {
147 if (new_file_simple->_mount == _mount) {
149 if (_mount->
copy_file(_local_filename, new_file_simple->_local_filename)) {
158 if (out ==
nullptr) {
169 static const size_t buffer_size = 4096;
170 char buffer[buffer_size];
172 in->read(buffer, buffer_size);
173 size_t count = in->gcount();
175 out->write(buffer, count);
182 in->read(buffer, buffer_size);
183 count = in->gcount();
212 bool do_uncompress = (_implicit_pz_file ||
216 Filename local_filename(_local_filename);
222 return _mount->open_read_file(local_filename, do_uncompress);
248 bool do_compress = (_implicit_pz_file || (auto_wrap && _local_filename.
get_extension() ==
"pz"));
250 Filename local_filename(_local_filename);
318 return _mount->get_file_size(_local_filename, stream);
327 return _mount->get_file_size(_local_filename);
342 return _mount->get_timestamp(_local_filename);
362 const string &old_contents,
363 const string &new_contents) {
380read_file(vector_uchar &result,
bool auto_unwrap)
const {
383 bool do_uncompress = (_implicit_pz_file ||
387 Filename local_filename(_local_filename);
393 return _mount->
read_file(local_filename, do_uncompress, result);
401write_file(
const unsigned char *data,
size_t data_size,
bool auto_wrap) {
403 bool do_compress = (_implicit_pz_file || (auto_wrap && _local_filename.
get_extension() ==
"pz"));
405 Filename local_filename(_local_filename);
411 return _mount->
write_file(local_filename, do_compress, data, data_size);
420bool VirtualFileSimple::
424 if (!_mount->scan_directory(names, _local_filename)) {
435 vector_string::const_iterator ni;
436 for (ni = names.begin(); ni != names.end(); ++ni) {
437 const string &basename = (*ni);
438 if (mount_points.find(basename) == mount_points.
end()) {
439 Filename filename(_local_filename, basename);
The name of a file, such as a texture file or an Egg file.
void set_binary()
Indicates that the filename represents a binary file.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
std::string get_extension() const
Returns the file extension.
This class records a particular byte sub-range within an existing file on disk.
TypeHandle is the identifier used to differentiate C++ class types.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
A list of VirtualFiles, as returned by VirtualFile::scan_directory().
void add_file(VirtualFile *file)
Adds a new file to the list.
virtual std::iostream * open_read_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual bool atomic_read_contents(const Filename &file, std::string &contents) const
See Filename::atomic_read_contents().
virtual bool is_writable(const Filename &file) const
Returns true if the named file or directory may be written to, false otherwise.
const Filename & get_mount_point() const
Returns the name of the directory within the virtual file system that this mount object is attached t...
virtual bool delete_file(const Filename &file)
Attempts to delete the indicated file or directory within the mount.
virtual bool read_file(const Filename &file, bool do_uncompress, vector_uchar &result) const
Fills up the indicated pvector with the contents of the file, if it is a regular file.
virtual void close_write_file(std::ostream *stream)
Closes a file opened by a previous call to open_write_file().
virtual void close_read_write_file(std::iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
virtual bool copy_file(const Filename &orig_filename, const Filename &new_filename)
Attempts to copy the contents of the indicated file to the indicated file.
virtual bool write_file(const Filename &file, bool do_compress, const unsigned char *data, size_t data_size)
Writes the indicated data to the file, if it is a writable file.
VirtualFileSystem * get_file_system() const
Returns the file system this mount object is attached to.
virtual std::ostream * open_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual std::ostream * open_append_file(const Filename &file)
Works like open_write_file(), but the file is opened in append mode.
virtual bool get_system_info(const Filename &file, SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, const std::string &old_contents, const std::string &new_contents)
See Filename::atomic_compare_and_exchange_contents().
virtual std::iostream * open_read_append_file(const Filename &file)
Works like open_read_write_file(), but the file is opened in append mode.
virtual bool rename_file(const Filename &orig_filename, const Filename &new_filename)
Attempts to rename the contents of the indicated file to the indicated file.
virtual void close_read_file(std::istream *stream) const
Closes a file opened by a previous call to open_read_file().
A simple file or directory within the VirtualFileSystem: this maps to exactly one file on one mount p...
virtual bool read_file(vector_uchar &result, bool auto_unwrap) const
Fills up the indicated pvector with the contents of the file, if it is a regular file.
virtual std::ostream * open_append_file()
Works like open_write_file(), but the file is opened in append mode.
virtual bool atomic_compare_and_exchange_contents(std::string &orig_contents, const std::string &old_contents, const std::string &new_contents)
See Filename::atomic_compare_and_exchange_contents().
virtual bool atomic_read_contents(std::string &contents) const
See Filename::atomic_read_contents().
virtual bool get_system_info(SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
virtual bool is_regular_file() const
Returns true if this file represents a regular file (and read_file() may be called),...
virtual bool has_file() const
Returns true if this file exists, false otherwise.
virtual std::ostream * open_write_file(bool auto_wrap, bool truncate)
Opens the file for writing.
virtual VirtualFileSystem * get_file_system() const
Returns the VirtualFileSystem this file is associated with.
virtual bool delete_file()
Attempts to delete this file or directory.
virtual bool write_file(const unsigned char *data, size_t data_size, bool auto_wrap)
Writes the indicated data to the file, if it is writable.
virtual bool copy_file(VirtualFile *new_file)
Attempts to copy the contents of this file to the indicated file.
virtual std::iostream * open_read_write_file(bool truncate)
Opens the file for writing.
virtual std::istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
virtual std::iostream * open_read_append_file()
Works like open_read_write_file(), but the file is opened in append mode.
virtual void close_write_file(std::ostream *stream)
Closes a file opened by a previous call to open_write_file().
virtual void close_read_file(std::istream *stream) const
Closes a file opened by a previous call to open_read_file().
virtual bool rename_file(VirtualFile *new_file)
Attempts to move or rename this file or directory.
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called),...
virtual bool is_writable() const
Returns true if this file represents a writable regular file (and write_file() may be called),...
virtual void close_read_write_file(std::iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
virtual Filename get_filename() const
Returns the full pathname to this file within the virtual file system.
virtual std::streamsize get_file_size() const
Returns the current size on disk (or wherever it is) of the file before it has been opened.
A hierarchy of directories and files that appears to be one continuous file system,...
The abstract base class for a file or directory within the VirtualFileSystem.
virtual bool delete_file()
Attempts to delete this file or directory.
virtual std::ostream * open_write_file(bool auto_wrap, bool truncate)
Opens the file for writing.
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called),...
virtual void close_write_file(std::ostream *stream)
Closes a file opened by a previous call to open_write_file().
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.