class WXDLLIMPEXP_FWD_BASE wxFFile;
#endif
+// this symbol is defined for the platforms where file systems use volumes in
+// paths
+#if defined(__WXMSW__) || defined(__DOS__) || defined(__OS2__)
+ #define wxHAS_FILESYSTEM_VOLUMES
+#endif
+
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// what exactly should GetPath() return?
enum
{
+ wxPATH_NO_SEPARATOR = 0x0000, // for symmetry with wxPATH_GET_SEPARATOR
wxPATH_GET_VOLUME = 0x0001, // include the volume if applicable
wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator
};
wxString *path,
wxPathFormat format = wxPATH_NATIVE);
- // Filesize
+#ifdef wxHAS_FILESYSTEM_VOLUMES
+ // return the string representing a file system volume, or drive
+ static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
+#endif // wxHAS_FILESYSTEM_VOLUMES
+
+ // File size
#if wxUSE_LONGLONG
// returns the size of the given filename
wxString GetName() const;
/**
- Returns the path part of the filename (without the name or extension). The
- possible flags values are:
+ Returns the path part of the filename (without the name or extension).
+
+ The possible flags values are:
@b wxPATH_GET_VOLUME
- Return the path with the volume (does nothing for the filename formats without
- volumes), otherwise the path without volume part is returned.
+ Return the path with the volume (does nothing for the filename formats
+ without volumes), otherwise the path without volume part is returned.
@b wxPATH_GET_SEPARATOR
- Return the path with the trailing separator, if this flag is not given there
- will be no separator at the end of the path.
+ Return the path with the trailing separator, if this flag is not given
+ there will be no separator at the end of the path.
+
+ @b wxPATH_NO_SEPARATOR
+
+ Don't include the trailing separator in the returned string. This is
+ the default (the value of this flag is 0) and exists only for symmetry
+ with wxPATH_GET_SEPARATOR.
*/
wxString GetPath(int flags = wxPATH_GET_VOLUME,
wxPathFormat format = wxPATH_NATIVE) const;
*/
static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE);
+ /**
+ This function builds a volume path string, for example "C:\\".
+
+ Implemented for the platforms which use drive letters, i.e. DOS, MSW
+ and OS/2 only.
+
+ @since 2.9.0
+
+ @param drive
+ The drive letter, 'A' through 'Z' or 'a' through 'z'.
+
+ @param flags
+ @c wxPATH_NO_SEPARATOR or @c wxPATH_GET_SEPARATOR to omit or include
+ the trailing path separator, the default is to include it.
+
+ @return Volume path string.
+ */
+ static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
+
/**
Returns @true if an extension is present.
*/
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
// ----------------------------------------------------------------------------
#include "wx/module.h"
#endif
+#include "wx/filename.h"
#include "wx/filefn.h"
#include "wx/imaglist.h"
#include "wx/tokenzr.h"
size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids)
{
-#if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
+#ifdef wxHAS_FILESYSTEM_VOLUMES
#ifdef __WXWINCE__
// No logical drives; return "\"
{
if (ulDriveMap & ( 1 << i ))
{
- wxString path, name;
- path.Printf(wxT("%c:\\"), 'A' + i);
- name.Printf(wxT("%c:"), 'A' + i);
+ const wxString path = wxFileName::GetVolumeString(
+ 'A' + i, wxPATH_GET_SEPARATOR);
+ const wxString name = wxFileName::GetVolumeString(
+ 'A' + i, wxPATH_NO_SEPARATOR);
// Note: If _filesys is unsupported by some compilers,
// we can always replace it by DosQueryFSAttach
}
}
#else // !__WIN32__, !__OS2__
- int drive;
-
/* If we can switch to the drive, it exists. */
- for( drive = 1; drive <= 26; drive++ )
+ for ( char drive = 'A'; drive <= 'Z'; drive++ )
{
- wxString path, name;
- path.Printf(wxT("%c:\\"), (char) (drive + 'a' - 1));
- name.Printf(wxT("%c:"), (char) (drive + 'A' - 1));
+ const wxString
+ path = wxFileName::GetVolumeString(drive, wxPATH_GET_SEPARATOR);
if (wxIsDriveAvailable(path))
{
paths.Add(path);
- names.Add(name);
- icon_ids.Add((drive <= 2) ? wxFileIconsTable::floppy : wxFileIconsTable::drive);
+ names.Add(wxFileName::GetVolumeString(drive, wxPATH_NO_SEPARATOR));
+ icon_ids.Add(drive <= 2 ? wxFileIconsTable::floppy
+ : wxFileIconsTable::drive);
}
}
#endif // __WIN32__/!__WIN32__