[colobot] 283/390: Use std::wstring in boost::filesystem calls on Windows, fixes #414
Didier Raboud
odyx at moszumanska.debian.org
Fri Jun 12 14:21:55 UTC 2015
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch upstream/latest
in repository colobot.
commit 47ed73247bed29f31720ef795141328b5d810d0e
Author: krzys-h <krzys_h at interia.pl>
Date: Sun Mar 22 13:34:17 2015 +0100
Use std::wstring in boost::filesystem calls on Windows, fixes #414
---
src/common/pathman.cpp | 25 +++++++++++++++++++++++++
src/common/resources/resourcemanager.cpp | 19 +++++++++++++++++--
src/script/scriptfunc.cpp | 9 +++++++++
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/src/common/pathman.cpp b/src/common/pathman.cpp
index ccf61ab..51e7e7d 100644
--- a/src/common/pathman.cpp
+++ b/src/common/pathman.cpp
@@ -35,6 +35,10 @@
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
+#ifdef PLATFORM_WINDOWS
+ #include "app/system_windows.h"
+#endif
+
template<> CPathManager* CSingleton<CPathManager>::m_instance = nullptr;
CPathManager::CPathManager()
@@ -96,7 +100,11 @@ const std::string& CPathManager::GetSavePath()
std::string CPathManager::VerifyPaths()
{
+ #if PLATFORM_WINDOWS
+ boost::filesystem::path dataPath(CSystemUtilsWindows::UTF8_Decode(m_dataPath));
+ #else
boost::filesystem::path dataPath(m_dataPath);
+ #endif
if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
{
CLogger::GetInstancePointer()->Error("Data directory '%s' doesn't exist or is not a directory\n", m_dataPath.c_str());
@@ -105,14 +113,23 @@ std::string CPathManager::VerifyPaths()
std::string("Please check your installation, or supply a valid data directory by -datadir option.");
}
+ #if PLATFORM_WINDOWS
+ boost::filesystem::path langPath(CSystemUtilsWindows::UTF8_Decode(m_langPath));
+ #else
boost::filesystem::path langPath(m_langPath);
+ #endif
if (! (boost::filesystem::exists(langPath) && boost::filesystem::is_directory(langPath)) )
{
CLogger::GetInstancePointer()->Warn("Language path '%s' is invalid, assuming translation files not installed\n", m_langPath.c_str());
}
+ #if PLATFORM_WINDOWS
+ boost::filesystem::create_directories(CSystemUtilsWindows::UTF8_Decode(m_savePath));
+ boost::filesystem::create_directories(CSystemUtilsWindows::UTF8_Decode(m_savePath+"/mods"));
+ #else
boost::filesystem::create_directories(m_savePath);
boost::filesystem::create_directories(m_savePath+"/mods");
+ #endif
return "";
}
@@ -132,10 +149,18 @@ void CPathManager::InitPaths()
void CPathManager::LoadModsFromDir(const std::string &dir)
{
try {
+ #if PLATFORM_WINDOWS
+ boost::filesystem::directory_iterator iterator(CSystemUtilsWindows::UTF8_Decode(dir));
+ #else
boost::filesystem::directory_iterator iterator(dir);
+ #endif
for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
{
+ #if PLATFORM_WINDOWS
+ AddMod(CSystemUtilsWindows::UTF8_Encode(iterator->path().wstring()));
+ #else
AddMod(iterator->path().string());
+ #endif
}
}
catch(std::exception &e)
diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp
index 64cb4ee..6f9ae24 100644
--- a/src/common/resources/resourcemanager.cpp
+++ b/src/common/resources/resourcemanager.cpp
@@ -28,6 +28,10 @@
#include <boost/filesystem.hpp>
#include <boost/regex.hpp>
+#if PLATFORM_WINDOWS
+ #include "app/system_windows.h"
+#endif
+
namespace fs = boost::filesystem;
namespace
@@ -183,7 +187,12 @@ bool CResourceManager::RemoveDirectory(const std::string& directory)
std::string writeDir = PHYSFS_getWriteDir();
try
{
- fs::remove_all(writeDir + "/" + CleanPath(directory));
+ std::string path = writeDir + "/" + CleanPath(directory);
+ #ifdef PLATFORM_WINDOWS
+ fs::remove_all(CSystemUtilsWindows::UTF8_Decode(path));
+ #else
+ fs::remove_all(path);
+ #endif
}
catch (std::exception & e)
{
@@ -267,7 +276,13 @@ bool CResourceManager::Move(const std::string& from, const std::string& to)
std::string writeDir = PHYSFS_getWriteDir();
try
{
- fs::rename(writeDir + "/" + CleanPath(from), writeDir + "/" + CleanPath(to));
+ std::string path_from = writeDir + "/" + CleanPath(from);
+ std::string path_to = writeDir + "/" + CleanPath(to);
+ #ifdef PLATFORM_WINDOWS
+ fs::rename(CSystemUtilsWindows::UTF8_Decode(path_from), CSystemUtilsWindows::UTF8_Decode(path_to));
+ #else
+ fs::rename(path_from, path_to);
+ #endif
}
catch (std::exception & e)
{
diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp
index 3fd3add..3416343 100644
--- a/src/script/scriptfunc.cpp
+++ b/src/script/scriptfunc.cpp
@@ -22,6 +22,7 @@
#include "app/app.h"
+#include "common/config.h"
#include "common/pathman.h"
#include "common/resources/inputstream.h"
#include "common/resources/resourcemanager.h"
@@ -49,6 +50,10 @@
#include "ui/displaytext.h"
+#if PLATFORM_WINDOWS
+ #include "app/system_windows.h"
+#endif
+
// Compiling a procedure without any parameters.
@@ -3245,7 +3250,11 @@ void PrepareFilename(CBotString &filename)
filename = filename.Mid(pos+1); // also removes the drive letter C:
}
+ #if PLATFORM_WINDOWS
+ boost::filesystem::create_directories(CSystemUtilsWindows::UTF8_Decode(CScriptFunctions::m_filesDir));
+ #else
boost::filesystem::create_directories(CScriptFunctions::m_filesDir);
+ #endif
filename = CBotString(CScriptFunctions::m_filesDir.c_str()) + CBotString("/") + filename;
CLogger::GetInstancePointer()->Debug("CBot accessing file '%s'\n", static_cast<const char*>(filename));
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list