Skip to content

Commit

Permalink
Merge pull request #214 from muttleyxd/crash-fixes
Browse files Browse the repository at this point in the history
Crash fixes (#212 and #213)
  • Loading branch information
muttleyxd authored Mar 15, 2022
2 parents 21a891d + 9929404 commit 3427529
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
setup_argparse()
setup_curlpp()
setup_fmt()
setup_httplib()
setup_pugixml()
setup_nlohmann_json()
setup_scope_guard()
Expand Down
30 changes: 14 additions & 16 deletions cmake/external_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ function(setup_argparse)
endif()
endfunction()

function(setup_curlpp)
set(CHECK_SOURCE "#error unimplemented}")
setup_library("${CHECK_SOURCE}"
NAME curlpp
GIT_REPOSITORY https://github.com/jpbarrette/curlpp.git
)
if (NOT APPLE)
set(CURLPP_LIB_PATH1 "${curlpp_BINARY_DIR}/libcurlpp.so" PARENT_SCOPE)
set(CURLPP_LIB_PATH2 "${curlpp_BINARY_DIR}/libcurlpp.so.1" PARENT_SCOPE)
set(CURLPP_LIB_PATH3 "${curlpp_BINARY_DIR}/libcurlpp.so.1.0.0" PARENT_SCOPE)
endif()
add_library(curlpp::curlpp ALIAS curlpp)
endfunction()

function(setup_doctest)
set(CHECK_SOURCE "#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>")
Expand Down Expand Up @@ -98,21 +112,6 @@ function(setup_fmt)
endif()
endfunction()

function(setup_httplib)
set(CHECK_SOURCE "#include <httplib.h>
int main()
{
httplib::Client cli(\"http://127.0.0.1\");
return 0;
}")
set(HTTPLIB_REQUIRE_OPENSSL ON)
setup_library("${CHECK_SOURCE}"
NAME httplib
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
)
endfunction()

function(setup_nlohmann_json)
set(CHECK_SOURCE "#include <nlohmann/json.hpp>
int main()
Expand Down Expand Up @@ -213,7 +212,6 @@ function(setup_steamworkssdk)
set(STEAMWORKS_LIB_PATH "${steamworkssdk_SOURCE_DIR}/lib/steam/libsteam_api.dylib" PARENT_SCOPE)
set(STEAMWORKS_LIB_PATH "${steamworkssdk_SOURCE_DIR}/lib/steam/libsteam_api.dylib")
else()
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/share/arma3-unix-launcher/lib")
set(STEAMWORKS_LIB_PATH "${steamworkssdk_SOURCE_DIR}/bin/steam/libsteam_api.so" PARENT_SCOPE)
set(STEAMWORKS_LIB_PATH "${steamworkssdk_SOURCE_DIR}/bin/steam/libsteam_api.so")
endif()
Expand Down
6 changes: 6 additions & 0 deletions src/arma3-unix-launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if (NOT APPLE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/share/arma3-unix-launcher/lib" PARENT_SCOPE)
endif()

find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Svg CONFIG REQUIRED)
Expand Down Expand Up @@ -63,6 +66,9 @@ if (APPLE)
COMMENT "Copying Steamworks SDK")
else()
install(FILES "${STEAMWORKS_LIB_PATH}"
"${CURLPP_LIB_PATH1}"
"${CURLPP_LIB_PATH2}"
"${CURLPP_LIB_PATH3}"
"${CMAKE_SOURCE_DIR}/external/steamworks-LICENSE.txt"
DESTINATION share/arma3-unix-launcher/lib)
endif()
2 changes: 1 addition & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ file(GLOB_RECURSE SOURCES *.cpp *.hpp)
add_library(common STATIC ${SOURCES})
target_compile_definitions(common PRIVATE "-DREPOSITORY_VERSION=${COMMIT_COUNT}")
target_include_directories(common INTERFACE .)
target_link_libraries(common PRIVATE httplib::httplib fmt::fmt-header-only nlohmann::json spdlog::spdlog)
target_link_libraries(common PRIVATE curlpp::curlpp curl fmt::fmt-header-only nlohmann::json spdlog::spdlog)

if (UNIX AND NOT APPLE)
target_link_libraries(common INTERFACE ${CMAKE_DL_LIBS})
Expand Down
38 changes: 32 additions & 6 deletions src/common/update_checker.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
#include "update_checker.hpp"

#include <httplib.h>
#include <sstream>

#include <nlohmann/json.hpp>
#include <spdlog/spdlog.h>

#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>

#include "filesystem_utils.hpp"

#ifndef REPOSITORY_VERSION
#define REPOSITORY_VERSION 0
#endif

namespace
{
std::filesystem::path get_ca_bundle_path()
{
if (FilesystemUtils::Exists("/etc/ssl/certs/ca-certificates.crt"))
return "/etc/ssl/certs/ca-certificates.crt";
if (FilesystemUtils::Exists("/etc/ssl/certs/ca-bundle.crt"))
return "/etc/ssl/certs/ca-bundle.crt";
throw std::runtime_error("not able to find ca bundle file");
}
}

namespace UpdateChecker
{
std::thread is_update_available(std::function<void(bool, std::string)> &&callback)
Expand All @@ -22,12 +41,19 @@ namespace UpdateChecker

try
{
httplib::Client cli("https://api.github.com");
auto res = cli.Get("/repos/muttleyxd/arma3-unix-launcher/releases");
if (res->status != 200)
throw std::runtime_error(fmt::format("HTTP request returned: {}\n{}", res->status, res->body));
curlpp::Cleanup curl_cleanup;
curlpp::Easy curl_request;
curl_request.setOpt<curlpp::options::CaInfo>(get_ca_bundle_path().string());
curl_request.setOpt<curlpp::options::Url>("https://api.github.com/repos/muttleyxd/arma3-unix-launcher/releases");
curl_request.setOpt<curlpp::options::UserAgent>("curl/12.3.4.5");

std::ostringstream output_stream;
curlpp::options::WriteStream write_stream(&output_stream);
curl_request.setOpt(write_stream);
curl_request.perform();

auto const response = nlohmann::json::parse(res->body);
auto const response_body = output_stream.str();
auto const response = nlohmann::json::parse(response_body);
if (!response.is_array())
throw std::runtime_error("Response is not JSON array");

Expand Down
4 changes: 4 additions & 0 deletions src/dayz-linux-launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/share/dayz-linux-launcher/lib" PARENT_SCOPE)

find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5Svg CONFIG REQUIRED)
Expand Down Expand Up @@ -33,5 +34,8 @@ install(FILES blagoicons/dayz.png
install(FILES dayz-linux-launcher.desktop
DESTINATION share/applications)
install(FILES "${STEAMWORKS_LIB_PATH}"
"${CURLPP_LIB_PATH1}"
"${CURLPP_LIB_PATH2}"
"${CURLPP_LIB_PATH3}"
"${CMAKE_SOURCE_DIR}/external/steamworks-LICENSE.txt"
DESTINATION share/dayz-linux-launcher/lib)
4 changes: 2 additions & 2 deletions tools/ci/docker/Dockerfile.a3ul_ubuntu-16.04_build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN add-apt-repository ppa:ubuntu-toolchain-r/test
RUN apt-get update

# Install required dependencies
RUN apt-get install -y build-essential devscripts cmake git g++-8 p7zip-full wget libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev lzma lzma-dev liblzma-dev
RUN apt-get install -y build-essential devscripts cmake git g++-8 p7zip-full wget libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev lzma lzma-dev liblzma-dev libcurl4-openssl-dev

# Build Python 3.7 - deadsnakes PPA just removed support for Ubuntu 16.04
# https://stackoverflow.com/a/70866416
Expand All @@ -37,7 +37,7 @@ RUN chmod +x /qt/qt-downloader && cd qt && ./qt-downloader linux desktop 5.15.2

# OpenSSL 1.1.1m
RUN wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz && tar xf openssl-1.1.1m.tar.gz
RUN export CC=gcc-8; export CXX=gcc-8; cd openssl-1.1.1m; ./config --static -static && make -j$(nproc) && make install_sw
RUN export CC=gcc-8; export CXX=gcc-8; cd openssl-1.1.1m; ./config && make -j$(nproc) && make install_sw

# Download nlohmann-json and doctest from GitHub
ADD https://github.com/nlohmann/json/releases/download/v3.7.3/json.hpp /usr/include/nlohmann/json.hpp
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/docker/Dockerfile.a3ul_ubuntu-18.04_build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/nul
RUN apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' && apt-get update

# Install required dependencies
RUN apt-get install -y build-essential devscripts cmake g++-8 qt5-default libqt5widgets5 libqt5svg5 libqt5svg5-dev p7zip-full wget
RUN apt-get install -y build-essential devscripts cmake g++-8 qt5-default libqt5widgets5 libqt5svg5 libqt5svg5-dev p7zip-full wget libcurl4-openssl-dev

# OpenSSL 1.1.1m
RUN wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz && tar xf openssl-1.1.1m.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/packaging/appimage/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pushd $BUILD_DIR

pushd cmake_build
cmake $A3UL_DIR -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_FLAGS="-static-libstdc++" -DRUN_TESTS=ON -DSPDLOG_BUILD_SHARED=OFF -DCMAKE_PREFIX_PATH=/qt/5.15.2/gcc_64 -DCOMMIT_COUNT=$COMMIT_COUNT
make -j4
make -j$(nproc)
ctest --output-on-failure
make install DESTDIR=$PKG_DIR
popd
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/packaging/appimage_dayz/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pushd $BUILD_DIR

pushd cmake_build
cmake $A3UL_DIR -DBUILD_DAYZ_LAUNCHER=ON -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_FLAGS="-static-libstdc++" -DRUN_TESTS=ON -DSPDLOG_BUILD_SHARED=OFF -DCMAKE_PREFIX_PATH=/qt/5.15.2/gcc_64 -DCOMMIT_COUNT=$COMMIT_COUNT
make -j4
make -j$(nproc)
ctest --output-on-failure
make install DESTDIR=$PKG_DIR
popd
Expand Down

0 comments on commit 3427529

Please sign in to comment.