Added GetTempDir

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42290 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2006-10-23 17:47:02 +00:00
parent 8ddf534ad5
commit 8d7d6deac6
3 changed files with 64 additions and 48 deletions

View 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}}

View 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);

View 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);