Skip to content

Commit

Permalink
Merge tag '4.0.1'
Browse files Browse the repository at this point in the history
* tag '4.0.1':
  4.0.1
  misc change
  fix: dns outbound
  change: domain rule use domain_suffix
  refactor: replace non-empty QString constructors with QStringLiteral()
  • Loading branch information
bygreencn committed Dec 13, 2024
2 parents ed061e8 + adef6cd commit 132d138
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 64 deletions.
4 changes: 2 additions & 2 deletions 3rdparty/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ namespace Qv2ray::components::proxy {
// execute and get the code
const auto returnCode = QProcess::execute(action.first, action.second);
// print out the commands and result codes
DEBUG(QString("[%1] Program: %2, Args: %3").arg(returnCode).arg(action.first).arg(action.second.join(";")));
DEBUG(QStringLiteral("[%1] Program: %2, Args: %3").arg(returnCode).arg(action.first).arg(action.second.join(";")));
// give the code back
results << (returnCode == QProcess::NormalExit);
}
Expand Down Expand Up @@ -423,7 +423,7 @@ namespace Qv2ray::components::proxy {
// execute and get the code
const auto returnCode = QProcess::execute(action.first, action.second);
// print out the commands and result codes
DEBUG(QString("[%1] Program: %2, Args: %3").arg(returnCode).arg(action.first).arg(action.second.join(";")));
DEBUG(QStringLiteral("[%1] Program: %2, Args: %3").arg(returnCode).arg(action.first).arg(action.second.join(";")));
}

#else
Expand Down
6 changes: 3 additions & 3 deletions 3rdparty/qv2ray/v2/ui/widgets/common/QJsonModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ QVariant QJsonModel::data(const QModelIndex &index, int role) const {

if (role == Qt::DisplayRole) {
if (index.column() == 0)
return QString("%1").arg(item->key());
return QStringLiteral("%1").arg(item->key());

if (index.column() == 1)
return QString("%1").arg(item->value());
return QStringLiteral("%1").arg(item->value());
} else if (Qt::EditRole == role) {
if (index.column() == 1) {
return QString("%1").arg(item->value());
return QStringLiteral("%1").arg(item->value());
}
}

Expand Down
62 changes: 40 additions & 22 deletions db/ConfigBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,41 @@ namespace NekoGui {
return tun_name;
}

void MergeJson(const QJsonObject &custom, QJsonObject &outbound) {
void MergeJson(QJsonObject &dst, const QJsonObject &src) {
// 合并
if (custom.isEmpty()) return;
for (const auto &key: custom.keys()) {
if (outbound.contains(key)) {
auto v = custom[key];
auto v_orig = outbound[key];
if (v.isObject() && v_orig.isObject()) { // isObject 则合并?
auto vo = v.toObject();
QJsonObject vo_orig = v_orig.toObject();
MergeJson(vo, vo_orig);
outbound[key] = vo_orig;
if (src.isEmpty()) return;
for (const auto &key: src.keys()) {
auto v_src = src[key];
if (dst.contains(key)) {
auto v_dst = dst[key];
if (v_src.isObject() && v_dst.isObject()) { // isObject 则合并?
auto v_src_obj = v_src.toObject();
auto v_dst_obj = v_dst.toObject();
MergeJson(v_dst_obj, v_src_obj);
dst[key] = v_dst_obj;
} else {
outbound[key] = v;
dst[key] = v_src;
}
} else if (v_src.isArray()) {
if (key.startsWith("+")) {
auto key2 = SubStrAfter(key, "+");
auto v_dst = dst[key2];
auto v_src_arr = v_src.toArray();
auto v_dst_arr = v_dst.toArray();
QJSONARRAY_ADD(v_src_arr, v_dst_arr)
dst[key2] = v_src_arr;
} else if (key.endsWith("+")) {
auto key2 = SubStrBefore(key, "+");
auto v_dst = dst[key2];
auto v_src_arr = v_src.toArray();
auto v_dst_arr = v_dst.toArray();
QJSONARRAY_ADD(v_dst_arr, v_src_arr)
dst[key2] = v_dst_arr;
} else {
dst[key] = v_src;
}
} else {
outbound[key] = custom[key];
dst[key] = v_src;
}
}
}
Expand All @@ -68,15 +86,15 @@ namespace NekoGui {
}

// apply custom config
MergeJson(QString2QJsonObject(ent->bean->custom_config), result->coreConfig);
MergeJson(result->coreConfig, QString2QJsonObject(ent->bean->custom_config));

return result;
}

QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status) {
auto group = profileManager->GetGroup(status->ent->gid);
if (group == nullptr) {
status->result->error = QString("This profile is not in any group, your data may be corrupted.");
status->result->error = QStringLiteral("This profile is not in any group, your data may be corrupted.");
return {};
}

Expand All @@ -88,11 +106,11 @@ namespace NekoGui {
for (auto id: list) {
resolved += profileManager->GetProfile(id);
if (resolved.last() == nullptr) {
status->result->error = QString("chain missing ent: %1").arg(id);
status->result->error = QStringLiteral("chain missing ent: %1").arg(id);
break;
}
if (resolved.last()->type == "chain") {
status->result->error = QString("chain in chain is not allowed: %1").arg(id);
status->result->error = QStringLiteral("chain in chain is not allowed: %1").arg(id);
break;
}
}
Expand All @@ -109,7 +127,7 @@ namespace NekoGui {
if (group->front_proxy_id >= 0) {
auto fEnt = profileManager->GetProfile(group->front_proxy_id);
if (fEnt == nullptr) {
status->result->error = QString("front proxy ent not found.");
status->result->error = QStringLiteral("front proxy ent not found.");
return {};
}
ents += resolveChain(fEnt);
Expand Down Expand Up @@ -342,7 +360,7 @@ namespace NekoGui {
}

// apply custom outbound settings
MergeJson(QString2QJsonObject(ent->bean->custom_outbound), outbound);
MergeJson(outbound, QString2QJsonObject(ent->bean->custom_outbound));

// Bypass Lookup for the first profile
auto serverAddress = ent->bean->serverAddress;
Expand Down Expand Up @@ -486,7 +504,7 @@ namespace NekoGui {
} else if (item.startsWith("keyword:")) {
domain_keyword += item.replace("keyword:", "").toLower();
} else {
domain_full += item.toLower();
domain_subdomain += item.toLower();
}
}
}
Expand Down Expand Up @@ -537,7 +555,7 @@ namespace NekoGui {
}
dnsRules.append(QJsonObject{
{"outbound", "any"},
{"server", "direct"},
{"server", "dns-direct"},
});

// block
Expand Down Expand Up @@ -797,4 +815,4 @@ namespace NekoGui {
return QFileInfo(file2).absoluteFilePath();
}

} // namespace NekoGui
} // namespace NekoGui
20 changes: 10 additions & 10 deletions db/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace NekoGui {
// Load Proxys
QList<int> delProfile;
for (auto id: profilesIdOrder) {
auto ent = LoadProxyEntity(QString("profiles/%1.json").arg(id));
auto ent = LoadProxyEntity(QStringLiteral("profiles/%1.json").arg(id));
// Corrupted profile?
if (ent == nullptr || ent->bean == nullptr || ent->bean->version == -114514) {
delProfile << id;
Expand All @@ -58,7 +58,7 @@ namespace NekoGui {
auto loadedOrder = groupsTabOrder;
groupsTabOrder = {};
for (auto id: groupsIdOrder) {
auto ent = LoadGroup(QString("groups/%1.json").arg(id));
auto ent = LoadGroup(QStringLiteral("groups/%1.json").arg(id));
// Corrupted group?
if (ent->id != id) {
continue;
Expand Down Expand Up @@ -103,7 +103,7 @@ namespace NekoGui {
auto newId = i++;
profile->id = newId;
profile->gid = gidOld2New[gid];
profile->fn = QString("profiles/%1.json").arg(newId);
profile->fn = QStringLiteral("profiles/%1.json").arg(newId);
profile->Save();
newProfiles[newId] = profile;
newProfilesIdOrder << newId;
Expand All @@ -122,7 +122,7 @@ namespace NekoGui {
auto group = groups[oldGid];
QFile::remove(group->fn);
group->id = newId;
group->fn = QString("groups/%1.json").arg(newId);
group->fn = QStringLiteral("groups/%1.json").arg(newId);
group->Save();
newGroups[newId] = group;
newGroupsIdOrder << newId;
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace NekoGui {
if (latency < 0) {
return QObject::tr("Unavailable");
} else if (latency > 0) {
return UNICODE_LRO + QString("%1 ms").arg(latency);
return UNICODE_LRO + QStringLiteral("%1 ms").arg(latency);
} else {
return "";
}
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace NekoGui {
profiles[ent->id] = ent;
profilesIdOrder.push_back(ent->id);

ent->fn = QString("profiles/%1.json").arg(ent->id);
ent->fn = QStringLiteral("profiles/%1.json").arg(ent->id);
ent->Save();
return true;
}
Expand All @@ -278,7 +278,7 @@ namespace NekoGui {
if (dataStore->started_id == id) return;
profiles.erase(id);
profilesIdOrder.removeAll(id);
QFile(QString("profiles/%1.json").arg(id)).remove();
QFile(QStringLiteral("profiles/%1.json").arg(id)).remove();
}

void ProfileManager::MoveProfile(const std::shared_ptr<ProxyEntity> &ent, int gid) {
Expand Down Expand Up @@ -342,7 +342,7 @@ namespace NekoGui {
groupsIdOrder.push_back(ent->id);
groupsTabOrder.push_back(ent->id);

ent->fn = QString("groups/%1.json").arg(ent->id);
ent->fn = QStringLiteral("groups/%1.json").arg(ent->id);
ent->Save();
return true;
}
Expand All @@ -359,7 +359,7 @@ namespace NekoGui {
groups.erase(gid);
groupsIdOrder.removeAll(gid);
groupsTabOrder.removeAll(gid);
QFile(QString("groups/%1.json").arg(gid)).remove();
QFile(QStringLiteral("groups/%1.json").arg(gid)).remove();
}

std::shared_ptr<Group> ProfileManager::GetGroup(int id) {
Expand Down Expand Up @@ -391,4 +391,4 @@ namespace NekoGui {
}
}

} // namespace NekoGui
} // namespace NekoGui
4 changes: 2 additions & 2 deletions db/traffic/TrafficData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ namespace NekoGui_traffic {
}

[[nodiscard]] QString DisplaySpeed() const {
return UNICODE_LRO + QString("%1↑ %2↓").arg(ReadableSize(uplink_rate), ReadableSize(downlink_rate));
return UNICODE_LRO + QStringLiteral("%1↑ %2↓").arg(ReadableSize(uplink_rate), ReadableSize(downlink_rate));
}

[[nodiscard]] QString DisplayTraffic() const {
if (downlink + uplink == 0) return "";
return UNICODE_LRO + QString("%1↑ %2↓").arg(ReadableSize(uplink), ReadableSize(downlink));
return UNICODE_LRO + QStringLiteral("%1↑ %2↓").arg(ReadableSize(uplink), ReadableSize(downlink));
}
};
} // namespace NekoGui_traffic
2 changes: 1 addition & 1 deletion fmt/AbstractBean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace NekoGui_fmt {
}

QString AbstractBean::DisplayTypeAndName() {
return QString("[%1] %2").arg(DisplayType(), DisplayName());
return QStringLiteral("[%1] %2").arg(DisplayType(), DisplayName());
}

void AbstractBean::ResolveDomainToIP(const std::function<void()> &onFinished) {
Expand Down
2 changes: 1 addition & 1 deletion fmt/Bean2External.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define WriteTempFile(fn, data) \
QDir dir; \
if (!dir.exists("temp")) dir.mkdir("temp"); \
QFile f(QString("temp/") + fn); \
QFile f(QStringLiteral("temp/") + fn); \
bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate); \
if (ok) { \
f.write(data); \
Expand Down
4 changes: 2 additions & 2 deletions fmt/Bean2Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NekoGui_fmt {
url.setScheme("http");
}
} else {
url.setScheme(QString("socks%1").arg(socks_http_type));
url.setScheme(QStringLiteral("socks%1").arg(socks_http_type));
}
if (!name.isEmpty()) url.setFragment(name);
if (!username.isEmpty()) url.setUserName(username);
Expand Down Expand Up @@ -222,4 +222,4 @@ namespace NekoGui_fmt {
return url.toString(QUrl::FullyEncoded);
}

} // namespace NekoGui_fmt
} // namespace NekoGui_fmt
2 changes: 1 addition & 1 deletion main/HTTPRequestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace NekoGui_network {
for (const auto &err: errors) {
error_str << err.errorString();
}
MW_show_log(QString("SSL Errors: %1 %2").arg(error_str.join(","), NekoGui::dataStore->sub_insecure ? "(Ignored)" : ""));
MW_show_log(QStringLiteral("SSL Errors: %1 %2").arg(error_str.join(","), NekoGui::dataStore->sub_insecure ? "(Ignored)" : ""));
});
// Wait for response
auto abortTimer = new QTimer;
Expand Down
2 changes: 1 addition & 1 deletion main/NekoGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ namespace NekoGui {
}

QString Routing::DisplayRouting() const {
return QString("[Proxy] %1\n[Proxy] %2\n[Direct] %3\n[Direct] %4\n[Block] %5\n[Block] %6\n[Default Outbound] %7\n[DNS] %8")
return QStringLiteral("[Proxy] %1\n[Proxy] %2\n[Direct] %3\n[Direct] %4\n[Block] %5\n[Block] %6\n[Default Outbound] %7\n[DNS] %8")
.arg(SplitLinesSkipSharp(proxy_domain).join(","), 10)
.arg(SplitLinesSkipSharp(proxy_ip).join(","), 10)
.arg(SplitLinesSkipSharp(direct_domain).join(","), 10)
Expand Down
2 changes: 1 addition & 1 deletion main/NekoGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ namespace NekoGui {
bool IsAdmin();
} // namespace NekoGui

#define ROUTES_PREFIX_NAME QString("routes_box")
#define ROUTES_PREFIX_NAME QStringLiteral("routes_box")
#define ROUTES_PREFIX QString(ROUTES_PREFIX_NAME + "/")
2 changes: 1 addition & 1 deletion nekoray_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0-beta4-2024-10-09
4.0.1-2024-12-12
2 changes: 1 addition & 1 deletion rpc/gRPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ namespace NekoGui_rpc {

#define NOT_OK \
*rpcOK = false; \
onError(QString("QNetworkReply::NetworkError code: %1\n").arg(status));
onError(QStringLiteral("QNetworkReply::NetworkError code: %1\n").arg(status));

void Client::Exit() {
libcore::EmptyReq request;
Expand Down
2 changes: 1 addition & 1 deletion sys/windows/MiniDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ LONG __stdcall CreateCrashHandler(EXCEPTION_POINTERS *pException) {
}
// 创建消息提示
QMessageBox::warning(NULL, "Application crashed",
QString("ErrorCode: %1 ErrorAddr:%2 ErrorFlag: %3 ErrorPara: %4\nVersion: %5\nDump file at %6")
QStringLiteral("ErrorCode: %1 ErrorAddr:%2 ErrorFlag: %3 ErrorPara: %4\nVersion: %5\nDump file at %6")
.arg(errCode)
.arg(errAddr)
.arg(errFlag)
Expand Down
2 changes: 1 addition & 1 deletion ui/dialog_basic_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)

// Common

ui->log_level->addItems(QString("trace debug info warn error fatal panic").split(" "));
ui->log_level->addItems(QStringLiteral("trace debug info warn error fatal panic").split(" "));
ui->mux_protocol->addItems({"h2mux", "smux", "yamux"});

refresh_auth();
Expand Down
2 changes: 1 addition & 1 deletion ui/dialog_manage_routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
//
ui->outbound_domain_strategy->addItems(Preset::SingBox::DomainStrategy);
ui->domainStrategyCombo->addItems(Preset::SingBox::DomainStrategy);
qsValue += QString("prefer_ipv4 prefer_ipv6 ipv4_only ipv6_only").split(" ");
qsValue += QStringLiteral("prefer_ipv4 prefer_ipv6 ipv4_only ipv6_only").split(" ");
ui->dns_object->setPlaceholderText(DecodeB64IfValid("ewogICJzZXJ2ZXJzIjogW10sCiAgInJ1bGVzIjogW10sCiAgImZpbmFsIjogIiIsCiAgInN0cmF0ZWd5IjogIiIsCiAgImRpc2FibGVfY2FjaGUiOiBmYWxzZSwKICAiZGlzYWJsZV9leHBpcmUiOiBmYWxzZSwKICAiaW5kZXBlbmRlbnRfY2FjaGUiOiBmYWxzZSwKICAicmV2ZXJzZV9tYXBwaW5nIjogZmFsc2UsCiAgImZha2VpcCI6IHt9Cn0="));
dnsHelpDocumentUrl = "https://sing-box.sagernet.org/configuration/dns/";
//
Expand Down
2 changes: 1 addition & 1 deletion ui/edit/edit_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void EditCustom::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
auto command = QStringList{extR->program};
command += extR->arguments;
auto btn = QMessageBox::information(this, tr("Preview config"),
QString("Command: %1\n\n%2").arg(QStringList2Command(command), extR->config_export),
QStringLiteral("Command: %1\n\n%2").arg(QStringList2Command(command), extR->config_export),
"OK", "Copy", "", 0, 0);
if (btn == 1) {
QApplication::clipboard()->setText(extR->config_export);
Expand Down
Loading

0 comments on commit 132d138

Please sign in to comment.