+ 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();