Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * This code shows how to read a zipfile included in an app's binary. |
||
3 | * |
||
4 | * License: this code is public domain. I make no warranty that it is useful, |
||
5 | * correct, harmless, or environmentally safe. |
||
6 | * |
||
7 | * This particular file may be used however you like, including copying it |
||
8 | * verbatim into a closed-source project, exploiting it commercially, and |
||
9 | * removing any trace of my name from the source (although I hope you won't |
||
10 | * do that). I welcome enhancements and corrections to this file, but I do |
||
11 | * not require you to send me patches if you make changes. This code has |
||
12 | * NO WARRANTY. |
||
13 | * |
||
14 | * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license. |
||
15 | * Please see LICENSE.txt in the root of the source tree. |
||
16 | * |
||
17 | * This file was written by Ryan C. Gordon. (icculus@icculus.org). |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * Compile this program and then attach a .zip file to the end of the |
||
22 | * compiled binary. |
||
23 | * |
||
24 | * On Linux, something like this will build the final binary: |
||
25 | * gcc -o selfextract.tmp selfextract.c -lphysfs && \ |
||
26 | * cat selfextract.tmp myzipfile.zip >> selfextract && \ |
||
27 | * chmod a+x selfextract && \ |
||
28 | * rm -f selfextract.tmp |
||
29 | * |
||
30 | * This may not work on all platforms, and it probably only works with |
||
31 | * .zip files, since they are designed to be appended to another file. |
||
32 | */ |
||
33 | |||
34 | #include <stdio.h> |
||
35 | #include "physfs.h" |
||
36 | |||
37 | int main(int argc, char **argv) |
||
38 | { |
||
39 | int rc = 0; |
||
40 | |||
41 | if (!PHYSFS_init(argv[0])) |
||
42 | { |
||
43 | printf("PHYSFS_init() failed: %s\n", PHYSFS_getLastError()); |
||
44 | return 42; |
||
45 | } /* if */ |
||
46 | |||
47 | rc = PHYSFS_addToSearchPath(argv[0], 0); |
||
48 | if (!rc) |
||
49 | { |
||
50 | printf("Couldn't find self-extract data: %s\n", PHYSFS_getLastError()); |
||
51 | printf("This might mean you didn't append a zipfile to the binary.\n"); |
||
52 | return 42; |
||
53 | } /* if */ |
||
54 | |||
55 | char **files = PHYSFS_enumerateFiles("/"); |
||
56 | char **i; |
||
57 | for (i = files; *i != NULL; i++) |
||
58 | { |
||
59 | const char *dirorfile = PHYSFS_isDirectory(*i) ? "Directory" : "File"; |
||
60 | printf(" * %s '%s' is in root of attached data.\n", dirorfile, *i); |
||
61 | } /* for */ |
||
62 | PHYSFS_freeList(files); |
||
63 | |||
64 | return 0; |
||
65 | } /* main */ |
||
66 |