diff --git a/src/android/io_realm_react_RealmReactModule.cpp b/src/android/io_realm_react_RealmReactModule.cpp index b6bb714c..8fcd4b21 100644 --- a/src/android/io_realm_react_RealmReactModule.cpp +++ b/src/android/io_realm_react_RealmReactModule.cpp @@ -29,6 +29,11 @@ using namespace realm::rpc; static RPCServer *s_rpc_server; extern bool realmContextInjected; +namespace realm { + // set the AssetManager used to access bundled files within the APK + void set_asset_manager(AAssetManager* assetManager); +} + JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileDirectory (JNIEnv *env, jclass, jstring fileDir, jobject javaAssetManager) { diff --git a/src/android/platform.cpp b/src/android/platform.cpp index 98f8c941..0a364e13 100644 --- a/src/android/platform.cpp +++ b/src/android/platform.cpp @@ -64,28 +64,24 @@ namespace realm { AAssetDir* assetDir = AAssetManager_openDir(androidAssetManager, ""); const char* filename = (const char*)NULL; - while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) - { - if (isRealmFile(filename)) - { - AAsset* asset = AAssetManager_open(androidAssetManager, filename, AASSET_MODE_STREAMING); + while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) { + if (isRealmFile(filename)) { + AAsset* asset = AAssetManager_open(androidAssetManager, filename, AASSET_MODE_STREAMING); - char buf[BUFSIZ]; - int nb_read = 0; + char buf[BUFSIZ]; + int nb_read = 0; - const char* destFilename = (s_default_realm_directory + '/' + filename).c_str(); - if(access(destFilename, F_OK ) == -1 ) { - // file doesn't exist, copy - FILE* out = fopen(destFilename, "w"); - while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0) - { - fwrite(buf, nb_read, 1, out); + const char* destFilename = (s_default_realm_directory + '/' + filename).c_str(); + if (access(destFilename, F_OK ) == -1) { + // file doesn't exist, copy + FILE* out = fopen(destFilename, "w"); + while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0) { + fwrite(buf, nb_read, 1, out); + } + fclose(out); } - fclose(out); + AAsset_close(asset); } - - AAsset_close(asset); - } } AAssetDir_close(assetDir); } diff --git a/src/platform.hpp b/src/platform.hpp index 568be954..7f497a79 100644 --- a/src/platform.hpp +++ b/src/platform.hpp @@ -19,7 +19,6 @@ #pragma once #include -#include extern std::string s_default_realm_directory; @@ -32,9 +31,6 @@ namespace realm { // set the directory where realm files should be stored void set_default_realm_file_directory(std::string dir); -// set the AssetManager used to access bundled files within the APK -void set_asset_manager(AAssetManager* assetManager); - // return the directory in which realm files can/should be written to std::string default_realm_file_directory();