Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions src/pc/mods/mod_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ static mINI::INIStructure &mod_storage_read_file(const char *filename) {

mINI::INIFile file(filename);
mINI::INIStructure ini;
if (fs_sys_path_exists(filename)) {
file.read(ini);
}
sModStorageFiles[filename] = ini;
return sModStorageFiles[filename];
}
Expand All @@ -168,28 +170,18 @@ C_FIELD const char* mod_storage_load(const char* key) {
if (!mod_storage_check_inputs(key, NULL, filename)) {
return NULL;
}
const mINI::INIStructure &ini = mod_storage_read_file(filename);
std::string str = ini.get("storage").get(key);
if (str.empty()) { return NULL; }

// save cache before read
#ifdef __ANDROID__
char *cached_value = NULL;
cached_value = key_cached(key, NULL);
if (cached_value) {
return cached_value;
}
cache_key(key, str.c_str());
#endif

const mINI::INIStructure &ini = mod_storage_read_file(filename);
std::string str = ini.get("storage").get(key);
if (str.empty()) { return NULL; }

// Store string results in a temporary buffer
// this assumes mod_storage_load will only ever be called by Lua
static char value[MAX_KEY_VALUE_LENGTH];
snprintf(value, MAX_KEY_VALUE_LENGTH, "%s", str.c_str());

#ifdef __ANDROID__
cache_key(key, (char*)value);
#endif
return value;
static char value[MAX_KEY_VALUE_LENGTH];
snprintf(value, MAX_KEY_VALUE_LENGTH, "%s", str.c_str());
return value;
}

C_FIELD f32 mod_storage_load_number(const char* key) {
Expand Down Expand Up @@ -316,3 +308,9 @@ C_FIELD void mod_storage_shutdown(void) {
}
sModStorageFiles.clear();
}

C_FIELD void mod_storage_init(void) {
#ifdef __ANDROID__
key_cache_init();
#endif
}