Files
kichikuou_system3-sdl2/src/resource.cpp
T
kichikuou af69b3cfb3 Migrate to SDL3 (except for Android and Switch)
Switch desktop/emscripten builds from SDL2 to SDL3, applying only the
API changes that cannot compile through the SDL_oldnames.h aliases. Pure
renames will be swept in a follow-up commit.
2026-09-10 20:47:34 +09:00

42 lines
1.1 KiB
C++

#include <limits.h>
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#undef ERROR
#endif
#include <SDL3/SDL.h>
#include "common.h"
SDL_RWops* open_resource(const char* name, const char* type) {
#ifdef _WIN32
// On Windows, read from resource.
HINSTANCE hInst = GetModuleHandle(NULL);
HRSRC hRes = FindResource(hInst, name, type);
HGLOBAL hGlobal = LoadResource(hInst, hRes);
if (!hGlobal) {
WARNING("Cannot load resource %s (type: %s)", name, type);
return NULL;
}
return SDL_RWFromConstMem(LockResource(hGlobal), SizeofResource(hInst, hRes));
#else
// On Android, read from APK assets.
// On other platforms, read from a file under RESOURCE_PATH.
char path[PATH_MAX];
snprintf(path, PATH_MAX, "%s%s/%s", RESOURCE_PATH, type, name);
return SDL_RWFromFile(path, "rb");
#endif
}
SDL_RWops* open_file(const char* name) {
#ifdef __ANDROID__
// We cannot use SDL_RWFromFile() because it does not resolve relative
// paths using the current directory on Android.
FILE *fp = fopen(name, "rb");
if (!fp)
return NULL;
return SDL_RWFromFP(fp, SDL_TRUE);
#else
return SDL_RWFromFile(name, "rb");
#endif
}