diff --git a/ChangeLog b/ChangeLog index 5e67e1e34..339324e10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * drop support for windows compilers without std::wstring * implemented support for DHT infohash indexing, BEP51 * removed deprecated support for file_base in file_storage * added support for running separate DHT nodes on each network interface diff --git a/Jamfile b/Jamfile index 92b6581ed..d5ded1abf 100644 --- a/Jamfile +++ b/Jamfile @@ -465,9 +465,6 @@ feature.compose libgcrypt : TORRENT_USE_LIBGCRYPT ; feature ssl : off openssl : composite propagated ; feature.compose openssl : TORRENT_USE_OPENSSL OPENSSL_NO_SSL2 ; -feature character-set : unicode ansi : composite propagated link-incompatible ; -feature.compose unicode : _UNICODE UNICODE ; - feature deprecated-functions : on off : composite propagated link-incompatible ; feature.compose off : TORRENT_NO_DEPRECATE ; @@ -751,6 +748,8 @@ lib torrent shared:TORRENT_BUILDING_SHARED BOOST_NO_DEPRECATED shared:BOOST_SYSTEM_SOURCE + windows:UNICODE + windows:_UNICODE on:src/kademlia/$(KADEMLIA_SOURCES).cpp on:ed25519/src/$(ED25519_SOURCES).cpp diff --git a/bindings/python/src/create_torrent.cpp b/bindings/python/src/create_torrent.cpp index 7358f311f..b35f67b2f 100644 --- a/bindings/python/src/create_torrent.cpp +++ b/bindings/python/src/create_torrent.cpp @@ -101,13 +101,11 @@ namespace FileIter end_files(file_storage const& self) { return FileIter(self, self.end_file()); } -#if TORRENT_USE_WSTRING void add_file_wstring(file_storage& fs, std::wstring const& file, std::int64_t size , int flags, std::time_t md, std::string link) { fs.add_file(file, size, flags, md, link); } -#endif // TORRENT_USE_WSTRING #endif // TORRENT_NO_DEPRECATE void add_files_callback(file_storage& fs, std::string const& file @@ -132,7 +130,7 @@ void bind_create_torrent() { void (file_storage::*set_name0)(std::string const&) = &file_storage::set_name; void (file_storage::*rename_file0)(file_index_t, std::string const&) = &file_storage::rename_file; -#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE +#if !defined TORRENT_NO_DEPRECATE void (file_storage::*set_name1)(std::wstring const&) = &file_storage::set_name; void (file_storage::*rename_file1)(file_index_t, std::wstring const&) = &file_storage::rename_file; #endif @@ -163,9 +161,7 @@ void bind_create_torrent() .def("add_file", add_file_deprecated, arg("entry")) .def("__iter__", boost::python::range(&begin_files, &end_files)) .def("__len__", &file_storage::num_files) -#if TORRENT_USE_WSTRING .def("add_file", add_file_wstring, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = "")) -#endif #endif // TORRENT_NO_DEPRECATE .def("hash", file_storage_hash) .def("symlink", file_storage_symlink, return_value_policy()) @@ -182,7 +178,7 @@ void bind_create_torrent() .def("piece_size", &file_storage::piece_size) .def("set_name", set_name0) .def("rename_file", rename_file0) -#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE +#if !defined TORRENT_NO_DEPRECATE .def("set_name", set_name1) .def("rename_file", rename_file1) #endif diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 34613cd24..bc8022656 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -444,7 +444,7 @@ void bind_torrent_handle() void (torrent_handle::*move_storage0)(std::string const&, lt::move_flags_t) const = &torrent_handle::move_storage; void (torrent_handle::*rename_file0)(file_index_t, std::string const&) const = &torrent_handle::rename_file; -#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE +#if !defined TORRENT_NO_DEPRECATE void (torrent_handle::*move_storage1)(std::wstring const&, int) const = &torrent_handle::move_storage; void (torrent_handle::*rename_file1)(file_index_t, std::wstring const&) const = &torrent_handle::rename_file; #endif @@ -567,7 +567,7 @@ void bind_torrent_handle() .def("force_recheck", _(&torrent_handle::force_recheck)) .def("rename_file", _(rename_file0)) .def("set_ssl_certificate", &torrent_handle::set_ssl_certificate, (arg("cert"), arg("private_key"), arg("dh_params"), arg("passphrase")="")) -#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE +#if !defined TORRENT_NO_DEPRECATE .def("move_storage", _(move_storage1), (arg("path"), arg("flags") = always_replace_files)) .def("rename_file", _(rename_file1)) #endif diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index 80cf6b4f8..598cdb3c3 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -241,7 +241,7 @@ void bind_torrent_info() return_value_policy copy; void (torrent_info::*rename_file0)(file_index_t, std::string const&) = &torrent_info::rename_file; -#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE +#if !defined TORRENT_NO_DEPRECATE void (torrent_info::*rename_file1)(file_index_t, std::wstring const&) = &torrent_info::rename_file; #endif @@ -261,7 +261,7 @@ void bind_torrent_info() .def("__init__", make_constructor(&file_constructor1)) .def(init((arg("ti")))) -#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE +#if !defined TORRENT_NO_DEPRECATE .def(init((arg("file"), arg("flags") = 0))) #endif @@ -294,9 +294,7 @@ void bind_torrent_info() #ifndef TORRENT_NO_DEPRECATE .def("file_at", &torrent_info::file_at) .def("file_at_offset", &torrent_info::file_at_offset) -#if TORRENT_USE_WSTRING .def("rename_file", rename_file1) -#endif // TORRENT_USE_WSTRING #endif // TORRENT_NO_DEPRECATE .def("is_valid", &torrent_info::is_valid) diff --git a/docs/building.rst b/docs/building.rst index e93446efc..c1d20e794 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -316,14 +316,6 @@ Build features: | | * ``profile`` - builds libtorrent with profile | | | information. | +--------------------------+----------------------------------------------------+ -| ``character-set`` | This setting will only have an affect on windows. | -| | Other platforms are expected to support UTF-8. | -| | | -| | * ``unicode`` - The unicode version of the win32 | -| | API is used. This is default. | -| | * ``ansi`` - The ansi version of the win32 API is | -| | used. | -+--------------------------+----------------------------------------------------+ | ``invariant-checks`` | This setting only affects debug builds (where | | | ``NDEBUG`` is not defined). It defaults to ``on``. | | | | @@ -534,11 +526,6 @@ defines you can use to control the build. | | checks in the storage, including logging of | | | piece sorting. | +----------------------------------------+-------------------------------------------------+ -| ``UNICODE`` | If building on windows this will make sure the | -| | UTF-8 strings in pathnames are converted into | -| | UTF-16 before they are passed to the file | -| | operations. | -+----------------------------------------+-------------------------------------------------+ | ``TORRENT_DISABLE_POOL_ALLOCATOR`` | Disables use of ``boost::pool<>``. | +----------------------------------------+-------------------------------------------------+ | ``TORRENT_DISABLE_MUTABLE_TORRENTS`` | Disables mutable torrent support (`BEP 38`_) | @@ -576,10 +563,6 @@ defines you can use to control the build. | | disabled along with support for the extension | | | handskake (BEP 10). | +----------------------------------------+-------------------------------------------------+ -| ``_UNICODE`` | On windows, this will cause the file IO | -| | use wide character API, to properly support | -| | non-ansi characters. | -+----------------------------------------+-------------------------------------------------+ | ``TORRENT_USE_INVARIANT_CHECKS`` | If defined to non-zero, this will enable | | | internal invariant checks in libtorrent. | | | The invariant checks can sometimes | diff --git a/include/libtorrent/aux_/escape_string.hpp b/include/libtorrent/aux_/escape_string.hpp index 83e772df1..0b73d423a 100644 --- a/include/libtorrent/aux_/escape_string.hpp +++ b/include/libtorrent/aux_/escape_string.hpp @@ -96,7 +96,7 @@ namespace libtorrent { TORRENT_EXTRA_EXPORT std::string read_until(char const*& str, char delim , char const* end); -#if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING +#if defined TORRENT_WINDOWS TORRENT_EXTRA_EXPORT std::wstring convert_to_wstring(std::string const& s); TORRENT_EXTRA_EXPORT std::string convert_from_wstring(std::wstring const& s); #endif diff --git a/include/libtorrent/aux_/path.hpp b/include/libtorrent/aux_/path.hpp index f301364db..3277c0f29 100644 --- a/include/libtorrent/aux_/path.hpp +++ b/include/libtorrent/aux_/path.hpp @@ -172,7 +172,7 @@ namespace libtorrent { // internal type alias export should be used at unit tests only using native_path_string = -#if TORRENT_USE_WSTRING && defined TORRENT_WINDOWS +#if defined TORRENT_WINDOWS std::wstring; #else std::string; @@ -181,12 +181,12 @@ namespace libtorrent { // internal export should be used at unit tests only TORRENT_EXTRA_EXPORT native_path_string convert_to_native_path_string(std::string const& path); -// internal export should be used at unit tests only - TORRENT_EXTRA_EXPORT std::string convert_from_native_path(char const* s); - -#if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING +#if defined TORRENT_WINDOWS // internal export should be used at unit tests only TORRENT_EXTRA_EXPORT std::string convert_from_native_path(wchar_t const* s); +#else +// internal export should be used at unit tests only + TORRENT_EXTRA_EXPORT std::string convert_from_native_path(char const* s); #endif TORRENT_EXTRA_EXPORT int bufs_size(span bufs); diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 30c7d378c..390320a17 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -414,13 +414,9 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_USE_LOCALE 0 #endif -#ifndef TORRENT_USE_WSTRING -#if !defined BOOST_NO_STD_WSTRING -#define TORRENT_USE_WSTRING 1 -#else -#define TORRENT_USE_WSTRING 0 -#endif // BOOST_NO_STD_WSTRING -#endif // TORRENT_USE_WSTRING +#if defined BOOST_NO_STD_WSTRING +#error your C++ standard library appears to be missing std::wstring. This type is required on windows +#endif #ifndef TORRENT_HAS_FALLOCATE #define TORRENT_HAS_FALLOCATE 1 diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index 64cae822f..3fab4d463 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -423,9 +423,6 @@ namespace detail { } #endif -#if TORRENT_USE_WSTRING - // wstring versions - // all wstring APIs are deprecated since 0.16.11 // instead, use the wchar -> utf8 conversion functions // and pass in utf8 strings @@ -473,7 +470,6 @@ namespace detail { set_piece_hashes_deprecated(t, p, detail::nop, ec); } #endif // TORRENT_NO_DEPRECATE -#endif // TORRENT_USE_WSTRING } diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index c8fb2b9e9..f223700e6 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -106,11 +106,7 @@ namespace libtorrent { #ifdef TORRENT_WINDOWS HANDLE m_handle; int m_inode; -#if TORRENT_USE_WSTRING WIN32_FIND_DATAW m_fd; -#else - WIN32_FIND_DATAA m_fd; -#endif #else DIR* m_handle; // the dirent struct contains a zero-sized diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index be5f917c8..1df95dfa5 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -291,7 +291,6 @@ namespace libtorrent { TORRENT_DEPRECATED void add_file(file_entry const& fe, char const* filehash = nullptr); -#if TORRENT_USE_WSTRING // all wstring APIs are deprecated since 0.16.11 // instead, use the wchar -> utf8 conversion functions // and pass in utf8 strings @@ -304,7 +303,6 @@ namespace libtorrent { void set_name(std::wstring const& n); void rename_file_deprecated(file_index_t index, std::wstring const& new_filename); -#endif // TORRENT_USE_WSTRING #endif // TORRENT_NO_DEPRECATE // returns a list of file_slice objects representing the portions of diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index ef105ec54..ea718d2b8 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -539,7 +539,6 @@ namespace libtorrent { void load_country_db(char const* file); TORRENT_DEPRECATED int as_for_ip(address const& addr); -#if TORRENT_USE_WSTRING // all wstring APIs are deprecated since 0.16.11 // instead, use the wchar -> utf8 conversion functions // and pass in utf8 strings @@ -547,7 +546,6 @@ namespace libtorrent { void load_country_db(wchar_t const* file); TORRENT_DEPRECATED void load_asnum_db(wchar_t const* file); -#endif // TORRENT_USE_WSTRING // deprecated in 0.15 // use load_state and save_state instead diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 0d99d380f..d3f4944d1 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -1254,7 +1254,6 @@ namespace libtorrent { namespace aux { void rename_file(file_index_t index, std::string const& new_name) const; #ifndef TORRENT_NO_DEPRECATE -#if TORRENT_USE_WSTRING // all wstring APIs are deprecated since 0.16.11 // instead, use the wchar -> utf8 conversion functions // and pass in utf8 strings @@ -1262,7 +1261,6 @@ namespace libtorrent { namespace aux { void move_storage(std::wstring const& save_path, int flags = 0) const; TORRENT_DEPRECATED void rename_file(file_index_t index, std::wstring const& new_name) const; -#endif // TORRENT_USE_WSTRING #endif // TORRENT_NO_DEPRECATE // Enables or disabled super seeding/initial seeding for this torrent. diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 11ca53f46..bc2366f1a 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -163,7 +163,6 @@ namespace libtorrent { TORRENT_DEPRECATED torrent_info(lazy_entry const& torrent_file, error_code& ec , int flags = 0); -#if TORRENT_USE_WSTRING // all wstring APIs are deprecated since 0.16.11 instead, use the wchar // -> utf8 conversion functions and pass in utf8 strings TORRENT_DEPRECATED @@ -171,7 +170,6 @@ namespace libtorrent { , int flags = 0); TORRENT_DEPRECATED explicit torrent_info(std::wstring const& filename, int flags = 0); -#endif // TORRENT_USE_WSTRING #endif // TORRENT_NO_DEPRECATE // frees all storage associated with this torrent_info object @@ -220,13 +218,11 @@ namespace libtorrent { m_files.rename_file(index, new_filename); } #ifndef TORRENT_NO_DEPRECATE -#if TORRENT_USE_WSTRING // all wstring APIs are deprecated since 0.16.11 // instead, use the wchar -> utf8 conversion functions // and pass in utf8 strings TORRENT_DEPRECATED void rename_file(file_index_t index, std::wstring const& new_filename); -#endif // TORRENT_USE_WSTRING #endif // TORRENT_NO_DEPRECATE // Remaps the file storage to a new file layout. This can be used to, for diff --git a/include/libtorrent/utf8.hpp b/include/libtorrent/utf8.hpp index e0cbdecee..ef783a970 100644 --- a/include/libtorrent/utf8.hpp +++ b/include/libtorrent/utf8.hpp @@ -35,10 +35,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/export.hpp" -// on windows we need these functions for -// convert_to_native and convert_from_native -#if TORRENT_USE_WSTRING || defined TORRENT_WINDOWS - #include #include #include @@ -84,6 +80,5 @@ namespace libtorrent { TORRENT_EXTRA_EXPORT std::pair parse_utf8_codepoint(char const* str, int len); } -#endif // !BOOST_NO_STD_WSTRING #endif diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index b4752b767..4fb0b14f8 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -62,13 +62,8 @@ namespace libtorrent { { #ifdef TORRENT_WINDOWS WIN32_FILE_ATTRIBUTE_DATA attr; -#if TORRENT_USE_WSTRING std::wstring path = convert_to_wstring(p); GetFileAttributesExW(path.c_str(), GetFileExInfoStandard, &attr); -#else - std::string path = convert_to_native(p); - GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &attr); -#endif // TORRENT_USE_WSTRING if (attr.dwFileAttributes == INVALID_FILE_ATTRIBUTES) return 0; if (attr.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) return file_storage::attribute_hidden; return 0; @@ -198,7 +193,6 @@ namespace libtorrent { } // anonymous namespace -#if TORRENT_USE_WSTRING #ifndef TORRENT_NO_DEPRECATE void add_files(file_storage& fs, std::wstring const& wfile @@ -231,7 +225,6 @@ namespace libtorrent { set_piece_hashes(t, utf8, f, ec); } #endif // TORRENT_NO_DEPRECATE -#endif // TORRENT_USE_WSTRING void add_files(file_storage& fs, std::string const& file , std::function p, std::uint32_t flags) diff --git a/src/escape_string.cpp b/src/escape_string.cpp index 62a973b13..a096fd00a 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -499,7 +499,7 @@ namespace libtorrent { return url.substr(pos, find(url, "&", pos) - pos); } -#if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING +#if defined TORRENT_WINDOWS std::wstring convert_to_wstring(std::string const& s) { error_code ec; diff --git a/src/file.cpp b/src/file.cpp index 2947c843a..b2d669c28 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -326,16 +326,6 @@ done: # endif #endif -#if defined TORRENT_WINDOWS && defined UNICODE && !TORRENT_USE_WSTRING - -#ifdef _MSC_VER -#pragma message ( "wide character support not available. Files will be saved using narrow string names" ) -#else -#warning "wide character support not available. Files will be saved using narrow string names" -#endif - -#endif // TORRENT_WINDOWS - namespace libtorrent { static_assert((open_mode_t::rw_mask & open_mode_t::sparse) == open_mode_t::none, "internal flags error"); @@ -364,19 +354,13 @@ static_assert((open_mode_t::sparse & open_mode_t::attribute_mask) == open_mode_t #ifdef TORRENT_WINDOWS m_inode = 0; -#if TORRENT_USE_WSTRING -#define FindFirstFile_ FindFirstFileW -#else -#define FindFirstFile_ FindFirstFileA -#endif - m_handle = FindFirstFile_(f.c_str(), &m_fd); + m_handle = FindFirstFileW(f.c_str(), &m_fd); if (m_handle == INVALID_HANDLE_VALUE) { ec.assign(GetLastError(), system_category()); m_done = true; return; } -#undef FindFirstFile_ #else std::memset(&m_dirent, 0, sizeof(dirent)); @@ -426,19 +410,13 @@ static_assert((open_mode_t::sparse & open_mode_t::attribute_mask) == open_mode_t { ec.clear(); #ifdef TORRENT_WINDOWS -#if TORRENT_USE_WSTRING -#define FindNextFile_ FindNextFileW -#else -#define FindNextFile_ FindNextFileA -#endif - if (FindNextFile_(m_handle, &m_fd) == 0) + if (FindNextFileW(m_handle, &m_fd) == 0) { m_done = true; int err = GetLastError(); if (err != ERROR_NO_MORE_FILES) ec.assign(err, system_category()); } -#undef FindNextFile_ ++m_inode; #else dirent* dummy; @@ -552,12 +530,6 @@ static_assert((open_mode_t::sparse & open_mode_t::attribute_mask) == open_mode_t FILE_ATTRIBUTE_HIDDEN, // hidden + executable }}; -#if TORRENT_USE_WSTRING -#define CreateFile_ CreateFileW -#else -#define CreateFile_ CreateFileA -#endif - TORRENT_ASSERT(static_cast(mode & open_mode_t::rw_mask) < mode_array.size()); win_open_mode_t const& m = mode_array[static_cast(mode & open_mode_t::rw_mask)]; DWORD a = attrib_array[static_cast(mode & open_mode_t::attribute_mask) >> 12]; @@ -571,12 +543,10 @@ static_assert((open_mode_t::sparse & open_mode_t::attribute_mask) == open_mode_t | FILE_FLAG_OVERLAPPED | (test(mode & open_mode_t::no_cache) ? FILE_FLAG_WRITE_THROUGH : 0); - handle_type handle = CreateFile_(file_path.c_str(), m.rw_mode + handle_type handle = CreateFileW(file_path.c_str(), m.rw_mode , test(mode & open_mode_t::lock_file) ? FILE_SHARE_READ : FILE_SHARE_READ | FILE_SHARE_WRITE , 0, m.create_mode, flags, 0); -#undef CreateFile_ - if (handle == INVALID_HANDLE_VALUE) { ec.assign(GetLastError(), system_category()); diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 560e6f2f4..f7804a192 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -347,7 +347,6 @@ namespace { , fe.symlink_path); } -#if TORRENT_USE_WSTRING void file_storage::set_name(std::wstring const& n) { m_name = wchar_utf8(n); @@ -369,7 +368,6 @@ namespace { { rename_file_deprecated(index, new_filename); } -#endif // TORRENT_USE_WSTRING #endif // TORRENT_NO_DEPRECATE void file_storage::rename_file(file_index_t const index diff --git a/src/path.cpp b/src/path.cpp index 2d785c0aa..f37313302 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -134,10 +134,10 @@ namespace libtorrent { return int(size); } - std::string convert_from_native_path(char const* s) { return convert_from_native(s); } - -#if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING +#if defined TORRENT_WINDOWS std::string convert_from_native_path(wchar_t const* s) { return convert_from_wstring(s); } +#else + std::string convert_from_native_path(char const* s) { return convert_from_native(s); } #endif template @@ -170,20 +170,16 @@ namespace libtorrent { prepared_path = path; else { - std::string sep_path { path }; + std::string sep_path = path; std::replace(sep_path.begin(), sep_path.end(), '/', '\\'); - prepared_path = "\\\\?\\" + (is_complete(sep_path) ? sep_path : combine_path(current_working_directory(), sep_path)); + prepared_path = "\\\\?\\" + (is_complete(sep_path) ? sep_path : complete(sep_path)); } #else - std::string prepared_path { path }; + std::string prepared_path = path; std::replace(prepared_path.begin(), prepared_path.end(), '/', '\\'); #endif -#if TORRENT_USE_WSTRING return convert_to_wstring(prepared_path); -#else - return convert_to_native(prepared_path); -#endif #else // TORRENT_WINDOWS return convert_to_native(path); #endif @@ -198,16 +194,9 @@ namespace libtorrent { TORRENT_UNUSED(flags); -#if TORRENT_USE_WSTRING -#define CreateFile_ CreateFileW -#else -#define CreateFile_ CreateFileA -#endif - // in order to open a directory, we need the FILE_FLAG_BACKUP_SEMANTICS - HANDLE h = CreateFile_(f.c_str(), 0, FILE_SHARE_DELETE | FILE_SHARE_READ + HANDLE h = CreateFileW(f.c_str(), 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); -#undef CreateFile_ if (h == INVALID_HANDLE_VALUE) { ec.assign(GetLastError(), system_category()); @@ -273,8 +262,8 @@ namespace libtorrent { native_path_string f1 = convert_to_native_path_string(inf); native_path_string f2 = convert_to_native_path_string(newf); -#if TORRENT_USE_WSTRING && defined TORRENT_WINDOWS -#define RenameFunction_ _wrename +#if defined TORRENT_WINDOWS +#define RenameFunction_ ::_wrename #else #define RenameFunction_ ::rename #endif @@ -308,16 +297,9 @@ namespace libtorrent { native_path_string n = convert_to_native_path_string(f); #ifdef TORRENT_WINDOWS -#if TORRENT_USE_WSTRING -#define CreateDirectory_ CreateDirectoryW -#else -#define CreateDirectory_ CreateDirectoryA -#endif // TORRENT_USE_WSTRING - - if (CreateDirectory_(n.c_str(), 0) == 0 + if (CreateDirectoryW(n.c_str(), 0) == 0 && GetLastError() != ERROR_ALREADY_EXISTS) ec.assign(GetLastError(), system_category()); -#undef CreateDirectory_ #else int ret = ::mkdir(n.c_str(), 0777); if (ret < 0 && errno != EEXIST) @@ -332,18 +314,12 @@ namespace libtorrent { native_path_string n_link = convert_to_native_path_string(link); #ifdef TORRENT_WINDOWS -#if TORRENT_USE_WSTRING -#define CreateHardLink_ CreateHardLinkW -#else -#define CreateHardLink_ CreateHardLinkA -#endif - BOOL ret = CreateHardLink_(n_link.c_str(), n_exist.c_str(), nullptr); + BOOL ret = CreateHardLinkW(n_link.c_str(), n_exist.c_str(), nullptr); if (ret) { ec.clear(); return; } -#undef CreateHardLink_ // something failed. Does the filesystem not support hard links? // TODO: 3 find out what error code is reported when the filesystem // does not support hard links. @@ -425,15 +401,9 @@ namespace libtorrent { native_path_string f2 = convert_to_native_path_string(newf); #ifdef TORRENT_WINDOWS -#if TORRENT_USE_WSTRING -#define CopyFile_ CopyFileW -#else -#define CopyFile_ CopyFileA -#endif - if (CopyFile_(f1.c_str(), f2.c_str(), false) == 0) + if (CopyFileW(f1.c_str(), f2.c_str(), false) == 0) ec.assign(GetLastError(), system_category()); -#undef CopyFile_ #elif defined __APPLE__ && defined __MACH__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 // this only works on 10.5 @@ -756,12 +726,8 @@ namespace libtorrent { std::string current_working_directory() { #if defined TORRENT_WINDOWS -#if TORRENT_USE_WSTRING #define GetCurrentDir_ ::_wgetcwd #else -#define GetCurrentDir_ ::_getcwd -#endif // TORRENT_USE_WSTRING -#else #define GetCurrentDir_ ::getcwd #endif auto cwd = GetCurrentDir_(nullptr, 0); @@ -875,25 +841,17 @@ namespace libtorrent { f.back() == '/' || f.back() == '\\' )) f.pop_back(); -#if TORRENT_USE_WSTRING -#define DeleteFile_ DeleteFileW -#define RemoveDirectory_ RemoveDirectoryW -#else -#define DeleteFile_ DeleteFileA -#define RemoveDirectory_ RemoveDirectoryA -#endif - if (DeleteFile_(f.c_str()) == 0) + + if (DeleteFileW(f.c_str()) == 0) { if (GetLastError() == ERROR_ACCESS_DENIED) { - if (RemoveDirectory_(f.c_str()) != 0) + if (RemoveDirectoryW(f.c_str()) != 0) return; } ec.assign(GetLastError(), system_category()); return; } -#undef DeleteFile_ -#undef RemoveDirectory_ #else // TORRENT_WINDOWS if (::remove(f.c_str()) < 0) { diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 6452ac09c..6b498dba1 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -697,10 +697,8 @@ namespace { int session_handle::as_for_ip(address const&) { return 0; } -#if TORRENT_USE_WSTRING void session_handle::load_asnum_db(wchar_t const*) {} void session_handle::load_country_db(wchar_t const*) {} -#endif // TORRENT_USE_WSTRING void session_handle::load_state(entry const& ses_state , std::uint32_t const flags) diff --git a/src/storage.cpp b/src/storage.cpp index 0682af607..bb858adda 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -199,12 +199,8 @@ namespace libtorrent { #ifdef TORRENT_WINDOWS // don't do full file allocations on network drives -#if TORRENT_USE_WSTRING std::wstring file_name = convert_to_wstring(m_save_path); int const drive_type = GetDriveTypeW(file_name.c_str()); -#else - int const drive_type = GetDriveTypeA(m_save_path.c_str()); -#endif if (drive_type == DRIVE_REMOTE) m_allocate_files = false; diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 5e446ab7b..a5556cf20 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -225,7 +225,6 @@ namespace libtorrent { } #endif -#if TORRENT_USE_WSTRING #ifndef TORRENT_NO_DEPRECATE void torrent_handle::move_storage( std::wstring const& save_path, int flags) const @@ -238,7 +237,6 @@ namespace libtorrent { async_call(&torrent::rename_file, index, wchar_utf8(new_name)); } #endif // TORRENT_NO_DEPRECATE -#endif // TORRENT_USE_WSTRING void torrent_handle::rename_file(file_index_t index, std::string const& new_name) const { diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 2854a99e1..9671c4158 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -822,7 +822,6 @@ namespace libtorrent { INVARIANT_CHECK; } -#if TORRENT_USE_WSTRING #ifndef TORRENT_NO_DEPRECATE torrent_info::torrent_info(std::wstring const& filename , int const flags) @@ -849,7 +848,6 @@ namespace libtorrent { m_files.rename_file_deprecated(index, new_filename); } #endif // TORRENT_NO_DEPRECATE -#endif // TORRENT_USE_WSTRING #endif torrent_info::torrent_info(bdecode_node const& torrent_file @@ -889,7 +887,6 @@ namespace libtorrent { INVARIANT_CHECK; } -#if TORRENT_USE_WSTRING #ifndef TORRENT_NO_DEPRECATE torrent_info::torrent_info(std::wstring const& filename , error_code& ec @@ -907,7 +904,6 @@ namespace libtorrent { INVARIANT_CHECK; } #endif // TORRENT_NO_DEPRECATE -#endif // TORRENT_USE_WSTRING // constructor used for creating new torrents // will not contain any hashes, comments, creation date diff --git a/src/utf8.cpp b/src/utf8.cpp index da0228986..1224aec5b 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -32,10 +32,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -// on windows we need these functions for -// convert_to_native and convert_from_native -#if TORRENT_USE_WSTRING || defined TORRENT_WINDOWS - #include #include "libtorrent/utf8.hpp" #include "libtorrent/assert.hpp" @@ -307,4 +303,3 @@ namespace { #pragma clang diagnostic pop #endif -#endif diff --git a/test/main.cpp b/test/main.cpp index 45d9e8048..e85563562 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -223,16 +223,9 @@ void change_directory(std::string const& f, error_code& ec) ec.clear(); #ifdef TORRENT_WINDOWS -#if TORRENT_USE_WSTRING -#define SetCurrentDirectory_ SetCurrentDirectoryW native_path_string const n = convert_to_wstring(f); -#else -#define SetCurrentDirectory_ SetCurrentDirectoryA - native_path_string const n = convert_to_native(f); -#endif // TORRENT_USE_WSTRING - if (SetCurrentDirectory_(n.c_str()) == 0) + if (SetCurrentDirectoryW(n.c_str()) == 0) ec.assign(GetLastError(), system_category()); -#undef SetCurrentDirectory_ #else native_path_string const n = convert_to_native_path_string(f); int ret = ::chdir(n.c_str());