From 910ce5f10d8f170d6d6a6962fa6d72b890b812a9 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 23 Oct 2018 16:58:54 +0200 Subject: [PATCH] Fix for Windows - "winsock2.h" needs to be included before "windows.h". But if a compilation unit include "windows.h" and after "networkTools.h", we fails and it is complicated to handle. The include must not be in the header but in the cpp - windows define some ERROR macro. It is a pitty but we cannot use `ERROR` in our enum. - If build statically using mingw we need to define `CURL_STATICLIB` --- include/common/networkTools.h | 17 ----------------- include/downloader.h | 6 +++--- meson.build | 6 ++++++ src/common/networkTools.cpp | 16 ++++++++++++++++ src/downloader.cpp | 20 ++++++++++---------- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/include/common/networkTools.h b/include/common/networkTools.h index 8ca5919b1..4281860f5 100644 --- a/include/common/networkTools.h +++ b/include/common/networkTools.h @@ -20,25 +20,8 @@ #ifndef KIWIX_NETWORKTOOLS_H #define KIWIX_NETWORKTOOLS_H -#ifdef _WIN32 -#include -#include -#else -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif - -#include #include #include -#include namespace kiwix { diff --git a/include/downloader.h b/include/downloader.h index e7afa6d8d..1fa439f25 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -45,13 +45,13 @@ class AriaError : public std::runtime_error { class Download { public: - typedef enum { ACTIVE, WAITING, PAUSED, ERROR, COMPLETE, REMOVED, UNKNOWN } StatusResult; + typedef enum { K_ACTIVE, K_WAITING, K_PAUSED, K_ERROR, K_COMPLETE, K_REMOVED, K_UNKNOWN } StatusResult; Download() : - m_status(UNKNOWN) {} + m_status(K_UNKNOWN) {} Download(std::shared_ptr p_aria, std::string did) : mp_aria(p_aria), - m_status(UNKNOWN), + m_status(K_UNKNOWN), m_did(did) {}; void updateStatus(bool follow=false); StatusResult getStatus() { return m_status; } diff --git a/meson.build b/meson.build index a855be365..62c0bb26c 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,12 @@ libzim_dep = dependency('libzim', version : '>=4.0.0', static:static_deps) pugixml_dep = dependency('pugixml', static:static_deps) libcurl_dep = dependency('libcurl', static:static_deps) +if target_machine.system() == 'windows' and static_deps + add_project_arguments('-DCURL_STATICLIB', language : 'cpp') +endif + + + ctpp2_include_path = '' has_ctpp2_dep = false ctpp2_prefix_install = get_option('ctpp2-install-prefix') diff --git a/src/common/networkTools.cpp b/src/common/networkTools.cpp index 9ee98e488..0066b3d48 100644 --- a/src/common/networkTools.cpp +++ b/src/common/networkTools.cpp @@ -19,9 +19,25 @@ #include +#ifdef _WIN32 +#include +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #include #include +#include std::map kiwix::getNetworkInterfaces() diff --git a/src/downloader.cpp b/src/downloader.cpp index 6902ea2ee..071afce8e 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -48,24 +48,24 @@ void Download::updateStatus(bool follow) // std::cout << strStatus << std::endl; MethodResponse response(strStatus); if (response.isFault()) { - m_status = Download::UNKNOWN; + m_status = Download::K_UNKNOWN; return; } auto structNode = response.getParams().getParam(0).getValue().getStruct(); auto _status = structNode.getMember("status").getValue().getAsS(); - auto status = _status == "active" ? Download::ACTIVE - : _status == "waiting" ? Download::WAITING - : _status == "paused" ? Download::PAUSED - : _status == "error" ? Download::ERROR - : _status == "complete" ? Download::COMPLETE - : _status == "removed" ? Download::REMOVED - : Download::UNKNOWN; - if (status == COMPLETE) { + auto status = _status == "active" ? Download::K_ACTIVE + : _status == "waiting" ? Download::K_WAITING + : _status == "paused" ? Download::K_PAUSED + : _status == "error" ? Download::K_ERROR + : _status == "complete" ? Download::K_COMPLETE + : _status == "removed" ? Download::K_REMOVED + : Download::K_UNKNOWN; + if (status == K_COMPLETE) { try { auto followedByMember = structNode.getMember("followedBy"); m_followedBy = followedByMember.getValue().getArray().getValue(0).getAsS(); if (follow) { - status = ACTIVE; + status = K_ACTIVE; updateStatus(true); return; }