15 #include "virtualFileSimple.h"
16 #include "virtualFileMount.h"
17 #include "virtualFileList.h"
43 if (_local_filename.empty()) {
44 if (mount_point.empty()) {
47 return string(
"/") + mount_point;
51 if (mount_point.empty()) {
54 return string(
"/") + mount_point + string(
"/") + _local_filename.
get_fullpath();
66 return _mount->has_file(_local_filename);
77 return _mount->is_directory(_local_filename);
88 return _mount->is_regular_file(_local_filename);
135 if (new_file->
is_of_type(VirtualFileSimple::get_class_type())) {
137 if (new_file_simple->_mount == _mount) {
139 if (_mount->
rename_file(_local_filename, new_file_simple->_local_filename)) {
168 if (new_file->
is_of_type(VirtualFileSimple::get_class_type())) {
170 if (new_file_simple->_mount == _mount) {
172 if (_mount->
copy_file(_local_filename, new_file_simple->_local_filename)) {
183 static const size_t buffer_size = 4096;
184 char buffer[buffer_size];
186 in->read(buffer, buffer_size);
187 size_t count = in->gcount();
189 out->write(buffer, count);
196 in->read(buffer, buffer_size);
197 count = in->gcount();
230 bool do_uncompress = (_implicit_pz_file || (auto_unwrap && _local_filename.
get_extension() ==
"pz"));
232 Filename local_filename(_local_filename);
238 return _mount->open_read_file(local_filename, do_uncompress);
271 bool do_compress = (_implicit_pz_file || (auto_wrap && _local_filename.
get_extension() ==
"pz"));
273 Filename local_filename(_local_filename);
360 return _mount->get_file_size(_local_filename, stream);
371 return _mount->get_file_size(_local_filename);
390 return _mount->get_timestamp(_local_filename);
415 const string &old_contents,
416 const string &new_contents) {
441 bool do_uncompress = (_implicit_pz_file || (auto_unwrap && _local_filename.
get_extension() ==
"pz"));
443 Filename local_filename(_local_filename);
449 return _mount->
read_file(local_filename, do_uncompress, result);
459 write_file(
const unsigned char *data,
size_t data_size,
bool auto_wrap) {
461 bool do_compress = (_implicit_pz_file || (auto_wrap && _local_filename.
get_extension() ==
"pz"));
463 Filename local_filename(_local_filename);
469 return _mount->
write_file(local_filename, do_compress, data, data_size);
481 bool VirtualFileSimple::
485 if (!_mount->scan_directory(names, _local_filename)) {
496 vector_string::const_iterator ni;
497 for (ni = names.begin(); ni != names.end(); ++ni) {
498 const string &basename = (*ni);
499 if (mount_points.find(basename) == mount_points.
end()) {
500 Filename filename(_local_filename, basename);
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
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 is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.
virtual VirtualFileSystem * get_file_system() const
Returns the VirtualFileSystem this file is associated with.
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
virtual ostream * open_write_file(bool auto_wrap, bool truncate)
Opens the file for writing.
void set_binary()
Indicates that the filename represents a binary file.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
virtual bool delete_file(const Filename &file)
Attempts to delete the indicated file or directory within the mount.
virtual bool atomic_compare_and_exchange_contents(string &orig_contents, const string &old_contents, const string &new_contents)
See Filename::atomic_compare_and_exchange_contents().
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 void close_write_file(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.
virtual bool is_writable() const
Returns true if this file represents a writable regular file (and write_file() may be called)...
The abstract base class for a file or directory within the VirtualFileSystem.
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 ostream * open_append_file()
Works like open_write_file(), but the file is opened in append mode.
virtual void close_read_file(istream *stream) const
Closes a file opened by a previous call to open_read_file().
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
virtual bool rename_file(VirtualFile *new_file)
Attempts to move or rename this file or directory.
virtual void close_read_file(istream *stream) const
Closes a file opened by a previous call to open_read_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 streamsize get_file_size() const
Returns the current size on disk (or wherever it is) of the file before it has been opened...
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 bool is_regular_file() const
Returns true if this file represents a regular file (and read_file() may be called), false otherwise.
virtual bool atomic_read_contents(string &contents) const
See Filename::atomic_read_contents().
virtual bool has_file() const
Returns true if this file exists, false otherwise.
A list of VirtualFiles, as returned by VirtualFile::scan_directory().
The name of a file, such as a texture file or an Egg file.
virtual bool read_file(const Filename &file, bool do_uncompress, pvector< unsigned char > &result) const
Fills up the indicated pvector with the contents of the file, if it is a regular file.
virtual ostream * open_write_file(bool auto_wrap, bool truncate)
Opens the file for writing.
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.
virtual bool is_writable(const Filename &file) const
Returns true if the named file or directory may be written to, false otherwise.
virtual bool delete_file()
Attempts to delete this file or directory.
virtual ostream * open_append_file(const Filename &file)
Works like open_write_file(), but the file is opened in append mode.
virtual bool delete_file()
Attempts to delete this file or directory.
virtual iostream * open_read_append_file(const Filename &file)
Works like open_read_write_file(), but the file is opened in append mode.
virtual istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
VirtualFileSystem * get_file_system() const
Returns the file system this mount object is attached to.
virtual bool copy_file(VirtualFile *new_file)
Attempts to copy the contents of this file to the indicated file.
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...
This class records a particular byte sub-range within an existing file on disk.
virtual void close_write_file(ostream *stream)
Closes a file opened by a previous call to open_write_file().
virtual iostream * open_read_write_file(bool truncate)
Opens the file for writing.
virtual bool read_file(pvector< unsigned char > &result, bool auto_unwrap) const
Fills up the indicated pvector with the contents of the file, if it is a regular file.
virtual bool atomic_read_contents(const Filename &file, string &contents) const
See Filename::atomic_read_contents().
TypeHandle is the identifier used to differentiate C++ class types.
virtual void close_read_write_file(iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
virtual bool atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents, const string &old_contents, const string &new_contents)
See Filename::atomic_compare_and_exchange_contents().
string get_extension() const
Returns the file extension.
virtual void close_write_file(ostream *stream)
Closes a file opened by a previous call to open_write_file().
A simple file or directory within the VirtualFileSystem: this maps to exactly one file on one mount p...
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.
virtual ostream * open_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual void close_read_write_file(iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
virtual bool get_system_info(SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
virtual Filename get_filename() const
Returns the full pathname to this file within the virtual file system.
void add_file(VirtualFile *file)
Adds a new file to the list.
virtual iostream * open_read_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual iostream * open_read_append_file()
Works like open_read_write_file(), but the file is opened in append mode.