Skip to content

Commit 0979187

Browse files
committed
If the base path ends with "runtime" then Launch.lua is looked for in the parent directory\src\Launch.lua
- The check for "runtime" is to avoid looking in folders not owned by Path of Building. This is based on the new directory structure: - Base path -- runtime --- executable -- src --- Launch.lua
1 parent ed279e6 commit 0979187

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

Launcher.cpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,63 @@ bool IsValidLuaFile(const std::wstring &path, std::string &firstLine)
7474

7575
bool FindLaunchLua(std::wstring basePath, std::vector<std::wstring> &commandLine, std::string &firstLine)
7676
{
77-
std::wstring launchPath = basePath + L"Launch.lua";
77+
// Unify path separator characters
78+
for (size_t i = 0; i < basePath.length(); i++)
79+
{
80+
if (basePath[i] == L'/')
81+
{
82+
basePath[i] = L'\\';
83+
}
84+
}
85+
86+
// Remove the trailing slash if it exists
87+
if (basePath[basePath.size() - 1] == L'\\')
88+
{
89+
basePath = basePath.substr(0, basePath.size() - 1);
90+
}
91+
92+
// Look for Launch.lua directly in the base path
93+
std::wstring launchPath = basePath + L"\\Launch.lua";
7894
if (IsValidLuaFile(launchPath, firstLine))
7995
{
8096
commandLine.insert(commandLine.begin() + 1, launchPath);
8197
return true;
8298
}
8399

84-
launchPath = basePath + L"src\\Launch.lua";
100+
// Look for src\\Launch.lua
101+
launchPath = basePath + L"\\src\\Launch.lua";
85102
if (IsValidLuaFile(launchPath, firstLine))
86103
{
87104
commandLine.insert(commandLine.begin() + 1, launchPath);
88105
return true;
89106
}
90107

108+
// If the base path ends with "runtime" then strip that off, append "src" and look for Launch.lua there
109+
static const std::wstring runtime = L"runtime";
110+
if (basePath.length() > runtime.length() + 1)
111+
{
112+
// Find the last slash
113+
const size_t lastSlash = basePath.find_last_of(L'\\');
114+
if (lastSlash != std::wstring::npos)
115+
{
116+
// Extract the full subdirectory name
117+
std::wstring subDir = basePath.substr(lastSlash + 1);
118+
for (size_t i = 0; i < subDir.size(); i++)
119+
{
120+
subDir[i] = towlower(subDir[i]);
121+
}
122+
if (subDir == runtime)
123+
{
124+
std::wstring parentPath = basePath.substr(0, lastSlash);
125+
launchPath = parentPath + L"\\src\\Launch.lua";
126+
if (IsValidLuaFile(launchPath, firstLine))
127+
{
128+
commandLine.insert(commandLine.begin() + 1, launchPath);
129+
return true;
130+
}
131+
}
132+
}
133+
}
91134
return false;
92135
}
93136

@@ -110,7 +153,7 @@ bool InsertLaunchLua(std::vector<std::wstring> &commandLine, std::string &firstL
110153

111154
// Search for the Launch.lua file in various locations it may exist
112155

113-
// Look in the same directory as the executable as well as the "src" folder within that
156+
// Look in the same directory as the executable
114157
{
115158
wchar_t wszModuleFilename[MAX_PATH]{};
116159
if (GetModuleFileName(nullptr, wszModuleFilename, MAX_PATH) > 0)

0 commit comments

Comments
 (0)