Fix reloading addons, ticket #854

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12966 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2013-06-24 19:11:44 +00:00
parent 5a8f411128
commit 15cebefa34
2 changed files with 16 additions and 8 deletions

View File

@ -179,7 +179,7 @@ void *NetworkHttp::mainLoop(void *obj)
switch(me->m_current_request->getCommand())
{
case Request::HC_INIT:
status = me->init();
status = me->init(false);
break;
case Request::HC_REINIT:
status = me->reInit();
@ -269,7 +269,7 @@ NetworkHttp::~NetworkHttp()
* \return 0 if an error happened and no online connection will be available,
* 1 otherwise.
*/
CURLcode NetworkHttp::init()
CURLcode NetworkHttp::init(bool forceRefresh)
{
news_manager->clearErrorMessage();
core::stringw error_message("");
@ -332,7 +332,7 @@ CURLcode NetworkHttp::init()
xml = new XMLNode(xml_file);
}
news_manager->init();
status = loadAddonsList(xml, xml_file);
status = loadAddonsList(xml, xml_file, forceRefresh);
delete xml;
if(status==CURLE_OK)
{
@ -408,7 +408,7 @@ CURLcode NetworkHttp::reInit()
if(UserConfigParams::logAddons())
printf("[addons] Xml files deleted, re-initialising addon manager.\n");
return init();
return init(true /* force refresh */);
} // reInit
@ -424,7 +424,8 @@ CURLcode NetworkHttp::reInit()
* \return curl error code (esp. CURLE_OK if no error occurred)
*/
CURLcode NetworkHttp::loadAddonsList(const XMLNode *xml,
const std::string &filename)
const std::string &filename,
bool forceRefresh)
{
std::string addon_list_url("");
Time::TimeType mtime(0);
@ -445,7 +446,8 @@ CURLcode NetworkHttp::loadAddonsList(const XMLNode *xml,
return CURLE_COULDNT_CONNECT;
}
bool download = mtime > UserConfigParams::m_addons_last_updated;
bool download = (mtime > UserConfigParams::m_addons_last_updated) || forceRefresh;
if(!download)
{
std::string filename=file_manager->getAddonsFile("addons.xml");
@ -453,6 +455,11 @@ CURLcode NetworkHttp::loadAddonsList(const XMLNode *xml,
download = true;
}
if (download)
Log::info("NetworkHttp", "Downloading updated addons.xml");
else
Log::info("NetworkHttp", "Using cached addons.xml");
Request r(Request::HC_DOWNLOAD_FILE, 9999, false,
addon_list_url, "addons.xml");
CURLcode status = download ? downloadFileInternal(&r)

View File

@ -65,9 +65,10 @@ private:
CURL *m_curl_session;
static void *mainLoop(void *obj);
CURLcode init();
CURLcode init(bool forceRefresh);
CURLcode loadAddonsList(const XMLNode *xml,
const std::string &filename);
const std::string &filename,
bool forceRefresh);
CURLcode downloadFileInternal(Request *request);
static int progressDownload(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow);