diff --git a/app/src/androidTest/java/at/tomtasche/reader/test/CoreTest.java b/app/src/androidTest/java/at/tomtasche/reader/test/CoreTest.java index 06f450b65132..525dfaf82ad0 100644 --- a/app/src/androidTest/java/at/tomtasche/reader/test/CoreTest.java +++ b/app/src/androidTest/java/at/tomtasche/reader/test/CoreTest.java @@ -64,11 +64,13 @@ private static void copy(InputStream src, File dst) throws IOException { @Test public void test() { File cacheDir = InstrumentationRegistry.getInstrumentation().getTargetContext().getCacheDir(); - File outputDir = new File(cacheDir, "output"); + File outputPath = new File(cacheDir, "core_output"); + File cachePath = new File(cacheDir, "core_cache"); CoreWrapper.CoreOptions coreOptions = new CoreWrapper.CoreOptions(); coreOptions.inputPath = m_testFile.getAbsolutePath(); - coreOptions.outputPath = outputDir.getPath(); + coreOptions.outputPath = outputPath.getPath(); + coreOptions.cachePath = cachePath.getPath(); coreOptions.editable = true; CoreWrapper.CoreResult coreResult = CoreWrapper.parse(coreOptions); diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index af18b6ac56d9..b2aa86f677b9 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -98,6 +98,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_setGlobalParams(JNIEnv *env, jcl JNIEXPORT jobject JNICALL Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jclass clazz, jobject options) { + std::error_code ec; auto logger = std::make_shared(); jclass resultClass = env->FindClass("at/tomtasche/reader/background/CoreWrapper$CoreResult"); @@ -121,6 +122,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jclass jboolean editable = env->GetBooleanField(options, editableField); std::string outputPathCpp = getStringField(env, optionsClass, options, "outputPath"); + std::string cachePathCpp = getStringField(env, optionsClass, options, "cachePath"); jclass listClass = env->FindClass("java/util/List"); jmethodID addMethod = env->GetMethodID(listClass, "add", "(Ljava/lang/Object;)Z"); @@ -195,11 +197,11 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jclass __android_log_print(ANDROID_LOG_VERBOSE, "smn", "Translate to HTML"); - std::string output_tmp = outputPathCpp + "/tmp"; - std::filesystem::create_directories(output_tmp); - odr::HtmlService service = odr::html::translate(file, output_tmp, htmlConfig, logger); + std::filesystem::remove_all(cachePathCpp, ec); + std::filesystem::create_directories(cachePathCpp); + odr::HtmlService service = odr::html::translate(file, cachePathCpp, htmlConfig, logger); odr::Html html = service.bring_offline(outputPathCpp); - std::filesystem::remove_all(output_tmp); + std::filesystem::remove_all(cachePathCpp); for (const odr::HtmlPage &page: html.pages()) { jstring pageName = env->NewStringUTF(page.name.c_str()); @@ -318,6 +320,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_hostFileNative(JNIEnv *env, jcla jobject options) { __android_log_print(ANDROID_LOG_INFO, "smn", "host file"); + std::error_code ec; auto logger = std::make_shared(); jclass resultClass = env->FindClass("at/tomtasche/reader/background/CoreWrapper$CoreResult"); @@ -350,6 +353,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_hostFileNative(JNIEnv *env, jcla jboolean editable = env->GetBooleanField(options, editableField); std::string outputPathCpp = getStringField(env, optionsClass, options, "outputPath"); + std::string cachePathCpp = getStringField(env, optionsClass, options, "cachePath"); jclass listClass = env->FindClass("java/util/List"); jmethodID addMethod = env->GetMethodID(listClass, "add", "(Ljava/lang/Object;)Z"); @@ -395,9 +399,9 @@ Java_at_tomtasche_reader_background_CoreWrapper_hostFileNative(JNIEnv *env, jcla htmlConfig.text_document_margin = paging; htmlConfig.editable = editable; - std::string output_tmp = outputPathCpp + "/tmp"; - std::filesystem::create_directories(output_tmp); - odr::HtmlService service = odr::html::translate(file, output_tmp, htmlConfig, logger); + std::filesystem::remove_all(cachePathCpp, ec); + std::filesystem::create_directories(cachePathCpp); + odr::HtmlService service = odr::html::translate(file, cachePathCpp, htmlConfig, logger); s_server->connect_service(service, prefixCpp); odr::HtmlViews htmlViews = service.list_views(); diff --git a/app/src/main/java/at/tomtasche/reader/background/CoreLoader.java b/app/src/main/java/at/tomtasche/reader/background/CoreLoader.java index a21c0d24e4be..997609a17d34 100644 --- a/app/src/main/java/at/tomtasche/reader/background/CoreLoader.java +++ b/app/src/main/java/at/tomtasche/reader/background/CoreLoader.java @@ -7,6 +7,7 @@ import android.webkit.MimeTypeMap; import java.io.File; +import java.util.Objects; import at.tomtasche.reader.nonfree.AnalyticsManager; import at.tomtasche.reader.nonfree.ConfigManager; @@ -92,9 +93,13 @@ private void translate(Options options, Result result) throws Exception { File cacheDirectory = AndroidFileCache.getCacheDirectory(cachedFile); + File coreOutputDirectory = new File(cacheDirectory, "core_output"); + File coreCacheDirectory = new File(cacheDirectory, "core_cache"); + CoreWrapper.CoreOptions coreOptions = new CoreWrapper.CoreOptions(); coreOptions.inputPath = cachedFile.getPath(); - coreOptions.outputPath = cacheDirectory.getPath(); + coreOptions.outputPath = coreOutputDirectory.getPath(); + coreOptions.cachePath = coreCacheDirectory.getPath(); coreOptions.password = options.password; coreOptions.editable = options.translatable; coreOptions.ooxml = doOoxml; diff --git a/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java b/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java index c9e583e12f24..4c337f9c3b11 100644 --- a/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java +++ b/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java @@ -57,6 +57,7 @@ public static class CoreOptions { public String inputPath; public String outputPath; + public String cachePath; } public static CoreResult parse(CoreOptions options) { diff --git a/app/src/main/java/at/tomtasche/reader/background/RawLoader.java b/app/src/main/java/at/tomtasche/reader/background/RawLoader.java index 73b34330ade1..d274d5b53cdf 100644 --- a/app/src/main/java/at/tomtasche/reader/background/RawLoader.java +++ b/app/src/main/java/at/tomtasche/reader/background/RawLoader.java @@ -21,7 +21,6 @@ public class RawLoader extends FileLoader { private static final String[] MIME_BLACKLIST = {"image/vnd.dwg", "image/g3fax", "image/tiff", "image/vnd.djvu", "image/x-eps", "image/x-tga", "image/x-tga", "audio/amr", "video/3gpp", "video/quicktime", "text/calendar", "text/vcard", "text/rtf"}; private CoreWrapper lastCore; - private CoreWrapper.CoreOptions lastCoreOptions; public RawLoader(Context context) { super(context, LoaderType.RAW); @@ -142,8 +141,6 @@ public void loadSync(Options options) { coreOptions.txt = true; coreOptions.pdf = false; - lastCoreOptions = coreOptions; - CoreWrapper.CoreResult coreResult = lastCore.parse(coreOptions); if (coreResult.exception != null) { throw coreResult.exception;