Esempio n. 1
0
void Update::updateFinished(QNetworkReply *reply)
{
    reply->deleteLater();

    QString update_url = reply->property("update_url").toString();

    if (reply->error())
        hUpdateResults[update_url] = QString::null;
    else
    {
        QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
        if (!possibleRedirectUrl.toUrl().isEmpty())
        {
            updateRequest("GET", possibleRedirectUrl.toString(), update_url);
            return;
        }

        QString strUpdateXml = reply->readAll();

        hUpdateResults[update_url] = strUpdateXml;
    }

    if (hUpdateResults.size() == 1)
    {
        checkUpdateGithub();
    }
    else if (hUpdateResults.size() == 2)
    {
        int updateSourceforge = fastParseVersion(hUpdateResults.value(UPDATE_URL_SOURCEFORGE));
        int updateGithub = fastParseVersion(hUpdateResults.value(UPDATE_URL_GITHUB));

        if ((updateSourceforge != 0) && (updateGithub != 0))
        {
            if (updateSourceforge >= updateGithub)
                saveUpdate(hUpdateResults.value(UPDATE_URL_SOURCEFORGE));
            else
                saveUpdate(hUpdateResults.value(UPDATE_URL_GITHUB));

            if (!Settings::instance()->get("motd").isEmpty())
            {
                QString strMOTD = Settings::instance()->get("motd");
                QString strMessageOfTheDay = QString("%Fb%%1 %2").arg(tr("Message Of The Day:"), strMOTD);
                Message::instance()->showMessage(STATUS_WINDOW, strMessageOfTheDay, MessageDefault);
            }

            if (Settings::instance()->get("available_version") != "0.0.0.0")
            {
                QString strVersionStatus = fullParseVersion();

                // save status
                Settings::instance()->set("version_status", strVersionStatus);

                if (Settings::instance()->get("updates") == "true")
                    Notification::instance()->refreshUpdate();
            }
        }
    }
}
Esempio n. 2
0
void
CKLBUpdate::exec_download(u32 /*deltaT*/)
{
	bool bResult = m_httpIF->httpRECV();
	// Current downloaded size (may be inacurate)
	s64 size			= m_httpIF->getDwnldSize();
	// Completly download size (accurate but updated at the end)
	s64 completeOnSize	= m_httpIF->getSize();

	if(size != m_dlSize) {
		m_dlSize = size;	// 読み込み済サイズを更新
		if(m_callbackDL) {
			float progress = (m_dlSize * 1000 / m_zipSize) / 1000.0f;
			if (progress < 0.0f) {
				progress = 0.0f;

			// Trick :
			// - avoid callback at 100% because 100% is better to be done when we are sure
			//   that download is complete.
			// - because of inacurracy, we may also go over 100%
			} else if (progress >= 0.999f) {	
				progress = 0.999f;
			}

			char buf[64];
			CKLBUtility::numString64(buf, (u64)(m_zipSize * progress));

			// Ensure that we get only higher values, no backward.
			if (progress > m_maxProgress) {
				m_maxProgress = progress;
				// Only perform callback here when progress is NOT complete.
				if (!bResult) {
					CKLBScriptEnv::getInstance().call_eventUpdateDownload(m_callbackDL, this, (double)progress, buf);
				}
			}
		}
	}

	// 平成24年12月17日(月)
	// RECVの結果がtrueの時、
	// もしdownload sizeとそもそものzip sizeとの値が異なっている場合は正常に受信できていないので、
	// ひとまずリトライするようにしてみる.
	if(bResult) {
		if (completeOnSize == m_zipSize) {
			char buf[64];
			CKLBUtility::numString64(buf, completeOnSize);
			// Perform a 100% callback here because we know download IS complete.
			CKLBScriptEnv::getInstance().call_eventUpdateDownload(m_callbackDL, this, (double)1.0, buf);
			saveUpdate();
			m_eStep = S_INIT_UNZIP;
		} else {
			CKLBScriptEnv::getInstance().call_eventUpdateError(m_callbackError, this);
			DEBUG_PRINT("[update] download success but with invalid size. retry.");
			m_eStep = S_INIT_DL;
		}
	}
}