@@ -182,14 +182,16 @@ static void InitializeProcessBaseDir(SString& strProcessBaseDir)
182182
183183 if (DWORD lengthFull = GetFullPathNameW (corePathBuffer.c_str (), static_cast <DWORD>(fullPath.size ()), fullPath.data (), nullptr ); lengthFull > 0 )
184184 {
185- // Process path and extract base directory by walking up to find Bin/ directory
186- const auto processPath = [&strProcessBaseDir, bCoreModuleFound](const std::wstring_view fullPathStr) {
185+ // Process path and extract base directory
186+ // The directory above /MTA/ is always the base directory
187+ const auto processPath = [&strProcessBaseDir](const std::wstring_view fullPathStr) {
187188 if (const auto lastSeparator = fullPathStr.find_last_of (L" \\ /" ); lastSeparator != std::wstring_view::npos)
188189 {
189190 const auto moduleDir = fullPathStr.substr (0 , lastSeparator);
190191 auto currentPath = std::filesystem::path (moduleDir);
191192
192- // Walk up the directory tree to find Bin/ folder
193+ // Walk up to find MTA/ folder
194+ // Stop at first MTA folder found - it's guaranteed to be the correct one
193195 // Check current directory and up to 2 parent levels
194196 for (auto level = 0 ; level < 3 ; ++level)
195197 {
@@ -198,10 +200,15 @@ static void InitializeProcessBaseDir(SString& strProcessBaseDir)
198200 // Convert to lowercase for case-insensitive comparison
199201 std::transform (folderName.begin (), folderName.end (), folderName.begin (), ::towlower);
200202
201- if (folderName == L" bin " )
203+ if (folderName == L" mta " )
202204 {
203- strProcessBaseDir = ToUTF8 (currentPath.wstring ());
204- return ;
205+ // Found MTA folder - base directory is its parent
206+ // Stop searching immediately to avoid finding outer "MTA" folders (e.g user with custom intall dir)
207+ if (currentPath.has_parent_path ())
208+ {
209+ strProcessBaseDir = ToUTF8 (currentPath.parent_path ().wstring ());
210+ }
211+ return ; // Always stop at first MTA folder found
205212 }
206213
207214 // Move up one level
@@ -210,25 +217,6 @@ static void InitializeProcessBaseDir(SString& strProcessBaseDir)
210217 else
211218 break ; // Reached root, can't go further
212219 }
213-
214- // Fallback: Check if current working directory is or contains Bin/
215- if (!bCoreModuleFound)
216- {
217- if (auto cwdBuffer = std::array<wchar_t , MAX_PATH>{}; GetCurrentDirectoryW (MAX_PATH, cwdBuffer.data ()) > 0 )
218- {
219- const auto cwdPath = std::filesystem::path{cwdBuffer.data ()};
220- auto cwdName = cwdPath.filename ().wstring ();
221- std::transform (cwdName.cbegin (), cwdName.cend (), cwdName.begin (), ::towlower);
222-
223- if (cwdName == L" bin" )
224- {
225- strProcessBaseDir = ToUTF8 (cwdPath.wstring ());
226- return ;
227- }
228- }
229- }
230-
231- // No Bin/ folder found - leave strProcessBaseDir empty
232220 }
233221 };
234222
0 commit comments