Updater::Updater(QObject *parent) : QObject(parent) { Client = new HttpClient(this); CurrentVersion = GetLocalVersion(); CanSkip = !CurrentVersion.isEmpty(); Progress = 0; Timer = new QTimer(this); Timer->setInterval(60000); Timer->setSingleShot(true); connect(Timer,SIGNAL(timeout()),this,SLOT(Skip())); }
int CUpdator::Check() { //get local version CVersion local = GetLocalVersion(); //get remote version CVersion remote=GetRemoteVersion(); //remote is empty,so return if (remote ==CVersion()) { LOG(_T("remote version error.")); //notify l DWORD res = 4; Event loading(E_UPDATE_OVER,(void*)this,0,res); Notify(loading); return false; } //check version bool need_update = CheckVersion(local,remote); return need_update; }
void f_check::CheckForUpdate() { // Wait 3s before to check for update QEventLoop loop; QTimer::singleShot(3000, &loop, SLOT(quit())); loop.exec(); // Check for different mod name and avoid looking for update if it's not the standard one QString url_check = "http://civ.afforess.com/changelog_last.xml"; if(readCheckerParam("Mod/url_check") != "error"){ return; } // Begin the check for update //qDebug()<<"Starting worker process in Thread "<<thread()->currentThreadId(); bool update; QFile::remove("checker/changelog_last.xml"); QProcess download; QString get_address = tools::TOOL_GET + "-O checker/changelog_last.xml " + url_check; //qDebug() << get_address; download.start(get_address); if (download.waitForFinished(60000)) { // Check for update if(GetDistantVersion() > GetLocalVersion()){ update = true; } else { update = false; } //qDebug() << "New version available :" << update; } // Check MCP version bool update_mcp = false; QString url = getModURL("Custom_Civilizations_MCP"); if(!url.isEmpty()) { QString get_address_mod = tools::TOOL_GET + "-O checker/changelog_mod.xml " + url; download.start(get_address_mod); if (download.waitForFinished(60000)) { // Open the downloaded file and compare version float version = 0; QFile file("checker/changelog_mod.xml"); if(file.open(QIODevice::ReadOnly)){ QDomDocument modxml; modxml.setContent(&file); file.close(); QDomElement filexml = modxml.firstChildElement("root").firstChildElement("version"); if(!filexml.isNull()){ version = QString(filexml.firstChild().nodeValue()).toFloat(); } if(version != 0 && version > getModLocalVersion("Custom_Civilizations_MCP")) { // Notify the new update update_mcp = true; } } } } // Set _working to false, meaning the process can't be aborted anymore. mutex.lock(); _working = false; mutex.unlock(); //qDebug()<<"Worker process finished in Thread "<<thread()->currentThreadId(); qDebug("Update checking ended..."); // Finished signal emit finished(update, update_mcp); }