@@ -46,6 +46,35 @@ namespace {
46
46
std::cout << " \t " << str << std::endl;
47
47
}
48
48
}
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
+ }
49
78
}
50
79
51
80
@@ -65,9 +94,7 @@ int main(int argc, char *argv[])
65
94
try
66
95
{
67
96
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);
71
98
filesystem.mountReadWrite (filesystem.prefPath ());
72
99
73
100
filesystem.makeDirectory (constants::SaveGamePath);
0 commit comments