]> wimlib.net Git - wimlib/blob - examples/makewim.c
imagex_update(): Error if no image specified with multi-image WIM
[wimlib] / examples / makewim.c
1 /*
2  * makewim.c - A simple program to make a LZX-compressed WIM file from a
3  * directory.
4  */
5
6 #include <wimlib.h>
7 #include <stdio.h>
8
9 int main(int argc, char **argv)
10 {
11         int ret;
12         WIMStruct *wim;
13
14         if (argc != 3) {
15                 fprintf(stderr, "Usage: makewim DIR WIM\n");
16                 ret = 2;
17                 goto out;
18         }
19
20         /* Initialize the library. */
21         ret = wimlib_global_init(0);
22         if (ret)
23                 goto out;
24
25         /* Create a WIMStruct for a LZX-compressed WIM. */
26         ret = wimlib_create_new_wim(WIMLIB_COMPRESSION_TYPE_LZX, &wim);
27         if (ret)
28                 goto out_wimlib_global_cleanup;
29
30         /* Add the directory tree to the WIMStruct as an image. */
31         ret = wimlib_add_image(wim, argv[1], "1", NULL, 0, NULL);
32         if (ret)
33                 goto out_wimlib_free;
34
35         /* Write the desired WIM file. */
36         ret = wimlib_write(wim, argv[2], WIMLIB_ALL_IMAGES, 0, 0, NULL);
37
38 out_wimlib_free:
39         /* Free the WIM file */
40         wimlib_free(wim);
41
42 out_wimlib_global_cleanup:
43         /* Finalize the library */
44         wimlib_global_cleanup();
45 out:
46         return ret;
47 }