]>
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
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/webviewarchivehandler.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 wxWebViewArchiveHandler::wxWebViewArchiveHandler(const wxString
& scheme
) :
48 wxWebViewHandler(scheme
)
50 m_fileSystem
= new wxFileSystem();
53 wxWebViewArchiveHandler::~wxWebViewArchiveHandler()
55 wxDELETE(m_fileSystem
);
58 wxFSFile
* wxWebViewArchiveHandler::GetFile(const wxString
&uri
)
60 //If there is a fragment at the end of the path then we need to strip it
61 //off as not all backends do this for us
63 size_t hashloc
= uri
.find('#');
64 if(hashloc
!= wxString::npos
)
66 path
= uri
.substr(0, hashloc
);
69 //We iterate through the string to see if there is a protocol description
70 size_t start
= wxString::npos
;
71 for(size_t i
= 0; i
< path
.length(); i
++)
73 if(path
[i
] == ';' && path
.substr(i
, 10) == ";protocol=")
80 //We do not have a protocol string so we just pass the path withouth the
81 if(start
== wxString::npos
)
83 size_t doubleslash
= path
.find("//");
84 //The path is incorrectly formed without // after the scheme
85 if(doubleslash
== wxString::npos
)
88 wxString fspath
= "file:" +
89 EscapeFileNameCharsInURL(path
.substr(doubleslash
+ 2).c_str());
90 return m_fileSystem
->OpenFile(fspath
);
92 //Otherwise we need to extract the protocol
95 size_t end
= path
.find('/', start
);
96 //For the path to be valid there must to a path after the protocol
97 if(end
== wxString::npos
)
101 wxString mainpath
= path
.substr(0, start
);
102 wxString archivepath
= path
.substr(end
);
103 wxString protstring
= path
.substr(start
, end
- start
);
104 wxString protocol
= protstring
.substr(10);
105 //We can now construct the correct path
106 size_t doubleslash
= path
.find("//");
107 //The path is incorrectly formed without // after the first protocol
108 if(doubleslash
== wxString::npos
)
111 wxString fspath
= "file:" +
112 EscapeFileNameCharsInURL(mainpath
.substr(doubleslash
+ 2).c_str())
113 + "#" + protocol
+":" + archivepath
;
114 return m_fileSystem
->OpenFile(fspath
);
118 #endif // wxUSE_WEBVIEW