fixed incorrect assert in file_win.cpp, added windows-unicode function for file_size

This commit is contained in:
Arvid Norberg 2005-10-17 20:37:40 +00:00
parent d3996ccfb9
commit 51052fa2b1
3 changed files with 30 additions and 10 deletions

View File

@ -211,7 +211,7 @@ namespace libtorrent
size_type read(char* buffer, size_type num_bytes) size_type read(char* buffer, size_type num_bytes)
{ {
assert(buffer); assert(buffer);
assert(num_bytes > 0); assert(num_bytes >= 0);
assert((DWORD)num_bytes == num_bytes); assert((DWORD)num_bytes == num_bytes);
DWORD bytes_read = 0; DWORD bytes_read = 0;

View File

@ -2226,22 +2226,21 @@ namespace libtorrent
m_statistics.received_bytes(0, received); m_statistics.received_bytes(0, received);
if (m_recv_pos < m_packet_size) break; if (m_recv_pos < m_packet_size) break;
assert(m_recv_pos == m_packet_size); assert(m_recv_pos == m_packet_size);
// ok, now we have got enough of the handshake. Is this connection
// attached to a torrent?
// the use of this bit collides with Mainline // the use of this bit collides with Mainline
// the new way of identifying support for the extensions // the new way of identifying support for the extensions
// is in the peer_id // is in the peer_id
// if ((m_recv_buffer[7] & 0x01) && m_ses.extensions_enabled()) // if ((m_recv_buffer[7] & 0x01) && m_ses.extensions_enabled())
// m_supports_extensions = true; // m_supports_extensions = true;
// ok, now we have got enough of the handshake. Is this connection
// attached to a torrent?
if (m_torrent == 0) if (m_torrent == 0)
{ {
// now, we have to see if there's a torrent with the // now, we have to see if there's a torrent with the
// info_hash we got from the peer // info_hash we got from the peer
sha1_hash info_hash; sha1_hash info_hash;
std::copy(m_recv_buffer.begin()+8, m_recv_buffer.begin() + 28, (char*)info_hash.begin()); std::copy(m_recv_buffer.begin() + 8, m_recv_buffer.begin() + 28, (char*)info_hash.begin());
m_torrent = m_ses.find_torrent(info_hash); m_torrent = m_ses.find_torrent(info_hash);
if (m_torrent && m_torrent->is_aborted()) m_torrent = 0; if (m_torrent && m_torrent->is_aborted()) m_torrent = 0;
@ -2264,7 +2263,7 @@ namespace libtorrent
throw protocol_error("connection rejected by paused torrent"); throw protocol_error("connection rejected by paused torrent");
} }
// if the torrent's isn't ready to accept // if the torrent isn't ready to accept
// connections yet, we'll have to wait with // connections yet, we'll have to wait with
// our initialization // our initialization
if (m_torrent->ready_for_connections()) init(); if (m_torrent->ready_for_connections()) init();

View File

@ -126,8 +126,8 @@ namespace
bool exists_win( const path & ph ) bool exists_win( const path & ph )
{ {
std::wstring wsave_path(safe_convert(ph.string())); std::wstring wpath(safe_convert(ph.string()));
if(::GetFileAttributes( wsave_path.c_str() ) == 0xFFFFFFFF) if(::GetFileAttributes( wpath.c_str() ) == 0xFFFFFFFF)
{ {
UINT err = ::GetLastError(); UINT err = ::GetLastError();
if((err == ERROR_FILE_NOT_FOUND) if((err == ERROR_FILE_NOT_FOUND)
@ -144,6 +144,25 @@ namespace
return true; return true;
} }
BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph )
{
std::wstring wpath(safe_convert(ph.string()));
// by now, intmax_t is 64-bits on all Windows compilers
WIN32_FILE_ATTRIBUTE_DATA fad;
if ( !::GetFileAttributesExW( wpath.c_str(),
::GetFileExInfoStandard, &fad ) )
boost::throw_exception( filesystem_error(
"boost::filesystem::file_size",
ph, fs::detail::system_error_code() ) );
if ( (fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0 )
boost::throw_exception( filesystem_error(
"boost::filesystem::file_size",
ph, "invalid: is a directory",
is_directory_error ) );
return (static_cast<boost::intmax_t>(fad.nFileSizeHigh)
<< (sizeof(fad.nFileSizeLow)*8))
+ fad.nFileSizeLow;
}
std::time_t last_write_time_win( const path & ph ) std::time_t last_write_time_win( const path & ph )
{ {
@ -341,10 +360,11 @@ namespace libtorrent
try try
{ {
path f = p / i->path; path f = p / i->path;
size = file_size(f);
#if defined(_WIN32) && defined(UNICODE) #if defined(_WIN32) && defined(UNICODE)
size = file_size_win(f);
time = last_write_time_win(f); time = last_write_time_win(f);
#else #else
size = file_size(f);
time = last_write_time(f); time = last_write_time(f);
#endif #endif
} }
@ -377,10 +397,11 @@ namespace libtorrent
try try
{ {
path f = p / i->path; path f = p / i->path;
size = file_size(f);
#if defined(_WIN32) && defined(UNICODE) #if defined(_WIN32) && defined(UNICODE)
size = file_size_win(f);
time = last_write_time_win(f); time = last_write_time_win(f);
#else #else
size = file_size(f);
time = last_write_time(f); time = last_write_time(f);
#endif #endif
} }