2 * applywim.c - A program to extract the first image from a WIM file.
4 * The following copying information applies to this specific source code file:
6 * Written in 2013-2014 by Eric Biggers <ebiggers3@gmail.com>
8 * To the extent possible under law, the author(s) have dedicated all copyright
9 * and related and neighboring rights to this software to the public domain
10 * worldwide via the Creative Commons Zero 1.0 Universal Public Domain
11 * Dedication (the "CC0").
13 * This software is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the CC0 for more details.
17 * You should have received a copy of the CC0 along with this software; if not
18 * see <http://creativecommons.org/publicdomain/zero/1.0/>.
24 #define TO_PERCENT(numerator, denominator) \
25 ((float)(((denominator) == 0) ? 0 : ((numerator) * 100 / (float)(denominator))))
27 static enum wimlib_progress_status
28 extract_progress(enum wimlib_progress_msg msg,
29 union wimlib_progress_info *info, void *progctx)
32 case WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS:
33 printf("Extracting files: %.2f%% complete\n",
34 TO_PERCENT(info->extract.completed_bytes,
35 info->extract.total_bytes));
40 return WIMLIB_PROGRESS_STATUS_CONTINUE;
43 int main(int argc, char **argv)
46 WIMStruct *wim = NULL;
50 /* Check for the correct number of arguments. */
52 fprintf(stderr, "Usage: applywim WIM DIR\n");
59 /* Open the WIM file as a WIMStruct. */
60 ret = wimlib_open_wim(wimpath, /* Path of WIM file to open */
61 0, /* WIMLIB_OPEN_FLAG_* flags (0 means all defaults) */
62 &wim); /* Return the WIMStruct pointer in this location */
63 if (ret != 0) /* Always should check the error codes. */
66 /* Register our progress function. */
67 wimlib_register_progress_function(wim, extract_progress, NULL);
69 /* Extract the first image. */
70 ret = wimlib_extract_image(wim, /* WIMStruct from which to extract the image */
71 1, /* Image to extract */
72 destdir, /* Directory to extract the image to */
73 0); /* WIMLIB_EXTRACT_FLAG_* flags (0 means all defaults) */
76 /* Free the WIMStruct. Has no effect if the pointer to it is NULL. */
79 /* Check for error status. */
81 fprintf(stderr, "wimlib error %d: %s\n",
82 ret, wimlib_get_error_string(ret));
85 /* Free global memory (optional). */
86 wimlib_global_cleanup();