]>
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 //We iterate through the string to see if there is a protocol description
57 for(int i
= 0; i
< uri
.length(); i
++)
59 if(uri
[i
] == ';' && uri
.substr(i
, 10) == ";protocol=")
66 //We do not have a protocol string so we just pass the path withouth the
69 size_t doubleslash
= uri
.find("//");
70 //The path is incorrectly formed without // after the scheme
71 if(doubleslash
== wxString::npos
)
74 wxString fspath
= "file:" +
75 EscapeFileNameCharsInURL(uri
.substr(doubleslash
+ 2));
76 return m_fileSystem
->OpenFile(fspath
);
78 //Otherwise we need to extract the protocol
81 int end
= uri
.find('/', start
);
82 //For the path to be valid there must to a path after the protocol
83 if(end
== wxString::npos
)
87 wxString mainpath
= uri
.substr(0, start
);
88 wxString archivepath
= uri
.substr(end
);
89 wxString protstring
= uri
.substr(start
, end
- start
);
90 wxString protocol
= protstring
.substr(10);
91 //We can now construct the correct path
92 size_t doubleslash
= uri
.find("//");
93 //The path is incorrectly formed without // after the first protocol
94 if(doubleslash
== wxString::npos
)
97 wxString fspath
= "file:" +
98 EscapeFileNameCharsInURL(mainpath
.substr(doubleslash
+ 2))
99 + "#" + protocol
+":" + archivepath
;
100 return m_fileSystem
->OpenFile(fspath
);