diff options
| author | Ray <raysan5@gmail.com> | 2016-05-31 00:01:19 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2016-05-31 00:01:19 +0200 |
| commit | 8a4e28f81db16c034274e5d78dddfe33824e59fe (patch) | |
| tree | ea7c5cfeb76ad4d00d22dafed10ea2a8575a156c /src | |
| parent | 4b93349db575bedb48b8c13e95d37df1ec694387 (diff) | |
| download | raylib-8a4e28f81db16c034274e5d78dddfe33824e59fe.tar.gz raylib-8a4e28f81db16c034274e5d78dddfe33824e59fe.zip | |
Support Android internal data storage
Useful to save small data files (configuration and so)
For bigger files, external data storage should be used (SDCard)
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 26 | ||||
| -rw-r--r-- | src/utils.c | 2 |
2 files changed, 24 insertions, 4 deletions
@@ -147,6 +147,7 @@ static bool windowMinimized = false; static struct android_app *app; // Android activity static struct android_poll_source *source; // Android events polling source static int ident, events; // Android ALooper_pollAll() variables +static const char *internalDataPath; // Android internal data path to write data (/data/data/<package>/files) static bool windowReady = false; // Used to detect display initialization static bool appEnabled = true; // Used to detec if app is active @@ -363,6 +364,7 @@ void InitWindow(int width, int height, struct android_app *state) screenHeight = height; app = state; + internalDataPath = app->activity->internalDataPath; // Set desired windows flags before initializing anything ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FULLSCREEN, 0); //AWINDOW_FLAG_SCALED, AWINDOW_FLAG_DITHER @@ -838,12 +840,21 @@ void ClearDroppedFiles(void) void StorageSaveValue(int position, int value) { FILE *storageFile = NULL; + + char path[128]; +#if defined(PLATFORM_ANDROID) + strcpy(path, internalDataPath); + strcat(path, "/"); + strcat(path, STORAGE_FILENAME); +#else + strcpy(path, STORAGE_FILENAME); +#endif // Try open existing file to append data - storageFile = fopen(STORAGE_FILENAME, "rb+"); + storageFile = fopen(path, "rb+"); // If file doesn't exist, create a new storage data file - if (!storageFile) storageFile = fopen(STORAGE_FILENAME, "wb"); + if (!storageFile) storageFile = fopen(path, "wb"); if (!storageFile) TraceLog(WARNING, "Storage data file could not be created"); else @@ -870,8 +881,17 @@ int StorageLoadValue(int position) { int value = 0; + char path[128]; +#if defined(PLATFORM_ANDROID) + strcpy(path, internalDataPath); + strcat(path, "/"); + strcat(path, STORAGE_FILENAME); +#else + strcpy(path, STORAGE_FILENAME); +#endif + // Try open existing file to append data - FILE *storageFile = fopen(STORAGE_FILENAME, "rb"); + FILE *storageFile = fopen(path, "rb"); if (!storageFile) TraceLog(WARNING, "Storage data file could not be found"); else diff --git a/src/utils.c b/src/utils.c index 974088f3..f0ccf3e2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -247,7 +247,7 @@ FILE *android_fopen(const char *fileName, const char *mode) AAsset *asset = AAssetManager_open(assetManager, fileName, 0); - if(!asset) return NULL; + if (!asset) return NULL; return funopen(asset, android_read, android_write, android_seek, android_close); } |
