+
+ /* If capturing a delta WIM, reference resources from the base WIM
+ * before adding the new image. */
+ if (base_wimfile) {
+ ret = wimlib_open_wim(base_wimfile, open_flags,
+ &base_wim, imagex_progress_func);
+ if (ret)
+ goto out_free_wim;
+
+ imagex_printf(T("Capturing delta WIM based on \"%"TS"\"\n"),
+ base_wimfile);
+
+ ret = wimlib_reference_resources(wim, &base_wim, 1, 0);
+ if (ret)
+ goto out_free_base_wim;
+ } else {
+ base_wim = 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 (template_wimfile == base_wimfile) {
+ template_wim = base_wim;
+ } 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_wim;
+ }
+
+ 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;
+ }
+