void WebUpdater::installUpdate_p (const Core::ProductVersion &version, const QString &dir) { const QString &name = outputFileName (dir, version.productUrl ()); const bool isCorrect = isFileCorrect (name, version.productMd5sum()); if (!isCorrect) { QFile::remove (name); } lastError_ = isCorrect && QProcess::startDetached (name, config_.value ("InstallerParameters").toStringList()) ? NoError : InstallError; emit stateChanged (InstallFinishedState); }
const bool EvaCachedFile::generateDestFile() { if(m_IsLoading) return false; if(m_DirPath.empty()) return false; string cachedFileName = m_DirPath + "/" + m_FileName + CacheFileName_Ext; string destFileName = m_DirPath + "/" + m_FileName; FILE* cached; FILE* dest; if(!(cached=fopen(cachedFileName.c_str(),"rb"))){ util_log(0, "EvaCachedFile::generateDestFile -- cannot open cached file \"%s\"!\n", cachedFileName.c_str()); return false; } if(!(dest=fopen(destFileName.c_str(),"wb"))){ util_log(0, "EvaCachedFile::generateDestFile -- cannot create destination file \"%s\"!\n", destFileName.c_str()); fclose(cached); return false; } char *buf; // we might create a fixed-size buffer to save time char strHeader[8]; unsigned int offset, len; while(!feof(cached)){ if (fread(strHeader,1,8,cached)!=8) break; memcpy(&offset, strHeader, 4); memcpy(&len, strHeader+4, 4); buf = new char [len]; fread(buf,len,1,cached); fseek(dest,offset,SEEK_SET); fwrite(buf,len,1,dest); delete []buf; } fclose(cached); fclose(dest); if(!isFileCorrect()){ //dest.remove(); util_log(0, "EvaCachedFile::generateDestFile -- md5 checking wrong\n"); return false; } // actually we got all we want, we don't care about the result of removing following files DeleteFileA(cachedFileName.c_str()); DeleteFileA(string(m_DirPath + "/" + m_InfoFileName).c_str()); m_FragInfo.clear(); return true; }
QString WebUpdater::downloadUpdate_p (const ProductVersion &version, const QString &dir) { outputFile_.setFileName (outputFileName (dir, version.productUrl ())); if (outputFile_.exists() && isFileCorrect (outputFile_.fileName(), version.productMd5sum())) { qDebug () << "File alredy downloaded"; emit downloadFinished (); return outputFile_.fileName(); } if (!outputFile_.open (QIODevice::WriteOnly | QIODevice::Truncate)) { qDebug () << "Error open file " << outputFile_.fileName (); return outputFile_.fileName(); } qDebug () << version.productUrl () << outputFile_.fileName(); const QUrl url (version.productUrl ()); const QNetworkRequest request (url); QNetworkReply *reply_ = manager_->get (request); replyList.push_back (reply_); connect (reply_, SIGNAL (downloadProgress (qint64, qint64)), this, SIGNAL (downloadProgress (qint64, qint64))); connect (reply_, SIGNAL (readyRead()), this, SLOT (readyRead())); connect (reply_, SIGNAL (finished()), this, SLOT (updateDownloaded())); connect (reply_, SIGNAL (finished()), this, SLOT (replyFinished())); return outputFile_.fileName(); }