1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

Temp directory option

This commit is contained in:
Nikolay Pultsin 2014-04-12 14:17:02 +01:00
parent 487aeb2053
commit 3d49eb8366
8 changed files with 24 additions and 18 deletions

View file

@ -39,7 +39,7 @@ Library::~Library() {
std::string Library::cacheDirectory() const { std::string Library::cacheDirectory() const {
JNIEnv *env = AndroidUtil::getEnv(); JNIEnv *env = AndroidUtil::getEnv();
jstring res = (jstring)AndroidUtil::StaticMethod_Paths_cacheDirectory->call(); jstring res = (jstring)AndroidUtil::StaticMethod_Paths_tempDirectory->call();
std::string str = AndroidUtil::fromJavaString(env, res); std::string str = AndroidUtil::fromJavaString(env, res);
if (res != 0) { if (res != 0) {
env->DeleteLocalRef(res); env->DeleteLocalRef(res);

View file

@ -101,7 +101,7 @@ shared_ptr<Constructor> AndroidUtil::Constructor_FileEncryptionInfo;
shared_ptr<Constructor> AndroidUtil::Constructor_ZLFileImage; shared_ptr<Constructor> AndroidUtil::Constructor_ZLFileImage;
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Paths_cacheDirectory; shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_Paths_tempDirectory;
shared_ptr<ObjectField> AndroidUtil::Field_Book_File; shared_ptr<ObjectField> AndroidUtil::Field_Book_File;
shared_ptr<StringMethod> AndroidUtil::Method_Book_getTitle; shared_ptr<StringMethod> AndroidUtil::Method_Book_getTitle;
@ -185,7 +185,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
Constructor_ZLFileImage = new Constructor(Class_ZLFileImage, "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;Ljava/lang/String;[I[ILorg/geometerplus/zlibrary/core/drm/FileEncryptionInfo;)V"); Constructor_ZLFileImage = new Constructor(Class_ZLFileImage, "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;Ljava/lang/String;[I[ILorg/geometerplus/zlibrary/core/drm/FileEncryptionInfo;)V");
StaticMethod_Paths_cacheDirectory = new StaticObjectMethod(Class_Paths, "cacheDirectory", Class_java_lang_String, "()"); StaticMethod_Paths_tempDirectory = new StaticObjectMethod(Class_Paths, "tempDirectory", Class_java_lang_String, "()");
Field_Book_File = new ObjectField(Class_Book, "File", Class_ZLFile); Field_Book_File = new ObjectField(Class_Book, "File", Class_ZLFile);
Method_Book_getTitle = new StringMethod(Class_Book, "getTitle", "()"); Method_Book_getTitle = new StringMethod(Class_Book, "getTitle", "()");

View file

@ -139,7 +139,7 @@ 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_cacheDirectory; static shared_ptr<StaticObjectMethod> StaticMethod_Paths_tempDirectory;
static shared_ptr<ObjectField> Field_Book_File; static shared_ptr<ObjectField> Field_Book_File;
static shared_ptr<StringMethod> Method_Book_getTitle; static shared_ptr<StringMethod> Method_Book_getTitle;

View file

@ -102,6 +102,7 @@ public class PreferenceActivity extends ZLPreferenceActivity {
directoriesScreen.addPreference(new ZLStringListOptionPreference( directoriesScreen.addPreference(new ZLStringListOptionPreference(
this, Paths.WallpaperPathOption, directoriesScreen.Resource, "wallpaperPath" this, Paths.WallpaperPathOption, directoriesScreen.Resource, "wallpaperPath"
)); ));
directoriesScreen.addOption(Paths.TempDirectoryOption(), "tempDir");
final Screen appearanceScreen = createPreferenceScreen("appearance"); final Screen appearanceScreen = createPreferenceScreen("appearance");
appearanceScreen.addPreference(new LanguagePreference( appearanceScreen.addPreference(new LanguagePreference(

View file

@ -29,13 +29,21 @@ import org.geometerplus.zlibrary.core.options.ZLStringListOption;
public abstract class Paths { public abstract class Paths {
public static ZLStringListOption BookPathOption = public static ZLStringListOption BookPathOption =
directoryOption("BooksDirectory", defaultBookDirectory()); pathOption("BooksDirectory", defaultBookDirectory());
public static ZLStringListOption FontPathOption = public static ZLStringListOption FontPathOption =
directoryOption("FontPathOption", cardDirectory() + "/Fonts"); pathOption("FontPathOption", cardDirectory() + "/Fonts");
public static ZLStringListOption WallpaperPathOption = public static ZLStringListOption WallpaperPathOption =
directoryOption("WallpapersDirectory", cardDirectory() + "/Wallpapers"); pathOption("WallpapersDirectory", cardDirectory() + "/Wallpapers");
public static ZLStringOption TempDirectoryOption() {
final ZLStringOption option = new ZLStringOption("Files", "tmp", "");
if (option.getValue().isEmpty()) {
option.setValue(mainBookDirectory() + "/.FBReader");
}
return option;
}
public static String cardDirectory() { public static String cardDirectory() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
@ -84,7 +92,7 @@ public abstract class Paths {
return cardDirectory() + "/Books"; return cardDirectory() + "/Books";
} }
private static ZLStringListOption directoryOption(String key, String defaultDirectory) { private static ZLStringListOption pathOption(String key, String defaultDirectory) {
final ZLStringListOption option = new ZLStringListOption( final ZLStringListOption option = new ZLStringListOption(
"Files", key, Collections.<String>emptyList(), "\n" "Files", key, Collections.<String>emptyList(), "\n"
); );
@ -99,16 +107,12 @@ public abstract class Paths {
return bookPath.isEmpty() ? defaultBookDirectory() : bookPath.get(0); return bookPath.isEmpty() ? defaultBookDirectory() : bookPath.get(0);
} }
public static String cacheDirectory() {
return mainBookDirectory() + "/.FBReader";
}
public static String tempDirectory() { public static String tempDirectory() {
return mainBookDirectory() + "/.FBReader"; return TempDirectoryOption().getValue();
} }
public static String networkCacheDirectory() { public static String networkCacheDirectory() {
return cacheDirectory() + "/cache"; return tempDirectory() + "/cache";
} }
public static String systemShareDirectory() { public static String systemShareDirectory() {

View file

@ -29,8 +29,8 @@ public class JavaBookModel extends BookModelImpl {
JavaBookModel(Book book) { JavaBookModel(Book book) {
super(book); super(book);
myInternalHyperlinks = new CachedCharStorage(32768, Paths.cacheDirectory(), "links"); myInternalHyperlinks = new CachedCharStorage(32768, Paths.tempDirectory(), "links");
BookTextModel = new ZLTextWritablePlainModel(null, book.getLanguage(), 1024, 65536, Paths.cacheDirectory(), "cache", myImageMap, FontManager); BookTextModel = new ZLTextWritablePlainModel(null, book.getLanguage(), 1024, 65536, Paths.tempDirectory(), "cache", myImageMap, FontManager);
} }
@Override @Override
@ -42,7 +42,7 @@ public class JavaBookModel extends BookModelImpl {
public ZLTextModel getFootnoteModel(String id) { public ZLTextModel getFootnoteModel(String id) {
ZLTextModel model = myFootnotes.get(id); ZLTextModel model = myFootnotes.get(id);
if (model == null) { if (model == null) {
model = new ZLTextWritablePlainModel(id, Book.getLanguage(), 8, 512, Paths.cacheDirectory(), "cache" + myFootnotes.size(), myImageMap, FontManager); model = new ZLTextWritablePlainModel(id, Book.getLanguage(), 8, 512, Paths.tempDirectory(), "cache" + myFootnotes.size(), myImageMap, FontManager);
myFootnotes.put(id, model); myFootnotes.put(id, model);
} }
return model; return model;

View file

@ -41,7 +41,7 @@ final class Base64EncodedImage extends ZLBase64EncodedImage {
public Base64EncodedImage(MimeType mimeType, String namePostfix) { public Base64EncodedImage(MimeType mimeType, String namePostfix) {
// TODO: use contentType // TODO: use contentType
super(mimeType); super(mimeType);
myDirName = Paths.cacheDirectory(); myDirName = Paths.tempDirectory();
new File(myDirName).mkdirs(); new File(myDirName).mkdirs();
myFileNumber = ourCounter++; myFileNumber = ourCounter++;
myNamePostfix = namePostfix; myNamePostfix = namePostfix;

View file

@ -286,6 +286,7 @@ public final class AndroidFontUtil {
// ignore // ignore
} }
} }
new File(realFileName).delete();
} }
ourCachedEmbeddedTypefaces.put(spec, cached != null ? cached : NULL_OBJECT); ourCachedEmbeddedTypefaces.put(spec, cached != null ? cached : NULL_OBJECT);
} }