]> git.saurik.com Git - wxWidgets.git/commitdiff
Added GetTempDir
authorJulian Smart <julian@anthemion.co.uk>
Mon, 23 Oct 2006 17:47:02 +0000 (17:47 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Mon, 23 Oct 2006 17:47:02 +0000 (17:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42290 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/filename.tex
include/wx/filename.h
src/common/filename.cpp

index ba2c91213b8822826455f18223809e687e45d9f2..b7c8e658f0774196d6d34b2516f39a288f8823b5 100644 (file)
@@ -556,6 +556,13 @@ In case of success, the returned string is a floating-point number with {\tt pre
 followed by the size unit (B, kB, MB, GB, TB: respectively bytes, kilobytes, megabytes, gigabytes, terabytes).
 
 
+\membersection{wxFileName::GetTempDir}\label{wxfilenamegettempdir}
+
+\func{static wxString}{GetTempDir}{\void}
+
+Returns the directory used for temporary files.
+
+
 \membersection{wxFileName::GetTimes}\label{wxfilenamegettimes}
 
 \constfunc{bool}{GetTimes}{\param{wxDateTime* }{dtAccess}, \param{wxDateTime* }{dtMod}, \param{wxDateTime* }{dtCreate}}
index 762237b5ae93f92ee8c89ce5a6fa16cee7183835..f78164d73e8d80d38f623ac9f09af8febaa16e18 100644 (file)
@@ -270,6 +270,9 @@ public:
     void AssignHomeDir();
     static wxString GetHomeDir();
 
+        // get the system temporary directory
+    static wxString GetTempDir();
+
 #if wxUSE_FILE || wxUSE_FFILE
         // get a temp file name starting with the specified prefix
     void AssignTempFileName(const wxString& prefix);
index c6e42ca2329dc86dc92bb2c67cb2c81505684bbf..98af00ab43c0631cb18ae03c9a0c8652fd3008d9 100644 (file)
@@ -697,24 +697,10 @@ static wxString wxCreateTempImpl(
 
     if (dir.empty())
     {
-        dir = wxGetenv(_T("TMPDIR"));
-        if (dir.empty())
-        {
-            dir = wxGetenv(_T("TMP"));
-            if (dir.empty())
-            {
-                dir = wxGetenv(_T("TEMP"));
-            }
-        }
+        dir = wxFileName::GetTempDir();
     }
 
 #if defined(__WXWINCE__)
-    if (dir.empty())
-    {
-        // FIXME. Create \temp dir?
-        if (wxFileName::DirExists(wxT("\\temp")))
-            dir = wxT("\\temp");
-    }
     path = dir + wxT("\\") + name;
     int i = 1;
     while (wxFileName::FileExists(path))
@@ -725,27 +711,6 @@ static wxString wxCreateTempImpl(
     }
 
 #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
-
-    if ( dir.empty() )
-    {
-        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('.');
-        }
-    }
-    else // we have a dir to create the file in
-    {
-        // ensure we use only the back slashes as GetTempFileName(), unlike all
-        // the other APIs, is picky and doesn't accept the forward ones
-        dir.Replace(_T("/"), _T("\\"));
-    }
-
     if ( !::GetTempFileName(dir, name, 0, wxStringBuffer(path, MAX_PATH + 1)) )
     {
         wxLogLastError(_T("GetTempFileName"));
@@ -754,18 +719,6 @@ static wxString wxCreateTempImpl(
     }
 
 #else // !Windows
-    if ( dir.empty() )
-    {
-        // default
-#if defined(__DOS__) || defined(__OS2__)
-        dir = _T(".");
-#elif defined(__WXMAC__)
-        dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder);
-#else
-        dir = _T("/tmp");
-#endif
-    }
-
     path = dir;
 
     if ( !wxEndsWithPathSeparator(dir) &&
@@ -1036,6 +989,59 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFFile *fileTemp)
 // directory operations
 // ----------------------------------------------------------------------------
 
+wxString wxFileName::GetTempDir()
+{
+    wxString dir;
+    dir = wxGetenv(_T("TMPDIR"));
+    if (dir.empty())
+    {
+        dir = wxGetenv(_T("TMP"));
+        if (dir.empty())
+        {
+            dir = wxGetenv(_T("TEMP"));
+        }
+    }
+
+#if defined(__WXWINCE__)
+    if (dir.empty())
+    {
+        // FIXME. Create \temp dir?
+        if (DirExists(wxT("\\temp")))
+            dir = wxT("\\temp");
+    }
+#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
+
+    if ( dir.empty() )
+    {
+        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('.');
+        }
+    }
+#else // !Windows
+
+    if ( dir.empty() )
+    {
+        // default
+#if defined(__DOS__) || defined(__OS2__)
+        dir = _T(".");
+#elif defined(__WXMAC__)
+        dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder);
+#else
+        dir = _T("/tmp");
+#endif
+    }
+#endif
+
+    return dir;
+}
+
 bool wxFileName::Mkdir( int perm, int flags )
 {
     return wxFileName::Mkdir(GetPath(), perm, flags);