mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
add package compatible
This commit is contained in:
@@ -47,6 +47,10 @@ include("cmake/nkr.cmake")
|
|||||||
|
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
|
|
||||||
|
if (NKR_PACKAGE)
|
||||||
|
add_compile_definitions(NKR_PACKAGE)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (NKR_NO_EXTERNAL)
|
if (NKR_NO_EXTERNAL)
|
||||||
add_compile_definitions(NKR_NO_EXTERNAL)
|
add_compile_definitions(NKR_NO_EXTERNAL)
|
||||||
else ()
|
else ()
|
||||||
|
|||||||
@@ -696,12 +696,10 @@ namespace NekoRay {
|
|||||||
{"outbound", "dns-out"}};
|
{"outbound", "dns-out"}};
|
||||||
|
|
||||||
// geopath
|
// geopath
|
||||||
auto geopath = dataStore->v2ray_asset_dir;
|
auto geoip = FindCoreAsset("geoip.db");
|
||||||
if (geopath.isEmpty()) geopath = QApplication::applicationDirPath();
|
auto geosite = FindCoreAsset("geosite.db");
|
||||||
auto geoip = geopath + "/geoip.db";
|
if (geoip.isEmpty()) result->error = geoip + " not found";
|
||||||
auto geosite = geopath + "/geosite.db";
|
if (geosite.isEmpty()) result->error = geosite + " not found";
|
||||||
if (!QFile::exists(geoip)) result->error = geoip + " not found";
|
|
||||||
if (!QFile::exists(geosite)) result->error = geosite + " not found";
|
|
||||||
|
|
||||||
// final add routing rule
|
// final add routing rule
|
||||||
QJSONARRAY_ADD(routingRules, QString2QJsonObject(dataStore->custom_route_global)["rules"].toArray())
|
QJSONARRAY_ADD(routingRules, QString2QJsonObject(dataStore->custom_route_global)["rules"].toArray())
|
||||||
|
|||||||
@@ -30,12 +30,13 @@ ninja
|
|||||||
|
|
||||||
#### CMake 参数
|
#### CMake 参数
|
||||||
|
|
||||||
| CMake 参数 | 默认值 | 含义 |
|
| CMake 参数 | 默认值 | 含义 |
|
||||||
|-------------------------|-----|-------------------------|
|
|------------------|-----|-------------------------|
|
||||||
| QT_VERSION_MAJOR | 5 | QT版本 |
|
| QT_VERSION_MAJOR | 5 | QT版本 |
|
||||||
| NKR_NO_EXTERNAL | | 不包含外部C++依赖(如ZXing/gRPC) |
|
| NKR_NO_EXTERNAL | | 不包含外部C++依赖(如ZXing/gRPC) |
|
||||||
| NKR_NO_GRPC | | 不包含gRPC |
|
| NKR_NO_GRPC | | 不包含gRPC |
|
||||||
| NKR_CROSS | | |
|
| NKR_CROSS | | |
|
||||||
|
| NKR_PACKAGE | | 打包 |
|
||||||
|
|
||||||
#### C++ 部分
|
#### C++ 部分
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ func (s *server) Test(ctx context.Context, in *gen.TestReq) (out *gen.TestResp,
|
|||||||
|
|
||||||
// Latency
|
// Latency
|
||||||
var t int32
|
var t int32
|
||||||
t, err = speedtest.UrlTest(getProxyHttpClient(i), in.Address, in.Timeout)
|
t, err = speedtest.UrlTest(getProxyHttpClient(i), in.Url, in.Timeout)
|
||||||
out.Ms = t // sn: ms==0 是错误
|
out.Ms = t // sn: ms==0 是错误
|
||||||
} else if in.Mode == gen.TestMode_TcpPing {
|
} else if in.Mode == gen.TestMode_TcpPing {
|
||||||
out.Ms, err = speedtest.TcpPing(in.Address, in.Timeout)
|
out.Ms, err = speedtest.TcpPing(in.Address, in.Timeout)
|
||||||
@@ -149,7 +149,7 @@ func (s *server) Test(ctx context.Context, in *gen.TestReq) (out *gen.TestResp,
|
|||||||
// Latency
|
// Latency
|
||||||
var latency string
|
var latency string
|
||||||
if in.FullLatency {
|
if in.FullLatency {
|
||||||
t, _ := speedtest.UrlTest(getProxyHttpClient(i), in.Address, in.Timeout)
|
t, _ := speedtest.UrlTest(getProxyHttpClient(i), in.Url, in.Timeout)
|
||||||
out.Ms = t
|
out.Ms = t
|
||||||
if t > 0 {
|
if t > 0 {
|
||||||
latency = fmt.Sprint(t, "ms")
|
latency = fmt.Sprint(t, "ms")
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
namespace NekoRay {
|
namespace NekoRay {
|
||||||
|
|
||||||
@@ -324,4 +326,22 @@ namespace NekoRay {
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
QString FindCoreAsset(const QString &name) {
|
||||||
|
QStringList search{dataStore->v2ray_asset_dir};
|
||||||
|
search << QApplication::applicationDirPath();
|
||||||
|
search << "/usr/share/v2ray";
|
||||||
|
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 {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace NekoRay {
|
namespace NekoRay {
|
||||||
|
|
||||||
|
QString FindCoreAsset(const QString& name);
|
||||||
|
|
||||||
class Routing : public JsonStore {
|
class Routing : public JsonStore {
|
||||||
public:
|
public:
|
||||||
QString direct_ip;
|
QString direct_ip;
|
||||||
@@ -14,7 +16,7 @@ namespace NekoRay {
|
|||||||
|
|
||||||
explicit Routing(int preset = 0);
|
explicit Routing(int preset = 0);
|
||||||
|
|
||||||
QString toString() const;
|
[[nodiscard]] QString toString() const;
|
||||||
|
|
||||||
static QStringList List();
|
static QStringList List();
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ int main(int argc, char *argv[]) {
|
|||||||
auto args = QApplication::arguments();
|
auto args = QApplication::arguments();
|
||||||
if (args.contains("-many")) NekoRay::dataStore->flag_many = true;
|
if (args.contains("-many")) NekoRay::dataStore->flag_many = true;
|
||||||
if (args.contains("-appdata")) NekoRay::dataStore->flag_use_appdata = true;
|
if (args.contains("-appdata")) NekoRay::dataStore->flag_use_appdata = true;
|
||||||
|
#ifdef NKR_PACKAGE
|
||||||
|
NekoRay::dataStore->flag_use_appdata = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
// dirs & clean
|
// dirs & clean
|
||||||
auto wd = QDir(QApplication::applicationDirPath());
|
auto wd = QDir(QApplication::applicationDirPath());
|
||||||
|
|||||||
@@ -109,13 +109,11 @@ namespace NekoRay::sys {
|
|||||||
|
|
||||||
void CoreProcess::Start() {
|
void CoreProcess::Start() {
|
||||||
show_stderr = false;
|
show_stderr = false;
|
||||||
auto v2ray_asset_dir = dataStore->v2ray_asset_dir;
|
auto v2ray_asset_dir = FindCoreAsset("geoip.dat");
|
||||||
if (v2ray_asset_dir.isEmpty() || QDir(v2ray_asset_dir).exists()) {
|
if (!v2ray_asset_dir.isEmpty()) {
|
||||||
v2ray_asset_dir = QApplication::applicationDirPath();
|
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
|
||||||
|
env = QStringList{"V2RAY_LOCATION_ASSET=" + v2ray_asset_dir};
|
||||||
}
|
}
|
||||||
env = QStringList{
|
|
||||||
"V2RAY_LOCATION_ASSET=" + v2ray_asset_dir
|
|
||||||
};
|
|
||||||
ExternalProcess::Start();
|
ExternalProcess::Start();
|
||||||
write((dataStore->core_token + "\n").toUtf8());
|
write((dataStore->core_token + "\n").toUtf8());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,12 +58,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) :
|
|||||||
builtInSchemesMenu->addActions(this->getBuiltInSchemes());
|
builtInSchemesMenu->addActions(this->getBuiltInSchemes());
|
||||||
ui->preset->setMenu(builtInSchemesMenu);
|
ui->preset->setMenu(builtInSchemesMenu);
|
||||||
|
|
||||||
QString geoipFn = QApplication::applicationDirPath() + "/geoip.dat";
|
QString geoipFn = NekoRay::FindCoreAsset("geoip.dat");
|
||||||
QString geositeFn = QApplication::applicationDirPath() + +"/geosite.dat";
|
QString geositeFn = NekoRay::FindCoreAsset("geosite.dat");
|
||||||
if (!NekoRay::dataStore->v2ray_asset_dir.isEmpty()) {
|
|
||||||
geoipFn = NekoRay::dataStore->v2ray_asset_dir + "/geoip.dat";
|
|
||||||
geositeFn = NekoRay::dataStore->v2ray_asset_dir + "/geosite.dat";
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
const auto sourceStringsDomain = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geoipFn);
|
const auto sourceStringsDomain = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geoipFn);
|
||||||
directDomainTxt = new AutoCompleteTextEdit("geosite", sourceStringsDomain, this);
|
directDomainTxt = new AutoCompleteTextEdit("geosite", sourceStringsDomain, this);
|
||||||
|
|||||||
Reference in New Issue
Block a user