Skip to content

Commit 68890b0

Browse files
committed
system: load <libpath>/../pkg if <libpath>/pkg doesn't exist but <libpath>/../pkg does
1 parent 559e2df commit 68890b0

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/engine/framework/System.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,27 @@ static void Init(int argc, char** argv)
658658

659659
// Initialize the filesystem. For pakpaths, the libpath is added first and has the
660660
// lowest priority, while the homepath is added last and has the highest.
661-
cmdlineArgs.pakPaths.insert(cmdlineArgs.pakPaths.begin(), FS::Path::Build(cmdlineArgs.libPath, "pkg"));
661+
662+
/* The default pakpath is <libpath>/pkg, but we load <libpath>/../pkg instead
663+
if <libpath>/pkg doesn't exist but <libpath>/../pkg exists.
664+
This is to make sure extracting the engine archive in a subfolder works.
665+
Many file browsers create a parent directory when there is no directory in an archive. */
666+
std::string defaultPakPath = FS::Path::Build(cmdlineArgs.libPath, "pkg");
667+
668+
std::error_code missing;
669+
FS::RawPath::ListFiles(defaultPakPath, missing);
670+
if (missing)
671+
{
672+
std::string parentPakPath = FS::Path::Build(cmdlineArgs.libPath, FS::Path::Build("..", "pkg"));
673+
FS::RawPath::ListFiles(parentPakPath, missing);
674+
if (!missing)
675+
{
676+
defaultPakPath = parentPakPath;
677+
}
678+
}
679+
680+
cmdlineArgs.pakPaths.insert(cmdlineArgs.pakPaths.begin(), defaultPakPath);
681+
662682
cmdlineArgs.pakPaths.push_back(FS::Path::Build(cmdlineArgs.homePath, "pkg"));
663683
EarlyCvar("fs_legacypaks", cmdlineArgs);
664684
FS::Initialize(cmdlineArgs.homePath, cmdlineArgs.libPath, cmdlineArgs.pakPaths);

0 commit comments

Comments
 (0)