1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-09-11 06:45:59 +00:00

find_file to find files in HYPERPATH

This commit is contained in:
Zeno Rogue
2022-08-26 12:23:58 +02:00
parent 7be773ea03
commit 31b2bd9690
4 changed files with 21 additions and 4 deletions

View File

@@ -766,6 +766,19 @@ EX bool file_exists(string fname) {
return access(fname.c_str(), F_OK) != -1;
}
/** find a file named s, possibly in HYPERPATH */
EX string find_file(string s) {
string s1;
if(file_exists(s)) return s;
char *p = getenv("HYPERPATH");
if(p && file_exists(s1 = s0 + p + s)) return s1;
if(file_exists(s1 = HYPERPATH + s)) return s1;
#ifdef FHS
if(file_exists(s1 = "/usr/share/hyperrogue/" + s)) return s1;
#endif
return s;
}
EX void open_url(string s) {
#if ISWEB
EM_ASM_({