109 Filename this_filename = get_filename();
110 vector_string mount_points_flat;
116 std::copy(mount_points_flat.begin(), mount_points_flat.end(),
117 std::back_inserter(mount_points));
125 ov_set<string>::const_iterator mi;
126 for (mi = mount_points.
begin(); mi != mount_points.
end(); ++mi) {
127 const string &basename = (*mi);
128 Filename filename(this_filename, basename);
130 file_list->add_file(file);
135 if (!scan_local_directory(file_list, mount_points)) {
137 if (file_list->get_num_files() == 0) {
153 output(ostream &out)
const {
154 out << get_filename();
161 ls(ostream &out)
const {
163 if (contents ==
nullptr) {
165 out << get_filename() <<
"\n";
167 out << get_filename() <<
" cannot be read.\n";
172 int num_files = contents->get_num_files();
173 for (
int i = 0; i < num_files; i++) {
186 out << get_filename() <<
" is not a directory.\n";
188 r_ls_all(out, get_filename());
338 const string &old_contents,
339 const string &new_contents) {
365 result.append((
const char *)&pv[0], pv.size());
376 read_file(vector_uchar &result,
bool auto_unwrap)
const {
385 write_file(
const unsigned char *data,
size_t data_size,
bool auto_wrap) {
396 static const size_t buffer_size = 4096;
397 char buffer[buffer_size];
399 in->read(buffer, buffer_size);
400 size_t count = in->gcount();
402 thread_consider_yield();
403 result.insert(result.end(), buffer, buffer + count);
404 in->read(buffer, buffer_size);
405 count = in->gcount();
408 return (!in->fail() || in->eof());
417 static const size_t buffer_size = 4096;
418 char buffer[buffer_size];
420 in->read(buffer, std::min(buffer_size, max_bytes));
421 size_t count = in->gcount();
423 thread_consider_yield();
424 nassertr(count <= max_bytes,
false);
425 result.insert(result.end(), buffer, buffer + count);
427 in->read(buffer, std::min(buffer_size, max_bytes));
428 count = in->gcount();
431 return (!in->fail() || in->eof());
449 r_ls_all(ostream &out,
const Filename &root)
const {
451 if (contents ==
nullptr) {
455 int num_files = contents->get_num_files();
456 for (
int i = 0; i < num_files; i++) {
458 Filename filename = file->get_filename();
460 out << filename <<
"\n";
462 file->r_ls_all(out, root);
bool write_file(const std::string &data, bool auto_wrap)
Writes the entire contents of the file as a string, if it is writable.
virtual std::ostream * open_append_file()
Works like open_write_file(), but the file is opened in append mode.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A hierarchy of directories and files that appears to be one continuous file system,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::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 is_writable() const
Returns true if this file may be written to, which implies write_file() may be called (unless it is a...
virtual bool copy_file(VirtualFile *new_file)
Attempts to copy the contents of this file to the indicated file.
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
PointerTo< VirtualFileList > scan_directory() const
If the file represents a directory (that is, is_directory() returns true), this returns the list of f...
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.
void ls_all(std::ostream &out=std::cout) const
If the file represents a directory, recursively lists its contents and those of all subdirectories.
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
virtual bool get_system_info(SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
virtual std::iostream * open_read_write_file(bool truncate)
Opens the file for writing.
A list of VirtualFiles, as returned by VirtualFile::scan_directory().
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(std::string &contents) const
See Filename::atomic_read_contents().
virtual void close_read_write_file(std::iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
The name of a file, such as a texture file or an Egg file.
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called),...
void sort()
Maps to sort_unique().
virtual std::iostream * open_read_append_file()
Works like open_read_write_file(), but the file is opened in append mode.
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,...
virtual bool delete_file()
Attempts to delete this file or directory.
virtual bool was_read_successful() const
Call this method after a reading the istream returned by open_read_file() to completion.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
std::string read_file(bool auto_unwrap) const
Returns the entire contents of the file as a string.
virtual bool has_file() const
Returns true if this file exists, false otherwise.
bool make_relative_to(Filename directory, bool allow_backups=true)
Adjusts this filename, which must be a fully-specified pathname beginning with a slash,...
std::string get_basename() const
Returns the basename part of the filename.
virtual std::istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
void ls(std::ostream &out=std::cout) const
If the file represents a directory, lists its contents.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool rename_file(VirtualFile *new_file)
Attempts to move or rename this file or directory.
This class records a particular byte sub-range within an existing file on disk.
virtual std::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(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.
virtual bool is_regular_file() const
Returns true if this file represents a regular file (and read_file() may be called),...
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.
virtual bool atomic_compare_and_exchange_contents(std::string &orig_contents, const std::string &old_contents, const std::string &new_contents)
See Filename::atomic_compare_and_exchange_contents().