]>
git.saurik.com Git - wxWidgets.git/blob - src/common/webviewarchivehandler.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: webviewfilehandler.cpp
3 // Purpose: Custom webview handler to allow archive browsing
4 // Author: Steven Lamerton
5 // Copyright: (c) 2011 Steven Lamerton
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
14 #if defined(__BORLANDC__)
18 #include "wx/webviewarchivehandler.h"
19 #include "wx/filesys.h"
21 //Taken from wx/filesys.cpp
22 static wxString
EscapeFileNameCharsInURL(const char *in
)
26 for ( const unsigned char *p
= (const unsigned char*)in
; *p
; ++p
)
28 const unsigned char c
= *p
;
30 if ( c
== '/' || c
== '-' || c
== '.' || c
== '_' || c
== '~' ||
31 (c
>= '0' && c
<= '9') ||
32 (c
>= 'a' && c
<= 'z') ||
33 (c
>= 'A' && c
<= 'Z') )
39 s
<< wxString::Format("%%%02x", c
);
46 wxWebViewArchiveHandler::wxWebViewArchiveHandler(const wxString
& scheme
) :
47 wxWebViewHandler(scheme
)
49 m_fileSystem
= new wxFileSystem();
52 wxWebViewArchiveHandler::~wxWebViewArchiveHandler()
54 wxDELETE(m_fileSystem
);
57 wxFSFile
* wxWebViewArchiveHandler::GetFile(const wxString
&uri
)
59 //If there is a fragment at the end of the path then we need to strip it
60 //off as not all backends do this for us
62 size_t hashloc
= uri
.find('#');
63 if(hashloc
!= wxString::npos
)
65 path
= uri
.substr(0, hashloc
);
68 //We iterate through the string to see if there is a protocol description
69 size_t start
= wxString::npos
;
70 for(size_t i
= 0; i
< path
.length(); i
++)
72 if(path
[i
] == ';' && path
.substr(i
, 10) == ";protocol=")
79 //We do not have a protocol string so we just pass the path withouth the
80 if(start
== wxString::npos
)
82 size_t doubleslash
= path
.find("//");
83 //The path is incorrectly formed without // after the scheme
84 if(doubleslash
== wxString::npos
)
87 wxString fspath
= "file:" +
88 EscapeFileNameCharsInURL(path
.substr(doubleslash
+ 2).c_str());
89 return m_fileSystem
->OpenFile(fspath
);
91 //Otherwise we need to extract the protocol
94 size_t end
= path
.find('/', start
);
95 //For the path to be valid there must to a path after the protocol
96 if(end
== wxString::npos
)
100 wxString mainpath
= path
.substr(0, start
);
101 wxString archivepath
= path
.substr(end
);
102 wxString protstring
= path
.substr(start
, end
- start
);
103 wxString protocol
= protstring
.substr(10);
104 //We can now construct the correct path
105 size_t doubleslash
= path
.find("//");
106 //The path is incorrectly formed without // after the first protocol
107 if(doubleslash
== wxString::npos
)
110 wxString fspath
= "file:" +
111 EscapeFileNameCharsInURL(mainpath
.substr(doubleslash
+ 2).c_str())
112 + "#" + protocol
+":" + archivepath
;
113 return m_fileSystem
->OpenFile(fspath
);
117 #endif // wxUSE_WEBVIEW