mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:50:12 +08:00
fix: check the existence of geo-assets in specific paths (#320)
This commit is contained in:
parent
3ef8b64988
commit
d73beb799b
@ -8,14 +8,14 @@
|
|||||||
// Switch core support
|
// Switch core support
|
||||||
|
|
||||||
namespace NekoGui {
|
namespace NekoGui {
|
||||||
QString FindCoreAsset(const QString &name);
|
|
||||||
|
|
||||||
QString FindNekoBoxCoreRealPath();
|
QString FindNekoBoxCoreRealPath();
|
||||||
|
|
||||||
bool IsAdmin(bool forceRenew=false);
|
bool IsAdmin(bool forceRenew=false);
|
||||||
|
|
||||||
QString GetBasePath();
|
QString GetBasePath();
|
||||||
|
|
||||||
|
QString GetCoreAssetDir(const QString &name);
|
||||||
|
|
||||||
bool NeedGeoAssets();
|
bool NeedGeoAssets();
|
||||||
} // namespace NekoGui
|
} // namespace NekoGui
|
||||||
|
|
||||||
|
|||||||
@ -355,24 +355,6 @@ namespace NekoGui {
|
|||||||
|
|
||||||
// System Utils
|
// System Utils
|
||||||
|
|
||||||
QString FindCoreAsset(const QString &name) {
|
|
||||||
QStringList search{QApplication::applicationDirPath()};
|
|
||||||
search << "/usr/share/sing-geoip";
|
|
||||||
search << "/usr/share/sing-geosite";
|
|
||||||
search << "/usr/share/v2ray";
|
|
||||||
search << "/usr/share/sing-box";
|
|
||||||
search << "/usr/local/share/v2ray";
|
|
||||||
search << "/opt/v2ray";
|
|
||||||
for (const auto &dir: search) {
|
|
||||||
if (dir.isEmpty()) continue;
|
|
||||||
QFileInfo asset(dir + "/" + name);
|
|
||||||
if (asset.exists()) {
|
|
||||||
return asset.absoluteFilePath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QString FindNekoBoxCoreRealPath() {
|
QString FindNekoBoxCoreRealPath() {
|
||||||
auto fn = QApplication::applicationDirPath() + "/nekobox_core";
|
auto fn = QApplication::applicationDirPath() + "/nekobox_core";
|
||||||
auto fi = QFileInfo(fn);
|
auto fi = QFileInfo(fn);
|
||||||
@ -405,10 +387,26 @@ namespace NekoGui {
|
|||||||
return qApp->applicationDirPath();
|
return qApp->applicationDirPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GetCoreAssetDir(const QString &name) {
|
||||||
|
QStringList search = {
|
||||||
|
GetBasePath(),
|
||||||
|
QString("/usr/share/sing-geoip"),
|
||||||
|
QString("/usr/share/sing-geosite"),
|
||||||
|
QString("/usr/share/sing-box"),
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto &dir: search) {
|
||||||
|
if (dir.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (QFile(QString("%1/%2").arg(dir, name)).exists())
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
bool NeedGeoAssets(){
|
bool NeedGeoAssets(){
|
||||||
auto path = GetBasePath();
|
return GetCoreAssetDir("geoip.db").isEmpty() || GetCoreAssetDir("geosite.db").isEmpty();
|
||||||
auto geoIP = QFile(path + "/geoip.db");
|
|
||||||
auto geoSite = QFile(path + "/geosite.db");
|
|
||||||
return !geoIP.exists() || !geoSite.exists();
|
|
||||||
}
|
}
|
||||||
} // namespace NekoGui
|
} // namespace NekoGui
|
||||||
|
|||||||
@ -65,8 +65,8 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptr<NekoGui::RoutingChai
|
|||||||
|
|
||||||
// setup rule set helper
|
// setup rule set helper
|
||||||
bool ok; // for now we discard this
|
bool ok; // for now we discard this
|
||||||
auto geoIpList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip, NekoGui::GetBasePath());
|
auto geoIpList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip, NekoGui::GetCoreAssetDir("geoip.db"));
|
||||||
auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site, NekoGui::GetBasePath());
|
auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site, NekoGui::GetCoreAssetDir("geosite.db"));
|
||||||
geo_items << geoIpList << geoSiteList;
|
geo_items << geoIpList << geoSiteList;
|
||||||
rule_set_editor = new AutoCompleteTextEdit("", geo_items, this);
|
rule_set_editor = new AutoCompleteTextEdit("", geo_items, this);
|
||||||
ui->rule_attr_data->layout()->addWidget(rule_set_editor);
|
ui->rule_attr_data->layout()->addWidget(rule_set_editor);
|
||||||
@ -472,4 +472,4 @@ void RouteItem::on_delete_route_item_clicked() {
|
|||||||
}
|
}
|
||||||
updateRouteItemsView();
|
updateRouteItemsView();
|
||||||
updateRuleSection();
|
updateRuleSection();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,8 +141,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
|
|||||||
});
|
});
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
auto geoIpList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip, NekoGui::GetBasePath());
|
auto geoIpList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip, NekoGui::GetCoreAssetDir("geoip.db"));
|
||||||
auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site, NekoGui::GetBasePath());
|
auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site, NekoGui::GetCoreAssetDir("geosite.db"));
|
||||||
QStringList ruleItems = {"domain:", "suffix:", "regex:"};
|
QStringList ruleItems = {"domain:", "suffix:", "regex:"};
|
||||||
for (const auto& geoIP : geoIpList) {
|
for (const auto& geoIP : geoIpList) {
|
||||||
ruleItems.append("ruleset:"+geoIP);
|
ruleItems.append("ruleset:"+geoIP);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user