Skip to content

Commit

Permalink
add package compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Sep 27, 2022
1 parent e442797 commit 0b783d9
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
10 changes: 4 additions & 6 deletions db/ConfigBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
13 changes: 7 additions & 6 deletions examples/docs/Build_Linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -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++ 部分

Expand Down
4 changes: 2 additions & 2 deletions go/cmd/nekoray_core/grpc_ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
20 changes: 20 additions & 0 deletions main/NekoRay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <QFile>
#include <QDir>
#include <QApplication>
#include <QFileInfo>

namespace NekoRay {

Expand Down Expand Up @@ -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 {};
}

}
4 changes: 3 additions & 1 deletion main/NekoRay_DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace NekoRay {

QString FindCoreAsset(const QString& name);

class Routing : public JsonStore {
public:
QString direct_ip;
Expand All @@ -14,7 +16,7 @@ namespace NekoRay {

explicit Routing(int preset = 0);

QString toString() const;
[[nodiscard]] QString toString() const;

static QStringList List();

Expand Down
3 changes: 3 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
10 changes: 4 additions & 6 deletions sys/ExternalProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
8 changes: 2 additions & 6 deletions ui/dialog_manage_routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0b783d9

Please sign in to comment.