pr feedback

This commit is contained in:
Ari Lazier 2016-05-12 11:42:22 -07:00
parent 194f238c1c
commit 299c82b7d2
3 changed files with 19 additions and 22 deletions

View File

@ -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)
{

View File

@ -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);
}

View File

@ -19,7 +19,6 @@
#pragma once
#include <string>
#include <android/asset_manager.h>
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();