32 nassertv(_file_system ==
nullptr);
43 const Filename &original_filename,
bool implicit_pz_file,
46 if (original_filename.
is_text()) {
53 file->set_original_filename(original_filename);
55 if ((open_flags & VirtualFileSystem::OF_create_file) != 0) {
57 }
else if ((open_flags & VirtualFileSystem::OF_make_directory) != 0) {
132 vector_uchar &result)
const {
135 istream *in = open_read_file(file, do_uncompress);
138 <<
"Unable to read " << file <<
"\n";
142 std::streamsize file_size = get_file_size(file, in);
144 result.reserve((
size_t)file_size);
153 <<
"Error while reading " << file <<
"\n";
164 const unsigned char *data,
size_t data_size) {
166 if (out ==
nullptr) {
168 <<
"Unable to write " << file <<
"\n";
172 out->write((
const char *)data, data_size);
173 bool okflag = (!out->fail());
178 <<
"Error while writing " << file <<
"\n";
191 istream *VirtualFileMount::
192 open_read_file(
const Filename &file,
bool do_uncompress)
const {
193 istream *result = open_read_file(file);
196 if (result !=
nullptr && do_uncompress) {
198 IDecompressStream *wrapper =
new IDecompressStream(result,
true);
239 if (result !=
nullptr && do_compress) {
241 OCompressStream *wrapper =
new OCompressStream(result,
true);
318 const string &old_contents,
319 const string &new_contents) {
334 void VirtualFileMount::
335 output(ostream &out)
const {
342 void VirtualFileMount::
343 write(ostream &out)
const {
virtual void close_write_file(std::ostream *stream)
Closes a file opened by a previous call to open_write_file().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void close_read_write_file(std::iostream *stream)
Closes a file opened by a previous call to open_read_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 atomic_read_contents(const Filename &file, std::string &contents) const
See Filename::atomic_read_contents().
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.
virtual void close_read_write_file(std::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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 is_writable(const Filename &file) const
Returns true if the named file or directory may be written to, false otherwise.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
virtual bool create_file(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
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 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 std::ostream * open_append_file(const Filename &file)
Works like open_write_file(), but the file is opened in append mode.
virtual std::iostream * open_read_append_file(const Filename &file)
Works like open_read_write_file(), but the file is opened in append mode.
bool is_text() const
Returns true if the Filename has been indicated to represent a text file via a previous call to set_t...
virtual bool make_directory(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
static void close_write_file(std::ostream *stream)
Closes a file opened by a previous call to open_write_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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class records a particular byte sub-range within an existing file on disk.
static bool simple_read_file(std::istream *stream, vector_uchar &result)
Fills up the indicated pvector with the contents of the just-opened file.
TypeHandle is the identifier used to differentiate C++ class types.
A simple file or directory within the VirtualFileSystem: this maps to exactly one file on one mount p...
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 std::ostream * open_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual PointerTo< VirtualFile > make_virtual_file(const Filename &local_filename, const Filename &original_filename, bool implicit_pz_file, int open_flags)
Constructs and returns a new VirtualFile instance that corresponds to the indicated filename within t...
virtual std::iostream * open_read_write_file(const Filename &file, bool truncate)
Opens the file for writing.