From c8dade2060f6c119c1af858d299db9863f2d037b Mon Sep 17 00:00:00 2001
From: danteruiz <danteruiz102@gmail.com>
Date: Mon, 4 Nov 2019 15:20:37 -0800
Subject: [PATCH] making requested changes

---
 .../qt/src/LauncherInstaller_windows.cpp      | 38 +++++++++++++------
 launchers/qt/src/LauncherInstaller_windows.h  |  1 +
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/launchers/qt/src/LauncherInstaller_windows.cpp b/launchers/qt/src/LauncherInstaller_windows.cpp
index a166074c01..b5558f972c 100644
--- a/launchers/qt/src/LauncherInstaller_windows.cpp
+++ b/launchers/qt/src/LauncherInstaller_windows.cpp
@@ -150,19 +150,35 @@ void LauncherInstaller::uninstall() {
             qDebug() << "Failed to complete uninstall launcher";
         }
         return;
+    } else {
+
+        bool deletedHQLauncherExe = deleteHQLauncherExecutable();
+        if (deletedHQLauncherExe) {
+            qDebug() << "Deleteing registry keys";
+            deleteApplicationRegistryKeys();
+        }
+    }
+}
+
+bool LauncherInstaller::deleteHQLauncherExecutable() {
+    static const int MAX_DELETE_ATTEMPTS = 3;
+
+    int deleteAttempts = 0;
+    bool fileRemoved = false;
+    QString launcherPath = _launcherInstallDir.absoluteFilePath("HQ Launcher.exe");
+    while (deleteAttempts < MAX_DELETE_ATTEMPTS) {
+        fileRemoved = QFile::remove(launcherPath);
+        if (fileRemoved) {
+            break;
+        }
+
+        timeDelay();
+        deleteAttempts++;
     }
 
-    if (options->contains("--resumeUninstall")) {
-        // delaying time here to make sure that the previous process exits
-        // before we try to delete it the file.
-        timeDelay();
-    }
-    QString launcherPath = _launcherInstallDir.absoluteFilePath("HQ Launcher.exe");
-    if (QFile::exists(launcherPath)) {
-        bool removed = QFile::remove(launcherPath);
-        qDebug() << "Successfully removed " << launcherPath << ": " << removed;
-    }
-    deleteApplicationRegistryKeys();
+    qDebug() << "Successfully removed " << launcherPath << ": " << fileRemoved;
+
+    return fileRemoved;
 }
 
 void LauncherInstaller::deleteShortcuts() {
diff --git a/launchers/qt/src/LauncherInstaller_windows.h b/launchers/qt/src/LauncherInstaller_windows.h
index ffb402cce5..e06cbc4b40 100644
--- a/launchers/qt/src/LauncherInstaller_windows.h
+++ b/launchers/qt/src/LauncherInstaller_windows.h
@@ -15,6 +15,7 @@ private:
     void createApplicationRegistryKeys();
     void deleteShortcuts();
     void deleteApplicationRegistryKeys();
+    bool deleteHQLauncherExecutable();
 
     QDir _launcherInstallDir;
     QDir _launcherApplicationsDir;