mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
no tempDirectory() call in native code
This commit is contained in:
parent
c4769ba472
commit
7302442028
9 changed files with 14 additions and 112 deletions
|
@ -171,7 +171,6 @@ LOCAL_SRC_FILES := \
|
||||||
NativeFormats/fbreader/src/library/Author.cpp \
|
NativeFormats/fbreader/src/library/Author.cpp \
|
||||||
NativeFormats/fbreader/src/library/Book.cpp \
|
NativeFormats/fbreader/src/library/Book.cpp \
|
||||||
NativeFormats/fbreader/src/library/Comparators.cpp \
|
NativeFormats/fbreader/src/library/Comparators.cpp \
|
||||||
NativeFormats/fbreader/src/library/Library.cpp \
|
|
||||||
NativeFormats/fbreader/src/library/Tag.cpp \
|
NativeFormats/fbreader/src/library/Tag.cpp \
|
||||||
NativeFormats/fbreader/src/library/UID.cpp
|
NativeFormats/fbreader/src/library/UID.cpp
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include "fbreader/src/bookmodel/BookModel.h"
|
#include "fbreader/src/bookmodel/BookModel.h"
|
||||||
#include "fbreader/src/formats/FormatPlugin.h"
|
#include "fbreader/src/formats/FormatPlugin.h"
|
||||||
#include "fbreader/src/library/Library.h"
|
|
||||||
#include "fbreader/src/library/Author.h"
|
#include "fbreader/src/library/Author.h"
|
||||||
#include "fbreader/src/library/Book.h"
|
#include "fbreader/src/library/Book.h"
|
||||||
#include "fbreader/src/library/Tag.h"
|
#include "fbreader/src/library/Tag.h"
|
||||||
|
@ -162,8 +161,8 @@ JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
|
||||||
fillLanguageAndEncoding(env, javaBook, *book);
|
fillLanguageAndEncoding(env, javaBook, *book);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool initInternalHyperlinks(JNIEnv *env, jobject javaModel, BookModel &model) {
|
static bool initInternalHyperlinks(JNIEnv *env, jobject javaModel, BookModel &model, const std::string &cacheDir) {
|
||||||
ZLCachedMemoryAllocator allocator(131072, Library::Instance().cacheDirectory(), "nlinks");
|
ZLCachedMemoryAllocator allocator(131072, cacheDir, "nlinks");
|
||||||
|
|
||||||
ZLUnicodeUtil::Ucs2String ucs2id;
|
ZLUnicodeUtil::Ucs2String ucs2id;
|
||||||
ZLUnicodeUtil::Ucs2String ucs2modelId;
|
ZLUnicodeUtil::Ucs2String ucs2modelId;
|
||||||
|
@ -269,16 +268,18 @@ static jobject createJavaFileInfo(JNIEnv *env, shared_ptr<FileInfo> info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel) {
|
JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel, jstring javaCacheDir) {
|
||||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||||
if (plugin.isNull()) {
|
if (plugin.isNull()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string cacheDir = AndroidUtil::fromJavaString(env, javaCacheDir);
|
||||||
|
|
||||||
jobject javaBook = AndroidUtil::Field_BookModel_Book->value(javaModel);
|
jobject javaBook = AndroidUtil::Field_BookModel_Book->value(javaModel);
|
||||||
|
|
||||||
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
||||||
shared_ptr<BookModel> model = new BookModel(book, javaModel);
|
shared_ptr<BookModel> model = new BookModel(book, javaModel, cacheDir);
|
||||||
if (!plugin->readModel(*model)) {
|
if (!plugin->readModel(*model)) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -286,7 +287,7 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initInternalHyperlinks(env, javaModel, *model)) {
|
if (!initInternalHyperlinks(env, javaModel, *model, cacheDir)) {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,11 @@
|
||||||
|
|
||||||
#include "../formats/FormatPlugin.h"
|
#include "../formats/FormatPlugin.h"
|
||||||
#include "../library/Book.h"
|
#include "../library/Book.h"
|
||||||
#include "../library/Library.h"
|
|
||||||
|
|
||||||
BookModel::BookModel(const shared_ptr<Book> book, jobject javaModel) : myBook(book) {
|
BookModel::BookModel(const shared_ptr<Book> book, jobject javaModel, const std::string &cacheDir) : CacheDir(cacheDir), myBook(book) {
|
||||||
myJavaModel = AndroidUtil::getEnv()->NewGlobalRef(javaModel);
|
myJavaModel = AndroidUtil::getEnv()->NewGlobalRef(javaModel);
|
||||||
|
|
||||||
const std::string cacheDirectory = Library::Instance().cacheDirectory();
|
myBookTextModel = new ZLTextPlainModel(std::string(), book->language(), 131072, CacheDir, "ncache", myFontManager);
|
||||||
myBookTextModel = new ZLTextPlainModel(std::string(), book->language(), 131072, cacheDirectory, "ncache", myFontManager);
|
|
||||||
myContentsTree = new ContentsTree();
|
myContentsTree = new ContentsTree();
|
||||||
/*shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(book->file(), false);
|
/*shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(book->file(), false);
|
||||||
if (!plugin.isNull()) {
|
if (!plugin.isNull()) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BookModel(const shared_ptr<Book> book, jobject javaModel);
|
BookModel(const shared_ptr<Book> book, jobject javaModel, const std::string &cacheDir);
|
||||||
~BookModel();
|
~BookModel();
|
||||||
|
|
||||||
void setHyperlinkMatcher(shared_ptr<HyperlinkMatcher> matcher);
|
void setHyperlinkMatcher(shared_ptr<HyperlinkMatcher> matcher);
|
||||||
|
@ -86,6 +86,9 @@ public:
|
||||||
|
|
||||||
bool flush();
|
bool flush();
|
||||||
|
|
||||||
|
public:
|
||||||
|
const std::string CacheDir;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const shared_ptr<Book> myBook;
|
const shared_ptr<Book> myBook;
|
||||||
jobject myJavaModel;
|
jobject myJavaModel;
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "BookModel.h"
|
#include "BookModel.h"
|
||||||
|
|
||||||
#include "../library/Book.h"
|
#include "../library/Book.h"
|
||||||
#include "../library/Library.h"
|
|
||||||
|
|
||||||
BookReader::BookReader(BookModel &model) : myModel(model) {
|
BookReader::BookReader(BookModel &model) : myModel(model) {
|
||||||
myCurrentTextModel = 0;
|
myCurrentTextModel = 0;
|
||||||
|
@ -53,7 +52,7 @@ void BookReader::setFootnoteTextModel(const std::string &id) {
|
||||||
myCurrentTextModel = (*it).second;
|
myCurrentTextModel = (*it).second;
|
||||||
} else {
|
} else {
|
||||||
if (myFootnotesAllocator.isNull()) {
|
if (myFootnotesAllocator.isNull()) {
|
||||||
myFootnotesAllocator = new ZLCachedMemoryAllocator(8192, Library::Instance().cacheDirectory(), "footnotes");
|
myFootnotesAllocator = new ZLCachedMemoryAllocator(8192, myModel.CacheDir, "footnotes");
|
||||||
}
|
}
|
||||||
myCurrentTextModel = new ZLTextPlainModel(id, myModel.myBookTextModel->language(), myFootnotesAllocator, myModel.myFontManager);
|
myCurrentTextModel = new ZLTextPlainModel(id, myModel.myBookTextModel->language(), myFootnotesAllocator, myModel.myFontManager);
|
||||||
myModel.myFootnotes.insert(std::make_pair(id, myCurrentTextModel));
|
myModel.myFootnotes.insert(std::make_pair(id, myCurrentTextModel));
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2004-2015 FBReader.ORG Limited <contact@fbreader.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <AndroidUtil.h>
|
|
||||||
#include <JniEnvelope.h>
|
|
||||||
|
|
||||||
#include "Library.h"
|
|
||||||
|
|
||||||
shared_ptr<Library> Library::ourInstance;
|
|
||||||
|
|
||||||
Library &Library::Instance() {
|
|
||||||
if (ourInstance.isNull()) {
|
|
||||||
ourInstance = new Library();
|
|
||||||
}
|
|
||||||
return *ourInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
Library::Library() {
|
|
||||||
}
|
|
||||||
|
|
||||||
Library::~Library() {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Library::cacheDirectory() const {
|
|
||||||
JNIEnv *env = AndroidUtil::getEnv();
|
|
||||||
jstring res = (jstring)AndroidUtil::StaticMethod_Paths_tempDirectory->call();
|
|
||||||
std::string str = AndroidUtil::fromJavaString(env, res);
|
|
||||||
if (res != 0) {
|
|
||||||
env->DeleteLocalRef(res);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2004-2015 FBReader.ORG Limited <contact@fbreader.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LIBRARY_H__
|
|
||||||
#define __LIBRARY_H__
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <shared_ptr.h>
|
|
||||||
|
|
||||||
class Library {
|
|
||||||
|
|
||||||
public:
|
|
||||||
static Library &Instance();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static shared_ptr<Library> ourInstance;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Library();
|
|
||||||
|
|
||||||
public:
|
|
||||||
~Library();
|
|
||||||
|
|
||||||
std::string cacheDirectory() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* __LIBRARY_H__ */
|
|
|
@ -102,8 +102,6 @@ shared_ptr<Constructor> AndroidUtil::Constructor_FileEncryptionInfo;
|
||||||
|
|
||||||
shared_ptr<Constructor> AndroidUtil::Constructor_ZLFileImage;
|
shared_ptr<Constructor> AndroidUtil::Constructor_ZLFileImage;
|
||||||
|
|
||||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Paths_tempDirectory;
|
|
||||||
|
|
||||||
shared_ptr<StringMethod> AndroidUtil::Method_Book_getPath;
|
shared_ptr<StringMethod> AndroidUtil::Method_Book_getPath;
|
||||||
shared_ptr<StringMethod> AndroidUtil::Method_Book_getTitle;
|
shared_ptr<StringMethod> AndroidUtil::Method_Book_getTitle;
|
||||||
shared_ptr<StringMethod> AndroidUtil::Method_Book_getLanguage;
|
shared_ptr<StringMethod> AndroidUtil::Method_Book_getLanguage;
|
||||||
|
@ -185,8 +183,6 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
|
|
||||||
Constructor_ZLFileImage = new Constructor(Class_ZLFileImage, "(Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;Ljava/lang/String;[I[ILorg/geometerplus/zlibrary/core/drm/FileEncryptionInfo;)V");
|
Constructor_ZLFileImage = new Constructor(Class_ZLFileImage, "(Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;Ljava/lang/String;[I[ILorg/geometerplus/zlibrary/core/drm/FileEncryptionInfo;)V");
|
||||||
|
|
||||||
StaticMethod_Paths_tempDirectory = new StaticObjectMethod(Class_Paths, "tempDirectory", Class_java_lang_String, "()");
|
|
||||||
|
|
||||||
Method_Book_getPath = new StringMethod(Class_AbstractBook, "getPath", "()");
|
Method_Book_getPath = new StringMethod(Class_AbstractBook, "getPath", "()");
|
||||||
Method_Book_getTitle = new StringMethod(Class_AbstractBook, "getTitle", "()");
|
Method_Book_getTitle = new StringMethod(Class_AbstractBook, "getTitle", "()");
|
||||||
Method_Book_getLanguage = new StringMethod(Class_AbstractBook, "getLanguage", "()");
|
Method_Book_getLanguage = new StringMethod(Class_AbstractBook, "getLanguage", "()");
|
||||||
|
|
|
@ -140,8 +140,6 @@ public:
|
||||||
//static shared_ptr<ObjectMethod> Method_JavaEncodingCollection_getEncoding_int;
|
//static shared_ptr<ObjectMethod> Method_JavaEncodingCollection_getEncoding_int;
|
||||||
static shared_ptr<BooleanMethod> Method_JavaEncodingCollection_providesConverterFor;
|
static shared_ptr<BooleanMethod> Method_JavaEncodingCollection_providesConverterFor;
|
||||||
|
|
||||||
static shared_ptr<StaticObjectMethod> StaticMethod_Paths_tempDirectory;
|
|
||||||
|
|
||||||
static shared_ptr<StringMethod> Method_Book_getPath;
|
static shared_ptr<StringMethod> Method_Book_getPath;
|
||||||
static shared_ptr<StringMethod> Method_Book_getTitle;
|
static shared_ptr<StringMethod> Method_Book_getTitle;
|
||||||
static shared_ptr<StringMethod> Method_Book_getLanguage;
|
static shared_ptr<StringMethod> Method_Book_getLanguage;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue