Skip to content

Commit 987f607

Browse files
committed
2 parents 1bb3521 + 43474a3 commit 987f607

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

Sources/Jazz2/ContentResolver.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,31 @@ namespace Jazz2
204204
_contentPath = NCINE_INSTALL_PREFIX "/share/" NCINE_LINUX_PACKAGE "/Content/";
205205
# endif
206206
# if defined(NCINE_PACKAGED_CONTENT_PATH)
207-
// If Content is packaged with binaries, always use standard XDG paths for everything else
208-
auto localStorage = fs::GetLocalStorage();
209-
if (!localStorage.empty()) {
210-
auto appData = fs::CombinePath(localStorage, NCINE_LINUX_PACKAGE);
211-
_sourcePath = fs::CombinePath(appData, "Source/"_s);
212-
_cachePath = fs::CombinePath(appData, "Cache/"_s);
207+
// If Content is packaged with binaries, prefer a local Source/ for portable use and
208+
// fall back to standard XDG paths otherwise.
209+
// AppRun cds into the AppImage mount point before launching, so CWD is useless —
210+
// use dirname($APPIMAGE) to resolve paths relative to the .AppImage file itself.
211+
String localBase;
212+
StringView appImageEnv = ::getenv("APPIMAGE");
213+
if (!appImageEnv.empty()) {
214+
localBase = fs::GetDirectoryName(appImageEnv);
215+
}
216+
217+
String localSourcePath = fs::CombinePath(localBase, "Source/"_s);
218+
if (fs::FindPathCaseInsensitive(fs::CombinePath(localSourcePath, "Anims.j2a"_s)) ||
219+
fs::FindPathCaseInsensitive(fs::CombinePath(localSourcePath, "AnimsSw.j2a"_s))) {
220+
_sourcePath = std::move(localSourcePath);
221+
_cachePath = fs::CombinePath(localBase, "Cache/"_s);
213222
} else {
214-
_sourcePath = "Source/"_s;
215-
_cachePath = "Cache/"_s;
223+
auto localStorage = fs::GetLocalStorage();
224+
if (!localStorage.empty()) {
225+
auto appData = fs::CombinePath(localStorage, NCINE_LINUX_PACKAGE);
226+
_sourcePath = fs::CombinePath(appData, "Source/"_s);
227+
_cachePath = fs::CombinePath(appData, "Cache/"_s);
228+
} else {
229+
_sourcePath = "Source/"_s;
230+
_cachePath = "Cache/"_s;
231+
}
216232
}
217233
# else
218234
if (fs::DirectoryExists(_contentPath)) {

0 commit comments

Comments
 (0)