36#if !defined(EXTERNAL_CONFIG_FLAGS)
42#if defined(PLATFORM_ANDROID)
44 #include <android/log.h>
45 #include <android/asset_manager.h>
56#ifndef MAX_TRACELOG_MSG_LENGTH
57 #define MAX_TRACELOG_MSG_LENGTH 128
81#if defined(PLATFORM_ANDROID)
82static AAssetManager *assetManager =
NULL;
83static const char *internalDataPath =
NULL;
89#if defined(PLATFORM_ANDROID)
90FILE *funopen(
const void *cookie,
int (*readfn)(
void *,
char *,
int),
int (*writefn)(
void *,
const char *,
int),
91 fpos_t (*seekfn)(
void *, fpos_t,
int),
int (*closefn)(
void *));
93static int android_read(
void *cookie,
char *buf,
int size);
94static int android_write(
void *cookie,
const char *buf,
int size);
95static fpos_t android_seek(
void *cookie, fpos_t offset,
int whence);
96static int android_close(
void *cookie);
109#if defined(SUPPORT_TRACELOG)
111 if (logType < logTypeLevel)
return;
114 va_start(args, text);
118 traceLog(logType, text, args);
123#if defined(PLATFORM_ANDROID)
126 case LOG_TRACE: __android_log_vprint(ANDROID_LOG_VERBOSE,
"raylib", text, args);
break;
127 case LOG_DEBUG: __android_log_vprint(ANDROID_LOG_DEBUG,
"raylib", text, args);
break;
128 case LOG_INFO: __android_log_vprint(ANDROID_LOG_INFO,
"raylib", text, args);
break;
129 case LOG_WARNING: __android_log_vprint(ANDROID_LOG_WARN,
"raylib", text, args);
break;
130 case LOG_ERROR: __android_log_vprint(ANDROID_LOG_ERROR,
"raylib", text, args);
break;
131 case LOG_FATAL: __android_log_vprint(ANDROID_LOG_FATAL,
"raylib", text, args);
break;
139 case LOG_TRACE: strcpy(buffer,
"TRACE: ");
break;
140 case LOG_DEBUG: strcpy(buffer,
"DEBUG: ");
break;
141 case LOG_INFO: strcpy(buffer,
"INFO: ");
break;
142 case LOG_WARNING: strcpy(buffer,
"WARNING: ");
break;
143 case LOG_ERROR: strcpy(buffer,
"ERROR: ");
break;
144 case LOG_FATAL: strcpy(buffer,
"FATAL: ");
break;
148 strcat(buffer, text);
149 strcat(buffer,
"\n");
150 vprintf(buffer, args);
155 if (logType ==
LOG_FATAL) exit(EXIT_FAILURE);
182unsigned char *
LoadFileData(
const char *fileName,
unsigned int *bytesRead)
184 unsigned char *data =
NULL;
187 if (fileName !=
NULL)
191 data = loadFileData(fileName, bytesRead);
194#if defined(SUPPORT_STANDARD_FILEIO)
195 FILE *file = fopen(fileName,
"rb");
201 fseek(file, 0, SEEK_END);
202 int size = ftell(file);
203 fseek(file, 0, SEEK_SET);
207 data = (
unsigned char *)
RL_MALLOC(size*
sizeof(
unsigned char));
210 unsigned int count = (
unsigned int)fread(data,
sizeof(
unsigned char), size, file);
237bool SaveFileData(
const char *fileName,
void *data,
unsigned int bytesToWrite)
239 bool success =
false;
241 if (fileName !=
NULL)
245 return saveFileData(fileName, data, bytesToWrite);
247#if defined(SUPPORT_STANDARD_FILEIO)
248 FILE *file = fopen(fileName,
"wb");
252 unsigned int count = (
unsigned int)fwrite(data,
sizeof(
unsigned char), bytesToWrite, file);
255 else if (count != bytesToWrite)
TRACELOG(
LOG_WARNING,
"FILEIO: [%s] File partially written", fileName);
258 int result = fclose(file);
259 if (result == 0) success =
true;
274 bool success =
false;
276#ifndef TEXT_BYTES_PER_LINE
277 #define TEXT_BYTES_PER_LINE 20
282 char *txtData = (
char *)
RL_CALLOC(size*6 + 2000,
sizeof(
char));
285 byteCount += sprintf(txtData + byteCount,
"////////////////////////////////////////////////////////////////////////////////////////\n");
286 byteCount += sprintf(txtData + byteCount,
"// //\n");
287 byteCount += sprintf(txtData + byteCount,
"// DataAsCode exporter v1.0 - Raw data exported as an array of bytes //\n");
288 byteCount += sprintf(txtData + byteCount,
"// //\n");
289 byteCount += sprintf(txtData + byteCount,
"// more info and bugs-report: github.com/raysan5/raylib //\n");
290 byteCount += sprintf(txtData + byteCount,
"// feedback and support: ray[at]raylib.com //\n");
291 byteCount += sprintf(txtData + byteCount,
"// //\n");
292 byteCount += sprintf(txtData + byteCount,
"// Copyright (c) 2022 Ramon Santamaria (@raysan5) //\n");
293 byteCount += sprintf(txtData + byteCount,
"// //\n");
294 byteCount += sprintf(txtData + byteCount,
"////////////////////////////////////////////////////////////////////////////////////////\n\n");
297 char varFileName[256] = { 0 };
299 for (
int i = 0; varFileName[i] !=
'\0'; i++)
if ((varFileName[i] >=
'a') && (varFileName[i] <=
'z')) { varFileName[i] = varFileName[i] - 32; }
301 byteCount += sprintf(txtData + byteCount,
"static unsigned char %s_DATA[%i] = { ", varFileName, size);
302 for (
int i = 0; i < size - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%
TEXT_BYTES_PER_LINE == 0)?
"0x%x,\n" :
"0x%x, "), data[i]);
303 byteCount += sprintf(txtData + byteCount,
"0x%x };\n", data[size - 1]);
310 if (success != 0)
TRACELOG(
LOG_INFO,
"FILEIO: [%s] Data as code exported successfully", fileName);
322 if (fileName !=
NULL)
326 text = loadFileText(fileName);
329#if defined(SUPPORT_STANDARD_FILEIO)
330 FILE *file = fopen(fileName,
"rt");
337 fseek(file, 0, SEEK_END);
338 unsigned int size = (
unsigned int)ftell(file);
339 fseek(file, 0, SEEK_SET);
343 text = (
char *)
RL_MALLOC((size + 1)*
sizeof(char));
344 unsigned int count = (
unsigned int)fread(text,
sizeof(
char), size, file);
348 if (count < size) text =
RL_REALLOC(text, count + 1);
378 bool success =
false;
380 if (fileName !=
NULL)
384 return saveFileText(fileName, text);
386#if defined(SUPPORT_STANDARD_FILEIO)
387 FILE *file = fopen(fileName,
"wt");
391 int count = fprintf(file,
"%s", text);
394 else TRACELOG(
LOG_INFO,
"FILEIO: [%s] Text file saved successfully", fileName);
396 int result = fclose(file);
397 if (result == 0) success =
true;
409#if defined(PLATFORM_ANDROID)
411void InitAssetManager(AAssetManager *manager,
const char *dataPath)
413 assetManager = manager;
414 internalDataPath = dataPath;
419FILE *android_fopen(
const char *fileName,
const char *mode)
428 return fopen(
TextFormat(
"%s/%s", internalDataPath, fileName), mode);
429 #define fopen(name, mode) android_fopen(name, mode)
434 AAsset *asset = AAssetManager_open(assetManager, fileName, AASSET_MODE_UNKNOWN);
439 return funopen(asset, android_read, android_write, android_seek, android_close);
445 return fopen(
TextFormat(
"%s/%s", internalDataPath, fileName), mode);
446 #define fopen(name, mode) android_fopen(name, mode)
455#if defined(PLATFORM_ANDROID)
456static int android_read(
void *cookie,
char *buf,
int size)
458 return AAsset_read((AAsset *)cookie, buf, size);
461static int android_write(
void *cookie,
const char *buf,
int size)
468static fpos_t android_seek(
void *cookie, fpos_t offset,
int whence)
470 return AAsset_seek((AAsset *)cookie, offset, whence);
473static int android_close(
void *cookie)
475 AAsset_close((AAsset *)cookie);
#define MAX_TRACELOG_MSG_LENGTH
#define RL_MALLOC(sz)
raudio v1.0 - A simple and easy-to-use audio library based on miniaudio
#define TRACELOG(level,...)
RLAPI const char * TextFormat(const char *text,...)
bool(* SaveFileDataCallback)(const char *fileName, void *data, unsigned int bytesToWrite)
unsigned char *(* LoadFileDataCallback)(const char *fileName, unsigned int *bytesRead)
#define RL_REALLOC(ptr, sz)
char *(* LoadFileTextCallback)(const char *fileName)
bool(* SaveFileTextCallback)(const char *fileName, char *text)
RLAPI const char * GetFileNameWithoutExt(const char *filePath)
void(* TraceLogCallback)(int logLevel, const char *text, va_list args)
void UnloadFileText(char *text)
char * LoadFileText(const char *fileName)
void SetLoadFileTextCallback(LoadFileTextCallback callback)
void SetTraceLogCallback(TraceLogCallback callback)
unsigned char * LoadFileData(const char *fileName, unsigned int *bytesRead)
void UnloadFileData(unsigned char *data)
bool ExportDataAsCode(const char *data, unsigned int size, const char *fileName)
void SetTraceLogLevel(int logType)
void SetLoadFileDataCallback(LoadFileDataCallback callback)
void TraceLog(int logType, const char *text,...)
void * MemRealloc(void *ptr, int size)
#define TEXT_BYTES_PER_LINE
bool SaveFileText(const char *fileName, char *text)
void * MemAlloc(int size)
void SetSaveFileTextCallback(SaveFileTextCallback callback)
void SetSaveFileDataCallback(SaveFileDataCallback callback)
bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite)