2 * applywim.c - A program to extract the first image from a WIM file.
8 #define TO_PERCENT(numerator, denominator) \
9 ((float)(((denominator) == 0) ? 0 : ((numerator) * 100 / (float)(denominator))))
12 extract_progress(enum wimlib_progress_msg msg,
13 const union wimlib_progress_info *info)
16 case WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS:
17 printf("Extracting files: %.2f%% complete\n",
18 TO_PERCENT(info->extract.completed_bytes,
19 info->extract.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: applywim WIM DIR\n");
43 /* Open the WIM file as a WIMStruct. */
44 ret = wimlib_open_wim(wimpath, /* Path of WIM file to open */
45 0, /* WIMLIB_OPEN_FLAG_* flags (0 means all defaults) */
46 &wim, /* Return the WIMStruct pointer in this location */
47 NULL); /* Progress function (NULL means none) */
48 if (ret != 0) /* Always should check the error codes. */
51 /* Extract the first image. */
52 ret = wimlib_extract_image(wim, /* WIMStruct from which to extract the image */
53 1, /* Image to extract */
54 destdir, /* Directory to extract the image to */
55 0, /* WIMLIB_EXTRACT_FLAG_* flags (0 means all defaults) */
56 extract_progress); /* Progress function */
59 /* Free the WIMStruct. Has no effect if the pointer to it is NULL. */
62 /* Check for error status. */
64 fprintf(stderr, "wimlib error %d: %s\n",
65 ret, wimlib_get_error_string(ret));
68 /* Free global memory (optional). */
69 wimlib_global_cleanup();