diff --git a/include/extern.h b/include/extern.h index 4a947adfa..dfde30e53 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1825,7 +1825,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 b8023bb1e..0650a8af8 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 @@ -70,15 +63,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 4f1d29dea..af1944678 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