2 * applywim.c - A program to extract the first image from a WIM file.
4 * The author dedicates this file to the public domain.
5 * You can do whatever you want with this file.
11 #define TO_PERCENT(numerator, denominator) \
12 ((float)(((denominator) == 0) ? 0 : ((numerator) * 100 / (float)(denominator))))
14 static enum wimlib_progress_status
15 extract_progress(enum wimlib_progress_msg msg,
16 union wimlib_progress_info *info, void *progctx)
19 case WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS:
20 printf("Extracting files: %.2f%% complete\n",
21 TO_PERCENT(info->extract.completed_bytes,
22 info->extract.total_bytes));
27 return WIMLIB_PROGRESS_STATUS_CONTINUE;
30 int main(int argc, char **argv)
33 WIMStruct *wim = NULL;
37 /* Check for the correct number of arguments. */
39 fprintf(stderr, "Usage: applywim WIM DIR\n");
46 /* Open the WIM file as a WIMStruct. */
47 ret = wimlib_open_wim(wimpath, /* Path of WIM file to open */
48 0, /* WIMLIB_OPEN_FLAG_* flags (0 means all defaults) */
49 &wim); /* Return the WIMStruct pointer in this location */
50 if (ret != 0) /* Always should check the error codes. */
53 /* Register our progress function. */
54 wimlib_register_progress_function(wim, extract_progress, NULL);
56 /* Extract the first image. */
57 ret = wimlib_extract_image(wim, /* WIMStruct from which to extract the image */
58 1, /* Image to extract */
59 destdir, /* Directory to extract the image to */
60 0); /* WIMLIB_EXTRACT_FLAG_* flags (0 means all defaults) */
63 /* Free the WIMStruct. Has no effect if the pointer to it is NULL. */
66 /* Check for error status. */
68 fprintf(stderr, "wimlib error %d: %s\n",
69 ret, wimlib_get_error_string(ret));
72 /* Free global memory (optional). */
73 wimlib_global_cleanup();