Use std::wstring in boost::filesystem calls on Windows, fixes #414
parent
83599238d1
commit
47ed73247b
|
@ -35,6 +35,10 @@
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#ifdef PLATFORM_WINDOWS
|
||||||
|
#include "app/system_windows.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
template<> CPathManager* CSingleton<CPathManager>::m_instance = nullptr;
|
template<> CPathManager* CSingleton<CPathManager>::m_instance = nullptr;
|
||||||
|
|
||||||
CPathManager::CPathManager()
|
CPathManager::CPathManager()
|
||||||
|
@ -96,7 +100,11 @@ const std::string& CPathManager::GetSavePath()
|
||||||
|
|
||||||
std::string CPathManager::VerifyPaths()
|
std::string CPathManager::VerifyPaths()
|
||||||
{
|
{
|
||||||
|
#if PLATFORM_WINDOWS
|
||||||
|
boost::filesystem::path dataPath(CSystemUtilsWindows::UTF8_Decode(m_dataPath));
|
||||||
|
#else
|
||||||
boost::filesystem::path dataPath(m_dataPath);
|
boost::filesystem::path dataPath(m_dataPath);
|
||||||
|
#endif
|
||||||
if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
|
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());
|
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.");
|
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);
|
boost::filesystem::path langPath(m_langPath);
|
||||||
|
#endif
|
||||||
if (! (boost::filesystem::exists(langPath) && boost::filesystem::is_directory(langPath)) )
|
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());
|
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);
|
||||||
boost::filesystem::create_directories(m_savePath+"/mods");
|
boost::filesystem::create_directories(m_savePath+"/mods");
|
||||||
|
#endif
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -132,10 +149,18 @@ void CPathManager::InitPaths()
|
||||||
void CPathManager::LoadModsFromDir(const std::string &dir)
|
void CPathManager::LoadModsFromDir(const std::string &dir)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
#if PLATFORM_WINDOWS
|
||||||
|
boost::filesystem::directory_iterator iterator(CSystemUtilsWindows::UTF8_Decode(dir));
|
||||||
|
#else
|
||||||
boost::filesystem::directory_iterator iterator(dir);
|
boost::filesystem::directory_iterator iterator(dir);
|
||||||
|
#endif
|
||||||
for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
|
for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
|
||||||
{
|
{
|
||||||
|
#if PLATFORM_WINDOWS
|
||||||
|
AddMod(CSystemUtilsWindows::UTF8_Encode(iterator->path().wstring()));
|
||||||
|
#else
|
||||||
AddMod(iterator->path().string());
|
AddMod(iterator->path().string());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
|
#if PLATFORM_WINDOWS
|
||||||
|
#include "app/system_windows.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -183,7 +187,12 @@ bool CResourceManager::RemoveDirectory(const std::string& directory)
|
||||||
std::string writeDir = PHYSFS_getWriteDir();
|
std::string writeDir = PHYSFS_getWriteDir();
|
||||||
try
|
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)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
|
@ -267,7 +276,13 @@ bool CResourceManager::Move(const std::string& from, const std::string& to)
|
||||||
std::string writeDir = PHYSFS_getWriteDir();
|
std::string writeDir = PHYSFS_getWriteDir();
|
||||||
try
|
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)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
|
|
||||||
|
#include "common/config.h"
|
||||||
#include "common/pathman.h"
|
#include "common/pathman.h"
|
||||||
#include "common/resources/inputstream.h"
|
#include "common/resources/inputstream.h"
|
||||||
#include "common/resources/resourcemanager.h"
|
#include "common/resources/resourcemanager.h"
|
||||||
|
@ -49,6 +50,10 @@
|
||||||
|
|
||||||
#include "ui/displaytext.h"
|
#include "ui/displaytext.h"
|
||||||
|
|
||||||
|
#if PLATFORM_WINDOWS
|
||||||
|
#include "app/system_windows.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Compiling a procedure without any parameters.
|
// 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:
|
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);
|
boost::filesystem::create_directories(CScriptFunctions::m_filesDir);
|
||||||
|
#endif
|
||||||
filename = CBotString(CScriptFunctions::m_filesDir.c_str()) + CBotString("/") + filename;
|
filename = CBotString(CScriptFunctions::m_filesDir.c_str()) + CBotString("/") + filename;
|
||||||
CLogger::GetInstancePointer()->Debug("CBot accessing file '%s'\n", static_cast<const char*>(filename));
|
CLogger::GetInstancePointer()->Debug("CBot accessing file '%s'\n", static_cast<const char*>(filename));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue