Treat the updater separately

This commit is contained in:
Jan Dalheimer 2013-12-23 10:34:43 +01:00
parent 7a07ed7940
commit 00822fa0f9
2 changed files with 31 additions and 2 deletions

View File

@ -377,6 +377,9 @@ DownloadUpdateTask::processFileLists(NetJob *job,
// yep. this file actually needs an upgrade. PROCEED. // yep. this file actually needs an upgrade. PROCEED.
QLOG_DEBUG() << "Found file" << entry.path << " that needs updating."; QLOG_DEBUG() << "Found file" << entry.path << " that needs updating.";
// if it's the updater we want to treat it separately
bool isUpdater = entry.path.endsWith("updater") || entry.path.endsWith("updater.exe");
// Go through the sources list and find one to use. // Go through the sources list and find one to use.
// TODO: Make a NetAction that takes a source list and tries each of them until one // TODO: Make a NetAction that takes a source list and tries each of them until one
// works. For now, we'll just use the first http one. // works. For now, we'll just use the first http one.
@ -398,13 +401,22 @@ DownloadUpdateTask::processFileLists(NetJob *job,
auto download = MD5EtagDownload::make(source.url, dlPath); auto download = MD5EtagDownload::make(source.url, dlPath);
download->m_expected_md5 = entry.md5; download->m_expected_md5 = entry.md5;
job->addNetAction(download); job->addNetAction(download);
if (isUpdater)
{
download->setProperty("finalPath", entry.path);
connect(download.get(), &MD5EtagDownload::succeeded, this, &DownloadUpdateTask::directDeployFile);
}
} }
if (!isUpdater)
{
// Now add a copy operation to our operations list to install the file. // Now add a copy operation to our operations list to install the file.
ops.append(UpdateOperation::CopyOp(dlPath, entry.path, entry.mode)); ops.append(UpdateOperation::CopyOp(dlPath, entry.path, entry.mode));
} }
} }
} }
}
return true; return true;
} }
@ -512,6 +524,21 @@ void DownloadUpdateTask::fileDownloadProgressChanged(qint64 current, qint64 tota
setProgress((int)(((float)current / (float)total) * 100)); setProgress((int)(((float)current / (float)total) * 100));
} }
void DownloadUpdateTask::directDeployFile(const int index)
{
Md5EtagDownloadPtr download = std::dynamic_pointer_cast<MD5EtagDownload>(m_filesNetJob->operator[](index));
const QString finalPath = download->property("finalPath").toString();
QLOG_INFO() << "Replacing" << finalPath << "with" << download->m_output_file.fileName();
if (QFile::remove(finalPath))
{
if (download->m_output_file.copy(finalPath))
{
return;
}
}
emitFailed("Couldn't copy updater files");
}
QString DownloadUpdateTask::updateFilesDir() QString DownloadUpdateTask::updateFilesDir()
{ {
return m_updateFilesDir.path(); return m_updateFilesDir.path();

View File

@ -207,5 +207,7 @@ protected slots:
void fileDownloadFinished(); void fileDownloadFinished();
void fileDownloadFailed(); void fileDownloadFailed();
void fileDownloadProgressChanged(qint64 current, qint64 total); void fileDownloadProgressChanged(qint64 current, qint64 total);
void directDeployFile(const int index);
}; };