This commit is contained in:
arm64v8a
2022-12-02 15:23:11 +09:00
parent 6e75117bae
commit 9c0816c71a
10 changed files with 102 additions and 37 deletions

View File

@@ -16,7 +16,6 @@ if (WIN32)
endif () endif ()
# Find Qt # Find Qt
if (NOT QT_VERSION_MAJOR) if (NOT QT_VERSION_MAJOR)
set(QT_VERSION_MAJOR 5) set(QT_VERSION_MAJOR 5)
endif () endif ()
@@ -30,15 +29,11 @@ if (NKR_CROSS)
set_property(TARGET Qt5::lupdate PROPERTY IMPORTED_LOCATION /usr/bin/lupdate) set_property(TARGET Qt5::lupdate PROPERTY IMPORTED_LOCATION /usr/bin/lupdate)
endif () endif ()
if (NKR_PACKAGE OR NKR_PACKAGE_MACOS)
message("[add_compile_definitions] NKR_CPP_USE_APPDATA")
add_compile_definitions(NKR_CPP_USE_APPDATA)
endif ()
# Windows # Windows
include("cmake/fuck_windows/fuck.cmake") include("cmake/fuck_windows/fuck.cmake")
# default prefix path #### default prefix path ####
if (NKR_PACKAGE) if (NKR_PACKAGE)
list(APPEND NKR_LIBS ${CMAKE_SOURCE_DIR}/libs/deps/package) list(APPEND NKR_LIBS ${CMAKE_SOURCE_DIR}/libs/deps/package)
else () else ()
@@ -56,39 +51,63 @@ message("[CMAKE_PREFIX_PATH] ${CMAKE_PREFIX_PATH}")
list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH}) list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH})
message("[CMAKE_FIND_ROOT_PATH] ${CMAKE_FIND_ROOT_PATH}") message("[CMAKE_FIND_ROOT_PATH] ${CMAKE_FIND_ROOT_PATH}")
# NKR #### NKR ####
include("cmake/print.cmake") include("cmake/print.cmake")
include("cmake/nkr.cmake") include("cmake/nkr.cmake")
find_package(Threads) find_package(Threads)
if (NKR_NO_EXTERNAL) if (NKR_PACKAGE OR NKR_PACKAGE_MACOS)
add_compile_definitions(NKR_NO_EXTERNAL) nkr_add_compile_definitions(NKR_CPP_USE_APPDATA)
else () endif ()
if (NKR_NO_GRPC)
add_compile_definitions(NKR_NO_GRPC)
else ()
# My proto
include("cmake/myproto.cmake")
list(APPEND NKR_EXTERNAL_TARGETS myproto)
endif ()
# yaml-cpp (static) #### NKR EXTERNAL ####
if (NKR_NO_EXTERNAL)
set(NKR_NO_GRPC 1)
set(NKR_NO_YAML 1)
set(NKR_NO_ZXING 1)
set(NKR_NO_QHOTKEY 1)
endif ()
# grpc
if (NKR_NO_GRPC)
nkr_add_compile_definitions(NKR_NO_GRPC)
else ()
# My proto
include("cmake/myproto.cmake")
list(APPEND NKR_EXTERNAL_TARGETS myproto)
endif ()
# yaml-cpp
if (NKR_NO_YAML)
nkr_add_compile_definitions(NKR_NO_YAML)
else ()
find_package(yaml-cpp CONFIG REQUIRED) # only Release is built find_package(yaml-cpp CONFIG REQUIRED) # only Release is built
list(APPEND NKR_EXTERNAL_TARGETS yaml-cpp) list(APPEND NKR_EXTERNAL_TARGETS yaml-cpp)
endif ()
# zxing-cpp # zxing-cpp
if (NKR_NO_ZXING)
nkr_add_compile_definitions(NKR_NO_ZXING)
else ()
find_package(ZXing CONFIG REQUIRED) find_package(ZXing CONFIG REQUIRED)
list(APPEND NKR_EXTERNAL_TARGETS ZXing::ZXing) list(APPEND NKR_EXTERNAL_TARGETS ZXing::ZXing)
endif ()
# QHotkey (static submodule) # QHotkey (static submodule)
if (NKR_NO_QHOTKEY)
nkr_add_compile_definitions(NKR_NO_QHOTKEY)
else ()
set(QHOTKEY_INSTALL OFF) set(QHOTKEY_INSTALL OFF)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
add_subdirectory(3rdparty/QHotkey) add_subdirectory(3rdparty/QHotkey)
list(APPEND NKR_EXTERNAL_TARGETS qhotkey) list(APPEND NKR_EXTERNAL_TARGETS qhotkey)
endif () endif ()
# debug print #### debug print ####
if (DBG_CMAKE) if (DBG_CMAKE)
print_all_variables() print_all_variables()
print_target_properties(myproto) print_target_properties(myproto)

View File

@@ -4,3 +4,9 @@ add_compile_definitions(NKR_VERSION=\"${NKR_VERSION}\")
# Debug # Debug
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DNKR_CPP_DEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DNKR_CPP_DEBUG")
# Func
function(nkr_add_compile_definitions arg)
message("[add_compile_definitions] ${ARGV}")
add_compile_definitions(${ARGV})
endfunction()

View File

@@ -33,10 +33,11 @@ ninja
| CMake 参数 | 默认值 | 含义 | | CMake 参数 | 默认值 | 含义 |
|------------------|-----|-------------------------| |------------------|-----|-------------------------|
| QT_VERSION_MAJOR | 5 | QT版本 | | QT_VERSION_MAJOR | 5 | QT版本 |
| NKR_NO_EXTERNAL | | 不包含外部C++依赖(如ZXing/gRPC) | | NKR_NO_EXTERNAL | | 不包含外部C++依赖(以下所有) |
| NKR_NO_YAML | | 不包含yaml-cpp |
| NKR_NO_QHOTKEY | | 不包含qhotkey |
| NKR_NO_ZXING | | 不包含zxing |
| NKR_NO_GRPC | | 不包含gRPC | | NKR_NO_GRPC | | 不包含gRPC |
| NKR_CROSS | | |
| NKR_PACKAGE | | 打包 |
#### C++ 部分 #### C++ 部分

View File

@@ -16,7 +16,7 @@ git clone https://github.com/MatsuriDayo/nekoray.git --recursive
### 下载 Qt SDK ### 下载 Qt SDK
目前使用的版本是 Qt 5.15.2 其他版本未测试 目前使用的版本是 Qt 5.15.7 其他版本未测试
在此下载 `qtbase` `qtsvg` `qttools` 的包并解压到同一个目录。 在此下载 `qtbase` `qtsvg` `qttools` 的包并解压到同一个目录。

View File

@@ -12,6 +12,7 @@ import (
"neko/pkg/speedtest" "neko/pkg/speedtest"
"nekobox_core/box_main" "nekobox_core/box_main"
"reflect" "reflect"
"time"
"unsafe" "unsafe"
box "github.com/sagernet/sing-box" box "github.com/sagernet/sing-box"
@@ -38,6 +39,16 @@ func (s *server) Start(ctx context.Context, in *gen.LoadConfigReq) (out *gen.Err
log.Println("Start:", in.CoreConfig) log.Println("Start:", in.CoreConfig)
} }
if neko_common.GetBuildTime() > 0 {
if time.Now().Unix() >= neko_common.GetExpireTime() {
err = errors.New("Your version is too old! Please update!! 版本太旧,请升级!")
return
} else if time.Now().Unix() >= (neko_common.GetExpireTime() - 30*24*60*60) {
log.Println("Your version is too old! Please update!! 版本太旧,请升级!")
log.Println("This version expires on " + time.Unix(neko_common.GetExpireTime(), 0).Format("2006-01-02"))
}
}
if instance != nil { if instance != nil {
err = errors.New("instance already started") err = errors.New("instance already started")
return return

View File

@@ -8,6 +8,7 @@ import (
"io" "io"
"libcore" "libcore"
"libcore/stun" "libcore/stun"
"log"
"neko/gen" "neko/gen"
"neko/pkg/grpc_server" "neko/pkg/grpc_server"
"neko/pkg/neko_common" "neko/pkg/neko_common"
@@ -38,6 +39,16 @@ func (s *server) Start(ctx context.Context, in *gen.LoadConfigReq) (out *gen.Err
logrus.Println("Start:", in.CoreConfig, in.TryDomains) logrus.Println("Start:", in.CoreConfig, in.TryDomains)
} }
if neko_common.GetBuildTime() > 0 {
if time.Now().Unix() >= neko_common.GetExpireTime() {
err = errors.New("Your version is too old! Please update!! 版本太旧,请升级!")
return
} else if time.Now().Unix() >= (neko_common.GetExpireTime() - 30*24*60*60) {
log.Println("Your version is too old! Please update!! 版本太旧,请升级!")
log.Println("This version expires on " + time.Unix(neko_common.GetExpireTime(), 0).Format("2006-01-02"))
}
}
if instance != nil { if instance != nil {
err = errors.New("instance already started") err = errors.New("instance already started")
return return

View File

@@ -1,6 +1,10 @@
package neko_common package neko_common
import "net/http" import (
"net/http"
"strings"
"time"
)
var Version_v2ray string = "N/A" var Version_v2ray string = "N/A"
var Version_neko string = "N/A" var Version_neko string = "N/A"
@@ -16,3 +20,19 @@ const (
) )
var GetProxyHttpClient func() *http.Client var GetProxyHttpClient func() *http.Client
func GetBuildTime() int64 {
if !strings.HasPrefix(Version_neko, "nekoray-") {
return 0
}
ver := strings.TrimLeft(Version_neko, "nekoray-")
buildDate := ver[strings.Index(ver, "-")+1:]
buildTime, _ := time.Parse("2006-01-02", buildDate)
return buildTime.Unix()
}
func GetExpireTime() int64 {
buildTime := time.Unix(GetBuildTime(), 0)
expireTime := buildTime.AddDate(0, 6, 0) // current force update: 6 months
return expireTime.Unix()
}

View File

@@ -1,9 +1,5 @@
#pragma once #pragma once
#ifdef NKR_NO_EXTERNAL
#define NKR_NO_GRPC
#endif
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
#include "go/gen/libcore.pb.h" #include "go/gen/libcore.pb.h"

View File

@@ -10,7 +10,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QUrlQuery> #include <QUrlQuery>
#ifndef NKR_NO_EXTERNAL #ifndef NKR_NO_YAML
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
@@ -164,7 +164,7 @@ namespace NekoRay::sub {
update_counter++; update_counter++;
} }
#ifndef NKR_NO_EXTERNAL #ifndef NKR_NO_YAML
QString Node2QString(const YAML::Node &n, const QString &def = "") { QString Node2QString(const YAML::Node &n, const QString &def = "") {
try { try {
@@ -203,7 +203,7 @@ namespace NekoRay::sub {
// https://github.com/Dreamacro/clash/wiki/configuration // https://github.com/Dreamacro/clash/wiki/configuration
void RawUpdater::updateClash(const QString &str) { void RawUpdater::updateClash(const QString &str) {
#ifndef NKR_NO_EXTERNAL #ifndef NKR_NO_YAML
try { try {
auto proxies = YAML::Load(str.toStdString())["proxies"]; auto proxies = YAML::Load(str.toStdString())["proxies"];
for (auto proxy: proxies) { for (auto proxy: proxies) {

View File

@@ -21,7 +21,7 @@
#include "qv2ray/v2/components/proxy/QvProxyConfigurator.hpp" #include "qv2ray/v2/components/proxy/QvProxyConfigurator.hpp"
#include "qv2ray/v2/ui/LogHighlighter.hpp" #include "qv2ray/v2/ui/LogHighlighter.hpp"
#ifndef NKR_NO_EXTERNAL #ifndef NKR_NO_ZXING
#include "3rdparty/ZxingQtReader.hpp" #include "3rdparty/ZxingQtReader.hpp"
#endif #endif
@@ -766,6 +766,7 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
case NekoRay::GroupSortMethod::ById: { case NekoRay::GroupSortMethod::ById: {
// Clear Order // Clear Order
ui->proxyListTable->order.clear(); ui->proxyListTable->order.clear();
ui->proxyListTable->callback_save_order();
break; break;
} }
case NekoRay::GroupSortMethod::ByAddress: case NekoRay::GroupSortMethod::ByAddress:
@@ -1101,7 +1102,7 @@ void MainWindow::display_qr_link(bool nkrFormat) {
} }
void MainWindow::on_menu_scan_qr_triggered() { void MainWindow::on_menu_scan_qr_triggered() {
#ifndef NKR_NO_EXTERNAL #ifndef NKR_NO_ZXING
using namespace ZXingQt; using namespace ZXingQt;
hide(); hide();
@@ -1387,7 +1388,7 @@ void MainWindow::refresh_connection_list(const QJsonArray &arr) {
// Hotkey // Hotkey
#ifndef NKR_NO_EXTERNAL #ifndef NKR_NO_QHOTKEY
#include <QHotkey> #include <QHotkey>