Skip to content

Commit

Permalink
Merge pull request #15 from s12mmm3/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
s12mmm3 authored Oct 30, 2023
2 parents 733f215 + ac6b9a7 commit 8219eda
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 11 deletions.
139 changes: 139 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Windows
on:
# push代码时触发workflow
push:
paths:
- '**'
pull_request:
paths:
- '**'
jobs:
build:
name: Build
# 运行平台, windows-latest目前是windows server 2019
# 参考文档 https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md
runs-on: windows-2019
strategy:
# 矩阵配置
matrix:
include:
# 5.12.12
- qt_ver: 5.12.12
qt_arch: win64_msvc2015_64
tools: 'tools_opensslv3_x64'
- qt_ver: 5.12.12
qt_arch: win64_msvc2017_64
tools: 'tools_opensslv3_x64'
# 5.15.2
# - qt_ver: 5.15.2
# qt_arch: win32_msvc2019
- qt_ver: 5.15.2
qt_arch: win64_msvc2019_64
tools: 'tools_opensslv3_x64'
# 6.2.4
- qt_ver: 6.2.4
qt_arch: win64_msvc2019_64
tools: 'tools_opensslv3_x64'
# 6.6.0
- qt_ver: 6.6.0
qt_arch: win64_msvc2019_64
tools: 'tools_opensslv3_x64'
modules: 'qthttpserver qtwebsockets'
env:
targetName: Test.exe
# 步骤
steps:
# 安装Qt
- name: Install Qt
if: 'true'
# 使用外部action。这个action专门用来安装Qt
uses: jurplel/install-qt-action@v3
with:
# Version of Qt to install
version: ${{ matrix.qt_ver }}
# Target platform for build
# target: ${{ matrix.qt_target }}
arch: ${{ matrix.qt_arch }}
cache: 'true'
aqtversion: '==2.0.5'
modules: ${{ matrix.modules }}
tools: ${{ matrix.tools }}
# 拉取代码
- uses: actions/checkout@v2
with:
fetch-depth: 1
# # Conan Install
# - name: Conan Install
# id: conanInstall
# shell: pwsh
# run: |
# pip install conan
# conan -v
# conan profile detect --force
# # Conan Run
# - name: Conan Run
# id: conanRun
# shell: pwsh
# run: |
# conan install .
# ls build/generators/
# build/generators/conanrun.bat
# CMake Build
- name: CMake Build
id: build
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.msvc_arch }}
mkdir build
cd build
cmake --version
cmake -DCMAKE_INSTALL_PREFIX=${{ github.workspace }} ../
ls
# CMake Install
- name: CMake Install
env:
prefix: ${{ github.workspace }}
shell: pwsh
run: |
cd ${{ github.workspace }}/build
cmake --build . --target INSTALL --config release
ls
# 打包
- name: Package
id: package
env:
archiveName: 'QCloudMusicApi-${{ github.ref_name }}-${{ matrix.qt_ver }}-${{ matrix.qt_arch }}'
shell: pwsh
run: |
cd ${{ github.workspace }}/build
ls
Tree output /F
# 拷贝依赖
windeployqt --qmldir . --no-translations --compiler-runtime output\bin\QCloudMusicApi.dll
windeployqt --qmldir . --no-translations --compiler-runtime output\bin\Test.exe
windeployqt --qmldir . --no-translations --compiler-runtime output\bin\ApiServer.exe
# 打包zip
Compress-Archive -Path output\* ${env:archiveName}'.zip'
Tree output /F
# 记录packageName给后续step
$name = ${env:archiveName}
echo "::set-output name=packageName::$name"
ls
# tag 查询github-Release
# 上传artifacts
- uses: actions/upload-artifact@v2
with:
name: ${{ steps.package.outputs.packageName }}
path: ${{ github.workspace }}/build/output
# tag 上传Release
- name: Upload Release
if: startsWith(github.event.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ github.workspace }}/build/${{ steps.package.outputs.packageName }}.zip
asset_name: ${{ steps.package.outputs.packageName }}.zip
tag: ${{ github.ref }}
overwrite: true
5 changes: 5 additions & 0 deletions CApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ add_library(CApi SHARED
target_link_libraries(CApi PRIVATE Qt${QT_VERSION_MAJOR}::Core QCloudMusicApi)

target_compile_definitions(CApi PRIVATE CAPI_LIBRARY)

set(PUBLIC_HEADERS
capi.h
)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_HEADER_OUTPUT_DIRECTORY})
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ project(QCloudMusicApiProject VERSION 1.0)
# C++标准
set(CMAKE_CXX_STANDARD 17)

# 设置动态库和可执行程序的输出路径为 bin 目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# set default output path
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/lib)
set(CMAKE_HEADER_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/include)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})

# 添加子目录
add_subdirectory(QCloudMusicApi)
Expand Down
7 changes: 5 additions & 2 deletions QCloudMusicApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ target_link_libraries(QCloudMusicApi Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_

target_compile_definitions(QCloudMusicApi PRIVATE QCLOUDMUSICAPI_LIBRARY)

set(PUBLIC_HEADERS module.h)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_BINARY_DIR}/include)
set(PUBLIC_HEADERS
module.h
)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_HEADER_OUTPUT_DIRECTORY})
install(DIRECTORY ${OPENSSL_INCLUDE_DIR}/../bin DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../)
3 changes: 0 additions & 3 deletions QCloudMusicApi/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ static auto createRequest(QNetworkAccessManager::Operation method, QString urlSt
{ "cookie", {} }
};

//设置默认超时时间
reply->manager()->setTransferTimeout(QNetworkRequest::DefaultTransferTimeoutConstant);

// 开启一个局部的事件循环,等待响应结束,退出
QEventLoop eventLoop;
QObject::connect(reply->manager(), &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit); // 请求结束时退出事件循环
Expand Down
8 changes: 8 additions & 0 deletions QCloudMusicApi/util/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,13 @@ QList<QNetworkCookie> mapToCookie(QVariantMap &cookie) {
}
return list;
}
QVariantMap mergeMap(const QVariantMap &map0, const QVariantMap &map1)
{
QVariantMap result = map0; //复制第一个map
for (auto i = map1.constBegin(); i != map1.constEnd(); ++i) {
result.insert(i.key(), i.value()); //插入或覆盖第二个map的键值对
}
return result;
}
}
#endif // INDEX_H
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Qt版 网易云音乐 API
## 需求和依赖
本项目需要以下库和工具:

- Qt >= 5.10
- Qt >= 5.12
- OpenSSL >= 1.1.1
- conan2

Expand Down
2 changes: 1 addition & 1 deletion Test/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void MainWindow::updateCookie(QVariantMap ret) {
if (ret["body"].toMap()["token"].isValid()) {
map["MUSIC_A"] = ret["body"].toMap()["token"];
}
map.insert(newMap);
Index::mergeMap(map, newMap);
cookie = Index::mapToString(map);
}

Expand Down

0 comments on commit 8219eda

Please sign in to comment.