Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/cpp/CoreWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AndroidLogger>();

jclass resultClass = env->FindClass("at/tomtasche/reader/background/CoreWrapper$CoreResult");
Expand All @@ -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");
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<AndroidLogger>();

jclass resultClass = env->FindClass("at/tomtasche/reader/background/CoreWrapper$CoreResult");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static class CoreOptions {

public String inputPath;
public String outputPath;
public String cachePath;
}

public static CoreResult parse(CoreOptions options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Loading