mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
update zip entry cache every time base file is modified
This commit is contained in:
parent
0a90ed38cd
commit
7d5ad20f14
11 changed files with 42 additions and 2 deletions
|
@ -95,6 +95,7 @@ shared_ptr<ObjectMethod> AndroidUtil::Method_ZLFile_getInputStream;
|
|||
shared_ptr<StringMethod> AndroidUtil::Method_ZLFile_getPath;
|
||||
shared_ptr<BooleanMethod> AndroidUtil::Method_ZLFile_isDirectory;
|
||||
shared_ptr<LongMethod> AndroidUtil::Method_ZLFile_size;
|
||||
shared_ptr<LongMethod> AndroidUtil::Method_ZLFile_lastModified;
|
||||
|
||||
shared_ptr<Constructor> AndroidUtil::Constructor_FileInfo;
|
||||
shared_ptr<Constructor> AndroidUtil::Constructor_FileEncryptionInfo;
|
||||
|
@ -177,6 +178,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
Method_ZLFile_getInputStream = new ObjectMethod(Class_ZLFile, "getInputStream", Class_java_io_InputStream, "()");
|
||||
Method_ZLFile_getPath = new StringMethod(Class_ZLFile, "getPath", "()");
|
||||
Method_ZLFile_size = new LongMethod(Class_ZLFile, "size", "()");
|
||||
Method_ZLFile_lastModified = new LongMethod(Class_ZLFile, "lastModified", "()");
|
||||
|
||||
Constructor_FileInfo = new Constructor(Class_FileInfo, "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/drm/FileEncryptionInfo;)V");
|
||||
Constructor_FileEncryptionInfo = new Constructor(Class_FileEncryptionInfo, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
|
|
|
@ -117,6 +117,7 @@ public:
|
|||
static shared_ptr<StringMethod> Method_ZLFile_getPath;
|
||||
static shared_ptr<BooleanMethod> Method_ZLFile_isDirectory;
|
||||
static shared_ptr<LongMethod> Method_ZLFile_size;
|
||||
static shared_ptr<LongMethod> Method_ZLFile_lastModified;
|
||||
|
||||
static shared_ptr<Constructor> Constructor_FileInfo;
|
||||
static shared_ptr<Constructor> Constructor_FileEncryptionInfo;
|
||||
|
|
|
@ -238,6 +238,13 @@ std::size_t ZLFile::size() const {
|
|||
return myInfo.Size;
|
||||
}
|
||||
|
||||
std::size_t ZLFile::lastModified() const {
|
||||
if (!myInfoIsFilled) {
|
||||
fillInfo();
|
||||
}
|
||||
return myInfo.MTime;
|
||||
}
|
||||
|
||||
bool ZLFile::isDirectory() const {
|
||||
if (!myInfoIsFilled) {
|
||||
fillInfo();
|
||||
|
|
|
@ -59,6 +59,7 @@ public:
|
|||
|
||||
bool exists() const;
|
||||
std::size_t size() const;
|
||||
std::size_t lastModified() const;
|
||||
|
||||
void forceArchiveType(ArchiveType type) const;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ struct ZLFileInfo {
|
|||
bool Exists;
|
||||
bool IsDirectory;
|
||||
std::size_t Size;
|
||||
std::size_t MTime;
|
||||
|
||||
ZLFileInfo();
|
||||
};
|
||||
|
|
|
@ -57,8 +57,12 @@ public:
|
|||
Info info(const std::string &entryName) const;
|
||||
void collectFileNames(std::vector<std::string> &names) const;
|
||||
|
||||
private:
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
const std::string myContainerName;
|
||||
std::size_t myLastModifiedTime;
|
||||
std::map<std::string,Info> myInfoMap;
|
||||
};
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <AndroidUtil.h>
|
||||
#include <ZLLogger.h>
|
||||
#include <ZLFile.h>
|
||||
|
||||
#include "ZLZip.h"
|
||||
#include "ZLZipHeader.h"
|
||||
|
@ -34,6 +35,12 @@ shared_ptr<ZLZipEntryCache> ZLZipEntryCache::cache(const std::string &containerN
|
|||
for (std::size_t i = 0; i < ourStorageSize; ++i) {
|
||||
shared_ptr<ZLZipEntryCache> cache = ourStoredCaches[i];
|
||||
if (!cache.isNull() && cache->myContainerName == containerName) {
|
||||
//ZLLogger::Instance().println("ZipEntryCache", "cache found for " + containerName);
|
||||
if (!cache->isValid()) {
|
||||
//ZLLogger::Instance().println("ZipEntryCache", "cache is not valid for " + containerName);
|
||||
cache = new ZLZipEntryCache(containerName, containerStream);
|
||||
ourStoredCaches[i] = cache;
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +55,7 @@ ZLZipEntryCache::Info::Info() : Offset(-1) {
|
|||
|
||||
ZLZipEntryCache::ZLZipEntryCache(const std::string &containerName, ZLInputStream &containerStream) : myContainerName(containerName) {
|
||||
//ZLLogger::Instance().println("ZipEntryCache", "creating cache for " + containerName);
|
||||
myLastModifiedTime = ZLFile(containerName).lastModified();
|
||||
if (!containerStream.open()) {
|
||||
return;
|
||||
}
|
||||
|
@ -75,6 +83,10 @@ ZLZipEntryCache::ZLZipEntryCache(const std::string &containerName, ZLInputStream
|
|||
containerStream.close();
|
||||
}
|
||||
|
||||
bool ZLZipEntryCache::isValid() const {
|
||||
return myLastModifiedTime == ZLFile(myContainerName).lastModified();
|
||||
}
|
||||
|
||||
ZLZipEntryCache::Info ZLZipEntryCache::info(const std::string &entryName) const {
|
||||
std::map<std::string,Info>::const_iterator it = myInfoMap.find(entryName);
|
||||
return (it != myInfoMap.end()) ? it->second : Info();
|
||||
|
|
|
@ -47,6 +47,7 @@ ZLFileInfo ZLUnixFSManager::fileInfo(const std::string &path) const {
|
|||
info.Exists = stat(path.c_str(), &fileStat) == 0;
|
||||
if (info.Exists) {
|
||||
info.Size = fileStat.st_size;
|
||||
info.MTime = fileStat.st_mtime;
|
||||
info.IsDirectory = S_ISDIR(fileStat.st_mode);
|
||||
}
|
||||
return info;
|
||||
|
|
|
@ -93,6 +93,7 @@ ZLFileInfo ZLAndroidFSManager::fileInfo(const std::string &path) const {
|
|||
if (exists) {
|
||||
info.Exists = true;
|
||||
info.Size = AndroidUtil::Method_ZLFile_size->call(javaFile);
|
||||
info.MTime = AndroidUtil::Method_ZLFile_lastModified->call(javaFile);
|
||||
}
|
||||
env->DeleteLocalRef(javaFile);
|
||||
|
||||
|
|
|
@ -151,6 +151,11 @@ public abstract class ZLFile implements InputStreamHolder {
|
|||
public abstract ZLPhysicalFile getPhysicalFile();
|
||||
public abstract InputStream getInputStream() throws IOException;
|
||||
|
||||
public long lastModified() {
|
||||
final ZLFile physicalFile = getPhysicalFile();
|
||||
return physicalFile != null ? physicalFile.lastModified() : 0;
|
||||
}
|
||||
|
||||
public final InputStream getInputStream(FileEncryptionInfo encryptionInfo) throws IOException {
|
||||
if (encryptionInfo == null) {
|
||||
return getInputStream();
|
||||
|
|
|
@ -44,6 +44,11 @@ public final class ZLPhysicalFile extends ZLFile {
|
|||
return myFile.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lastModified() {
|
||||
return myFile.lastModified();
|
||||
}
|
||||
|
||||
private Boolean myIsDirectory;
|
||||
@Override
|
||||
public boolean isDirectory() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue