23 if (_vfs ==
nullptr) {
31 Rocket::Core::FileHandle RocketFileInterface::
32 Open(
const Rocket::Core::String& path) {
33 rocket_cat.debug() <<
"Opening " << path.CString() <<
"\n";
38 if (file ==
nullptr) {
41 rocket_cat.error() <<
"Could not resolve " << fn
42 <<
" along the model-path (currently: " << get_model_path() <<
")\n";
43 return (Rocket::Core::FileHandle)
nullptr;
47 if (file ==
nullptr) {
48 rocket_cat.error() <<
"Failed to get " << fn <<
", found on model-path\n";
49 return (Rocket::Core::FileHandle)
nullptr;
53 std::istream *str = file->open_read_file(
true);
55 rocket_cat.error() <<
"Failed to open " << fn <<
" for reading\n";
56 return (Rocket::Core::FileHandle)
nullptr;
59 VirtualFileHandle *handle =
new VirtualFileHandle;
61 handle->_stream = str;
64 return (Rocket::Core::FileHandle) handle;
70 void RocketFileInterface::
71 Close(Rocket::Core::FileHandle file) {
72 VirtualFileHandle *handle = (VirtualFileHandle*) file;
73 if (handle ==
nullptr) {
84 size_t RocketFileInterface::
85 Read(
void* buffer,
size_t size, Rocket::Core::FileHandle file) {
86 VirtualFileHandle *handle = (VirtualFileHandle*) file;
87 if (handle ==
nullptr) {
91 handle->_stream->read((
char*) buffer, size);
92 return handle->_stream->gcount();
98 bool RocketFileInterface::
99 Seek(Rocket::Core::FileHandle file,
long offset,
int origin) {
100 VirtualFileHandle *handle = (VirtualFileHandle*) file;
101 if (handle ==
nullptr) {
107 handle->_stream->seekg(offset, std::ios::beg);
110 handle->_stream->seekg(offset, std::ios::cur);
113 handle->_stream->seekg(offset, std::ios::end);
116 return !handle->_stream->fail();
122 size_t RocketFileInterface::
123 Tell(Rocket::Core::FileHandle file) {
124 VirtualFileHandle *handle = (VirtualFileHandle*) file;
125 if (handle ==
nullptr) {
129 return handle->_stream->tellg();
135 size_t RocketFileInterface::
136 Length(Rocket::Core::FileHandle file) {
137 VirtualFileHandle *handle = (VirtualFileHandle*) file;
138 if (handle ==
nullptr) {
142 return handle->_file->get_file_size(handle->_stream);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const std::string &default_extension=std::string()) const
Searches the given search path for the filename.
The abstract base class for a file or directory within the VirtualFileSystem.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
The name of a file, such as a texture file or an Egg file.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
RocketFileInterface(VirtualFileSystem *vfs=nullptr)
Constructs a RocketFileInterface for the given VFS, or the default if NULL is given.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).