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<StringMethod> AndroidUtil::Method_ZLFile_getPath;
|
||||||
shared_ptr<BooleanMethod> AndroidUtil::Method_ZLFile_isDirectory;
|
shared_ptr<BooleanMethod> AndroidUtil::Method_ZLFile_isDirectory;
|
||||||
shared_ptr<LongMethod> AndroidUtil::Method_ZLFile_size;
|
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_FileInfo;
|
||||||
shared_ptr<Constructor> AndroidUtil::Constructor_FileEncryptionInfo;
|
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_getInputStream = new ObjectMethod(Class_ZLFile, "getInputStream", Class_java_io_InputStream, "()");
|
||||||
Method_ZLFile_getPath = new StringMethod(Class_ZLFile, "getPath", "()");
|
Method_ZLFile_getPath = new StringMethod(Class_ZLFile, "getPath", "()");
|
||||||
Method_ZLFile_size = new LongMethod(Class_ZLFile, "size", "()");
|
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_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");
|
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<StringMethod> Method_ZLFile_getPath;
|
||||||
static shared_ptr<BooleanMethod> Method_ZLFile_isDirectory;
|
static shared_ptr<BooleanMethod> Method_ZLFile_isDirectory;
|
||||||
static shared_ptr<LongMethod> Method_ZLFile_size;
|
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_FileInfo;
|
||||||
static shared_ptr<Constructor> Constructor_FileEncryptionInfo;
|
static shared_ptr<Constructor> Constructor_FileEncryptionInfo;
|
||||||
|
|
|
@ -238,6 +238,13 @@ std::size_t ZLFile::size() const {
|
||||||
return myInfo.Size;
|
return myInfo.Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t ZLFile::lastModified() const {
|
||||||
|
if (!myInfoIsFilled) {
|
||||||
|
fillInfo();
|
||||||
|
}
|
||||||
|
return myInfo.MTime;
|
||||||
|
}
|
||||||
|
|
||||||
bool ZLFile::isDirectory() const {
|
bool ZLFile::isDirectory() const {
|
||||||
if (!myInfoIsFilled) {
|
if (!myInfoIsFilled) {
|
||||||
fillInfo();
|
fillInfo();
|
||||||
|
|
|
@ -59,6 +59,7 @@ public:
|
||||||
|
|
||||||
bool exists() const;
|
bool exists() const;
|
||||||
std::size_t size() const;
|
std::size_t size() const;
|
||||||
|
std::size_t lastModified() const;
|
||||||
|
|
||||||
void forceArchiveType(ArchiveType type) const;
|
void forceArchiveType(ArchiveType type) const;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ struct ZLFileInfo {
|
||||||
bool Exists;
|
bool Exists;
|
||||||
bool IsDirectory;
|
bool IsDirectory;
|
||||||
std::size_t Size;
|
std::size_t Size;
|
||||||
|
std::size_t MTime;
|
||||||
|
|
||||||
ZLFileInfo();
|
ZLFileInfo();
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,8 +57,12 @@ public:
|
||||||
Info info(const std::string &entryName) const;
|
Info info(const std::string &entryName) const;
|
||||||
void collectFileNames(std::vector<std::string> &names) const;
|
void collectFileNames(std::vector<std::string> &names) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string myContainerName;
|
const std::string myContainerName;
|
||||||
|
std::size_t myLastModifiedTime;
|
||||||
std::map<std::string,Info> myInfoMap;
|
std::map<std::string,Info> myInfoMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include <AndroidUtil.h>
|
#include <AndroidUtil.h>
|
||||||
#include <ZLLogger.h>
|
#include <ZLLogger.h>
|
||||||
|
#include <ZLFile.h>
|
||||||
|
|
||||||
#include "ZLZip.h"
|
#include "ZLZip.h"
|
||||||
#include "ZLZipHeader.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) {
|
for (std::size_t i = 0; i < ourStorageSize; ++i) {
|
||||||
shared_ptr<ZLZipEntryCache> cache = ourStoredCaches[i];
|
shared_ptr<ZLZipEntryCache> cache = ourStoredCaches[i];
|
||||||
if (!cache.isNull() && cache->myContainerName == containerName) {
|
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;
|
return cache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +55,7 @@ ZLZipEntryCache::Info::Info() : Offset(-1) {
|
||||||
|
|
||||||
ZLZipEntryCache::ZLZipEntryCache(const std::string &containerName, ZLInputStream &containerStream) : myContainerName(containerName) {
|
ZLZipEntryCache::ZLZipEntryCache(const std::string &containerName, ZLInputStream &containerStream) : myContainerName(containerName) {
|
||||||
//ZLLogger::Instance().println("ZipEntryCache", "creating cache for " + containerName);
|
//ZLLogger::Instance().println("ZipEntryCache", "creating cache for " + containerName);
|
||||||
|
myLastModifiedTime = ZLFile(containerName).lastModified();
|
||||||
if (!containerStream.open()) {
|
if (!containerStream.open()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +83,10 @@ ZLZipEntryCache::ZLZipEntryCache(const std::string &containerName, ZLInputStream
|
||||||
containerStream.close();
|
containerStream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ZLZipEntryCache::isValid() const {
|
||||||
|
return myLastModifiedTime == ZLFile(myContainerName).lastModified();
|
||||||
|
}
|
||||||
|
|
||||||
ZLZipEntryCache::Info ZLZipEntryCache::info(const std::string &entryName) const {
|
ZLZipEntryCache::Info ZLZipEntryCache::info(const std::string &entryName) const {
|
||||||
std::map<std::string,Info>::const_iterator it = myInfoMap.find(entryName);
|
std::map<std::string,Info>::const_iterator it = myInfoMap.find(entryName);
|
||||||
return (it != myInfoMap.end()) ? it->second : Info();
|
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;
|
info.Exists = stat(path.c_str(), &fileStat) == 0;
|
||||||
if (info.Exists) {
|
if (info.Exists) {
|
||||||
info.Size = fileStat.st_size;
|
info.Size = fileStat.st_size;
|
||||||
|
info.MTime = fileStat.st_mtime;
|
||||||
info.IsDirectory = S_ISDIR(fileStat.st_mode);
|
info.IsDirectory = S_ISDIR(fileStat.st_mode);
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
|
|
|
@ -93,6 +93,7 @@ ZLFileInfo ZLAndroidFSManager::fileInfo(const std::string &path) const {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
info.Exists = true;
|
info.Exists = true;
|
||||||
info.Size = AndroidUtil::Method_ZLFile_size->call(javaFile);
|
info.Size = AndroidUtil::Method_ZLFile_size->call(javaFile);
|
||||||
|
info.MTime = AndroidUtil::Method_ZLFile_lastModified->call(javaFile);
|
||||||
}
|
}
|
||||||
env->DeleteLocalRef(javaFile);
|
env->DeleteLocalRef(javaFile);
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,11 @@ public abstract class ZLFile implements InputStreamHolder {
|
||||||
public abstract ZLPhysicalFile getPhysicalFile();
|
public abstract ZLPhysicalFile getPhysicalFile();
|
||||||
public abstract InputStream getInputStream() throws IOException;
|
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 {
|
public final InputStream getInputStream(FileEncryptionInfo encryptionInfo) throws IOException {
|
||||||
if (encryptionInfo == null) {
|
if (encryptionInfo == null) {
|
||||||
return getInputStream();
|
return getInputStream();
|
||||||
|
|
|
@ -44,6 +44,11 @@ public final class ZLPhysicalFile extends ZLFile {
|
||||||
return myFile.length();
|
return myFile.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long lastModified() {
|
||||||
|
return myFile.lastModified();
|
||||||
|
}
|
||||||
|
|
||||||
private Boolean myIsDirectory;
|
private Boolean myIsDirectory;
|
||||||
@Override
|
@Override
|
||||||
public boolean isDirectory() {
|
public boolean isDirectory() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue