From bf649df9f2a5a7a68ec952f4486214f233498759 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 6 Jun 2019 12:15:31 -0300 Subject: [PATCH] Add Wine version to user agent string in case that we're running Aseprite from Wine --- src/updater/user_agent.cpp | 5 +++++ src/updater/user_agent_win.c | 31 ++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/updater/user_agent.cpp b/src/updater/user_agent.cpp index fb9c448b8..3efbb30e1 100644 --- a/src/updater/user_agent.cpp +++ b/src/updater/user_agent.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -16,6 +17,7 @@ #include extern "C" BOOL IsWow64(); + extern "C" const char* WineVersion(); #elif __APPLE__ // Mac OS X @@ -77,6 +79,9 @@ std::string getUserAgent() if (IsWow64()) userAgent << "; WOW64"; + if (const char* wineVer = WineVersion()) + userAgent << "; Wine " << wineVer; + #elif __APPLE__ // ---------------------------------------------------------------------- diff --git a/src/updater/user_agent_win.c b/src/updater/user_agent_win.c index 13788c6cb..86877229a 100644 --- a/src/updater/user_agent_win.c +++ b/src/updater/user_agent_win.c @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2015 David Capello // // This program is distributed under the terms of @@ -10,19 +11,35 @@ #include -typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL); +typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS)(HANDLE, PBOOL); +typedef const char* (CDECL* LPFN_WINE_GET_VERSION)(void); static LPFN_ISWOW64PROCESS fnIsWow64Process = NULL; +static LPFN_WINE_GET_VERSION fnWineGetVersion = NULL; BOOL IsWow64() { + if (!fnIsWow64Process) { + fnIsWow64Process = (LPFN_ISWOW64PROCESS) + GetProcAddress(GetModuleHandle(L"kernel32"), + "IsWow64Process"); + } + BOOL isWow64 = FALSE; - - fnIsWow64Process = (LPFN_ISWOW64PROCESS) - GetProcAddress(GetModuleHandle(L"kernel32"), - "IsWow64Process"); - if (fnIsWow64Process != NULL) + if (fnIsWow64Process) fnIsWow64Process(GetCurrentProcess(), &isWow64); - return isWow64; } + +const char* WineVersion() +{ + if (!fnWineGetVersion) { + fnWineGetVersion = (LPFN_WINE_GET_VERSION) + GetProcAddress(GetModuleHandle(L"ntdll.dll"), + "wine_get_version"); + } + if (fnWineGetVersion) + return fnWineGetVersion(); + else + return NULL; +}