Skip to content

Commit c1e3ced

Browse files
authored
Better asset path lookup for Haiku (diasurgical#7927)
1 parent b256396 commit c1e3ced

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

Source/utils/paths.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#ifdef __HAIKU__
1515
#include <FindDirectory.h>
16+
#include <dirent.h>
1617
#include <fs_info.h>
1718
#endif
1819

@@ -124,10 +125,24 @@ const std::string &AssetsPath()
124125
{
125126
if (!assetsPath) {
126127
#if defined(__HAIKU__)
128+
// Look in system first (system-wide install)
127129
char buffer[B_PATH_NAME_LENGTH + 10];
128130
find_directory(B_SYSTEM_DATA_DIRECTORY, dev_for_path("/boot"), false, buffer, B_PATH_NAME_LENGTH);
129131
strcat(buffer, "/devilutionx/");
130-
assetsPath.emplace(strdup(buffer));
132+
if (opendir(buffer)) {
133+
assetsPath.emplace(strdup(buffer));
134+
} else {
135+
// Then look in user data (home-data install)
136+
char homedata[B_PATH_NAME_LENGTH + 10];
137+
find_directory(B_USER_DATA_DIRECTORY, dev_for_path("/boot"), false, homedata, B_PATH_NAME_LENGTH);
138+
strcat(homedata, "/devilutionx/");
139+
if (opendir(homedata)) {
140+
assetsPath.emplace(strdup(homedata));
141+
} else {
142+
// If that fails just fall back to the binary's dir (compiled raw & other misc. cases)
143+
assetsPath.emplace(FromSDL(SDL_GetBasePath()) + ("assets" DIRECTORY_SEPARATOR_STR));
144+
}
145+
}
131146
#elif __EMSCRIPTEN__
132147
assetsPath.emplace("assets/");
133148
#elif defined(NXDK)

0 commit comments

Comments
 (0)