removed Widgets from service part
This commit is contained in:
parent
f7926847ac
commit
23ad006187
11 changed files with 178 additions and 162 deletions
|
@ -10,7 +10,6 @@
|
|||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
|
||||
#include "core/servercontroller.h"
|
||||
#include "logger.h"
|
||||
#include "version.h"
|
||||
|
||||
|
@ -20,7 +19,6 @@
|
|||
#endif
|
||||
|
||||
#include "protocols/qml_register_protocols.h"
|
||||
#include "ui/pages.h"
|
||||
|
||||
#if defined(Q_OS_IOS)
|
||||
#include "platforms/ios/QtAppDelegate-C-Interface.h"
|
||||
|
@ -81,8 +79,6 @@ void AmneziaApplication::init()
|
|||
|
||||
m_engine->rootContext()->setContextProperty("Debug", &Logger::Instance());
|
||||
|
||||
//
|
||||
|
||||
m_configurator = std::shared_ptr<VpnConfigurator>(new VpnConfigurator(m_settings, this));
|
||||
m_vpnConnection.reset(new VpnConnection(m_settings, m_configurator));
|
||||
m_vpnConnection->moveToThread(&m_vpnConnectionThread);
|
||||
|
@ -125,14 +121,8 @@ void AmneziaApplication::init()
|
|||
connect(m_notificationHandler.get(), &NotificationHandler::disconnectRequested, m_connectionController.get(),
|
||||
&ConnectionController::closeConnection);
|
||||
|
||||
//
|
||||
|
||||
m_engine->load(url);
|
||||
|
||||
// if (m_engine->rootObjects().size() > 0) {
|
||||
// m_uiLogic->setQmlRoot(m_engine->rootObjects().at(0));
|
||||
// }
|
||||
|
||||
if (m_settings->isSaveLogs()) {
|
||||
if (!Logger::init()) {
|
||||
qWarning() << "Initialization of debug subsystem failed";
|
||||
|
|
47
client/fileUtilites.cpp
Normal file
47
client/fileUtilites.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "fileUtilites.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QStandardPaths>
|
||||
|
||||
void FileUtilites::saveFile(const QString &fileExtension, const QString &caption, const QString &fileName,
|
||||
const QString &data)
|
||||
{
|
||||
QString docDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
||||
QUrl fileUrl = QFileDialog::getSaveFileUrl(nullptr, caption, QUrl::fromLocalFile(docDir + "/" + fileName),
|
||||
"*" + fileExtension);
|
||||
if (fileUrl.isEmpty())
|
||||
return;
|
||||
if (!fileUrl.toString().endsWith(fileExtension)) {
|
||||
fileUrl = QUrl(fileUrl.toString() + fileExtension);
|
||||
}
|
||||
if (fileUrl.isEmpty())
|
||||
return;
|
||||
|
||||
QFile save(fileUrl.toLocalFile());
|
||||
|
||||
// todo check if save successful
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(data.toUtf8());
|
||||
save.close();
|
||||
|
||||
QFileInfo fi(fileUrl.toLocalFile());
|
||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
}
|
||||
|
||||
QString FileUtilites::getFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter,
|
||||
QString *selectedFilter, QFileDialog::Options options)
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options);
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
// patch for files containing spaces etc
|
||||
const QString sep { "raw%3A%2F" };
|
||||
if (fileName.startsWith("content://") && fileName.contains(sep)) {
|
||||
QString contentUrl = fileName.split(sep).at(0);
|
||||
QString rawUrl = fileName.split(sep).at(1);
|
||||
rawUrl.replace(" ", "%20");
|
||||
fileName = contentUrl + sep + rawUrl;
|
||||
}
|
||||
#endif
|
||||
return fileName;
|
||||
}
|
19
client/fileUtilites.h
Normal file
19
client/fileUtilites.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef FILEUTILITES_H
|
||||
#define FILEUTILITES_H
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
class FileUtilites : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static void saveFile(const QString &fileExtension, const QString &caption, const QString &fileName,
|
||||
const QString &data);
|
||||
|
||||
static QString getFileName(QWidget *parent = nullptr, const QString &caption = QString(),
|
||||
const QString &dir = QString(), const QString &filter = QString(),
|
||||
QString *selectedFilter = nullptr, QFileDialog::Options options = QFileDialog::Options());
|
||||
};
|
||||
|
||||
#endif // FILEUTILITES_H
|
|
@ -4,7 +4,6 @@
|
|||
#include <QDataStream>
|
||||
#include <QDesktopServices>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QImage>
|
||||
#include <QStandardPaths>
|
||||
|
@ -12,7 +11,7 @@
|
|||
#include "configurators/openvpn_configurator.h"
|
||||
#include "configurators/wireguard_configurator.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "utilities.h"
|
||||
#include "fileUtilites.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "platforms/android/android_controller.h"
|
||||
#include "platforms/android/androidutils.h"
|
||||
|
@ -230,7 +229,7 @@ void ExportController::saveFile(const QString &fileExtension, const QString &cap
|
|||
return;
|
||||
#endif
|
||||
|
||||
Utils::saveFile(fileExtension, caption, fileName, m_config);
|
||||
FileUtilites::saveFile(fileExtension, caption, fileName, m_config);
|
||||
}
|
||||
|
||||
QList<QString> ExportController::generateQrCodeImageSeries(const QByteArray &data)
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "../../platforms/android/androidutils.h"
|
||||
#include <QJniObject>
|
||||
#endif
|
||||
#include "utilities.h"
|
||||
#include "fileUtilites.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -84,9 +84,9 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
|||
|
||||
void ImportController::extractConfigFromFile()
|
||||
{
|
||||
QString fileName = Utils::getFileName(Q_NULLPTR, tr("Open config file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
|
||||
"*.vpn *.ovpn *.conf");
|
||||
QString fileName = FileUtilites::getFileName(Q_NULLPTR, tr("Open config file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
|
||||
"*.vpn *.ovpn *.conf");
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QString data = file.readAll();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "core/errorstrings.h"
|
||||
#include "core/servercontroller.h"
|
||||
#include "fileUtilites.h"
|
||||
#include "utilities.h"
|
||||
|
||||
namespace
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "fileUtilites.h"
|
||||
#include "logger.h"
|
||||
#include "utilities.h"
|
||||
#include "version.h"
|
||||
|
||||
SettingsController::SettingsController(const QSharedPointer<ServersModel> &serversModel,
|
||||
|
@ -69,7 +69,7 @@ void SettingsController::openLogsFolder()
|
|||
|
||||
void SettingsController::exportLogsFile()
|
||||
{
|
||||
Utils::saveFile(".log", tr("Save log"), "AmneziaVPN", Logger::getLogFile());
|
||||
FileUtilites::saveFile(".log", tr("Save log"), "AmneziaVPN", Logger::getLogFile());
|
||||
}
|
||||
|
||||
void SettingsController::clearLogs()
|
||||
|
@ -80,14 +80,14 @@ void SettingsController::clearLogs()
|
|||
|
||||
void SettingsController::backupAppConfig()
|
||||
{
|
||||
Utils::saveFile(".backup", tr("Backup application config"), "AmneziaVPN", m_settings->backupAppConfig());
|
||||
FileUtilites::saveFile(".backup", tr("Backup application config"), "AmneziaVPN", m_settings->backupAppConfig());
|
||||
}
|
||||
|
||||
void SettingsController::restoreAppConfig()
|
||||
{
|
||||
QString fileName =
|
||||
Utils::getFileName(Q_NULLPTR, tr("Open backup"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.backup");
|
||||
FileUtilites::getFileName(Q_NULLPTR, tr("Open backup"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.backup");
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <QHostInfo>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "utilities.h"
|
||||
#include "fileUtilites.h"
|
||||
|
||||
SitesController::SitesController(const std::shared_ptr<Settings> &settings,
|
||||
const QSharedPointer<VpnConnection> &vpnConnection,
|
||||
|
@ -80,8 +80,9 @@ void SitesController::removeSite(int index)
|
|||
|
||||
void SitesController::importSites(bool replaceExisting)
|
||||
{
|
||||
QString fileName = Utils::getFileName(Q_NULLPTR, tr("Open sites file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.json");
|
||||
QString fileName =
|
||||
FileUtilites::getFileName(Q_NULLPTR, tr("Open sites file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.json");
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
|
@ -149,7 +150,7 @@ void SitesController::exportSites()
|
|||
QJsonDocument jsonDocument(jsonArray);
|
||||
QByteArray jsonData = jsonDocument.toJson();
|
||||
|
||||
Utils::saveFile(".json", tr("Export sites file"), "sites", jsonData);
|
||||
FileUtilites::saveFile(".json", tr("Export sites file"), "sites", jsonData);
|
||||
|
||||
emit finished(tr("Export completed"));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QHostAddress>
|
||||
#include <QHostInfo>
|
||||
|
@ -10,15 +9,15 @@
|
|||
#include <QStandardPaths>
|
||||
#include <QUrl>
|
||||
|
||||
#include "version.h"
|
||||
#include "utilities.h"
|
||||
#include "version.h"
|
||||
|
||||
QString Utils::getRandomString(int len)
|
||||
{
|
||||
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||
|
||||
QString randomString;
|
||||
for(int i=0; i<len; ++i) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
quint32 index = QRandomGenerator::global()->generate() % possibleCharacters.length();
|
||||
QChar nextChar = possibleCharacters.at(index);
|
||||
randomString.append(nextChar);
|
||||
|
@ -31,7 +30,7 @@ QString Utils::systemLogPath()
|
|||
#ifdef Q_OS_WIN
|
||||
QStringList locationList = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||
QString primaryLocation = "ProgramData";
|
||||
foreach (const QString& location, locationList) {
|
||||
foreach (const QString &location, locationList) {
|
||||
if (location.contains(primaryLocation)) {
|
||||
return QString("%1/%2/log").arg(location).arg(APPLICATION_NAME);
|
||||
}
|
||||
|
@ -42,7 +41,7 @@ QString Utils::systemLogPath()
|
|||
#endif
|
||||
}
|
||||
|
||||
bool Utils::initializePath(const QString& path)
|
||||
bool Utils::initializePath(const QString &path)
|
||||
{
|
||||
QDir dir;
|
||||
if (!dir.mkpath(path)) {
|
||||
|
@ -52,13 +51,13 @@ bool Utils::initializePath(const QString& path)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Utils::createEmptyFile(const QString& path)
|
||||
bool Utils::createEmptyFile(const QString &path)
|
||||
{
|
||||
QFile f(path);
|
||||
return f.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
}
|
||||
|
||||
QString Utils::executable(const QString& baseName, bool absPath)
|
||||
QString Utils::executable(const QString &baseName, bool absPath)
|
||||
{
|
||||
QString ext;
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -71,7 +70,7 @@ QString Utils::executable(const QString& baseName, bool absPath)
|
|||
return QCoreApplication::applicationDirPath() + "/" + fileName;
|
||||
}
|
||||
|
||||
QString Utils::usrExecutable(const QString& baseName)
|
||||
QString Utils::usrExecutable(const QString &baseName)
|
||||
{
|
||||
if (QFileInfo::exists("/usr/sbin/" + baseName))
|
||||
return ("/usr/sbin/" + baseName);
|
||||
|
@ -79,18 +78,22 @@ QString Utils::usrExecutable(const QString& baseName)
|
|||
return ("/usr/bin/" + baseName);
|
||||
}
|
||||
|
||||
bool Utils::processIsRunning(const QString& fileName)
|
||||
bool Utils::processIsRunning(const QString &fileName)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QProcess process;
|
||||
process.setReadChannel(QProcess::StandardOutput);
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
process.start("wmic.exe", QStringList() << "/OUTPUT:STDOUT" << "PROCESS" << "get" << "Caption");
|
||||
process.start("wmic.exe",
|
||||
QStringList() << "/OUTPUT:STDOUT"
|
||||
<< "PROCESS"
|
||||
<< "get"
|
||||
<< "Caption");
|
||||
process.waitForStarted();
|
||||
process.waitForFinished();
|
||||
QString processData(process.readAll());
|
||||
QStringList processList = processData.split(QRegularExpression("[\r\n]"),Qt::SkipEmptyParts);
|
||||
foreach (const QString& rawLine, processList) {
|
||||
QStringList processList = processData.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
|
||||
foreach (const QString &rawLine, processList) {
|
||||
const QString line = rawLine.simplified();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
|
@ -99,7 +102,6 @@ bool Utils::processIsRunning(const QString& fileName)
|
|||
if (line == fileName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
#elif defined(Q_OS_IOS)
|
||||
|
@ -107,7 +109,7 @@ bool Utils::processIsRunning(const QString& fileName)
|
|||
#else
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
process.start("pgrep", QStringList({fileName}));
|
||||
process.start("pgrep", QStringList({ fileName }));
|
||||
process.waitForFinished();
|
||||
if (process.exitStatus() == QProcess::NormalExit) {
|
||||
return (process.readAll().toUInt() > 0);
|
||||
|
@ -116,7 +118,7 @@ bool Utils::processIsRunning(const QString& fileName)
|
|||
#endif
|
||||
}
|
||||
|
||||
QString Utils::getIPAddress(const QString& host)
|
||||
QString Utils::getIPAddress(const QString &host)
|
||||
{
|
||||
if (ipAddressRegExp().match(host).hasMatch()) {
|
||||
return host;
|
||||
|
@ -130,42 +132,48 @@ QString Utils::getIPAddress(const QString& host)
|
|||
return "";
|
||||
}
|
||||
|
||||
QString Utils::getStringBetween(const QString& s, const QString& a, const QString& b)
|
||||
QString Utils::getStringBetween(const QString &s, const QString &a, const QString &b)
|
||||
{
|
||||
int ap = s.indexOf(a), bp = s.indexOf(b, ap + a.length());
|
||||
if(ap < 0 || bp < 0)
|
||||
if (ap < 0 || bp < 0)
|
||||
return QString();
|
||||
ap += a.length();
|
||||
if(bp - ap <= 0)
|
||||
if (bp - ap <= 0)
|
||||
return QString();
|
||||
return s.mid(ap, bp - ap).trimmed();
|
||||
}
|
||||
|
||||
bool Utils::checkIPv4Format(const QString& ip)
|
||||
bool Utils::checkIPv4Format(const QString &ip)
|
||||
{
|
||||
if (ip.isEmpty()) return false;
|
||||
if (ip.isEmpty())
|
||||
return false;
|
||||
int count = ip.count(".");
|
||||
if(count != 3) return false;
|
||||
if (count != 3)
|
||||
return false;
|
||||
|
||||
QHostAddress addr(ip);
|
||||
return (addr.protocol() == QAbstractSocket::NetworkLayerProtocol::IPv4Protocol);
|
||||
return (addr.protocol() == QAbstractSocket::NetworkLayerProtocol::IPv4Protocol);
|
||||
}
|
||||
|
||||
bool Utils::checkIpSubnetFormat(const QString &ip)
|
||||
{
|
||||
if (!ip.contains("/")) return checkIPv4Format(ip);
|
||||
if (!ip.contains("/"))
|
||||
return checkIPv4Format(ip);
|
||||
|
||||
QStringList parts = ip.split("/");
|
||||
if (parts.size() != 2) return false;
|
||||
if (parts.size() != 2)
|
||||
return false;
|
||||
|
||||
bool ok;
|
||||
int subnet = parts.at(1).toInt(&ok);
|
||||
if (subnet >= 0 && subnet <= 32 && ok) return checkIPv4Format(parts.at(0));
|
||||
else return false;
|
||||
if (subnet >= 0 && subnet <= 32 && ok)
|
||||
return checkIPv4Format(parts.at(0));
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void Utils::killProcessByName(const QString &name)
|
||||
{
|
||||
{
|
||||
qDebug().noquote() << "Kill process" << name;
|
||||
#ifdef Q_OS_WIN
|
||||
QProcess::execute("taskkill", QStringList() << "/IM" << name << "/F");
|
||||
|
@ -178,40 +186,39 @@ void Utils::killProcessByName(const QString &name)
|
|||
|
||||
QString Utils::netMaskFromIpWithSubnet(const QString ip)
|
||||
{
|
||||
if (!ip.contains("/")) return "255.255.255.255";
|
||||
if (!ip.contains("/"))
|
||||
return "255.255.255.255";
|
||||
|
||||
bool ok;
|
||||
int prefix = ip.split("/").at(1).toInt(&ok);
|
||||
if (!ok) return "255.255.255.255";
|
||||
if (!ok)
|
||||
return "255.255.255.255";
|
||||
|
||||
unsigned long mask = (0xFFFFFFFF << (32 - prefix)) & 0xFFFFFFFF;
|
||||
|
||||
return QString("%1.%2.%3.%4")
|
||||
.arg(mask >> 24)
|
||||
.arg((mask >> 16) & 0xFF)
|
||||
.arg((mask >> 8) & 0xFF)
|
||||
.arg( mask & 0xFF);
|
||||
return QString("%1.%2.%3.%4").arg(mask >> 24).arg((mask >> 16) & 0xFF).arg((mask >> 8) & 0xFF).arg(mask & 0xFF);
|
||||
}
|
||||
|
||||
QString Utils::ipAddressFromIpWithSubnet(const QString ip)
|
||||
{
|
||||
if (ip.count(".") != 3) return "";
|
||||
if (ip.count(".") != 3)
|
||||
return "";
|
||||
return ip.split("/").first();
|
||||
}
|
||||
|
||||
QStringList Utils::summarizeRoutes(const QStringList &ips, const QString cidr)
|
||||
{
|
||||
// QMap<int, int>
|
||||
// QHostAddress
|
||||
// QMap<int, int>
|
||||
// QHostAddress
|
||||
|
||||
// QMap<QString, QStringList> subnets; // <"a.b", <list subnets>>
|
||||
// QMap<QString, QStringList> subnets; // <"a.b", <list subnets>>
|
||||
|
||||
// for (const QString &ip : ips) {
|
||||
// if (ip.count(".") != 3) continue;
|
||||
// for (const QString &ip : ips) {
|
||||
// if (ip.count(".") != 3) continue;
|
||||
|
||||
// const QStringList &parts = ip.split(".");
|
||||
// subnets[parts.at(0) + "." + parts.at(1)].append(ip);
|
||||
// }
|
||||
// const QStringList &parts = ip.split(".");
|
||||
// subnets[parts.at(0) + "." + parts.at(1)].append(ip);
|
||||
// }
|
||||
|
||||
return QStringList();
|
||||
}
|
||||
|
@ -252,58 +259,6 @@ QString Utils::certUtilPath()
|
|||
#endif
|
||||
}
|
||||
|
||||
void Utils::saveFile(const QString &fileExtension,
|
||||
const QString &caption,
|
||||
const QString &fileName,
|
||||
const QString &data)
|
||||
{
|
||||
QString docDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
||||
QUrl fileUrl = QFileDialog::getSaveFileUrl(nullptr,
|
||||
caption,
|
||||
QUrl::fromLocalFile(docDir + "/" + fileName),
|
||||
"*" + fileExtension);
|
||||
if (fileUrl.isEmpty())
|
||||
return;
|
||||
if (!fileUrl.toString().endsWith(fileExtension)) {
|
||||
fileUrl = QUrl(fileUrl.toString() + fileExtension);
|
||||
}
|
||||
if (fileUrl.isEmpty())
|
||||
return;
|
||||
|
||||
QFile save(fileUrl.toLocalFile());
|
||||
|
||||
//todo check if save successful
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(data.toUtf8());
|
||||
save.close();
|
||||
|
||||
QFileInfo fi(fileUrl.toLocalFile());
|
||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
}
|
||||
|
||||
QString Utils::getFileName(QWidget *parent,
|
||||
const QString &caption,
|
||||
const QString &dir,
|
||||
const QString &filter,
|
||||
QString *selectedFilter,
|
||||
QFileDialog::Options options)
|
||||
{
|
||||
QString fileName
|
||||
= QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options);
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
// patch for files containing spaces etc
|
||||
const QString sep{"raw%3A%2F"};
|
||||
if (fileName.startsWith("content://") && fileName.contains(sep)) {
|
||||
QString contentUrl = fileName.split(sep).at(0);
|
||||
QString rawUrl = fileName.split(sep).at(1);
|
||||
rawUrl.replace(" ", "%20");
|
||||
fileName = contentUrl + sep + rawUrl;
|
||||
}
|
||||
#endif
|
||||
return fileName;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
// Inspired from http://stackoverflow.com/a/15281070/1529139
|
||||
// and http://stackoverflow.com/q/40059902/1529139
|
||||
|
@ -315,8 +270,7 @@ bool Utils::signalCtrl(DWORD dwProcessId, DWORD dwCtrlEvent)
|
|||
// (otherwise AttachConsole will return ERROR_ACCESS_DENIED)
|
||||
bool consoleDetached = (FreeConsole() != FALSE);
|
||||
|
||||
if (AttachConsole(dwProcessId) != FALSE)
|
||||
{
|
||||
if (AttachConsole(dwProcessId) != FALSE) {
|
||||
// Add a fake Ctrl-C handler for avoid instant kill is this console
|
||||
// WARNING: do not revert it or current program will be also killed
|
||||
SetConsoleCtrlHandler(nullptr, true);
|
||||
|
@ -324,11 +278,9 @@ bool Utils::signalCtrl(DWORD dwProcessId, DWORD dwCtrlEvent)
|
|||
FreeConsole();
|
||||
}
|
||||
|
||||
if (consoleDetached)
|
||||
{
|
||||
if (consoleDetached) {
|
||||
// Create a new console if previous was deleted by OS
|
||||
if (AttachConsole(thisConsoleId) == FALSE)
|
||||
{
|
||||
if (AttachConsole(thisConsoleId) == FALSE) {
|
||||
int errorCode = GetLastError();
|
||||
if (errorCode == 31) // 31=ERROR_GEN_FAILURE
|
||||
{
|
||||
|
|
|
@ -1,45 +1,64 @@
|
|||
#ifndef UTILITIES_H
|
||||
#define UTILITIES_H
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "Windows.h"
|
||||
#include "Windows.h"
|
||||
#endif
|
||||
|
||||
class Utils : public QObject {
|
||||
class Utils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QString getRandomString(int len);
|
||||
|
||||
static QString executable(const QString& baseName, bool absPath);
|
||||
static QString usrExecutable(const QString& baseName);
|
||||
static QString executable(const QString &baseName, bool absPath);
|
||||
static QString usrExecutable(const QString &baseName);
|
||||
static QString systemLogPath();
|
||||
static bool createEmptyFile(const QString& path);
|
||||
static bool initializePath(const QString& path);
|
||||
static bool createEmptyFile(const QString &path);
|
||||
static bool initializePath(const QString &path);
|
||||
|
||||
static QString getIPAddress(const QString& host);
|
||||
static QString getStringBetween(const QString& s, const QString& a, const QString& b);
|
||||
static bool checkIPv4Format(const QString& ip);
|
||||
static bool checkIpSubnetFormat(const QString& ip);
|
||||
static QRegularExpression ipAddressRegExp() { return QRegularExpression("^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$"); }
|
||||
static QRegularExpression ipAddressPortRegExp() { return QRegularExpression("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
||||
"(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\:[0-9]{1,5}){0,1}$"); }
|
||||
static QString getIPAddress(const QString &host);
|
||||
static QString getStringBetween(const QString &s, const QString &a, const QString &b);
|
||||
static bool checkIPv4Format(const QString &ip);
|
||||
static bool checkIpSubnetFormat(const QString &ip);
|
||||
static QRegularExpression ipAddressRegExp()
|
||||
{
|
||||
return QRegularExpression("^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$");
|
||||
}
|
||||
static QRegularExpression ipAddressPortRegExp()
|
||||
{
|
||||
return QRegularExpression("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
||||
"(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\:[0-9]{1,5}){0,1}$");
|
||||
}
|
||||
|
||||
static QRegExp ipAddressWithSubnetRegExp() { return QRegExp("(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
||||
"(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\/[0-9]{1,2}){0,1}"); }
|
||||
static QRegExp ipAddressWithSubnetRegExp()
|
||||
{
|
||||
return QRegExp("(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
||||
"(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\/[0-9]{1,2}){0,1}");
|
||||
}
|
||||
|
||||
static QRegExp ipNetwork24RegExp() { return QRegExp("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
||||
"0$"); }
|
||||
static QRegExp ipNetwork24RegExp()
|
||||
{
|
||||
return QRegExp("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
||||
"0$");
|
||||
}
|
||||
|
||||
static QRegExp ipPortRegExp() { return QRegExp("^()([1-9]|[1-5]?[0-9]{2,4}|6[1-4][0-9]{3}|65[1-4][0-9]{2}|655[1-2][0-9]|6553[1-5])$"); }
|
||||
static QRegExp ipPortRegExp()
|
||||
{
|
||||
return QRegExp("^()([1-9]|[1-5]?[0-9]{2,4}|6[1-4][0-9]{3}|65[1-4][0-9]{2}|655[1-2][0-9]|6553[1-5])$");
|
||||
}
|
||||
|
||||
static QRegExp domainRegExp() { return QRegExp("(((?!\\-))(xn\\-\\-)?[a-z0-9\\-_]{0,61}[a-z0-9]{1,1}\\.)*(xn\\-\\-)?([a-z0-9\\-]{1,61}|[a-z0-9\\-]{1,30})\\.[a-z]{2,}"); }
|
||||
static bool processIsRunning(const QString& fileName);
|
||||
static QRegExp domainRegExp()
|
||||
{
|
||||
return QRegExp("(((?!\\-))(xn\\-\\-)?[a-z0-9\\-_]{0,61}[a-z0-9]{1,1}\\.)*(xn\\-\\-)?([a-z0-9\\-]{1,61}|[a-z0-"
|
||||
"9\\-]{1,30})\\.[a-z]{2,}");
|
||||
}
|
||||
static bool processIsRunning(const QString &fileName);
|
||||
static void killProcessByName(const QString &name);
|
||||
|
||||
static QString netMaskFromIpWithSubnet(const QString ip);
|
||||
|
@ -51,18 +70,6 @@ public:
|
|||
static QString wireguardExecPath();
|
||||
static QString certUtilPath();
|
||||
|
||||
static void saveFile(const QString &fileExtension,
|
||||
const QString &caption,
|
||||
const QString &fileName,
|
||||
const QString &data);
|
||||
|
||||
static QString getFileName(QWidget *parent = nullptr,
|
||||
const QString &caption = QString(),
|
||||
const QString &dir = QString(),
|
||||
const QString &filter = QString(),
|
||||
QString *selectedFilter = nullptr,
|
||||
QFileDialog::Options options = QFileDialog::Options());
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
static bool signalCtrl(DWORD dwProcessId, DWORD dwCtrlEvent);
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@ project(${PROJECT})
|
|||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Network RemoteObjects Core5Compat Widgets)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Network RemoteObjects Core5Compat)
|
||||
qt_standard_project_setup()
|
||||
|
||||
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
|
||||
|
@ -188,7 +188,7 @@ include_directories(
|
|||
)
|
||||
|
||||
add_executable(${PROJECT} ${SOURCES} ${HEADERS})
|
||||
target_link_libraries(${PROJECT} PRIVATE Qt6::Core Qt6::Network Qt6::RemoteObjects Qt6::Core5Compat Qt6::Widgets ${LIBS})
|
||||
target_link_libraries(${PROJECT} PRIVATE Qt6::Core Qt6::Network Qt6::RemoteObjects Qt6::Core5Compat ${LIBS})
|
||||
target_compile_definitions(${PROJECT} PRIVATE "MZ_$<UPPER_CASE:${MZ_PLATFORM_NAME}>")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue