Skip to content

Commit

Permalink
Temp directory option
Browse files Browse the repository at this point in the history
  • Loading branch information
geometer committed Apr 12, 2014
1 parent 487aeb2 commit 3d49eb8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion jni/NativeFormats/fbreader/src/library/Library.cpp
Expand Up @@ -39,7 +39,7 @@ Library::~Library() {

std::string Library::cacheDirectory() const {
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);
if (res != 0) {
env->DeleteLocalRef(res);
Expand Down
4 changes: 2 additions & 2 deletions jni/NativeFormats/util/AndroidUtil.cpp
Expand Up @@ -101,7 +101,7 @@ shared_ptr<Constructor> AndroidUtil::Constructor_FileEncryptionInfo;

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<StringMethod> AndroidUtil::Method_Book_getTitle;
Expand Down Expand Up @@ -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");

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);
Method_Book_getTitle = new StringMethod(Class_Book, "getTitle", "()");
Expand Down
2 changes: 1 addition & 1 deletion jni/NativeFormats/util/AndroidUtil.h
Expand Up @@ -139,7 +139,7 @@ class AndroidUtil {
//static shared_ptr<ObjectMethod> Method_JavaEncodingCollection_getEncoding_int;
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<StringMethod> Method_Book_getTitle;
Expand Down
Expand Up @@ -102,6 +102,7 @@ public void run() {
directoriesScreen.addPreference(new ZLStringListOptionPreference(
this, Paths.WallpaperPathOption, directoriesScreen.Resource, "wallpaperPath"
));
directoriesScreen.addOption(Paths.TempDirectoryOption(), "tempDir");

final Screen appearanceScreen = createPreferenceScreen("appearance");
appearanceScreen.addPreference(new LanguagePreference(
Expand Down
24 changes: 14 additions & 10 deletions src/org/geometerplus/fbreader/Paths.java
Expand Up @@ -29,13 +29,21 @@

public abstract class Paths {
public static ZLStringListOption BookPathOption =
directoryOption("BooksDirectory", defaultBookDirectory());
pathOption("BooksDirectory", defaultBookDirectory());

public static ZLStringListOption FontPathOption =
directoryOption("FontPathOption", cardDirectory() + "/Fonts");
pathOption("FontPathOption", cardDirectory() + "/Fonts");

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() {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
Expand Down Expand Up @@ -84,7 +92,7 @@ private static String defaultBookDirectory() {
return cardDirectory() + "/Books";
}

private static ZLStringListOption directoryOption(String key, String defaultDirectory) {
private static ZLStringListOption pathOption(String key, String defaultDirectory) {
final ZLStringListOption option = new ZLStringListOption(
"Files", key, Collections.<String>emptyList(), "\n"
);
Expand All @@ -99,16 +107,12 @@ public static String mainBookDirectory() {
return bookPath.isEmpty() ? defaultBookDirectory() : bookPath.get(0);
}

public static String cacheDirectory() {
return mainBookDirectory() + "/.FBReader";
}

public static String tempDirectory() {
return mainBookDirectory() + "/.FBReader";
return TempDirectoryOption().getValue();
}

public static String networkCacheDirectory() {
return cacheDirectory() + "/cache";
return tempDirectory() + "/cache";
}

public static String systemShareDirectory() {
Expand Down
6 changes: 3 additions & 3 deletions src/org/geometerplus/fbreader/bookmodel/JavaBookModel.java
Expand Up @@ -29,8 +29,8 @@ public class JavaBookModel extends BookModelImpl {

JavaBookModel(Book book) {
super(book);
myInternalHyperlinks = new CachedCharStorage(32768, Paths.cacheDirectory(), "links");
BookTextModel = new ZLTextWritablePlainModel(null, book.getLanguage(), 1024, 65536, Paths.cacheDirectory(), "cache", myImageMap, FontManager);
myInternalHyperlinks = new CachedCharStorage(32768, Paths.tempDirectory(), "links");
BookTextModel = new ZLTextWritablePlainModel(null, book.getLanguage(), 1024, 65536, Paths.tempDirectory(), "cache", myImageMap, FontManager);
}

@Override
Expand All @@ -42,7 +42,7 @@ public ZLTextModel getTextModel() {
public ZLTextModel getFootnoteModel(String id) {
ZLTextModel model = myFootnotes.get(id);
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);
}
return model;
Expand Down
Expand Up @@ -41,7 +41,7 @@ static void resetCounter() {
public Base64EncodedImage(MimeType mimeType, String namePostfix) {
// TODO: use contentType
super(mimeType);
myDirName = Paths.cacheDirectory();
myDirName = Paths.tempDirectory();
new File(myDirName).mkdirs();
myFileNumber = ourCounter++;
myNamePostfix = namePostfix;
Expand Down
Expand Up @@ -286,6 +286,7 @@ private static Typeface getOrCreateEmbeddedTypeface(FontEntry entry, boolean bol
// ignore
}
}
new File(realFileName).delete();
}
ourCachedEmbeddedTypefaces.put(spec, cached != null ? cached : NULL_OBJECT);
}
Expand Down

0 comments on commit 3d49eb8

Please sign in to comment.