#include "wx/mimetype.h"
#include "wx/filename.h"
#include "wx/tokenzr.h"
+#include "wx/uri.h"
#include "wx/private/fileback.h"
+// ----------------------------------------------------------------------------
+// wxFSFile
+// ----------------------------------------------------------------------------
-//--------------------------------------------------------------------------------
+const wxString& wxFSFile::GetMimeType() const
+{
+ if ( m_MimeType.empty() && !m_Location.empty() )
+ {
+ wxConstCast(this, wxFSFile)->m_MimeType =
+ wxFileSystemHandler::GetMimeTypeFromExt(m_Location);
+ }
+
+ return m_MimeType;
+}
+
+// ----------------------------------------------------------------------------
// wxFileSystemHandler
-//--------------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxFileSystemHandler, wxObject)
+/* static */
wxString wxFileSystemHandler::GetMimeTypeFromExt(const wxString& location)
{
wxString ext, mime;
-wxString wxFileSystemHandler::GetProtocol(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetProtocol(const wxString& location)
{
wxString s = wxEmptyString;
int i, l = location.length();
}
-wxString wxFileSystemHandler::GetLeftLocation(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetLeftLocation(const wxString& location)
{
int i;
bool fnd = false;
return wxEmptyString;
}
-wxString wxFileSystemHandler::GetRightLocation(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetRightLocation(const wxString& location)
{
int i, l = location.length();
int l2 = l + 1;
else return location.Mid(i + 1, l2 - i - 2);
}
-wxString wxFileSystemHandler::GetAnchor(const wxString& location) const
+/* static */
+wxString wxFileSystemHandler::GetAnchor(const wxString& location)
{
wxChar c;
int l = location.length();
return new wxFSFile(is,
right,
- GetMimeTypeFromExt(location),
+ wxEmptyString,
GetAnchor(location)
#if wxUSE_DATETIME
,wxDateTime(wxFileModificationTime(fullpath))
}
bool wxFileSystem::FindFileInPath(wxString *pStr,
- const wxChar *path,
- const wxChar *basename)
+ const wxString& path,
+ const wxString& basename)
{
// we assume that it's not empty
- wxCHECK_MSG( !wxIsEmpty(basename), false,
+ wxCHECK_MSG( !basename.empty(), false,
_T("empty file name in wxFileSystem::FindFileInPath"));
+ wxString name;
// skip path separator in the beginning of the file name if present
- if ( wxIsPathSeparator(*basename) )
- basename++;
+ if ( wxIsPathSeparator(basename[0u]) )
+ name = basename.substr(1);
+ else
+ name = basename;
wxStringTokenizer tokenizer(path, wxPATH_SEP);
while ( tokenizer.HasMoreTokens() )
wxString strFile = tokenizer.GetNextToken();
if ( !wxEndsWithPathSeparator(strFile) )
strFile += wxFILE_SEP_PATH;
- strFile += basename;
+ strFile += name;
wxFSFile *file = OpenFile(strFile);
if ( file )
path = path.Mid(2);
#endif
- path.Replace(wxT("%25"), wxT("%"));
- path.Replace(wxT("%3A"), wxT(":"));
+ path = wxURI::Unescape(path);
#ifdef __WXMSW__
// file urls either start with a forward slash (local harddisk),
#endif
url.Replace(g_nativePathString, g_unixPathString);
- url.Replace(wxT("%"), wxT("%25"));
+ url.Replace(wxT("%"), wxT("%25")); // '%'s must be replaced first!
+ url.Replace(wxT("#"), wxT("%23"));
+
+ // notice that all colons *must* be encoded in the paths used by
+ // wxFileSystem even though this makes URLs produced by this method
+ // unusable with IE under Windows as it requires "file:///c:/foo.bar" and
+ // doesn't accept "file:///c%3a/foo.bar" -- but then we never made any
+ // guarantees about general suitability of the strings returned by this
+ // method, they must work with wxFileSystem only and not encoding the colon
+ // breaks handling of "http://wherever/whatever.zip#zip:filename.ext" URLs
+ // so we really can't do this without heavy changes to the parsing code
+ // here, in particular in GetRightLocation()
url.Replace(wxT(":"), wxT("%3A"));
url = wxT("file:") + url;
return url;