mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-19 18:30:34 +08:00
[add] Added --noAPI flag in commandline
This commit is contained in:
parent
d9b860fa5f
commit
01b2f3ac96
@ -1 +1 @@
|
||||
2555
|
||||
2573
|
||||
|
@ -35,12 +35,13 @@ CONFIG += lrelease embed_translations
|
||||
|
||||
SOURCES += \
|
||||
src/components/QvComponentsHandler.cpp \
|
||||
src/components/QvCore/QvCommandLineArgs.cpp \
|
||||
src/components/QvKernelInteractions.cpp \
|
||||
src/components/QvLaunchAtLoginConfigurator.cpp \
|
||||
src/components/QvPACHandler.cpp \
|
||||
src/components/QvSystemProxyConfigurator.cpp \
|
||||
src/components/QvTCPing.cpp \
|
||||
src/main.cpp \
|
||||
src/components/QvCoreInteractions.cpp \
|
||||
src/components/QvGFWPACConverter.cpp \
|
||||
src/components/QvHTTPRequestHelper.cpp \
|
||||
src/components/QvLogHighlighter.cpp \
|
||||
@ -84,8 +85,9 @@ HEADERS += \
|
||||
src/QvCoreConfigOperations.hpp \
|
||||
src/QvUtils.hpp \
|
||||
src/components/QvComponentsHandler.hpp \
|
||||
src/components/QvCoreInteractions.hpp \
|
||||
src/components/QvCore/QvCommandLineArgs.hpp \
|
||||
src/components/QvHTTPRequestHelper.hpp \
|
||||
src/components/QvKernelInteractions.hpp \
|
||||
src/components/QvLaunchAtLoginConfigurator.hpp \
|
||||
src/components/QvLogHighlighter.hpp \
|
||||
src/components/QvNetSpeedPlugin.hpp \
|
||||
|
@ -74,10 +74,6 @@ const int QV2RAY_CONFIG_VERSION = 6;
|
||||
|
||||
#define NEWLINE "\r\n"
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
|
||||
|
@ -69,17 +69,5 @@ namespace Qv2ray
|
||||
bool cRules = cRule && root["routing"].toObject()["rules"].toArray().count() > 0;
|
||||
return cRules;
|
||||
}
|
||||
|
||||
int FindIndexByTag(INOUTLIST list, const QString &tag)
|
||||
{
|
||||
for (int i = 0; i < list.count(); i++) {
|
||||
auto value = list[i].toObject();
|
||||
|
||||
if (value.contains("tag") && value["tag"].toString() == tag)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ namespace Qv2ray
|
||||
QMap<QString, CONFIGROOT> GetSubscriptionConnection(QString subscription);
|
||||
QMap<QString, QMap<QString, CONFIGROOT>> GetSubscriptionConnections(QStringList subscriptions);
|
||||
bool CheckIsComplexConfig(CONFIGROOT root);
|
||||
int FindIndexByTag(INOUTLIST list, const QString &tag);
|
||||
|
||||
//
|
||||
// -------------------------- BEGIN CONFIG CONVERSIONS --------------------------
|
||||
|
45
src/components/QvCore/QvCommandLineArgs.cpp
Normal file
45
src/components/QvCore/QvCommandLineArgs.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "QvCommandLineArgs.hpp"
|
||||
#include "Qv2rayBase.hpp"
|
||||
#include <QCommandLineParser>
|
||||
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
namespace CommandArgOperations
|
||||
{
|
||||
// Instantiation
|
||||
QvStartupOptions StartupOption = QvStartupOptions{};
|
||||
|
||||
QvCommandArgParser::QvCommandArgParser() : QObject(),
|
||||
noAPIOption("FAKE"), helpOption("FAKE"), versionOption("FAKE")
|
||||
{
|
||||
parser.setApplicationDescription(QObject::tr("Qv2ray - An cross-platform Qt frontend for V2ray."));
|
||||
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
||||
//
|
||||
noAPIOption = QCommandLineOption("noAPI", QObject::tr("Disable gRPC API subsystems."));
|
||||
parser.addOption(noAPIOption);
|
||||
helpOption = parser.addHelpOption();
|
||||
versionOption = parser.addVersionOption();
|
||||
}
|
||||
|
||||
CommandLineParseResult QvCommandArgParser::ParseCommandLine(QString *errorMessage)
|
||||
{
|
||||
if (!parser.parse(QCoreApplication::arguments())) {
|
||||
*errorMessage = parser.errorText();
|
||||
return CommandLineError;
|
||||
}
|
||||
|
||||
if (parser.isSet(versionOption))
|
||||
return CommandLineVersionRequested;
|
||||
|
||||
if (parser.isSet(helpOption))
|
||||
return CommandLineHelpRequested;
|
||||
|
||||
if (parser.isSet(noAPIOption)) {
|
||||
StartupOption.noAPI = true;
|
||||
}
|
||||
|
||||
return CommandLineOk;
|
||||
}
|
||||
}
|
||||
}
|
44
src/components/QvCore/QvCommandLineArgs.hpp
Normal file
44
src/components/QvCore/QvCommandLineArgs.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef QVCOMMANDLINEARGS_HPP
|
||||
#define QVCOMMANDLINEARGS_HPP
|
||||
|
||||
#include "Qv2rayBase.hpp"
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
namespace CommandArgOperations
|
||||
{
|
||||
struct QvStartupOptions {
|
||||
/// No API subsystem
|
||||
bool noAPI;
|
||||
};
|
||||
enum CommandLineParseResult {
|
||||
CommandLineOk,
|
||||
CommandLineError,
|
||||
CommandLineVersionRequested,
|
||||
CommandLineHelpRequested
|
||||
};
|
||||
//
|
||||
extern QvStartupOptions StartupOption;
|
||||
|
||||
class QvCommandArgParser : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QvCommandArgParser();
|
||||
CommandLineParseResult ParseCommandLine(QString *errorMessage);
|
||||
const QCommandLineParser *Parser()
|
||||
{
|
||||
return &parser;
|
||||
}
|
||||
|
||||
private:
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption noAPIOption;
|
||||
QCommandLineOption helpOption;
|
||||
QCommandLineOption versionOption;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
using namespace Qv2ray::CommandArgOperations;
|
||||
#endif
|
@ -1,10 +1,9 @@
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QDesktopServices>
|
||||
#include "QvCoreInteractions.hpp"
|
||||
#include "QvKernelInteractions.hpp"
|
||||
#include "QvCoreConfigOperations.hpp"
|
||||
|
||||
#include "QvTinyLog.hpp"
|
||||
#include "QvCore/QvCommandLineArgs.hpp"
|
||||
|
||||
using namespace v2ray::core::app::stats::command;
|
||||
using grpc::Channel;
|
||||
@ -16,9 +15,9 @@ using grpc::Status;
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
namespace QvCoreInteration
|
||||
namespace QvKernelInterations
|
||||
{
|
||||
bool ConnectionInstance::ValidateConfig(const QString &path)
|
||||
bool V2rayKernelInstance::ValidateConfig(const QString &path)
|
||||
{
|
||||
auto conf = GetGlobalConfig();
|
||||
|
||||
@ -53,7 +52,7 @@ namespace Qv2ray
|
||||
}
|
||||
}
|
||||
|
||||
ConnectionInstance::ConnectionInstance()
|
||||
V2rayKernelInstance::V2rayKernelInstance()
|
||||
{
|
||||
auto proc = new QProcess();
|
||||
vProcess = proc;
|
||||
@ -63,7 +62,7 @@ namespace Qv2ray
|
||||
ConnectionStatus = STOPPED;
|
||||
}
|
||||
|
||||
bool ConnectionInstance::StartConnection(CONFIGROOT root, int apiPort)
|
||||
bool V2rayKernelInstance::StartConnection(CONFIGROOT root, int apiPort)
|
||||
{
|
||||
inboundTags.clear();
|
||||
|
||||
@ -96,7 +95,10 @@ namespace Qv2ray
|
||||
vProcess->start(GetGlobalConfig().v2CorePath, QStringList() << "-config" << filePath, QIODevice::ReadWrite | QIODevice::Text);
|
||||
vProcess->waitForStarted();
|
||||
ConnectionStatus = STARTED;
|
||||
{
|
||||
|
||||
if (StartupOption.noAPI) {
|
||||
LOG(MODULE_VCORE, "API is disabled by the command line arg \"--noAPI\"")
|
||||
} else {
|
||||
// Config API
|
||||
apiFailedCounter = 0;
|
||||
this->apiPort = apiPort;
|
||||
@ -106,6 +108,7 @@ namespace Qv2ray
|
||||
apiTimerId = startTimer(1000);
|
||||
LOG(MODULE_VCORE, "API Worker started.")
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
ConnectionStatus = STOPPED;
|
||||
@ -113,7 +116,7 @@ namespace Qv2ray
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionInstance::timerEvent(QTimerEvent *event)
|
||||
void V2rayKernelInstance::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
QObject::timerEvent(event);
|
||||
|
||||
@ -134,7 +137,7 @@ namespace Qv2ray
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionInstance::StopConnection()
|
||||
void V2rayKernelInstance::StopConnection()
|
||||
{
|
||||
vProcess->close();
|
||||
killTimer(apiTimerId);
|
||||
@ -144,7 +147,7 @@ namespace Qv2ray
|
||||
ConnectionStatus = STOPPED;
|
||||
}
|
||||
|
||||
ConnectionInstance::~ConnectionInstance()
|
||||
V2rayKernelInstance::~V2rayKernelInstance()
|
||||
{
|
||||
if (ConnectionStatus != STOPPED) {
|
||||
StopConnection();
|
||||
@ -153,7 +156,7 @@ namespace Qv2ray
|
||||
delete vProcess;
|
||||
}
|
||||
|
||||
long ConnectionInstance::CallStatsAPIByName(QString name)
|
||||
long V2rayKernelInstance::CallStatsAPIByName(QString name)
|
||||
{
|
||||
if (ConnectionStatus != STARTED) {
|
||||
LOG(MODULE_VCORE, "Invalid connection status when calling API")
|
||||
@ -186,23 +189,23 @@ namespace Qv2ray
|
||||
return response.stat().value();
|
||||
}
|
||||
// ------------------------------------------------------------- API FUNCTIONS --------------------------
|
||||
long ConnectionInstance::getTagSpeedUp(const QString &tag)
|
||||
long V2rayKernelInstance::getTagSpeedUp(const QString &tag)
|
||||
{
|
||||
return transferSpeed[tag + "_up"];
|
||||
}
|
||||
long ConnectionInstance::getTagSpeedDown(const QString &tag)
|
||||
long V2rayKernelInstance::getTagSpeedDown(const QString &tag)
|
||||
{
|
||||
return transferSpeed[tag + "_down"];
|
||||
}
|
||||
long ConnectionInstance::getTagDataUp(const QString &tag)
|
||||
long V2rayKernelInstance::getTagDataUp(const QString &tag)
|
||||
{
|
||||
return transferData[tag + "_up"];
|
||||
}
|
||||
long ConnectionInstance::getTagDataDown(const QString &tag)
|
||||
long V2rayKernelInstance::getTagDataDown(const QString &tag)
|
||||
{
|
||||
return transferData[tag + "_down"];
|
||||
}
|
||||
long ConnectionInstance::getAllDataUp()
|
||||
long V2rayKernelInstance::getAllDataUp()
|
||||
{
|
||||
long val = 0;
|
||||
|
||||
@ -212,7 +215,7 @@ namespace Qv2ray
|
||||
|
||||
return val;
|
||||
}
|
||||
long ConnectionInstance::getAllDataDown()
|
||||
long V2rayKernelInstance::getAllDataDown()
|
||||
{
|
||||
long val = 0;
|
||||
|
||||
@ -222,7 +225,7 @@ namespace Qv2ray
|
||||
|
||||
return val;
|
||||
}
|
||||
long ConnectionInstance::getAllSpeedUp()
|
||||
long V2rayKernelInstance::getAllSpeedUp()
|
||||
{
|
||||
long val = 0;
|
||||
|
||||
@ -232,7 +235,7 @@ namespace Qv2ray
|
||||
|
||||
return val;
|
||||
}
|
||||
long ConnectionInstance::getAllSpeedDown()
|
||||
long V2rayKernelInstance::getAllSpeedDown()
|
||||
{
|
||||
long val = 0;
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef VINTERACT_H
|
||||
#define VINTERACT_H
|
||||
#include <QProcess>
|
||||
#include <QString>
|
||||
#include "Qv2rayBase.hpp"
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "QvUtils.hpp"
|
||||
#include "v2ray_api_commands.pb.h"
|
||||
@ -10,7 +8,7 @@
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
namespace QvCoreInteration
|
||||
namespace QvKernelInterations
|
||||
{
|
||||
enum QvInstanceStatus {
|
||||
STOPPED,
|
||||
@ -18,12 +16,12 @@ namespace Qv2ray
|
||||
STARTED
|
||||
};
|
||||
|
||||
class ConnectionInstance : public QObject
|
||||
class V2rayKernelInstance : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConnectionInstance();
|
||||
~ConnectionInstance() override;
|
||||
explicit V2rayKernelInstance();
|
||||
~V2rayKernelInstance() override;
|
||||
//
|
||||
// Speed
|
||||
long getTagSpeedUp(const QString &tag);
|
||||
@ -63,6 +61,6 @@ namespace Qv2ray
|
||||
}
|
||||
}
|
||||
|
||||
using namespace Qv2ray::QvCoreInteration;
|
||||
using namespace Qv2ray::QvKernelInterations;
|
||||
|
||||
#endif // VINTERACT_H
|
31
src/main.cpp
31
src/main.cpp
@ -11,6 +11,8 @@
|
||||
|
||||
#include "w_MainWindow.hpp"
|
||||
|
||||
#include "QvCore/QvCommandLineArgs.hpp"
|
||||
|
||||
bool verifyConfigAvaliability(QString path, bool checkExistingConfig)
|
||||
{
|
||||
// Does not exist.
|
||||
@ -207,6 +209,28 @@ int main(int argc, char *argv[])
|
||||
LOG(MODULE_UI, "Installing a tranlator from OS: " + _lang.toStdString() + " -- " + (_result_ ? "OK" : "Failed"))
|
||||
}
|
||||
|
||||
QvCommandArgParser parser;
|
||||
QString errorMessage;
|
||||
|
||||
switch (parser.ParseCommandLine(&errorMessage)) {
|
||||
case CommandLineOk:
|
||||
break;
|
||||
|
||||
case CommandLineError:
|
||||
cout << errorMessage.toStdString() << endl;
|
||||
cout << parser.Parser()->helpText().toStdString() << endl;
|
||||
return 1;
|
||||
|
||||
case CommandLineVersionRequested:
|
||||
LOG(QCoreApplication::applicationName().toStdString(), QCoreApplication::applicationVersion().toStdString());
|
||||
return 0;
|
||||
|
||||
case CommandLineHelpRequested:
|
||||
cout << parser.Parser()->helpText().toStdString() << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
LOG("LICENCE", NEWLINE "This program comes with ABSOLUTELY NO WARRANTY." NEWLINE
|
||||
"This is free software, and you are welcome to redistribute it" NEWLINE
|
||||
"under certain conditions." NEWLINE NEWLINE
|
||||
@ -250,7 +274,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Load the config for upgrade, but do not parse it to the struct.
|
||||
auto conf = JsonFromString(StringFromFile(new QFile(QV2RAY_CONFIG_FILE)));
|
||||
//
|
||||
auto confVersion = conf["config_version"].toVariant().toString().toInt();
|
||||
|
||||
if (confVersion > QV2RAY_CONFIG_VERSION) {
|
||||
@ -261,7 +284,7 @@ int main(int argc, char *argv[])
|
||||
QObject::tr("Please check if there's an issue explaining about it.") + NEWLINE +
|
||||
QObject::tr("Or submit a new issue if you think this is an error.") + NEWLINE + NEWLINE +
|
||||
QObject::tr("Qv2ray will now exit."));
|
||||
return -3;
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (confVersion < QV2RAY_CONFIG_VERSION) {
|
||||
@ -313,7 +336,7 @@ int main(int argc, char *argv[])
|
||||
QObject::tr("Technical Details") + "\r\n" +
|
||||
"OSsl.Rq.V=" + osslReqVersion + "\r\n" +
|
||||
"OSsl.Cr.V=" + osslCurVersion);
|
||||
return -2;
|
||||
return -3;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@ -386,7 +409,7 @@ int main(int argc, char *argv[])
|
||||
} catch (...) {
|
||||
QvMessageBox(nullptr, "ERROR", "There's something wrong happened and Qv2ray will quit now.");
|
||||
LOG(MODULE_INIT, "EXCEPTION THROWN: " __FILE__)
|
||||
return -9;
|
||||
return -99;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "qzxing/src/QZXing.h"
|
||||
|
||||
#include "QvUtils.hpp"
|
||||
#include "QvCoreInteractions.hpp"
|
||||
#include "QvKernelInteractions.hpp"
|
||||
#include "QvCoreConfigOperations.hpp"
|
||||
|
||||
#include "w_ScreenShot_Core.hpp"
|
||||
@ -70,7 +70,7 @@ void ImportConfigWindow::on_beginImportBtn_clicked()
|
||||
bool keepInBound = keepImportedInboundCheckBox->isChecked();
|
||||
QString path = fileLineTxt->text();
|
||||
|
||||
if (!ConnectionInstance::ValidateConfig(path)) {
|
||||
if (!V2rayKernelInstance::ValidateConfig(path)) {
|
||||
QvMessageBox(this, tr("Import config file"), tr("Failed to check the validity of the config file."));
|
||||
return;
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ MainWindow::MainWindow(QWidget *parent):
|
||||
{
|
||||
MainWindow::mwInstance = this;
|
||||
currentConfig = GetGlobalConfig();
|
||||
vinstance = new ConnectionInstance();
|
||||
connect(vinstance, &ConnectionInstance::onProcessOutputReadyRead, this, &MainWindow::UpdateVCoreLog);
|
||||
vinstance = new V2rayKernelInstance();
|
||||
connect(vinstance, &V2rayKernelInstance::onProcessOutputReadyRead, this, &MainWindow::UpdateVCoreLog);
|
||||
setupUi(this);
|
||||
//
|
||||
// Two browsers
|
||||
@ -957,13 +957,13 @@ void MainWindow::timerEvent(QTimerEvent *event)
|
||||
auto _totalDataUp = vinstance->getAllDataUp();
|
||||
auto _totalDataDown = vinstance->getAllDataDown();
|
||||
//
|
||||
double max = 0;
|
||||
double _max = 0;
|
||||
double historyMax = 0;
|
||||
auto graphVUp = _totalSpeedUp / 1024;
|
||||
auto graphVDown = _totalSpeedDown / 1024;
|
||||
|
||||
for (auto i = 0; i < 29; i++) {
|
||||
historyMax = MAX(historyMax, MAX(uploadList[i + 1], downloadList[i + 1]));
|
||||
historyMax = max(historyMax, max(uploadList[i + 1], downloadList[i + 1]));
|
||||
uploadList[i] = uploadList[i + 1];
|
||||
downloadList[i] = downloadList[i + 1];
|
||||
uploadSerie->replace(i, i, uploadList[i + 1]);
|
||||
@ -975,8 +975,8 @@ void MainWindow::timerEvent(QTimerEvent *event)
|
||||
uploadSerie->replace(29, 29, graphVUp);
|
||||
downloadSerie->replace(29, 29, graphVDown);
|
||||
//
|
||||
max = MAX(MAX(graphVUp, graphVDown), historyMax);
|
||||
speedChartObj->axes(Qt::Vertical).first()->setRange(0, max * 1.2);
|
||||
_max = max(historyMax, double(max(graphVUp, graphVDown)));
|
||||
speedChartObj->axes(Qt::Vertical).first()->setRange(0, _max * 1.2);
|
||||
//
|
||||
auto totalSpeedUp = FormatBytes(_totalSpeedUp) + "/s";
|
||||
auto totalSpeedDown = FormatBytes(_totalSpeedDown) + "/s";
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "ui_w_MainWindow.h"
|
||||
|
||||
#include "QvUtils.hpp"
|
||||
#include "QvCoreInteractions.hpp"
|
||||
#include "QvKernelInteractions.hpp"
|
||||
#include "QvCoreConfigOperations.hpp"
|
||||
#include "QvHTTPRequestHelper.hpp"
|
||||
#include "QvPACHandler.hpp"
|
||||
@ -74,7 +74,7 @@ class MainWindow : public QMainWindow, Ui::MainWindow
|
||||
public:
|
||||
static MainWindow *mwInstance;
|
||||
QString CurrentConnectionName = "";
|
||||
ConnectionInstance *vinstance;
|
||||
V2rayKernelInstance *vinstance;
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "QvUtils.hpp"
|
||||
#include "QvCoreInteractions.hpp"
|
||||
#include "QvKernelInteractions.hpp"
|
||||
#include "QvNetSpeedPlugin.hpp"
|
||||
#include "QvCoreConfigOperations.hpp"
|
||||
|
||||
|
@ -9,7 +9,6 @@ namespace Qv2ray
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
|
||||
QTranslator *getTranslator(const QString &lang);
|
||||
QStringList GetFileList(QDir dir);
|
||||
QString Base64Encode(QString string);
|
||||
|
Loading…
Reference in New Issue
Block a user