diff options
| author | Victor Tran <vicr12345@gmail.com> | 2018-07-13 00:39:24 +1000 |
|---|---|---|
| committer | Victor Tran <vicr12345@gmail.com> | 2018-07-13 00:39:24 +1000 |
| commit | abc4021919f406ee25e101122144879f8770d51d (patch) | |
| tree | 9f835b216b8481e84fb988e495da42c1aa1aa20a /installer/process/installworker.cpp | |
| parent | 2adcd4f24eca2fa529c42fc1165319bcc4ea179e (diff) | |
| download | theInstaller-abc4021919f406ee25e101122144879f8770d51d.tar.gz theInstaller-abc4021919f406ee25e101122144879f8770d51d.tar.bz2 theInstaller-abc4021919f406ee25e101122144879f8770d51d.zip | |
Uninstall support
Diffstat (limited to 'installer/process/installworker.cpp')
| -rw-r--r-- | installer/process/installworker.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/installer/process/installworker.cpp b/installer/process/installworker.cpp index 48c7c10..5b44ad1 100644 --- a/installer/process/installworker.cpp +++ b/installer/process/installworker.cpp @@ -6,7 +6,7 @@ InstallWorker::InstallWorker(QObject *parent) : QObject(parent) bool InstallWorker::startWork() { QLocalSocket* sock = new QLocalSocket(); - QString vendor, name, url, destPath; + QString vendor, name, url, destPath, executable; bool isStableStream = true, isGlobalInstall = true; QString previousToken; @@ -22,10 +22,12 @@ bool InstallWorker::startWork() { url = arg; } else if (previousToken == "--destdir") { destPath = arg; + } else if (previousToken == "--executable") { + executable = arg; } previousToken = ""; } else { - if (arg == "--socket" || arg == "--vendor" || arg == "--name" || arg == "--url" || arg == "--destdir") { + if (arg == "--socket" || arg == "--vendor" || arg == "--name" || arg == "--url" || arg == "--destdir" || arg == "--executable") { previousToken = arg; } else if (arg == "--blueprint") { isStableStream = false; @@ -66,9 +68,51 @@ bool InstallWorker::startWork() { req.setHeader(QNetworkRequest::UserAgentHeader, "theInstaller/1.0"); QNetworkReply* reply = mgr.get(req); connect(reply, &QNetworkReply::finished, [=] { + packageFile.flush(); + packageFile.seek(0); + sock->write(QString("STATUS ").append(tr("Unpacking %1...").arg(name)).append("\n").toUtf8()); sock->write("PROGRESS 0 0\n"); sock->write(QString("DEBUG %1").arg(packageTemporaryDir.path()).toUtf8()); + + QDir::root().mkpath(destPath); + QDir dest(destPath); + + JlCompress::extractDir(packageFile.fileName(), destPath); + + sock->write(QString("STATUS ").append(tr("Configuring %1...").arg(name)).append("\n").toUtf8()); + + QDir startMenu; + if (isGlobalInstall) { + startMenu = QDir("C:/ProgramData/Microsoft/Windows/Start Menu/Programs"); + } else { + startMenu = QDir(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)); + } + startMenu.mkpath(vendor + "/" + name); + startMenu.cd(vendor + "/" + name); + + QFileInfo executableFile(destPath + "/" + executable); + QFile::link(executableFile.absoluteFilePath(), startMenu.absoluteFilePath(executableFile.completeBaseName() + ".lnk")); + QFile::copy(QApplication::applicationFilePath(), dest.absoluteFilePath("uninstall.exe")); + + QJsonObject dataRoot; + dataRoot.insert("vendor", vendor); + dataRoot.insert("name", name); + dataRoot.insert("installPath", destPath); + dataRoot.insert("global", isGlobalInstall); + dataRoot.insert("appurl", url); + + QFile uninstallDataFile(dest.absoluteFilePath("uninstall.json")); + uninstallDataFile.open(QFile::WriteOnly); + uninstallDataFile.write(QJsonDocument(dataRoot).toJson()); + + sock->write("COMPLETE\n"); + sock->flush(); + sock->waitForBytesWritten(); + QApplication::exit(0); + }); + connect(reply, &QNetworkReply::readyRead, [=] { + packageFile.write(reply->readAll()); }); connect(reply, &QNetworkReply::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal) { sock->write(QString("PROGRESS %1 %2\n").arg(QString::number(bytesReceived), QString::number(bytesTotal)).toUtf8()); |
