add FileStream class

* minimize memory consumption by using FileStream for loading sprites
This commit is contained in:
Eduardo Bart
2012-04-02 12:51:03 -03:00
parent 7e6fe71b5e
commit 8450f1f896
8 changed files with 258 additions and 23 deletions

View File

@@ -21,6 +21,7 @@
*/
#include "resourcemanager.h"
#include "filestream.h"
#include <framework/application.h>
#include <framework/luascript/luainterface.h>
@@ -114,7 +115,7 @@ std::string ResourceManager::loadFile(const std::string& fileName)
bool ResourceManager::saveFile(const std::string& fileName, const uchar* data, uint size)
{
PHYSFS_file* file = PHYSFS_openWrite(checkPath(fileName).c_str());
PHYSFS_file* file = PHYSFS_openWrite(fileName.c_str());
if(!file)
return false;
@@ -141,6 +142,37 @@ bool ResourceManager::saveFile(const std::string& fileName, const std::string& d
return saveFile(fileName, (const uchar*)data.c_str(), data.size());
}
FileStreamPtr ResourceManager::openFile(const std::string& fileName)
{
std::string fullPath = checkPath(fileName);
PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str());
if(!file) {
logTraceError("unable to open file '", fullPath, "': ", PHYSFS_getLastError());
return nullptr;
}
return FileStreamPtr(new FileStream(fullPath, file));
}
FileStreamPtr ResourceManager::appendFile(const std::string& fileName)
{
PHYSFS_File* file = PHYSFS_openAppend(fileName.c_str());
if(!file) {
logTraceError("failed to append file '", fileName, "': ", PHYSFS_getLastError());
return nullptr;
}
return FileStreamPtr(new FileStream(fileName, file));
}
FileStreamPtr ResourceManager::createFile(const std::string& fileName)
{
PHYSFS_File* file = PHYSFS_openWrite(fileName.c_str());
if(!file) {
logTraceError("failed to create file '", fileName, "': ", PHYSFS_getLastError());
return nullptr;
}
return FileStreamPtr(new FileStream(fileName, file));
}
bool ResourceManager::deleteFile(const std::string& fileName)
{
return PHYSFS_delete(checkPath(fileName).c_str()) != 0;