From 49338fc5d70ceb91d23b91f0afec88e6af5f3c89 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Wed, 4 Jun 2008 19:51:30 +0000 Subject: [PATCH] lt unicode fix in storage --- libtorrent/include/libtorrent/config.hpp | 8 +++++++- libtorrent/src/storage.cpp | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/libtorrent/include/libtorrent/config.hpp b/libtorrent/include/libtorrent/config.hpp index dc9769840..1ee97bd57 100755 --- a/libtorrent/include/libtorrent/config.hpp +++ b/libtorrent/include/libtorrent/config.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_CONFIG_HPP_INCLUDED #include +#include #if defined(__GNUC__) && __GNUC__ >= 4 @@ -81,7 +82,12 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_BSD #endif - +// should wpath or path be used? +#if defined UNICODE && !defined BOOST_FILESYSTEM_NARROW_ONLY && BOOST_VERSION >= 103400 +#define TORRENT_USE_WPATH 1 +#else +#define TORRENT_USE_WPATH 0 +#endif #endif // TORRENT_CONFIG_HPP_INCLUDED diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 8abaea813..a0fa62b5a 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -94,9 +94,12 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if defined(_WIN32) && defined(UNICODE) +#if TORRENT_USE_WPATH +#ifdef BOOST_WINDOWS #include +#endif + #include #include "libtorrent/utf8.hpp" #include "libtorrent/buffer.hpp" @@ -265,7 +268,7 @@ namespace libtorrent fs::path f = p / i->path; size = file_size_win(f); time = last_write_time_win(f); -#elif defined(_WIN32) && defined(UNICODE) +#elif TORRENT_USE_WPATH fs::wpath f = safe_convert((p / i->path).string()); size = file_size(f); time = last_write_time(f); @@ -314,7 +317,7 @@ namespace libtorrent fs::path f = p / i->path; size = file_size_win(f); time = last_write_time_win(f); -#elif defined(_WIN32) && defined(UNICODE) +#elif TORRENT_USE_WPATH fs::wpath f = safe_convert((p / i->path).string()); size = file_size(f); time = last_write_time(f); @@ -436,7 +439,7 @@ namespace libtorrent last_path = dir; if (!exists_win(last_path)) create_directories_win(last_path); -#elif defined(_WIN32) && defined(UNICODE) +#elif TORRENT_USE_WPATH last_path = dir; fs::wpath wp = safe_convert(last_path.string()); if (!exists(wp)) @@ -499,7 +502,7 @@ namespace libtorrent std::pair ret = directories.insert((m_save_path / bp).string()); bp = bp.branch_path(); } -#if defined(_WIN32) && defined(UNICODE) +#if TORRENT_USE_WPATH try { fs::remove(safe_convert(p)); } catch (std::exception& e) @@ -516,7 +519,7 @@ namespace libtorrent for (std::set::reverse_iterator i = directories.rbegin() , end(directories.rend()); i != end; ++i) { -#if defined(_WIN32) && defined(UNICODE) +#if TORRENT_USE_WPATH try { fs::remove(safe_convert(*i)); } catch (std::exception& e) @@ -614,7 +617,7 @@ namespace libtorrent // returns true on success bool storage::move_storage(fs::path save_path) { -#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION >= 103400 +#if TORRENT_USE_WPATH fs::wpath old_path; fs::wpath new_path; #else @@ -630,7 +633,7 @@ namespace libtorrent CreateDirectory(wsave_path.c_str(), 0); else if ((GetFileAttributes(wsave_path.c_str()) & FILE_ATTRIBUTE_DIRECTORY) == 0) return false; -#elif defined(_WIN32) && defined(UNICODE) +#elif TORRENT_USE_WPATH fs::wpath wp = safe_convert(save_path.string()); if (!exists(wp)) create_directory(wp); @@ -645,7 +648,7 @@ namespace libtorrent m_files.release(this); -#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION >= 103400 +#if TORRENT_USE_WPATH old_path = safe_convert((m_save_path / m_info->name()).string()); new_path = safe_convert((save_path / m_info->name()).string()); #else