summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfs.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-29 01:49:04 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-29 01:49:04 +0300
commit97d9ed131ae4fad7d54274cf5b74cf587b391bad (patch)
treed742590d67aa5eb462ee3bccd28f64bcd67d7322 /src/fs/virtfs/virtfs.cpp
parenta85c68d09497c1242064998dbc19ffab4a485ab6 (diff)
downloadplus-97d9ed131ae4fad7d54274cf5b74cf587b391bad.tar.gz
plus-97d9ed131ae4fad7d54274cf5b74cf587b391bad.tar.bz2
plus-97d9ed131ae4fad7d54274cf5b74cf587b391bad.tar.xz
plus-97d9ed131ae4fad7d54274cf5b74cf587b391bad.zip
Impliment loadFile in each virtual file system.
Diffstat (limited to 'src/fs/virtfs/virtfs.cpp')
-rw-r--r--src/fs/virtfs/virtfs.cpp34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/fs/virtfs/virtfs.cpp b/src/fs/virtfs/virtfs.cpp
index b36ee5ddd..9d1432270 100644
--- a/src/fs/virtfs/virtfs.cpp
+++ b/src/fs/virtfs/virtfs.cpp
@@ -562,32 +562,24 @@ namespace VirtFs
return file->funcs->eof(file);
}
- char *loadFile(const std::string &restrict fileName,
+ char *loadFile(std::string filename,
int &restrict fileSize)
{
- // Attempt to open the specified file using PhysicsFS
- VirtFile *restrict const file = VirtFs::openRead(fileName);
-
- if (!file)
+ prepareFsPath(filename);
+ if (checkPath(filename) == false)
{
- logger->log("Warning: Failed to load %s.",
- fileName.c_str());
+ reportAlways("VirtFs::loadFile invalid path: %s",
+ filename.c_str());
return nullptr;
}
-
- logger->log("Loaded %s/%s",
- VirtFs::getRealDir(fileName).c_str(),
- fileName.c_str());
-
- fileSize = CAST_S32(VirtFs::fileLength(file));
- // Allocate memory and load the file
- char *restrict const buffer = new char[fileSize];
- if (fileSize > 0)
- buffer[fileSize - 1] = 0;
- VirtFs::read(file, buffer, 1, fileSize);
- VirtFs::close(file);
-
- return buffer;
+ FOR_EACH (std::vector<VirtFsEntry*>::const_iterator, it, mEntries)
+ {
+ VirtFsEntry *const entry = *it;
+ char *const buf = entry->funcs->loadFile(entry, filename, fileSize);
+ if (buf != nullptr)
+ return buf;
+ }
+ return nullptr;
}
} // namespace VirtFs