#endif
#if defined(__WXMAC__)
- #include "wx/mac/private.h" // includes mac headers
+ #include "wx/osx/private.h" // includes mac headers
#endif
// utime() is POSIX so should normally be available on all Unices
// directory operations
// ----------------------------------------------------------------------------
-wxString wxFileName::GetTempDir()
+// helper of GetTempDir(): check if the given directory exists and return it if
+// it does or an empty string otherwise
+namespace
{
- 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())
+wxString CheckIfDirExists(const wxString& dir)
+{
+ return wxFileName::DirExists(dir) ? dir : wxString();
+}
+
+} // anonymous namespace
+
+wxString wxFileName::GetTempDir()
+{
+ // 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() )
{
- // FIXME. Create \temp dir?
- if (DirExists(wxT("\\temp")))
- dir = wxT("\\temp");
+ dir = CheckIfDirExists(wxGetenv("TMP"));
+ if ( dir.empty() )
+ dir = CheckIfDirExists(wxGetenv("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__)
- 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;
}
size_t count = dirs.GetCount();
for ( size_t i = 0; i < count; i++ )
{
- if ( i > 0 ||
-#if defined(__WXMAC__) && !defined(__DARWIN__)
- // relative pathnames are exactely the other way round under mac...
- !filename.IsAbsolute()
-#else
- filename.IsAbsolute()
-#endif
- )
+ if ( i > 0 || filename.IsAbsolute() )
currPath += wxFILE_SEP_PATH;
currPath += dirs[i];
}
}
- if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
- {
- dir.MakeLower();
- }
-
m_dirs.Add(dir);
}
wxString filename;
if (GetShortcutTarget(GetFullPath(format), filename))
{
- // Repeat this since we may now have a new path
- if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
- {
- filename.MakeLower();
- }
m_relative = false;
Assign(filename);
}
}
#endif
- if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
+#if defined(__WIN32__)
+ if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) )
{
- // VZ: expand env vars here too?
+ Assign(GetLongPath());
+ }
+#endif // Win32
+ // Change case (this should be kept at the end of the function, to ensure
+ // that the path doesn't change any more after we normalize its case)
+ if ( (flags & wxPATH_NORM_CASE) && !IsCaseSensitive(format) )
+ {
m_volume.MakeLower();
m_name.MakeLower();
m_ext.MakeLower();
- }
-#if defined(__WIN32__)
- if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) )
- {
- Assign(GetLongPath());
+ // directory entries must be made lower case as well
+ count = m_dirs.GetCount();
+ for ( size_t i = 0; i < count; i++ )
+ {
+ m_dirs[i].MakeLower();
+ }
}
-#endif // Win32
return true;
}
#if defined(__WIN32__) && !defined(__WXWINCE__) && !defined(__WXMICROWIN__)
-#if wxUSE_DYNAMIC_LOADER
+#if wxUSE_DYNLIB_CLASS
typedef DWORD (WINAPI *GET_LONG_PATH_NAME)(const wxChar *, wxChar *, DWORD);
// this is MT-safe as in the worst case we're going to resolve the function
}
}
}
-#endif // wxUSE_DYNAMIC_LOADER
+#endif // wxUSE_DYNLIB_CLASS
// The OS didn't support GetLongPathName, or some other error.
// We need to call FindFirstFile on each component in turn.
size_t count = dirs.GetCount();
for ( size_t i = 0; i < count; i++ )
{
+ const wxString& dir = dirs[i];
+
// We're using pathOut to collect the long-name path, but using a
// temporary for appending the last path component which may be
// short-name
- tmpPath = pathOut + dirs[i];
-
- if ( tmpPath.empty() )
- continue;
-
- // can't see this being necessary? MF
- if ( tmpPath.Last() == GetVolumeSeparator(wxPATH_DOS) )
+ tmpPath = pathOut + dir;
+
+ // We must not process "." or ".." here as they would be (unexpectedly)
+ // replaced by the corresponding directory names so just leave them
+ // alone
+ //
+ // And we can't pass a drive and root dir to FindFirstFile (VZ: why?)
+ if ( tmpPath.empty() || dir == '.' || dir == ".." ||
+ tmpPath.Last() == GetVolumeSeparator(wxPATH_DOS) )
{
- // Can't pass a drive and root dir to FindFirstFile,
- // so continue to next dir
tmpPath += wxFILE_SEP_PATH;
pathOut = tmpPath;
continue;
{
#if defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__)
format = wxPATH_DOS;
-#elif defined(__WXMAC__) && !defined(__DARWIN__)
- format = wxPATH_MAC;
#elif defined(__VMS)
format = wxPATH_VMS;
#else
return format;
}
+#ifdef wxHAS_FILESYSTEM_VOLUMES
+
+/* static */
+wxString wxFileName::GetVolumeString(char drive, int flags)
+{
+ wxASSERT_MSG( !(flags & ~wxPATH_GET_SEPARATOR), "invalid flag specified" );
+
+ wxString vol(drive);
+ vol += wxFILE_SEP_DSK;
+ if ( flags & wxPATH_GET_SEPARATOR )
+ vol += wxFILE_SEP_PATH;
+
+ return vol;
+}
+
+#endif // wxHAS_FILESYSTEM_VOLUMES
+
// ----------------------------------------------------------------------------
// path splitting function
// ----------------------------------------------------------------------------
// not 9x
bool ok;
FILETIME ftAccess, ftCreate, ftWrite;
- if ( IsDir() )
+ if ( IsDir() )
{
// implemented in msw/dir.cpp
extern bool wxGetDirectoryTimes(const wxString& dirname,
// Mac-specific functions
// ----------------------------------------------------------------------------
-#ifdef __WXMAC__
+#if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON
const short kMacExtensionMaxLength = 16 ;
class MacDefaultExtensionRecord