+ 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(wxT("/"), wxT("\\"));
+ }
+ }
+
+ 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(wxT("/"), wxT("\\"));
+#endif
+ // it needs to be a full path to be usable
+ if ( prog.compare(1, 2, wxT(":\\")) == 0 )
+ wxFileName::SplitPath(prog, &strDir, NULL, NULL);
+ }
+ if ( strDir.empty() )
+ {
+ strDir = wxT(".");
+ }
+ }
+
+ return strDir.c_str();
+}
+
+wxString wxGetUserHome(const wxString& user)
+{
+ wxString home;
+
+ if (user.empty() || user == wxGetUserId())
+ wxGetHomeDir(&home);
+
+ return home;
+}
+
+// returns %UserName%, $USER or just "user"
+//
+bool wxGetUserId(wxChar *buf, int n)
+{
+ const wxChar *user = wxGetenv(wxT("UserName"));
+
+ if (!user)
+ user = wxGetenv(wxT("USER"));
+
+ if (!user)
+ user = wxT("user");
+
+ wxStrlcpy(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(wxT("ComputerName"));
+
+ if (!host)
+ host = wxGetenv(wxT("HOSTNAME"));
+
+ if (!host)
+ host = wxT("host");
+
+ wxStrlcpy(buf, host, n);
+ return true;
+}
+
+// adds %UserDnsDomain% to wxGetHostName()
+//
+bool wxGetFullHostName(wxChar *buf, int n)
+{
+ wxGetHostName(buf, n);
+
+ const wxChar *domain = wxGetenv(wxT("UserDnsDomain"));
+
+ if (domain)
+ wxStrncat(wxStrncat(buf, wxT("."), n), domain, n);
+
+ return true;