GH-1060 implement very basic updater (only linux and maybe osx right now)

This commit is contained in:
Petr Mrázek
2015-06-08 02:43:16 +02:00
parent 166813cb91
commit 82e05661d2
8 changed files with 170 additions and 116 deletions

View File

@ -89,7 +89,6 @@ void DownloadTask::processDownloadedVersionInfo()
{
VersionFileList m_currentVersionFileList;
VersionFileList m_newVersionFileList;
OperationList operationList;
setStatus(tr("Reading file list for new version..."));
qDebug() << "Reading file list for new version...";
@ -125,19 +124,12 @@ void DownloadTask::processDownloadedVersionInfo()
NetJobPtr netJob (new NetJob("Update Files"));
// fill netJob and operationList
if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, operationList))
if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, m_operations))
{
emitFailed(tr("Failed to process update lists..."));
return;
}
// write the instruction file for the file swapper
if(!writeInstallScript(operationList, PathCombine(m_updateFilesDir.path(), "file_list.xml")))
{
emitFailed(tr("Failed to write update script file."));
return;
}
// Now start the download.
QObject::connect(netJob.get(), &NetJob::succeeded, this, &DownloadTask::fileDownloadFinished);
QObject::connect(netJob.get(), &NetJob::progress, this, &DownloadTask::fileDownloadProgressChanged);
@ -170,4 +162,9 @@ QString DownloadTask::updateFilesDir()
return m_updateFilesDir.path();
}
OperationList DownloadTask::operations()
{
return m_operations;
}
}

View File

@ -35,6 +35,9 @@ public:
/// Get the directory that will contain the update files.
QString updateFilesDir();
/// Get the list of operations that should be done
OperationList operations();
/// set updater download behavior
void setUseLocalUpdater(bool useLocal);
@ -61,6 +64,8 @@ protected:
Status m_status;
OperationList m_operations;
/*!
* Temporary directory to store update files in.
* This will be set to not auto delete. Task will fail if this fails to be created.

View File

@ -213,78 +213,4 @@ bool fixPathForOSX(QString &path)
return false;
}
}
bool writeInstallScript(OperationList &opsList, QString scriptFile)
{
// Build the base structure of the XML document.
QDomDocument doc;
QDomElement root = doc.createElement("update");
root.setAttribute("version", "3");
doc.appendChild(root);
QDomElement installFiles = doc.createElement("install");
root.appendChild(installFiles);
QDomElement removeFiles = doc.createElement("uninstall");
root.appendChild(removeFiles);
// Write the operation list to the XML document.
for (Operation op : opsList)
{
QDomElement file = doc.createElement("file");
switch (op.type)
{
case Operation::OP_COPY:
{
// Install the file.
QDomElement name = doc.createElement("source");
QDomElement path = doc.createElement("dest");
QDomElement mode = doc.createElement("mode");
name.appendChild(doc.createTextNode(op.file));
path.appendChild(doc.createTextNode(op.dest));
// We need to add a 0 at the beginning here, because Qt doesn't convert to octal
// correctly.
mode.appendChild(doc.createTextNode("0" + QString::number(op.mode, 8)));
file.appendChild(name);
file.appendChild(path);
file.appendChild(mode);
installFiles.appendChild(file);
qDebug() << "Will install file " << op.file << " to " << op.dest;
}
break;
case Operation::OP_DELETE:
{
// Delete the file.
file.appendChild(doc.createTextNode(op.file));
removeFiles.appendChild(file);
qDebug() << "Will remove file" << op.file;
}
break;
default:
qWarning() << "Can't write update operation of type" << op.type
<< "to file. Not implemented.";
continue;
}
}
// Write the XML document to the file.
QFile outFile(scriptFile);
if (outFile.open(QIODevice::WriteOnly))
{
outFile.write(doc.toByteArray());
}
else
{
return false;
}
return true;
}
}

View File

@ -88,22 +88,17 @@ struct Operation
OP_DELETE,
} type;
//! The file to operate on. If this is a DELETE or CHMOD operation, this is the file that will be modified.
//! The file to operate on.
QString file;
//! The destination file. If this is a DELETE or CHMOD operation, this field will be ignored.
//! The destination file.
QString dest;
//! The mode to change the source file to. Ignored if this isn't a CHMOD operation.
//! The mode to change the source file to.
int mode;
};
typedef QList<Operation> OperationList;
/**
* Takes the @OperationList list and writes an install script for the updater to the update files directory.
*/
bool writeInstallScript(OperationList& opsList, QString scriptFile);
/**
* Loads the file list from the given version info JSON object into the given list.
*/