Use std::wstring in boost::filesystem calls on Windows, fixes #414

master
krzys-h 2015-03-22 13:34:17 +01:00
parent 83599238d1
commit 47ed73247b
3 changed files with 51 additions and 2 deletions

View File

@ -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)

View File

@ -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)
{

View File

@ -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));
}