]>
Commit | Line | Data |
---|---|---|
ccaaf5b0 | 1 | \section{wxFileSystem}\label{fs} |
704a4b75 | 2 | |
b453e1b2 RR |
3 | The wxHTML library uses a {\bf virtual file systems} mechanism |
4 | similar to the one used in Midnight Commander, Dos Navigator, | |
f6bcfd97 BP |
5 | FAR or almost any modern file manager. It allows the user to access |
6 | data stored in archives as if they were ordinary files. On-the-fly | |
7 | generated files that exist only in memory are also supported. | |
704a4b75 VS |
8 | |
9 | \wxheading{Classes} | |
10 | ||
f6bcfd97 | 11 | Three classes are used in order to provide virtual file systems mechanism: |
704a4b75 | 12 | |
22d6efa8 | 13 | \begin{itemize}\itemsep=0pt |
b453e1b2 | 14 | \item The \helpref{wxFSFile}{wxfsfile} class provides information |
f6bcfd97 | 15 | about opened file (name, input stream, mime type and anchor). |
b453e1b2 RR |
16 | \item The \helpref{wxFileSystem}{wxfilesystem} class is the interface. |
17 | Its main methods are ChangePathTo() and OpenFile(). This class | |
704a4b75 | 18 | is most often used by the end user. |
b453e1b2 | 19 | \item The \helpref{wxFileSystemHandler}{wxfilesystemhandler} is the core |
f6bcfd97 BP |
20 | of virtual file systems mechanism. You can derive your own handler and pass it to |
21 | of the VFS mechanism. You can derive your own handler and pass it to | |
704a4b75 | 22 | wxFileSystem's AddHandler() method. In the new handler you only need to |
f6bcfd97 | 23 | override the OpenFile() and CanOpen() methods. |
704a4b75 VS |
24 | \end{itemize} |
25 | ||
26 | \wxheading{Locations} | |
27 | ||
f6bcfd97 | 28 | Locations (aka filenames aka addresses) are constructed from four parts: |
704a4b75 | 29 | |
22d6efa8 | 30 | \begin{itemize}\itemsep=0pt |
b453e1b2 RR |
31 | \item {\bf protocol} - handler can recognize if it is able to open a |
32 | file by checking its protocol. Examples are "http", "file" or "ftp". | |
704a4b75 | 33 | \item {\bf right location} - is the name of file within the protocol. |
b453e1b2 | 34 | In "http://www.wxwindows.org/index.html" the right location is "//www.wxwindows.org/index.html". |
f6bcfd97 | 35 | \item {\bf anchor} - an anchor is optional and is usually not present. |
b453e1b2 | 36 | In "index.htm\#chapter2" the anchor is "chapter2". |
b453e1b2 | 37 | \item {\bf left location} - this is usually an empty string. |
704a4b75 VS |
38 | It is used by 'local' protocols such as ZIP. |
39 | See Combined Protocols paragraph for details. | |
40 | \end{itemize} | |
41 | ||
42 | \wxheading{Combined Protocols} | |
43 | ||
f6bcfd97 BP |
44 | The left location precedes the protocol in the URL string. |
45 | It is not used by global protocols like HTTP but it becomes handy when nesting | |
46 | protocols - for example you may want to access files in ZIP archive that is | |
47 | located on some FTP server: | |
48 | ||
49 | ftp:ftp.archives.org/pub/cpp\_doc.zip\#zip:reference/fopen.htm\#syntax | |
50 | ||
51 | In fact, you have to use 'left location' even when accessing local ZIPs: | |
704a4b75 VS |
52 | |
53 | file:archives/cpp\_doc.zip\#zip:reference/fopen.htm\#syntax | |
54 | ||
f6bcfd97 BP |
55 | In this example, the protocol is "zip", the left location is |
56 | "reference/fopen.htm", the anchor is "syntax" and the right location | |
57 | is "file:archives/cpp\_doc.zip". | |
704a4b75 | 58 | |
f6bcfd97 | 59 | There are {\bf two} protocols used in this example: "zip" and "file". |
704a4b75 VS |
60 | You can construct even more complicated addresses like this one: |
61 | ||
62 | http://www.archives.org/myarchive.zip\#zip:local/docs/cpp/stdio.zip\#zip:index.htm | |
63 | ||
f6bcfd97 BP |
64 | In this example you access zip virtual file system stdio.zip stored in another zip (myarchive.zip) |
65 | which can be found at WWW. | |
704a4b75 VS |
66 | |
67 | \wxheading{File Systems Included in wxHTML} | |
68 | ||
f6bcfd97 | 69 | The following virtual file system handlers are part of wxWindows so far: |
cadd476d VS |
70 | |
71 | \begin{twocollist} | |
f6bcfd97 | 72 | \twocolitem{{\bf wxInternetFSHandler}}{A handler for accessing documents |
cadd476d | 73 | via HTTP or FTP protocols. Include file is <wx/fs_inet.h>.} |
f6bcfd97 | 74 | \twocolitem{{\bf wxZipFSHandler}}{A handler for ZIP archives. |
cadd476d VS |
75 | Include file is <wx/fs_zip.h>. URL is in form "archive.zip\#zip:filename".} |
76 | \twocolitem{{\bf wxMemoryFSHandler}}{This handler allows you to access | |
77 | data stored in memory (such as bitmaps) as if they were regular files. | |
78 | See \helpref{wxMemoryFSHandler documentation}{wxmemoryfshandler} for details. | |
79 | Include file is <wx/fs_mem.h>. UURL is prefixed with memory:, e.g. | |
80 | "memory:myfile.htm"} | |
81 | \end{twocollist} | |
82 | ||
f6bcfd97 BP |
83 | In addition, wxFileSystem itself can access local files. |
84 | ||
cadd476d | 85 | |
f6bcfd97 | 86 | \wxheading{Initializing file system handlers} |
cadd476d VS |
87 | |
88 | Use \helpref{wxFileSystem::AddHandler}{wxfilesystemaddhandler} to initialize | |
89 | a handler, for example: | |
90 | ||
91 | \begin{verbatim} | |
92 | #include <wx/fs_mem.h> | |
93 | ||
94 | ... | |
95 | ||
96 | bool MyApp::OnInit() | |
97 | { | |
98 | wxFileSystem::AddHandler(new wxMemoryFSHandler); | |
99 | ... | |
f6bcfd97 | 100 | } |
cadd476d VS |
101 | \end{verbatim} |
102 |