+ wxString& strDir = *home;
+
+ strDir.clear();
+
+ // try HOMEDRIVE/PATH
+ 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 )
+ strDir.clear();
+ }
+
+ if ( strDir.empty() )
+ {
+ // If we have a valid USERPROFILE directory, as is the case in
+ // Windows NT, 2000 and XP, we should use that as our home directory.
+ szHome = wxGetenv(wxT("USERPROFILE"));
+
+ if ( szHome != NULL )
+ strDir = szHome;
+ }
+
+ if ( strDir.empty() )
+ {
+ // If we have a valid HOME directory, as is used on many machines
+ // that have unix utilities on them, we should use that.
+ szHome = wxGetenv(wxT("HOME"));
+
+ if ( szHome != NULL )
+ {
+ strDir = szHome;
+ // when msys sets %HOME% it uses '/' (cygwin uses '\\')
+ strDir.Replace(_T("/"), _T("\\"));
+ }
+ }
+
+ if ( !strDir.empty() )
+ {
+ // sometimes the value of HOME may be "%USERPROFILE%", so reexpand the
+ // value once again, it shouldn't hurt anyhow
+ strDir = wxExpandEnvVars(strDir);
+ }
+ else // fall back to the program directory
+ {
+ if ( wxTheApp )
+ {
+ wxString prog(wxTheApp->argv[0]);
+#ifdef __DJGPP__
+ // djgpp startup code switches the slashes around, so restore them
+ prog.Replace(_T("/"), _T("\\"));
+#endif
+ // it needs to be a full path to be usable
+ if ( prog.compare(1, 2, _T(":\\")) == 0 )
+ wxSplitPath(prog, &strDir, NULL, NULL);
+ }
+ if ( strDir.empty() )
+ {
+ strDir = _T(".");
+ }
+ }
+
+ return strDir.c_str();
+}
+
+wxChar *wxGetUserHome(const wxString& user)
+{
+ static wxString home;
+
+ if (user.empty() || user == wxGetUserId())
+ return wx_const_cast(wxChar*, wxGetHomeDir(&home));
+ else
+ return _T("");
+}
+
+// returns %UserName%, $USER or just "user"
+//
+bool wxGetUserId(wxChar *buf, int n)
+{
+ const wxChar *user = wxGetenv(_T("UserName"));
+
+ if (!user)
+ user = wxGetenv(_T("USER"));
+
+ if (!user)
+ user = _T("user");
+
+ wxStrncpy(buf, user, n);
+ return true;
+}
+
+bool wxGetUserName(wxChar *buf, int n)
+{
+ return wxGetUserId(buf, n);
+}
+
+// returns %ComputerName%, or $HOSTNAME, or "host"
+//
+bool wxGetHostName(wxChar *buf, int n)
+{
+ const wxChar *host = wxGetenv(_T("ComputerName"));
+
+ if (!host)
+ host = wxGetenv(_T("HOSTNAME"));
+
+ if (!host)
+ host = _T("host");
+
+ wxStrncpy(buf, host, n);
+ return true;
+}
+
+// adds %UserDnsDomain% to wxGetHostName()
+//
+bool wxGetFullHostName(wxChar *buf, int n)
+{
+ wxGetHostName(buf, n);
+
+ const wxChar *domain = wxGetenv(_T("UserDnsDomain"));
+
+ if (domain)
+ wxStrncat(wxStrncat(buf, _T("."), n), domain, n);
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+// Processes
+//----------------------------------------------------------------------------
+
+unsigned long wxGetProcessId()
+{
+ return (unsigned long)getpid();