Skip to content

Commit 860f653

Browse files
authored
Merge pull request #1526 from OutpostUniverse/searchForData
Add ability to search for `data` folder
2 parents 291316d + 33ada9c commit 860f653

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

OPHD/main.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@ namespace {
4646
std::cout << "\t" << str << std::endl;
4747
}
4848
}
49+
50+
51+
/**
52+
* Mount data folder(s) for static assets
53+
*
54+
* Prioritize data from working directory, fallback on data from executable path,
55+
* searching up to 2 levels above the executable
56+
*
57+
* @return Nonzero on success, zero on error.
58+
*/
59+
int mountDataFolder(Filesystem& filesystem)
60+
{
61+
// Current working directory may contain a partial data folder with customizations
62+
int result = filesystem.mountSoftFail("data");
63+
64+
// Assuming above folder was partial, we still want full data loaded for static assets
65+
// We find static assets folder with executable or in parent folders
66+
auto basePath = filesystem.basePath();
67+
for (int i = 0; i <= 2; ++i)
68+
{
69+
result = filesystem.mountSoftFail(basePath / "data");
70+
if (result != 0)
71+
{
72+
return result;
73+
}
74+
basePath = basePath / "..";
75+
}
76+
return result;
77+
}
4978
}
5079

5180

@@ -65,9 +94,7 @@ int main(int argc, char *argv[])
6594
try
6695
{
6796
auto& filesystem = Utility<Filesystem>::init<Filesystem>("OutpostHD", "LairWorks");
68-
// Prioritize data from working directory, fallback on data from executable path
69-
filesystem.mountSoftFail("data");
70-
filesystem.mountSoftFail(filesystem.basePath() / "data");
97+
mountDataFolder(filesystem);
7198
filesystem.mountReadWrite(filesystem.prefPath());
7299

73100
filesystem.makeDirectory(constants::SaveGamePath);

0 commit comments

Comments
 (0)