diff --git a/README.md b/README.md index e068470..a76b0dc 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ launcher 参数 - [MatsuriDayo/Matsuri](https://github.com/MatsuriDayo/Matsuri) - [MatsuriDayo/v2ray-core](https://github.com/MatsuriDayo/v2ray-core) - [SagerNet/sing-box](https://github.com/SagerNet/sing-box) +- [Qv2ray](https://github.com/Qv2ray/Qv2ray) - [Qt](https://www.qt.io/) - [protobuf](https://github.com/protocolbuffers/protobuf) - [yaml-cpp](https://github.com/jbeder/yaml-cpp) diff --git a/db/ConfigBuilder.cpp b/db/ConfigBuilder.cpp index 09d0a50..a3ca8d7 100644 --- a/db/ConfigBuilder.cpp +++ b/db/ConfigBuilder.cpp @@ -724,17 +724,17 @@ namespace NekoRay { }); // api - result->coreConfig.insert("experimental", QJsonObject{ - {"v2ray_api", QJsonObject{ - {"listen", "127.0.0.1:" + Int2String(dataStore->inbound_socks_port + 10)}, - {"stats", QJsonObject{ - {"enabled", true}, - {"outbounds", QJsonArray{ - tagProxy, "bypass", "block" - }}, - }} - }}, - }); + if (dataStore->traffic_loop_interval > 0) { + result->coreConfig.insert("experimental", QJsonObject{ + {"v2ray_api", QJsonObject{ + {"listen", "127.0.0.1:" + Int2String(dataStore->inbound_socks_port + 10)}, + {"stats", QJsonObject{ + {"enabled", true}, + {"outbounds", QJsonArray{tagProxy, "bypass"}}, + }} + }}, + }); + } return result; } diff --git a/main/NekoRay.cpp b/main/NekoRay.cpp index 4b686fd..f965076 100644 --- a/main/NekoRay.cpp +++ b/main/NekoRay.cpp @@ -11,7 +11,7 @@ namespace NekoRay { // datastore - DataStore::DataStore() : JsonStore("groups/nekoray.json") { + DataStore::DataStore() : JsonStore() { _add(new configItem("extraCore", dynamic_cast(extraCore), itemType::jsonStore)); _add(new configItem("user_agent", &user_agent, itemType::string)); @@ -58,7 +58,6 @@ namespace NekoRay { _add(new configItem("vpn_bypass_process", &vpn_bypass_process, itemType::string)); _add(new configItem("vpn_bypass_cidr", &vpn_bypass_cidr, itemType::string)); _add(new configItem("check_include_pre", &check_include_pre, itemType::boolean)); - _add(new configItem("neko_core", &neko_core, itemType::integer)); } void DataStore::UpdateStartedId(int id) { @@ -110,15 +109,15 @@ namespace NekoRay { QStringList Routing::List() { QStringList l; QDir d; - if (d.exists("routes")) { - QDir dr("routes"); + if (d.exists(ROUTES_PREFIX)) { + QDir dr(ROUTES_PREFIX); return dr.entryList(QDir::Files); } return l; } void Routing::SetToActive(const QString &name) { - dataStore->routing->fn = "routes/" + name; + dataStore->routing->fn = ROUTES_PREFIX + name; dataStore->routing->Load(); dataStore->active_routing = name; dataStore->Save(); diff --git a/main/NekoRay_DataStore.hpp b/main/NekoRay_DataStore.hpp index 2ea7b3f..a704e32 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoRay_DataStore.hpp @@ -2,7 +2,7 @@ namespace NekoRay { - QString FindCoreAsset(const QString& name); + QString FindCoreAsset(const QString &name); class Routing : public JsonStore { public: @@ -58,8 +58,6 @@ namespace NekoRay { // Saved // Misc - int neko_core = CoreType::V2RAY; - QString log_level = "warning"; QString user_agent = "Nekoray/1.0 (Prefer Clash Format)"; bool sub_use_proxy = false; @@ -129,6 +127,10 @@ namespace NekoRay { extern DataStore *dataStore; + inline int coreType = NekoRay::CoreType::V2RAY; + } -#define IS_NEKO_BOX (NekoRay::dataStore->neko_core == NekoRay::CoreType::SING_BOX) +#define IS_NEKO_BOX (NekoRay::coreType == NekoRay::CoreType::SING_BOX) +#define ROUTES_PREFIX_NAME QString( IS_NEKO_BOX ? "routes_box" : "routes" ) +#define ROUTES_PREFIX QString( ROUTES_PREFIX_NAME + "/" ) diff --git a/main/main.cpp b/main/main.cpp index 594833c..d00e2f7 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -86,6 +86,9 @@ int main(int argc, char *argv[]) { QIcon::setThemeName("breeze"); } + // Load coreType + NekoRay::coreType = ReadFileText("groups/coreType").toInt(); // default to 0 + // Dir QDir dir; bool dir_success = true; @@ -95,8 +98,8 @@ int main(int argc, char *argv[]) { if (!dir.exists("groups")) { dir_success = dir_success && dir.mkdir("groups"); } - if (!dir.exists("routes")) { - dir_success = dir_success && dir.mkdir("routes"); + if (!dir.exists(ROUTES_PREFIX_NAME)) { + dir_success = dir_success && dir.mkdir(ROUTES_PREFIX_NAME); } if (!dir_success) { QMessageBox::warning(nullptr, "Error", "No permission to write " + dir.absolutePath()); @@ -104,13 +107,24 @@ int main(int argc, char *argv[]) { } // Load dataStore + switch (NekoRay::coreType) { + case NekoRay::CoreType::V2RAY: + NekoRay::dataStore->fn = "groups/nekoray.json"; + break; + case NekoRay::CoreType::SING_BOX: + NekoRay::dataStore->fn = "groups/nekobox.json"; + break; + default: + MessageBoxWarning("Error", "Unknown coreType."); + return 0; + } auto isLoaded = NekoRay::dataStore->Load(); if (!isLoaded) { NekoRay::dataStore->Save(); } // load routing - NekoRay::dataStore->routing->fn = "routes/" + NekoRay::dataStore->active_routing; + NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing; isLoaded = NekoRay::dataStore->routing->Load(); if (!isLoaded) { NekoRay::dataStore->routing->Save(); diff --git a/ui/dialog_basic_settings.cpp b/ui/dialog_basic_settings.cpp index db73f87..f592cae 100644 --- a/ui/dialog_basic_settings.cpp +++ b/ui/dialog_basic_settings.cpp @@ -194,8 +194,11 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) tr("Switching the core to %1, click \"Yes\" to complete the switch and the program will restart. This feature may be unstable, please do not switch frequently.") .arg(core_name_new) ) == QMessageBox::StandardButton::Yes) { - NekoRay::dataStore->neko_core = neko_core_new; - NekoRay::dataStore->Save(); + QFile file; + file.setFileName("groups/coreType"); + file.open(QIODevice::ReadWrite | QIODevice::Truncate); + file.write(Int2String(neko_core_new).toUtf8()); + file.close(); dialog_message("", "SwitchCore"); } }; @@ -268,14 +271,12 @@ void DialogBasicSettings::on_set_custom_icon_clicked() { if (c == 0) { auto fn = QFileDialog::getOpenFileName(this, QObject::tr("Select"), QDir::currentPath(), "*.png", nullptr, QFileDialog::Option::ReadOnly); - if (!fn.isEmpty()) { - QImage img(fn); - if (img.isNull() || img.height() != img.width()) { - MessageBoxWarning(title, tr("Please select a valid square image.")); - return; - } - QFile::copy(fn, user_icon_path); + QImage img(fn); + if (img.isNull() || img.height() != img.width()) { + MessageBoxWarning(title, tr("Please select a valid square image.")); + return; } + QFile::copy(fn, user_icon_path); } else if (c == 1) { QFile::remove(user_icon_path); } else { diff --git a/ui/dialog_manage_routes.cpp b/ui/dialog_manage_routes.cpp index 6646e85..5657f80 100644 --- a/ui/dialog_manage_routes.cpp +++ b/ui/dialog_manage_routes.cpp @@ -101,7 +101,7 @@ void DialogManageRoutes::accept() { if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true; SAVE_TO_ROUTING(NekoRay::dataStore->routing) NekoRay::dataStore->active_routing = active_routing; - NekoRay::dataStore->routing->fn = "routes/" + NekoRay::dataStore->active_routing; + NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing; if (NekoRay::dataStore->routing->Save()) routeChanged = true; // QString info = "UpdateDataStore"; @@ -170,7 +170,7 @@ void DialogManageRoutes::on_load_save_clicked() { if (!fn.isEmpty()) { auto r = std::make_unique(); r->load_control_force = true; - r->fn = "routes/" + fn; + r->fn = ROUTES_PREFIX + fn; if (r->Load()) { auto btn = QMessageBox::question(nullptr, software_name, tr("Load routing: %1").arg(fn) + "\n" + r->toString()); @@ -186,7 +186,7 @@ void DialogManageRoutes::on_load_save_clicked() { if (!fn.isEmpty()) { auto r = std::make_unique(); SAVE_TO_ROUTING(r) - r->fn = "routes/" + fn; + r->fn = ROUTES_PREFIX + fn; auto btn = QMessageBox::question(nullptr, software_name, tr("Save routing: %1").arg(fn) + "\n" + r->toString()); if (btn == QMessageBox::Yes) { @@ -201,7 +201,7 @@ void DialogManageRoutes::on_load_save_clicked() { if (!fn.isEmpty() && NekoRay::Routing::List().length() > 1) { auto btn = QMessageBox::question(nullptr, software_name, tr("Remove routing: %1").arg(fn)); if (btn == QMessageBox::Yes) { - QFile f("routes/" + fn); + QFile f(ROUTES_PREFIX + fn); f.remove(); if (NekoRay::dataStore->active_routing == fn) { NekoRay::Routing::SetToActive(NekoRay::Routing::List().first()); diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 9f9d36a..bff00ec 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -299,7 +299,7 @@ MainWindow::MainWindow(QWidget *parent) if (!fn.isEmpty()) { NekoRay::Routing r; r.load_control_force = true; - r.fn = "routes/" + fn; + r.fn = ROUTES_PREFIX + fn; if (r.Load()) { auto btn = QMessageBox::question(GetMessageBoxParent(), software_name, tr("Load routing and apply: %1").arg(fn) + "\n" + r.toString());