Add some logs
This commit is contained in:
parent
9df9314e73
commit
a73234ec2a
1 changed files with 33 additions and 102 deletions
|
|
@ -383,133 +383,67 @@ int IpcServer::mountDmg(const QString &path, bool mount)
|
||||||
|
|
||||||
int IpcServer::installApp(const QString &path)
|
int IpcServer::installApp(const QString &path)
|
||||||
{
|
{
|
||||||
qDebug() << "Installing app from:" << path;
|
Logger logger("IpcServer");
|
||||||
|
logger.info() << "Installing app from:" << path;
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
QProcess process;
|
QProcess process;
|
||||||
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
logger.info() << "Launching installer with elevated privileges...";
|
||||||
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",
|
process.start("powershell.exe",
|
||||||
QStringList() << "Expand-Archive"
|
QStringList() << "Start-Process" << path << "-Verb"
|
||||||
<< "-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");
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
|
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
qDebug() << "Installation error:" << process.readAllStandardError();
|
logger.error() << "Installation error:" << process.readAllStandardError();
|
||||||
}
|
}
|
||||||
return process.exitCode();
|
return process.exitCode();
|
||||||
|
|
||||||
#elif defined(Q_OS_MACOS)
|
#elif defined(Q_OS_MACOS)
|
||||||
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
|
||||||
dir = QDir(mountPoint);
|
QDir dir(mountPoint);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkpath(".");
|
dir.mkpath(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount DMG image
|
// Mount DMG image
|
||||||
qDebug() << "Mounting DMG image...";
|
logger.info() << "Mounting DMG image...";
|
||||||
process.start("hdiutil", QStringList() << "attach" << dmgPath << "-mountpoint" << mountPoint << "-nobrowse");
|
process.start("hdiutil", QStringList() << "attach" << path << "-mountpoint" << mountPoint << "-nobrowse");
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
|
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
qDebug() << "Failed to mount DMG:" << process.readAllStandardError();
|
logger.error() << "Failed to mount DMG:" << process.readAllStandardError();
|
||||||
return process.exitCode();
|
return process.exitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for .app bundle in mounted image
|
// Look for .app bundle in mounted image
|
||||||
QDirIterator appIt(mountPoint, QStringList() << "*.app", QDir::Dirs);
|
QDirIterator it(mountPoint, QStringList() << "*.app", QDir::Dirs);
|
||||||
if (!appIt.hasNext()) {
|
if (!it.hasNext()) {
|
||||||
qDebug() << "No .app bundle found in DMG";
|
logger.error() << "No .app bundle found in DMG";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString appPath = appIt.next();
|
QString appPath = it.next();
|
||||||
QString targetPath = "/Applications/" + QFileInfo(appPath).fileName();
|
QString targetPath = "/Applications/" + QFileInfo(appPath).fileName();
|
||||||
|
|
||||||
// Copy application to /Applications
|
// Copy application to /Applications
|
||||||
qDebug() << "Copying app to Applications folder...";
|
logger.info() << "Copying app to Applications folder...";
|
||||||
process.start("cp", QStringList() << "-R" << appPath << targetPath);
|
process.start("cp", QStringList() << "-R" << appPath << targetPath);
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
|
|
||||||
// Unmount DMG
|
// Unmount DMG
|
||||||
qDebug() << "Unmounting DMG...";
|
logger.info() << "Unmounting DMG...";
|
||||||
process.start("hdiutil", QStringList() << "detach" << mountPoint);
|
process.start("hdiutil", QStringList() << "detach" << mountPoint);
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
|
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
qDebug() << "Installation error:" << process.readAllStandardError();
|
logger.error() << "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)
|
||||||
|
|
@ -517,67 +451,64 @@ int IpcServer::installApp(const QString &path)
|
||||||
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
||||||
QString extractDir = tempDir + "/amnezia_update";
|
QString extractDir = tempDir + "/amnezia_update";
|
||||||
|
|
||||||
qDebug() << "Installing app from:" << path;
|
logger.info() << "Using temp directory:" << extractDir;
|
||||||
qDebug() << "Using temp directory:" << extractDir;
|
|
||||||
|
|
||||||
// Create extraction directory if it doesn't exist
|
// Create extraction directory if it doesn't exist
|
||||||
QDir dir(extractDir);
|
QDir dir(extractDir);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
dir.mkpath(".");
|
dir.mkpath(".");
|
||||||
qDebug() << "Created extraction directory";
|
logger.info() << "Created extraction directory";
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, extract the zip archive
|
// First, extract the zip archive
|
||||||
qDebug() << "Extracting ZIP archive...";
|
logger.info() << "Extracting ZIP archive...";
|
||||||
process.start("unzip", QStringList() << path << "-d" << extractDir);
|
process.start("unzip", QStringList() << path << "-d" << extractDir);
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
qDebug() << "ZIP extraction error:" << process.readAllStandardError();
|
logger.error() << "ZIP extraction error:" << process.readAllStandardError();
|
||||||
return process.exitCode();
|
return process.exitCode();
|
||||||
}
|
}
|
||||||
qDebug() << "ZIP archive extracted successfully";
|
logger.info() << "ZIP archive extracted successfully";
|
||||||
|
|
||||||
// Look for tar file in extracted files
|
// Look for tar file in extracted files
|
||||||
qDebug() << "Looking for TAR file...";
|
logger.info() << "Looking for TAR file...";
|
||||||
QDirIterator tarIt(extractDir, QStringList() << "*.tar", QDir::Files);
|
QDirIterator tarIt(extractDir, QStringList() << "*.tar", QDir::Files);
|
||||||
if (!tarIt.hasNext()) {
|
if (!tarIt.hasNext()) {
|
||||||
qDebug() << "TAR file not found in the extracted archive";
|
logger.error() << "TAR file not found in the extracted archive";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract found tar archive
|
// Extract found tar archive
|
||||||
QString tarPath = tarIt.next();
|
QString tarPath = tarIt.next();
|
||||||
qDebug() << "Found TAR file:" << tarPath;
|
logger.info() << "Found TAR file:" << tarPath;
|
||||||
qDebug() << "Extracting TAR archive...";
|
logger.info() << "Extracting TAR archive...";
|
||||||
|
|
||||||
process.start("tar", QStringList() << "-xf" << tarPath << "-C" << extractDir);
|
process.start("tar", QStringList() << "-xf" << tarPath << "-C" << extractDir);
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
if (process.exitCode() != 0) {
|
if (process.exitCode() != 0) {
|
||||||
qDebug() << "TAR extraction error:" << process.readAllStandardError();
|
logger.error() << "TAR extraction error:" << process.readAllStandardError();
|
||||||
return process.exitCode();
|
return process.exitCode();
|
||||||
}
|
}
|
||||||
qDebug() << "TAR archive extracted successfully";
|
logger.info() << "TAR archive extracted successfully";
|
||||||
|
|
||||||
// Remove tar file as it's no longer needed
|
// Remove tar file as it's no longer needed
|
||||||
QFile::remove(tarPath);
|
QFile::remove(tarPath);
|
||||||
qDebug() << "Removed temporary TAR file";
|
logger.info() << "Removed temporary TAR file";
|
||||||
|
|
||||||
// Find executable file and run it
|
// Find executable file and run it
|
||||||
qDebug() << "Looking for executable file...";
|
logger.info() << "Looking for executable file...";
|
||||||
QDirIterator it(extractDir, QDir::Files | QDir::Executable, QDirIterator::Subdirectories);
|
QDirIterator it(extractDir, QDir::Files | QDir::Executable, QDirIterator::Subdirectories);
|
||||||
if (it.hasNext()) {
|
if (it.hasNext()) {
|
||||||
QString execPath = it.next();
|
QString execPath = it.next();
|
||||||
qDebug() << "Found executable:" << execPath;
|
logger.info() << "Found executable:" << execPath;
|
||||||
qDebug() << "Launching installer...";
|
logger.info() << "Launching installer...";
|
||||||
process.start("sudo", QStringList() << execPath);
|
process.start("sudo", QStringList() << execPath);
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
qDebug() << "Installer stdout:" << process.readAllStandardOutput();
|
logger.info() << "Installer finished with exit code:" << process.exitCode();
|
||||||
qDebug() << "Installer stderr:" << process.readAllStandardError();
|
|
||||||
qDebug() << "Installer finished with exit code:" << process.exitCode();
|
|
||||||
return process.exitCode();
|
return process.exitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "No executable file found";
|
logger.error() << "No executable file found";
|
||||||
return -1; // Executable not found
|
return -1; // Executable not found
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue