Support Android internal data storage
Useful to save small data files (configuration and so) For bigger files, external data storage should be used (SDCard)
This commit is contained in:
parent
4b93349db5
commit
8a4e28f81d
2 changed files with 24 additions and 4 deletions
26
src/core.c
26
src/core.c
|
@ -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
|
||||
|
@ -839,11 +841,20 @@ 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue