X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c933e267beed72a1c535c8d30ac930fc80587add..03af437f7586bba182c76ff73e058f8c16fd8e2b:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index d781b78685..1e3444bc87 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1026,55 +1026,55 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFFile *fileTemp) // directory operations // ---------------------------------------------------------------------------- +// helper of GetTempDir(): check if the given directory exists and return it if +// it does or an empty string otherwise +namespace +{ + +wxString CheckIfDirExists(const wxString& dir) +{ + return wxFileName::DirExists(dir) ? dir : wxString(); +} + +} // anonymous namespace + wxString wxFileName::GetTempDir() { - wxString dir; - dir = wxGetenv(_T("TMPDIR")); - if (dir.empty()) + // first try getting it from environment: this allows overriding the values + // used by default if the user wants to create temporary files in another + // directory + wxString dir = CheckIfDirExists(wxGetenv("TMPDIR")); + if ( dir.empty() ) { - dir = wxGetenv(_T("TMP")); - if (dir.empty()) - { - dir = wxGetenv(_T("TEMP")); - } + dir = CheckIfDirExists(wxGetenv("TMP")); + if ( dir.empty() ) + dir = CheckIfDirExists(wxGetenv("TEMP")); } -#if defined(__WXWINCE__) - if (dir.empty()) - { - // FIXME. Create \temp dir? - if (DirExists(wxT("\\temp"))) - dir = wxT("\\temp"); - } -#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) - + // if no environment variables are set, use the system default if ( dir.empty() ) { +#if defined(__WXWINCE__) + dir = CheckIfDirExists(wxT("\\temp")); +#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) if ( !::GetTempPath(MAX_PATH, wxStringBuffer(dir, MAX_PATH + 1)) ) { wxLogLastError(_T("GetTempPath")); } - - if ( dir.empty() ) - { - // GetTempFileName() fails if we pass it an empty string - dir = _T('.'); - } +#elif defined(__WXMAC__) && wxOSX_USE_CARBON + dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder); +#endif // systems with native way } -#else // !Windows + // fall back to hard coded value if ( dir.empty() ) { - // default -#if defined(__DOS__) || defined(__OS2__) - dir = _T("."); -#elif defined(__WXMAC__) && !defined(__WXOSX_IPHONE__) - dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder); -#else - dir = _T("/tmp"); -#endif +#ifdef __UNIX_LIKE__ + dir = CheckIfDirExists("/tmp"); + if ( dir.empty() ) +#endif // __UNIX_LIKE__ + dir = "."; } -#endif return dir; } @@ -2383,7 +2383,7 @@ wxString wxFileName::GetHumanReadableSize(const wxString &failmsg, int precision // Mac-specific functions // ---------------------------------------------------------------------------- -#if defined( __WXMAC__ ) && !defined( __WXOSX_IPHONE__ ) +#if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON const short kMacExtensionMaxLength = 16 ; class MacDefaultExtensionRecord