From 33149eed0e8c78630dbce2b01557c1db61028ccb Mon Sep 17 00:00:00 2001 From: Bart House Date: Sat, 2 Nov 2019 11:39:11 -0700 Subject: [PATCH] Move is_desktop_bridge() api to win10 wrapper. --- include/extern.h | 1 - sys/winnt/win10.c | 26 ++++++++++++++++++++++++++ sys/winnt/win10.h | 5 ++++- sys/winnt/windmain.c | 16 ---------------- sys/winnt/winnt.c | 8 +++++++- win/win32/vs2017/common.props | 2 +- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/include/extern.h b/include/extern.h index b1a28d4b8..989f07f50 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1826,7 +1826,6 @@ E int NDECL(dohistory); E void FDECL(chdirx, (char *, BOOLEAN_P)); #endif /* CHDIR */ E boolean NDECL(authorize_wizard_mode); -E boolean NDECL(is_desktop_bridge_application); #endif /* MICRO || WIN32 */ diff --git a/sys/winnt/win10.c b/sys/winnt/win10.c index c6d667080..07b898107 100644 --- a/sys/winnt/win10.c +++ b/sys/winnt/win10.c @@ -34,6 +34,17 @@ void win10_init() FreeLibrary(hUser32); + HINSTANCE hKernel32 = LoadLibraryA("kernel32.dll"); + + if (hKernel32 == NULL) + panic("Unable to load user32.dll"); + + gWin10.GetCurrentPackageFullName = (GetCurrentPackageFullNameProc) GetProcAddress(hKernel32, "GetCurrentPackageFullName"); + if (gWin10.GetCurrentPackageFullName == NULL) + panic("Unable to get address of GetCurrentPackageFullName"); + + FreeLibrary(hKernel32); + gWin10.Valid = TRUE; } @@ -80,4 +91,19 @@ void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo) monitorInfo->left = info.rcMonitor.left; monitorInfo->top = info.rcMonitor.top; } + +BOOL +win10_is_desktop_bridge_application() +{ + if (gWin10.Valid) { + UINT32 length = 0; + LONG rc = gWin10.GetCurrentPackageFullName(&length, NULL); + + return (rc == ERROR_INSUFFICIENT_BUFFER); + } + + return FALSE; +} + + #endif /* _MSC_VER */ diff --git a/sys/winnt/win10.h b/sys/winnt/win10.h index 458e6991d..4ba834995 100644 --- a/sys/winnt/win10.h +++ b/sys/winnt/win10.h @@ -11,12 +11,15 @@ typedef DPI_AWARENESS_CONTEXT(WINAPI *GetThreadDpiAwarenessContextProc)(VOID); typedef BOOL(WINAPI *AreDpiAwarenessContextsEqualProc)( DPI_AWARENESS_CONTEXT dpiContextA, DPI_AWARENESS_CONTEXT dpiContextB); typedef UINT(WINAPI *GetDpiForWindowProc)(HWND hwnd); +typedef LONG (WINAPI *GetCurrentPackageFullNameProc)(UINT32 *packageFullNameLength, + PWSTR packageFullName); typedef struct { BOOL Valid; GetThreadDpiAwarenessContextProc GetThreadDpiAwarenessContext; AreDpiAwarenessContextsEqualProc AreDpiAwarenessContextsEqual; GetDpiForWindowProc GetDpiForWindow; + GetCurrentPackageFullNameProc GetCurrentPackageFullName; } Win10; typedef struct { @@ -34,6 +37,6 @@ int win10_monitor_dpi(HWND hWnd); double win10_monitor_scale(HWND hWnd); void win10_monitor_size(HWND hWnd, int * width, int * height); void win10_monitor_info(HWND hWnd, MonitorInfo * monitorInfo); - +BOOL win10_is_desktop_bridge_application(void); #endif // WIN10_H diff --git a/sys/winnt/windmain.c b/sys/winnt/windmain.c index 44a1902f5..df2eaff4e 100644 --- a/sys/winnt/windmain.c +++ b/sys/winnt/windmain.c @@ -13,13 +13,6 @@ #include #include -#ifdef __MINGW32__ -extern LONG GetCurrentPackageFullName(UINT32 *packageFullNameLength, - PWSTR packageFullName); -#else -# include -#endif - #if !defined(SAFEPROCS) #error You must #define SAFEPROCS to build windmain.c #endif @@ -71,15 +64,6 @@ static struct stat hbuf; extern char orgdir[]; -boolean -is_desktop_bridge_application() -{ - UINT32 length = 0; - LONG rc = GetCurrentPackageFullName(&length, NULL); - - return (rc == ERROR_INSUFFICIENT_BUFFER); -} - void get_known_folder_path( const KNOWNFOLDERID * folder_id, diff --git a/sys/winnt/winnt.c b/sys/winnt/winnt.c index 37edbbcbf..967fa6e4e 100644 --- a/sys/winnt/winnt.c +++ b/sys/winnt/winnt.c @@ -11,6 +11,7 @@ * */ +#include "win10.h" #include "winos.h" #define NEED_VARARGS @@ -189,15 +190,20 @@ int *lan_username_size; { static TCHAR username_buffer[BUFSZ]; DWORD i = BUFSZ - 1; + BOOL allowUserName = TRUE; Strcpy(username_buffer, "NetHack"); +#ifndef WIN32CON /* Our privacy policy for the windows store version of nethack makes * a promise about not collecting any personally identifiable information. * Do not allow getting user name if we being run from windows store * version of nethack. In 3.7, we should remove use of username. */ - if (!is_desktop_bridge_application()) { + allowUserName = !win10_is_desktop_bridge_application(); +#endif + + if (allowUserName) { /* i gets updated with actual size */ if (GetUserName(username_buffer, &i)) username_buffer[i] = '\0'; diff --git a/win/win32/vs2017/common.props b/win/win32/vs2017/common.props index 8f5d2a450..ee802873c 100644 --- a/win/win32/vs2017/common.props +++ b/win/win32/vs2017/common.props @@ -9,7 +9,7 @@ Level3 - WIN32;CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;WINVER=0x0601;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions) Console