@@ -74,20 +74,63 @@ bool IsValidLuaFile(const std::wstring &path, std::string &firstLine)
74
74
75
75
bool FindLaunchLua (std::wstring basePath, std::vector<std::wstring> &commandLine, std::string &firstLine)
76
76
{
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" ;
78
94
if (IsValidLuaFile (launchPath, firstLine))
79
95
{
80
96
commandLine.insert (commandLine.begin () + 1 , launchPath);
81
97
return true ;
82
98
}
83
99
84
- launchPath = basePath + L" src\\ Launch.lua" ;
100
+ // Look for src\\Launch.lua
101
+ launchPath = basePath + L" \\ src\\ Launch.lua" ;
85
102
if (IsValidLuaFile (launchPath, firstLine))
86
103
{
87
104
commandLine.insert (commandLine.begin () + 1 , launchPath);
88
105
return true ;
89
106
}
90
107
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
+ }
91
134
return false ;
92
135
}
93
136
@@ -110,7 +153,7 @@ bool InsertLaunchLua(std::vector<std::wstring> &commandLine, std::string &firstL
110
153
111
154
// Search for the Launch.lua file in various locations it may exist
112
155
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
114
157
{
115
158
wchar_t wszModuleFilename[MAX_PATH]{};
116
159
if (GetModuleFileName (nullptr , wszModuleFilename, MAX_PATH) > 0 )
0 commit comments