Merge pull request #16442 from danteruiz/fix-startmenu-icons

dev-2641: Uninstall does not show in the Windows Start Menu until the second launch of the app
This commit is contained in:
Shannon Romano 2019-11-05 11:38:06 -08:00 committed by GitHub
commit ab2f77ea8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 14 deletions

View file

@ -14,7 +14,16 @@
#include <QFileInfo> #include <QFileInfo>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QTime>
void timeDelay() {
static const int ONE_SECOND = 1;
QTime delayTime = QTime::currentTime().addSecs(ONE_SECOND);
while (QTime::currentTime() < delayTime) {
qDebug() << "Delaying time";
}
}
LauncherInstaller::LauncherInstaller() { LauncherInstaller::LauncherInstaller() {
_launcherInstallDir = PathUtils::getLauncherDirectory(); _launcherInstallDir = PathUtils::getLauncherDirectory();
_launcherApplicationsDir = PathUtils::getApplicationsDirectory(); _launcherApplicationsDir = PathUtils::getApplicationsDirectory();
@ -56,8 +65,8 @@ void LauncherInstaller::install() {
} }
deleteShortcuts(); deleteShortcuts();
createShortcuts();
deleteApplicationRegistryKeys(); deleteApplicationRegistryKeys();
createShortcuts();
createApplicationRegistryKeys(); createApplicationRegistryKeys();
} else { } else {
qDebug() << "Failed to install HQ Launcher"; qDebug() << "Failed to install HQ Launcher";
@ -67,26 +76,26 @@ void LauncherInstaller::install() {
void LauncherInstaller::createShortcuts() { void LauncherInstaller::createShortcuts() {
QString launcherPath = PathUtils::getLauncherFilePath(); QString launcherPath = PathUtils::getLauncherFilePath();
QString uninstallLinkPath = _launcherInstallDir.absoluteFilePath("Uninstall HQ.lnk"); QString uninstallLinkPath = _launcherInstallDir.absoluteFilePath("Uninstall HQ Launcher.lnk");
QDir desktopDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); QDir desktopDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
QString appStartLinkPath = _launcherApplicationsDir.absoluteFilePath("HQ Launcher.lnk"); QString appStartLinkPath = _launcherApplicationsDir.absoluteFilePath("HQ Launcher.lnk");
QString uninstallAppStartLinkPath = _launcherApplicationsDir.absoluteFilePath("Uninstall HQ.lnk"); QString uninstallAppStartLinkPath = _launcherApplicationsDir.absoluteFilePath("Uninstall HQ Launcher.lnk");
QString desktopAppLinkPath = desktopDir.absoluteFilePath("HQ Launcher.lnk"); QString desktopAppLinkPath = desktopDir.absoluteFilePath("HQ Launcher.lnk");
createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)uninstallLinkPath.toStdString().c_str(), createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)uninstallLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Uninstall HQ"), (LPCSTR)("--uninstall")); (LPCSTR)("Click to Uninstall HQ Launcher"), (LPCSTR)("--uninstall"));
createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)uninstallAppStartLinkPath.toStdString().c_str(), createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)uninstallAppStartLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Uninstall HQ"), (LPCSTR)("--uninstall")); (LPCSTR)("Click to Uninstall HQ Launcher"), (LPCSTR)("--uninstall"));
createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)desktopAppLinkPath.toStdString().c_str(), createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)desktopAppLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Setup and Launch HQ")); (LPCSTR)("Click to Setup and Launch HQ Launcher"));
createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)appStartLinkPath.toStdString().c_str(), createSymbolicLink((LPCSTR)launcherPath.toStdString().c_str(), (LPCSTR)appStartLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Setup and Launch HQ")); (LPCSTR)("Click to Setup and Launch HQ Launcher"));
} }
QString randomQtString() { QString randomQtString() {
@ -141,20 +150,42 @@ void LauncherInstaller::uninstall() {
qDebug() << "Failed to complete uninstall launcher"; qDebug() << "Failed to complete uninstall launcher";
} }
return; 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"); QString launcherPath = _launcherInstallDir.absoluteFilePath("HQ Launcher.exe");
if (QFile::exists(launcherPath)) { while (deleteAttempts < MAX_DELETE_ATTEMPTS) {
bool removed = QFile::remove(launcherPath); fileRemoved = QFile::remove(launcherPath);
qDebug() << "Successfully removed " << launcherPath << ": " << removed; if (fileRemoved) {
break;
}
timeDelay();
deleteAttempts++;
} }
deleteApplicationRegistryKeys();
qDebug() << "Successfully removed " << launcherPath << ": " << fileRemoved;
return fileRemoved;
} }
void LauncherInstaller::deleteShortcuts() { void LauncherInstaller::deleteShortcuts() {
QDir desktopDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); QDir desktopDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
QString applicationPath = _launcherApplicationsDir.absolutePath(); QString applicationPath = _launcherApplicationsDir.absolutePath();
QString uninstallLinkPath = _launcherInstallDir.absoluteFilePath("Uninstall HQ.lnk"); QString uninstallLinkPath = _launcherInstallDir.absoluteFilePath("Uninstall HQ Launcher.lnk");
if (QFile::exists(uninstallLinkPath)) { if (QFile::exists(uninstallLinkPath)) {
QFile::remove(uninstallLinkPath); QFile::remove(uninstallLinkPath);
} }
@ -164,7 +195,7 @@ void LauncherInstaller::deleteShortcuts() {
QFile::remove(appStartLinkPath); QFile::remove(appStartLinkPath);
} }
QString uninstallAppStartLinkPath = _launcherApplicationsDir.absoluteFilePath("Uninstall HQ.lnk"); QString uninstallAppStartLinkPath = _launcherApplicationsDir.absoluteFilePath("Uninstall HQ Launcher.lnk");
if (QFile::exists(uninstallAppStartLinkPath)) { if (QFile::exists(uninstallAppStartLinkPath)) {
QFile::remove(uninstallAppStartLinkPath); QFile::remove(uninstallAppStartLinkPath);
} }
@ -212,7 +243,7 @@ void LauncherInstaller::uninstallOldLauncher() {
void LauncherInstaller::createApplicationRegistryKeys() { void LauncherInstaller::createApplicationRegistryKeys() {
const std::string REGISTRY_PATH = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\HQ"; const std::string REGISTRY_PATH = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\HQ";
bool success = insertRegistryKey(REGISTRY_PATH, "DisplayName", "HQ"); bool success = insertRegistryKey(REGISTRY_PATH, "DisplayName", "HQ Launcher");
std::string installPath = _launcherInstallDir.absolutePath().replace("/", "\\").toStdString(); std::string installPath = _launcherInstallDir.absolutePath().replace("/", "\\").toStdString();
success = insertRegistryKey(REGISTRY_PATH, "InstallLocation", installPath); success = insertRegistryKey(REGISTRY_PATH, "InstallLocation", installPath);
std::string applicationExe = installPath + "\\HQ Launcher.exe"; std::string applicationExe = installPath + "\\HQ Launcher.exe";

View file

@ -15,6 +15,7 @@ private:
void createApplicationRegistryKeys(); void createApplicationRegistryKeys();
void deleteShortcuts(); void deleteShortcuts();
void deleteApplicationRegistryKeys(); void deleteApplicationRegistryKeys();
bool deleteHQLauncherExecutable();
QDir _launcherInstallDir; QDir _launcherInstallDir;
QDir _launcherApplicationsDir; QDir _launcherApplicationsDir;