Skip to content

Latest commit

 

History

History
66 lines (58 loc) · 2.07 KB

selfextract.c

File metadata and controls

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