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))))
11 static enum wimlib_progress_status
12 extract_progress(enum wimlib_progress_msg msg,
13 union wimlib_progress_info *info, void *progctx)
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));
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: 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 if (ret != 0) /* Always should check the error codes. */
50 /* Register our progress function. */
51 wimlib_register_progress_function(wim, extract_progress, NULL);
53 /* Extract the first image. */
54 ret = wimlib_extract_image(wim, /* WIMStruct from which to extract the image */
55 1, /* Image to extract */
56 destdir, /* Directory to extract the image to */
57 0); /* WIMLIB_EXTRACT_FLAG_* flags (0 means all defaults) */
60 /* Free the WIMStruct. Has no effect if the pointer to it is NULL. */
63 /* Check for error status. */
65 fprintf(stderr, "wimlib error %d: %s\n",
66 ret, wimlib_get_error_string(ret));
69 /* Free global memory (optional). */
70 wimlib_global_cleanup();