[Fixed] Fixed an auto update bug in Win32 env.

Former-commit-id: c01b80c9d6
This commit is contained in:
Leroy.H.Y 2019-08-19 15:34:14 +08:00
parent 754ee71b05
commit 5e183fc59e
16 changed files with 114 additions and 85 deletions

View File

@ -8,21 +8,17 @@ QT += core gui widgets network
TARGET = Qv2ray
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
CONFIG += c++11 openssl-linked lrelease
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
win32: QMAKE_TARGET_DESCRIPTION = "Qv2ray, a cross-platform v2ray GUI client."
win32: QMAKE_TARGET_PRODUCT = "Qv2ray"
CONFIG += c++11
VERSION = 1.3.3
DEFINES += "QVVERSION=\"\\\"$${VERSION}\\\"\""
SOURCES += \
src/QvConfigUpgrade.cpp \
src/QvCoreConfigOperations_Convertion.cpp \
src/QvCoreConfigOperations_Generation.cpp \
src/QvCoreConfigOperations_Verification.cpp \
@ -38,7 +34,6 @@ SOURCES += \
src/w_SubscribeEditor.cpp
HEADERS += \
ignored_cpp_structs.hpp \
src/QJsonObjectInsertMacros.h \
src/Qv2rayBase.h \
src/QvCoreConfigObjects.h \
@ -70,16 +65,14 @@ TRANSLATIONS += \
translations/en-US.ts
RC_ICONS += ./icons/Qv2ray.ico
ICON = ./icons/Qv2ray.icns
INCLUDEPATH += \
3rdparty/\
3rdparty/ \
3rdparty/jsoncons/include
win32: QMAKE_CXXFLAGS += "-Wno-missing-field-initializers"
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
unix: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

BIN
libs/libcrypto-1_1.dll Normal file

Binary file not shown.

BIN
libs/libssl-1_1.dll Normal file

Binary file not shown.

View File

@ -1,15 +1,15 @@
#ifndef HCONFIGOBJECTS_H
#define HCONFIGOBJECTS_H
#ifndef QV2RAYBASE_H
#define QV2RAYBASE_H
#include <QtCore>
#include "QvTinyLog.h"
#include "QvCoreConfigObjects.h"
#define QV2RAY_VERSION_STRING "v1.3.2"
#define QV2RAY_CONFIG_VERSION "1.1"
#define QV2RAY_CONFIG_PATH (Qv2ray::Utils::GetConfigDirPath() + "/")
#define QV2RAY_GUI_CONFIG_PATH (QV2RAY_CONFIG_PATH + "Qv2ray.conf")
#define QV2RAY_GENERATED_CONFIG_FILE_PATH (QV2RAY_CONFIG_PATH + "generated/config.gen.json")
#define QV2RAY_CONFIG_VERSION "2"
#define QV2RAY_VERSION_STRING "v" QVVERSION
#define QV2RAY_CONFIG_DIR_PATH (Qv2ray::Utils::GetConfigDirPath() + "/")
#define QV2RAY_CONFIG_FILE_PATH (QV2RAY_CONFIG_DIR_PATH + "Qv2ray.conf")
#define QV2RAY_GENERATED_FILE_PATH (QV2RAY_CONFIG_DIR_PATH + "generated/config.gen.json")
#define QV2RAY_VCORE_LOG_DIRNAME "logs/"
#define QV2RAY_VCORE_ACCESS_LOG_FILENAME "access.log"
@ -19,14 +19,14 @@
// GUI TOOLS
#define RED(obj) \
auto _p = ui->obj->palette(); \
_p.setColor(QPalette::Text, Qt::red); \
ui->obj->setPalette(_p);
auto _temp = ui->obj->palette(); \
_temp.setColor(QPalette::Text, Qt::red); \
ui->obj->setPalette(_temp);
#define BLACK(obj) \
auto _p = ui->obj->palette(); \
_p.setColor(QPalette::Text, Qt::black); \
ui->obj->setPalette(_p);
auto _temp = ui->obj->palette(); \
_temp.setColor(QPalette::Text, Qt::black); \
ui->obj->setPalette(_temp);
#define QSTRING(std_string) QString::fromStdString(std_string)
@ -36,12 +36,11 @@
#define NEWLINE "\r"
#endif
namespace Qv2ray
{
namespace QvConfigModels
{
struct QvBasicInboundSetting {
struct Qv2rayBasicInboundsConfig {
string listenip;
// SOCKS
int socks_port;
@ -51,12 +50,8 @@ namespace Qv2ray
int http_port;
bool http_useAuth;
AccountObject httpAccount;
QvBasicInboundSetting():
listenip(),
socks_port(), socks_useAuth(), socksAccount(),
http_port(), http_useAuth(), httpAccount() {}
QvBasicInboundSetting(string listen, int socksPort, int httpPort): QvBasicInboundSetting()
{
Qv2rayBasicInboundsConfig(): listenip(), socks_port(), socks_useAuth(), socksAccount(), http_port(), http_useAuth(), httpAccount() {}
Qv2rayBasicInboundsConfig(string listen, int socksPort, int httpPort): Qv2rayBasicInboundsConfig() {
socks_port = socksPort;
http_port = httpPort;
listenip = listen;
@ -64,7 +59,7 @@ namespace Qv2ray
XTOSTRUCT(O(listenip, socks_port, socks_useAuth, socksAccount, http_port, http_useAuth, httpAccount))
};
struct Qv2Config {
struct Qv2rayConfig {
string config_version;
bool runAsRoot;
int logLevel;
@ -81,13 +76,13 @@ namespace Qv2ray
bool withLocalDNS;
list<string> dnsList;
//
QvBasicInboundSetting inBoundSettings;
Qv2rayBasicInboundsConfig inBoundSettings;
list<string> configs;
map<string, string> subscribes;
MuxObject mux;
Qv2Config(): config_version(QV2RAY_CONFIG_VERSION), runAsRoot(false), logLevel(), proxyDefault(), proxyCN(), withLocalDNS(), inBoundSettings(), configs(), subscribes(), mux() { }
Qv2Config(string lang, string exePath, string assetsPath, int log, QvBasicInboundSetting _inBoundSettings): Qv2Config()
{
Qv2rayConfig(): config_version(QV2RAY_CONFIG_VERSION), runAsRoot(false), logLevel(), proxyDefault(), proxyCN(), withLocalDNS(), inBoundSettings(), configs(), subscribes(), mux() { }
Qv2rayConfig(string lang, string exePath, string assetsPath, int log, Qv2rayBasicInboundsConfig _inBoundSettings): Qv2rayConfig() {
// These settings below are defaults.
ignoredVersion = "";
autoStartConfig = "";
language = lang;
@ -106,14 +101,14 @@ namespace Qv2ray
}
XTOSTRUCT(O(config_version, runAsRoot, logLevel, language, autoStartConfig, ignoredVersion, v2CorePath, v2AssetsPath, proxyDefault, proxyCN, withLocalDNS, dnsList, inBoundSettings, mux, configs, subscribes))
};
QJsonObject UpgradeConfig(int fromVersion, int toVersion, QJsonObject root);
}
}
// I want to use all namespaces
using namespace std;
using namespace Qv2ray;
using namespace Qv2ray::V2ConfigModels;
using namespace Qv2ray::QvConfigModels;
#endif // QCONFIGOBJECTS_H
#endif // QV2RAYBASE_H

27
src/QvConfigUpgrade.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "Qv2rayBase.h"
#define XConfLog(oldVersion, newVersion) LOG(MODULE_CONFIG, "Migrating config from version " \
+ to_string(oldVersion) + " to " + to_string(newVersion))
namespace Qv2ray {
namespace QvConfigModels {
// Secret member
QJsonObject UpgradeConfig_Inc(int fromVersion, QJsonObject root) {
XConfLog(fromVersion, fromVersion + 1);
switch (fromVersion) {
case 1:
break;
}
return root;
}
// Exported function
QJsonObject UpgradeConfig(int fromVersion, int toVersion, QJsonObject root) {
for (int i = fromVersion; i < toVersion; i++) {
root = UpgradeConfig_Inc(i, root);
}
return root;
}
}
}

View File

@ -6,7 +6,7 @@ namespace Qv2ray
// -------------------------- BEGIN CONFIG CONVERSIONS ----------------------------------------------------------------------------
bool SaveConnectionConfig(QJsonObject obj, const QString *alias)
{
QFile config(QV2RAY_CONFIG_PATH + *alias + QV2RAY_CONNECTION_FILE_EXTENSION);
QFile config(QV2RAY_CONFIG_DIR_PATH + *alias + QV2RAY_CONNECTION_FILE_EXTENSION);
return StringToFile(JSONToString(obj), &config);
}
@ -109,7 +109,7 @@ namespace Qv2ray
QMap<QString, QJsonObject> list;
foreach (auto conn, connectionNames) {
QString jsonString = StringFromFile(new QFile(QV2RAY_CONFIG_PATH + QString::fromStdString(conn) + QV2RAY_CONNECTION_FILE_EXTENSION));
QString jsonString = StringFromFile(new QFile(QV2RAY_CONFIG_DIR_PATH + QString::fromStdString(conn) + QV2RAY_CONNECTION_FILE_EXTENSION));
QJsonObject connectionObject = JSONFromString(jsonString);
list.insert(QString::fromStdString(conn), connectionObject);
}
@ -119,13 +119,13 @@ namespace Qv2ray
bool RenameConnection(QString originalName, QString newName)
{
return QFile(QV2RAY_CONFIG_PATH + originalName + QV2RAY_CONNECTION_FILE_EXTENSION).rename(QV2RAY_CONFIG_PATH + newName + QV2RAY_CONNECTION_FILE_EXTENSION);
return QFile(QV2RAY_CONFIG_DIR_PATH + originalName + QV2RAY_CONNECTION_FILE_EXTENSION).rename(QV2RAY_CONFIG_DIR_PATH + newName + QV2RAY_CONNECTION_FILE_EXTENSION);
}
int StartPreparation(QJsonObject fullConfig)
{
QString json = JSONToString(fullConfig);
StringToFile(json, new QFile(QV2RAY_GENERATED_CONFIG_FILE_PATH));
StringToFile(json, new QFile(QV2RAY_GENERATED_FILE_PATH));
return 0;
}
}

View File

@ -64,12 +64,12 @@ namespace Qv2ray
Status = STARTING;
if (ValidateV2rayCoreExe()) {
if (VerifyVConfigFile(QV2RAY_GENERATED_CONFIG_FILE_PATH)) {
if (VerifyVConfigFile(QV2RAY_GENERATED_FILE_PATH)) {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("V2RAY_LOCATION_ASSET", QString::fromStdString(GetGlobalConfig().v2AssetsPath));
vProcess->setProcessEnvironment(env);
vProcess->start(QString::fromStdString(GetGlobalConfig().v2CorePath), QStringList() << "-config"
<< QV2RAY_GENERATED_CONFIG_FILE_PATH,
<< QV2RAY_GENERATED_FILE_PATH,
QIODevice::ReadWrite | QIODevice::Text);
vProcess->waitForStarted();
Status = STARTED;

View File

@ -76,6 +76,7 @@ namespace Qv2ray
void QvHttpRequestHelper::onRequestFinished()
{
LOG(MODULE_NETWORK, "Network request errcode: " + to_string(reply->error()));
emit httpRequestFinished(this->data);
}

View File

@ -11,9 +11,11 @@ using namespace std;
#define MODULE_INIT "INIT"
#define MODULE_UPDATE "UPDATE"
#define MODULE_VCORE "VCORE"
#define MODULE_CONFIG "CONFIG"
#define MODULE_CONNECTION_VMESS "CONNETION-VMESS"
#define MODULE_CONNECTION "CONNECTION"
#define MODULE_UI "UI"
#define MODULE_NETWORK "NETWORK"
#define MODULE_FILE "FILE"
#endif // QVTINYLOG_H

View File

@ -5,14 +5,14 @@ namespace Qv2ray
{
namespace Utils
{
static Qv2Config GlobalConfig;
static Qv2rayConfig GlobalConfig;
static QString ConfigDirPath;
void SetGlobalConfig(Qv2Config conf)
void SetGlobalConfig(Qv2rayConfig conf)
{
GlobalConfig = conf;
}
Qv2Config GetGlobalConfig()
Qv2rayConfig GetGlobalConfig()
{
return GlobalConfig;
}
@ -29,7 +29,7 @@ namespace Qv2ray
void SaveGlobalConfig()
{
QFile config(QV2RAY_GUI_CONFIG_PATH);
QFile config(QV2RAY_CONFIG_FILE_PATH);
QString str = StructToJSONString(GetGlobalConfig());
StringToFile(str, &config);
}
@ -89,11 +89,11 @@ namespace Qv2ray
void LoadGlobalConfig()
{
QFile file(QV2RAY_GUI_CONFIG_PATH);
QFile file(QV2RAY_CONFIG_FILE_PATH);
file.open(QFile::ReadOnly);
QTextStream stream(&file);
auto str = stream.readAll();
auto config = StructFromJSONString<Qv2Config>(str);
auto config = StructFromJSONString<Qv2rayConfig>(str);
SetGlobalConfig(config);
file.close();
}

View File

@ -21,8 +21,8 @@ namespace Qv2ray
void SetConfigDirPath(QString path);
QString GetConfigDirPath();
void SetGlobalConfig(Qv2Config conf);
Qv2Config GetGlobalConfig();
void SetGlobalConfig(Qv2rayConfig conf);
Qv2rayConfig GetGlobalConfig();
void SaveGlobalConfig();
void LoadGlobalConfig();

View File

@ -34,17 +34,17 @@ bool initQv()
auto ConfigDir = new QDir(configPath);
if (!ConfigDir->exists()) {
auto result = QDir().mkdir(QV2RAY_CONFIG_PATH);
auto result = QDir().mkdir(QV2RAY_CONFIG_DIR_PATH);
if (result) {
LOG(MODULE_INIT, "Created Qv2ray config dir at: " + QV2RAY_CONFIG_PATH.toStdString())
LOG(MODULE_INIT, "Created Qv2ray config dir at: " + QV2RAY_CONFIG_DIR_PATH.toStdString())
} else {
LOG(MODULE_INIT, "Failed to create config dir at: " + QV2RAY_CONFIG_PATH.toStdString())
LOG(MODULE_INIT, "Failed to create config dir at: " + QV2RAY_CONFIG_DIR_PATH.toStdString())
return false;
}
}
auto genPath = QV2RAY_CONFIG_PATH + "generated/";
auto genPath = QV2RAY_CONFIG_DIR_PATH + "generated/";
if (!QDir(genPath).exists()) {
auto result2 = QDir().mkdir(genPath);
@ -56,20 +56,24 @@ bool initQv()
return false;
}
}
if (!QFile(QV2RAY_GUI_CONFIG_PATH).exists()) {
QFile configFile(QV2RAY_CONFIG_FILE_PATH);
if (!configFile.exists()) {
// This is first run!
//
// These below genenrated very basic global config.
QvBasicInboundSetting inboundSetting = QvBasicInboundSetting("127.0.0.1", 1080, 8000);
Qv2Config conf = Qv2Config("zh-CN", exeDefaultPath.toStdString(), v2AssetsPath.toStdString(), 2, inboundSetting);
Qv2rayBasicInboundsConfig inboundSetting = Qv2rayBasicInboundsConfig("127.0.0.1", 1080, 8000);
Qv2rayConfig conf = Qv2rayConfig("zh-CN", exeDefaultPath.toStdString(), v2AssetsPath.toStdString(), 2, inboundSetting);
//
// Save initial config.
SetGlobalConfig(conf);
SaveGlobalConfig();
//
LOG(MODULE_INIT, "Created initial default config file.")
LOG(MODULE_INIT, "Created initial config file.")
} else {
auto conf = JSONFromString(StringFromFile(&configFile));
if(conf["config_version"].toString() != QV2RAY_CONFIG_VERSION) {
UpgradeConfig(stoi(conf["config_version"].toString().toStdString()), stoi(QV2RAY_CONFIG_VERSION), conf);
}
LoadGlobalConfig();
LOG(MODULE_INIT, "Loaded config file.")
}
@ -87,12 +91,10 @@ int main(int argc, char *argv[])
"Hv2ray/Qv2ray (partial) Copyright 2019 (C) SoneWinstone\r\n"
"Qv2ray Copyright (C) 2019 Leroy.H.Y\r\n"
"\r\n"
"Qv2ray Version: " QV2RAY_VERSION_STRING
"\r\n"
"OS: " + QSysInfo::prettyProductName().toStdString() +
"\r\n"
"Arch: " + QSysInfo::currentCpuArchitecture().toStdString())
LOG("DEBUG", "============================== This is a debug build ==============================")
"Qv2ray " QV2RAY_VERSION_STRING " running on " + QSysInfo::prettyProductName().toStdString() + QSysInfo::currentCpuArchitecture().toStdString())
#ifdef QT_DEBUG
LOG("DEBUG", "============================== This is a debug build, many features are not stable enough. ==============================")
#endif
//
QApplication _qApp(argc, argv);
//
@ -128,11 +130,21 @@ int main(int argc, char *argv[])
);
if (!guard.isSingleInstance()) {
LOG(MODULE_INIT, "Another Instance running, QUIT.")
Utils::QvMessageBox(nullptr, "Qv2ray", QObject::tr("#AnotherInstanceRunning"));
LOG(MODULE_INIT, "Another Instance running, Quit.")
QvMessageBox(nullptr, "Qv2ray", QObject::tr("#AnotherInstanceRunning"));
return -1;
}
#ifdef __WIN32
auto osslReqVersion = QSslSocket::sslLibraryBuildVersionString().toStdString();
auto osslCurVersion = QSslSocket::sslLibraryVersionString().toStdString();
if (osslCurVersion != osslReqVersion){
LOG(MODULE_NETWORK, "Required OpenSSL version: " + osslReqVersion)
LOG(MODULE_NETWORK, "Current OpenSSL version: " + osslCurVersion)
QvMessageBox(nullptr, QObject::tr("DependencyMissing"), QObject::tr("osslDependMissing,PleaseReDownload"));
LOG(MODULE_NETWORK, "OpenSSL library MISSING, Quitting.")
return -2;
}
#endif
// Show MainWindow
MainWindow w;
return _qApp.exec();

View File

@ -75,7 +75,7 @@ void ImportConfigWindow::on_buttonBox_accepted()
config.remove("QV2RAY_ALIAS");
}
Qv2Config conf = GetGlobalConfig();
Qv2rayConfig conf = GetGlobalConfig();
conf.configs.push_back(alias.toStdString());
SetGlobalConfig(conf);
auto needReload = SaveConnectionConfig(config, &alias);

View File

@ -210,7 +210,7 @@ void MainWindow::on_stopButton_clicked()
LOG(MODULE_VCORE, "Disconnected: " + CurrentConnectionName.toStdString())
this->vinstance->Stop();
hTray->setToolTip(TRAY_TOOLTIP_PREFIX);
QFile(QV2RAY_GENERATED_CONFIG_FILE_PATH).remove();
QFile(QV2RAY_GENERATED_FILE_PATH).remove();
ui->statusLabel->setText(tr("#Disconnected"));
ui->logText->clear();
trayMenu->actions()[2]->setEnabled(true);

View File

@ -27,7 +27,6 @@ class MainWindow : public QMainWindow
void UpdateLog();
private slots:
void VersionUpdate(QByteArray &data);
void on_restartButton_clicked();
void on_startButton_clicked();
void on_stopButton_clicked();
void on_activatedTray(QSystemTrayIcon::ActivationReason reason);
@ -48,9 +47,6 @@ class MainWindow : public QMainWindow
void on_connectionListWidget_customContextMenuRequested(const QPoint &pos);
void on_action_RenameConnection_triggered();
void on_action_StartThis_triggered();
void on_connectionListWidget_itemChanged(QListWidgetItem *item);
void on_removeConfigButton_clicked();
@ -62,6 +58,9 @@ class MainWindow : public QMainWindow
void on_editConfigButton_clicked();
private:
void on_action_StartThis_triggered();
void on_action_RenameConnection_triggered();
void on_restartButton_clicked();
Ui::MainWindow *ui;
QvHttpRequestHelper HTTPRequestHelper;
QSystemTrayIcon *hTray;

View File

@ -77,7 +77,7 @@ class PrefrencesWindow : public QDialog
private:
bool IsConnectionPropertyChanged = false;
bool finishedLoading = false;
Qv2ray::QvConfigModels::Qv2Config CurrentConfig;
Qv2ray::QvConfigModels::Qv2rayConfig CurrentConfig;
Ui::PrefrencesWindow *ui;
};
#endif // HVCONF_H