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.
fix-squashed-planets
MrSimbax 2021-09-04 20:34:02 +02:00
parent 8f0b367f9c
commit bbf5c806d8
7 changed files with 15 additions and 15 deletions

View File

@ -176,7 +176,7 @@ void CSignalHandlers::ReportError(const std::string& errorMessage)
if (result == SDR_YES) if (result == SDR_YES)
{ {
triedSaving = true; 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); 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"); m_systemUtils->SystemDialog(SDT_INFO, "Try to save?", "Saving finished.\nPlease restart the game now");
} }

View File

@ -156,7 +156,7 @@ bool CResourceManager::DirectoryExists(const std::string& directory)
return false; return false;
} }
bool CResourceManager::CreateDirectory(const std::string& directory) bool CResourceManager::CreateNewDirectory(const std::string& directory)
{ {
if (PHYSFS_isInit()) if (PHYSFS_isInit())
{ {
@ -165,7 +165,7 @@ bool CResourceManager::CreateDirectory(const std::string& directory)
return false; return false;
} }
bool CResourceManager::RemoveDirectory(const std::string& directory) bool CResourceManager::RemoveExistingDirectory(const std::string& directory)
{ {
if (PHYSFS_isInit()) if (PHYSFS_isInit())
{ {

View File

@ -57,9 +57,9 @@ public:
static bool DirectoryExists(const std::string& directory); static bool DirectoryExists(const std::string& directory);
//! Create directory in write 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 //! 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 //! List files contained in directory
static std::vector<std::string> ListFiles(const std::string &directory, bool excludeDirs = false); static std::vector<std::string> ListFiles(const std::string &directory, bool excludeDirs = false);

View File

@ -148,14 +148,14 @@ bool CPlayerProfile::Create()
{ {
if (!CResourceManager::DirectoryExists(GetSaveDir())) if (!CResourceManager::DirectoryExists(GetSaveDir()))
{ {
return CResourceManager::CreateDirectory(GetSaveDir()); return CResourceManager::CreateNewDirectory(GetSaveDir());
} }
return true; return true;
} }
bool CPlayerProfile::Delete() bool CPlayerProfile::Delete()
{ {
return CResourceManager::RemoveDirectory(GetSaveDir()); return CResourceManager::RemoveExistingDirectory(GetSaveDir());
} }
std::string CPlayerProfile::GetName() std::string CPlayerProfile::GetName()
@ -507,7 +507,7 @@ void CPlayerProfile::SaveScene(std::string dir, std::string info)
{ {
if (!CResourceManager::DirectoryExists(dir)) 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()); 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)) if (CResourceManager::DirectoryExists(dir))
{ {
return CResourceManager::RemoveDirectory(dir); return CResourceManager::RemoveExistingDirectory(dir);
} }
return false; return false;
} }

View File

@ -504,12 +504,12 @@ void CRobotMain::ChangePhase(Phase phase)
GetLogger()->Info("Trying to restore pre-crash state...\n"); GetLogger()->Info("Trying to restore pre-crash state...\n");
assert(m_playerProfile != nullptr); assert(m_playerProfile != nullptr);
m_playerProfile->LoadScene("../../crashsave"); m_playerProfile->LoadScene("../../crashsave");
CResourceManager::RemoveDirectory("crashsave"); CResourceManager::RemoveExistingDirectory("crashsave");
}, },
[&]() [&]()
{ {
GetLogger()->Info("Not restoring pre-crash state\n"); 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<std::string>()); std::sort(autosaves.begin(), autosaves.end(), std::less<std::string>());
for (int i = 0; i < static_cast<int>(autosaves.size()) - m_autosaveSlots + 1; i++) for (int i = 0; i < static_cast<int>(autosaves.size()) - m_autosaveSlots + 1; i++)
{ {
CResourceManager::RemoveDirectory(m_playerProfile->GetSaveDir() + "/" + autosaves[i]); CResourceManager::RemoveExistingDirectory(m_playerProfile->GetSaveDir() + "/" + autosaves[i]);
} }
} }

View File

@ -3400,7 +3400,7 @@ public:
private: private:
static std::string PrepareFilename(const std::string& filename) static std::string PrepareFilename(const std::string& filename)
{ {
CResourceManager::CreateDirectory("files"); CResourceManager::CreateNewDirectory("files");
return "files/" + filename; return "files/" + filename;
} }
}; };

View File

@ -1090,7 +1090,7 @@ std::string CFileDialog::SearchDirectory(bool bCreate)
if (bCreate && !CResourceManager::DirectoryExists(dir)) if (bCreate && !CResourceManager::DirectoryExists(dir))
{ {
CResourceManager::CreateDirectory(dir); CResourceManager::CreateNewDirectory(dir);
} }
if (!m_subDirPath.empty()) if (!m_subDirPath.empty())
@ -1098,7 +1098,7 @@ std::string CFileDialog::SearchDirectory(bool bCreate)
dir += "/" + m_subDirPath; dir += "/" + m_subDirPath;
if (bCreate && !CResourceManager::DirectoryExists(dir)) if (bCreate && !CResourceManager::DirectoryExists(dir))
{ {
CResourceManager::CreateDirectory(dir); CResourceManager::CreateNewDirectory(dir);
} }
} }