diff --git a/src/common.h b/src/common.h index 61beccc..bf067b1 100644 --- a/src/common.h +++ b/src/common.h @@ -58,5 +58,6 @@ static inline bool is_2byte_message(uint8_t c) { // resource.cpp SDL_RWops* open_resource(const char* name, const char* type); +SDL_RWops* open_file(const char* name); #endif diff --git a/src/resource.cpp b/src/resource.cpp index e93d001..2f763e1 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -23,3 +23,16 @@ SDL_RWops* open_resource(const char* name, const char* type) { 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 +} diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index e83dc0b..d29d7e3 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -63,14 +63,9 @@ AGS::AGS(NACT* parent, const Config& config) : nact(parent), dirty(false) // フォント TTF_Init(); if (!config.font_file.empty()) { - // We cannot use SDL_RWFromFile() here because it does not resolve - // relative paths using the current directory on Android. - FILE *fp = fopen(config.font_file.c_str(), "rb"); - if (!fp) - parent->fatal("Cannot open font file %s", config.font_file.c_str()); - rw_font = SDL_RWFromFP(fp, SDL_TRUE); + rw_font = open_file(config.font_file.c_str()); if (!rw_font) - parent->fatal("Cannot load font file %s: %s", config.font_file.c_str(), SDL_GetError()); + parent->fatal("Cannot open font file %s", config.font_file.c_str()); } else { rw_font = open_resource(FONT_RESOURCE_NAME, "fonts"); if (!rw_font)