Skip to content

Commit

Permalink
chore: change qt version
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Nov 26, 2022
1 parent 09d37fa commit b2ebd0e
Show file tree
Hide file tree
Showing 20 changed files with 405 additions and 174 deletions.
25 changes: 21 additions & 4 deletions .github/workflows/build-qv2ray-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ jobs:
# 14.1 is for vs2017, 14.2 is vs2019, following the upstream vcpkg build from Qv2ray-deps repo
toolset: 14.2
arch: ${{ matrix.arch }}
- name: Download Artifacts
- name: Download Artifacts for macOS
if: matrix.platform == 'macos-10.15'
uses: actions/download-artifact@v3
with:
path: download-artifact
- name: Install Qt
# ========================================================================================================= Qt Install
- name: macOS - Install Qt 5.15
if: matrix.platform == 'macos-10.15'
uses: jurplel/install-qt-action@v3
with:
version: ${{ matrix.qt_version }}
Expand All @@ -91,10 +93,24 @@ jobs:
setup-python: false
cache: true
cache-key-prefix: QtCache-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.qt_version }}
# ========================================================================================================= Other install
- name: Windows - Download Custom Qt 5.15 SDK
shell: bash
if: matrix.platform == 'windows-2022'
run: |
mkdir qtsdk ; cd qtsdk
curl -LSO https://github.com/MatsuriDayo/nekoray_qt_runtime/releases/download/20220503/Qt5.15.7-Windows-x86_64-VS2019-16.11.20-20221103.7z
7z x *.7z
rm *.7z
mv Qt* Qt
- name: Linux - Install Qt 5.12 via apt
shell: bash
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y zlib1g-dev fcitx-frontend-qt5 qtbase5-dev qttools5-dev libqt5svg5-dev libqt5x11extras5-dev
# ========================================================================================================= 编译与 Qt 无关的依赖
- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v3
# ========================================================================================================= 编译与 Qt 无关的依赖
- name: Cache Download
id: cache-deps
uses: actions/cache@v3
Expand All @@ -114,6 +130,7 @@ jobs:
CC: cl.exe
CXX: cl.exe
run: |
source libs/env_qtsdk.sh $PWD/qtsdk/Qt
mkdir build
cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ CMakeLists.txt.user*
# Deploy
/deployment
/neko*.sh
/qtsdk/
88 changes: 88 additions & 0 deletions 3rdparty/base64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "base64.h"

namespace Qt515Base64 {
namespace {
struct fromBase64_helper_result {
qsizetype decodedLength;
Base64DecodingStatus status;
};

fromBase64_helper_result fromBase64_helper(const char *input, qsizetype inputSize,
char *output /* may alias input */,
Base64Options options) {
fromBase64_helper_result result{0, Base64DecodingStatus::Ok};

unsigned int buf = 0;
int nbits = 0;

qsizetype offset = 0;
for (qsizetype i = 0; i < inputSize; ++i) {
int ch = input[i];
int d;

if (ch >= 'A' && ch <= 'Z') {
d = ch - 'A';
} else if (ch >= 'a' && ch <= 'z') {
d = ch - 'a' + 26;
} else if (ch >= '0' && ch <= '9') {
d = ch - '0' + 52;
} else if (ch == '+' && (options & Base64UrlEncoding) == 0) {
d = 62;
} else if (ch == '-' && (options & Base64UrlEncoding) != 0) {
d = 62;
} else if (ch == '/' && (options & Base64UrlEncoding) == 0) {
d = 63;
} else if (ch == '_' && (options & Base64UrlEncoding) != 0) {
d = 63;
} else {
if (options & AbortOnBase64DecodingErrors) {
if (ch == '=') {
// can have 1 or 2 '=' signs, in both cases padding base64Size to
// a multiple of 4. Any other case is illegal.
if ((inputSize % 4) != 0) {
result.status = Base64DecodingStatus::IllegalInputLength;
return result;
} else if ((i == inputSize - 1) ||
(i == inputSize - 2 && input[++i] == '=')) {
d = -1; // ... and exit the loop, normally
} else {
result.status = Base64DecodingStatus::IllegalPadding;
return result;
}
} else {
result.status = Base64DecodingStatus::IllegalCharacter;
return result;
}
} else {
d = -1;
}
}

if (d != -1) {
buf = (buf << 6) | d;
nbits += 6;
if (nbits >= 8) {
nbits -= 8;
Q_ASSERT(offset < i);
output[offset++] = buf >> nbits;
buf &= (1 << nbits) - 1;
}
}
}

result.decodedLength = offset;
return result;
}
} // namespace

FromBase64Result QByteArray_fromBase64Encoding(const QByteArray &base64, Base64Options options) {
const auto base64Size = base64.size();
QByteArray result((base64Size * 3) / 4, Qt::Uninitialized);
const auto base64result = fromBase64_helper(base64.data(),
base64Size,
const_cast<char *>(result.constData()),
options);
result.truncate(int(base64result.decodedLength));
return {std::move(result), base64result.status};
}
} // namespace Qt515Base64
47 changes: 47 additions & 0 deletions 3rdparty/base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <QByteArray>

namespace Qt515Base64 {
enum Base64Option {
Base64Encoding = 0,
Base64UrlEncoding = 1,

KeepTrailingEquals = 0,
OmitTrailingEquals = 2,

IgnoreBase64DecodingErrors = 0,
AbortOnBase64DecodingErrors = 4,
};
Q_DECLARE_FLAGS(Base64Options, Base64Option)
Q_DECLARE_OPERATORS_FOR_FLAGS(Base64Options)

enum class Base64DecodingStatus {
Ok,
IllegalInputLength,
IllegalCharacter,
IllegalPadding,
};

class FromBase64Result {
public:
QByteArray decoded;
Base64DecodingStatus decodingStatus;

void swap(FromBase64Result &other) noexcept {
qSwap(decoded, other.decoded);
qSwap(decodingStatus, other.decodingStatus);
}

explicit operator bool() const noexcept { return decodingStatus == Base64DecodingStatus::Ok; }

#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(Q_QDOC)
QByteArray &operator*() &noexcept { return decoded; }
const QByteArray &operator*() const &noexcept { return decoded; }
QByteArray &&operator*() &&noexcept { return std::move(decoded); }
#else
QByteArray &operator*() noexcept { return decoded; }
const QByteArray &operator*() const noexcept { return decoded; }
#endif
};

FromBase64Result QByteArray_fromBase64Encoding(const QByteArray &base64, Base64Options options);
} // namespace Qt515Base64
53 changes: 33 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ include("cmake/fuck_windows/fuck.cmake")

# default prefix path
if (NKR_PACKAGE)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/libs/deps/package)
list(APPEND NKR_LIBS ${CMAKE_SOURCE_DIR}/libs/deps/package)
else ()
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/libs/deps/built)
list(APPEND NKR_LIBS ${CMAKE_SOURCE_DIR}/libs/deps/built)
endif ()

if (NKR_DISABLE_LIBS)
else ()
list(APPEND CMAKE_PREFIX_PATH ${NKR_LIBS})
endif ()

message("[CMAKE_PREFIX_PATH] ${CMAKE_PREFIX_PATH}")

# for some cross toolchain
Expand Down Expand Up @@ -100,6 +106,7 @@ set(PROJECT_SOURCES
main/NekoRay.cpp
main/NekoRay_Utils.cpp

3rdparty/base64.cpp
3rdparty/qrcodegen.cpp
3rdparty/QtExtKeySequenceEdit.cpp

Expand Down Expand Up @@ -207,14 +214,6 @@ set(PROJECT_SOURCES
${QV2RAY_RC}
)

# Translations
set(TS_FILES
translations/zh_CN.ts
)
qt_create_translation(QM_FILES ${PROJECT_SOURCES} ${TS_FILES} OPTIONS -locations none)
configure_file(translations/translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)
set(PROJECT_SOURCES ${PROJECT_SOURCES} ${TS_FILES} ${QM_FILES} ${CMAKE_BINARY_DIR}/translations.qrc)

# Qt exe
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(nekoray
Expand Down Expand Up @@ -245,21 +244,12 @@ set_property(TARGET nekoray PROPERTY AUTOUIC ON)
set_property(TARGET nekoray PROPERTY AUTOMOC ON)
set_property(TARGET nekoray PROPERTY AUTORCC ON)

# Target Link

target_link_libraries(nekoray PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Svg
Threads::Threads
${NKR_EXTERNAL_TARGETS}
${PLATFORM_FUCKING_LIBRARIES}
)
# Target Source macOS

set(MACOSX_ICON ${CMAKE_SOURCE_DIR}/res/nekoray.icns)

if (APPLE)
target_sources(nekoray PRIVATE ${MACOSX_ICON})
endif ()

set_target_properties(nekoray PROPERTIES
MACOSX_BUNDLE_ICON_FILE "nekoray.icns"
RESOURCE ${MACOSX_ICON}
Expand All @@ -269,6 +259,29 @@ set_target_properties(nekoray PROPERTIES
WIN32_EXECUTABLE TRUE
)

# Target Source Translations

set(TS_FILES
translations/zh_CN.ts
)
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_lupdate(nekoray TS_FILES ${TS_FILES})
qt_add_lrelease(nekoray TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES)
else ()
qt5_create_translation(QM_FILES ${PROJECT_SOURCES} ${TS_FILES} OPTIONS -locations none)
endif ()
configure_file(translations/translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)
target_sources(nekoray PRIVATE ${CMAKE_BINARY_DIR}/translations.qrc)

# Target Link

target_link_libraries(nekoray PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Svg
Threads::Threads
${NKR_EXTERNAL_TARGETS}
${PLATFORM_FUCKING_LIBRARIES}
)

if (QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(nekoray)
endif ()
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,7 @@ https://matsuridayo.github.io

## Linux 运行

**使用 Linux 系统相信您已具备基本的排错能力,
本项目不提供特定发行版/架构的支持,预编译文件不能满足您的需求时,请自行编译/适配。**

要求:已安装主流的发行版和 xcb 桌面环境。

运行: `./launcher` 或 部分系统可双击打开

launcher 参数

* `./launcher -- -appdata` ( `--` 后的参数传递给主程序 )
* `-debug` Debug mode
* `-theme` Use local QT theme (unstable) (1.0+)

已知部分 Linux 发行版无法使用预编译版、非 x86_64 暂无适配,可以尝试自行编译。

Ubuntu 22.04: `sudo apt install libxcb-xinerama0`
[Linux 运行教程](examples/docs/Run_Linux.md)

## 编译教程

Expand Down
4 changes: 4 additions & 0 deletions db/TrafficLooper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "ui/mainwindow_interface.h"

#include <QThread>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QElapsedTimer>

namespace NekoRay::traffic {

Expand Down
30 changes: 30 additions & 0 deletions examples/docs/Run_Linux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Linux 运行

**使用 Linux 系统相信您已具备基本的排错能力,
本项目不提供特定发行版/架构的支持,预编译文件不能满足您的需求时,请自行编译/适配。**

已知部分 Linux 发行版无法使用、非 x86_64 暂无适配,可以尝试自行编译。

目前 Release 便携包解压后,有两种使用方法:

1. System: 若要使用系统的 Qt5 运行库,请执行 `./nekoray`
2. Bundle: 若要使用预编译的 Qt 运行库,请执行 `./launcher`

### Bundle

要求:已安装主流的发行版和 xcb 桌面环境。

运行: `./launcher` 或 部分系统可双击打开

launcher 参数

* `./launcher -- -appdata` ( `--` 后的参数传递给主程序 )
* `-debug` Debug mode

Ubuntu 22.04: `sudo apt install libxcb-xinerama0`

### System

要求:已安装主流的发行版和 xcb 桌面环境,已安装 Qt5.12 ~ Qt5.15 环境。

运行: `./nekoray` 或 部分系统可双击打开。如果无法运行,建议使用 Bundle 版。
3 changes: 1 addition & 2 deletions fmt/AbstractBean.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "includes.h"

#include <functional>

#include <QApplication>
#include <QHostInfo>
#include <QUrl>

namespace NekoRay::fmt {
AbstractBean::AbstractBean(int version) {
Expand Down
3 changes: 3 additions & 0 deletions fmt/AbstractBean.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <QJsonObject>
#include <QJsonArray>

#include "main/NekoRay.hpp"

namespace NekoRay::fmt {
Expand Down
Loading

0 comments on commit b2ebd0e

Please sign in to comment.