author | David Yip <dwyip@peach-bun.com> |
Mon, 15 Aug 2016 00:50:58 -0500 | |
changeset 1375 | 20ee02ea086c |
parent 1016 | 957c97389257 |
child 1631 | 1aec60db9326 |
permissions | -rw-r--r-- |
633 | 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. |
|
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
767
diff
changeset
|
15 |
* Please see LICENSE.txt in the root of the source tree. |
633 | 16 |
* |
767
db29bf06d171
Changed my email address.
Ryan C. Gordon <icculus@icculus.org>
parents:
633
diff
changeset
|
17 |
* This file was written by Ryan C. Gordon. (icculus@icculus.org). |
633 | 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()); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
44 |
return 42; |
633 | 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"); |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
52 |
return 42; |
633 | 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 |
||
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
64 |
return 0; |
633 | 65 |
} /* main */ |
66 |