Revision: 1499
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1499&view=rev
Author:   rorthomas
Date:     2010-07-25 03:52:01 +0000 (Sun, 25 Jul 2010)

Log Message:
-----------
installer using libcurl now, replacing BOOST::ASIO

Modified Paths:
--------------
    trunk/CMakeDependenciesConfig.txt
    trunk/source/installer/CMakeLists.txt
    trunk/source/installer/ConfigManager.cpp
    trunk/source/installer/ConfigManager.h
    trunk/source/installer/installerlog.h
    trunk/source/installer/utils.cpp
    trunk/source/installer/utils.h
    trunk/source/installer/wizard.cpp
    trunk/source/installer/wsyncdownload.cpp
    trunk/source/installer/wsyncdownload.h
    trunk/source/installer/wthread.cpp
    trunk/source/installer/wthread.h

Modified: trunk/CMakeDependenciesConfig.txt
===================================================================
--- trunk/CMakeDependenciesConfig.txt   2010-07-25 00:01:56 UTC (rev 1498)
+++ trunk/CMakeDependenciesConfig.txt   2010-07-25 03:52:01 UTC (rev 1499)
@@ -48,6 +48,10 @@
                set(BOOST_INCLUDE_DIRS "${ROR_DEPENDENCIES_DIR}/include/boost" 
CACHE PATH "The BOOST include path to use")
                set(BOOST_LIBRARY_DIRS "${ROR_DEPENDENCIES_DIR}/lib/boost" 
CACHE PATH "The BOOST lib path to use")
 
+               set(CURL_INCLUDE_DIRS "${ROR_DEPENDENCIES_DIR}/include/" CACHE 
PATH "The curl include path to use")
+               set(CURL_LIBRARY_DIRS "${ROR_DEPENDENCIES_DIR}/lib" CACHE PATH 
"The curl lib path to use")
+               set(CURL_LIBRARIES "libcurl.lib" CACHE STRING "The curl lib to 
link against")
+               
                set(PThread_INCLUDE_DIRS 
"${ROR_DEPENDENCIES_DIR}/include/pthread" CACHE PATH "The pthread include path 
to use")
                set(PThread_LIBRARY_DIRS "${ROR_DEPENDENCIES_DIR}/lib" CACHE 
PATH "The pthread lib path to use")
                set(PThread_LIBRARIES "pthreadVC2.lib" CACHE STRING "The 
pthread lib to link against")
@@ -155,6 +159,11 @@
 
    PKG_CHECK_MODULES  (Ois OIS REQUIRED)
 
+   find_package(CURL)
+   if(NOT CURL_FOUND)
+     message(ERROR "curl not found, please install curl")
+   endif(NOT CURL_FOUND)
+   
    # using cmake fingd modules
    # Open-AL
    find_package(OpenAL)

Modified: trunk/source/installer/CMakeLists.txt
===================================================================
--- trunk/source/installer/CMakeLists.txt       2010-07-25 00:01:56 UTC (rev 
1498)
+++ trunk/source/installer/CMakeLists.txt       2010-07-25 03:52:01 UTC (rev 
1499)
@@ -42,6 +42,8 @@
 add_definitions("-DINSTALLER_PLATFORM=\"${INSTALLER_PLATFORM}\"")
 message("the default installer platform is \"${INSTALLER_PLATFORM}\". To 
change this, edit INSTALLER_PLATFORM value in cmake.")
 
+include_directories(${CURL_INCLUDE_DIRS})
+link_directories   (${CURL_LIBRARY_DIRS})
 include_directories(${BOOST_INCLUDE_DIRS})
 link_directories   (${BOOST_LIBRARY_DIRS})
 
@@ -87,5 +89,6 @@
    TARGET_LINK_LIBRARIES(installer ${Boost_LIBRARIES})
    TARGET_LINK_LIBRARIES(installer ${wxWidgets_LIBRARIES})
 ENDIF(WIN32)
+TARGET_LINK_LIBRARIES(installer ${CURL_LIBRARIES})
+   
 
-

Modified: trunk/source/installer/ConfigManager.cpp
===================================================================
--- trunk/source/installer/ConfigManager.cpp    2010-07-25 00:01:56 UTC (rev 
1498)
+++ trunk/source/installer/ConfigManager.cpp    2010-07-25 03:52:01 UTC (rev 
1499)
@@ -45,7 +45,6 @@
        #include <shellapi.h> // for executing the binaries
 #endif //OGRE_PLATFORM
 
-#include "boost/asio.hpp"
 #include "boost/filesystem.hpp"
 
 //icons must be 50x50

Modified: trunk/source/installer/ConfigManager.h
===================================================================
--- trunk/source/installer/ConfigManager.h      2010-07-25 00:01:56 UTC (rev 
1498)
+++ trunk/source/installer/ConfigManager.h      2010-07-25 03:52:01 UTC (rev 
1499)
@@ -24,7 +24,6 @@
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 #include <vector>
-#include "boost/asio.hpp"
 #include "boost/filesystem.hpp"
 
 // for all others, include the necessary headers

Modified: trunk/source/installer/installerlog.h
===================================================================
--- trunk/source/installer/installerlog.h       2010-07-25 00:01:56 UTC (rev 
1498)
+++ trunk/source/installer/installerlog.h       2010-07-25 03:52:01 UTC (rev 
1499)
@@ -23,6 +23,7 @@
        void logMessage(const char* fmt, ...);
        void logMessageNoNewLine(const char* fmt, ...);
 
+       FILE *getLogFilePtr() { return file; };
 
        static InstallerLog *instance;
 protected:

Modified: trunk/source/installer/utils.cpp
===================================================================
--- trunk/source/installer/utils.cpp    2010-07-25 00:01:56 UTC (rev 1498)
+++ trunk/source/installer/utils.cpp    2010-07-25 03:52:01 UTC (rev 1499)
@@ -4,8 +4,6 @@
 
 #include <boost/algorithm/string.hpp>
 
-using namespace boost::asio;
-using namespace boost::asio::ip;
 using namespace boost::filesystem;
 
 BEGIN_EVENT_TABLE(myClickBitmap, wxStaticBitmap)

Modified: trunk/source/installer/utils.h
===================================================================
--- trunk/source/installer/utils.h      2010-07-25 00:01:56 UTC (rev 1498)
+++ trunk/source/installer/utils.h      2010-07-25 03:52:01 UTC (rev 1499)
@@ -25,7 +25,6 @@
 #include <wx/statbmp.h>
 #include <wx/stattext.h>
 
-#include <boost/asio.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 

Modified: trunk/source/installer/wizard.cpp
===================================================================
--- trunk/source/installer/wizard.cpp   2010-07-25 00:01:56 UTC (rev 1498)
+++ trunk/source/installer/wizard.cpp   2010-07-25 03:52:01 UTC (rev 1499)
@@ -168,7 +168,6 @@
        wizard.RunWizard(wizard.GetFirstPage());
 
        // we're done
-       // forecfully end this, otherwise: CRASH when we used ASIO :(
        exit(0);
 
        // this crashes the app:
@@ -1089,6 +1088,10 @@
        std::string fromVersion = CONFIG->readVersionInfo();
        std::string toVersion   = CONFIG->getOnlineVersion();
        std::string versionText = std::string("updating from ") + fromVersion + 
std::string(" to ") + toVersion;
+       if(fromVersion == "unkown")
+               versionText = toVersion;
+       if(fromVersion == toVersion)
+               versionText = toVersion;
        std::string versionURL  = std::string(CHANGELOGURL) + toVersion;
        hlink->SetLabel(conv(versionText));
        hlink->SetURL(conv(versionURL));
@@ -1128,13 +1131,16 @@
        case MSE_DOWNLOAD_PROGRESS:
        {
                wxString str = ev.GetString();
-               for(int i=statusList->GetCount()-1;i>=0;--i)
+               if(ev.GetProgress() > 0)
                {
-                       wxString str_comp = 
statusList->GetString(i).SubString(0, str.size()-1);
-                       if(str_comp == str)
+                       for(int i=statusList->GetCount()-1;i>=0;--i)
                        {
-                               statusList->SetString(i, str + 
wxString::Format(wxT(" (%3.1f%% downloaded)"), ev.GetProgress() * 100.0f));
-                               break;
+                               wxString str_comp = 
statusList->GetString(i).SubString(0, str.size()-1);
+                               if(str_comp == str)
+                               {
+                                       statusList->SetString(i, str + 
wxString::Format(wxT(" (%3.1f%% downloaded)"), ev.GetProgress() * 100.0f));
+                                       break;
+                               }
                        }
                }
        }

Modified: trunk/source/installer/wsyncdownload.cpp
===================================================================
--- trunk/source/installer/wsyncdownload.cpp    2010-07-25 00:01:56 UTC (rev 
1498)
+++ trunk/source/installer/wsyncdownload.cpp    2010-07-25 03:52:01 UTC (rev 
1499)
@@ -2,22 +2,25 @@
 
 #include <wx/thread.h>
 #include <wx/event.h>
-#include <wx/progdlg.h>
 #include <string.h>
 #include "Timer.h"
 #include "installerlog.h"
 #include "tokenize.h"
 #include "utils.h"
 
-#include <boost/asio.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
 
+#define CURL_STATICLIB
+#include <stdio.h>
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+#include <string>
+
 #include <iostream>
 #include <fstream>
 
-using namespace boost::asio;
-using namespace boost::asio::ip;
 using namespace boost::filesystem;
 using namespace std;
 
@@ -29,228 +32,137 @@
        mDownloadMessage = wxT("downloading file ...");
 }
 
-int WsyncDownload::downloadFile(int jobID, boost::filesystem::path localFile, 
string server, string path, boost::uintmax_t predDownloadSize, boost::uintmax_t 
*fileSizeArg, bool showProgress)
+int progress_callback(void *data, double dltotal, double dlnow, double 
ultotal, double ulnow)
 {
-       LOG("DLFile-%04d| starting: http://%s%s -> %s ... \n", jobID, 
server.c_str(), path.c_str(), localFile.string().c_str());
+       job_info_t *jinfo = (job_info_t *)data;
+       if(!jinfo) return 1;
+       
+       jinfo->realDownloadSize = dltotal;
+       jinfo->downloadDoneSize = dlnow;
 
-       wxProgressDialog *wxp = 0;
-       if(showProgress)
-               wxp = new wxProgressDialog(mDownloadMessage, 
conv(string("downloading http://";) + server + path), 1000,0, 
wxPD_AUTO_HIDE|wxPD_SMOOTH|wxPD_ELAPSED_TIME|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME|wxPD_CAN_ABORT);
-       boost::uintmax_t downloadDoneSize=0;
+       jinfo->filesize_left = jinfo->realDownloadSize - 
jinfo->downloadDoneSize;
+       
+       double tdiff = (jinfo->speedTimer->elapsed() - jinfo->lastTime);
+       if(tdiff > 1.0f)
+       {
+               // slow down the GUI updates
+               if(jinfo->wxp)
+                       
jinfo->wxp->Update(1000*(((float)jinfo->downloadDoneSize)/((float)jinfo->realDownloadSize)),
 wxT("downloading..."));
+               jinfo->parent->reportDownloadProgress(jinfo->jobID, 
*jinfo->dlStartTime, jinfo->realDownloadSize, jinfo->downloadDoneSize);
+               jinfo->lastTime = jinfo->speedTimer->elapsed();
+       }
+       return 0;
+}
 
-       Timer dlStartTime = Timer();
 
+int WsyncDownload::downloadFile(int jobID, boost::filesystem::path localFile, 
string server, string path, boost::uintmax_t predDownloadSize, boost::uintmax_t 
*fileSizeArg, bool showProgress)
+{
+       LOG("DLFile-%04d| starting: http://%s%s -> %s ... \n", jobID, 
server.c_str(), path.c_str(), localFile.string().c_str());
+
        // remove '//' and '///' from url
        cleanURL(path);
-       double lastTime=-1;
-       boost::uintmax_t fileSize = 0;
-       try
-       {
-               Timer time = Timer();
 
-               std::ofstream myfile;
-               ensurePathExist(localFile);
+       job_info jinfo;
+       jinfo.parent = this;
+       jinfo.jobID = jobID;
+       jinfo.showProgress = showProgress;
+       jinfo.realDownloadSize = predDownloadSize;
+       jinfo.predDownloadSize = predDownloadSize;
+       jinfo.downloadDoneSize=0;
+       jinfo.datacounter=0;
+       jinfo.dataspeed=0;
+       jinfo.filesize_left=0;
+       jinfo.lastTime=-1;
+       jinfo.dlStartTime = new Timer();
+       jinfo.speedTimer = new Timer();
+       jinfo.wxp = 0;
+       if(showProgress)
+               jinfo.wxp = new wxProgressDialog(mDownloadMessage, 
conv(string("downloading http://";) + server + path), 1000,0, 
wxPD_AUTO_HIDE|wxPD_SMOOTH|wxPD_ELAPSED_TIME|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME|wxPD_CAN_ABORT);
 
-               boost::asio::io_service io_service;
+       ensurePathExist(localFile);
 
-               // Get a list of endpoints corresponding to the server name.
-               tcp::resolver resolver(io_service);
-               char *host = const_cast<char*>(server.c_str());
-               tcp::resolver::query query(tcp::v4(), host, "80");
-               tcp::resolver::iterator endpoint_iterator = 
resolver.resolve(query);
-               tcp::resolver::iterator end;
+       CURL *curl = curl_easy_init();
+       if(!curl)
+       {
+               LOG("DLFile-%04d|error creating curl: %s\n", jobID, 
localFile.string().c_str());
+               LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
+               if(jinfo.wxp) jinfo.wxp->Update(1000, wxT("error"));
+               return 1;
+       }
 
-               // Try each endpoint until we successfully establish a 
connection.
-               if(wxp) wxp->Update(0, wxT("Connecting to ") + conv(server) + 
wxT(" ..."));
-               tcp::socket socket(io_service);
-               boost::system::error_code error = 
boost::asio::error::host_not_found;
-               while (error && endpoint_iterator != end)
-               {
-                       socket.close();
-                       socket.connect(*endpoint_iterator++, error);
-               }
-               if (error)
-                       throw boost::system::system_error(error);
+       string url = "http://"; + server + path;
+       FILE *outFile = fopen(localFile.string().c_str(), "wb");
+       if(!outFile)
+       {
+               perror("error opening file");
+               LOG("DLFile-%04d|error opening local file: %s.\n", jobID, 
localFile.string().c_str());
+               LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
+               if(jinfo.wxp) jinfo.wxp->Update(1000, wxT("error"));    
+       }
 
-               // Form the request. We specify the "Connection: close" header 
so that the
-               // server will close the socket after transmitting the 
response. This will
-               // allow us to treat all data up until the EOF as the content.
-               boost::asio::streambuf request;
-               std::ostream request_stream(&request);
-               request_stream << "GET " << path << " HTTP/1.0\r\n";
-               request_stream << "Host: " << server << "\r\n";
-               request_stream << "Accept: */*\r\n";
-               request_stream << "Connection: close\r\n\r\n";
+       char *curl_err_str[CURL_ERROR_SIZE];
+       memset(curl_err_str, 0, CURL_ERROR_SIZE);
 
-               // Send the request.
-               boost::asio::write(socket, request);
+       CURLcode res;
+       curl_easy_setopt(curl, CURLOPT_URL,              url.c_str());
+       
+       // logging stuff
+       curl_easy_setopt(curl, CURLOPT_STDERR,           
InstallerLog::getSingleton()->getLogFilePtr());
+       curl_easy_setopt(curl, CURLOPT_ERRORBUFFER,      curl_err_str[0]);
 
-               // Read the response status line.
-               boost::asio::streambuf response;
-               boost::asio::streambuf data;
-               boost::asio::read_until(socket, response, "\r\n");
+       // progess stuff
+       curl_easy_setopt(curl, CURLOPT_NOPROGRESS,       0);
+       curl_easy_setopt(curl, CURLOPT_PROGRESSDATA,     &jinfo);
+       curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, &progress_callback);
+       curl_easy_setopt(curl, CURLOPT_WRITEDATA,        outFile);
 
-               // Check that response is OK.
-               std::istream response_stream(&response);
-               std::string http_version;
-               response_stream >> http_version;
-               unsigned int status_code;
-               response_stream >> status_code;
-               std::string status_message;
-               std::getline(response_stream, status_message);
-               if (!response_stream || http_version.substr(0, 5) != "HTTP/")
-               {
-                       socket.close();
-                       LOG("DLFile-%04d|Error: Invalid response: %s\n", jobID, 
http_version.c_str());
-                       LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
-                       if(wxp) wxp->Update(1000, wxT("error"));
-                       return 1;
-               }
-               if (status_code == 302)
-               {
-                       // catch redirects
-                       socket.close();
-                       boost::asio::read_until(socket, response, "\r\n\r\n");
-                       std::string line="",new_url="";
-                       size_t counter = 0;
-                       size_t reported_filesize = 0;
-                       {
-                               while (std::getline(response_stream, line) && 
line != "\r")
-                               {
-                                       if(line.substr(0, 10) == "location: ")
-                                               new_url = 
line.substr(10).c_str();
-                               }
-                       }
-                       // check protocol
-                       if(new_url.substr(0, 7) != "http://";)
-                       {
-                               LOG("DLFile-%04d|Error: redirection uses unkown 
protocol: %s\n", jobID, new_url.c_str());
-                               LOG("DLFile-%04d|download URL: http://%s%s\n";, 
jobID, server.c_str(), path.c_str());
-                               if(wxp) wxp->Update(1000, wxT("error"));
-                               return 1;
-                       }
-                       // trim line
-                       new_url = new_url.substr(0, 
new_url.find_first_of("\r"));
+       // http related settings
+       curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,   1); // follow redirects
+       curl_easy_setopt(curl, CURLOPT_AUTOREFERER,      1); // set the 
Referer: field in requests where it follows a Location: redirect. 
+       curl_easy_setopt(curl, CURLOPT_MAXREDIRS,        20);
+       curl_easy_setopt(curl, CURLOPT_USERAGENT,        "RoRInstaller");
+       curl_easy_setopt(curl, CURLOPT_FILETIME,         1);
+       
 
-                       // separate URL into server and path
-                       string new_server = new_url.substr(7, 
new_url.find_first_of("/", 7)-7);
-                       string new_path = 
new_url.substr(new_url.find_first_of("/", 7));
+       // important for us later:
+       //curl_easy_setopt(curl, CURLOPT_RANGE,        "...");
+       
+       res = curl_easy_perform(curl);
+       curl_easy_cleanup(curl);
+       fclose(outFile);
 
-                       LOG("DLFile-%04d| got redirected: http://%s%s -> 
http://%s%s\n";, jobID, server.c_str(), path.c_str(), new_server.c_str(), 
new_path.c_str());
-                       if(wxp) wxp->Update(1000, wxT("error"));
-                       return downloadFile(jobID, localFile, new_server, 
new_path);
-               }
-               if (status_code != 200)
-               {
-                       LOG("DLFile-%04d|Error: Response returned with status 
code: %d\n", jobID, status_code);
-                       LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
-                       if(wxp) wxp->Update(1000, wxT("error"));
-                       return -(int)status_code;
-               }
-
-               // Read the response headers, which are terminated by a blank 
line.
-               boost::asio::read_until(socket, response, "\r\n\r\n");
-
-               // Process the response headers.
-               std::string line;
-               size_t counter = 0;
-               size_t reported_filesize = 0;
-               {
-                       while (std::getline(response_stream, line) && line != 
"\r")
-                       {
-                               if(line.substr(0, 15) == "Content-Length:")
-                               {
-                                       reported_filesize = 
atoi(line.substr(16).c_str());
-                                       if(predDownloadSize <= 0)
-                                               predDownloadSize = 
reported_filesize;
-                               }
-                       }
-               }
-
-               // open local file late -> prevent creating empty files
-               try
-               {
-                       // throw exceptions
-                       myfile.exceptions ( ofstream::eofbit | 
ofstream::failbit | ofstream::badbit );
-                       myfile.open(localFile.string().c_str(), ios::out | 
ios::binary);
-               }
-               catch (ofstream::failure e)
-               {
-                       LOG("DLFile-%04d|error opening local file: %s. error: 
%s\n", jobID, localFile.string().c_str(), e.what());
-                       LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
-                       if(wxp) wxp->Update(1000, wxT("error"));
-                       return 2;
-               }
-
-               if(!myfile.is_open())
-               {
-                       LOG("DLFile-%04d|error opening local file: %s\n", 
jobID, localFile.string().c_str());
-                       LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
-                       if(wxp) wxp->Update(1000, wxT("error"));
-                       return 2;
-               }
-
-               // Write whatever content we already have to output.
-               if (response.size() > 0)
-                       myfile << &response;
-
-               // Read until EOF, writing data to output as we go.
-               boost::uintmax_t datacounter=0;
-               boost::uintmax_t dataspeed=0;
-               boost::uintmax_t filesize_left=reported_filesize;
-               while (boost::asio::read(socket, data, 
boost::asio::transfer_at_least(1), error))
-               {
-                       double tdiff = (time.elapsed() - lastTime);
-                       if(tdiff >= 0.5f)
-                       {
-                               if(wxp) 
wxp->Update(1000*(((float)downloadDoneSize)/((float)predDownloadSize)), 
wxT("downloading..."));
-                               downloadDoneSize += dataspeed;
-                               reportDownloadProgress(jobID, dlStartTime, 
predDownloadSize, downloadDoneSize);
-                               dataspeed=0;
-                               lastTime=time.elapsed();
-                       }
-
-                       dataspeed += data.size();
-                       datacounter += data.size();
-                       filesize_left -= data.size();
-                       myfile << &data;
-               }
-
-               // dont loose some last bytes
-               if(dataspeed>0)
-                       downloadDoneSize += dataspeed;
-
-               if (error != boost::asio::error::eof)
-                       throw boost::system::system_error(error);
-
-               myfile.close();
-               fileSize = file_size(localFile);
-               socket.close();
-               if(reported_filesize != 0 && fileSize != reported_filesize)
-               {
-                       LOG("DLFile-%04d|Error: file size is different: should 
be %d, is %d. removing file.\n", jobID, reported_filesize, (int)fileSize);
-                       LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
-                       if(wxp) wxp->Update(1000, wxT("error"));
-
-                       tryRemoveFile(localFile);
-                       return 1;
-               }
-               if(wxp) wxp->Update(1000, wxT("done"));
-
-               // traffic stats tracking
-               increaseServerStats(server, fileSize);
-
-               if(fileSizeArg)
-                       *fileSizeArg = (int)fileSize;
+       // print curl error if existing
+       if(res != CURLE_OK)
+       {
+               LOG("DLFile-%04d| CURL returned: %d\n", jobID, res);
+               LOG("DLFile-%04d| CURL error: %s\n", jobID, curl_err_str);
        }
-       catch (std::exception& e)
+
+       // check results
+       boost::uintmax_t fileSize = file_size(localFile);
+       if(jinfo.predDownloadSize != 0 && fileSize != jinfo.predDownloadSize)
        {
-               if(wxp) wxp->Update(1000, wxT("error"));
-               LOG("DLFile-%04d|Exception Error: %s\n", jobID, 
string(e.what()).c_str());
+               LOG("DLFile-%04d|Error: file size is different: should be %d, 
is %d. removing file.\n", jobID, jinfo.realDownloadSize, (int)fileSize);
                LOG("DLFile-%04d|download URL: http://%s%s\n";, jobID, 
server.c_str(), path.c_str());
+               if(jinfo.wxp) jinfo.wxp->Update(1000, wxT("error"));
 
+               tryRemoveFile(localFile);
                return 1;
        }
+
+       // close dialog
+       if(jinfo.wxp) jinfo.wxp->Update(1000, wxT("done"));
+
+       // delete timers
+       delete (jinfo.dlStartTime); jinfo.dlStartTime = 0;
+       delete (jinfo.speedTimer); jinfo.speedTimer = 0;
+       if(jinfo.wxp) { delete (jinfo.wxp); jinfo.wxp = 0; }
+
+       // traffic stats tracking
+       increaseServerStats(server, fileSize);
+
+       if(fileSizeArg)
+               *fileSizeArg = (int)fileSize;
        LOG("DLFile-%04d| download ok, %d bytes received\n", jobID, fileSize);
 
        return 0;

Modified: trunk/source/installer/wsyncdownload.h
===================================================================
--- trunk/source/installer/wsyncdownload.h      2010-07-25 00:01:56 UTC (rev 
1498)
+++ trunk/source/installer/wsyncdownload.h      2010-07-25 03:52:01 UTC (rev 
1499)
@@ -2,6 +2,7 @@
 #define WSYNCDOWNLOAD_H__
 
 #include <wx/event.h>
+#include <wx/progdlg.h>
 
 #include "cevent.h"
 #include "Timer.h"
@@ -9,6 +10,24 @@
 #include "boost/asio.hpp"
 #include "boost/filesystem.hpp"
 
+class WsyncDownload;
+typedef struct job_info
+{
+       WsyncDownload *parent;
+       int jobID;
+       bool showProgress;
+       wxProgressDialog *wxp;
+       Timer *dlStartTime;
+       Timer *speedTimer;
+       boost::uintmax_t predDownloadSize;
+       boost::uintmax_t realDownloadSize;
+       boost::uintmax_t downloadDoneSize;
+       boost::uintmax_t filesize_left;
+       boost::uintmax_t datacounter;
+       boost::uintmax_t dataspeed;
+       double lastTime;
+} job_info_t;
+
 class WsyncDownload
 {
 public:
@@ -26,14 +45,15 @@
 
        void setDownloadMessage(wxString msg) { mDownloadMessage = msg; };
 
+       void reportDownloadProgress(int jobID, Timer dlStartTime, 
boost::uintmax_t predDownloadSize, boost::uintmax_t downloaded);
 protected:
        wxEvtHandler* parent;
        static std::map < std::string, boost::uintmax_t > traffic_stats;
 
-       void reportDownloadProgress(int jobID, Timer dlStartTime, 
boost::uintmax_t predDownloadSize, boost::uintmax_t downloaded);
        void updateCallback(int jobID, int type, std::string txt = 
std::string(), float percent=-1);
 
        wxString mDownloadMessage;
+
 };
 
 #endif //WSYNCDOWNLOAD_H__
\ No newline at end of file

Modified: trunk/source/installer/wthread.cpp
===================================================================
--- trunk/source/installer/wthread.cpp  2010-07-25 00:01:56 UTC (rev 1498)
+++ trunk/source/installer/wthread.cpp  2010-07-25 03:52:01 UTC (rev 1499)
@@ -80,8 +80,12 @@
                break;
        }
 
-       // then report the progress to the GUI
-       reportProgress();
+       if(updateTimer.elapsed() > 0.5f)
+       {
+               // then report the progress to the GUI
+               reportProgress();
+               updateTimer.restart();
+       }
 }
 
 void WsyncThread::reportProgress()

Modified: trunk/source/installer/wthread.h
===================================================================
--- trunk/source/installer/wthread.h    2010-07-25 00:01:56 UTC (rev 1498)
+++ trunk/source/installer/wthread.h    2010-07-25 03:52:01 UTC (rev 1499)
@@ -9,7 +9,6 @@
 #include "ConfigManager.h" //only use for stream_desc_t, dont use functions, 
as its not thread safe!
 #include "threadpool.h"
 
-#include "boost/asio.hpp"
 #include "boost/filesystem.hpp"
 
 
@@ -97,6 +96,7 @@
        boost::filesystem::path ipath; // installation path, what we work on
        boost::uintmax_t predDownloadSize;
        Timer dlStartTime;
+       Timer updateTimer;
        int dlNum;
        std::map<int, dlstatus_t> dlStatus;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to