X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7124df9b59f2627c083b1fecaaa3e93c7088e3d0..4178000933f0618d2cc9dc2f80dfed91b0c61464:/src/common/filename.cpp diff --git a/src/common/filename.cpp b/src/common/filename.cpp index ef07caccef..5e4f6beaad 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -38,6 +38,12 @@ #include "wx/config.h" // for wxExpandEnvVars #include "wx/utils.h" +// For GetShort/LongPathName +#ifdef __WIN32__ +#include +#include "wx/msw/winundef.h" +#endif + // ============================================================================ // implementation // ============================================================================ @@ -249,7 +255,7 @@ bool wxFileName::Normalize(wxPathNormalize flags, { curDir.AssignDir(wxGetUserHome(dir.c_str() + 1)); - dirs.Remove(0u); + dirs.RemoveAt(0u); } } } @@ -316,6 +322,13 @@ bool wxFileName::Normalize(wxPathNormalize flags, m_ext.MakeLower(); } +#if defined(__WXMSW__) && defined(__WIN32__) + if (flags & wxPATH_NORM_LONG) + { + Assign(GetLongPath()); + } +#endif + return TRUE; } @@ -358,9 +371,15 @@ bool wxFileName::IsAbsolute( wxPathFormat format ) { wxChar ch = m_dirs.IsEmpty() ? _T('\0') : m_dirs[0u][0u]; + // Hack to cope with e.g. c:\thing - need something better + wxChar driveSep = _T('\0'); + if (!m_dirs.IsEmpty() && m_dirs[0].Length() > 1) + driveSep = m_dirs[0u][1u]; + // the path is absolute if it starts with a path separator or, only for // Unix filenames, with "~" or "~user" return IsPathSeparator(ch, format) || + driveSep == _T(':') || (GetFormat(format) == wxPATH_UNIX && ch == _T('~') ); } @@ -469,6 +488,60 @@ wxString wxFileName::GetFullPath( wxPathFormat format ) const return GetPathWithSep() + GetFullName(); } +// Return the short form of the path (returns identity on non-Windows platforms) +wxString wxFileName::GetShortPath() const +{ +#if defined(__WXMSW__) && defined(__WIN32__) + wxString path(GetFullPath()); + wxString pathOut; + DWORD sz = ::GetShortPathName(path, NULL, 0); + bool ok = sz != 0; + if ( ok ) + { + ok = ::GetShortPathName + ( + path, + pathOut.GetWriteBuf(sz), + sz + ) != 0; + pathOut.UngetWriteBuf(); + } + if (ok) + return pathOut; + else + return path; +#else + return GetFullPath(); +#endif +} + +// Return the long form of the path (returns identity on non-Windows platforms) +wxString wxFileName::GetLongPath() const +{ +#if defined(__WXMSW__) && defined(__WIN32__) + wxString path(GetFullPath()); + wxString pathOut; + DWORD sz = ::GetLongPathName(path, NULL, 0); + bool ok = sz != 0; + if ( ok ) + { + ok = ::GetLongPathName + ( + path, + pathOut.GetWriteBuf(sz), + sz + ) != 0; + pathOut.UngetWriteBuf(); + } + if (ok) + return pathOut; + else + return path; +#else + return GetFullPath(); +#endif +} + wxPathFormat wxFileName::GetFormat( wxPathFormat format ) { if (format == wxPATH_NATIVE) @@ -476,7 +549,7 @@ wxPathFormat wxFileName::GetFormat( wxPathFormat format ) #if defined(__WXMSW__) || defined(__WXPM__) format = wxPATH_DOS; #elif defined(__WXMAC__) - format = wxPATH_MAC; + format = wxPATH_UNIX; // that's the way the rest of wx' code works right now #else format = wxPATH_UNIX; #endif @@ -512,7 +585,10 @@ void wxFileName::SplitPath(const wxString& fullpath, } } - if ( (posLastDot != wxString::npos) && (posLastDot < posLastSlash) ) + // 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; @@ -535,9 +611,23 @@ void wxFileName::SplitPath(const wxString& fullpath, 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 = posLastDot == wxString::npos ? wxString::npos - : posLastDot - posLastSlash; + size_t count; + if ( posLastDot == wxString::npos ) + { + // take all until the end + count = wxString::npos; + } + else if ( posLastSlash == wxString::npos ) + { + count = posLastDot; + } + else // have both dot and slash + { + count = posLastDot - posLastSlash - 1; + } *pstrName = fullpath.Mid(nStart, count); }