-// ---------------------------------------------------------------------------
-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();
-}
-
-// Hack for MS-DOS
-wxChar *wxGetUserHome (const wxString& user)
-{
- wxChar *home;
- wxString user1(user);
-
- if (user1 != wxT("")) {
- wxChar tmp[64];
- if (wxGetUserId(tmp, sizeof(tmp)/sizeof(char))) {
- // Guests belong in the temp dir
- if (wxStricmp(tmp, wxT("annonymous")) == 0) {
- if ((home = wxGetenv(wxT("TMP"))) != NULL ||
- (home = wxGetenv(wxT("TMPDIR"))) != NULL ||
- (home = wxGetenv(wxT("TEMP"))) != NULL)
- return *home ? home : (wxChar*)wxT("\\");
- }
- if (wxStricmp(tmp, WXSTRINGCAST user1) == 0)
- user1 = wxT("");
- }
- }
- if (user1 == wxT(""))
- if ((home = wxGetenv(wxT("HOME"))) != NULL)
- {
- wxStrcpy(wxBuffer, home);
- Unix2DosFilename(wxBuffer);
- return wxBuffer;
- }
- return NULL; // No home known!
-}
-