15 #include "virtualFileMount.h"
16 #include "virtualFileSimple.h"
17 #include "virtualFileSystem.h"
30 nassertv(_file_system == NULL);
44 make_virtual_file(const
Filename &local_filename,
45 const
Filename &original_filename,
bool implicit_pz_file,
48 if (original_filename.is_text()) {
55 file->set_original_filename(original_filename);
57 if ((open_flags & VirtualFileSystem::OF_create_file) != 0) {
59 }
else if ((open_flags & VirtualFileSystem::OF_make_directory) != 0) {
60 make_directory(local);
158 istream *in = open_read_file(file, do_uncompress);
159 if (in == (istream *)NULL) {
161 <<
"Unable to read " << file <<
"\n";
165 streamsize file_size = get_file_size(file, in);
167 result.reserve((
size_t)file_size);
176 <<
"Error while reading " << file <<
"\n";
190 const unsigned char *data,
size_t data_size) {
192 if (out == (ostream *)NULL) {
194 <<
"Unable to write " << file <<
"\n";
198 out->write((
const char *)data, data_size);
199 bool okflag = (!out->fail());
204 <<
"Error while writing " << file <<
"\n";
220 istream *VirtualFileMount::
221 open_read_file(
const Filename &file,
bool do_uncompress)
const {
222 istream *result = open_read_file(file);
225 if (result != (istream *)NULL && do_uncompress) {
227 IDecompressStream *wrapper =
new IDecompressStream(result,
true);
278 if (result != (ostream *)NULL && do_compress) {
280 OCompressStream *wrapper =
new OCompressStream(result,
true);
377 const string &old_contents,
378 const string &new_contents) {
397 void VirtualFileMount::
398 output(ostream &out)
const {
407 void VirtualFileMount::
408 write(ostream &out)
const {
const Filename & get_mount_point() const
Returns the name of the directory within the virtual file system that this mount object is attached t...
void set_binary()
Indicates that the filename represents a binary file.
void set_text()
Indicates that the filename represents a text file.
virtual bool delete_file(const Filename &file)
Attempts to delete the indicated file or directory within the mount.
static void close_read_write_file(iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
The abstract base class for a file or directory within the VirtualFileSystem.
static void close_read_file(istream *stream)
Closes a file opened by a previous call to open_read_file().
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 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 create_file(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
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 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 ostream * open_append_file(const Filename &file)
Works like open_write_file(), but the file is opened in append mode.
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 make_directory(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
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...
The abstract base class for a mount definition used within a VirtualFileSystem.
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 atomic_read_contents(const Filename &file, string &contents) const
See Filename::atomic_read_contents().
static bool simple_read_file(istream *stream, pvector< unsigned char > &result)
Fills up the indicated pvector with the contents of the just-opened file.
TypeHandle is the identifier used to differentiate C++ class types.
static void close_write_file(ostream *stream)
Closes a file opened by a previous call to open_write_file().
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().
A simple file or directory within the VirtualFileSystem: this maps to exactly one file on one mount p...
virtual ostream * open_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual iostream * open_read_write_file(const Filename &file, bool truncate)
Opens the file for writing.