From 31b2bd9690c5ecb8d930d9b1a7dfabd87a829694 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 26 Aug 2022 12:23:58 +0200 Subject: [PATCH] find_file to find files in HYPERPATH --- arbitrile.cpp | 2 +- sound.cpp | 2 +- textures.cpp | 8 ++++++-- util.cpp | 13 +++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/arbitrile.cpp b/arbitrile.cpp index 6bf0a826..97ea2c67 100644 --- a/arbitrile.cpp +++ b/arbitrile.cpp @@ -1722,7 +1722,7 @@ auto hook = addHook(hooks_args, 100, readArgs); EX bool in() { return geometry == gArbitrary; } -EX string tes = "tessellations/sample/marjorie-rice.tes"; +EX string tes = find_file("tessellations/sample/marjorie-rice.tes"); EX bool linespattern(cell *c) { return current.shapes[id_of(c->master)].flags & arcm::sfLINE; diff --git a/sound.cpp b/sound.cpp index 04687ea8..254a622f 100644 --- a/sound.cpp +++ b/sound.cpp @@ -207,7 +207,7 @@ EX bool loadMusicInfo() { #endif #ifdef FHS || loadMusicInfo("/usr/share/hyperrogue/hyperrogue-music.txt") - || loadMusicInfo(s0 + getenv("HOME") + "/.hyperrogue-music.txt") + || (getenv("HOME") && loadMusicInfo(s0 + getenv("HOME") + "/.hyperrogue-music.txt")) #endif ; } diff --git a/textures.cpp b/textures.cpp index c52aed0e..e6be9bdb 100644 --- a/textures.cpp +++ b/textures.cpp @@ -28,6 +28,10 @@ struct textureinfo : basic_textureinfo { }; #endif +#if HDR +string find_file(string s); +#endif + EX namespace texture { #if HDR @@ -120,8 +124,8 @@ struct texture_config { texture_config() { // argh, no member initialization in some of my compilers - texturename = "textures/hyperrogue-texture.png"; - configname = "textures/hyperrogue.txc"; + texturename = find_file("textures/hyperrogue-texture.png"); + configname = find_file("textures/hyperrogue.txc"); itt = Id; grid_color = 0; mesh_color = 0; diff --git a/util.cpp b/util.cpp index 822c9267..96947a7b 100644 --- a/util.cpp +++ b/util.cpp @@ -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_({