Skip to content

Commit

Permalink
update wx
Browse files Browse the repository at this point in the history
  • Loading branch information
DraconPern committed Jun 24, 2024
1 parent 4352482 commit 9105730
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 93 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ endif()
find_package(DCMTK REQUIRED)

#include zlib
find_package(ZLIB REQUIRED ${ZLIB_ROOT})
find_package(ZLIB REQUIRED)

#include openjpeg
find_package(OpenJPEG REQUIRED)
Expand All @@ -44,17 +44,18 @@ add_definitions(-DOPJ_STATIC)
#include fmjpeg2koj
find_package(fmjpeg2k REQUIRED)

set (OPENSSL_USE_STATIC_LIBS TRUE)
set (OPENSSL_MSVC_STATIC_RT TRUE)
find_package(OpenSSL REQUIRED)
if(WIN32)
else()
find_package(OpenSSL)
endif()

set(wxWidgets_USE_STATIC ON)
#define this so that wxWidgets doesn't define it. Conflicts w/ dcmtk's declaration
#add_definitions(-DHAVE_SSIZE_T)
find_package(wxWidgets COMPONENTS core base adv REQUIRED)
include(${wxWidgets_USE_FILE})

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/sqlite3 ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/boost-wintls/include ${FMJPEG2K_INCLUDE_DIRS} ${DCMTK_INCLUDE_DIRS} ${VLD}/include)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/sqlite3 ${Boost_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/boost-wintls/include ${FMJPEG2K_INCLUDE_DIRS} ${DCMTK_INCLUDE_DIRS} ${VLD}/include ${OPENSSL_INCLUDE_DIR})
LINK_DIRECTORIES(${FMJPEG2K}/lib ${Boost_LIBRARY_DIRS} ${VLD}/lib/Win64)

set(dovo_HEADERS
Expand Down
30 changes: 9 additions & 21 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ SET CL=/MP
SET BOOSTTOOLSET=toolset=msvc

SET GENERATOR=-G "Visual Studio 17 2022" -A x64
SET OPENSSLFLAG=VC-WIN64A
SET BOOSTADDRESSMODEL=address-model=64

cd %DEVSPACE%
git clone --branch=master --single-branch --depth=1 https://github.com/madler/zlib.git
git clone --branch=master --depth=1 https://github.com/madler/zlib.git
cd zlib
mkdir build-%TYPE%
cd build-%TYPE%
Expand All @@ -36,22 +35,8 @@ IF "%TYPE%" == "Debug" copy /Y %DEVSPACE%\libiconv\Debug\lib\libiconv.lib %DEV
IF "%TYPE%" == "Debug" copy /Y %DEVSPACE%\libiconv\Debug\lib\libiconv.lib %DEVSPACE%\libiconv\Debug\lib\libiconv_d.lib
IF "%TYPE%" == "Release" copy /Y %DEVSPACE%\libiconv\Release\lib\libiconv.lib %DEVSPACE%\libiconv\Release\lib\libiconv_o.lib

if DEFINED FORCEBUILD goto buildssl
if EXIST "%DEVSPACE%\openssl\%TYPE%\lib\libcrypto.lib" goto dontbuildssl
:buildssl
cd %DEVSPACE%
git clone https://github.com/openssl/openssl.git --branch OpenSSL_1_1_1-stable --single-branch --depth 1
cd openssl
SET OLDPATH=%PATH%
IF "%TYPE%" == "Release" perl Configure -D_CRT_SECURE_NO_WARNINGS=1 no-asm no-shared --openssldir=%DEVSPACE%\openssl\Release --prefix=%DEVSPACE%\openssl\Release %OPENSSLFLAG%
IF "%TYPE%" == "Debug" perl Configure -D_CRT_SECURE_NO_WARNINGS=1 no-asm no-shared --openssldir=%DEVSPACE%\openssl\Debug --prefix=%DEVSPACE%\openssl\Debug %OPENSSLFLAG%
nmake install
SET PATH=%OLDPATH%
:dontbuildssl
SET OPENSSL_ROOT_DIR=%DEVSPACE%\openssl\%TYPE%

cd %DEVSPACE%
git clone --branch=DCMTK-3.6.5 https://github.com/DCMTK/dcmtk.git
git clone --depth 1 --branch=DCMTK-3.6.6 https://github.com/DCMTK/dcmtk.git
cd dcmtk
mkdir build-%TYPE%
cd build-%TYPE%
Expand All @@ -60,7 +45,7 @@ msbuild /P:Configuration=%TYPE% INSTALL.vcxproj
if ERRORLEVEL 1 exit /B %ERRORLEVEL%

cd %DEVSPACE%
git clone --branch=v2.4.0 --single-branch --depth 1 https://github.com/uclouvain/openjpeg.git
git clone --branch=v2.4.0 --depth 1 https://github.com/uclouvain/openjpeg.git
cd openjpeg
mkdir build-%TYPE%
cd build-%TYPE%
Expand All @@ -78,7 +63,7 @@ msbuild /P:Configuration=%TYPE% INSTALL.vcxproj
if ERRORLEVEL 1 exit /B %ERRORLEVEL%

cd %DEVSPACE%
git clone --branch=boost-1.81.0 --recurse-submodules https://github.com/boostorg/boost.git
git clone --depth 1 --branch=boost-1.81.0 --recurse-submodules https://github.com/boostorg/boost.git
cd boost
call bootstrap
SET COMMONb2Flag=%BOOSTTOOLSET% %BOOSTADDRESSMODEL% runtime-link=static define=_BIND_TO_CURRENT_VCLIBS_VERSION=1 -j 4 stage
Expand All @@ -87,7 +72,7 @@ IF "%TYPE%" == "Release" b2 %COMMONb2Flag% %BOOSTmodules% release
IF "%TYPE%" == "Debug" b2 %COMMONb2Flag% %BOOSTmodules% debug

cd %DEVSPACE%
git clone --branch=3.2.2-hotfix --recurse-submodule https://github.com/wxWidgets/wxWidgets.git
git clone --depth 1 --branch=v3.2.5 --recurse-submodule https://github.com/wxWidgets/wxWidgets.git
cd wxWidgets
mkdir build-%TYPE%
cd build-%TYPE%
Expand All @@ -97,10 +82,13 @@ powershell "gci . *.vcxproj -recurse | ForEach { (Get-Content $_.FullName | ForE
msbuild /P:Configuration=%TYPE% INSTALL.vcxproj
if ERRORLEVEL 1 exit /B %ERRORLEVEL%

cd %DEVSPACE%
git clone https://github.com/laudrup/boost-wintls.git

cd %BUILD_DIR%
mkdir build-%TYPE%
cd build-%TYPE%
cmake .. %GENERATOR% -DwxWidgets_ROOT_DIR=%DEVSPACE%\wxWidgets\%TYPE% -DBoost_ROOT=%DEVSPACE%\boost -DDCMTK_ROOT=%DEVSPACE%\dcmtk\%TYPE% -DZLIB_ROOT=%DEVSPACE%\zlib\%TYPE% -Dfmjpeg2k_ROOT=%DEVSPACE%\fmjpeg2koj\%TYPE% -DOpenJPEG_ROOT=%DEVSPACE%\openjpeg\%TYPE% -DOPENSSL_ROOT_DIR=%OPENSSL_ROOT_DIR% -DVLD="C:\Program Files (x86)\Visual Leak Detector"
cmake .. %GENERATOR% -DwxWidgets_ROOT_DIR=%DEVSPACE%\wxWidgets\%TYPE% -DBoost_ROOT=%DEVSPACE%\boost -DDCMTK_ROOT=%DEVSPACE%\dcmtk\%TYPE% -DZLIB_ROOT=%DEVSPACE%\zlib\%TYPE% -Dfmjpeg2k_ROOT=%DEVSPACE%\fmjpeg2koj\%TYPE% -DOpenJPEG_ROOT=%DEVSPACE%\openjpeg\%TYPE% -DVLD="C:\Program Files (x86)\Visual Leak Detector"
msbuild /P:Configuration=%TYPE% ALL_BUILD.vcxproj
if ERRORLEVEL 1 exit /B %ERRORLEVEL%

Expand Down
86 changes: 25 additions & 61 deletions src/fetch.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "fetch.h"

#include <boost/asio.hpp>
#ifdef _WIN32
#include <wintls.hpp>
#else
#include <boost/beast/ssl.hpp>
#endif
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>

#ifdef _WIN32
#include <cryptuiapi.h>
#elif defined(__APPLE__)
#if defined(__APPLE__)
#include <Security/Security.h>
#endif

Expand Down Expand Up @@ -53,35 +55,15 @@ std::string fetch_string(std::string uri, const FetchOptions& options)
// Try each endpoint until we successfully establish a connection.
if (protocol == "https")
{
#if defined(_WIN32)
wintls::context ssl_context{wintls::method::system_default};
wintls::stream<boost::asio::ip::tcp::socket> socket(io_context, ssl_context);
boost::asio::connect(socket.next_layer(), endpoint);
socket.handshake(wintls::handshake_type::client);
#else
boost::asio::ssl::context ssl_context(boost::asio::ssl::context::tlsv12_client);
ssl_context.set_verify_mode(boost::asio::ssl::verify_peer);
#ifdef _WIN32
// use windows cert store for openssl
HCERTSTORE hStore;
PCCERT_CONTEXT pContext = NULL;
X509* x509;
X509_STORE* store = SSL_CTX_get_cert_store(ssl_context.native_handle());

hStore = CertOpenSystemStore(NULL, L"ROOT");

if (hStore)
{
while (pContext = CertEnumCertificatesInStore(hStore, pContext))
{
x509 = NULL;
const unsigned char* encoded_cert = pContext->pbCertEncoded;
x509 = d2i_X509(NULL, (const unsigned char**)&encoded_cert, pContext->cbCertEncoded);
if (x509)
{
int i = X509_STORE_add_cert(store, x509);
X509_free(x509);
}
}

CertFreeCertificateContext(pContext);
CertCloseStore(hStore, 0);
}
#elif defined(__APPLE__)
#if defined(__APPLE__)
CFMutableDictionaryRef search;
CFArrayRef result;
SecKeychainRef keychain;
Expand Down Expand Up @@ -133,6 +115,7 @@ std::string fetch_string(std::string uri, const FetchOptions& options)
}
boost::beast::get_lowest_layer(socket).connect(endpoint);
socket.handshake(boost::asio::ssl::stream_base::client);
#endif
http::write(socket, req);
http::read(socket, buffer, res);
boost::system::error_code ec;
Expand Down Expand Up @@ -214,40 +197,20 @@ bool fetch_file(boost::filesystem::path outputpath, std::string uri, const Fetch

boost::beast::flat_buffer buffer;
http::response_parser<http::file_body> parser;
parser.body_limit((std::numeric_limits<std::uint64_t>::max)());
parser.body_limit((std::numeric_limits<std::uint64_t>::max)());

// Try each endpoint until we successfully establish a connection.
if (protocol == "https")
{
#if defined(_WIN32)
wintls::context ssl_context{wintls::method::system_default};
wintls::stream<boost::asio::ip::tcp::socket> socket(io_context, ssl_context);
boost::asio::connect(socket.next_layer(), endpoint);
socket.handshake(wintls::handshake_type::client);
#else
boost::asio::ssl::context ssl_context(boost::asio::ssl::context::tlsv12_client);
ssl_context.set_verify_mode(boost::asio::ssl::verify_peer);
#ifdef _WIN32
// use windows cert store for openssl
HCERTSTORE hStore;
PCCERT_CONTEXT pContext = NULL;
X509* x509;
X509_STORE* store = SSL_CTX_get_cert_store(ssl_context.native_handle());

hStore = CertOpenSystemStore(NULL, L"ROOT");

if (hStore)
{
while (pContext = CertEnumCertificatesInStore(hStore, pContext))
{
x509 = NULL;
const unsigned char* encoded_cert = pContext->pbCertEncoded;
x509 = d2i_X509(NULL, (const unsigned char**)&encoded_cert, pContext->cbCertEncoded);
if (x509)
{
int i = X509_STORE_add_cert(store, x509);
X509_free(x509);
}
}

CertFreeCertificateContext(pContext);
CertCloseStore(hStore, 0);
}
#elif defined(__APPLE__)
#if defined(__APPLE__)
CFMutableDictionaryRef search;
CFArrayRef result;
SecKeychainRef keychain;
Expand Down Expand Up @@ -296,9 +259,10 @@ bool fetch_file(boost::filesystem::path outputpath, std::string uri, const Fetch
{
boost::beast::error_code ec{ static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category() };
throw boost::beast::system_error{ ec };
}
}
boost::beast::get_lowest_layer(socket).connect(endpoint);
socket.handshake(boost::asio::ssl::stream_base::client);
#endif
http::write(socket, req);
boost::system::error_code ec;
parser.get().body().open(outputpath.string().c_str(), boost::beast::file_mode::write, ec);
Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include <boost/filesystem.hpp>
#include "dovo_about.h"
#include "dcm2img.h"
#ifndef _WIN32
#include <boost/asio/ssl.hpp>

#endif
class MyApp: public wxApp
{
public:
Expand Down Expand Up @@ -52,8 +53,9 @@ bool MyApp::OnInit()
wxConfig::Get()->SetVendorName("FrontMotion");

boost::filesystem::path::codecvt(); // ensure VC++ does not race during initialization.
#ifndef _WIN32
boost::asio::ssl::detail::openssl_init<> _openssl_init;

#endif
// check for update in background and save result for next run
updater = boost::thread(&updateChecker);

Expand Down
9 changes: 5 additions & 4 deletions src/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <wx/platinfo.h>

#include "dovo_updateCheck.h"
#include <openssl/crypto.h>

// returns true if the application needs to exit
bool informUserOfUpdate(std::string json)
Expand Down Expand Up @@ -52,9 +51,9 @@ bool informUserOfUpdate(std::string json)

/*
if(today > timelimit)
{
{
updatecheckdlg.m_updatetext = wxT("This software is outdated, please upgrade!");
updatecheckdlg.m_updatetext = wxT("This software is outdated, please upgrade!");
updatecheckdlg.ShowModal();
return true;
}*/
Expand All @@ -81,8 +80,10 @@ void updateChecker()
{
std::string updateinfo;
getUpdateJSON(updateinfo);
#ifndef _WIN32
OPENSSL_thread_stop(); // required when static linking OpenSSL
wxConfig::Get()->Write("/Settings/UpdateInfo", updateinfo.c_str());
#endif
wxConfig::Get()->Write("/Settings/UpdateInfo", updateinfo.c_str());
}

int getUpdateJSON(std::string &updateinfo)
Expand Down

0 comments on commit 9105730

Please sign in to comment.