2 * This code shows how to read a zipfile included in an app's binary.
4 * License: this code is public domain. I make no warranty that it is useful,
5 * correct, harmless, or environmentally safe.
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
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.
17 * This file was written by Ryan C. Gordon. (icculus@icculus.org).
21 * Compile this program and then attach a .zip file to the end of the
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
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.
37 int main(int argc, char **argv)
41 if (!PHYSFS_init(argv[0]))
43 printf("PHYSFS_init() failed: %s\n", PHYSFS_getLastError());
47 rc = PHYSFS_addToSearchPath(argv[0], 0);
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");
55 char **files = PHYSFS_enumerateFiles("/");
57 for (i = files; *i != NULL; i++)
59 const char *dirorfile = PHYSFS_isDirectory(*i) ? "Directory" : "File";
60 printf(" * %s '%s' is in root of attached data.\n", dirorfile, *i);
62 PHYSFS_freeList(files);