Fix formatting

This commit is contained in:
aiamnezia 2024-12-10 19:04:11 +04:00
parent 9e7cf7fa1f
commit 6a21994736
4 changed files with 50 additions and 56 deletions

View file

@ -9,7 +9,8 @@
#include "core/errorstrings.h" #include "core/errorstrings.h"
#include "version.h" #include "version.h"
namespace { namespace
{
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
const QString installerPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/AmneziaVPN.dmg"; const QString installerPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/AmneziaVPN.dmg";
#elif defined Q_OS_WINDOWS #elif defined Q_OS_WINDOWS
@ -19,7 +20,8 @@ namespace {
#endif #endif
} }
UpdateController::UpdateController(const std::shared_ptr<Settings> &settings, QObject *parent) : QObject(parent), m_settings(settings) UpdateController::UpdateController(const std::shared_ptr<Settings> &settings, QObject *parent)
: QObject(parent), m_settings(settings)
{ {
} }
@ -62,19 +64,19 @@ void UpdateController::checkForUpdates()
for (auto asset : assets) { for (auto asset : assets) {
QJsonObject assetObject = asset.toObject(); QJsonObject assetObject = asset.toObject();
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
if (assetObject.value("name").toString().endsWith(".exe")) { if (assetObject.value("name").toString().endsWith(".exe")) {
m_downloadUrl = assetObject.value("browser_download_url").toString(); m_downloadUrl = assetObject.value("browser_download_url").toString();
} }
#elif defined(Q_OS_MACOS) #elif defined(Q_OS_MACOS)
if (assetObject.value("name").toString().endsWith(".dmg")) { if (assetObject.value("name").toString().endsWith(".dmg")) {
m_downloadUrl = assetObject.value("browser_download_url").toString(); m_downloadUrl = assetObject.value("browser_download_url").toString();
} }
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) #elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
if (assetObject.value("name").toString().contains(".tar.zip")) { if (assetObject.value("name").toString().contains(".tar.zip")) {
m_downloadUrl = assetObject.value("browser_download_url").toString(); m_downloadUrl = assetObject.value("browser_download_url").toString();
} }
#endif #endif
} }
emit updateFound(); emit updateFound();
@ -141,5 +143,4 @@ void UpdateController::runInstaller()
reply->deleteLater(); reply->deleteLater();
}); });
} }

View file

@ -22,6 +22,7 @@ public slots:
signals: signals:
void updateFound(); void updateFound();
void errorOccured(const QString &errorMessage); void errorOccured(const QString &errorMessage);
private: private:
std::shared_ptr<Settings> m_settings; std::shared_ptr<Settings> m_settings;

View file

@ -9,8 +9,8 @@
#include "logger.h" #include "logger.h"
#include "router.h" #include "router.h"
#include "../core/networkUtilities.h"
#include "../client/protocols/protocols_defs.h" #include "../client/protocols/protocols_defs.h"
#include "../core/networkUtilities.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include "../client/platforms/windows/daemon/windowsdaemon.h" #include "../client/platforms/windows/daemon/windowsdaemon.h"
#include "../client/platforms/windows/daemon/windowsfirewall.h" #include "../client/platforms/windows/daemon/windowsfirewall.h"
@ -60,12 +60,15 @@ int IpcServer::createPrivilegedProcess()
} }
}); });
QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::error, this, QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::error, this, [pd](QRemoteObjectNode::ErrorCode errorCode) {
[pd](QRemoteObjectNode::ErrorCode errorCode) { qDebug() << "QRemoteObjectHost::error" << errorCode; }); qDebug() << "QRemoteObjectHost::error" << errorCode;
});
QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::destroyed, this, [pd]() { qDebug() << "QRemoteObjectHost::destroyed"; }); QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::destroyed, this,
[pd]() { qDebug() << "QRemoteObjectHost::destroyed"; });
// connect(pd.ipcProcess.data(), &IpcServerProcess::finished, this, [this, pid=m_localpid](int exitCode, QProcess::ExitStatus exitStatus){ // connect(pd.ipcProcess.data(), &IpcServerProcess::finished, this, [this, pid=m_localpid](int exitCode,
// QProcess::ExitStatus exitStatus){
// qDebug() << "IpcServerProcess finished" << exitCode << exitStatus; // qDebug() << "IpcServerProcess finished" << exitCode << exitStatus;
//// if (m_processes.contains(pid)) { //// if (m_processes.contains(pid)) {
//// m_processes[pid].ipcProcess.reset(); //// m_processes[pid].ipcProcess.reset();
@ -386,17 +389,14 @@ int IpcServer::installApp(const QString &path)
// On Windows, simply run the .exe file with administrator privileges // On Windows, simply run the .exe file with administrator privileges
QProcess process; QProcess process;
process.setProgram("powershell.exe"); process.setProgram("powershell.exe");
process.setArguments(QStringList() process.setArguments(QStringList() << "Start-Process" << path << "-Verb"
<< "Start-Process" << "RunAs"
<< path << "-Wait");
<< "-Verb"
<< "RunAs"
<< "-Wait");
qDebug() << "Launching installer with elevated privileges..."; qDebug() << "Launching installer with elevated privileges...";
process.start(); process.start();
process.waitForFinished(); process.waitForFinished();
if (process.exitCode() != 0) { if (process.exitCode() != 0) {
qDebug() << "Installation error:" << process.readAllStandardError(); qDebug() << "Installation error:" << process.readAllStandardError();
} }
@ -404,57 +404,47 @@ int IpcServer::installApp(const QString &path)
#elif defined(Q_OS_MACOS) #elif defined(Q_OS_MACOS)
// DRAFT // DRAFT
QProcess process; QProcess process;
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
QString mountPoint = tempDir + "/AmneziaVPN_mount"; QString mountPoint = tempDir + "/AmneziaVPN_mount";
// Create mount point // Create mount point
QDir dir(mountPoint); QDir dir(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() process.start("hdiutil", QStringList() << "attach" << path << "-mountpoint" << mountPoint << "-nobrowse");
<< "attach"
<< path
<< "-mountpoint"
<< mountPoint
<< "-nobrowse");
process.waitForFinished(); process.waitForFinished();
if (process.exitCode() != 0) { if (process.exitCode() != 0) {
qDebug() << "Failed to mount DMG:" << process.readAllStandardError(); qDebug() << "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 it(mountPoint, QStringList() << "*.app", QDir::Dirs); QDirIterator it(mountPoint, QStringList() << "*.app", QDir::Dirs);
if (!it.hasNext()) { if (!it.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 = 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..."; qDebug() << "Copying app to Applications folder...";
process.start("cp", QStringList() process.start("cp", QStringList() << "-R" << appPath << targetPath);
<< "-R"
<< appPath
<< targetPath);
process.waitForFinished(); process.waitForFinished();
// Unmount DMG // Unmount DMG
qDebug() << "Unmounting DMG..."; qDebug() << "Unmounting DMG...";
process.start("hdiutil", QStringList() process.start("hdiutil", QStringList() << "detach" << mountPoint);
<< "detach"
<< mountPoint);
process.waitForFinished(); process.waitForFinished();
if (process.exitCode() != 0) { if (process.exitCode() != 0) {
qDebug() << "Installation error:" << process.readAllStandardError(); qDebug() << "Installation error:" << process.readAllStandardError();
} }
@ -464,17 +454,17 @@ int IpcServer::installApp(const QString &path)
QProcess process; QProcess process;
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; qDebug() << "Installing app from:" << path;
qDebug() << "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"; qDebug() << "Created extraction directory";
} }
// First, extract the zip archive // First, extract the zip archive
qDebug() << "Extracting ZIP archive..."; qDebug() << "Extracting ZIP archive...";
process.start("unzip", QStringList() << path << "-d" << extractDir); process.start("unzip", QStringList() << path << "-d" << extractDir);
@ -484,7 +474,7 @@ int IpcServer::installApp(const QString &path)
return process.exitCode(); return process.exitCode();
} }
qDebug() << "ZIP archive extracted successfully"; qDebug() << "ZIP archive extracted successfully";
// Look for tar file in extracted files // Look for tar file in extracted files
qDebug() << "Looking for TAR file..."; qDebug() << "Looking for TAR file...";
QDirIterator tarIt(extractDir, QStringList() << "*.tar", QDir::Files); QDirIterator tarIt(extractDir, QStringList() << "*.tar", QDir::Files);
@ -492,12 +482,12 @@ int IpcServer::installApp(const QString &path)
qDebug() << "TAR file not found in the extracted archive"; qDebug() << "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; qDebug() << "Found TAR file:" << tarPath;
qDebug() << "Extracting TAR archive..."; qDebug() << "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) {
@ -505,11 +495,11 @@ int IpcServer::installApp(const QString &path)
return process.exitCode(); return process.exitCode();
} }
qDebug() << "TAR archive extracted successfully"; qDebug() << "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"; qDebug() << "Removed temporary TAR file";
// Find executable file and run it // Find executable file and run it
qDebug() << "Looking for executable file..."; qDebug() << "Looking for executable file...";
QDirIterator it(extractDir, QDir::Files | QDir::Executable, QDirIterator::Subdirectories); QDirIterator it(extractDir, QDir::Files | QDir::Executable, QDirIterator::Subdirectories);
@ -524,7 +514,7 @@ int IpcServer::installApp(const QString &path)
qDebug() << "Installer finished with exit code:" << process.exitCode(); qDebug() << "Installer finished with exit code:" << process.exitCode();
return process.exitCode(); return process.exitCode();
} }
qDebug() << "No executable file found"; qDebug() << "No executable file found";
return -1; // Executable not found return -1; // Executable not found
#endif #endif

View file

@ -1,11 +1,11 @@
#ifndef IPCSERVER_H #ifndef IPCSERVER_H
#define IPCSERVER_H #define IPCSERVER_H
#include "../client/daemon/interfaceconfig.h"
#include <QJsonObject>
#include <QLocalServer> #include <QLocalServer>
#include <QObject> #include <QObject>
#include <QRemoteObjectNode> #include <QRemoteObjectNode>
#include <QJsonObject>
#include "../client/daemon/interfaceconfig.h"
#include "ipc.h" #include "ipc.h"
#include "ipcserverprocess.h" #include "ipcserverprocess.h"
@ -37,15 +37,17 @@ public:
virtual bool enablePeerTraffic(const QJsonObject &configStr) override; virtual bool enablePeerTraffic(const QJsonObject &configStr) override;
virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override; virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override;
virtual bool disableKillSwitch() override; virtual bool disableKillSwitch() override;
virtual bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) override; virtual bool updateResolvers(const QString &ifname, const QList<QHostAddress> &resolvers) override;
virtual int mountDmg(const QString &path, bool mount) override; virtual int mountDmg(const QString &path, bool mount) override;
virtual int installApp(const QString &path) override; virtual int installApp(const QString &path) override;
private: private:
int m_localpid = 0; int m_localpid = 0;
struct ProcessDescriptor { struct ProcessDescriptor
ProcessDescriptor (QObject *parent = nullptr) { {
ProcessDescriptor(QObject *parent = nullptr)
{
serverNode = QSharedPointer<QRemoteObjectHost>(new QRemoteObjectHost(parent)); serverNode = QSharedPointer<QRemoteObjectHost>(new QRemoteObjectHost(parent));
ipcProcess = QSharedPointer<IpcServerProcess>(new IpcServerProcess(parent)); ipcProcess = QSharedPointer<IpcServerProcess>(new IpcServerProcess(parent));
tun2socksProcess = QSharedPointer<IpcProcessTun2Socks>(new IpcProcessTun2Socks(parent)); tun2socksProcess = QSharedPointer<IpcProcessTun2Socks>(new IpcProcessTun2Socks(parent));