// wxPathList
// ----------------------------------------------------------------------------
-void wxPathList::Add (const wxString& path)
+void wxPathList::Add(const wxString& path)
{
- // add only the path part of the given string (not the filename, in case it's present)
+ // add a path separator to force wxFileName to interpret it always as a directory
+ // (i.e. if we are called with '/home/user' we want to consider it a folder and
+ // not, as wxFileName would consider, a filename).
wxFileName fn(path + wxFileName::GetPathSeparator());
- fn.Normalize(); // add only normalized paths
+
+ // add only normalized relative/absolute paths
+ fn.Normalize(wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_LONG|wxPATH_NORM_ENV_VARS);
wxString toadd = fn.GetPath();
if (Index(toadd) == wxNOT_FOUND)
wxString wxPathList::FindValidPath (const wxString& file) const
{
+ // normalize the given string as it could be a path + a filename
+ // and not only a filename
wxFileName fn(file);
wxString strend;
- fn.Normalize();
+ // NB: normalize without making absolute !
+ fn.Normalize(wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_LONG|wxPATH_NORM_ENV_VARS);
+
+ wxASSERT_MSG(!fn.IsDir(), wxT("Cannot search for directories; only for files"));
if (fn.IsAbsolute())
- strend = fn.GetFullName();
+ strend = fn.GetFullName(); // search for the file name and ignore the path part
else
strend = fn.GetFullPath();
return wxMacCFStringHolder(cfMutableString).AsString() ;
}
+#ifndef __LP64__
+
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
{
FSRef fsRef ;
wxMacPathToFSRef( path , &fsRef ) ;
err = FSRefMakeFSSpec( &fsRef , spec ) ;
}
+#endif
#endif // __WXMAC__
// Get a temporary filename, opening and closing the file.
wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf)
{
-#if wxUSE_FILE
- wxString filename = wxFileName::CreateTempFileName(prefix);
- if ( filename.empty() )
+ wxString filename;
+ if ( !wxGetTempFileName(prefix, filename) )
return NULL;
if ( buf )
buf = MYcopystring(filename);
return buf;
-#else
- wxUnusedVar(prefix);
- wxUnusedVar(buf);
- // wxFileName::CreateTempFileName needs wxFile class enabled
- return NULL;
-#endif
}
bool wxGetTempFileName(const wxString& prefix, wxString& buf)
{
- buf = wxGetTempFileName(prefix);
+#if wxUSE_FILE
+ buf = wxFileName::CreateTempFileName(prefix);
return !buf.empty();
+#else // !wxUSE_FILE
+ wxUnusedVar(prefix);
+ wxUnusedVar(buf);
+
+ return false;
+#endif // wxUSE_FILE/!wxUSE_FILE
}
// Get first file name matching given wild card.
#ifdef HAVE_WGETCWD
#if wxUSE_UNICODE_MSLU
- if ( wxGetOsVersion() != wxWIN95 )
+ if ( wxGetOsVersion() != wxOS_WINDOWS_9X )
#else
char *cbuf = NULL; // never really used because needsANSI will always be false
#endif
return filters.GetCount();
}
+#if defined( __WINDOWS__ )
+bool wxCheckGenericPermission(const wxString &path, DWORD access)
+{
+ // quoting the MSDN: "To obtain a handle to a directory, call the
+ // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag"
+ wxWinVersion ver = wxGetWinVersion();
+ bool isdir = wxDirExists(path);
+ if (isdir && (ver == wxWinVersion_95 || ver == wxWinVersion_98 || ver == wxWinVersion_ME))
+ {
+ // however Win95/98/ME do not support FILE_FLAG_BACKUP_SEMANTICS...
+ if (access == GENERIC_READ)
+ {
+ WIN32_FILE_ATTRIBUTE_DATA data;
+ if (GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &data) == 0)
+ return false; // cannot query attributes
+ return (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
+ }
+
+ // FIXME: is it true that directories are always writable & executable on Win9X family ?
+ return true;
+ }
+ else
+ {
+ HANDLE h = CreateFile(path.c_str(), access,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
+ OPEN_EXISTING, isdir ? FILE_FLAG_BACKUP_SEMANTICS : 0, NULL);
+ if (h != INVALID_HANDLE_VALUE)
+ CloseHandle(h);
+
+ return h != INVALID_HANDLE_VALUE;
+ }
+}
+#endif
+
+bool wxIsWritable(const wxString &path)
+{
+#if defined( __UNIX__ )
+ // access() will take in count also symbolic links
+ return access(wxConvFile.cWX2MB(path), W_OK) == 0;
+#elif defined( __WINDOWS__ )
+ return wxCheckGenericPermission(path, GENERIC_WRITE);
+#else
+ wxUnusedVar(path);
+ // TODO
+ return false;
+#endif
+}
+
+bool wxIsReadable(const wxString &path)
+{
+#if defined( __UNIX__ )
+ // access() will take in count also symbolic links
+ return access(wxConvFile.cWX2MB(path), R_OK) == 0;
+#elif defined( __WINDOWS__ )
+ return wxCheckGenericPermission(path, GENERIC_READ);
+#else
+ wxUnusedVar(path);
+ // TODO
+ return false;
+#endif
+}
+
+bool wxIsExecutable(const wxString &path)
+{
+#if defined( __UNIX__ )
+ // access() will take in count also symbolic links
+ return access(wxConvFile.cWX2MB(path), X_OK) == 0;
+#elif defined( __WINDOWS__ )
+ return wxCheckGenericPermission(path, GENERIC_EXECUTE);
+#else
+ wxUnusedVar(path);
+ // TODO
+ return false;
+#endif
+}
+
//------------------------------------------------------------------------
// wild character routines