+
+ /* If capturing a delta WIM, reference resources from the base WIMs
+ * before adding the new image. */
+ if (base_wimfiles.num_strings) {
+ base_wims = calloc(base_wimfiles.num_strings,
+ sizeof(base_wims[0]));
+ if (base_wims == NULL) {
+ imagex_error(T("Out of memory!"));
+ ret = -1;
+ goto out_free_wim;
+ }
+
+ for (size_t i = 0; i < base_wimfiles.num_strings; i++) {
+ ret = wimlib_open_wim(base_wimfiles.strings[i],
+ open_flags, &base_wims[i],
+ imagex_progress_func);
+ if (ret)
+ goto out_free_base_wims;
+
+ }
+
+ ret = wimlib_reference_resources(wim, base_wims,
+ base_wimfiles.num_strings, 0);
+ if (ret)
+ goto out_free_base_wims;
+
+ if (base_wimfiles.num_strings == 1) {
+ imagex_printf(T("Capturing delta WIM based on \"%"TS"\"\n"),
+ base_wimfiles.strings[0]);
+ } else {
+ imagex_printf(T("Capturing delta WIM based on %u WIMs\n"),
+ base_wimfiles.num_strings);
+ }
+
+ } else {
+ base_wims = NULL;
+ }
+
+ /* If capturing or appending as an update of an existing (template) image,
+ * open the WIM if needed and parse the image index. */
+ if (template_image_name_or_num) {
+
+
+ if (base_wimfiles.num_strings == 1 &&
+ template_wimfile == base_wimfiles.strings[0]) {
+ template_wim = base_wims[0];
+ } else if (template_wimfile == wimfile) {
+ template_wim = wim;
+ } else {
+ ret = wimlib_open_wim(template_wimfile, open_flags,
+ &template_wim, imagex_progress_func);
+ if (ret)
+ goto out_free_base_wims;
+ }
+
+ template_image = wimlib_resolve_image(template_wim,
+ template_image_name_or_num);
+
+ if (template_image_name_or_num[0] == T('-')) {
+ tchar *tmp;
+ unsigned long n;
+ struct wimlib_wim_info info;
+
+ wimlib_get_wim_info(template_wim, &info);
+ n = tstrtoul(template_image_name_or_num + 1, &tmp, 10);
+ if (n >= 1 && n <= info.image_count &&
+ *tmp == T('\0') &&
+ tmp != template_image_name_or_num + 1)
+ {
+ template_image = info.image_count - (n - 1);
+ }
+ }
+ ret = verify_image_exists_and_is_single(template_image,
+ template_image_name_or_num,
+ template_wimfile);
+ if (ret)
+ goto out_free_template_wim;
+ } else {
+ template_wim = NULL;
+ }