install and uninstall features

This commit is contained in:
danteruiz 2019-09-27 15:31:44 -07:00
parent 836e23f5cf
commit e8205728ce
4 changed files with 62 additions and 6 deletions

View file

@ -17,5 +17,5 @@ bool replaceDirectory(const QString& orginalDirectory, const QString& newDirecto
#endif
#ifdef Q_OS_WIN
HRESULT createSymbolicLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs);
HRESULT createSymbolicLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs = (LPCSTR)"");
#endif

View file

@ -10,8 +10,11 @@
LauncherInstaller::LauncherInstaller(const QString& applicationFilePath) {
_launcherInstallDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/HQ";
_launcherApplicationsDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/HQ";
qDebug() << "Launcher install dir: " << _launcherInstallDir.absolutePath();
qDebug() << "Launcher Application dir: " << _launcherApplicationsDir.absolutePath();
_launcherInstallDir.mkpath(_launcherInstallDir.absolutePath());
_launcherApplicationsDir.mkpath(_launcherApplicationsDir.absolutePath());
QFileInfo fileInfo(applicationFilePath);
_launcherRunningFilePath = fileInfo.absoluteFilePath();
_launcherRunningDirPath = fileInfo.absoluteDir().absolutePath();
@ -24,6 +27,7 @@ bool LauncherInstaller::runningOutsideOfInstallDir() {
}
void LauncherInstaller::install() {
//qDebug() << "Is install dir empty: " << _launcherInstallDir.isEmpty();
if (runningOutsideOfInstallDir()) {
qDebug() << "Installing HQ Launcher....";
QString oldLauncherPath = _launcherInstallDir.absolutePath() + "/HQ Launcher.exe";
@ -40,14 +44,59 @@ void LauncherInstaller::install() {
}
qDebug() << "LauncherInstaller: create uninstall link";
QString uninstallLinkPath = _launcherInstallDir.absolutePath() + "/Uninstall HQ.link";
QString uninstallLinkPath = _launcherInstallDir.absolutePath() + "/Uninstall HQ.lnk";
if (QFile::exists(uninstallLinkPath)) {
QFile::remove(uninstallLinkPath);
}
QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
QString applicationPath = _launcherApplicationsDir.absolutePath();
QString appStartLinkPath = applicationPath + "/HQ.lnk";
QString uninstallAppStartLinkPath = applicationPath + "/Uninstall HQ.lnk";
QString desktopAppLinkPath = desktopPath + "/HQ.lnk";
createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)uninstallLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Uninstall HQ"), (LPCSTR)("--uninstall"));
createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)uninstallAppStartLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Uninstall HQ"), (LPCSTR)("--uninstall"));
createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)desktopAppLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Setup and Launch HQ"));
createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)appStartLinkPath.toStdString().c_str(),
(LPCSTR)("Click to Setup and Launch HQ"));
} else {
qDebug() << "FAILED!!!!!!!";
}
}
void LauncherInstaller::uninstall() {}
void LauncherInstaller::uninstall() {
qDebug() << "Uninstall Launcher";
QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
QString applicationPath = _launcherApplicationsDir.absolutePath();
QString uninstallLinkPath = _launcherInstallDir.absolutePath() + "/Uninstall HQ.lnk";
if (QFile::exists(uninstallLinkPath)) {
QFile::remove(uninstallLinkPath);
}
QString appStartLinkPath = applicationPath + "/HQ.lnk";
if (QFile::exists(appStartLinkPath)) {
QFile::remove(appStartLinkPath);
}
QString uninstallAppStartLinkPath = applicationPath + "/Uninstall HQ.lnk";
if (QFile::exists(uninstallAppStartLinkPath)) {
QFile::remove(uninstallAppStartLinkPath);
}
QString desktopAppLinkPath = desktopPath + "/HQ.lnk";
if (QFile::exists(desktopAppLinkPath)) {
QFile::remove(desktopAppLinkPath);
}
}

View file

@ -8,9 +8,13 @@ public:
void install();
void uninstall();
private:
bool runningOutsideOfInstallDir();
private:
void createShortcuts();
void deleteShortcuts();
QDir _launcherInstallDir;
QDir _launcherApplicationsDir;
QString _launcherRunningFilePath;
QString _launcherRunningDirPath;
};

View file

@ -40,9 +40,12 @@ int main(int argc, char *argv[]) {
CommandlineOptions* options = CommandlineOptions::getInstance();
options->parse(argc, argv);
#ifdef Q_OS_WIN
if (options->contains("--restart")) {
LauncherInstaller launcherInstaller(argv[0]);
LauncherInstaller launcherInstaller(argv[0]);
if (options->contains("--restart") || launcherInstaller.runningOutsideOfInstallDir()) {
launcherInstaller.install();
} else if (options->contains("--uninstall")) {
launcherInstaller.uninstall();
return 0;
}
#endif
QString name { "High Fidelity" };