#ifndef WX_PRECOMP
#include "wx/intl.h"
+ #include "wx/log.h"
+ #include "wx/utils.h"
#endif
-#include "wx/utils.h"
#include "wx/file.h" // This does include filefn.h
#include "wx/filename.h"
#include "wx/dir.h"
+#include "wx/tokenzr.h"
+
// there are just too many of those...
#ifdef __VISUALC__
#pragma warning(disable:4706) // assignment within conditional expression
#include "wx/mac/private.h" // includes mac headers
#endif
-#include "wx/log.h"
-
#ifdef __WINDOWS__
#include "wx/msw/private.h"
#include "wx/msw/mslu.h"
// wxPathList
// ----------------------------------------------------------------------------
-// IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
-
-static inline wxChar* MYcopystring(const wxString& s)
+void wxPathList::Add (const wxString& path)
{
- wxChar* copy = new wxChar[s.length() + 1];
- return wxStrcpy(copy, s.c_str());
-}
+ // add only the path part of the given string (not the filename, in case it's present)
+ wxFileName fn(path + wxFileName::GetPathSeparator());
+ fn.Normalize(); // add only normalized paths
-static inline wxChar* MYcopystring(const wxChar* s)
-{
- wxChar* copy = new wxChar[wxStrlen(s) + 1];
- return wxStrcpy(copy, s);
+ wxString toadd = fn.GetPath();
+ if (Index(toadd) == wxNOT_FOUND)
+ wxArrayString::Add(toadd); // do not add duplicates
}
-void wxPathList::Add (const wxString& path)
+void wxPathList::Add(const wxArrayString &arr)
{
- wxStringList::Add (WXSTRINGCAST path);
+ for (size_t j=0; j < arr.GetCount(); j++)
+ Add(arr[j]);
}
// Add paths e.g. from the PATH environment variable
{
// No environment variables on WinCE
#ifndef __WXWINCE__
+
+ // The space has been removed from the tokenizers, otherwise a
+ // path such as "C:\Program Files" would be split into 2 paths:
+ // "C:\Program" and "Files"; this is true for both Windows and Unix.
+
static const wxChar PATH_TOKS[] =
#if defined(__WINDOWS__) || defined(__OS2__)
- /*
- The space has been removed from the tokenizers, otherwise a
- path such as "C:\Program Files" would be split into 2 paths:
- "C:\Program" and "Files"
- */
-// wxT(" ;"); // Don't separate with colon in DOS (used for drive)
wxT(";"); // Don't separate with colon in DOS (used for drive)
#else
- wxT(" :;");
+ wxT(":;");
#endif
- wxString val ;
- if (wxGetEnv (WXSTRINGCAST envVariable, &val))
+ wxString val;
+ if ( wxGetEnv(envVariable, &val) )
{
- wxChar *s = MYcopystring (val);
- wxChar *save_ptr, *token = wxStrtok (s, PATH_TOKS, &save_ptr);
-
- if (token)
- {
- Add(token);
- while (token)
- {
- if ( (token = wxStrtok ((wxChar *) NULL, PATH_TOKS, &save_ptr))
- != NULL )
- {
- Add(token);
- }
- }
- }
-
- // suppress warning about unused variable save_ptr when wxStrtok() is a
- // macro which throws away its third argument
- save_ptr = token;
-
- delete [] s;
+ // split into an array of string the value of the env var
+ wxArrayString arr = wxStringTokenize(val, PATH_TOKS);
+ WX_APPEND_ARRAY(*this, arr);
}
#endif // !__WXWINCE__
}
wxString path_only(wxPathOnly(path));
if ( !path_only.empty() )
{
- if ( !Member(path_only) )
+ if ( Index(path_only) == wxNOT_FOUND )
Add(path_only);
}
}
-bool wxPathList::Member (const wxString& path)
+// deprecated !
+bool wxPathList::Member (const wxString& path) const
{
- for (wxStringList::compatibility_iterator node = GetFirst(); node; node = node->GetNext())
- {
- wxString path2( node->GetData() );
- if (
-#if defined(__WINDOWS__) || defined(__OS2__) || defined(__VMS__) || defined(__WXMAC__)
- // Case INDEPENDENT
- path.CompareTo (path2, wxString::ignoreCase) == 0
-#else
- // Case sensitive File System
- path.CompareTo (path2) == 0
-#endif
- )
- return true;
- }
- return false;
+ return Index(path) != wxNOT_FOUND;
}
-wxString wxPathList::FindValidPath (const wxString& file)
+wxString wxPathList::FindValidPath (const wxString& file) const
{
- wxExpandPath(wxFileFunctionsBuffer, file);
-
- wxChar buf[_MAXPATHLEN];
- wxStrcpy(buf, wxFileFunctionsBuffer);
+ wxFileName fn(file);
+ wxString strend;
- wxChar *filename = wxIsAbsolutePath (buf) ? wxFileNameFromPath (buf) : (wxChar *)buf;
+ fn.Normalize();
+ if (fn.IsAbsolute())
+ strend = fn.GetFullName();
+ else
+ strend = fn.GetFullPath();
- for (wxStringList::compatibility_iterator node = GetFirst(); node; node = node->GetNext())
+ for (size_t i=0; i<GetCount(); i++)
{
- const wxString path(node->GetData());
- wxStrcpy (wxFileFunctionsBuffer, path);
- wxChar ch = wxFileFunctionsBuffer[wxStrlen(wxFileFunctionsBuffer)-1];
- if (ch != wxT('\\') && ch != wxT('/'))
- wxStrcat (wxFileFunctionsBuffer, wxT("/"));
- wxStrcat (wxFileFunctionsBuffer, filename);
-#ifdef __WINDOWS__
- wxUnix2DosFilename (wxFileFunctionsBuffer);
-#endif
- if (wxFileExists (wxFileFunctionsBuffer))
- {
- return wxString(wxFileFunctionsBuffer); // Found!
- }
- } // for()
+ wxString strstart = Item(i);
+ if (!strstart.IsEmpty() && strstart.Last() != wxFileName::GetPathSeparator())
+ strstart += wxFileName::GetPathSeparator();
- return wxEmptyString; // Not found
+ if (wxFileExists(strstart + strend))
+ return strstart + strend; // Found!
+ }
+
+ return wxEmptyString; // Not found
}
-wxString wxPathList::FindAbsoluteValidPath (const wxString& file)
+wxString wxPathList::FindAbsoluteValidPath (const wxString& file) const
{
wxString f = FindValidPath(file);
if ( f.empty() || wxIsAbsolutePath(f) )
return buf;
}
+// ----------------------------------------------------------------------------
+// miscellaneous global functions (TOFIX!)
+// ----------------------------------------------------------------------------
+
+static inline wxChar* MYcopystring(const wxString& s)
+{
+ wxChar* copy = new wxChar[s.length() + 1];
+ return wxStrcpy(copy, s.c_str());
+}
+
+static inline wxChar* MYcopystring(const wxChar* s)
+{
+ wxChar* copy = new wxChar[wxStrlen(s) + 1];
+ return wxStrcpy(copy, s);
+}
+
+
bool
wxFileExists (const wxString& filename)
{
return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY);
#else // !__WIN32__
+ #ifndef S_ISREG
+ #define S_ISREG(mode) ((mode) & S_IFREG)
+ #endif
wxStructStat st;
#ifndef wxNEED_WX_UNISTD_H
- return (wxStat( filename.fn_str() , &st) == 0 && (st.st_mode & S_IFREG))
+ return (wxStat( filename.fn_str() , &st) == 0 && S_ISREG(st.st_mode))
#ifdef __OS2__
|| (errno == EACCES) // if access is denied something with that name
// exists and is opened in exclusive mode.
#endif
;
#else
- return wxStat( filename , &st) == 0 && (st.st_mode & S_IFREG);
+ return wxStat( filename , &st) == 0 && S_ISREG(st.st_mode);
#endif
#endif // __WIN32__/!__WIN32__
}
}
CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, kDefaultPathStyle);
CFRelease( fullURLRef ) ;
- return wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());
+ CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString);
+ CFRelease( cfString );
+ CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
+ return wxMacCFStringHolder(cfMutableString).AsString();
}
OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef )
{
OSStatus err = noErr ;
- CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, wxMacCFStringHolder(path ,wxLocale::GetSystemEncoding() ) , kDefaultPathStyle, false);
+ CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(path));
+ CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
+ CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kDefaultPathStyle, false);
+ CFRelease( cfMutableString );
if ( NULL != url )
{
if ( CFURLGetFSRef(url, fsRef) == false )
CFStringRef cfname = CFStringCreateWithCharacters( kCFAllocatorDefault,
uniname->unicode,
uniname->length );
- return wxMacCFStringHolder(cfname).AsString() ;
+ CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfname);
+ CFRelease( cfname );
+ CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
+ return wxMacCFStringHolder(cfMutableString).AsString() ;
}
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
wxFileName::SplitPath(pszFileName, pstrPath, pstrName, pstrExt);
}
+#if wxUSE_DATETIME
+
time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename)
{
wxDateTime mtime;
return mtime.GetTicks();
}
+#endif // wxUSE_DATETIME
+
// Parses the filterStr, returning the number of filters.
// Returns 0 if none or if there's a problem.