mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 06:46:03 +00:00
Cleanup Android platform.cpp
This commit is contained in:
parent
1b21f21c35
commit
0250234a30
@ -20,14 +20,14 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <android/log.h>
|
|
||||||
#include <android/asset_manager.h>
|
#include <android/asset_manager.h>
|
||||||
|
|
||||||
#include "../platform.hpp"
|
#include "../platform.hpp"
|
||||||
|
|
||||||
#define REALM_FILE_FILTER ".realm"
|
#define REALM_FILE_FILTER ".realm"
|
||||||
#define REALM_FILE_FILTER_LEN strlen(REALM_FILE_FILTER)
|
#define REALM_FILE_FILTER_LEN 6
|
||||||
AAssetManager* androidAssetManager;
|
|
||||||
inline bool isRealmFile(const char *str)
|
static inline bool is_realm_file(const char* str)
|
||||||
{
|
{
|
||||||
size_t lenstr = strlen(str);
|
size_t lenstr = strlen(str);
|
||||||
if (REALM_FILE_FILTER_LEN > lenstr)
|
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;
|
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 {
|
namespace realm {
|
||||||
|
|
||||||
@ -44,9 +45,9 @@ namespace realm {
|
|||||||
s_default_realm_directory = dir;
|
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()
|
std::string default_realm_file_directory()
|
||||||
@ -61,20 +62,20 @@ namespace realm {
|
|||||||
|
|
||||||
void copy_bundled_realm_files()
|
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)) != nullptr) {
|
||||||
while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
|
if (is_realm_file(filename)) {
|
||||||
if (isRealmFile(filename)) {
|
AAsset* asset = AAssetManager_open(s_asset_manager, filename, AASSET_MODE_STREAMING);
|
||||||
AAsset* asset = AAssetManager_open(androidAssetManager, filename, AASSET_MODE_STREAMING);
|
|
||||||
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
int nb_read = 0;
|
int nb_read = 0;
|
||||||
|
|
||||||
const char* destFilename = (s_default_realm_directory + '/' + filename).c_str();
|
const char* dest_filename = (s_default_realm_directory + '/' + filename).c_str();
|
||||||
if (access(destFilename, F_OK ) == -1) {
|
if (access(dest_filename, F_OK ) == -1) {
|
||||||
// file doesn't exist, copy
|
// 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) {
|
while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0) {
|
||||||
fwrite(buf, nb_read, 1, out);
|
fwrite(buf, nb_read, 1, out);
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
extern std::string s_default_realm_directory;
|
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
//
|
//
|
||||||
// These methods are used internally and must be implemented
|
// These methods are used internally and must be implemented
|
||||||
|
Loading…
x
Reference in New Issue
Block a user