Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: ui_fileinterface.cpp
- ===================================================================
- --- ui_fileinterface.cpp (revision 16715)
- +++ ui_fileinterface.cpp (working copy)
- @@ -14,7 +14,7 @@
- UI_FileInterface::UI_FileInterface() : Rocket::Core::FileInterface()
- {
- // TODO Auto-generated constructor stub
- -
- + fileSizeMap.clear();
- }
- UI_FileInterface::~UI_FileInterface()
- @@ -29,17 +29,23 @@
- if( path2[0] == '/' )
- path2.Erase( 0, 1 );
- - if( trap::FS_FOpenFile( path2.CString(), &filenum, FS_READ ) == -1 )
- + int length = trap::FS_FOpenFile( path2.CString(), &filenum, FS_READ );
- + if( length == -1 )
- return 0;
- + // cache file length
- + fileSizeMap[filenum] = length;
- +
- Com_Printf("UI_FileInterface opened %s\n", path2.CString() );
- return static_cast<Rocket::Core::FileHandle>( filenum );
- }
- void UI_FileInterface::Close(Rocket::Core::FileHandle file)
- {
- - if( file != 0 )
- + if( file != 0 ) {
- + fileSizeMap.erase( static_cast<int>( file ) );
- trap::FS_FCloseFile( static_cast<int>( file ) );
- + }
- }
- size_t UI_FileInterface::Read(void *buffer, size_t size, Rocket::Core::FileHandle file)
- @@ -66,4 +72,18 @@
- return trap::FS_Tell( static_cast<int>( file ) );
- }
- +size_t UI_FileInterface::Length(Rocket::Core::FileHandle file)
- +{
- + int filenum = static_cast<int>( file );
- + UI_FileSizeMap::iterator it = fileSizeMap.find( filenum );
- +
- + // assertion failure here means that Length was called without preceeding Open call
- + assert( it != fileSizeMap.end() );
- + if( it == fileSizeMap.end() ) {
- + return 0;
- + }
- +
- + return fileSizeMap[filenum];
- }
- +
- +}
- Index: ui_fileinterface.h
- ===================================================================
- --- ui_fileinterface.h (revision 16715)
- +++ ui_fileinterface.h (working copy)
- @@ -13,6 +13,8 @@
- namespace WSWUI
- {
- +typedef std::map<int, size_t> UI_FileSizeMap;
- +
- class UI_FileInterface : public Rocket::Core::FileInterface
- {
- public:
- @@ -35,6 +37,12 @@
- /// Returns the current position of the file pointer.
- virtual size_t Tell(Rocket::Core::FileHandle file);
- +
- + /// Returns the length of the file.
- + virtual size_t Length(Rocket::Core::FileHandle file);
- +
- +private:
- + UI_FileSizeMap fileSizeMap;
- };
- }
Add Comment
Please, Sign In to add comment