15 #include "virtualFile.h"
16 #include "virtualFileSystem.h"
17 #include "virtualFileList.h"
18 #include "config_express.h"
125 scan_directory()
const {
129 Filename this_filename = get_filename();
130 vector_string mount_points_flat;
136 copy(mount_points_flat.begin(), mount_points_flat.end(),
137 back_inserter(mount_points));
145 ov_set<string>::const_iterator mi;
146 for (mi = mount_points.
begin(); mi != mount_points.
end(); ++mi) {
147 const string &basename = (*mi);
148 Filename filename(this_filename, basename);
150 file_list->add_file(file);
155 if (!scan_local_directory(file_list, mount_points)) {
157 if (file_list->get_num_files() == 0) {
175 output(ostream &out)
const {
176 out << get_filename();
186 ls(ostream &out)
const {
190 out << get_filename() <<
"\n";
192 out << get_filename() <<
" cannot be read.\n";
197 int num_files = contents->get_num_files();
198 for (
int i = 0; i < num_files; i++) {
213 out << get_filename() <<
" is not a directory.\n";
215 r_ls_all(out, get_filename());
407 const string &old_contents,
408 const string &new_contents) {
439 result.append((
const char *)&pv[0], pv.size());
464 write_file(
const unsigned char *data,
size_t data_size,
bool auto_wrap) {
478 static const size_t buffer_size = 4096;
479 char buffer[buffer_size];
481 in->read(buffer, buffer_size);
482 size_t count = in->gcount();
484 thread_consider_yield();
485 result.insert(result.end(), buffer, buffer + count);
486 in->read(buffer, buffer_size);
487 count = in->gcount();
490 return (!in->fail() || in->eof());
501 static const size_t buffer_size = 4096;
502 char buffer[buffer_size];
504 in->read(buffer, min(buffer_size, max_bytes));
505 size_t count = in->gcount();
507 thread_consider_yield();
508 nassertr(count <= max_bytes,
false);
509 result.insert(result.end(), buffer, buffer + count);
511 in->read(buffer, min(buffer_size, max_bytes));
512 count = in->gcount();
515 return (!in->fail() || in->eof());
538 r_ls_all(ostream &out,
const Filename &root)
const {
544 int num_files = contents->get_num_files();
545 for (
int i = 0; i < num_files; i++) {
547 Filename filename = file->get_filename();
549 out << filename <<
"\n";
551 file->r_ls_all(out, root);
void scan_mount_points(vector_string &names, const Filename &path) const
Adds to names a list of all the mount points in use that are one directory below path, if any.
void ls_all(ostream &out=cout) const
If the file represents a directory, recursively lists its contents and those of all subdirectories...
virtual ostream * open_append_file()
Works like open_write_file(), but the file is opened in append mode.
virtual istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
virtual void close_read_write_file(iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
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 bool atomic_read_contents(string &contents) const
See Filename::atomic_read_contents().
virtual ostream * open_write_file(bool auto_wrap, bool truncate)
Opens the file for writing.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
virtual bool copy_file(VirtualFile *new_file)
Attempts to copy the contents of this file to the indicated file.
virtual bool is_writable() const
Returns true if this file may be written to, which implies write_file() may be called (unless it is a...
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.
The abstract base class for a file or directory within the VirtualFileSystem.
PointerTo< VirtualFileList > scan_directory() const
If the file represents a directory (that is, is_directory() returns true), this returns the list of f...
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
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 has_file() const
Returns true if this file exists, false otherwise.
virtual bool get_system_info(SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
virtual iostream * open_read_write_file(bool truncate)
Opens the file for writing.
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
A list of VirtualFiles, as returned by VirtualFile::scan_directory().
The name of a file, such as a texture file or an Egg file.
void sort()
Maps to sort_unique().
virtual iostream * open_read_append_file()
Works like open_read_write_file(), but the file is opened in append mode.
virtual bool delete_file()
Attempts to delete this file or directory.
void ls(ostream &out=cout) const
If the file represents a directory, lists its contents.
virtual void close_read_file(istream *stream) const
Closes a file opened by a previous call to open_read_file().
bool make_relative_to(Filename directory, bool allow_backups=true)
Adjusts this filename, which must be a fully-specified pathname beginning with a slash, to make it a relative filename, relative to the fully-specified directory indicated (which must also begin with, and may or may not end with, a slash–a terminating slash is ignored).
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
bool write_file(const string &data, bool auto_wrap)
Writes the entire contents of the file as a string, if it is writable.
string get_basename() const
Returns the basename part of the filename.
virtual bool was_read_successful() const
Call this method after a reading the istream returned by open_read_file() to completion.
string read_file(bool auto_unwrap) const
Returns the entire contents of the file as a string.
virtual bool rename_file(VirtualFile *new_file)
Attempts to move or rename this file or directory.
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().
This class records a particular byte sub-range within an existing file on disk.
virtual streamsize get_file_size() const
Returns the current size on disk (or wherever it is) of the file before it has been opened...
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.
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.