* String that specifies the 1-based index or name of the image to extract.
* It is translated to an image index using the same rules that
* wimlib_resolve_image() uses. However, unlike wimlib_extract_image(),
- * only a single image (not all images) can be specified.
+ * only a single image (not all images) can be specified. Alternatively,
+ * specify @p NULL here to use the first image in the WIM if it contains
+ * exactly one image but otherwise return @p WIMLIB_ERR_INVALID_IMAGE.
* @param target
* Same as the corresponding parameter to wimlib_extract_image().
* @param extract_flags
if (!tstrcmp(wimfile, T("-"))) {
/* Attempt to apply pipable WIM from standard input. */
- if (argc < 3) {
- imagex_error(T("Imagex index or name must be explicitly "
- "specified when applying pipable WIM on "
- "standard input."));
- goto out_usage;
+ if (argc == 2) {
+ image_num_or_name = NULL;
+ target = argv[1];
+ } else {
+ image_num_or_name = argv[1];
+ target = argv[2];
}
- image_num_or_name = argv[1];
- target = argv[2];
wim = NULL;
num_additional_swms = 0;
additional_swms = NULL;
/* Get image index (this may use the XML data that was just read to
* resolve an image name). */
- image = wimlib_resolve_image(pwm, image_num_or_name);
- if (image == WIMLIB_NO_IMAGE) {
- ERROR("\"%"TS"\" is not a valid image in the pipable WIM!",
- image_num_or_name);
- ret = WIMLIB_ERR_INVALID_IMAGE;
- goto out_wimlib_free;
- } else if (image == WIMLIB_ALL_IMAGES) {
- ERROR("Applying all images from a pipe is not supported.");
- ret = WIMLIB_ERR_INVALID_IMAGE;
- goto out_wimlib_free;
+ if (image_num_or_name) {
+ image = wimlib_resolve_image(pwm, image_num_or_name);
+ if (image == WIMLIB_NO_IMAGE) {
+ ERROR("\"%"TS"\" is not a valid image in the pipable WIM!",
+ image_num_or_name);
+ ret = WIMLIB_ERR_INVALID_IMAGE;
+ goto out_wimlib_free;
+ } else if (image == WIMLIB_ALL_IMAGES) {
+ ERROR("Applying all images from a pipe is not supported.");
+ ret = WIMLIB_ERR_INVALID_IMAGE;
+ goto out_wimlib_free;
+ }
+ } else {
+ if (pwm->hdr.image_count != 1) {
+ ERROR("No image was specified, but the pipable WIM "
+ "did not contain exactly 1 image");
+ ret = WIMLIB_ERR_INVALID_IMAGE;
+ goto out_wimlib_free;
+ }
+ image = 1;
}
/* Load the needed metadata resource. */