mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
improve switch core
use different datastore for each core
This commit is contained in:
@@ -66,6 +66,7 @@ launcher 参数
|
|||||||
- [MatsuriDayo/Matsuri](https://github.com/MatsuriDayo/Matsuri)
|
- [MatsuriDayo/Matsuri](https://github.com/MatsuriDayo/Matsuri)
|
||||||
- [MatsuriDayo/v2ray-core](https://github.com/MatsuriDayo/v2ray-core)
|
- [MatsuriDayo/v2ray-core](https://github.com/MatsuriDayo/v2ray-core)
|
||||||
- [SagerNet/sing-box](https://github.com/SagerNet/sing-box)
|
- [SagerNet/sing-box](https://github.com/SagerNet/sing-box)
|
||||||
|
- [Qv2ray](https://github.com/Qv2ray/Qv2ray)
|
||||||
- [Qt](https://www.qt.io/)
|
- [Qt](https://www.qt.io/)
|
||||||
- [protobuf](https://github.com/protocolbuffers/protobuf)
|
- [protobuf](https://github.com/protocolbuffers/protobuf)
|
||||||
- [yaml-cpp](https://github.com/jbeder/yaml-cpp)
|
- [yaml-cpp](https://github.com/jbeder/yaml-cpp)
|
||||||
|
|||||||
@@ -724,17 +724,17 @@ namespace NekoRay {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// api
|
// api
|
||||||
|
if (dataStore->traffic_loop_interval > 0) {
|
||||||
result->coreConfig.insert("experimental", QJsonObject{
|
result->coreConfig.insert("experimental", QJsonObject{
|
||||||
{"v2ray_api", QJsonObject{
|
{"v2ray_api", QJsonObject{
|
||||||
{"listen", "127.0.0.1:" + Int2String(dataStore->inbound_socks_port + 10)},
|
{"listen", "127.0.0.1:" + Int2String(dataStore->inbound_socks_port + 10)},
|
||||||
{"stats", QJsonObject{
|
{"stats", QJsonObject{
|
||||||
{"enabled", true},
|
{"enabled", true},
|
||||||
{"outbounds", QJsonArray{
|
{"outbounds", QJsonArray{tagProxy, "bypass"}},
|
||||||
tagProxy, "bypass", "block"
|
|
||||||
}},
|
|
||||||
}}
|
}}
|
||||||
}},
|
}},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace NekoRay {
|
|||||||
|
|
||||||
// datastore
|
// datastore
|
||||||
|
|
||||||
DataStore::DataStore() : JsonStore("groups/nekoray.json") {
|
DataStore::DataStore() : JsonStore() {
|
||||||
_add(new configItem("extraCore", dynamic_cast<JsonStore *>(extraCore), itemType::jsonStore));
|
_add(new configItem("extraCore", dynamic_cast<JsonStore *>(extraCore), itemType::jsonStore));
|
||||||
|
|
||||||
_add(new configItem("user_agent", &user_agent, itemType::string));
|
_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_process", &vpn_bypass_process, itemType::string));
|
||||||
_add(new configItem("vpn_bypass_cidr", &vpn_bypass_cidr, 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("check_include_pre", &check_include_pre, itemType::boolean));
|
||||||
_add(new configItem("neko_core", &neko_core, itemType::integer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::UpdateStartedId(int id) {
|
void DataStore::UpdateStartedId(int id) {
|
||||||
@@ -110,15 +109,15 @@ namespace NekoRay {
|
|||||||
QStringList Routing::List() {
|
QStringList Routing::List() {
|
||||||
QStringList l;
|
QStringList l;
|
||||||
QDir d;
|
QDir d;
|
||||||
if (d.exists("routes")) {
|
if (d.exists(ROUTES_PREFIX)) {
|
||||||
QDir dr("routes");
|
QDir dr(ROUTES_PREFIX);
|
||||||
return dr.entryList(QDir::Files);
|
return dr.entryList(QDir::Files);
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Routing::SetToActive(const QString &name) {
|
void Routing::SetToActive(const QString &name) {
|
||||||
dataStore->routing->fn = "routes/" + name;
|
dataStore->routing->fn = ROUTES_PREFIX + name;
|
||||||
dataStore->routing->Load();
|
dataStore->routing->Load();
|
||||||
dataStore->active_routing = name;
|
dataStore->active_routing = name;
|
||||||
dataStore->Save();
|
dataStore->Save();
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ namespace NekoRay {
|
|||||||
// Saved
|
// Saved
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
int neko_core = CoreType::V2RAY;
|
|
||||||
|
|
||||||
QString log_level = "warning";
|
QString log_level = "warning";
|
||||||
QString user_agent = "Nekoray/1.0 (Prefer Clash Format)";
|
QString user_agent = "Nekoray/1.0 (Prefer Clash Format)";
|
||||||
bool sub_use_proxy = false;
|
bool sub_use_proxy = false;
|
||||||
@@ -129,6 +127,10 @@ namespace NekoRay {
|
|||||||
|
|
||||||
extern DataStore *dataStore;
|
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 + "/" )
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ int main(int argc, char *argv[]) {
|
|||||||
QIcon::setThemeName("breeze");
|
QIcon::setThemeName("breeze");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load coreType
|
||||||
|
NekoRay::coreType = ReadFileText("groups/coreType").toInt(); // default to 0
|
||||||
|
|
||||||
// Dir
|
// Dir
|
||||||
QDir dir;
|
QDir dir;
|
||||||
bool dir_success = true;
|
bool dir_success = true;
|
||||||
@@ -95,8 +98,8 @@ int main(int argc, char *argv[]) {
|
|||||||
if (!dir.exists("groups")) {
|
if (!dir.exists("groups")) {
|
||||||
dir_success = dir_success && dir.mkdir("groups");
|
dir_success = dir_success && dir.mkdir("groups");
|
||||||
}
|
}
|
||||||
if (!dir.exists("routes")) {
|
if (!dir.exists(ROUTES_PREFIX_NAME)) {
|
||||||
dir_success = dir_success && dir.mkdir("routes");
|
dir_success = dir_success && dir.mkdir(ROUTES_PREFIX_NAME);
|
||||||
}
|
}
|
||||||
if (!dir_success) {
|
if (!dir_success) {
|
||||||
QMessageBox::warning(nullptr, "Error", "No permission to write " + dir.absolutePath());
|
QMessageBox::warning(nullptr, "Error", "No permission to write " + dir.absolutePath());
|
||||||
@@ -104,13 +107,24 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load dataStore
|
// 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();
|
auto isLoaded = NekoRay::dataStore->Load();
|
||||||
if (!isLoaded) {
|
if (!isLoaded) {
|
||||||
NekoRay::dataStore->Save();
|
NekoRay::dataStore->Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// load routing
|
// 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();
|
isLoaded = NekoRay::dataStore->routing->Load();
|
||||||
if (!isLoaded) {
|
if (!isLoaded) {
|
||||||
NekoRay::dataStore->routing->Save();
|
NekoRay::dataStore->routing->Save();
|
||||||
|
|||||||
@@ -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.")
|
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)
|
.arg(core_name_new)
|
||||||
) == QMessageBox::StandardButton::Yes) {
|
) == QMessageBox::StandardButton::Yes) {
|
||||||
NekoRay::dataStore->neko_core = neko_core_new;
|
QFile file;
|
||||||
NekoRay::dataStore->Save();
|
file.setFileName("groups/coreType");
|
||||||
|
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
|
||||||
|
file.write(Int2String(neko_core_new).toUtf8());
|
||||||
|
file.close();
|
||||||
dialog_message("", "SwitchCore");
|
dialog_message("", "SwitchCore");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -268,14 +271,12 @@ void DialogBasicSettings::on_set_custom_icon_clicked() {
|
|||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
auto fn = QFileDialog::getOpenFileName(this, QObject::tr("Select"), QDir::currentPath(),
|
auto fn = QFileDialog::getOpenFileName(this, QObject::tr("Select"), QDir::currentPath(),
|
||||||
"*.png", nullptr, QFileDialog::Option::ReadOnly);
|
"*.png", nullptr, QFileDialog::Option::ReadOnly);
|
||||||
if (!fn.isEmpty()) {
|
|
||||||
QImage img(fn);
|
QImage img(fn);
|
||||||
if (img.isNull() || img.height() != img.width()) {
|
if (img.isNull() || img.height() != img.width()) {
|
||||||
MessageBoxWarning(title, tr("Please select a valid square image."));
|
MessageBoxWarning(title, tr("Please select a valid square image."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QFile::copy(fn, user_icon_path);
|
QFile::copy(fn, user_icon_path);
|
||||||
}
|
|
||||||
} else if (c == 1) {
|
} else if (c == 1) {
|
||||||
QFile::remove(user_icon_path);
|
QFile::remove(user_icon_path);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void DialogManageRoutes::accept() {
|
|||||||
if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true;
|
if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true;
|
||||||
SAVE_TO_ROUTING(NekoRay::dataStore->routing)
|
SAVE_TO_ROUTING(NekoRay::dataStore->routing)
|
||||||
NekoRay::dataStore->active_routing = active_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;
|
if (NekoRay::dataStore->routing->Save()) routeChanged = true;
|
||||||
//
|
//
|
||||||
QString info = "UpdateDataStore";
|
QString info = "UpdateDataStore";
|
||||||
@@ -170,7 +170,7 @@ void DialogManageRoutes::on_load_save_clicked() {
|
|||||||
if (!fn.isEmpty()) {
|
if (!fn.isEmpty()) {
|
||||||
auto r = std::make_unique<NekoRay::Routing>();
|
auto r = std::make_unique<NekoRay::Routing>();
|
||||||
r->load_control_force = true;
|
r->load_control_force = true;
|
||||||
r->fn = "routes/" + fn;
|
r->fn = ROUTES_PREFIX + fn;
|
||||||
if (r->Load()) {
|
if (r->Load()) {
|
||||||
auto btn = QMessageBox::question(nullptr,
|
auto btn = QMessageBox::question(nullptr,
|
||||||
software_name, tr("Load routing: %1").arg(fn) + "\n" + r->toString());
|
software_name, tr("Load routing: %1").arg(fn) + "\n" + r->toString());
|
||||||
@@ -186,7 +186,7 @@ void DialogManageRoutes::on_load_save_clicked() {
|
|||||||
if (!fn.isEmpty()) {
|
if (!fn.isEmpty()) {
|
||||||
auto r = std::make_unique<NekoRay::Routing>();
|
auto r = std::make_unique<NekoRay::Routing>();
|
||||||
SAVE_TO_ROUTING(r)
|
SAVE_TO_ROUTING(r)
|
||||||
r->fn = "routes/" + fn;
|
r->fn = ROUTES_PREFIX + fn;
|
||||||
auto btn = QMessageBox::question(nullptr, software_name,
|
auto btn = QMessageBox::question(nullptr, software_name,
|
||||||
tr("Save routing: %1").arg(fn) + "\n" + r->toString());
|
tr("Save routing: %1").arg(fn) + "\n" + r->toString());
|
||||||
if (btn == QMessageBox::Yes) {
|
if (btn == QMessageBox::Yes) {
|
||||||
@@ -201,7 +201,7 @@ void DialogManageRoutes::on_load_save_clicked() {
|
|||||||
if (!fn.isEmpty() && NekoRay::Routing::List().length() > 1) {
|
if (!fn.isEmpty() && NekoRay::Routing::List().length() > 1) {
|
||||||
auto btn = QMessageBox::question(nullptr, software_name, tr("Remove routing: %1").arg(fn));
|
auto btn = QMessageBox::question(nullptr, software_name, tr("Remove routing: %1").arg(fn));
|
||||||
if (btn == QMessageBox::Yes) {
|
if (btn == QMessageBox::Yes) {
|
||||||
QFile f("routes/" + fn);
|
QFile f(ROUTES_PREFIX + fn);
|
||||||
f.remove();
|
f.remove();
|
||||||
if (NekoRay::dataStore->active_routing == fn) {
|
if (NekoRay::dataStore->active_routing == fn) {
|
||||||
NekoRay::Routing::SetToActive(NekoRay::Routing::List().first());
|
NekoRay::Routing::SetToActive(NekoRay::Routing::List().first());
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
if (!fn.isEmpty()) {
|
if (!fn.isEmpty()) {
|
||||||
NekoRay::Routing r;
|
NekoRay::Routing r;
|
||||||
r.load_control_force = true;
|
r.load_control_force = true;
|
||||||
r.fn = "routes/" + fn;
|
r.fn = ROUTES_PREFIX + fn;
|
||||||
if (r.Load()) {
|
if (r.Load()) {
|
||||||
auto btn = QMessageBox::question(GetMessageBoxParent(), software_name,
|
auto btn = QMessageBox::question(GetMessageBoxParent(), software_name,
|
||||||
tr("Load routing and apply: %1").arg(fn) + "\n" + r.toString());
|
tr("Load routing and apply: %1").arg(fn) + "\n" + r.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user