]>
git.saurik.com Git - wxWidgets.git/blob - src/common/webviewfilehandler.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: webviewfilehandler.cpp
3 // Purpose: Custom handler for the file scheme to allow archive browsing
4 // Author: Steven Lamerton
6 // Copyright: (c) 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #if defined(__BORLANDC__)
19 #include "wx/webviewfilehandler.h"
20 #include "wx/filesys.h"
22 //Taken from wx/filesys.cpp
23 static wxString
EscapeFileNameCharsInURL(const char *in
)
27 for ( const unsigned char *p
= (const unsigned char*)in
; *p
; ++p
)
29 const unsigned char c
= *p
;
31 if ( c
== '/' || c
== '-' || c
== '.' || c
== '_' || c
== '~' ||
32 (c
>= '0' && c
<= '9') ||
33 (c
>= 'a' && c
<= 'z') ||
34 (c
>= 'A' && c
<= 'Z') )
40 s
<< wxString::Format("%%%02x", c
);
47 wxWebFileHandler::wxWebFileHandler()
50 m_fileSystem
= new wxFileSystem();
53 wxFSFile
* wxWebFileHandler::GetFile(const wxString
&uri
)
55 //If there is a fragment at the end of the path then we need to strip it
56 //off as not all backends do this for us
58 size_t hashloc
= uri
.find('#');
59 if(hashloc
!= wxString::npos
)
61 path
= uri
.substr(0, hashloc
);
64 //We iterate through the string to see if there is a protocol description
65 size_t start
= wxString::npos
;
66 for(size_t i
= 0; i
< path
.length(); i
++)
68 if(path
[i
] == ';' && path
.substr(i
, 10) == ";protocol=")
75 //We do not have a protocol string so we just pass the path withouth the
76 if(start
== wxString::npos
)
78 size_t doubleslash
= path
.find("//");
79 //The path is incorrectly formed without // after the scheme
80 if(doubleslash
== wxString::npos
)
83 wxString fspath
= "file:" +
84 EscapeFileNameCharsInURL(path
.substr(doubleslash
+ 2));
85 return m_fileSystem
->OpenFile(fspath
);
87 //Otherwise we need to extract the protocol
90 size_t end
= path
.find('/', start
);
91 //For the path to be valid there must to a path after the protocol
92 if(end
== wxString::npos
)
96 wxString mainpath
= path
.substr(0, start
);
97 wxString archivepath
= path
.substr(end
);
98 wxString protstring
= path
.substr(start
, end
- start
);
99 wxString protocol
= protstring
.substr(10);
100 //We can now construct the correct path
101 size_t doubleslash
= path
.find("//");
102 //The path is incorrectly formed without // after the first protocol
103 if(doubleslash
== wxString::npos
)
106 wxString fspath
= "file:" +
107 EscapeFileNameCharsInURL(mainpath
.substr(doubleslash
+ 2))
108 + "#" + protocol
+":" + archivepath
;
109 return m_fileSystem
->OpenFile(fspath
);