From 1b21f21c35c24b26c501d27741b13afe31db1996 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Fri, 13 May 2016 15:24:48 -0700 Subject: [PATCH 1/2] Symlink ReactTestApp assets for Android --- tests/react-test-app/android/app/src/main/assets | 1 + 1 file changed, 1 insertion(+) create mode 120000 tests/react-test-app/android/app/src/main/assets diff --git a/tests/react-test-app/android/app/src/main/assets b/tests/react-test-app/android/app/src/main/assets new file mode 120000 index 00000000..89ea34e1 --- /dev/null +++ b/tests/react-test-app/android/app/src/main/assets @@ -0,0 +1 @@ +../../../../../data \ No newline at end of file From 0250234a30989f7ee0ff99470b42f1e1f57d3bc0 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Fri, 13 May 2016 15:25:18 -0700 Subject: [PATCH 2/2] Cleanup Android platform.cpp --- src/android/platform.cpp | 31 ++++++++++++++++--------------- src/platform.hpp | 2 -- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/android/platform.cpp b/src/android/platform.cpp index 0a364e13..e008169f 100644 --- a/src/android/platform.cpp +++ b/src/android/platform.cpp @@ -20,14 +20,14 @@ #include #include #include -#include #include + #include "../platform.hpp" #define REALM_FILE_FILTER ".realm" -#define REALM_FILE_FILTER_LEN strlen(REALM_FILE_FILTER) -AAssetManager* androidAssetManager; -inline bool isRealmFile(const char *str) +#define REALM_FILE_FILTER_LEN 6 + +static inline bool is_realm_file(const char* str) { size_t lenstr = strlen(str); if (REALM_FILE_FILTER_LEN > lenstr) @@ -35,7 +35,8 @@ inline bool isRealmFile(const char *str) return strncmp(str + lenstr - REALM_FILE_FILTER_LEN, REALM_FILE_FILTER, REALM_FILE_FILTER_LEN) == 0; } -std::string s_default_realm_directory; +static AAssetManager* s_asset_manager; +static std::string s_default_realm_directory; namespace realm { @@ -44,9 +45,9 @@ namespace realm { s_default_realm_directory = dir; } - void set_asset_manager(AAssetManager* assetManager) + void set_asset_manager(AAssetManager* asset_manager) { - androidAssetManager = assetManager; + s_asset_manager = asset_manager; } std::string default_realm_file_directory() @@ -61,20 +62,20 @@ namespace realm { void copy_bundled_realm_files() { - AAssetDir* assetDir = AAssetManager_openDir(androidAssetManager, ""); + AAssetDir* assetDir = AAssetManager_openDir(s_asset_manager, ""); + const char* filename = nullptr; - 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)) != nullptr) { + if (is_realm_file(filename)) { + AAsset* asset = AAssetManager_open(s_asset_manager, filename, AASSET_MODE_STREAMING); char buf[BUFSIZ]; int nb_read = 0; - const char* destFilename = (s_default_realm_directory + '/' + filename).c_str(); - if (access(destFilename, F_OK ) == -1) { + const char* dest_filename = (s_default_realm_directory + '/' + filename).c_str(); + if (access(dest_filename, F_OK ) == -1) { // file doesn't exist, copy - FILE* out = fopen(destFilename, "w"); + FILE* out = fopen(dest_filename, "w"); while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0) { fwrite(buf, nb_read, 1, out); } diff --git a/src/platform.hpp b/src/platform.hpp index 7f497a79..56afc299 100644 --- a/src/platform.hpp +++ b/src/platform.hpp @@ -20,8 +20,6 @@ #include -extern std::string s_default_realm_directory; - namespace realm { // // These methods are used internally and must be implemented