# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1303199707 0 # Node ID 3e393a9375c4b7a942d035275b00e3c2d1f83c17 # Parent 71b0e132d9df0d14edc6064aa668ee2637a91ad3 Implemented _dw_user_dir() using GetUserProfileDirectory() on Windows. GetUserProfileDirectory is in userenv.dll which is a file only included on NT-based Windows versions. Therefore Windows 95/98/ME are no longer supported by Dynamic Windows. diff -r 71b0e132d9df -r 3e393a9375c4 makefile.vc --- a/makefile.vc Tue Apr 19 05:54:01 2011 +0000 +++ b/makefile.vc Tue Apr 19 07:55:07 2011 +0000 @@ -48,7 +48,7 @@ CC = cl CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -DBUILD_DLL -I$(SRCDIR)\platform -I$(SRCDIR) -LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib ole32.lib oleaut32.lib +LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib ole32.lib oleaut32.lib userenv.lib RES = LINKFLAGS = -machine:$(TARGET_CPU) -manifest $(LINK_DEBUG) DLLLINKFLAGS = -dll diff -r 71b0e132d9df -r 3e393a9375c4 win/dw.c --- a/win/dw.c Tue Apr 19 05:54:01 2011 +0000 +++ b/win/dw.c Tue Apr 19 07:55:07 2011 +0000 @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -10145,19 +10146,27 @@ */ char * API dw_user_dir(void) { - static char _user_dir[1024] = ""; - - if(!_user_dir[0]) - { - /* Figure out how to do this the "Windows way" */ - char *home = getenv("HOME"); - - if(home) - strcpy(_user_dir, home); - else - strcpy(_user_dir, "C:\\"); - } - return _user_dir; + static char _user_dir[1024] = ""; + + if(!_user_dir[0]) + { + HANDLE hToken = 0; + + /* Use the Windows API to get the user's profile directory */ + if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) + { + DWORD BufSize = 1024; + + GetUserProfileDirectory(hToken, _user_dir, &BufSize); + CloseHandle(hToken); + } + /* If it fails set it to the root directory */ + if(!_user_dir[0]) + { + strcpy(_user_dir, "C:\\"); + } + } + return _user_dir; } /*