summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfszip.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/virtfszip.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/virtfszip.cpp')
-rw-r--r--src/fs/virtfs/virtfszip.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/fs/virtfs/virtfszip.cpp b/src/fs/virtfs/virtfszip.cpp
index 78c294f85..687245f3a 100644
--- a/src/fs/virtfs/virtfszip.cpp
+++ b/src/fs/virtfs/virtfszip.cpp
@@ -72,6 +72,7 @@ namespace VirtFsZip
ptr->openRead = &VirtFsZip::openRead;
ptr->openWrite = &VirtFsZip::openWrite;
ptr->openAppend = &VirtFsZip::openAppend;
+ ptr->loadFile = &VirtFsZip::loadFile;
}
bool getRealDir(VirtFsEntry *restrict const entry,
@@ -336,4 +337,36 @@ namespace VirtFsZip
return file->mPrivate->mPos >= file->mPrivate->mSize;
}
+
+ char *loadFile(VirtFsEntry *restrict const entry,
+ const std::string &restrict filename,
+ int &restrict fileSize)
+ {
+ VirtZipEntry *const zipEntry = static_cast<VirtZipEntry*>(entry);
+ FOR_EACH (std::vector<ZipLocalHeader*>::const_iterator,
+ it2,
+ zipEntry->mHeaders)
+ {
+ const ZipLocalHeader *restrict const header = *it2;
+ if (header->fileName == filename)
+ {
+ uint8_t *restrict const buf = Zip::readFile(header);
+ if (buf == nullptr)
+ return nullptr;
+
+ logger->log("Loaded %s/%s",
+ entry->root.c_str(),
+ filename.c_str());
+
+ fileSize = header->uncompressSize;
+ // Allocate memory and load the file
+ char *restrict const buffer = new char[fileSize];
+ if (fileSize > 0)
+ buffer[fileSize - 1] = 0;
+ memcpy(buffer, buf, fileSize);
+ return buffer;
+ }
+ }
+ return nullptr;
+ }
} // namespace VirtFsZip