mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
Use cURL instead of cpp-httplib
This commit is contained in:
parent
9538dcb6e7
commit
58f7e6f1fe
5 changed files with 258 additions and 88 deletions
216
.github/workflows/shared-build.yml
vendored
216
.github/workflows/shared-build.yml
vendored
|
@ -43,7 +43,8 @@ jobs:
|
|||
runs-on: ${{ matrix.architecture.os }}
|
||||
environment: ${{ inputs.environment }}
|
||||
env:
|
||||
openssl-version: '3.4.1'
|
||||
wolfssl-version: 'v5.7.6-stable'
|
||||
curl-version: '8_12_1'
|
||||
openal-soft-branch: '1.24.2'
|
||||
|
||||
steps:
|
||||
|
@ -122,32 +123,72 @@ jobs:
|
|||
cmake --install ./build --config Release
|
||||
|
||||
###
|
||||
# OpenSSL
|
||||
# WolfSSL
|
||||
###
|
||||
- name: Cache OpenSSL
|
||||
id: cache-openssl
|
||||
- name: Cache WolfSSL
|
||||
id: cache-wolfssl
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: 'thirdparties/openssl/install'
|
||||
key: ${{ runner.os }}-${{ matrix.architecture.name }}-openssl-${{ env.openssl-version }}-v1
|
||||
path: 'thirdparties/wolfssl/install'
|
||||
key: ${{ runner.os }}-${{ matrix.architecture.name }}-wolfssl-${{ env.wolfssl-version }}-v1
|
||||
|
||||
# OpenSSL setup
|
||||
- name: Checkout openssl
|
||||
if: steps.cache-openssl.outputs.cache-hit != 'true'
|
||||
# WolfSSL setup
|
||||
- name: Checkout WolfSSL
|
||||
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: 'openssl/openssl'
|
||||
path: 'thirdparties/openssl'
|
||||
ref: 'openssl-${{ env.openssl-version }}'
|
||||
repository: 'wolfssl/wolfssl'
|
||||
path: 'thirdparties/wolfssl'
|
||||
ref: '${{ env.wolfssl-version }}'
|
||||
|
||||
# OpenSSL build
|
||||
- name: Configure and install openssl
|
||||
if: steps.cache-openssl.outputs.cache-hit != 'true'
|
||||
working-directory: ${{github.workspace}}/thirdparties/openssl
|
||||
# WolfSSL build
|
||||
- name: Configure and install wolfssl
|
||||
if: steps.cache-wolfssl.outputs.cache-hit != 'true'
|
||||
working-directory: ${{github.workspace}}/thirdparties/wolfssl
|
||||
run: |
|
||||
CC=gcc-12 CFLAGS= ./Configure --prefix=${{github.workspace}}/thirdparties/openssl/install --cross-compile-prefix=${{matrix.architecture.triple}}- ${{matrix.architecture.arch_option}}
|
||||
make -j$(nproc)
|
||||
make install
|
||||
cmake -B ./build \
|
||||
-DCMAKE_INSTALL_PREFIX='${{github.workspace}}/thirdparties/wolfssl/install' \
|
||||
-DCMAKE_C_FLAGS="$CFLAGS -fPIC" \
|
||||
-DCMAKE_CXX_FLAGS="$CFLAGS -fPIC" \
|
||||
-DBUILD_SHARED_LIBS=OFF -DWOLFSSL_OPENSSLEXTRA=ON -DWOLFSSL_ASM=OFF -DWOLFSSL_EXAMPLES=OFF -DWOLFSSL_CURL=ON
|
||||
cmake --build ./build --config Release --parallel
|
||||
cmake --install ./build --config Release
|
||||
|
||||
###
|
||||
# cURL
|
||||
###
|
||||
- name: Cache cURL
|
||||
id: cache-curl
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: 'thirdparties/curl/install'
|
||||
key: ${{ runner.os }}-${{ matrix.architecture.name }}-curl-${{ env.curl-version }}-v1
|
||||
|
||||
# cURL setup
|
||||
- name: Checkout cURL
|
||||
if: steps.cache-curl.outputs.cache-hit != 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: 'curl/curl'
|
||||
path: 'thirdparties/curl'
|
||||
ref: 'curl-${{ env.curl-version }}'
|
||||
|
||||
# cURL build
|
||||
- name: Configure and install curl
|
||||
if: steps.cache-curl.outputs.cache-hit != 'true'
|
||||
working-directory: ${{github.workspace}}/thirdparties/curl
|
||||
run: |
|
||||
cmake -B ./build \
|
||||
-DCMAKE_INSTALL_PREFIX='${{github.workspace}}/thirdparties/curl/install' \
|
||||
-DCURL_USE_LIBPSL=OFF \
|
||||
-DCURL_USE_WOLFSSL=ON \
|
||||
-DCURL_ZLIB="" \
|
||||
-DCURL_BROTLI="" \
|
||||
-DCURL_ZSTD="" \
|
||||
-DCMAKE_SHARED_LINKER_FLAGS="-lm" \
|
||||
-DWolfSSL_ROOT='${{github.workspace}}/thirdparties/wolfssl/install'
|
||||
cmake --build ./build --config Release --parallel
|
||||
cmake --install ./build --config Release
|
||||
|
||||
###
|
||||
# Project
|
||||
|
@ -163,9 +204,7 @@ jobs:
|
|||
-DCMAKE_INSTALL_PREFIX='${{github.workspace}}/install' \
|
||||
-DOPENAL_LIBRARY='${{github.workspace}}/thirdparties/soft-oal' \
|
||||
-DOPENAL_INCLUDE_DIR='${{github.workspace}}/thirdparties/soft-oal/install/include' \
|
||||
-DOPENSSL_ROOT_DIR='${{github.workspace}}/thirdparties/openssl/install' \
|
||||
-DHTTPLIB_REQUIRE_OPENSSL=ON \
|
||||
-DHTTPLIB_USE_BROTLI_IF_AVAILABLE=OFF \
|
||||
-DCURL_ROOT='${{github.workspace}}/thirdparties/curl/install' \
|
||||
-DGIT_REVISION_BUILD_NUMBER=${{ github.run_number }} \
|
||||
-DPRODUCT_VERSION_STAGE='${{ env.RELEASE_STAGE }}'" >> $GITHUB_ENV
|
||||
|
||||
|
@ -196,8 +235,7 @@ jobs:
|
|||
mkdir ${{github.workspace}}/package
|
||||
cp -l ${{steps.sdl.outputs.prefix}}/lib/libSDL2-2.0.so.0 '${{github.workspace}}/package/'
|
||||
cp -l ${{github.workspace}}/thirdparties/soft-oal/install/lib/libopenal.so.1 '${{github.workspace}}/package/'
|
||||
cp -l ${{github.workspace}}/thirdparties/openssl/install/lib*/libcrypto.so.3 '${{github.workspace}}/package/'
|
||||
cp -l ${{github.workspace}}/thirdparties/openssl/install/lib*/libssl.so.3 '${{github.workspace}}/package/'
|
||||
cp -l ${{github.workspace}}/thirdparties/curl/install/lib*/libcurl.so.4 '${{github.workspace}}/package/'
|
||||
if [ -d ${{github.workspace}}/install/bin ]; then cp -r ${{github.workspace}}/install/bin/openmohaa/. '${{github.workspace}}/package'; fi
|
||||
if [ -d ${{github.workspace}}/install/lib ]; then cp -r ${{github.workspace}}/install/lib/openmohaa/. '${{github.workspace}}/package'; fi
|
||||
|
||||
|
@ -232,7 +270,8 @@ jobs:
|
|||
environment: ${{ inputs.environment }}
|
||||
env:
|
||||
flexbison-branch: 'v2.5.25'
|
||||
openssl-version: '3.4.1'
|
||||
wolfssl-version: 'v5.7.6-stable'
|
||||
curl-version: '8_12_1'
|
||||
openal-soft-branch: '1.24.2'
|
||||
|
||||
steps:
|
||||
|
@ -350,32 +389,37 @@ jobs:
|
|||
if (("x64", "ARM64") -icontains "${{ matrix.architecture.config }}") { Rename-Item -Path '.\install\bin\OpenAL32.dll' -NewName 'OpenAL64.dll' }
|
||||
|
||||
###
|
||||
# OpenSSL
|
||||
# cURL
|
||||
#
|
||||
# Uses Schannel as SSL backend, native CAs are used
|
||||
###
|
||||
- name: Cache OpenSSL
|
||||
id: cache-openssl
|
||||
- name: Cache cURL
|
||||
id: cache-curl
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: 'thirdparties/openssl/install'
|
||||
key: ${{ runner.os }}-${{ matrix.architecture.name }}-openssl-${{ env.openssl-version }}-v1
|
||||
path: 'thirdparties/curl/install'
|
||||
key: ${{ runner.os }}-${{ matrix.architecture.name }}-curl-${{ env.curl-version }}-v1
|
||||
|
||||
# OpenSSL setup
|
||||
- name: Checkout openssl
|
||||
if: steps.cache-openssl.outputs.cache-hit != 'true'
|
||||
# cURL setup
|
||||
- name: Checkout cURL
|
||||
if: steps.cache-curl.outputs.cache-hit != 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: 'openssl/openssl'
|
||||
path: 'thirdparties/openssl'
|
||||
ref: 'openssl-${{ env.openssl-version }}'
|
||||
repository: 'curl/curl'
|
||||
path: 'thirdparties/curl'
|
||||
ref: 'curl-${{ env.curl-version }}'
|
||||
|
||||
# OpenSSL build
|
||||
- name: Configure and install openssl
|
||||
if: steps.cache-openssl.outputs.cache-hit != 'true'
|
||||
working-directory: ${{github.workspace}}/thirdparties/openssl
|
||||
# cURL build
|
||||
- name: Configure and install curl
|
||||
if: steps.cache-curl.outputs.cache-hit != 'true'
|
||||
working-directory: ${{github.workspace}}/thirdparties/curl
|
||||
run: |
|
||||
perl .\Configure --prefix=${{github.workspace}}/thirdparties/openssl/install no-asm ${{matrix.architecture.arch_option}} /FS
|
||||
jom -j($(Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors)
|
||||
nmake install
|
||||
cmake -B ./build `
|
||||
-DCMAKE_INSTALL_PREFIX='${{github.workspace}}/thirdparties/curl/install' `
|
||||
-DCURL_USE_LIBPSL=OFF `
|
||||
-DCURL_USE_SCHANNEL=ON
|
||||
cmake --build ./build --config Release --parallel
|
||||
cmake --install ./build --config Release
|
||||
|
||||
###
|
||||
# Project
|
||||
|
@ -394,9 +438,7 @@ jobs:
|
|||
-DBISON_EXECUTABLE='${{github.workspace}}/thirdparties/winflexbison-install/win_bison.exe' `
|
||||
-DOPENAL_LIBRARY='${{github.workspace}}/thirdparties/soft-oal' `
|
||||
-DOPENAL_INCLUDE_DIR='${{github.workspace}}/thirdparties/soft-oal/install/include' `
|
||||
-DOPENSSL_ROOT_DIR='${{github.workspace}}/thirdparties/openssl/install' `
|
||||
-DHTTPLIB_REQUIRE_OPENSSL=ON `
|
||||
-DHTTPLIB_USE_BROTLI_IF_AVAILABLE=OFF `
|
||||
-DCURL_ROOT='${{github.workspace}}/thirdparties/curl/install' `
|
||||
-DFLEX_EXECUTABLE='${{github.workspace}}/thirdparties/winflexbison-install/win_flex.exe' `
|
||||
-DPRODUCT_VERSION_STAGE='${{ env.RELEASE_STAGE }}'".Replace("`r", "").Replace("`n", "") >> $env:GITHUB_ENV
|
||||
|
||||
|
@ -426,7 +468,7 @@ jobs:
|
|||
New-Item -ItemType Directory '${{github.workspace}}/package'
|
||||
Copy-Item '${{steps.sdl.outputs.prefix}}/bin/*.dll' -Destination '${{github.workspace}}/package'
|
||||
Copy-Item '${{github.workspace}}/thirdparties/soft-oal/install/bin/*.dll' -Destination '${{github.workspace}}/package'
|
||||
Copy-Item '${{github.workspace}}/thirdparties/openssl/install/bin/*.dll' -Destination '${{github.workspace}}/package'
|
||||
Copy-Item '${{github.workspace}}/thirdparties/curl/install/bin/*.dll' -Destination '${{github.workspace}}/package'
|
||||
if (Test-Path ${{github.workspace}}/install/bin) { Copy-Item '${{github.workspace}}/install/bin/*' -Include '*.dll','*.exe','*.pdb' -Destination '${{github.workspace}}/package' }
|
||||
if (Test-Path ${{github.workspace}}/install/lib) { Copy-Item '${{github.workspace}}/install/lib/*' -Include '*.dll','*.exe','*.pdb' -Destination '${{github.workspace}}/package' }
|
||||
|
||||
|
@ -473,6 +515,8 @@ jobs:
|
|||
environment: ${{inputs.environment}}
|
||||
env:
|
||||
openal-soft-branch: '1.24.2'
|
||||
wolfssl-version: 'v5.7.6-stable'
|
||||
curl-version: '8_12_1'
|
||||
|
||||
steps:
|
||||
###
|
||||
|
@ -538,6 +582,79 @@ jobs:
|
|||
cmake --build ./build --config Release --parallel
|
||||
cmake --install ./build --config Release
|
||||
|
||||
###
|
||||
# WolfSSL
|
||||
###
|
||||
# FIXME: Figure out how to compile WolfSSL cross-architecture
|
||||
#
|
||||
# - name: Cache WolfSSL
|
||||
# id: cache-wolfssl
|
||||
# uses: actions/cache@v4
|
||||
# with:
|
||||
# path: 'thirdparties/wolfssl_install'
|
||||
# key: ${{ runner.os }}-${{ matrix.architecture.name }}-wolfssl-${{ env.wolfssl-version }}-v1
|
||||
#
|
||||
# # WolfSSL setup
|
||||
# - name: Checkout WolfSSL
|
||||
# if: steps.cache-wolfssl.outputs.cache-hit != 'true'
|
||||
# uses: actions/checkout@v4
|
||||
# with:
|
||||
# repository: 'wolfssl/wolfssl'
|
||||
# path: 'thirdparties/wolfssl'
|
||||
# ref: '${{ env.wolfssl-version }}'
|
||||
#
|
||||
# # WolfSSL build
|
||||
# - name: Configure and install wolfssl
|
||||
# if: steps.cache-wolfssl.outputs.cache-hit != 'true'
|
||||
# working-directory: ${{github.workspace}}/thirdparties/wolfssl
|
||||
# run: |
|
||||
# cmake -B ./build \
|
||||
# -DCMAKE_INSTALL_PREFIX='${{github.workspace}}/thirdparties/wolfssl_install' \
|
||||
# -DCMAKE_OSX_ARCHITECTURES='${{ matrix.architecture.build_name }}' \
|
||||
# -DBUILD_SHARED_LIBS=OFF -DWOLFSSL_OPENSSLEXTRA=ON -DWOLFSSL_ASM=OFF -DWOLFSSL_EXAMPLES=OFF -DWOLFSSL_CURL=ON
|
||||
# cmake --build ./build --config Release --parallel
|
||||
# cmake --install ./build --config Release
|
||||
|
||||
###
|
||||
# cURL
|
||||
###
|
||||
- name: Cache cURL
|
||||
id: cache-curl
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: 'thirdparties/curl/install'
|
||||
key: ${{ runner.os }}-${{ matrix.architecture.name }}-curl-${{ env.curl-version }}-v1
|
||||
|
||||
# cURL setup
|
||||
- name: Checkout cURL
|
||||
if: steps.cache-curl.outputs.cache-hit != 'true'
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: 'curl/curl'
|
||||
path: 'thirdparties/curl'
|
||||
ref: 'curl-${{ env.curl-version }}'
|
||||
|
||||
# cURL build
|
||||
- name: Configure and install curl
|
||||
if: steps.cache-curl.outputs.cache-hit != 'true'
|
||||
working-directory: ${{github.workspace}}/thirdparties/curl
|
||||
run: |
|
||||
cmake -B ./build \
|
||||
-DCMAKE_INSTALL_PREFIX='${{github.workspace}}/thirdparties/curl/install' \
|
||||
-DCMAKE_OSX_ARCHITECTURES='${{ matrix.architecture.build_name }}' \
|
||||
-DCURL_USE_LIBPSL=OFF \
|
||||
-DCURL_USE_WOLFSSL=OFF \
|
||||
-DCURL_USE_LIBSSH2=OFF \
|
||||
-DUSE_LIBIDN2=OFF \
|
||||
-DUSE_NGHTTP2=OFF \
|
||||
-DCURL_ENABLE_SSL=OFF \
|
||||
-DCURL_ZLIB="" \
|
||||
-DCURL_BROTLI="" \
|
||||
-DCURL_ZSTD="" \
|
||||
-DWolfSSL_ROOT='${{github.workspace}}/thirdparties/wolfssl_install'
|
||||
cmake --build ./build --config Release --parallel
|
||||
cmake --install ./build --config Release
|
||||
|
||||
###
|
||||
# Project
|
||||
###
|
||||
|
@ -554,9 +671,7 @@ jobs:
|
|||
-DCMAKE_OSX_ARCHITECTURES='${{ matrix.architecture.build_name }}' \
|
||||
-DOPENAL_LIBRARY='${{github.workspace}}/thirdparties/soft-oal/install' \
|
||||
-DOPENAL_INCLUDE_DIR='${{github.workspace}}/thirdparties/soft-oal/install/include/AL' \
|
||||
-DOPENSSL_ROOT_DIR='${{github.workspace}}/thirdparties/openssl/install' \
|
||||
-DHTTPLIB_USE_OPENSSL_IF_AVAILABLE=OFF \
|
||||
-DHTTPLIB_USE_BROTLI_IF_AVAILABLE=OFF \
|
||||
-DCURL_ROOT='${{github.workspace}}/thirdparties/curl/install' \
|
||||
-DGIT_REVISION_BUILD_NUMBER=${{ github.run_number }} \
|
||||
-DPRODUCT_VERSION_STAGE='${{ env.RELEASE_STAGE }}'" >> $GITHUB_ENV
|
||||
|
||||
|
@ -587,6 +702,7 @@ jobs:
|
|||
mkdir ${{github.workspace}}/package
|
||||
cp -l ${{steps.sdl.outputs.prefix}}/lib/libSDL2-2.0.0.dylib '${{github.workspace}}/package/'
|
||||
cp -l ${{github.workspace}}/thirdparties/soft-oal/install/lib/libopenal.1.dylib '${{github.workspace}}/package/'
|
||||
cp -l ${{github.workspace}}/thirdparties/curl/install/lib*/libcurl.4.dylib '${{github.workspace}}/package/'
|
||||
if [ -d ${{github.workspace}}/install/bin ]; then cp -r ${{github.workspace}}/install/bin/openmohaa/. '${{github.workspace}}/package'; fi
|
||||
if [ -d ${{github.workspace}}/install/lib ]; then cp -r ${{github.workspace}}/install/lib/openmohaa/. '${{github.workspace}}/package'; fi
|
||||
|
||||
|
|
|
@ -45,15 +45,15 @@ target_compile_features(syslib INTERFACE cxx_nullptr cxx_std_17)
|
|||
target_compile_features(syslib INTERFACE c_variadic_macros)
|
||||
target_link_libraries(syslib INTERFACE qcommon)
|
||||
|
||||
find_package(OpenSSL)
|
||||
find_package(CURL)
|
||||
|
||||
if (NOT ${OPENSSL_FOUND})
|
||||
message(WARNING "OpenSSL is not available, cpp-httplib won't work with SSL/TLS websites")
|
||||
if (CURL_FOUND)
|
||||
target_link_libraries(syslib INTERFACE CURL::libcurl)
|
||||
target_compile_definitions(syslib INTERFACE HAS_LIBCURL=1)
|
||||
else()
|
||||
message(WARNING "CURL is not available, update checking will not work")
|
||||
endif()
|
||||
|
||||
add_subdirectory("../cpp-httplib-0.19.0" "cpp-httplib-0.19.0")
|
||||
target_link_libraries(syslib INTERFACE httplib)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(syslib INTERFACE wsock32 ws2_32)
|
||||
target_link_libraries(syslib INTERFACE winmm)
|
||||
|
|
|
@ -23,7 +23,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "sys_update_checker.h"
|
||||
#include "../qcommon/q_version.h"
|
||||
|
||||
#include <httplib.h>
|
||||
#ifdef HAS_LIBCURL
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
//#include <httplib.h>
|
||||
#include "../qcommon/json.hpp"
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
@ -50,38 +54,49 @@ UpdateChecker::UpdateChecker()
|
|||
{
|
||||
lastMajor = lastMinor = lastPatch = 0;
|
||||
versionChecked = false;
|
||||
client = NULL;
|
||||
handle = NULL;
|
||||
thread = NULL;
|
||||
}
|
||||
|
||||
UpdateChecker::~UpdateChecker()
|
||||
{
|
||||
if (client) {
|
||||
if (handle) {
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateChecker::Init()
|
||||
{
|
||||
assert(!client);
|
||||
CURLcode result;
|
||||
|
||||
assert(!handle);
|
||||
assert(!thread);
|
||||
|
||||
try {
|
||||
httplib::Client *updateCheckerClient = new httplib::Client("https://api.github.com");
|
||||
|
||||
client = updateCheckerClient;
|
||||
thread = new std::thread(&UpdateChecker::RequestThread, this);
|
||||
} catch (const std::exception& e) {
|
||||
client = NULL;
|
||||
thread = NULL;
|
||||
Com_DPrintf("Failed to create update checker: %s\n", e.what());
|
||||
handle = curl_easy_init();
|
||||
if (!handle) {
|
||||
Com_DPrintf("Failed to create curl client\n");
|
||||
return;
|
||||
}
|
||||
|
||||
result = curl_easy_setopt(handle, CURLOPT_URL, "https://api.github.com/repos/openmoh/openmohaa/releases/latest");
|
||||
|
||||
if (result != CURLE_OK) {
|
||||
Com_DPrintf("Failed to set curl URL: %s\n", curl_easy_strerror(result));
|
||||
curl_easy_cleanup(handle);
|
||||
handle = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_USERAGENT, "curl");
|
||||
|
||||
thread = new std::thread(&UpdateChecker::RequestThread, this);
|
||||
}
|
||||
|
||||
void UpdateChecker::Process()
|
||||
{
|
||||
std::chrono::time_point<std::chrono::steady_clock> currentTime = std::chrono::steady_clock::now();
|
||||
if (currentTime < lastMessageTime + std::chrono::milliseconds(std::max(1, com_updateCheckInterval->integer) * 60 * 1000)) {
|
||||
if (currentTime
|
||||
< lastMessageTime + std::chrono::milliseconds(Q_max(1, com_updateCheckInterval->integer) * 60 * 1000)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -109,12 +124,12 @@ void UpdateChecker::ShutdownClient()
|
|||
{
|
||||
std::lock_guard<std::shared_mutex> l(clientMutex);
|
||||
|
||||
if (!client) {
|
||||
if (!handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete (httplib::Client *)client;
|
||||
client = NULL;
|
||||
curl_easy_cleanup(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
|
||||
void UpdateChecker::ShutdownThread()
|
||||
|
@ -201,22 +216,35 @@ bool UpdateChecker::ParseVersionNumber(const char *value, int& major, int& minor
|
|||
return true;
|
||||
}
|
||||
|
||||
size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
std::string& responseString = *(std::string *)userp;
|
||||
responseString.append(contents, size * nmemb);
|
||||
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
void UpdateChecker::DoRequest()
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> l(clientMutex);
|
||||
CURLcode result;
|
||||
std::string responseString;
|
||||
|
||||
httplib::Client *updateCheckerClient = (httplib::Client *)client;
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &WriteCallback);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &responseString);
|
||||
|
||||
if (!updateCheckerClient) {
|
||||
result = curl_easy_perform(handle);
|
||||
if (result != CURLE_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Result result = updateCheckerClient->Get("/repos/openmoh/openmohaa/releases/latest");
|
||||
if (result.error() != httplib::Error::Success) {
|
||||
nlohmann::json data;
|
||||
|
||||
try {
|
||||
data = nlohmann::json::parse(responseString);
|
||||
} catch(const std::exception& e) {
|
||||
return;
|
||||
}
|
||||
httplib::Response response = result.value();
|
||||
nlohmann::json data = nlohmann::json::parse(response.body);
|
||||
|
||||
try {
|
||||
const nlohmann::json::string_t& tagName = data.at("tag_name");
|
||||
|
@ -237,9 +265,10 @@ void UpdateChecker::RequestThread()
|
|||
std::chrono::time_point<std::chrono::steady_clock> currentTime = std::chrono::steady_clock::now();
|
||||
std::chrono::time_point<std::chrono::steady_clock> lastCheckTime;
|
||||
|
||||
while (client) {
|
||||
while (handle) {
|
||||
currentTime = std::chrono::steady_clock::now();
|
||||
if (currentTime >= lastCheckTime + std::chrono::milliseconds(std::max(1, com_updateCheckInterval->integer) * 60 * 1000)) {
|
||||
if (currentTime
|
||||
>= lastCheckTime + std::chrono::milliseconds(Q_max(1, com_updateCheckInterval->integer) * 60 * 1000)) {
|
||||
lastCheckTime = currentTime;
|
||||
|
||||
DoRequest();
|
||||
|
@ -248,3 +277,19 @@ void UpdateChecker::RequestThread()
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void Sys_UpdateChecker_Init()
|
||||
{
|
||||
}
|
||||
|
||||
void Sys_UpdateChecker_Process()
|
||||
{
|
||||
}
|
||||
|
||||
void Sys_UpdateChecker_Shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
//
|
||||
// Thread-related variables
|
||||
//
|
||||
void *client;
|
||||
void *handle;
|
||||
std::shared_mutex clientMutex;
|
||||
std::thread *thread;
|
||||
};
|
||||
|
|
|
@ -10,13 +10,13 @@ The following tools are required for all platforms:
|
|||
- [OpenAL SDK](https://github.com/kcat/openal-soft)
|
||||
|
||||
The following tools may be useful:
|
||||
- [OpenSSL](https://github.com/openssl/openssl)
|
||||
- [cURL](https://github.com/curl/curl)
|
||||
|
||||
The installation directory can be set to the MOHAA directory with `-DCMAKE_INSTALL_PREFIX=/path/to/mohaa`.
|
||||
|
||||
Compiling debug binaries will result in a `-dbg` suffix appended to the name of the binaries to avoid mixing debug/release code.
|
||||
|
||||
OpenSSL is used to access websites using TLS over HTTP. It is currently used to check for a new release. If OpenSSL is not installed, OpenMoHAA will be unable to check for new updates automatically.
|
||||
cURL is used to access websites. It is currently used to check for a new release. If the project is compiled without cURL, OpenMoHAA will be unable to check for new updates automatically.
|
||||
|
||||
## Compiling for Linux
|
||||
|
||||
|
@ -25,12 +25,13 @@ These are the tools required on Linux :
|
|||
- libsdl2-dev
|
||||
- libopenal-dev
|
||||
- libssl-dev
|
||||
- libcurl4-openssl-dev
|
||||
|
||||
**clang-7** and **gcc-9** has been tested to work on Ubuntu 20.04. Although it's best to use the latest versions.
|
||||
|
||||
1 line install command with clang:
|
||||
```sh
|
||||
sudo apt-get install -y cmake ninja-build clang lld flex bison libsdl2-dev libopenal-dev libssl-dev
|
||||
sudo apt-get install -y cmake ninja-build clang lld flex bison libsdl2-dev libopenal-dev libcurl4-openssl-dev
|
||||
```
|
||||
|
||||
Example with **CMake** and **ninja-build** installed:
|
||||
|
@ -45,12 +46,20 @@ Other compilers can be specified by appending `-DCMAKE_C_COMPILER=/path/to/compi
|
|||
|
||||
Visual Studio (2019 or 2022) is generally preferred.
|
||||
|
||||
Flex and Bison can be downloaded from here: https://github.com/lexxmark/winflexbison/releases/latest
|
||||
OpenAL can be downloaded from here: https://github.com/kcat/openal-soft/releases/latest rename `soft_oal.dll` to `OpenAL64.dll` on 64-bit and `OpenAL32.dll` on 32-bit
|
||||
- Get Flex/Bison: https://github.com/lexxmark/winflexbison/releases/latest
|
||||
- Get OpenAL: https://github.com/kcat/openal-soft/releases/latest rename `soft_oal.dll` to `OpenAL64.dll` on 64-bit and `OpenAL32.dll` on 32-bit
|
||||
- Get cURL: https://github.com/curl/curl
|
||||
|
||||
Append `-DFLEX_EXECUTABLE=...\win_flex.exe -DBISON_EXECUTABLE=...\win_bison.exe -DOPENAL_INCLUDE_DIR="path/to/oal/include" -DOPENAL_LIBRARY="path/to/oal"` to the CMake command-line to use the package from the link above.
|
||||
|
||||
Optionally, you can append `-DOPENSSL_ROOT_DIR=path\to\openssl\install` to specify the path to OpenSSL.
|
||||
Optionally, The cURL library can be compiled with the following CMake commands:
|
||||
```
|
||||
cmake -DCMAKE_INSTALL_PREFIX="E:\Src\openmoh\openmohaa\thirdparty\curl\build\install" -DCURL_USE_LIBPSL=OFF -DCURL_USE_SCHANNEL=ON -B build
|
||||
cmake --build build --config Release
|
||||
cmake --install build --config Release
|
||||
```
|
||||
|
||||
afterwards you can can append `-DCURL_ROOT=path\to\curl\install` to specify the install path to cURL.
|
||||
|
||||
## Tweaking the build
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue