2 * capturewim.c - A program to capture a directory tree into a WIM file.
8 #define TO_PERCENT(numerator, denominator) \
9 ((float)(((denominator) == 0) ? 0 : ((numerator) * 100 / (float)(denominator))))
12 write_progress(enum wimlib_progress_msg msg,
13 const union wimlib_progress_info *info)
16 case WIMLIB_PROGRESS_MSG_WRITE_STREAMS:
17 printf("Writing WIM: %.2f%% complete\n",
18 TO_PERCENT(info->write_streams.completed_bytes,
19 info->write_streams.total_bytes));
27 int main(int argc, char **argv)
30 WIMStruct *wim = NULL;
34 /* Check for the correct number of arguments. */
36 fprintf(stderr, "Usage: capturewim DIR WIM\n");
43 /* Create a WIMStruct for a WIM. */
44 ret = wimlib_create_new_wim(WIMLIB_COMPRESSION_TYPE_LZX, &wim);
45 if (ret != 0) /* Always should check the error codes. */
48 /* Add the directory tree to the WIMStruct as an image. */
50 ret = wimlib_add_image(wim, /* WIMStruct to which to add the image */
51 srcdir, /* Directory from which to add the image */
52 NULL, /* Name to give the image (NULL means none) */
53 NULL, /* Capture configuration structure (NULL means none) */
54 0, /* WIMLIB_ADD_FLAG_* flags (0 means all defaults) */
55 NULL); /* Progress function (NULL means none) */
59 /* Write the WIM file. */
61 ret = wimlib_write(wim, /* WIMStruct from which to write a WIM */
62 wimpath, /* Path to write the WIM to */
63 WIMLIB_ALL_IMAGES, /* Image(s) in the WIM to write */
64 0, /* WIMLIB_WRITE_FLAG_* flags (0 means all defaults) */
65 0, /* Number of compressor threads (0 means default) */
66 write_progress); /* Progress function */
69 /* Free the WIMStruct. Has no effect if the pointer to it is NULL. */
72 /* Check for error status. */
74 fprintf(stderr, "wimlib error %d: %s\n",
75 ret, wimlib_get_error_string(ret));
78 /* Free global memory (optional). */
79 wimlib_global_cleanup();