diff options
author | Simon Tatham <anakin@pobox.com> | 2017-05-18 08:17:57 +0100 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2017-05-18 08:19:55 +0100 |
commit | 7ca5ab5ef2eb8bb0f65aedf11eb74ad2ada78a19 (patch) | |
tree | 592d68de8ae1edf910d9f4e783fecacb35df05cd | |
parent | 39faf94ea2fa54f6791641142ad03e7e4f884a69 (diff) | |
download | wix-on-linux-7ca5ab5ef2eb8bb0f65aedf11eb74ad2ada78a19.tar.gz wix-on-linux-7ca5ab5ef2eb8bb0f65aedf11eb74ad2ada78a19.tar.bz2 wix-on-linux-7ca5ab5ef2eb8bb0f65aedf11eb74ad2ada78a19.zip |
Move CAB-creation routines into their own file.
Also tidy up some of the memory management, while I'm here.
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | fake-winterop.c | 67 | ||||
-rw-r--r-- | makecab.c | 86 |
3 files changed, 88 insertions, 69 deletions
diff --git a/Makefile.am b/Makefile.am index b23c901..a113320 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -4,8 +4,8 @@ ACLOCAL_AMFLAGS = -I m4 | |||
4 | 4 | ||
5 | lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la | 5 | lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la |
6 | 6 | ||
7 | libwinterop_so_la_SOURCES = fake-winterop.c memory.c memory.h \ | 7 | libwinterop_so_la_SOURCES = fake-winterop.c makecab.c memory.c \ |
8 | dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h | 8 | memory.h dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h |
9 | 9 | ||
10 | libmsi_so_la_SOURCES = fake-msi.c md5.c memory.c memory.h version.c \ | 10 | libmsi_so_la_SOURCES = fake-msi.c md5.c memory.c memory.h version.c \ |
11 | dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h | 11 | dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h |
diff --git a/fake-winterop.c b/fake-winterop.c index d238784..755853f 100644 --- a/fake-winterop.c +++ b/fake-winterop.c | |||
@@ -28,73 +28,6 @@ uint32_t ResetAcls(const char16_t **pwzFiles, uint32_t cFiles) | |||
28 | return 0; | 28 | return 0; |
29 | } | 29 | } |
30 | 30 | ||
31 | typedef struct CabCreateContext { | ||
32 | char *outdir; | ||
33 | char *outfile; | ||
34 | |||
35 | char **args; | ||
36 | int nargs, argsize; | ||
37 | } CabCreateContext; | ||
38 | |||
39 | uint32_t CreateCabBegin(const char16_t *wzCab, const char16_t *wzCabDir, | ||
40 | uint32_t dwMaxFiles, uint32_t dwMaxSize, | ||
41 | uint32_t dwMaxThresh, int compression, | ||
42 | CabCreateContext **out_ctx) | ||
43 | { | ||
44 | CabCreateContext *ctx = snew(CabCreateContext); | ||
45 | ctx->outdir = ascii(wzCabDir, true); | ||
46 | ctx->outfile = dupcat(ctx->outdir, "/", ascii(wzCab, true), cNULL); | ||
47 | ctx->nargs = 0; | ||
48 | ctx->argsize = 16; | ||
49 | ctx->args = snewn(ctx->argsize, char *); | ||
50 | ctx->args[ctx->nargs++] = dupcat(getenv("WIX"), "/", "makecab.py", cNULL); | ||
51 | ctx->args[ctx->nargs++] = ctx->outfile; | ||
52 | *out_ctx = ctx; | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | uint32_t CreateCabAddFile(const char16_t *wzFile, const char16_t *wzToken, | ||
57 | void *pmfHash, CabCreateContext *ctx) | ||
58 | { | ||
59 | char *file = ascii(wzFile, true); | ||
60 | char *file_abs = realpath(file, NULL); | ||
61 | char *cabname = ascii(wzToken, true); | ||
62 | printf("CreateCabAddFile: %s :: %s <- %s\n", ctx->outfile, | ||
63 | cabname, file_abs); | ||
64 | if (ctx->nargs + 1 >= ctx->argsize) { | ||
65 | ctx->argsize = ctx->nargs * 5 / 4 + 16; | ||
66 | ctx->args = sresize(ctx->args, ctx->argsize, char *); | ||
67 | } | ||
68 | ctx->args[ctx->nargs++] = cabname; | ||
69 | ctx->args[ctx->nargs++] = file_abs; | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | uint32_t CreateCabAddFiles(const char16_t *const *pwzFiles, | ||
74 | const char16_t *const *pwzTokens, | ||
75 | void *pmfHash, uint32_t cFiles, | ||
76 | CabCreateContext *ctx) | ||
77 | { | ||
78 | for (uint32_t i = 0; i < cFiles; i++) | ||
79 | CreateCabAddFile(pwzFiles[i], pwzTokens[i], pmfHash, ctx); | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | uint32_t CreateCabFinish(CabCreateContext *ctx, void (*split_callback)(void)) | ||
84 | { | ||
85 | if (ctx->nargs + 1 >= ctx->argsize) { | ||
86 | ctx->argsize = ctx->nargs * 5 / 4 + 16; | ||
87 | ctx->args = sresize(ctx->args, ctx->argsize, char *); | ||
88 | } | ||
89 | ctx->args[ctx->nargs++] = NULL; | ||
90 | system_argv_array(ctx->args); | ||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | void CreateCabCancel(void *hContext) | ||
95 | { | ||
96 | } | ||
97 | |||
98 | uint32_t ExtractCabBegin(void) | 31 | uint32_t ExtractCabBegin(void) |
99 | { | 32 | { |
100 | return 0; | 33 | return 0; |
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 | } | ||