From 5a4f0fcfdef2e51c1e1d846793e79ef93e00b2d5 Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Wed, 21 Jan 2026 18:09:25 +0100 Subject: [PATCH 1/5] initial commit --- Client/core/CCore.cpp | 92 +++++++++ Client/core/CCore.h | 6 + Client/core/CSettings.cpp | 199 ++++++++++++++++++- Client/core/CSettings.h | 4 + Client/core/StdInc.h | 1 + Client/mods/deathmatch/logic/CClientGame.cpp | 2 +- Client/sdk/core/CCoreInterface.h | 5 + 7 files changed, 302 insertions(+), 7 deletions(-) diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 1128bfc0b6..251f4c94c8 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -2453,3 +2453,95 @@ std::shared_ptr CCore::GetDiscord() { return m_pDiscordRichPresence; } + +// Get File Cache Path from coreconfig.xml or fallback to registry +SString CCore::GetFileCachePath() +{ + // First check coreconfig.xml + CXMLNode* pRoot = GetConfig(); + if (pRoot) + { + CXMLNode* pFileCachePath = pRoot->FindSubNode("file_cache_path"); + if (pFileCachePath) + { + SString strPath = pFileCachePath->GetTagContent(); + if (!strPath.empty()) + return strPath; + } + } + + // Fallback to registry + return GetCommonRegistryValue("", "File Cache Path"); +} + +// Set File Cache Path in coreconfig.xml +bool CCore::SetFileCachePath(const SString& strPath) +{ + CXMLNode* pRoot = GetConfig(); + if (!pRoot) + return false; + + CXMLNode* pFileCachePath = pRoot->FindSubNode("file_cache_path"); + if (!pFileCachePath) + pFileCachePath = pRoot->CreateSubNode("file_cache_path"); + + pFileCachePath->SetTagContent(strPath); + SaveConfig(); + return true; +} + +// Remove File Cache Path from coreconfig.xml to fallback to registry +bool CCore::ResetFileCachePath() +{ + CXMLNode* pRoot = GetConfig(); + if (!pRoot) + return false; + + CXMLNode* pFileCachePath = pRoot->FindSubNode("file_cache_path"); + if (pFileCachePath) + { + pRoot->DeleteSubNode(pFileCachePath); + SaveConfig(); + } + + return true; +} + +// Validate a file cache path +bool CCore::ValidateFileCachePath(const SString& strPath, SString& strError) +{ + if (strPath.empty()) + { + strError = "Path cannot be empty"; + return false; + } + + // Check if directory exists + if (!DirectoryExists(strPath)) + { + strError = "Directory does not exist"; + return false; + } + + // Check if path is not inside MTA directory to avoid conflicts + SString strMTAPath = GetMTADataPath(); + SString strNormalizedPath = PathConform(strPath); + SString strNormalizedMTAPath = PathConform(strMTAPath); + + if (strNormalizedPath.BeginsWithI(strNormalizedMTAPath)) + { + strError = "Path cannot be inside MTA installation folder to avoid conflicts"; + return false; + } + + // Check if writable + SString strTestFile = PathJoin(strPath, "_test_write.tmp"); + if (!FileSave(strTestFile, "test")) + { + strError = "Directory is not writable"; + return false; + } + FileDelete(strTestFile); + + return true; +} diff --git a/Client/core/CCore.h b/Client/core/CCore.h index 7b9ee431fd..3e207cc546 100644 --- a/Client/core/CCore.h +++ b/Client/core/CCore.h @@ -113,6 +113,12 @@ class CCore : public CCoreInterface, public CSingleton void SaveConfig(bool bWaitUntilFinished = false); + // File Cache Path management + SString GetFileCachePath(); + bool SetFileCachePath(const SString& strPath); + bool ResetFileCachePath(); + bool ValidateFileCachePath(const SString& strPath, SString& strError); + // Debug void DebugEcho(const char* szText); void DebugPrintf(const char* szFormat, ...); diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index fe73aeaba8..1685c154e5 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -307,6 +307,8 @@ void CSettings::ResetGuiPointers() m_pCachePathLabel = NULL; m_pCachePathValue = NULL; m_pCachePathShowButton = NULL; + m_pCachePathBrowseButton = NULL; + m_pCachePathResetButton = NULL; m_pLabelMasterVolume = NULL; m_pLabelRadioVolume = NULL; @@ -1857,15 +1859,27 @@ void CSettings::CreateGUI() m_pCachePathLabel->AutoSize(); m_pCachePathShowButton = reinterpret_cast(pManager->CreateButton(pTabAdvanced, _("Show in Explorer"))); - m_pCachePathShowButton->SetPosition(CVector2D(vecTemp.fX + fIndentX + 1, vecTemp.fY - 1)); - m_pCachePathShowButton->AutoSize(NULL, 20.0f, 8.0f); + m_pCachePathShowButton->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY)); + m_pCachePathShowButton->SetSize(CVector2D(120.0f, 20.0f)); m_pCachePathShowButton->SetClickHandler(GUI_CALLBACK(&CSettings::OnCachePathShowButtonClick, this)); m_pCachePathShowButton->SetZOrderingEnabled(false); - m_pCachePathShowButton->GetSize(vecSize); - SString strFileCachePath = GetCommonRegistryValue("", "File Cache Path"); + m_pCachePathBrowseButton = reinterpret_cast(pManager->CreateButton(pTabAdvanced, _("Change Path"))); + m_pCachePathBrowseButton->SetPosition(CVector2D(vecTemp.fX + fIndentX + 130, vecTemp.fY)); + m_pCachePathBrowseButton->SetSize(CVector2D(120.0f, 20.0f)); + m_pCachePathBrowseButton->SetClickHandler(GUI_CALLBACK(&CSettings::OnCachePathBrowseButtonClick, this)); + m_pCachePathBrowseButton->SetZOrderingEnabled(false); + + m_pCachePathResetButton = reinterpret_cast(pManager->CreateButton(pTabAdvanced, _("Reset Path"))); + m_pCachePathResetButton->SetPosition(CVector2D(vecTemp.fX + fIndentX + 260, vecTemp.fY)); + m_pCachePathResetButton->SetSize(CVector2D(120.0f, 20.0f)); + m_pCachePathResetButton->SetClickHandler(GUI_CALLBACK(&CSettings::OnCachePathResetButtonClick, this)); + m_pCachePathResetButton->SetZOrderingEnabled(false); + vecTemp.fY += fLineHeight; + + SString strFileCachePath = CCore::GetSingleton().GetFileCachePath(); m_pCachePathValue = reinterpret_cast(pManager->CreateLabel(pTabAdvanced, strFileCachePath)); - m_pCachePathValue->SetPosition(CVector2D(vecTemp.fX + fIndentX + vecSize.fX + 10, vecTemp.fY + 3)); + m_pCachePathValue->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY)); m_pCachePathValue->SetFont("default-small"); m_pCachePathValue->AutoSize(); vecTemp.fY += fLineHeight; @@ -5586,12 +5600,185 @@ bool CSettings::OnUpdateButtonClick(CGUIElement* pElement) bool CSettings::OnCachePathShowButtonClick(CGUIElement* pElement) { - SString strFileCachePath = GetCommonRegistryValue("", "File Cache Path"); + SString strFileCachePath = CCore::GetSingleton().GetFileCachePath(); if (DirectoryExists(strFileCachePath)) ShellExecuteNonBlocking("open", strFileCachePath); return true; } +struct BrowseFolderThreadData +{ + WString strTitle; + wchar_t szResult[MAX_PATH]; + bool bSuccess; +}; + +DWORD WINAPI BrowseFolderThread(LPVOID lpParam) +{ + BrowseFolderThreadData* pData = (BrowseFolderThreadData*)lpParam; + + CoInitialize(NULL); + ShowCursor(TRUE); + SetCursor(LoadCursor(NULL, IDC_ARROW)); + + BROWSEINFOW bi = {0}; + bi.lpszTitle = pData->strTitle; + bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; + bi.hwndOwner = NULL; + + LPITEMIDLIST pidl = SHBrowseForFolderW(&bi); + + if (pidl != NULL) + { + if (SHGetPathFromIDListW(pidl, pData->szResult)) + { + pData->bSuccess = true; + } + CoTaskMemFree(pidl); + } + + CoUninitialize(); + return 0; +} + +bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) +{ + SString strCurrentPath = CCore::GetSingleton().GetFileCachePath(); + + BrowseFolderThreadData threadData; + threadData.strTitle = FromUTF8(_("Select a folder for Client resource files (must be outside MTA folder)")); + threadData.szResult[0] = 0; + threadData.bSuccess = false; + + HANDLE hThread = CreateThread(NULL, 0, BrowseFolderThread, &threadData, 0, NULL); + if (hThread) + { + WaitForSingleObject(hThread, INFINITE); + CloseHandle(hThread); + } + + if (threadData.bSuccess) + { + SString strSelectedPath = ToUTF8(threadData.szResult); + SString strDefaultPath = GetCommonRegistryValue("", "File Cache Path"); + SString strError; + + if (!strDefaultPath.empty() && PathConform(strSelectedPath) == PathConform(strDefaultPath)) + { + if (PathConform(strCurrentPath) != PathConform(strDefaultPath)) + { + if (CCore::GetSingleton().ResetFileCachePath()) + { + m_pCachePathValue->SetText(strDefaultPath); + m_pCachePathValue->AutoSize(); + + CCore::GetSingleton().ShowMessageBox( + _("File Cache Path Reset"), + _("File cache path has been reset to default. Changes will take effect after restarting MTA."), + MB_BUTTON_OK | MB_ICON_INFO + ); + + ShowRestartQuestion(); + } + } + else + { + CCore::GetSingleton().ShowMessageBox( + _("Info"), + _("You are already using the default file cache path."), + MB_BUTTON_OK | MB_ICON_INFO + ); + } + } + else if (CCore::GetSingleton().ValidateFileCachePath(strSelectedPath, strError)) + { + if (PathConform(strCurrentPath) != PathConform(strSelectedPath)) + { + if (CCore::GetSingleton().SetFileCachePath(strSelectedPath)) + { + m_pCachePathValue->SetText(strSelectedPath); + m_pCachePathValue->AutoSize(); + + CCore::GetSingleton().ShowMessageBox( + _("File Cache Path Changed"), + _("The file cache path has been successfully changed. Changes will take effect after restarting MTA."), + MB_BUTTON_OK | MB_ICON_INFO + ); + + ShowRestartQuestion(); + } + else + { + CCore::GetSingleton().ShowMessageBox( + _("Error"), + _("Failed to save the file cache path to configuration."), + MB_BUTTON_OK | MB_ICON_ERROR + ); + } + } + else + { + CCore::GetSingleton().ShowMessageBox( + _("Info"), + _("The selected path is the same as the current file cache path."), + MB_BUTTON_OK | MB_ICON_INFO + ); + } + } + else + { + CCore::GetSingleton().ShowMessageBox( + _("Invalid Path"), + strError, + MB_BUTTON_OK | MB_ICON_ERROR + ); + } + } + + return true; +} + +bool CSettings::OnCachePathResetButtonClick(CGUIElement* pElement) +{ + SString strCurrentPath = CCore::GetSingleton().GetFileCachePath(); + SString strDefaultPath = GetCommonRegistryValue("", "File Cache Path"); + + if (!strDefaultPath.empty() && PathConform(strCurrentPath) == PathConform(strDefaultPath)) + { + CCore::GetSingleton().ShowMessageBox( + _("Info"), + _("You are already using the default file cache path."), + MB_BUTTON_OK | MB_ICON_INFO + ); + return true; + } + + if (CCore::GetSingleton().ResetFileCachePath()) + { + strDefaultPath = CCore::GetSingleton().GetFileCachePath(); + m_pCachePathValue->SetText(strDefaultPath); + m_pCachePathValue->AutoSize(); + + CCore::GetSingleton().ShowMessageBox( + _("File Cache Path Reset"), + _("File cache path has been reset to default. Changes will take effect after restarting MTA."), + MB_BUTTON_OK | MB_ICON_INFO + ); + + ShowRestartQuestion(); + } + else + { + CCore::GetSingleton().ShowMessageBox( + _("Error"), + _("Failed to reset the file cache path."), + MB_BUTTON_OK | MB_ICON_ERROR + ); + } + + return true; +} + bool CSettings::OnFxQualityChanged(CGUIElement* pElement) { CGUIListItem* pItem = m_pComboFxQuality->GetSelectedItem(); diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index 3c23e99a25..d8ccc8ee09 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -256,6 +256,8 @@ class CSettings CGUILabel* m_pCachePathLabel; CGUILabel* m_pCachePathValue; CGUIButton* m_pCachePathShowButton; + CGUIButton* m_pCachePathBrowseButton; + CGUIButton* m_pCachePathResetButton; CGUILabel* m_pLabelMasterVolume; CGUILabel* m_pLabelRadioVolume; CGUILabel* m_pLabelSFXVolume; @@ -419,6 +421,8 @@ class CSettings bool OnChatAlphaChanged(CGUIElement* pElement); bool OnUpdateButtonClick(CGUIElement* pElement); bool OnCachePathShowButtonClick(CGUIElement* pElement); + bool OnCachePathBrowseButtonClick(CGUIElement* pElement); + bool OnCachePathResetButtonClick(CGUIElement* pElement); bool OnMouseSensitivityChanged(CGUIElement* pElement); bool OnVerticalAimSensitivityChanged(CGUIElement* pElement); bool OnBrowserBlacklistAdd(CGUIElement* pElement); diff --git a/Client/core/StdInc.h b/Client/core/StdInc.h index ed06205655..b81a7af8cd 100644 --- a/Client/core/StdInc.h +++ b/Client/core/StdInc.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 47d7461cdd..eb26ddf8db 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -6766,7 +6766,7 @@ void CClientGame::SetFileCacheRoot() else { // Get shared directory - SString strFileCachePath = GetCommonRegistryValue("", "File Cache Path"); + SString strFileCachePath = g_pCore->GetFileCachePath(); // Check exists if (!strFileCachePath.empty() && DirectoryExists(strFileCachePath)) { diff --git a/Client/sdk/core/CCoreInterface.h b/Client/sdk/core/CCoreInterface.h index 07f3848e61..d0be565dd7 100644 --- a/Client/sdk/core/CCoreInterface.h +++ b/Client/sdk/core/CCoreInterface.h @@ -135,6 +135,11 @@ class CCoreInterface virtual void SaveConfig(bool bWaitUntilFinished = false) = 0; virtual void UpdateRecentlyPlayed() = 0; + virtual SString GetFileCachePath() = 0; + virtual bool SetFileCachePath(const SString& strPath) = 0; + virtual bool ResetFileCachePath() = 0; + virtual bool ValidateFileCachePath(const SString& strPath, SString& strError) = 0; + virtual void SwitchRenderWindow(HWND hWnd, HWND hWndInput) = 0; virtual void SetCenterCursor(bool bEnabled) = 0; virtual bool IsTimingCheckpoints() = 0; From 8038096c84636d9c9ab44d56a6d0f10deac7ccd5 Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Wed, 21 Jan 2026 18:59:47 +0100 Subject: [PATCH 2/5] formatting fix --- Client/core/CSettings.cpp | 85 +++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 1685c154e5..139f4225c9 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -5610,7 +5610,8 @@ struct BrowseFolderThreadData { WString strTitle; wchar_t szResult[MAX_PATH]; - bool bSuccess; + bool bSuccess; + HWND hParentWindow; }; DWORD WINAPI BrowseFolderThread(LPVOID lpParam) @@ -5624,7 +5625,7 @@ DWORD WINAPI BrowseFolderThread(LPVOID lpParam) BROWSEINFOW bi = {0}; bi.lpszTitle = pData->strTitle; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; - bi.hwndOwner = NULL; + bi.hwndOwner = pData->hParentWindow; LPITEMIDLIST pidl = SHBrowseForFolderW(&bi); @@ -5644,19 +5645,36 @@ DWORD WINAPI BrowseFolderThread(LPVOID lpParam) bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) { SString strCurrentPath = CCore::GetSingleton().GetFileCachePath(); + HWND hWnd = CCore::GetSingleton().GetHookedWindow(); BrowseFolderThreadData threadData; threadData.strTitle = FromUTF8(_("Select a folder for Client resource files (must be outside MTA folder)")); threadData.szResult[0] = 0; threadData.bSuccess = false; + threadData.hParentWindow = NULL; + + EnableWindow(hWnd, FALSE); HANDLE hThread = CreateThread(NULL, 0, BrowseFolderThread, &threadData, 0, NULL); if (hThread) { - WaitForSingleObject(hThread, INFINITE); + MSG msg; + DWORD dwWaitResult = WaitForSingleObject(hThread, INFINITE); + while (dwWaitResult) + { + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + dwWaitResult = WaitForSingleObject(hThread, 0); + } CloseHandle(hThread); } + EnableWindow(hWnd, TRUE); + SetForegroundWindow(hWnd); + if (threadData.bSuccess) { SString strSelectedPath = ToUTF8(threadData.szResult); @@ -5672,22 +5690,16 @@ bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) m_pCachePathValue->SetText(strDefaultPath); m_pCachePathValue->AutoSize(); - CCore::GetSingleton().ShowMessageBox( - _("File Cache Path Reset"), - _("File cache path has been reset to default. Changes will take effect after restarting MTA."), - MB_BUTTON_OK | MB_ICON_INFO - ); + CCore::GetSingleton().ShowMessageBox(_("File Cache Path Reset"), + _("File cache path has been reset to default. Changes will take effect after restarting MTA."), + MB_BUTTON_OK | MB_ICON_INFO); ShowRestartQuestion(); } } else { - CCore::GetSingleton().ShowMessageBox( - _("Info"), - _("You are already using the default file cache path."), - MB_BUTTON_OK | MB_ICON_INFO - ); + CCore::GetSingleton().ShowMessageBox(_("Info"), _("You are already using the default file cache path."), MB_BUTTON_OK | MB_ICON_INFO); } } else if (CCore::GetSingleton().ValidateFileCachePath(strSelectedPath, strError)) @@ -5699,39 +5711,26 @@ bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) m_pCachePathValue->SetText(strSelectedPath); m_pCachePathValue->AutoSize(); - CCore::GetSingleton().ShowMessageBox( - _("File Cache Path Changed"), - _("The file cache path has been successfully changed. Changes will take effect after restarting MTA."), - MB_BUTTON_OK | MB_ICON_INFO - ); + CCore::GetSingleton().ShowMessageBox(_("File Cache Path Changed"), + _("The file cache path has been successfully changed. Changes will take effect after restarting MTA."), + MB_BUTTON_OK | MB_ICON_INFO); ShowRestartQuestion(); } else { - CCore::GetSingleton().ShowMessageBox( - _("Error"), - _("Failed to save the file cache path to configuration."), - MB_BUTTON_OK | MB_ICON_ERROR - ); + CCore::GetSingleton().ShowMessageBox(_("Error"), _("Failed to save the file cache path to configuration."), MB_BUTTON_OK | MB_ICON_ERROR); } } else { - CCore::GetSingleton().ShowMessageBox( - _("Info"), - _("The selected path is the same as the current file cache path."), - MB_BUTTON_OK | MB_ICON_INFO - ); + CCore::GetSingleton().ShowMessageBox(_("Info"), _("The selected path is the same as the current file cache path."), + MB_BUTTON_OK | MB_ICON_INFO); } } else { - CCore::GetSingleton().ShowMessageBox( - _("Invalid Path"), - strError, - MB_BUTTON_OK | MB_ICON_ERROR - ); + CCore::GetSingleton().ShowMessageBox(_("Invalid Path"), strError, MB_BUTTON_OK | MB_ICON_ERROR); } } @@ -5745,11 +5744,7 @@ bool CSettings::OnCachePathResetButtonClick(CGUIElement* pElement) if (!strDefaultPath.empty() && PathConform(strCurrentPath) == PathConform(strDefaultPath)) { - CCore::GetSingleton().ShowMessageBox( - _("Info"), - _("You are already using the default file cache path."), - MB_BUTTON_OK | MB_ICON_INFO - ); + CCore::GetSingleton().ShowMessageBox(_("Info"), _("You are already using the default file cache path."), MB_BUTTON_OK | MB_ICON_INFO); return true; } @@ -5759,21 +5754,15 @@ bool CSettings::OnCachePathResetButtonClick(CGUIElement* pElement) m_pCachePathValue->SetText(strDefaultPath); m_pCachePathValue->AutoSize(); - CCore::GetSingleton().ShowMessageBox( - _("File Cache Path Reset"), - _("File cache path has been reset to default. Changes will take effect after restarting MTA."), - MB_BUTTON_OK | MB_ICON_INFO - ); + CCore::GetSingleton().ShowMessageBox(_("File Cache Path Reset"), + _("File cache path has been reset to default. Changes will take effect after restarting MTA."), + MB_BUTTON_OK | MB_ICON_INFO); ShowRestartQuestion(); } else { - CCore::GetSingleton().ShowMessageBox( - _("Error"), - _("Failed to reset the file cache path."), - MB_BUTTON_OK | MB_ICON_ERROR - ); + CCore::GetSingleton().ShowMessageBox(_("Error"), _("Failed to reset the file cache path."), MB_BUTTON_OK | MB_ICON_ERROR); } return true; From f20f100827ca3dfc006665646418bdcd8c1c4c3b Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Wed, 21 Jan 2026 19:01:10 +0100 Subject: [PATCH 3/5] Implement file cache path validation and fallback to registry if deleted --- Client/core/CCore.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 251f4c94c8..75fb920408 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -2466,7 +2466,19 @@ SString CCore::GetFileCachePath() { SString strPath = pFileCachePath->GetTagContent(); if (!strPath.empty()) - return strPath; + { + // Check if custom path still exists + if (DirectoryExists(strPath)) + { + return strPath; + } + else + { + // Custom path was deleted, remove from config and fallback to registry + pRoot->DeleteSubNode(pFileCachePath); + SaveConfig(); + } + } } } From 8b60fded1d3b27d3e36e9aced3c5d77b611c9379 Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Wed, 21 Jan 2026 19:16:50 +0100 Subject: [PATCH 4/5] fix fullscreen issue --- Client/core/CSettings.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 139f4225c9..017ed59517 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -5647,6 +5647,16 @@ bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) SString strCurrentPath = CCore::GetSingleton().GetFileCachePath(); HWND hWnd = CCore::GetSingleton().GetHookedWindow(); + bool bWasFullscreen = !GetVideoModeManager()->IsWindowed(); + if (bWasFullscreen) + { + ShowWindow(hWnd, SW_MINIMIZE); + } + + CGUI* pGUI = CCore::GetSingleton().GetGUI(); + bool wasCursorEnabled = pGUI->IsCursorEnabled(); + pGUI->SetCursorEnabled(false); + BrowseFolderThreadData threadData; threadData.strTitle = FromUTF8(_("Select a folder for Client resource files (must be outside MTA folder)")); threadData.szResult[0] = 0; @@ -5675,6 +5685,14 @@ bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) EnableWindow(hWnd, TRUE); SetForegroundWindow(hWnd); + if (wasCursorEnabled) + pGUI->SetCursorEnabled(true); + + if (bWasFullscreen) + { + ShowWindow(hWnd, SW_RESTORE); + } + if (threadData.bSuccess) { SString strSelectedPath = ToUTF8(threadData.szResult); From fead7ae4d2f8354ee60125f1e08cb1269bed569d Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Wed, 21 Jan 2026 19:20:49 +0100 Subject: [PATCH 5/5] fixesy --- Client/core/CCore.cpp | 70 ++++++------ Client/core/CCore.h | 4 +- Client/core/CSettings.cpp | 110 +++++++++---------- Client/mods/deathmatch/logic/CClientGame.cpp | 22 ++-- Client/sdk/core/CCoreInterface.h | 4 +- 5 files changed, 105 insertions(+), 105 deletions(-) diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 75fb920408..e7be11bbbd 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -2458,24 +2458,24 @@ std::shared_ptr CCore::GetDiscord() SString CCore::GetFileCachePath() { // First check coreconfig.xml - CXMLNode* pRoot = GetConfig(); - if (pRoot) + CXMLNode* root = GetConfig(); + if (root) { - CXMLNode* pFileCachePath = pRoot->FindSubNode("file_cache_path"); - if (pFileCachePath) + CXMLNode* fileCachePath = root->FindSubNode("file_cache_path"); + if (fileCachePath) { - SString strPath = pFileCachePath->GetTagContent(); - if (!strPath.empty()) + SString path = fileCachePath->GetTagContent(); + if (!path.empty()) { // Check if custom path still exists - if (DirectoryExists(strPath)) + if (DirectoryExists(path)) { - return strPath; + return path; } else { // Custom path was deleted, remove from config and fallback to registry - pRoot->DeleteSubNode(pFileCachePath); + root->DeleteSubNode(fileCachePath); SaveConfig(); } } @@ -2487,17 +2487,17 @@ SString CCore::GetFileCachePath() } // Set File Cache Path in coreconfig.xml -bool CCore::SetFileCachePath(const SString& strPath) +bool CCore::SetFileCachePath(const SString& path) { - CXMLNode* pRoot = GetConfig(); - if (!pRoot) + CXMLNode* root = GetConfig(); + if (!root) return false; - CXMLNode* pFileCachePath = pRoot->FindSubNode("file_cache_path"); - if (!pFileCachePath) - pFileCachePath = pRoot->CreateSubNode("file_cache_path"); + CXMLNode* fileCachePath = root->FindSubNode("file_cache_path"); + if (!fileCachePath) + fileCachePath = root->CreateSubNode("file_cache_path"); - pFileCachePath->SetTagContent(strPath); + fileCachePath->SetTagContent(path); SaveConfig(); return true; } @@ -2505,14 +2505,14 @@ bool CCore::SetFileCachePath(const SString& strPath) // Remove File Cache Path from coreconfig.xml to fallback to registry bool CCore::ResetFileCachePath() { - CXMLNode* pRoot = GetConfig(); - if (!pRoot) + CXMLNode* root = GetConfig(); + if (!root) return false; - CXMLNode* pFileCachePath = pRoot->FindSubNode("file_cache_path"); - if (pFileCachePath) + CXMLNode* fileCachePath = root->FindSubNode("file_cache_path"); + if (fileCachePath) { - pRoot->DeleteSubNode(pFileCachePath); + root->DeleteSubNode(fileCachePath); SaveConfig(); } @@ -2520,40 +2520,40 @@ bool CCore::ResetFileCachePath() } // Validate a file cache path -bool CCore::ValidateFileCachePath(const SString& strPath, SString& strError) +bool CCore::ValidateFileCachePath(const SString& path, SString& error) { - if (strPath.empty()) + if (path.empty()) { - strError = "Path cannot be empty"; + error = "Path cannot be empty"; return false; } // Check if directory exists - if (!DirectoryExists(strPath)) + if (!DirectoryExists(path)) { - strError = "Directory does not exist"; + error = "Directory does not exist"; return false; } // Check if path is not inside MTA directory to avoid conflicts - SString strMTAPath = GetMTADataPath(); - SString strNormalizedPath = PathConform(strPath); - SString strNormalizedMTAPath = PathConform(strMTAPath); + SString mtaPath = GetMTADataPath(); + SString normalizedPath = PathConform(path); + SString normalizedMTAPath = PathConform(mtaPath); - if (strNormalizedPath.BeginsWithI(strNormalizedMTAPath)) + if (normalizedPath.BeginsWithI(normalizedMTAPath)) { - strError = "Path cannot be inside MTA installation folder to avoid conflicts"; + error = "Path cannot be inside MTA installation folder to avoid conflicts"; return false; } // Check if writable - SString strTestFile = PathJoin(strPath, "_test_write.tmp"); - if (!FileSave(strTestFile, "test")) + SString testFile = PathJoin(path, "_test_write.tmp"); + if (!FileSave(testFile, "test")) { - strError = "Directory is not writable"; + error = "Directory is not writable"; return false; } - FileDelete(strTestFile); + FileDelete(testFile); return true; } diff --git a/Client/core/CCore.h b/Client/core/CCore.h index 3e207cc546..2bbb80a0b7 100644 --- a/Client/core/CCore.h +++ b/Client/core/CCore.h @@ -115,9 +115,9 @@ class CCore : public CCoreInterface, public CSingleton // File Cache Path management SString GetFileCachePath(); - bool SetFileCachePath(const SString& strPath); + bool SetFileCachePath(const SString& path); bool ResetFileCachePath(); - bool ValidateFileCachePath(const SString& strPath, SString& strError); + bool ValidateFileCachePath(const SString& path, SString& error); // Debug void DebugEcho(const char* szText); diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 017ed59517..b8915d4e06 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -1877,8 +1877,8 @@ void CSettings::CreateGUI() m_pCachePathResetButton->SetZOrderingEnabled(false); vecTemp.fY += fLineHeight; - SString strFileCachePath = CCore::GetSingleton().GetFileCachePath(); - m_pCachePathValue = reinterpret_cast(pManager->CreateLabel(pTabAdvanced, strFileCachePath)); + SString fileCachePath = CCore::GetSingleton().GetFileCachePath(); + m_pCachePathValue = reinterpret_cast(pManager->CreateLabel(pTabAdvanced, fileCachePath)); m_pCachePathValue->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY)); m_pCachePathValue->SetFont("default-small"); m_pCachePathValue->AutoSize(); @@ -5600,40 +5600,40 @@ bool CSettings::OnUpdateButtonClick(CGUIElement* pElement) bool CSettings::OnCachePathShowButtonClick(CGUIElement* pElement) { - SString strFileCachePath = CCore::GetSingleton().GetFileCachePath(); - if (DirectoryExists(strFileCachePath)) - ShellExecuteNonBlocking("open", strFileCachePath); + SString fileCachePath = CCore::GetSingleton().GetFileCachePath(); + if (DirectoryExists(fileCachePath)) + ShellExecuteNonBlocking("open", fileCachePath); return true; } struct BrowseFolderThreadData { - WString strTitle; - wchar_t szResult[MAX_PATH]; - bool bSuccess; - HWND hParentWindow; + WString title; + wchar_t result[MAX_PATH]; + bool success; + HWND parentWindow; }; DWORD WINAPI BrowseFolderThread(LPVOID lpParam) { - BrowseFolderThreadData* pData = (BrowseFolderThreadData*)lpParam; + BrowseFolderThreadData* data = (BrowseFolderThreadData*)lpParam; CoInitialize(NULL); ShowCursor(TRUE); SetCursor(LoadCursor(NULL, IDC_ARROW)); BROWSEINFOW bi = {0}; - bi.lpszTitle = pData->strTitle; + bi.lpszTitle = data->title; bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; - bi.hwndOwner = pData->hParentWindow; + bi.hwndOwner = data->parentWindow; LPITEMIDLIST pidl = SHBrowseForFolderW(&bi); if (pidl != NULL) { - if (SHGetPathFromIDListW(pidl, pData->szResult)) + if (SHGetPathFromIDListW(pidl, data->result)) { - pData->bSuccess = true; + data->success = true; } CoTaskMemFree(pidl); } @@ -5644,68 +5644,68 @@ DWORD WINAPI BrowseFolderThread(LPVOID lpParam) bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) { - SString strCurrentPath = CCore::GetSingleton().GetFileCachePath(); - HWND hWnd = CCore::GetSingleton().GetHookedWindow(); + SString currentPath = CCore::GetSingleton().GetFileCachePath(); + HWND wnd = CCore::GetSingleton().GetHookedWindow(); - bool bWasFullscreen = !GetVideoModeManager()->IsWindowed(); - if (bWasFullscreen) + bool wasFullscreen = !GetVideoModeManager()->IsWindowed(); + if (wasFullscreen) { - ShowWindow(hWnd, SW_MINIMIZE); + ShowWindow(wnd, SW_MINIMIZE); } - CGUI* pGUI = CCore::GetSingleton().GetGUI(); - bool wasCursorEnabled = pGUI->IsCursorEnabled(); - pGUI->SetCursorEnabled(false); + CGUI* gui = CCore::GetSingleton().GetGUI(); + bool wasCursorEnabled = gui->IsCursorEnabled(); + gui->SetCursorEnabled(false); BrowseFolderThreadData threadData; - threadData.strTitle = FromUTF8(_("Select a folder for Client resource files (must be outside MTA folder)")); - threadData.szResult[0] = 0; - threadData.bSuccess = false; - threadData.hParentWindow = NULL; + threadData.title = FromUTF8(_("Select a folder for Client resource files (must be outside MTA folder)")); + threadData.result[0] = 0; + threadData.success = false; + threadData.parentWindow = NULL; - EnableWindow(hWnd, FALSE); + EnableWindow(wnd, FALSE); - HANDLE hThread = CreateThread(NULL, 0, BrowseFolderThread, &threadData, 0, NULL); - if (hThread) + HANDLE thread = CreateThread(NULL, 0, BrowseFolderThread, &threadData, 0, NULL); + if (thread) { MSG msg; - DWORD dwWaitResult = WaitForSingleObject(hThread, INFINITE); - while (dwWaitResult) + DWORD waitResult = WaitForSingleObject(thread, INFINITE); + while (waitResult) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } - dwWaitResult = WaitForSingleObject(hThread, 0); + waitResult = WaitForSingleObject(thread, 0); } - CloseHandle(hThread); + CloseHandle(thread); } - EnableWindow(hWnd, TRUE); - SetForegroundWindow(hWnd); + EnableWindow(wnd, TRUE); + SetForegroundWindow(wnd); if (wasCursorEnabled) - pGUI->SetCursorEnabled(true); + gui->SetCursorEnabled(true); - if (bWasFullscreen) + if (wasFullscreen) { - ShowWindow(hWnd, SW_RESTORE); + ShowWindow(wnd, SW_RESTORE); } - if (threadData.bSuccess) + if (threadData.success) { - SString strSelectedPath = ToUTF8(threadData.szResult); - SString strDefaultPath = GetCommonRegistryValue("", "File Cache Path"); - SString strError; + SString selectedPath = ToUTF8(threadData.result); + SString defaultPath = GetCommonRegistryValue("", "File Cache Path"); + SString error; - if (!strDefaultPath.empty() && PathConform(strSelectedPath) == PathConform(strDefaultPath)) + if (!defaultPath.empty() && PathConform(selectedPath) == PathConform(defaultPath)) { - if (PathConform(strCurrentPath) != PathConform(strDefaultPath)) + if (PathConform(currentPath) != PathConform(defaultPath)) { if (CCore::GetSingleton().ResetFileCachePath()) { - m_pCachePathValue->SetText(strDefaultPath); + m_pCachePathValue->SetText(defaultPath); m_pCachePathValue->AutoSize(); CCore::GetSingleton().ShowMessageBox(_("File Cache Path Reset"), @@ -5720,13 +5720,13 @@ bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) CCore::GetSingleton().ShowMessageBox(_("Info"), _("You are already using the default file cache path."), MB_BUTTON_OK | MB_ICON_INFO); } } - else if (CCore::GetSingleton().ValidateFileCachePath(strSelectedPath, strError)) + else if (CCore::GetSingleton().ValidateFileCachePath(selectedPath, error)) { - if (PathConform(strCurrentPath) != PathConform(strSelectedPath)) + if (PathConform(currentPath) != PathConform(selectedPath)) { - if (CCore::GetSingleton().SetFileCachePath(strSelectedPath)) + if (CCore::GetSingleton().SetFileCachePath(selectedPath)) { - m_pCachePathValue->SetText(strSelectedPath); + m_pCachePathValue->SetText(selectedPath); m_pCachePathValue->AutoSize(); CCore::GetSingleton().ShowMessageBox(_("File Cache Path Changed"), @@ -5748,7 +5748,7 @@ bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) } else { - CCore::GetSingleton().ShowMessageBox(_("Invalid Path"), strError, MB_BUTTON_OK | MB_ICON_ERROR); + CCore::GetSingleton().ShowMessageBox(_("Invalid Path"), error, MB_BUTTON_OK | MB_ICON_ERROR); } } @@ -5757,10 +5757,10 @@ bool CSettings::OnCachePathBrowseButtonClick(CGUIElement* pElement) bool CSettings::OnCachePathResetButtonClick(CGUIElement* pElement) { - SString strCurrentPath = CCore::GetSingleton().GetFileCachePath(); - SString strDefaultPath = GetCommonRegistryValue("", "File Cache Path"); + SString currentPath = CCore::GetSingleton().GetFileCachePath(); + SString defaultPath = GetCommonRegistryValue("", "File Cache Path"); - if (!strDefaultPath.empty() && PathConform(strCurrentPath) == PathConform(strDefaultPath)) + if (!defaultPath.empty() && PathConform(currentPath) == PathConform(defaultPath)) { CCore::GetSingleton().ShowMessageBox(_("Info"), _("You are already using the default file cache path."), MB_BUTTON_OK | MB_ICON_INFO); return true; @@ -5768,8 +5768,8 @@ bool CSettings::OnCachePathResetButtonClick(CGUIElement* pElement) if (CCore::GetSingleton().ResetFileCachePath()) { - strDefaultPath = CCore::GetSingleton().GetFileCachePath(); - m_pCachePathValue->SetText(strDefaultPath); + defaultPath = CCore::GetSingleton().GetFileCachePath(); + m_pCachePathValue->SetText(defaultPath); m_pCachePathValue->AutoSize(); CCore::GetSingleton().ShowMessageBox(_("File Cache Path Reset"), diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index eb26ddf8db..5b2f236b88 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -6766,21 +6766,21 @@ void CClientGame::SetFileCacheRoot() else { // Get shared directory - SString strFileCachePath = g_pCore->GetFileCachePath(); + SString fileCachePath = g_pCore->GetFileCachePath(); // Check exists - if (!strFileCachePath.empty() && DirectoryExists(strFileCachePath)) + if (!fileCachePath.empty() && DirectoryExists(fileCachePath)) { // Check writable - SString strTestFileName = PathJoin(strFileCachePath, "resources", "_test.tmp"); - if (FileSave(strTestFileName, "x")) + SString testFileName = PathJoin(fileCachePath, "resources", "_test.tmp"); + if (FileSave(testFileName, "x")) { - FileDelete(strTestFileName); - strTestFileName = PathJoin(strFileCachePath, "priv", "_test.tmp"); - if (FileSave(strTestFileName, "x")) + FileDelete(testFileName); + testFileName = PathJoin(fileCachePath, "priv", "_test.tmp"); + if (FileSave(testFileName, "x")) { - FileDelete(strTestFileName); + FileDelete(testFileName); // Use shared directory - m_strFileCacheRoot = strFileCachePath; + m_strFileCacheRoot = fileCachePath; AddReportLog(7411, SString("CClientGame::SetFileCacheRoot - Is shared '%s'", *m_strFileCacheRoot)); return; } @@ -6791,10 +6791,10 @@ void CClientGame::SetFileCacheRoot() m_strFileCacheRoot = GetModRoot(); SetCommonRegistryValue("", "File Cache Path", m_strFileCacheRoot); - if (strFileCachePath.empty()) + if (fileCachePath.empty()) AddReportLog(7412, SString("CClientGame::SetFileCacheRoot - Initial setting '%s'", *m_strFileCacheRoot)); else - AddReportLog(7413, SString("CClientGame::SetFileCacheRoot - Change shared from '%s' to '%s'", *strFileCachePath, *m_strFileCacheRoot)); + AddReportLog(7413, SString("CClientGame::SetFileCacheRoot - Change shared from '%s' to '%s'", *fileCachePath, *m_strFileCacheRoot)); } } diff --git a/Client/sdk/core/CCoreInterface.h b/Client/sdk/core/CCoreInterface.h index d0be565dd7..880b418d03 100644 --- a/Client/sdk/core/CCoreInterface.h +++ b/Client/sdk/core/CCoreInterface.h @@ -136,9 +136,9 @@ class CCoreInterface virtual void UpdateRecentlyPlayed() = 0; virtual SString GetFileCachePath() = 0; - virtual bool SetFileCachePath(const SString& strPath) = 0; + virtual bool SetFileCachePath(const SString& path) = 0; virtual bool ResetFileCachePath() = 0; - virtual bool ValidateFileCachePath(const SString& strPath, SString& strError) = 0; + virtual bool ValidateFileCachePath(const SString& path, SString& error) = 0; virtual void SwitchRenderWindow(HWND hWnd, HWND hWndInput) = 0; virtual void SetCenterCursor(bool bEnabled) = 0;