+#if wxUSE_PENWINDOWS && !defined(__WATCOMC__) && !defined(__GNUWIN32__)
+ extern HANDLE g_hPenWin; // PenWindows Running?
+ if (g_hPenWin)
+ {
+ // PenWindows Does have a user concept!
+ // Get the current owner of the recognizer
+ GetPrivateProfileString("Current", "User", default_name, wxBuffer, maxSize - 1, "PENWIN.INI");
+ strncpy(buf, wxBuffer, maxSize - 1);
+ }
+ else
+#endif
+ {
+#ifdef USE_NET_API
+ CHAR szUserName[256];
+ if ( !wxGetUserId(szUserName, WXSIZEOF(szUserName)) )
+ return FALSE;
+
+ // TODO how to get the domain name?
+ CHAR *szDomain = "";
+
+ // the code is based on the MSDN example (also see KB article Q119670)
+ WCHAR wszUserName[256]; // Unicode user name
+ WCHAR wszDomain[256];
+ LPBYTE ComputerName;
+
+ USER_INFO_2 *ui2; // User structure
+
+ // Convert ANSI user name and domain to Unicode
+ MultiByteToWideChar( CP_ACP, 0, szUserName, strlen(szUserName)+1,
+ wszUserName, WXSIZEOF(wszUserName) );
+ MultiByteToWideChar( CP_ACP, 0, szDomain, strlen(szDomain)+1,
+ wszDomain, WXSIZEOF(wszDomain) );
+
+ // Get the computer name of a DC for the domain.
+ if ( NetGetDCName( NULL, wszDomain, &ComputerName ) != NERR_Success )
+ {
+ wxLogError(wxT("Can not find domain controller"));
+
+ goto error;
+ }
+
+ // Look up the user on the DC
+ NET_API_STATUS status = NetUserGetInfo( (LPWSTR)ComputerName,
+ (LPWSTR)&wszUserName,
+ 2, // level - we want USER_INFO_2
+ (LPBYTE *) &ui2 );
+ switch ( status )
+ {
+ case NERR_Success:
+ // ok
+ break;
+
+ case NERR_InvalidComputer:
+ wxLogError(wxT("Invalid domain controller name."));
+
+ goto error;
+
+ case NERR_UserNotFound:
+ wxLogError(wxT("Invalid user name '%s'."), szUserName);
+
+ goto error;
+
+ default:
+ wxLogSysError(wxT("Can't get information about user"));
+
+ goto error;
+ }
+
+ // Convert the Unicode full name to ANSI
+ WideCharToMultiByte( CP_ACP, 0, ui2->usri2_full_name, -1,
+ buf, maxSize, NULL, NULL );
+
+ return TRUE;
+
+error:
+ wxLogError(wxT("Couldn't look up full user name."));
+
+ return FALSE;
+#else // !USE_NET_API
+ // Could use NIS, MS-Mail or other site specific programs
+ // Use wxWindows configuration data
+ bool ok = GetProfileString(WX_SECTION, eUSERNAME, wxT(""), buf, maxSize - 1) != 0;
+ if ( !ok )
+ {
+ ok = wxGetUserId(buf, maxSize);
+ }
+
+ if ( !ok )
+ {
+ wxStrncpy(buf, wxT("Unknown User"), maxSize);
+ }
+#endif // Win32/16
+ }
+
+ return TRUE;
+}
+
+const wxChar* wxGetHomeDir(wxString *pstr)
+{
+ wxString& strDir = *pstr;
+
+ #if defined(__UNIX__) && !defined(__TWIN32__)
+ const wxChar *szHome = wxGetenv("HOME");
+ if ( szHome == NULL ) {
+ // we're homeless...
+ wxLogWarning(_("can't find user's HOME, using current directory."));
+ strDir = wxT(".");
+ }
+ else
+ strDir = szHome;
+
+ // add a trailing slash if needed
+ if ( strDir.Last() != wxT('/') )
+ strDir << wxT('/');
+ #else // Windows
+ #ifdef __WIN32__
+ const wxChar *szHome = wxGetenv(wxT("HOMEDRIVE"));
+ if ( szHome != NULL )
+ strDir << szHome;
+ szHome = wxGetenv(wxT("HOMEPATH"));
+ if ( szHome != NULL ) {
+ strDir << szHome;
+
+ // the idea is that under NT these variables have default values
+ // of "%systemdrive%:" and "\\". As we don't want to create our
+ // config files in the root directory of the system drive, we will
+ // create it in our program's dir. However, if the user took care
+ // to set HOMEPATH to something other than "\\", we suppose that he
+ // knows what he is doing and use the supplied value.
+ if ( wxStrcmp(szHome, wxT("\\")) != 0 )
+ return strDir.c_str();
+ }
+
+ #else // Win16
+ // Win16 has no idea about home, so use the working directory instead
+ #endif // WIN16/32
+
+ // 260 was taken from windef.h
+ #ifndef MAX_PATH
+ #define MAX_PATH 260
+ #endif
+
+ wxString strPath;
+ ::GetModuleFileName(::GetModuleHandle(NULL),
+ strPath.GetWriteBuf(MAX_PATH), MAX_PATH);
+ strPath.UngetWriteBuf();
+
+ // extract the dir name
+ wxSplitPath(strPath, &strDir, NULL, NULL);
+
+ #endif // UNIX/Win
+
+ return strDir.c_str();
+}
+
+wxChar *wxGetUserHome(const wxString& WXUNUSED(user))
+{
+ // VZ: the old code here never worked for user != "" anyhow! Moreover, it
+ // returned sometimes a malloc()'d pointer, sometimes a pointer to a
+ // static buffer and sometimes I don't even know what.
+ static wxString s_home;
+
+ return (wxChar *)wxGetHomeDir(&s_home);
+}
+
+bool wxDirExists(const wxString& dir)
+{
+#if defined(__WIN32__)
+ DWORD attribs = GetFileAttributes(dir);
+ return ((attribs != (DWORD)-1) && (attribs & FILE_ATTRIBUTE_DIRECTORY));
+#else // Win16
+ #ifdef __BORLANDC__
+ struct ffblk fileInfo;
+ #else
+ struct find_t fileInfo;
+ #endif
+ // In Borland findfirst has a different argument
+ // ordering from _dos_findfirst. But _dos_findfirst
+ // _should_ be ok in both MS and Borland... why not?
+ #ifdef __BORLANDC__
+ return (findfirst(dir, &fileInfo, _A_SUBDIR) == 0 &&
+ (fileInfo.ff_attrib & _A_SUBDIR) != 0);
+ #else
+ return (_dos_findfirst(dir, _A_SUBDIR, &fileInfo) == 0) &&
+ ((fileInfo.attrib & _A_SUBDIR) != 0);
+ #endif
+#endif // Win32/16
+}
+
+// ----------------------------------------------------------------------------
+// env vars
+// ----------------------------------------------------------------------------
+
+bool wxGetEnv(const wxString& var, wxString *value)
+{
+ // first get the size of the buffer
+ DWORD dwRet = ::GetEnvironmentVariable(var, NULL, 0);
+ if ( !dwRet )
+ {
+ // this means that there is no such variable
+ return FALSE;
+ }
+
+ if ( value )
+ {
+ (void)::GetEnvironmentVariable(var, value->GetWriteBuf(dwRet), dwRet);
+ value->UngetWriteBuf();
+ }
+
+ return TRUE;
+}
+
+bool wxSetEnv(const wxString& var, const wxChar *value)
+{
+ // some compilers have putenv() or _putenv() or _wputenv() but it's better
+ // to always use Win32 function directly instead of dealing with them