diff options
Diffstat (limited to 'makecab.c')
-rw-r--r-- | makecab.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/makecab.c b/makecab.c new file mode 100644 index 0000000..ec4ba05 --- /dev/null +++ b/makecab.c | |||
@@ -0,0 +1,86 @@ | |||
1 | #include <stdint.h> | ||
2 | |||
3 | #include <err.h> | ||
4 | |||
5 | #include "memory.h" | ||
6 | #include "dupstr.h" | ||
7 | #include "subproc.h" | ||
8 | #include "uchars.h" | ||
9 | |||
10 | typedef struct CabCreateContext { | ||
11 | char *outfile; | ||
12 | |||
13 | char **args; | ||
14 | int nargs, argsize; | ||
15 | } CabCreateContext; | ||
16 | |||
17 | uint32_t CreateCabBegin(const char16_t *wzCab, const char16_t *wzCabDir, | ||
18 | uint32_t dwMaxFiles, uint32_t dwMaxSize, | ||
19 | uint32_t dwMaxThresh, int compression, | ||
20 | CabCreateContext **out_ctx) | ||
21 | { | ||
22 | CabCreateContext *ctx = snew(CabCreateContext); | ||
23 | char *outdir = ascii(wzCabDir, true); | ||
24 | char *cab = ascii(wzCab, true); | ||
25 | ctx->outfile = dupcat(outdir, "/", cab, cNULL); | ||
26 | sfree(cab); | ||
27 | sfree(outdir); | ||
28 | ctx->nargs = 0; | ||
29 | ctx->argsize = 16; | ||
30 | ctx->args = snewn(ctx->argsize, char *); | ||
31 | ctx->args[ctx->nargs++] = dupcat(getenv("WIX"), "/", "makecab.py", cNULL); | ||
32 | ctx->args[ctx->nargs++] = ctx->outfile; | ||
33 | *out_ctx = ctx; | ||
34 | return 0; | ||
35 | } | ||
36 | |||
37 | uint32_t CreateCabAddFile(const char16_t *wzFile, const char16_t *wzToken, | ||
38 | void *pmfHash, CabCreateContext *ctx) | ||
39 | { | ||
40 | char *file = ascii(wzFile, true); | ||
41 | char *file_abs = realpath(file, NULL); | ||
42 | char *cabname = ascii(wzToken, true); | ||
43 | warnx("CreateCabAddFile: %s :: %s <- %s", ctx->outfile, | ||
44 | cabname, file_abs); | ||
45 | if (ctx->nargs + 1 >= ctx->argsize) { | ||
46 | ctx->argsize = ctx->nargs * 5 / 4 + 16; | ||
47 | ctx->args = sresize(ctx->args, ctx->argsize, char *); | ||
48 | } | ||
49 | ctx->args[ctx->nargs++] = cabname; | ||
50 | ctx->args[ctx->nargs++] = file_abs; | ||
51 | sfree(file); | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | uint32_t CreateCabAddFiles(const char16_t *const *pwzFiles, | ||
56 | const char16_t *const *pwzTokens, | ||
57 | void *pmfHash, uint32_t cFiles, | ||
58 | CabCreateContext *ctx) | ||
59 | { | ||
60 | for (uint32_t i = 0; i < cFiles; i++) | ||
61 | CreateCabAddFile(pwzFiles[i], pwzTokens[i], pmfHash, ctx); | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | void CreateCabCancel(CabCreateContext *ctx) | ||
66 | { | ||
67 | for (int i = 0; i < ctx->nargs; i++) | ||
68 | sfree(ctx->args[i]); | ||
69 | sfree(ctx->args); | ||
70 | sfree(ctx->outfile); | ||
71 | sfree(ctx); | ||
72 | } | ||
73 | |||
74 | uint32_t CreateCabFinish(CabCreateContext *ctx, void (*split_callback)(void)) | ||
75 | { | ||
76 | if (ctx->nargs + 1 >= ctx->argsize) { | ||
77 | ctx->argsize = ctx->nargs * 5 / 4 + 16; | ||
78 | ctx->args = sresize(ctx->args, ctx->argsize, char *); | ||
79 | } | ||
80 | ctx->args[ctx->nargs++] = NULL; | ||
81 | system_argv_array(ctx->args); | ||
82 | |||
83 | CreateCabCancel(ctx); /* free everything */ | ||
84 | |||
85 | return 0; | ||
86 | } | ||