mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-19 18:30:34 +08:00
[Fix] Continue refactoring the project.
Signed-off-by: Leroy.H.Y <lhy20010403@hotmail.com>
This commit is contained in:
parent
adae62393f
commit
471beb1cce
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ v2ctl.sig
|
||||
build/
|
||||
python37/
|
||||
tools/python-3.7.3.exe
|
||||
./.vscode
|
||||
|
139
Hv2ray.pro
139
Hv2ray.pro
@ -24,36 +24,34 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
VPATH += ./src
|
||||
|
||||
SOURCES += \
|
||||
w_MainWindow.cpp \
|
||||
w_ConnectionEditWindow.cpp \
|
||||
w_ImportConfig.cpp \
|
||||
w_PrefrencesWindow.cpp \
|
||||
main.cpp \
|
||||
vinteract.cpp \
|
||||
utils.cpp \
|
||||
runguard.cpp
|
||||
./src/w_MainWindow.cpp \
|
||||
./src/w_ConnectionEditWindow.cpp \
|
||||
./src/w_ImportConfig.cpp \
|
||||
./src/w_PrefrencesWindow.cpp \
|
||||
./src/main.cpp \
|
||||
./src/vinteract.cpp \
|
||||
./src/utils.cpp \
|
||||
./src/runguard.cpp
|
||||
|
||||
HEADERS += \
|
||||
w_MainWindow.h \
|
||||
w_ConnectionEditWindow.h \
|
||||
w_ImportConfig.h \
|
||||
w_PrefrencesWindow.h \
|
||||
constants.h \
|
||||
vinteract.h \
|
||||
utils.h \
|
||||
runguard.h
|
||||
./src/w_MainWindow.h \
|
||||
./src/w_ConnectionEditWindow.h \
|
||||
./src/w_ImportConfig.h \
|
||||
./src/w_PrefrencesWindow.h \
|
||||
./src/constants.h \
|
||||
./src/vinteract.h \
|
||||
./src/utils.h \
|
||||
./src/runguard.h
|
||||
|
||||
FORMS += \
|
||||
w_MainWindow.ui \
|
||||
w_ConnectionEditWindow.ui \
|
||||
w_ImportConfig.ui \
|
||||
w_PrefrencesWindow.ui
|
||||
./src/w_MainWindow.ui \
|
||||
./src/w_ConnectionEditWindow.ui \
|
||||
./src/w_ImportConfig.ui \
|
||||
./src/w_PrefrencesWindow.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
./resources.qrc
|
||||
|
||||
|
||||
TRANSLATIONS += \
|
||||
@ -68,66 +66,57 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
WITH_PYTHON = no
|
||||
PYTHONVER = null
|
||||
|
||||
unix:!macx {
|
||||
exists( "/usr/include/python3.7m/Python.h" ) {
|
||||
equals(WITH_PYTHON, "no") {
|
||||
message("Will build with python lib version 3.7.")
|
||||
INCLUDEPATH += /usr/include/python3.7m/
|
||||
LIBS += -lpython3.7m
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unix:!macx {
|
||||
exists( "/usr/include/python3.6m/Python.h" ) {
|
||||
equals(WITH_PYTHON, "no") {
|
||||
message("Will build with python lib version 3.6.")
|
||||
INCLUDEPATH += /usr/include/python3.6m/
|
||||
LIBS += -lpython3.6m
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unix:!macx {
|
||||
# Python Headers check.
|
||||
exists( "/usr/include/python3.5m/Python.h" ) {
|
||||
equals(WITH_PYTHON, "no") {
|
||||
message("Will build with python lib version 3.5.")
|
||||
INCLUDEPATH += /usr/include/python3.5m/
|
||||
LIBS += -lpython3.5m
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
PYTHONVER = 3.5
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
exists( "/usr/include/python3.6m/Python.h" ) {
|
||||
PYTHONVER = 3.6
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
exists( "/usr/include/python3.7m/Python.h" ) {
|
||||
PYTHONVER = 3.7
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
|
||||
equals( WITH_PYTHON, "yes" ) {
|
||||
INCLUDEPATH += /usr/include/python$${PYTHONVER}m/
|
||||
LIBS += -lpython$${PYTHONVER}m
|
||||
message("Will build with python lib version $$PYTHONVER")
|
||||
}
|
||||
}
|
||||
|
||||
macx {
|
||||
PYTHON_ROOT=/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions
|
||||
exists( "$$PYTHON_ROOT/3.7/include/python3.7m/Python.h" ) {
|
||||
equals(WITH_PYTHON, "no") {
|
||||
message("Will build with python lib version 3.7.3.")
|
||||
INCLUDEPATH += $$PYTHON_ROOT/3.7/include/python3.7m/
|
||||
LIBS += -L$$PYTHON_ROOT/3.7/lib/python3.7/config-3.7m-darwin/ -lpython3.7m
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
PYTHON_ROOT=/usr/local/Cellar/python
|
||||
exists( "$${PYTHON_ROOT}/3.6.5_1/" ) {
|
||||
PYTHONVER = 3.6
|
||||
PYLDPATH=$${PYTHON_ROOT}/3.6.5_1/Frameworks/Python.framework/Versions/$${PYTHONVER}
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
|
||||
exists( "$$PYTHON_ROOT/3.7.3/" ) {
|
||||
PYTHONVER = 3.7
|
||||
PYLDPATH=$${PYTHON_ROOT}/3.7.3/Frameworks/Python.framework/Versions/$${PYTHONVER}
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
|
||||
INCLUDEPATH += $${PYLDPATH}/include/python$${PYTHONVER}m/
|
||||
LIBS += -L$${PYLDPATH}/lib/python$${PYTHONVER}/config-$${PYTHONVER}m-darwin/ -lpython$${PYTHONVER}m
|
||||
message("Will build with python lib version $$PYTHONVER")
|
||||
}
|
||||
|
||||
win32 {
|
||||
exists( "$$PWD/python37/libs/libpython37_mingw.a" ) {
|
||||
LIBS += -L$$PWD/python37/libs/ -lpython37_mingw
|
||||
INCLUDEPATH += $$PWD/python37/include
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
}
|
||||
|
||||
macx {
|
||||
PYTHON_ROOT=/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions
|
||||
exists( "$$PYTHON_ROOT/3.6/include/python3.6m/Python.h" ) {
|
||||
equals(WITH_PYTHON, "no") {
|
||||
message("Will build with python lib version 3.6.5_1.")
|
||||
INCLUDEPATH += $$PYTHON_ROOT/3.6/include/python3.6m/
|
||||
LIBS += -L$$PYTHON_ROOT/3.6/lib/python3.6/config-3.6m-darwin/ -lpython3.6m
|
||||
WITH_PYTHON = yes
|
||||
}
|
||||
}
|
||||
equals(WITH_PYTHON, "no") {
|
||||
error("No Python3 libs found, did you install dev packages such as python3-dev ?")
|
||||
}
|
||||
unix: equals(WITH_PYTHON, "no") {
|
||||
error("No python libs found, did you install python3 dev package?")
|
||||
}
|
||||
|
||||
win32: LIBS += -L$$PWD/python37/libs/ -lpython37_mingw
|
||||
win32: INCLUDEPATH += $$PWD/python37/include
|
||||
|
@ -48,15 +48,6 @@ bool getRootEnabled()
|
||||
return loadRootObjFromConf().value("v2suidEnabled").toBool();
|
||||
}
|
||||
|
||||
bool checkVCoreExes()
|
||||
{
|
||||
if (QFileInfo("v2ray").exists() && QFileInfo("geoip.dat").exists() && QFileInfo("geosite.dat").exists() && QFileInfo("v2ctl").exists()) {
|
||||
return true;
|
||||
} else {
|
||||
showWarnMessageBox(nullptr, QObject::tr("CoreNotFound"), QObject::tr("CoreFileNotFoundExplaination"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void showWarnMessageBox(QWidget* parent, QString title, QString text)
|
||||
{
|
||||
|
@ -8,7 +8,6 @@ QJsonObject switchJsonArrayObject(QJsonObject objest, QString value);
|
||||
QJsonObject findValueFromJsonArray(QJsonArray arr, QString key, QString val);
|
||||
QJsonObject loadRootObjFromConf();
|
||||
QJsonArray getInbounds();
|
||||
bool checkVCoreExes();
|
||||
void showWarnMessageBox(QWidget* parent, QString title, QString text);
|
||||
void overrideInbounds(QString path);
|
||||
int getIndexByValue(QJsonArray array, QString key, QString val);
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "w_MainWindow.h"
|
||||
#include "vinteract.h"
|
||||
|
||||
bool validationCheck(QString path)
|
||||
bool v2Instance::checkConfigFile(QString path)
|
||||
{
|
||||
if(checkVCoreExes()) {
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
@ -33,17 +33,24 @@ bool validationCheck(QString path)
|
||||
else return false;
|
||||
}
|
||||
|
||||
v2Instance::v2Instance()
|
||||
v2Instance::v2Instance(QWidget *parent)
|
||||
{
|
||||
this->vProcess = new QProcess();
|
||||
QObject::connect(vProcess, SIGNAL(readyReadStandardOutput()), parent, SLOT(updateLog()));
|
||||
}
|
||||
|
||||
v2Instance::~v2Instance()
|
||||
bool v2Instance::checkVCoreExes()
|
||||
{
|
||||
this->stop();
|
||||
if (QFileInfo("v2ray").exists() && QFileInfo("geoip.dat").exists() && QFileInfo("geosite.dat").exists() && QFileInfo("v2ctl").exists()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
showWarnMessageBox(nullptr, QObject::tr("CoreNotFound"), QObject::tr("CoreFileNotFoundExplaination"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool v2Instance::start(QWidget *parent)
|
||||
bool v2Instance::start()
|
||||
{
|
||||
if(this->vProcess->state() == QProcess::Running) {
|
||||
this->stop();
|
||||
@ -54,7 +61,7 @@ bool v2Instance::start(QWidget *parent)
|
||||
this->vProcess->setProcessEnvironment(env);
|
||||
this->vProcess->start("./v2ray", QStringList() << "-config" << "config.json", QIODevice::ReadWrite | QIODevice::Text);
|
||||
this->vProcess->waitForStarted();
|
||||
QObject::connect(vProcess, SIGNAL(readyReadStandardOutput()), parent, SLOT(updateLog()));
|
||||
processStatus = STARTED;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
@ -63,4 +70,10 @@ bool v2Instance::start(QWidget *parent)
|
||||
void v2Instance::stop()
|
||||
{
|
||||
this->vProcess->close();
|
||||
processStatus = STOPPED;
|
||||
}
|
||||
|
||||
v2Instance::~v2Instance()
|
||||
{
|
||||
this->stop();
|
||||
}
|
||||
|
@ -3,17 +3,27 @@
|
||||
#include <QString>
|
||||
#include <QProcess>
|
||||
|
||||
bool validationCheck(QString path);
|
||||
enum V2RAY_INSTANCE_STARTUP_STATUS {
|
||||
STOPPED,
|
||||
STARTING,
|
||||
STARTED
|
||||
};
|
||||
|
||||
class v2Instance
|
||||
{
|
||||
public:
|
||||
explicit v2Instance();
|
||||
bool start(QWidget *parent);
|
||||
explicit v2Instance(QWidget *parent);
|
||||
|
||||
bool start();
|
||||
void stop();
|
||||
void restart();
|
||||
QProcess *vProcess;
|
||||
|
||||
static bool checkVCoreExes();
|
||||
static bool checkConfigFile(QString path);
|
||||
~v2Instance();
|
||||
QProcess *vProcess;
|
||||
private:
|
||||
V2RAY_INSTANCE_STARTUP_STATUS processStatus;
|
||||
};
|
||||
|
||||
#endif // VINTERACT_H
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "w_ConnectionEditWindow.h"
|
||||
#include "ui_ConnectionEditWindow.h"
|
||||
#include "ui_w_ConnectionEditWindow.h"
|
||||
#include <iostream>
|
||||
#include "w_MainWindow.h"
|
||||
#include <QDebug>
|
||||
|
@ -14,7 +14,8 @@
|
||||
#include "vinteract.h"
|
||||
#include "utils.h"
|
||||
#include "w_ImportConfig.h"
|
||||
#include "ui_ImportConfig.h"
|
||||
#include "ui_w_ImportConfig.h"
|
||||
|
||||
|
||||
ImportConfig::ImportConfig(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@ -87,7 +88,7 @@ void ImportConfig::on_buttonBox_accepted()
|
||||
if(ui->importSourceCombo->currentIndex() == 0) // From File...
|
||||
{
|
||||
QString path = ui->fileLineTxt->text();
|
||||
bool isValid = validationCheck(path);
|
||||
bool isValid = v2Instance::checkConfigFile(path);
|
||||
if(isValid) {
|
||||
savefromFile(path, alias);
|
||||
}
|
||||
@ -109,7 +110,7 @@ void ImportConfig::on_buttonBox_accepted()
|
||||
Py_Finalize();
|
||||
if(QFile::exists(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
|
||||
ImportConfig *im = new ImportConfig(this->parentWidget());
|
||||
if (validationCheck(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
|
||||
if (v2Instance::checkConfigFile(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
|
||||
im->savefromFile("config.json.tmp", alias);
|
||||
}
|
||||
QFile::remove("config.json.tmp");
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "ui_MainWindow.h"
|
||||
#include "ui_w_MainWindow.h"
|
||||
#include "w_PrefrencesWindow.h"
|
||||
#include "w_MainWindow.h"
|
||||
#include "w_ConnectionEditWindow.h"
|
||||
@ -64,10 +64,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
UpdateConfigTable();
|
||||
// ui->configTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
// connect(ui->configTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
|
||||
this->v2instance = new v2Instance();
|
||||
this->vinstance = new v2Instance(this);
|
||||
CreateTrayIcon();
|
||||
if(QFileInfo("config.json").exists()) {
|
||||
v2instance->start(this);
|
||||
vinstance->start();
|
||||
}
|
||||
|
||||
// QAction *select = new QAction("Select", ui->configTable);
|
||||
@ -87,7 +87,7 @@ MainWindow::~MainWindow()
|
||||
{
|
||||
hTray->hide();
|
||||
delete this->hTray;
|
||||
delete this->v2instance;
|
||||
delete this->vinstance;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -107,6 +107,7 @@ void MainWindow::on_actionExisting_config_triggered()
|
||||
|
||||
void MainWindow::showMenu(QPoint pos)
|
||||
{
|
||||
Q_UNUSED(pos)
|
||||
// if(ui->configTable->indexAt(pos).column() != -1) {
|
||||
// popMenu->move(cursor().pos());
|
||||
// popMenu->show();
|
||||
@ -147,13 +148,13 @@ void MainWindow::GenerateConfig(int idIntable)
|
||||
}
|
||||
void MainWindow::UpdateLog()
|
||||
{
|
||||
ui->logText->insertPlainText(this->v2instance->vProcess->readAllStandardOutput());
|
||||
ui->logText->insertPlainText(this->vinstance->vProcess->readAllStandardOutput());
|
||||
}
|
||||
|
||||
void MainWindow::on_startButton_clicked()
|
||||
{
|
||||
ui->logText->clear();
|
||||
bool startFlag = this->v2instance->start(this);
|
||||
bool startFlag = this->vinstance->start();
|
||||
trayMenu->actions()[2]->setEnabled(!startFlag);
|
||||
trayMenu->actions()[3]->setEnabled(startFlag);
|
||||
trayMenu->actions()[4]->setEnabled(startFlag);
|
||||
@ -161,7 +162,7 @@ void MainWindow::on_startButton_clicked()
|
||||
|
||||
void MainWindow::on_stopButton_clicked()
|
||||
{
|
||||
this->v2instance->stop();
|
||||
this->vinstance->stop();
|
||||
ui->logText->clear();
|
||||
trayMenu->actions()[2]->setEnabled(true);
|
||||
trayMenu->actions()[3]->setEnabled(false);
|
||||
@ -209,7 +210,7 @@ void MainWindow::on_activatedTray(QSystemTrayIcon::ActivationReason reason)
|
||||
case QSystemTrayIcon::MiddleClick:
|
||||
// TODO: Check if an alert message box is present.
|
||||
// If so, do nothing but please wait for the message box to be closed.
|
||||
if(this->v2instance->vProcess->state() == QProcess::ProcessState::Running) {
|
||||
if(this->vinstance->vProcess->state() == QProcess::ProcessState::Running) {
|
||||
on_stopButton_clicked();
|
||||
} else {
|
||||
on_startButton_clicked();
|
||||
|
@ -19,7 +19,7 @@ class MainWindow : public QMainWindow
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
v2Instance *v2instance;
|
||||
v2Instance *vinstance;
|
||||
QSystemTrayIcon *hTray;
|
||||
QMenu *trayMenu = new QMenu(this);
|
||||
QMenu *popMenu = new QMenu(this);
|
||||
|
@ -143,6 +143,9 @@
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@ -241,7 +244,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>568</width>
|
||||
<height>21</height>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
@ -8,9 +8,10 @@
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
#include <unistd.h>
|
||||
#include <ui_PrefrencesWindow.h>
|
||||
#include <ui_w_PrefrencesWindow.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "vinteract.h"
|
||||
#include "w_PrefrencesWindow.h"
|
||||
|
||||
PrefrencesWindow::PrefrencesWindow(QWidget *parent) :
|
||||
@ -48,7 +49,7 @@ PrefrencesWindow::~PrefrencesWindow()
|
||||
|
||||
void PrefrencesWindow::on_buttonBox_accepted()
|
||||
{
|
||||
if(checkVCoreExes()) {
|
||||
if(v2Instance::checkVCoreExes()) {
|
||||
if(ui->httpPortLE->text().toInt() != ui->socksPortLE->text().toInt()) {
|
||||
QJsonArray inbounds;
|
||||
QJsonDocument modifiedDoc;
|
||||
|
Loading…
Reference in New Issue
Block a user