diff options
author | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2015-10-11 01:52:39 +0200 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2015-10-11 02:03:43 +0200 |
commit | 143fb0a4b5d4ab69d4928299d8112ab95d99870a (patch) | |
tree | 094673c521e14d4ba52fd706acba07be96bead49 /sal/android/lo-bootstrap.c | |
parent | ee8257a1c70eadb7330b0ee99ec3b86fe4084bdf (diff) |
move extracting assets to Java & use AssetManager to access assets
using AssetsManager in both java as well as native parts allows to
handle files both with and without compression transparently
Change-Id: If02f1159c498be7ea965fd9c217410722f2dca1f
Diffstat (limited to 'sal/android/lo-bootstrap.c')
-rw-r--r-- | sal/android/lo-bootstrap.c | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/sal/android/lo-bootstrap.c b/sal/android/lo-bootstrap.c index 5c47b8f6bd2f..7a2da48eb93b 100644 --- a/sal/android/lo-bootstrap.c +++ b/sal/android/lo-bootstrap.c @@ -311,10 +311,6 @@ Java_org_libreoffice_android_Bootstrap_setup__Ljava_lang_String_2Ljava_lang_Stri if (!setup_assets_tree()) return JNI_FALSE; - // Extract files from the .apk that can't be used mmapped directly from it - extract_files(UNPACK_TREE, UNPACK_TREE, 0); - extract_files(UNPACK_TREE_GZ, UNPACK_TREE_GZ, 1); - return JNI_TRUE; } @@ -635,184 +631,6 @@ lo_apk_lstat(const char *path, return -1; } -static int -mkdir_p(const char *dirname) -{ - char *p = malloc(strlen(dirname) + 1); - const char *q = dirname + 1; - const char *slash; - - do { - slash = strchr(q, '/'); - if (slash == NULL) - slash = q + strlen(q); - memcpy(p, dirname, slash-dirname); - p[slash-dirname] = '\0'; - if (mkdir(p, 0700) == -1 && errno != EEXIST) { - LOGE("mkdir_p: Could not create %s: %s", p, strerror(errno)); - free(p); - return 0; - } - if (*slash) - q = slash + 1; - } while (*slash); - - free(p); - return 1; -} - -static int -extract_gzipped(const char *filename, - const char *apkentry, - int size, - FILE *f) -{ - gzFile gzfd; - int gzerrno; - int nbytes; - char buf[5000]; - int total = 0; - char *tmpname; - FILE *tmp; - - tmpname = malloc(strlen(cache_dir) + strlen("/tmp.gz") + 1); - strcpy(tmpname, cache_dir); - strcat(tmpname, "/tmp.gz"); - - tmp = fopen(tmpname, "w+"); - unlink(tmpname); - - if (tmp == NULL) { - LOGE("extract_gzipped: could not create %s: %s", tmpname, strerror(errno)); - free(tmpname); - return 0; - } - - if (fwrite(apkentry, size, 1, tmp) != 1) { - LOGE("extract_gzipped: could not write gzipped entry to %s: %s", tmpname, strerror(errno)); - fclose(tmp); - free(tmpname); - return 0; - } - - free(tmpname); - rewind(tmp); - - gzfd = gzdopen(fileno(tmp), "rb"); - if (gzfd == NULL) { - LOGE("extract_gzipped: gzdopen failed"); - fclose(tmp); - return 0; - } - - while ((nbytes = gzread(gzfd, buf, sizeof(buf))) > 0) { - fwrite(buf, nbytes, 1, f); - total += nbytes; - } - if (nbytes == -1) { - LOGE("extract_gzipped: Could not gzread from %s: %s", filename, gzerror(gzfd, &gzerrno)); - return total; - } - if (gzclose(gzfd) == -1) { - LOGE("extract_gzipped: gzclose failed"); - return total; - } - - return total; -} - -void -extract_files(const char *root, - const char *prefix, - int gzipped) -{ - lo_apk_dir *tree = lo_apk_opendir(prefix); - struct dirent *dent; - - if (tree == NULL) - return; - - while ((dent = lo_apk_readdir(tree)) != NULL) { - if (strcmp(dent->d_name, ".") == 0 || - strcmp(dent->d_name, "..") == 0) - continue; - - if (dent->d_type == DT_DIR) { - char *subdir = malloc(strlen(prefix) + 1 + strlen(dent->d_name) + 1); - strcpy(subdir, prefix); - strcat(subdir, "/"); - strcat(subdir, dent->d_name); - extract_files(root, subdir, gzipped); - free(subdir); - } else { - char *filename; - char *newfilename; - const char *apkentry; - size_t size; - struct stat st; - FILE *f; - - filename = malloc(strlen(prefix) + 1 + strlen(dent->d_name) + 1); - strcpy(filename, prefix); - strcat(filename, "/"); - strcat(filename, dent->d_name); - - apkentry = lo_apkentry(filename, &size); - if (apkentry == NULL) { - LOGE("extract_files: Could not find %s in .apk", filename); - free(filename); - continue; - } - - newfilename = malloc(strlen(data_dir) + 1 + strlen(prefix) - strlen(root) + strlen(dent->d_name) + 1); - strcpy(newfilename, data_dir); - strcat(newfilename, "/"); - strcat(newfilename, prefix + strlen(root) + 1); - - if (!mkdir_p(newfilename)) { - free(filename); - free(newfilename); - continue; - } - - strcat(newfilename, "/"); - strcat(newfilename, dent->d_name); - - if (stat(newfilename, &st) == 0 && - (gzipped || st.st_size == (long long) size)) { - free(filename); - free(newfilename); - continue; - } - - f = fopen(newfilename, "w"); - if (f == NULL) { - LOGE("extract_files: Could not open %s for writing: %s", newfilename, strerror(errno)); - free(filename); - free(newfilename); - continue; - } - - if (!gzipped) { - if (fwrite(apkentry, size, 1, f) != 1) { - LOGE("extract_files: Could not write %lld bytes to %s: %s", (long long) size, newfilename, strerror(errno)); - } else { - LOGI("extract_files: Copied %s to %s: %lld bytes", filename, newfilename, (long long) size); - } - } else { - size = extract_gzipped(filename, apkentry, size, f); - LOGI("extract_files: Decompressed %s to %s: %lld bytes", filename, newfilename, (long long) size); - } - - fclose(f); - - free(filename); - free(newfilename); - } - } - lo_apk_closedir(tree); -} - /* Android's JNI works only to libraries loaded through Java's * System.loadLibrary(), it seems. But now with just one big app-specific .so * on Android, that would not be a problem, but for historical reasons, we |