15 #include "rocketFileInterface.h"
16 #include "virtualFileSystem.h"
36 Rocket::Core::FileHandle RocketFileInterface::
37 Open(
const Rocket::Core::String& path) {
38 rocket_cat.debug() <<
"Opening " << path.CString() <<
"\n";
46 rocket_cat.error() <<
"Could not resolve " << fn
47 <<
" along the model-path (currently: " << get_model_path() <<
")\n";
48 return (Rocket::Core::FileHandle) NULL;
53 rocket_cat.error() <<
"Failed to get " << fn <<
", found on model-path\n";
54 return (Rocket::Core::FileHandle) NULL;
58 istream *str = file->open_read_file(
true);
60 rocket_cat.error() <<
"Failed to open " << fn <<
" for reading\n";
61 return (Rocket::Core::FileHandle) NULL;
64 VirtualFileHandle *handle =
new VirtualFileHandle;
66 handle->_stream = str;
69 return (Rocket::Core::FileHandle) handle;
77 void RocketFileInterface::
78 Close(Rocket::Core::FileHandle file) {
79 VirtualFileHandle *handle = (VirtualFileHandle*) file;
93 size_t RocketFileInterface::
94 Read(
void* buffer,
size_t size, Rocket::Core::FileHandle file) {
95 VirtualFileHandle *handle = (VirtualFileHandle*) file;
100 handle->_stream->read((
char*) buffer, size);
101 return handle->_stream->gcount();
109 bool RocketFileInterface::
110 Seek(Rocket::Core::FileHandle file,
long offset,
int origin) {
111 VirtualFileHandle *handle = (VirtualFileHandle*) file;
112 if (handle == NULL) {
118 handle->_stream->seekg(offset, ios::beg);
121 handle->_stream->seekg(offset, ios::cur);
124 handle->_stream->seekg(offset, ios::end);
127 return !handle->_stream->fail();
135 size_t RocketFileInterface::
136 Tell(Rocket::Core::FileHandle file) {
137 VirtualFileHandle *handle = (VirtualFileHandle*) file;
138 if (handle == NULL) {
142 return handle->_stream->tellg();
150 size_t RocketFileInterface::
151 Length(Rocket::Core::FileHandle file) {
152 VirtualFileHandle *handle = (VirtualFileHandle*) file;
153 if (handle == NULL) {
157 return handle->_file->get_file_size(handle->_stream);
RocketFileInterface(VirtualFileSystem *vfs=NULL)
Constructs a RocketFileInterface for the given VFS, or the default if NULL is given.
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.
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().
The name of a file, such as a texture file or an Egg file.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const string &default_extension=string()) const
Searches the given search path for the filename.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
static Filename from_os_specific(const 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).