add package compatible

This commit is contained in:
arm64v8a
2022-09-27 15:02:31 +08:00
parent e44279742c
commit 0b783d9130
9 changed files with 49 additions and 27 deletions

View File

@@ -47,6 +47,10 @@ include("cmake/nkr.cmake")
find_package(Threads)
if (NKR_PACKAGE)
add_compile_definitions(NKR_PACKAGE)
endif()
if (NKR_NO_EXTERNAL)
add_compile_definitions(NKR_NO_EXTERNAL)
else ()

View File

@@ -696,12 +696,10 @@ namespace NekoRay {
{"outbound", "dns-out"}};
// geopath
auto geopath = dataStore->v2ray_asset_dir;
if (geopath.isEmpty()) geopath = QApplication::applicationDirPath();
auto geoip = geopath + "/geoip.db";
auto geosite = geopath + "/geosite.db";
if (!QFile::exists(geoip)) result->error = geoip + " not found";
if (!QFile::exists(geosite)) result->error = geosite + " not found";
auto geoip = FindCoreAsset("geoip.db");
auto geosite = FindCoreAsset("geosite.db");
if (geoip.isEmpty()) result->error = geoip + " not found";
if (geosite.isEmpty()) result->error = geosite + " not found";
// final add routing rule
QJSONARRAY_ADD(routingRules, QString2QJsonObject(dataStore->custom_route_global)["rules"].toArray())

View File

@@ -30,12 +30,13 @@ ninja
#### CMake 参数
| CMake 参数 | 默认值 | 含义 |
|-------------------------|-----|-------------------------|
| QT_VERSION_MAJOR | 5 | QT版本 |
| NKR_NO_EXTERNAL | | 不包含外部C++依赖(如ZXing/gRPC) |
| NKR_NO_GRPC | | 不包含gRPC |
| NKR_CROSS | | |
| CMake 参数 | 默认值 | 含义 |
|------------------|-----|-------------------------|
| QT_VERSION_MAJOR | 5 | QT版本 |
| NKR_NO_EXTERNAL | | 不包含外部C++依赖(如ZXing/gRPC) |
| NKR_NO_GRPC | | 不包含gRPC |
| NKR_CROSS | | |
| NKR_PACKAGE | | 打包 |
#### C++ 部分

View File

@@ -122,7 +122,7 @@ func (s *server) Test(ctx context.Context, in *gen.TestReq) (out *gen.TestResp,
// Latency
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 是错误
} else if in.Mode == gen.TestMode_TcpPing {
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
var latency string
if in.FullLatency {
t, _ := speedtest.UrlTest(getProxyHttpClient(i), in.Address, in.Timeout)
t, _ := speedtest.UrlTest(getProxyHttpClient(i), in.Url, in.Timeout)
out.Ms = t
if t > 0 {
latency = fmt.Sprint(t, "ms")

View File

@@ -2,6 +2,8 @@
#include <QFile>
#include <QDir>
#include <QApplication>
#include <QFileInfo>
namespace NekoRay {
@@ -324,4 +326,22 @@ namespace NekoRay {
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 {};
}
}

View File

@@ -2,6 +2,8 @@
namespace NekoRay {
QString FindCoreAsset(const QString& name);
class Routing : public JsonStore {
public:
QString direct_ip;
@@ -14,7 +16,7 @@ namespace NekoRay {
explicit Routing(int preset = 0);
QString toString() const;
[[nodiscard]] QString toString() const;
static QStringList List();

View File

@@ -50,6 +50,9 @@ int main(int argc, char *argv[]) {
auto args = QApplication::arguments();
if (args.contains("-many")) NekoRay::dataStore->flag_many = true;
if (args.contains("-appdata")) NekoRay::dataStore->flag_use_appdata = true;
#ifdef NKR_PACKAGE
NekoRay::dataStore->flag_use_appdata = true;
#endif
// dirs & clean
auto wd = QDir(QApplication::applicationDirPath());

View File

@@ -109,13 +109,11 @@ namespace NekoRay::sys {
void CoreProcess::Start() {
show_stderr = false;
auto v2ray_asset_dir = dataStore->v2ray_asset_dir;
if (v2ray_asset_dir.isEmpty() || QDir(v2ray_asset_dir).exists()) {
v2ray_asset_dir = QApplication::applicationDirPath();
auto v2ray_asset_dir = FindCoreAsset("geoip.dat");
if (!v2ray_asset_dir.isEmpty()) {
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();
write((dataStore->core_token + "\n").toUtf8());
}

View File

@@ -58,12 +58,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) :
builtInSchemesMenu->addActions(this->getBuiltInSchemes());
ui->preset->setMenu(builtInSchemesMenu);
QString geoipFn = QApplication::applicationDirPath() + "/geoip.dat";
QString geositeFn = QApplication::applicationDirPath() + +"/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";
}
QString geoipFn = NekoRay::FindCoreAsset("geoip.dat");
QString geositeFn = NekoRay::FindCoreAsset("geosite.dat");
//
const auto sourceStringsDomain = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geoipFn);
directDomainTxt = new AutoCompleteTextEdit("geosite", sourceStringsDomain, this);