From 9e9b65c1db303ea7000309ae9bc779db5b816a72 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 21 Mar 2001 12:34:56 +0000 Subject: [PATCH] Added long-filename functions & normalisation; patch to Watcom makefiles git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9556 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/filename.h | 9 +++++- src/common/filename.cpp | 71 +++++++++++++++++++++++++++++++++++++++++ src/makeprog.wat | 4 +-- src/zlib/makefile.wat | 2 +- 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/include/wx/filename.h b/include/wx/filename.h index 67a153d895..0f3153b65b 100644 --- a/include/wx/filename.h +++ b/include/wx/filename.h @@ -65,7 +65,8 @@ enum wxPathNormalize wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute - wxPATH_NORM_ALL = 0x001f + wxPATH_NORM_LONG = 0x0020, // make the path the long form + wxPATH_NORM_ALL = 0x003f }; // ---------------------------------------------------------------------------- @@ -241,6 +242,12 @@ public: // Construct full path with name and ext wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const; + // Return the short form of the path (returns identity on non-Windows platforms) + wxString GetShortPath() const; + + // Return the long form of the path (returns identity on non-Windows platforms) + wxString GetLongPath() const; + // various helpers // get the canonical path format for this platform diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 9495f6f929..87da62de5c 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 // ============================================================================ @@ -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,58 @@ 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()); + + wxChar outBuf[MAX_PATH]; + + // TODO: can't work out how to determine if the function failed + // (positive value if either it succeeded or the buffer was too small) + + int bufSz = ::GetShortPathName((const wxChar*) path, outBuf, MAX_PATH*sizeof(wxChar)); + + if (bufSz == 0) + { + return wxEmptyString; + } + else + { + return wxString(outBuf); + } +#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()); + + wxChar outBuf[MAX_PATH]; + + // TODO: can't work out how to determine if the function failed + // (positive value if either it succeeded or the buffer was too small) + + int bufSz = ::GetLongPathName((const wxChar*) path, outBuf, MAX_PATH*sizeof(wxChar)); + + if (bufSz == 0) + { + return wxEmptyString; + } + else + { + return wxString(outBuf); + } +#else + return GetFullPath(); +#endif +} + wxPathFormat wxFileName::GetFormat( wxPathFormat format ) { if (format == wxPATH_NATIVE) diff --git a/src/makeprog.wat b/src/makeprog.wat index 431ecc5d3f..99b984842e 100644 --- a/src/makeprog.wat +++ b/src/makeprog.wat @@ -20,9 +20,9 @@ $(LNK) : makefile.wat @%append $(LNK) system $(LINKOPTION) @%append $(LNK) $(STACK) @%append $(LNK) name $(PROGRAM).exe - @for %i in ($(LIBS)) do @%append $(LNK) file %i - @for %i in ($(EXTRALIBS)) do @%append $(LNK) file %i @for %i in ($(OBJECTS)) do @%append $(LNK) file %i + @for %i in ($(LIBS)) do @%append $(LNK) lib %i + @for %i in ($(EXTRALIBS)) do @%append $(LNK) lib %i # @%append $(LNK) $(MINDATA) # @%append $(LNK) $(MAXDATA) diff --git a/src/zlib/makefile.wat b/src/zlib/makefile.wat index 7f62708415..8b6dab6273 100644 --- a/src/zlib/makefile.wat +++ b/src/zlib/makefile.wat @@ -85,7 +85,7 @@ minigzip.obj: minigzip.c zlib.h zconf.h # we must cut the command line to fit in the MS/DOS 128 byte limit: $(LIBTARGET): $(OBJ1) $(OBJ2) $(OBJ3) - del $(LIBTARGET) + if exist $(LIBTARGET) del $(LIBTARGET) $(LIB) $(LIBTARGET) +$(OBJP1) $(LIB) $(LIBTARGET) +$(OBJP2) $(LIB) $(LIBTARGET) +$(OBJP3)