From a4bf68b613a443538a54e77ff2863c88c1c8a86a Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 2 May 2024 17:50:27 +0200 Subject: added logic to change default HTTP server implementation when running on Wine (#71) * added logic to change default HTTP server implementation when running on Wine * added log message to inform user about potential problems when running under Wine --- src/zencore/include/zencore/windows.h | 2 ++ src/zencore/windows.cpp | 13 +++++++++++++ src/zenserver/config.cpp | 11 ++++++++--- src/zenserver/zenserver.cpp | 8 ++++++++ src/zenutil/zenserverprocess.cpp | 11 ++++++++--- 5 files changed, 39 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/zencore/include/zencore/windows.h b/src/zencore/include/zencore/windows.h index 14026fef1..b2b220f8f 100644 --- a/src/zencore/include/zencore/windows.h +++ b/src/zencore/include/zencore/windows.h @@ -412,5 +412,7 @@ private: DWORD m_dwViewDesiredAccess; }; +bool IsRunningOnWine(); + } // namespace zen::windows #endif diff --git a/src/zencore/windows.cpp b/src/zencore/windows.cpp index 76d8ab445..d02fcd35e 100644 --- a/src/zencore/windows.cpp +++ b/src/zencore/windows.cpp @@ -9,6 +9,19 @@ namespace zen::windows { +bool +IsRunningOnWine() +{ + HMODULE NtDll = GetModuleHandleA("ntdll.dll"); + + if (NtDll) + { + return !!GetProcAddress(NtDll, "wine_get_version"); + } + + return false; +} + FileMapping::FileMapping(_In_ FileMapping& orig) { m_pData = NULL; diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index e33b6caf3..ce1b21926 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -35,6 +35,8 @@ ZEN_THIRD_PARTY_INCLUDES_END #if ZEN_PLATFORM_WINDOWS +# include + // Used for getting My Documents for default data directory # include # pragma comment(lib, "shell32.lib") @@ -550,10 +552,13 @@ ParseConfigFile(const std::filesystem::path& Path, void ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) { -#if ZEN_WITH_HTTPSYS - const char* DefaultHttp = "httpsys"; -#else const char* DefaultHttp = "asio"; + +#if ZEN_WITH_HTTPSYS + if (!zen::windows::IsRunningOnWine()) + { + DefaultHttp = "httpsys"; + } #endif // Note to those adding future options; std::filesystem::path-type options diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index 89f376709..0909c26e9 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -608,6 +608,14 @@ ZenServer::Run() } ZEN_INFO(ZEN_APP_NAME " now running (pid: {})", GetCurrentProcessId()); + +#if ZEN_PLATFORM_WINDOWS + if (zen::windows::IsRunningOnWine()) + { + ZEN_INFO("detected Wine session - " ZEN_APP_NAME " is not formally tested on Wine and may therefore not work or perform well"); + } +#endif + #if ZEN_USE_SENTRY ZEN_INFO("sentry crash handler {}", m_UseSentry ? "ENABLED" : "DISABLED"); if (m_UseSentry) diff --git a/src/zenutil/zenserverprocess.cpp b/src/zenutil/zenserverprocess.cpp index 26c72fc9b..a44ea4954 100644 --- a/src/zenutil/zenserverprocess.cpp +++ b/src/zenutil/zenserverprocess.cpp @@ -482,10 +482,15 @@ ZenServerEnvironment::InitializeForTest(std::filesystem::path ProgramBaseDir, if (ServerClass.empty()) { #if ZEN_WITH_HTTPSYS - m_ServerClass = "httpsys"sv; -#else - m_ServerClass = "asio"sv; + if (!zen::windows::IsRunningOnWine()) + { + m_ServerClass = "httpsys"sv; + + return; + } #endif + + m_ServerClass = "asio"sv; } else { -- cgit v1.2.3