From bbf5c806d806289b24d0d5c587fe4016d5640c21 Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Sat, 4 Sep 2021 20:34:02 +0200 Subject: [PATCH] Fix MSVC compilation due to macros in Windows API headers There exists `CreateDirectory` `#define` somewhere and it results in failed compilation of `resourcemanager.cpp`. Similarly for `RemoveDirectory`. See https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createdirectorya Rename the two methods to remove the conflict. The fail occurs at least when using Visual Studio 2022 Preview. --- src/app/signal_handlers.cpp | 2 +- src/common/resources/resourcemanager.cpp | 4 ++-- src/common/resources/resourcemanager.h | 4 ++-- src/level/player_profile.cpp | 8 ++++---- src/level/robotmain.cpp | 6 +++--- src/script/scriptfunc.cpp | 2 +- src/ui/filedialog.cpp | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp index ebcfe274..1558f4be 100644 --- a/src/app/signal_handlers.cpp +++ b/src/app/signal_handlers.cpp @@ -176,7 +176,7 @@ void CSignalHandlers::ReportError(const std::string& errorMessage) if (result == SDR_YES) { triedSaving = true; - CResourceManager::CreateDirectory("crashsave"); + CResourceManager::CreateNewDirectory("crashsave"); robotMain->IOWriteScene("crashsave/data.sav", "crashsave/cbot.run", "crashsave/screen.png", "Backup at the moment of a crash", true); m_systemUtils->SystemDialog(SDT_INFO, "Try to save?", "Saving finished.\nPlease restart the game now"); } diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp index 7c572483..3ff874db 100644 --- a/src/common/resources/resourcemanager.cpp +++ b/src/common/resources/resourcemanager.cpp @@ -156,7 +156,7 @@ bool CResourceManager::DirectoryExists(const std::string& directory) return false; } -bool CResourceManager::CreateDirectory(const std::string& directory) +bool CResourceManager::CreateNewDirectory(const std::string& directory) { if (PHYSFS_isInit()) { @@ -165,7 +165,7 @@ bool CResourceManager::CreateDirectory(const std::string& directory) return false; } -bool CResourceManager::RemoveDirectory(const std::string& directory) +bool CResourceManager::RemoveExistingDirectory(const std::string& directory) { if (PHYSFS_isInit()) { diff --git a/src/common/resources/resourcemanager.h b/src/common/resources/resourcemanager.h index d15a6f02..31dbd940 100644 --- a/src/common/resources/resourcemanager.h +++ b/src/common/resources/resourcemanager.h @@ -57,9 +57,9 @@ public: static bool DirectoryExists(const std::string& directory); //! Create directory in write directory - static bool CreateDirectory(const std::string& directory); + static bool CreateNewDirectory(const std::string& directory); //! Remove directory in write directory, recursively - static bool RemoveDirectory(const std::string& directory); + static bool RemoveExistingDirectory(const std::string& directory); //! List files contained in directory static std::vector ListFiles(const std::string &directory, bool excludeDirs = false); diff --git a/src/level/player_profile.cpp b/src/level/player_profile.cpp index cd7a1a3b..2b7e7e93 100644 --- a/src/level/player_profile.cpp +++ b/src/level/player_profile.cpp @@ -148,14 +148,14 @@ bool CPlayerProfile::Create() { if (!CResourceManager::DirectoryExists(GetSaveDir())) { - return CResourceManager::CreateDirectory(GetSaveDir()); + return CResourceManager::CreateNewDirectory(GetSaveDir()); } return true; } bool CPlayerProfile::Delete() { - return CResourceManager::RemoveDirectory(GetSaveDir()); + return CResourceManager::RemoveExistingDirectory(GetSaveDir()); } std::string CPlayerProfile::GetName() @@ -507,7 +507,7 @@ void CPlayerProfile::SaveScene(std::string dir, std::string info) { if (!CResourceManager::DirectoryExists(dir)) { - CResourceManager::CreateDirectory(dir); + CResourceManager::CreateNewDirectory(dir); } CRobotMain::GetInstancePointer()->IOWriteScene(dir + "/data.sav", dir + "/cbot.run", dir + "/screen.png", info.c_str()); @@ -568,7 +568,7 @@ bool CPlayerProfile::DeleteScene(std::string dir) { if (CResourceManager::DirectoryExists(dir)) { - return CResourceManager::RemoveDirectory(dir); + return CResourceManager::RemoveExistingDirectory(dir); } return false; } diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index af04448c..76a38833 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -504,12 +504,12 @@ void CRobotMain::ChangePhase(Phase phase) GetLogger()->Info("Trying to restore pre-crash state...\n"); assert(m_playerProfile != nullptr); m_playerProfile->LoadScene("../../crashsave"); - CResourceManager::RemoveDirectory("crashsave"); + CResourceManager::RemoveExistingDirectory("crashsave"); }, [&]() { GetLogger()->Info("Not restoring pre-crash state\n"); - CResourceManager::RemoveDirectory("crashsave"); + CResourceManager::RemoveExistingDirectory("crashsave"); } ); } @@ -5766,7 +5766,7 @@ void CRobotMain::AutosaveRotate() std::sort(autosaves.begin(), autosaves.end(), std::less()); for (int i = 0; i < static_cast(autosaves.size()) - m_autosaveSlots + 1; i++) { - CResourceManager::RemoveDirectory(m_playerProfile->GetSaveDir() + "/" + autosaves[i]); + CResourceManager::RemoveExistingDirectory(m_playerProfile->GetSaveDir() + "/" + autosaves[i]); } } diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index f35c7a2f..2c09a3e0 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -3400,7 +3400,7 @@ public: private: static std::string PrepareFilename(const std::string& filename) { - CResourceManager::CreateDirectory("files"); + CResourceManager::CreateNewDirectory("files"); return "files/" + filename; } }; diff --git a/src/ui/filedialog.cpp b/src/ui/filedialog.cpp index b73c4fb1..8416812b 100644 --- a/src/ui/filedialog.cpp +++ b/src/ui/filedialog.cpp @@ -1090,7 +1090,7 @@ std::string CFileDialog::SearchDirectory(bool bCreate) if (bCreate && !CResourceManager::DirectoryExists(dir)) { - CResourceManager::CreateDirectory(dir); + CResourceManager::CreateNewDirectory(dir); } if (!m_subDirPath.empty()) @@ -1098,7 +1098,7 @@ std::string CFileDialog::SearchDirectory(bool bCreate) dir += "/" + m_subDirPath; if (bCreate && !CResourceManager::DirectoryExists(dir)) { - CResourceManager::CreateDirectory(dir); + CResourceManager::CreateNewDirectory(dir); } }