Added DownloadFile function
This commit is contained in:
parent
f6578edf67
commit
327864be53
54
src/core.c
54
src/core.c
|
|
@ -541,6 +541,45 @@ static void *GamepadThread(void *arg); // Mouse reading thread
|
||||||
// Module Functions Definition - Window and OpenGL Context Functions
|
// Module Functions Definition - Window and OpenGL Context Functions
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Function got from Stack Overflow
|
||||||
|
// https://stackoverflow.com/questions/2736753/how-to-remove-extension-from-file-name
|
||||||
|
const char *remove_extension(char* myStr, char extSep, char pathSep) {
|
||||||
|
char *retStr, *lastExt, *lastPath;
|
||||||
|
|
||||||
|
// Error checks and allocate string.
|
||||||
|
|
||||||
|
if (myStr == NULL) return NULL;
|
||||||
|
if ((retStr = malloc (strlen (myStr) + 1)) == NULL) return NULL;
|
||||||
|
|
||||||
|
// Make a copy and find the relevant characters.
|
||||||
|
|
||||||
|
strcpy (retStr, myStr);
|
||||||
|
lastExt = strrchr (retStr, extSep);
|
||||||
|
lastPath = (pathSep == 0) ? NULL : strrchr (retStr, pathSep);
|
||||||
|
|
||||||
|
// If it has an extension separator.
|
||||||
|
|
||||||
|
if (lastExt != NULL) {
|
||||||
|
// and it's to the right of the path separator.
|
||||||
|
|
||||||
|
if (lastPath != NULL) {
|
||||||
|
if (lastPath < lastExt) {
|
||||||
|
// then remove it.
|
||||||
|
|
||||||
|
*lastExt = '\0';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Has extension separator with no path separator.
|
||||||
|
|
||||||
|
*lastExt = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the modified string.
|
||||||
|
|
||||||
|
return retStr;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
// To allow easier porting to android, we allow the user to define a
|
// To allow easier porting to android, we allow the user to define a
|
||||||
// main function which we call from android_main, defined by ourselves
|
// main function which we call from android_main, defined by ourselves
|
||||||
|
|
@ -2207,6 +2246,21 @@ long GetFileModTime(const char *fileName)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Downloads a file from source (URL) to directory
|
||||||
|
// NOTES: It uses cURL
|
||||||
|
void DownloadFile(const char *src,const char *dir)
|
||||||
|
{
|
||||||
|
#ifdef __ANDROID__ || TARGET_OS_IPHONE || TARGET_OS_EMBEDDED || TARGET_IPHONE_SIMULATOR
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
if (system("curl --version") == 0) {
|
||||||
|
if (!system(FormatText("cd %s",remove_extension(dir,".","/"))) == 0) system(FormatText("mkdir %s",remove_extension(dir,".","/")));
|
||||||
|
system(FormatText("curl -o %s/%s %s",dir,GetFileName(src),src));
|
||||||
|
}
|
||||||
|
else return -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Compress data (DEFLATE algorythm)
|
// Compress data (DEFLATE algorythm)
|
||||||
unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength)
|
unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1097,6 +1097,7 @@ RLAPI bool IsFileDropped(void); // Check if a
|
||||||
RLAPI char **GetDroppedFiles(int *count); // Get dropped files names (memory should be freed)
|
RLAPI char **GetDroppedFiles(int *count); // Get dropped files names (memory should be freed)
|
||||||
RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory)
|
RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory)
|
||||||
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
|
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
|
||||||
|
RLAPI void DownloadFile(const char *src,const char *dir); // Downloads a file from URL to directory
|
||||||
|
|
||||||
RLAPI unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength); // Compress data (DEFLATE algorythm)
|
RLAPI unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength); // Compress data (DEFLATE algorythm)
|
||||||
RLAPI unsigned char *DecompressData(unsigned char *compData, int compDataLength, int *dataLength); // Decompress data (DEFLATE algorythm)
|
RLAPI unsigned char *DecompressData(unsigned char *compData, int compDataLength, int *dataLength); // Decompress data (DEFLATE algorythm)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user