2019-06-26 03:01:54 +00:00
|
|
|
#include <SDL.h>
|
2017-05-24 18:44:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "utils.h"
|
|
|
|
|
2018-11-09 22:20:57 +00:00
|
|
|
const char *resource_folder(void)
|
2017-05-24 18:44:43 +00:00
|
|
|
{
|
2018-11-09 22:20:57 +00:00
|
|
|
#ifdef DATA_DIR
|
|
|
|
return DATA_DIR;
|
|
|
|
#else
|
2017-12-28 18:29:15 +00:00
|
|
|
static const char *ret = NULL;
|
|
|
|
if (!ret) {
|
|
|
|
ret = SDL_GetBasePath();
|
|
|
|
if (!ret) {
|
|
|
|
ret = "./";
|
2017-05-24 18:44:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-28 18:29:15 +00:00
|
|
|
return ret;
|
2018-11-09 22:20:57 +00:00
|
|
|
#endif
|
2017-05-24 18:44:43 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 22:20:57 +00:00
|
|
|
char *resource_path(const char *filename)
|
2017-05-24 18:44:43 +00:00
|
|
|
{
|
|
|
|
static char path[1024];
|
2018-11-09 22:20:57 +00:00
|
|
|
snprintf(path, sizeof(path), "%s%s", resource_folder(), filename);
|
2017-05-24 18:44:43 +00:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2018-11-09 22:20:57 +00:00
|
|
|
|
2017-05-24 18:44:43 +00:00
|
|
|
void replace_extension(const char *src, size_t length, char *dest, const char *ext)
|
|
|
|
{
|
|
|
|
memcpy(dest, src, length);
|
|
|
|
dest[length] = 0;
|
2018-11-09 22:20:57 +00:00
|
|
|
|
2017-05-24 18:44:43 +00:00
|
|
|
/* Remove extension */
|
|
|
|
for (size_t i = length; i--;) {
|
|
|
|
if (dest[i] == '/') break;
|
|
|
|
if (dest[i] == '.') {
|
|
|
|
dest[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-11-09 22:20:57 +00:00
|
|
|
|
2017-05-24 18:44:43 +00:00
|
|
|
/* Add new extension */
|
|
|
|
strcat(dest, ext);
|
|
|
|
}
|