aboutsummaryrefslogtreecommitdiff
path: root/installer/process/removeworker.cpp
diff options
context:
space:
mode:
authorVictor Tran <vicr12345@gmail.com>2018-07-13 00:39:24 +1000
committerVictor Tran <vicr12345@gmail.com>2018-07-13 00:39:24 +1000
commitabc4021919f406ee25e101122144879f8770d51d (patch)
tree9f835b216b8481e84fb988e495da42c1aa1aa20a /installer/process/removeworker.cpp
parent2adcd4f24eca2fa529c42fc1165319bcc4ea179e (diff)
downloadtheInstaller-abc4021919f406ee25e101122144879f8770d51d.tar.gz
theInstaller-abc4021919f406ee25e101122144879f8770d51d.tar.bz2
theInstaller-abc4021919f406ee25e101122144879f8770d51d.zip
Uninstall support
Diffstat (limited to 'installer/process/removeworker.cpp')
-rw-r--r--installer/process/removeworker.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/installer/process/removeworker.cpp b/installer/process/removeworker.cpp
new file mode 100644
index 0000000..bdc1f64
--- /dev/null
+++ b/installer/process/removeworker.cpp
@@ -0,0 +1,75 @@
+#include "removeworker.h"
+
+RemoveWorker::RemoveWorker(QObject *parent) : QObject(parent)
+{
+
+}
+
+bool RemoveWorker::startWork() {
+ QLocalSocket* sock = new QLocalSocket();
+
+ QString previousToken;
+ for (QString arg : QApplication::arguments()) {
+ if (previousToken != "") {
+ if (previousToken == "--socket") {
+ sock->setServerName(arg);
+ }
+ previousToken = "";
+ } else {
+ if (arg == "--socket") {
+ previousToken = arg;
+ }
+ }
+ }
+
+ if (sock->serverName() == "") {
+ qDebug() << "Required argument --socket missing";
+ return false;
+ }
+
+ qDebug() << "Connecting to socket server...";
+ sock->connectToServer();
+ if (!sock->waitForConnected()) {
+ qDebug() << "Failed to connect to socket server";
+ return false;
+ }
+ connect(sock, &QLocalSocket::disconnected, [=] {
+ qDebug() << "Socket closed";
+ QApplication::exit(1);
+ });
+
+ QFile metadataFile(QApplication::applicationDirPath() + "/uninstall.json");
+ metadataFile.open(QFile::ReadOnly);
+ QJsonObject metadata = QJsonDocument::fromJson(metadataFile.readAll()).object();
+
+ QString name = metadata.value("name").toString();
+ QString vendor = metadata.value("vendor").toString();
+
+ sock->write(QString("STATUS ").append(tr("Removing %1...").arg(name)).append("\n").toUtf8());
+
+ //Remove Start menu entry
+ QDir startMenu;
+ if (metadata.value("global").toBool()) {
+ startMenu = QDir("C:/ProgramData/Microsoft/Windows/Start Menu/Programs");
+ } else {
+ startMenu = QDir(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation));
+ }
+ startMenu.cd(vendor + "/" + name);
+ startMenu.removeRecursively();
+ startMenu.cdUp();
+ if (startMenu.entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs).count() == 0) {
+ startMenu.removeRecursively();
+ }
+
+ //Remove items in installation directory
+ QDir dest(metadata.value("installPath").toString());
+ dest.removeRecursively();
+
+ sock->write("COMPLETE\n");
+ sock->flush();
+ sock->waitForBytesWritten();
+ QTimer::singleShot(0, [=] {
+ QApplication::exit(0);
+ });
+ return 0;
+}