From 84cbb90e92efd8ddf96863a6995ddb9ec1695f7c Mon Sep 17 00:00:00 2001 From: lotodore Date: Sat, 21 Mar 2009 22:58:58 +0000 Subject: [PATCH] Trying to fix avatar download problem. --- src/net/common/downloaderthread.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/net/common/downloaderthread.cpp b/src/net/common/downloaderthread.cpp index f71a2a21..c3a3111e 100644 --- a/src/net/common/downloaderthread.cpp +++ b/src/net/common/downloaderthread.cpp @@ -91,8 +91,18 @@ DownloaderThread::Main() { path filepath(m_curDownloadData->filename); ifstream instream(filepath.file_string().c_str(), ios_base::in | ios_base::binary); - vector fileData; - copy(istream_iterator(instream), istream_iterator(), back_inserter(fileData)); + // Find out file size. + // Not fully portable, but works on win/linux/mac. + instream.seekg(0, ios_base::beg); + std::streampos startPos = instream.tellg(); + instream.seekg(0, ios_base::end); + std::streampos endPos = instream.tellg(); + instream.seekg(0, ios_base::beg); + std::streamoff posDiff(endPos - startPos); + unsigned fileSize = (unsigned)posDiff; + + vector fileData(fileSize); + instream.read((char *)&fileData[0], fileSize); instream.close(); remove(filepath);