diff --git a/Core/Tools/FileSystemUtils.cpp b/Core/Tools/FileSystemUtils.cpp index 329a37483e87c3e6e819b3ebea1159d69d27cbe3..b160580d8e357a9edc1be73023bc062565367d49 100644 --- a/Core/Tools/FileSystemUtils.cpp +++ b/Core/Tools/FileSystemUtils.cpp @@ -18,6 +18,8 @@ #include <regex> #include <cassert> #include <stdexcept> +#include <codecvt> +#include <locale> std::string FileSystemUtils::extension(const std::string& path) { @@ -33,12 +35,22 @@ std::string FileSystemUtils::extensions(const std::string& path) bool FileSystemUtils::createDirectory(const std::string& dir_name) { +#ifdef _WIN32 + boost::filesystem::path path(convert_utf8_to_utf16(dir_name)); +#else + boost::filesystem::path path(dir_name); +#endif return boost::filesystem::create_directory(dir_name); } bool FileSystemUtils::createDirectories(const std::string& dir_name) { - return boost::filesystem::create_directories(dir_name); +#ifdef _WIN32 + boost::filesystem::path path(convert_utf8_to_utf16(dir_name)); +#else + boost::filesystem::path path(dir_name); +#endif + return boost::filesystem::create_directories(path); } std::vector<std::string> FileSystemUtils::filesInDirectory(const std::string& dir_name) @@ -94,3 +106,19 @@ std::string FileSystemUtils::stem_ext(const std::string& path) return npos != std::string::npos ? name.substr(0, npos) : std::string(); } + +std::wstring FileSystemUtils::convert_utf8_to_utf16(const std::string& str) +{ + std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; + return converter.from_bytes(str); +} + +bool FileSystemUtils::IsFileExists(const std::string& str) +{ +#ifdef _WIN32 + boost::filesystem::path path(convert_utf8_to_utf16(str)); +#else + boost::filesystem::path path(str); +#endif + return boost::filesystem::exists(path); +} diff --git a/Core/Tools/FileSystemUtils.h b/Core/Tools/FileSystemUtils.h index 5fa741dc20c637505d8cda0472b3ffee118dda00..ba238e4c5998412fbf7da66ba329778e5b0eda0a 100644 --- a/Core/Tools/FileSystemUtils.h +++ b/Core/Tools/FileSystemUtils.h @@ -57,6 +57,12 @@ BA_CORE_API_ std::string stem_ext(const std::string& path); //! Returns file names that agree with a regex glob pattern. BA_CORE_API_ std::vector<std::string> glob(const std::string& dir, const std::string& pattern); +//! Converts utf8 string represented by std::string to utf16 string represented by std::wstring. +BA_CORE_API_ std::wstring convert_utf8_to_utf16(const std::string& str); + +//! Returns true if file with given name exists on disk. +BA_CORE_API_ bool IsFileExists(const std::string& str); + } // namespace FileSystemUtils #endif // FILESYSTEMUTILS_H