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))))
11 static enum wimlib_progress_status
12 write_progress(enum wimlib_progress_msg msg,
13 union wimlib_progress_info *info, void *progctx)
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));
24 return WIMLIB_PROGRESS_STATUS_CONTINUE;
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 /* Register our progress function. */
49 wimlib_register_progress_function(wim, write_progress, NULL);
51 /* Add the directory tree to the WIMStruct as an image. */
53 ret = wimlib_add_image(wim, /* WIMStruct to which to add the image */
54 srcdir, /* Directory from which to add the image */
55 NULL, /* Name to give the image (NULL means none) */
56 NULL, /* Capture configuration structure (NULL means none) */
57 0); /* WIMLIB_ADD_FLAG_* flags (0 means all defaults) */
61 /* Write the WIM file. */
63 ret = wimlib_write(wim, /* WIMStruct from which to write a WIM */
64 wimpath, /* Path to write the WIM to */
65 WIMLIB_ALL_IMAGES, /* Image(s) in the WIM to write */
66 0, /* WIMLIB_WRITE_FLAG_* flags (0 means all defaults) */
67 0); /* Number of compressor threads (0 means default) */
70 /* Free the WIMStruct. Has no effect if the pointer to it is NULL. */
73 /* Check for error status. */
75 fprintf(stderr, "wimlib error %d: %s\n",
76 ret, wimlib_get_error_string(ret));
79 /* Free global memory (optional). */
80 wimlib_global_cleanup();