From 4709d202e134de2e602707b6a7eb4a663d083c76 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 4 Jun 2008 07:57:07 +0000 Subject: [PATCH] fixed unicode issue in storage --- include/libtorrent/config.hpp | 8 +++++++- src/storage.cpp | 30 ++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index dc9769840..1ee97bd57 100755 --- a/include/libtorrent/config.hpp +++ b/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/src/storage.cpp b/src/storage.cpp index bb9c49264..ae3b0a9cf 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -95,9 +95,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" @@ -260,7 +263,7 @@ namespace libtorrent { size_type size = 0; std::time_t time = 0; -#if defined(_WIN32) && defined(UNICODE) +#if TORRENT_USE_WPATH fs::wpath f = safe_convert((p / i->path).string()); #else fs::path f = p / i->path; @@ -310,7 +313,7 @@ namespace libtorrent size_type size = 0; std::time_t time = 0; -#if defined(_WIN32) && defined(UNICODE) +#if TORRENT_USE_WPATH fs::wpath f = safe_convert((p / i->path).string()); #else fs::path f = p / i->path; @@ -443,7 +446,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)) @@ -506,9 +509,9 @@ namespace libtorrent fs::path old_name = m_save_path / files().at(index).path; m_pool.release(old_name); -#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION >= 103400 - fs::wpath old_path = safe_convert(old_name); - fs::wpath new_path = safe_convert(m_save_path / new_filename); +#if TORRENT_USE_WPATH + fs::wpath old_path = safe_convert(old_name.string()); + fs::wpath new_path = safe_convert((m_save_path / new_filename).string()); #else fs::path const& old_path = old_name; fs::path new_path = m_save_path / new_filename; @@ -565,7 +568,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) @@ -590,7 +593,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) @@ -725,7 +728,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 @@ -741,7 +744,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); @@ -756,7 +759,7 @@ namespace libtorrent m_pool.release(this); -#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION >= 103400 +#if TORRENT_USE_WPATH old_path = safe_convert((m_save_path / files().name()).string()); new_path = safe_convert((save_path / files().name()).string()); #else @@ -770,7 +773,6 @@ namespace libtorrent #endif #if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 103400 rename_win(old_path, new_path); - rename(old_path, new_path); #else rename(old_path, new_path); #endif @@ -1648,7 +1650,7 @@ namespace libtorrent #endif #if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 103400 file_exists = exists_win(f); -#elif defined(_WIN32) && defined(UNICODE) +#elif TORRENT_USE_WPATH fs::wpath wf = safe_convert(f.string()); file_exists = exists(wf); #else