61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include "sys.hpp"
|
|
#include <raylib.h>
|
|
|
|
#if defined(PLATFORM_ANDROID)
|
|
#include <raymob.h>
|
|
#endif
|
|
|
|
namespace sys
|
|
{
|
|
|
|
const char *transformFilePath(const char *filename)
|
|
{
|
|
#if defined(PLATFORM_ANDROID)
|
|
return TextFormat(
|
|
"%s/%s", GetAndroidApp()->activity->internalDataPath, filename);
|
|
#else
|
|
return filename;
|
|
#endif
|
|
}
|
|
|
|
size_t saveDataToFile(const char *filename, void *data, size_t size)
|
|
{
|
|
const char *saveFilePath = transformFilePath(filename);
|
|
|
|
FILE *file = fopen(saveFilePath, "wb");
|
|
if (file == NULL)
|
|
return false;
|
|
|
|
size_t ret = fwrite(data, 1, size, file);
|
|
fclose(file);
|
|
|
|
return ret;
|
|
}
|
|
|
|
size_t loadDataFromFile(const char *filename, void *data, size_t size)
|
|
{
|
|
const char *saveFilePath = transformFilePath(filename);
|
|
|
|
FILE *file = fopen(saveFilePath, "rb");
|
|
if (file == NULL)
|
|
return false;
|
|
|
|
size_t ret = fread(data, 1, size, file);
|
|
fclose(file);
|
|
|
|
return ret;
|
|
}
|
|
|
|
bool fileExists(const char *filename)
|
|
{
|
|
const char *saveFilePath = transformFilePath(filename);
|
|
|
|
bool result = false;
|
|
if (access(saveFilePath, F_OK) != -1)
|
|
result = true;
|
|
return result;
|
|
}
|
|
|
|
} |