+ wxString dir = dirs[0u];
+ if ( !dir.empty() && dir[0u] == wxT('~') )
+ {
+ // to make the path absolute use the home directory
+ curDir.AssignDir(wxGetUserHome(dir.c_str() + 1));
+ dirs.RemoveAt(0u);
+ }
+ }
+ }
+
+ // transform relative path into abs one
+ if ( curDir.IsOk() )
+ {
+ // this path may be relative because it doesn't have the volume name
+ // and still have m_relative=true; in this case we shouldn't modify
+ // our directory components but just set the current volume
+ if ( !HasVolume() && curDir.HasVolume() )
+ {
+ SetVolume(curDir.GetVolume());
+
+ if ( !m_relative )
+ {
+ // yes, it was the case - we don't need curDir then
+ curDir.Clear();
+ }
+ }
+
+ // finally, prepend curDir to the dirs array
+ wxArrayString dirsNew = curDir.GetDirs();
+ WX_PREPEND_ARRAY(dirs, dirsNew);
+
+ // if we used e.g. tilde expansion previously and wxGetUserHome didn't
+ // return for some reason an absolute path, then curDir maybe not be absolute!
+ if ( !curDir.m_relative )
+ {
+ // we have prepended an absolute path and thus we are now an absolute
+ // file name too
+ m_relative = false;
+ }
+ // else if (flags & wxPATH_NORM_ABSOLUTE):
+ // should we warn the user that we didn't manage to make the path absolute?
+ }
+
+ // now deal with ".", ".." and the rest
+ m_dirs.Empty();
+ size_t count = dirs.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxString dir = dirs[n];
+
+ if ( flags & wxPATH_NORM_DOTS )
+ {
+ if ( dir == wxT(".") )
+ {
+ // just ignore
+ continue;
+ }
+
+ if ( dir == wxT("..") )
+ {
+ if ( m_dirs.IsEmpty() )
+ {
+ wxLogError(_("The path '%s' contains too many \"..\"!"),
+ GetFullPath().c_str());
+ return false;
+ }
+
+ m_dirs.RemoveAt(m_dirs.GetCount() - 1);
+ continue;
+ }
+ }
+
+ m_dirs.Add(dir);
+ }
+
+#if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE
+ if ( (flags & wxPATH_NORM_SHORTCUT) )
+ {
+ wxString filename;
+ if (GetShortcutTarget(GetFullPath(format), filename))
+ {
+ m_relative = false;
+ Assign(filename);
+ }
+ }
+#endif
+
+#if defined(__WIN32__)
+ if ( (flags & wxPATH_NORM_LONG) && (format == wxPATH_DOS) )
+ {
+ 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();
+
+ // 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();
+ }
+ }
+
+ return true;
+}
+
+#ifndef __WXWINCE__
+bool wxFileName::ReplaceEnvVariable(const wxString& envname,
+ const wxString& replacementFmtString,
+ wxPathFormat format)
+{
+ // look into stringForm for the contents of the given environment variable
+ wxString val;
+ if (envname.empty() ||
+ !wxGetEnv(envname, &val))
+ return false;
+ if (val.empty())
+ return false;
+
+ wxString stringForm = GetPath(wxPATH_GET_VOLUME, format);
+ // do not touch the file name and the extension
+
+ wxString replacement = wxString::Format(replacementFmtString, envname);
+ stringForm.Replace(val, replacement);
+
+ // Now assign ourselves the modified path:
+ Assign(stringForm, GetFullName(), format);
+
+ return true;
+}
+#endif
+
+bool wxFileName::ReplaceHomeDir(wxPathFormat format)
+{
+ wxString homedir = wxGetHomeDir();
+ if (homedir.empty())
+ return false;
+
+ wxString stringForm = GetPath(wxPATH_GET_VOLUME, format);
+ // do not touch the file name and the extension
+
+ stringForm.Replace(homedir, "~");
+
+ // Now assign ourselves the modified path:
+ Assign(stringForm, GetFullName(), format);
+
+ return true;
+}
+
+// ----------------------------------------------------------------------------
+// get the shortcut target
+// ----------------------------------------------------------------------------
+
+// WinCE (3) doesn't have CLSID_ShellLink, IID_IShellLink definitions.
+// The .lnk file is a plain text file so it should be easy to
+// make it work. Hint from Google Groups:
+// "If you open up a lnk file, you'll see a
+// number, followed by a pound sign (#), followed by more text. The
+// number is the number of characters that follows the pound sign. The
+// characters after the pound sign are the command line (which _can_
+// include arguments) to be executed. Any path (e.g. \windows\program
+// files\myapp.exe) that includes spaces needs to be enclosed in
+// quotation marks."
+
+#if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE
+// The following lines are necessary under WinCE
+// #include "wx/msw/private.h"
+// #include <ole2.h>
+#include <shlobj.h>
+#if defined(__WXWINCE__)
+#include <shlguid.h>
+#endif
+
+bool wxFileName::GetShortcutTarget(const wxString& shortcutPath,
+ wxString& targetFilename,
+ wxString* arguments) const
+{
+ wxString path, file, ext;
+ wxFileName::SplitPath(shortcutPath, & path, & file, & ext);
+
+ HRESULT hres;
+ IShellLink* psl;
+ bool success = false;
+
+ // Assume it's not a shortcut if it doesn't end with lnk
+ if (ext.CmpNoCase(wxT("lnk"))!=0)
+ return false;
+
+ // create a ShellLink object
+ hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+ IID_IShellLink, (LPVOID*) &psl);
+
+ if (SUCCEEDED(hres))
+ {
+ IPersistFile* ppf;
+ hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
+ if (SUCCEEDED(hres))
+ {
+ WCHAR wsz[MAX_PATH];
+
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, shortcutPath.mb_str(), -1, wsz,
+ MAX_PATH);
+
+ hres = ppf->Load(wsz, 0);
+ ppf->Release();
+
+ if (SUCCEEDED(hres))
+ {
+ wxChar buf[2048];
+ // Wrong prototype in early versions
+#if defined(__MINGW32__) && !wxCHECK_W32API_VERSION(2, 2)
+ psl->GetPath((CHAR*) buf, 2048, NULL, SLGP_UNCPRIORITY);
+#else
+ psl->GetPath(buf, 2048, NULL, SLGP_UNCPRIORITY);
+#endif
+ targetFilename = wxString(buf);
+ success = (shortcutPath != targetFilename);
+
+ psl->GetArguments(buf, 2048);
+ wxString args(buf);
+ if (!args.empty() && arguments)
+ {
+ *arguments = args;
+ }
+ }
+ }
+
+ psl->Release();
+ }
+ return success;
+}
+
+#endif // __WIN32__ && !__WXWINCE__
+
+
+// ----------------------------------------------------------------------------
+// absolute/relative paths
+// ----------------------------------------------------------------------------
+
+bool wxFileName::IsAbsolute(wxPathFormat format) const
+{
+ // unix paths beginning with ~ are reported as being absolute
+ if ( format == wxPATH_UNIX )
+ {
+ if ( !m_dirs.IsEmpty() )
+ {
+ wxString dir = m_dirs[0u];
+
+ if (!dir.empty() && dir[0u] == wxT('~'))
+ return true;
+ }
+ }
+
+ // if our path doesn't start with a path separator, it's not an absolute
+ // path
+ if ( m_relative )
+ return false;
+
+ if ( !GetVolumeSeparator(format).empty() )
+ {
+ // this format has volumes and an absolute path must have one, it's not
+ // enough to have the full path to be an absolute file under Windows
+ if ( GetVolume().empty() )
+ return false;
+ }
+
+ return true;
+}
+
+bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format)
+{
+ wxFileName fnBase = wxFileName::DirName(pathBase, format);
+
+ // get cwd only once - small time saving
+ wxString cwd = wxGetCwd();
+ Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
+ fnBase.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, cwd, format);
+
+ bool withCase = IsCaseSensitive(format);
+
+ // we can't do anything if the files live on different volumes
+ if ( !GetVolume().IsSameAs(fnBase.GetVolume(), withCase) )
+ {
+ // nothing done
+ return false;
+ }
+
+ // same drive, so we don't need our volume
+ m_volume.clear();
+
+ // remove common directories starting at the top
+ while ( !m_dirs.IsEmpty() && !fnBase.m_dirs.IsEmpty() &&
+ m_dirs[0u].IsSameAs(fnBase.m_dirs[0u], withCase) )
+ {
+ m_dirs.RemoveAt(0);
+ fnBase.m_dirs.RemoveAt(0);
+ }
+
+ // add as many ".." as needed
+ size_t count = fnBase.m_dirs.GetCount();
+ for ( size_t i = 0; i < count; i++ )
+ {
+ m_dirs.Insert(wxT(".."), 0u);
+ }
+
+ if ( format == wxPATH_UNIX || format == wxPATH_DOS )
+ {
+ // a directory made relative with respect to itself is '.' under Unix
+ // and DOS, by definition (but we don't have to insert "./" for the
+ // files)
+ if ( m_dirs.IsEmpty() && IsDir() )
+ {
+ m_dirs.Add(wxT('.'));
+ }
+ }
+
+ m_relative = true;
+
+ // we were modified
+ return true;
+}
+
+// ----------------------------------------------------------------------------
+// filename kind tests
+// ----------------------------------------------------------------------------
+
+bool wxFileName::SameAs(const wxFileName& filepath, wxPathFormat format) const
+{
+ wxFileName fn1 = *this,
+ fn2 = filepath;
+
+ // get cwd only once - small time saving
+ wxString cwd = wxGetCwd();
+ fn1.Normalize(wxPATH_NORM_ALL | wxPATH_NORM_CASE, cwd, format);
+ fn2.Normalize(wxPATH_NORM_ALL | wxPATH_NORM_CASE, cwd, format);
+
+ if ( fn1.GetFullPath() == fn2.GetFullPath() )
+ return true;
+
+ // TODO: compare inodes for Unix, this works even when filenames are
+ // different but files are the same (symlinks) (VZ)
+
+ return false;
+}
+
+/* static */
+bool wxFileName::IsCaseSensitive( wxPathFormat format )
+{
+ // only Unix filenames are truely case-sensitive
+ return GetFormat(format) == wxPATH_UNIX;
+}
+
+/* static */
+wxString wxFileName::GetForbiddenChars(wxPathFormat format)
+{
+ // Inits to forbidden characters that are common to (almost) all platforms.
+ wxString strForbiddenChars = wxT("*?");
+
+ // If asserts, wxPathFormat has been changed. In case of a new path format
+ // addition, the following code might have to be updated.
+ wxCOMPILE_TIME_ASSERT(wxPATH_MAX == 5, wxPathFormatChanged);
+ switch ( GetFormat(format) )
+ {
+ default :
+ wxFAIL_MSG( wxT("Unknown path format") );
+ // !! Fall through !!
+
+ case wxPATH_UNIX:
+ break;
+
+ case wxPATH_MAC:
+ // On a Mac even names with * and ? are allowed (Tested with OS
+ // 9.2.1 and OS X 10.2.5)
+ strForbiddenChars = wxEmptyString;
+ break;
+
+ case wxPATH_DOS:
+ strForbiddenChars += wxT("\\/:\"<>|");
+ break;
+
+ case wxPATH_VMS:
+ break;
+ }
+
+ return strForbiddenChars;
+}
+
+/* static */
+wxString wxFileName::GetVolumeSeparator(wxPathFormat WXUNUSED_IN_WINCE(format))
+{
+#ifdef __WXWINCE__
+ return wxEmptyString;
+#else
+ wxString sepVol;
+
+ if ( (GetFormat(format) == wxPATH_DOS) ||
+ (GetFormat(format) == wxPATH_VMS) )
+ {
+ sepVol = wxFILE_SEP_DSK;
+ }
+ //else: leave empty
+
+ return sepVol;
+#endif
+}
+
+/* static */
+wxString wxFileName::GetPathSeparators(wxPathFormat format)
+{
+ wxString seps;
+ switch ( GetFormat(format) )
+ {
+ case wxPATH_DOS:
+ // accept both as native APIs do but put the native one first as
+ // this is the one we use in GetFullPath()
+ seps << wxFILE_SEP_PATH_DOS << wxFILE_SEP_PATH_UNIX;
+ break;
+
+ default:
+ wxFAIL_MSG( wxT("Unknown wxPATH_XXX style") );
+ // fall through
+
+ case wxPATH_UNIX:
+ seps = wxFILE_SEP_PATH_UNIX;
+ break;
+
+ case wxPATH_MAC:
+ seps = wxFILE_SEP_PATH_MAC;
+ break;
+
+ case wxPATH_VMS:
+ seps = wxFILE_SEP_PATH_VMS;
+ break;
+ }
+
+ return seps;
+}
+
+/* static */
+wxString wxFileName::GetPathTerminators(wxPathFormat format)
+{
+ format = GetFormat(format);
+
+ // under VMS the end of the path is ']', not the path separator used to
+ // separate the components
+ return format == wxPATH_VMS ? wxString(wxT(']')) : GetPathSeparators(format);
+}
+
+/* static */
+bool wxFileName::IsPathSeparator(wxChar ch, wxPathFormat format)
+{
+ // wxString::Find() doesn't work as expected with NUL - it will always find
+ // it, so test for it separately
+ return ch != wxT('\0') && GetPathSeparators(format).Find(ch) != wxNOT_FOUND;
+}
+
+/* static */
+bool
+wxFileName::IsMSWUniqueVolumeNamePath(const wxString& path, wxPathFormat format)
+{
+ // return true if the format used is the DOS/Windows one and the string begins
+ // with a Windows unique volume name ("\\?\Volume{guid}\")
+ return format == wxPATH_DOS &&
+ path.length() >= wxMSWUniqueVolumePrefixLength &&
+ path.StartsWith(wxS("\\\\?\\Volume{")) &&
+ path[wxMSWUniqueVolumePrefixLength - 1] == wxFILE_SEP_PATH_DOS;
+}
+
+// ----------------------------------------------------------------------------
+// path components manipulation
+// ----------------------------------------------------------------------------
+
+/* static */ bool wxFileName::IsValidDirComponent(const wxString& dir)
+{
+ if ( dir.empty() )
+ {
+ wxFAIL_MSG( wxT("empty directory passed to wxFileName::InsertDir()") );
+
+ return false;
+ }
+
+ const size_t len = dir.length();
+ for ( size_t n = 0; n < len; n++ )
+ {
+ if ( dir[n] == GetVolumeSeparator() || IsPathSeparator(dir[n]) )
+ {
+ wxFAIL_MSG( wxT("invalid directory component in wxFileName") );
+
+ return false;
+ }
+ }
+
+ return true;
+}
+
+void wxFileName::AppendDir( const wxString& dir )
+{
+ if ( IsValidDirComponent(dir) )
+ m_dirs.Add( dir );
+}
+
+void wxFileName::PrependDir( const wxString& dir )
+{
+ InsertDir(0, dir);
+}
+
+void wxFileName::InsertDir(size_t before, const wxString& dir)
+{
+ if ( IsValidDirComponent(dir) )
+ m_dirs.Insert(dir, before);
+}
+
+void wxFileName::RemoveDir(size_t pos)
+{
+ m_dirs.RemoveAt(pos);
+}
+
+// ----------------------------------------------------------------------------
+// accessors
+// ----------------------------------------------------------------------------
+
+void wxFileName::SetFullName(const wxString& fullname)
+{
+ SplitPath(fullname, NULL /* no volume */, NULL /* no path */,
+ &m_name, &m_ext, &m_hasExt);
+}
+
+wxString wxFileName::GetFullName() const
+{
+ wxString fullname = m_name;
+ if ( m_hasExt )
+ {
+ fullname << wxFILE_SEP_EXT << m_ext;
+ }
+
+ return fullname;
+}
+
+wxString wxFileName::GetPath( int flags, wxPathFormat format ) const
+{
+ format = GetFormat( format );
+
+ wxString fullpath;
+
+ // return the volume with the path as well if requested
+ if ( flags & wxPATH_GET_VOLUME )
+ {
+ fullpath += wxGetVolumeString(GetVolume(), format);
+ }
+
+ // the leading character
+ switch ( format )
+ {
+ case wxPATH_MAC:
+ if ( m_relative )
+ fullpath += wxFILE_SEP_PATH_MAC;
+ break;
+
+ case wxPATH_DOS:
+ if ( !m_relative )
+ fullpath += wxFILE_SEP_PATH_DOS;
+ break;
+
+ default:
+ wxFAIL_MSG( wxT("Unknown path format") );
+ // fall through
+
+ case wxPATH_UNIX:
+ if ( !m_relative )
+ {
+ fullpath += wxFILE_SEP_PATH_UNIX;
+ }
+ break;
+
+ case wxPATH_VMS:
+ // no leading character here but use this place to unset
+ // wxPATH_GET_SEPARATOR flag: under VMS it doesn't make sense
+ // as, if I understand correctly, there should never be a dot
+ // before the closing bracket
+ flags &= ~wxPATH_GET_SEPARATOR;
+ }
+
+ if ( m_dirs.empty() )
+ {
+ // there is nothing more
+ return fullpath;
+ }
+
+ // then concatenate all the path components using the path separator
+ if ( format == wxPATH_VMS )
+ {
+ fullpath += wxT('[');
+ }
+
+ const size_t dirCount = m_dirs.GetCount();
+ for ( size_t i = 0; i < dirCount; i++ )
+ {
+ switch (format)
+ {
+ case wxPATH_MAC:
+ if ( m_dirs[i] == wxT(".") )
+ {
+ // skip appending ':', this shouldn't be done in this
+ // case as "::" is interpreted as ".." under Unix
+ continue;
+ }
+
+ // convert back from ".." to nothing
+ if ( !m_dirs[i].IsSameAs(wxT("..")) )
+ fullpath += m_dirs[i];
+ break;
+
+ default:
+ wxFAIL_MSG( wxT("Unexpected path format") );
+ // still fall through
+
+ case wxPATH_DOS:
+ case wxPATH_UNIX:
+ fullpath += m_dirs[i];
+ break;
+
+ case wxPATH_VMS:
+ // TODO: What to do with ".." under VMS
+
+ // convert back from ".." to nothing
+ if ( !m_dirs[i].IsSameAs(wxT("..")) )
+ fullpath += m_dirs[i];
+ break;
+ }
+
+ if ( (flags & wxPATH_GET_SEPARATOR) || (i != dirCount - 1) )
+ fullpath += GetPathSeparator(format);
+ }
+
+ if ( format == wxPATH_VMS )
+ {
+ fullpath += wxT(']');
+ }
+
+ return fullpath;
+}
+
+wxString wxFileName::GetFullPath( wxPathFormat format ) const
+{
+ // we already have a function to get the path
+ wxString fullpath = GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR,
+ format);
+
+ // now just add the file name and extension to it
+ fullpath += GetFullName();
+
+ return fullpath;
+}
+
+// Return the short form of the path (returns identity on non-Windows platforms)
+wxString wxFileName::GetShortPath() const
+{
+ wxString path(GetFullPath());
+
+#if defined(__WXMSW__) && defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
+ DWORD sz = ::GetShortPathName(path.fn_str(), NULL, 0);
+ if ( sz != 0 )
+ {
+ wxString pathOut;
+ if ( ::GetShortPathName
+ (
+ path.fn_str(),
+ wxStringBuffer(pathOut, sz),
+ sz
+ ) != 0 )
+ {
+ return pathOut;
+ }
+ }
+#endif // Windows
+
+ return path;
+}
+
+// Return the long form of the path (returns identity on non-Windows platforms)
+wxString wxFileName::GetLongPath() const
+{
+ wxString pathOut,
+ path = GetFullPath();
+
+#if defined(__WIN32__) && !defined(__WXWINCE__) && !defined(__WXMICROWIN__)
+
+#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
+ // twice -- but as the result is the same in both threads, it's ok
+ static GET_LONG_PATH_NAME s_pfnGetLongPathName = NULL;
+ if ( !s_pfnGetLongPathName )
+ {
+ static bool s_triedToLoad = false;
+
+ if ( !s_triedToLoad )
+ {
+ s_triedToLoad = true;
+
+ wxDynamicLibrary dllKernel(wxT("kernel32"));
+
+ const wxChar* GetLongPathName = wxT("GetLongPathName")
+#if wxUSE_UNICODE
+ wxT("W");
+#else // ANSI
+ wxT("A");
+#endif // Unicode/ANSI
+
+ if ( dllKernel.HasSymbol(GetLongPathName) )
+ {
+ s_pfnGetLongPathName = (GET_LONG_PATH_NAME)
+ dllKernel.GetSymbol(GetLongPathName);
+ }
+
+ // note that kernel32.dll can be unloaded, it stays in memory
+ // anyhow as all Win32 programs link to it and so it's safe to call
+ // GetLongPathName() even after unloading it
+ }
+ }
+
+ if ( s_pfnGetLongPathName )
+ {
+ DWORD dwSize = (*s_pfnGetLongPathName)(path.fn_str(), NULL, 0);
+ if ( dwSize > 0 )
+ {
+ if ( (*s_pfnGetLongPathName)
+ (
+ path.fn_str(),
+ wxStringBuffer(pathOut, dwSize),
+ dwSize
+ ) != 0 )
+ {
+ return pathOut;
+ }
+ }
+ }
+#endif // wxUSE_DYNLIB_CLASS
+
+ // The OS didn't support GetLongPathName, or some other error.
+ // We need to call FindFirstFile on each component in turn.
+
+ WIN32_FIND_DATA findFileData;
+ HANDLE hFind;
+
+ if ( HasVolume() )
+ pathOut = GetVolume() +
+ GetVolumeSeparator(wxPATH_DOS) +
+ GetPathSeparator(wxPATH_DOS);
+ else
+ pathOut = wxEmptyString;
+
+ wxArrayString dirs = GetDirs();
+ dirs.Add(GetFullName());
+
+ wxString tmpPath;
+
+ 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 + 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) )
+ {
+ tmpPath += wxFILE_SEP_PATH;
+ pathOut = tmpPath;
+ continue;
+ }
+
+ hFind = ::FindFirstFile(tmpPath.fn_str(), &findFileData);
+ if (hFind == INVALID_HANDLE_VALUE)
+ {
+ // Error: most likely reason is that path doesn't exist, so
+ // append any unprocessed parts and return
+ for ( i += 1; i < count; i++ )
+ tmpPath += wxFILE_SEP_PATH + dirs[i];
+
+ return tmpPath;
+ }
+
+ pathOut += findFileData.cFileName;
+ if ( (i < (count-1)) )
+ pathOut += wxFILE_SEP_PATH;
+
+ ::FindClose(hFind);
+ }
+#else // !Win32
+ pathOut = path;
+#endif // Win32/!Win32
+
+ return pathOut;
+}
+
+wxPathFormat wxFileName::GetFormat( wxPathFormat format )
+{
+ if (format == wxPATH_NATIVE)
+ {
+#if defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__)
+ format = wxPATH_DOS;
+#elif defined(__VMS)
+ format = wxPATH_VMS;
+#else
+ format = wxPATH_UNIX;
+#endif
+ }
+ 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
+// ----------------------------------------------------------------------------
+
+/* static */
+void
+wxFileName::SplitVolume(const wxString& fullpathWithVolume,
+ wxString *pstrVolume,
+ wxString *pstrPath,
+ wxPathFormat format)
+{
+ format = GetFormat(format);
+
+ wxString fullpath = fullpathWithVolume;
+
+ if ( IsMSWUniqueVolumeNamePath(fullpath, format) )
+ {
+ // special Windows unique volume names hack: transform
+ // \\?\Volume{guid}\path into Volume{guid}:path
+ // note: this check must be done before the check for UNC path
+
+ // we know the last backslash from the unique volume name is located
+ // there from IsMSWUniqueVolumeNamePath
+ fullpath[wxMSWUniqueVolumePrefixLength - 1] = wxFILE_SEP_DSK;
+
+ // paths starting with a unique volume name should always be absolute
+ fullpath.insert(wxMSWUniqueVolumePrefixLength, 1, wxFILE_SEP_PATH_DOS);
+
+ // remove the leading "\\?\" part
+ fullpath.erase(0, 4);
+ }
+ else if ( IsUNCPath(fullpath, format) )
+ {
+ // special Windows UNC paths hack: transform \\share\path into share:path
+
+ fullpath.erase(0, 2);
+
+ size_t posFirstSlash =
+ fullpath.find_first_of(GetPathTerminators(format));
+ if ( posFirstSlash != wxString::npos )
+ {
+ fullpath[posFirstSlash] = wxFILE_SEP_DSK;
+
+ // UNC paths are always absolute, right? (FIXME)
+ fullpath.insert(posFirstSlash + 1, 1, wxFILE_SEP_PATH_DOS);
+ }
+ }
+
+ // We separate the volume here
+ if ( format == wxPATH_DOS || format == wxPATH_VMS )
+ {
+ wxString sepVol = GetVolumeSeparator(format);
+
+ // we have to exclude the case of a colon in the very beginning of the
+ // string as it can't be a volume separator (nor can this be a valid
+ // DOS file name at all but we'll leave dealing with this to our caller)
+ size_t posFirstColon = fullpath.find_first_of(sepVol);
+ if ( posFirstColon && posFirstColon != wxString::npos )
+ {
+ if ( pstrVolume )
+ {
+ *pstrVolume = fullpath.Left(posFirstColon);
+ }
+
+ // remove the volume name and the separator from the full path
+ fullpath.erase(0, posFirstColon + sepVol.length());
+ }
+ }
+
+ if ( pstrPath )
+ *pstrPath = fullpath;
+}
+
+/* static */
+void wxFileName::SplitPath(const wxString& fullpathWithVolume,
+ wxString *pstrVolume,
+ wxString *pstrPath,
+ wxString *pstrName,
+ wxString *pstrExt,
+ bool *hasExt,
+ wxPathFormat format)
+{
+ format = GetFormat(format);
+
+ wxString fullpath;
+ SplitVolume(fullpathWithVolume, pstrVolume, &fullpath, format);
+
+ // find the positions of the last dot and last path separator in the path
+ size_t posLastDot = fullpath.find_last_of(wxFILE_SEP_EXT);
+ size_t posLastSlash = fullpath.find_last_of(GetPathTerminators(format));
+
+ // check whether this dot occurs at the very beginning of a path component
+ if ( (posLastDot != wxString::npos) &&
+ (posLastDot == 0 ||
+ IsPathSeparator(fullpath[posLastDot - 1]) ||
+ (format == wxPATH_VMS && fullpath[posLastDot - 1] == wxT(']'))) )
+ {
+ // dot may be (and commonly -- at least under Unix -- is) the first
+ // character of the filename, don't treat the entire filename as
+ // extension in this case
+ posLastDot = wxString::npos;
+ }
+
+ // if we do have a dot and a slash, check that the dot is in the name part
+ if ( (posLastDot != wxString::npos) &&
+ (posLastSlash != wxString::npos) &&
+ (posLastDot < posLastSlash) )
+ {
+ // the dot is part of the path, not the start of the extension
+ posLastDot = wxString::npos;
+ }
+
+ // now fill in the variables provided by user
+ if ( pstrPath )
+ {
+ if ( posLastSlash == wxString::npos )
+ {
+ // no path at all
+ pstrPath->Empty();
+ }
+ else
+ {
+ // take everything up to the path separator but take care to make
+ // the path equal to something like '/', not empty, for the files
+ // immediately under root directory
+ size_t len = posLastSlash;
+
+ // this rule does not apply to mac since we do not start with colons (sep)
+ // except for relative paths
+ if ( !len && format != wxPATH_MAC)
+ len++;
+
+ *pstrPath = fullpath.Left(len);
+
+ // special VMS hack: remove the initial bracket
+ if ( format == wxPATH_VMS )
+ {
+ if ( (*pstrPath)[0u] == wxT('[') )
+ pstrPath->erase(0, 1);
+ }
+ }
+ }
+
+ if ( pstrName )
+ {
+ // take all characters starting from the one after the last slash and
+ // up to, but excluding, the last dot
+ size_t nStart = posLastSlash == wxString::npos ? 0 : posLastSlash + 1;
+ size_t count;
+ if ( posLastDot == wxString::npos )
+ {
+ // take all until the end
+ count = wxString::npos;