15 #include "virtualFileMountSystem.h"
17 TypeHandle VirtualFileMountSystem::_type_handle;
28 Filename pathname(_physical_filename, file);
35 if (case_pathname != pathname) {
37 <<
"Filename is incorrect case: " << pathname
38 <<
" instead of " << case_pathname <<
"\n";
56 Filename pathname(_physical_filename, file);
73 Filename pathname(_physical_filename, file);
88 Filename orig_pathname(_physical_filename, orig_filename);
89 Filename new_pathname(_physical_filename, new_filename);
90 return orig_pathname.
rename_to(new_pathname);
104 Filename orig_pathname(_physical_filename, orig_filename);
105 Filename new_pathname(_physical_filename, new_filename);
106 return orig_pathname.
copy_to(new_pathname);
120 Filename pathname(_physical_filename, file);
121 return pathname.
mkdir();
140 Filename pathname(_physical_filename, file);
160 Filename pathname(_physical_filename, file);
180 Filename pathname(_physical_filename, file);
202 Filename pathname(_physical_filename, file);
203 pifstream *stream =
new pifstream;
231 Filename pathname(_physical_filename, file);
232 pofstream *stream =
new pofstream;
233 if (!pathname.
open_write(*stream, truncate)) {
260 Filename pathname(_physical_filename, file);
261 pofstream *stream =
new pofstream;
289 Filename pathname(_physical_filename, file);
290 pfstream *stream =
new pfstream;
318 Filename pathname(_physical_filename, file);
319 pfstream *stream =
new pfstream;
341 streampos orig = stream->tellg();
344 stream->seekg(0, ios::end);
345 if (stream->fail()) {
350 streampos size = stream->tellg();
353 stream->seekg(orig, ios::beg);
369 Filename pathname(_physical_filename, file);
389 Filename pathname(_physical_filename, file);
405 Filename pathname(_physical_filename, file);
428 Filename pathname(_physical_filename, dir);
440 const string &old_contents,
441 const string &new_contents) {
450 Filename pathname(_physical_filename, file);
469 Filename pathname(_physical_filename, file);
478 void VirtualFileMountSystem::
479 output(ostream &out)
const {
virtual bool make_directory(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
bool mkdir() const
Creates the directory named by this filename.
bool open_append(ofstream &stream) const
Opens the indicated ofstream for writing the file, if possible.
bool atomic_read_contents(string &contents) const
Uses native file-locking mechanisms to atomically read the contents of a (small) file.
virtual bool is_directory(const Filename &file) const
Returns true if the indicated file exists within the mount system and is a directory.
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().
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
bool is_directory() const
Returns true if the filename exists and is a directory name, false otherwise.
virtual istream * open_read_file(const Filename &file) const
Opens the file for reading, if it exists.
virtual iostream * open_read_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual time_t get_timestamp(const Filename &file) const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
void set_binary()
Indicates that the filename represents a binary file.
bool open_read(ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
bool make_true_case()
On a case-insensitive operating system (e.g.
bool open_read_write(fstream &stream, bool truncate=false) const
Opens the indicated fstream for read/write access to the file, if possible.
bool scan_directory(vector_string &contents) const
Attempts to open the named filename as if it were a directory and looks for the non-hidden files with...
virtual bool has_file(const Filename &file) const
Returns true if the indicated file exists within the mount system.
virtual ostream * open_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual void close_read_file(istream *stream) const
Closes a file opened by a previous call to open_read_file().
bool copy_to(const Filename &other) const
Copies the file to the indicated new filename, by reading the contents and writing it to the new file...
virtual bool atomic_read_contents(const Filename &file, string &contents) const
See Filename::atomic_read_contents().
virtual ostream * open_append_file(const Filename &file)
Works like open_write_file(), but the file is opened in append mode.
const Filename & get_physical_filename() const
Returns the name of the source file on the OS filesystem of the directory or file that is mounted...
bool is_writable() const
Returns true if the filename exists and is either a directory or a regular file that can be written t...
virtual bool create_file(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
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 scan_directory(vector_string &contents, const Filename &dir) const
Fills the given vector up with the list of filenames that are local to this directory, if the filename is a directory.
bool rename_to(const Filename &other) const
Renames the file to the indicated new filename.
The name of a file, such as a texture file or an Egg file.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
virtual bool is_regular_file(const Filename &file) const
Returns true if the indicated file exists within the mount system and is a regular file...
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
bool open_read_append(fstream &stream) const
Opens the indicated ifstream for reading and writing the file, if possible; writes are appended to th...
streamsize get_file_size() const
Returns the size of the file in bytes, or 0 if there is an error.
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 bool delete_file(const Filename &file)
Attempts to delete the indicated file or directory within the mount.
bool is_regular_file() const
Returns true if the filename exists and is the name of a regular file (i.e.
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
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 iostream * open_read_append_file(const Filename &file)
Works like open_read_write_file(), but the file is opened in append mode.
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.
time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
bool rmdir() const
The inverse of mkdir(): this removes the directory named by this Filename, if it is in fact a directo...
bool atomic_compare_and_exchange_contents(string &orig_contents, const string &old_contents, const string &new_contents) const
Uses native file-locking mechanisms to atomically replace the contents of a (small) file with the spe...
virtual bool is_writable(const Filename &file) const
Returns true if the named file or directory may be written to, false otherwise.
virtual streamsize get_file_size(const Filename &file, istream *stream) const
Returns the current size on disk (or wherever it is) of the already-open 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...