diff --git a/include/global/NekoGui.hpp b/include/global/NekoGui.hpp index 3697148..ac9d810 100644 --- a/include/global/NekoGui.hpp +++ b/include/global/NekoGui.hpp @@ -8,14 +8,14 @@ // Switch core support namespace NekoGui { - QString FindCoreAsset(const QString &name); - QString FindNekoBoxCoreRealPath(); bool IsAdmin(bool forceRenew=false); QString GetBasePath(); + QString GetCoreAssetDir(const QString &name); + bool NeedGeoAssets(); } // namespace NekoGui diff --git a/src/global/NekoGui.cpp b/src/global/NekoGui.cpp index 42822e8..6990552 100644 --- a/src/global/NekoGui.cpp +++ b/src/global/NekoGui.cpp @@ -355,24 +355,6 @@ namespace NekoGui { // 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() { auto fn = QApplication::applicationDirPath() + "/nekobox_core"; auto fi = QFileInfo(fn); @@ -405,10 +387,26 @@ namespace NekoGui { 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(){ - auto path = GetBasePath(); - auto geoIP = QFile(path + "/geoip.db"); - auto geoSite = QFile(path + "/geosite.db"); - return !geoIP.exists() || !geoSite.exists(); + return GetCoreAssetDir("geoip.db").isEmpty() || GetCoreAssetDir("geosite.db").isEmpty(); } } // namespace NekoGui diff --git a/src/ui/setting/RouteItem.cpp b/src/ui/setting/RouteItem.cpp index 0045bd1..f27e309 100644 --- a/src/ui/setting/RouteItem.cpp +++ b/src/ui/setting/RouteItem.cpp @@ -65,8 +65,8 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptrGetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip, NekoGui::GetBasePath()); - auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site, 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::GetCoreAssetDir("geosite.db")); geo_items << geoIpList << geoSiteList; rule_set_editor = new AutoCompleteTextEdit("", geo_items, this); ui->rule_attr_data->layout()->addWidget(rule_set_editor); @@ -472,4 +472,4 @@ void RouteItem::on_delete_route_item_clicked() { } updateRouteItemsView(); updateRuleSection(); -} \ No newline at end of file +} diff --git a/src/ui/setting/dialog_manage_routes.cpp b/src/ui/setting/dialog_manage_routes.cpp index ec0dbb8..d343aac 100644 --- a/src/ui/setting/dialog_manage_routes.cpp +++ b/src/ui/setting/dialog_manage_routes.cpp @@ -141,8 +141,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne }); bool ok; - auto geoIpList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::ip, NekoGui::GetBasePath()); - auto geoSiteList = NekoGui_rpc::defaultClient->GetGeoList(&ok, NekoGui_rpc::GeoRuleSetType::site, 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::GetCoreAssetDir("geosite.db")); QStringList ruleItems = {"domain:", "suffix:", "regex:"}; for (const auto& geoIP : geoIpList) { ruleItems.append("ruleset:"+geoIP);