From e748ac35c9cf8c7aafe77eb4a1b093e110f83f96 Mon Sep 17 00:00:00 2001 From: aiamnezia Date: Tue, 10 Dec 2024 18:14:34 +0400 Subject: [PATCH] Add service side of installation logic for Windows --- ipc/ipcserver.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/ipc/ipcserver.cpp b/ipc/ipcserver.cpp index 67650221..d02fe56a 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -380,7 +380,87 @@ int IpcServer::mountDmg(const QString &path, bool mount) int IpcServer::installApp(const QString &path) { -#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + qDebug() << "Installing app from:" << path; + +#ifdef Q_OS_WINDOWS + // On Windows, simply run the .exe file with administrator privileges + QProcess process; + process.setProgram("powershell.exe"); + process.setArguments(QStringList() + << "Start-Process" + << path + << "-Verb" + << "RunAs" + << "-Wait"); + + qDebug() << "Launching installer with elevated privileges..."; + process.start(); + process.waitForFinished(); + + if (process.exitCode() != 0) { + qDebug() << "Installation error:" << process.readAllStandardError(); + } + return process.exitCode(); + +#elif defined(Q_OS_MACOS) + // DRAFT + + QProcess process; + QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + QString mountPoint = tempDir + "/AmneziaVPN_mount"; + + // Create mount point + QDir dir(mountPoint); + if (!dir.exists()) { + dir.mkpath("."); + } + + // Mount DMG image + qDebug() << "Mounting DMG image..."; + process.start("hdiutil", QStringList() + << "attach" + << path + << "-mountpoint" + << mountPoint + << "-nobrowse"); + process.waitForFinished(); + + if (process.exitCode() != 0) { + qDebug() << "Failed to mount DMG:" << process.readAllStandardError(); + return process.exitCode(); + } + + // Look for .app bundle in mounted image + QDirIterator it(mountPoint, QStringList() << "*.app", QDir::Dirs); + if (!it.hasNext()) { + qDebug() << "No .app bundle found in DMG"; + return -1; + } + + QString appPath = it.next(); + QString targetPath = "/Applications/" + QFileInfo(appPath).fileName(); + + // Copy application to /Applications + qDebug() << "Copying app to Applications folder..."; + process.start("cp", QStringList() + << "-R" + << appPath + << targetPath); + process.waitForFinished(); + + // Unmount DMG + qDebug() << "Unmounting DMG..."; + process.start("hdiutil", QStringList() + << "detach" + << mountPoint); + process.waitForFinished(); + + if (process.exitCode() != 0) { + qDebug() << "Installation error:" << process.readAllStandardError(); + } + return process.exitCode(); + +#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) QProcess process; QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); QString extractDir = tempDir + "/amnezia_update";