Fix installation for Windows and MacOS
This commit is contained in:
parent
6a21994736
commit
3b300a203f
1 changed files with 75 additions and 13 deletions
|
|
@ -386,15 +386,46 @@ int IpcServer::installApp(const QString &path)
|
||||||
qDebug() << "Installing app from:" << path;
|
qDebug() << "Installing app from:" << path;
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
// On Windows, simply run the .exe file with administrator privileges
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProgram("powershell.exe");
|
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
||||||
process.setArguments(QStringList() << "Start-Process" << path << "-Verb"
|
QString extractDir = tempDir + "/amnezia_update";
|
||||||
|
|
||||||
|
// Create extraction directory if it doesn't exist
|
||||||
|
QDir dir(extractDir);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkpath(".");
|
||||||
|
qDebug() << "Created extraction directory";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract ZIP archive
|
||||||
|
qDebug() << "Extracting ZIP archive...";
|
||||||
|
process.start("powershell.exe",
|
||||||
|
QStringList() << "Expand-Archive"
|
||||||
|
<< "-Path" << path << "-DestinationPath" << extractDir << "-Force");
|
||||||
|
process.waitForFinished();
|
||||||
|
|
||||||
|
if (process.exitCode() != 0) {
|
||||||
|
qDebug() << "ZIP extraction error:" << process.readAllStandardError();
|
||||||
|
return process.exitCode();
|
||||||
|
}
|
||||||
|
qDebug() << "ZIP archive extracted successfully";
|
||||||
|
|
||||||
|
// Find .exe file in extracted directory
|
||||||
|
QDirIterator it(extractDir, QStringList() << "*.exe", QDir::Files, QDirIterator::Subdirectories);
|
||||||
|
if (!it.hasNext()) {
|
||||||
|
qDebug() << "No .exe file found in the extracted archive";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString installerPath = it.next();
|
||||||
|
qDebug() << "Found installer:" << installerPath;
|
||||||
|
|
||||||
|
// Run installer with elevated privileges
|
||||||
|
qDebug() << "Launching installer with elevated privileges...";
|
||||||
|
process.start("powershell.exe",
|
||||||
|
QStringList() << "Start-Process" << installerPath << "-Verb"
|
||||||
<< "RunAs"
|
<< "RunAs"
|
||||||
<< "-Wait");
|
<< "-Wait");
|
||||||
|
|
||||||
qDebug() << "Launching installer with elevated privileges...";
|
|
||||||
process.start();
|
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
|
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
|
|
@ -403,21 +434,48 @@ int IpcServer::installApp(const QString &path)
|
||||||
return process.exitCode();
|
return process.exitCode();
|
||||||
|
|
||||||
#elif defined(Q_OS_MACOS)
|
#elif defined(Q_OS_MACOS)
|
||||||
// DRAFT
|
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
||||||
|
QString extractDir = tempDir + "/amnezia_update";
|
||||||
|
|
||||||
|
// Create extraction directory
|
||||||
|
QDir dir(extractDir);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkpath(".");
|
||||||
|
qDebug() << "Created extraction directory";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract ZIP archive using unzip command
|
||||||
|
qDebug() << "Extracting ZIP archive...";
|
||||||
|
process.start("unzip", QStringList() << path << "-d" << extractDir);
|
||||||
|
process.waitForFinished();
|
||||||
|
|
||||||
|
if (process.exitCode() != 0) {
|
||||||
|
qDebug() << "ZIP extraction error:" << process.readAllStandardError();
|
||||||
|
return process.exitCode();
|
||||||
|
}
|
||||||
|
qDebug() << "ZIP archive extracted successfully";
|
||||||
|
|
||||||
|
// Find .dmg file in extracted directory
|
||||||
|
QDirIterator it(extractDir, QStringList() << "*.dmg", QDir::Files, QDirIterator::Subdirectories);
|
||||||
|
if (!it.hasNext()) {
|
||||||
|
qDebug() << "No .dmg file found in the extracted archive";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString dmgPath = it.next();
|
||||||
|
qDebug() << "Found DMG file:" << dmgPath;
|
||||||
QString mountPoint = tempDir + "/AmneziaVPN_mount";
|
QString mountPoint = tempDir + "/AmneziaVPN_mount";
|
||||||
|
|
||||||
// Create mount point
|
// Create mount point
|
||||||
QDir dir(mountPoint);
|
dir = QDir(mountPoint);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkpath(".");
|
dir.mkpath(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount DMG image
|
// Mount DMG image
|
||||||
qDebug() << "Mounting DMG image...";
|
qDebug() << "Mounting DMG image...";
|
||||||
process.start("hdiutil", QStringList() << "attach" << path << "-mountpoint" << mountPoint << "-nobrowse");
|
process.start("hdiutil", QStringList() << "attach" << dmgPath << "-mountpoint" << mountPoint << "-nobrowse");
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
|
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
|
|
@ -426,13 +484,13 @@ int IpcServer::installApp(const QString &path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for .app bundle in mounted image
|
// Look for .app bundle in mounted image
|
||||||
QDirIterator it(mountPoint, QStringList() << "*.app", QDir::Dirs);
|
QDirIterator appIt(mountPoint, QStringList() << "*.app", QDir::Dirs);
|
||||||
if (!it.hasNext()) {
|
if (!appIt.hasNext()) {
|
||||||
qDebug() << "No .app bundle found in DMG";
|
qDebug() << "No .app bundle found in DMG";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString appPath = it.next();
|
QString appPath = appIt.next();
|
||||||
QString targetPath = "/Applications/" + QFileInfo(appPath).fileName();
|
QString targetPath = "/Applications/" + QFileInfo(appPath).fileName();
|
||||||
|
|
||||||
// Copy application to /Applications
|
// Copy application to /Applications
|
||||||
|
|
@ -448,6 +506,10 @@ int IpcServer::installApp(const QString &path)
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
qDebug() << "Installation error:" << process.readAllStandardError();
|
qDebug() << "Installation error:" << process.readAllStandardError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
QDir(extractDir).removeRecursively();
|
||||||
|
|
||||||
return process.exitCode();
|
return process.exitCode();
|
||||||
|
|
||||||
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue