+
+ if (compression_level != 0)
+ wimlib_set_default_compression_level(ctype, compression_level);
+ return ctype;
+}
+
+/* Parse the argument to --compact */
+static int
+set_compact_mode(const tchar *arg, int *extract_flags)
+{
+ int flag = 0;
+ if (!tstrcasecmp(arg, T("xpress4k")))
+ flag = WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K;
+ else if (!tstrcasecmp(arg, T("xpress8k")))
+ flag = WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K;
+ else if (!tstrcasecmp(arg, T("xpress16k")))
+ flag = WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K;
+ else if (!tstrcasecmp(arg, T("lzx")))
+ flag = WIMLIB_EXTRACT_FLAG_COMPACT_LZX;
+
+ if (flag) {
+ *extract_flags |= flag;
+ return 0;
+ }
+
+ imagex_error(T(
+"\"%"TS"\" is not a recognized System Compression format. The options are:"
+"\n"
+" --compact=xpress4k\n"
+" --compact=xpress8k\n"
+" --compact=xpress16k\n"
+" --compact=lzx\n"
+ ), arg);
+ return -1;
+}
+
+
+static void
+set_compress_slow(void)
+{
+#if 0
+ fprintf(stderr, "WARNING: the '--compress-slow' option is deprecated.\n"
+ " Use the '--compress=TYPE:LEVEL' option instead.\n");
+#endif
+ wimlib_set_default_compression_level(-1, 100);
+}
+
+struct string_set {
+ tchar **strings;
+ unsigned num_strings;
+ unsigned num_alloc_strings;
+};
+
+#define STRING_SET_INITIALIZER \
+ { .strings = NULL, .num_strings = 0, .num_alloc_strings = 0, }
+
+#define STRING_SET(_strings) \
+ struct string_set _strings = STRING_SET_INITIALIZER
+
+static int
+string_set_append(struct string_set *set, tchar *glob)
+{
+ unsigned num_alloc_strings = set->num_alloc_strings;
+
+ if (set->num_strings == num_alloc_strings) {
+ tchar **new_strings;
+
+ num_alloc_strings += 4;
+ new_strings = realloc(set->strings,
+ sizeof(set->strings[0]) * num_alloc_strings);
+ if (!new_strings) {
+ imagex_error(T("Out of memory!"));
+ return -1;
+ }
+ set->strings = new_strings;
+ set->num_alloc_strings = num_alloc_strings;
+ }
+ set->strings[set->num_strings++] = glob;
+ return 0;
+}
+
+static void
+string_set_destroy(struct string_set *set)
+{
+ free(set->strings);
+}
+
+static int
+wim_reference_globs(WIMStruct *wim, struct string_set *set, int open_flags)
+{
+ return wimlib_reference_resource_files(wim, (const tchar **)set->strings,
+ set->num_strings,
+ WIMLIB_REF_FLAG_GLOB_ENABLE,
+ open_flags);
+}
+
+static int
+append_image_property_argument(struct string_set *image_properties)
+{
+ if (!tstrchr(optarg, '=')) {
+ imagex_error(T("'--image-property' argument "
+ "must be in the form NAME=VALUE"));
+ return -1;
+ }
+ return string_set_append(image_properties, optarg);
+}
+
+static int
+apply_image_properties(struct string_set *image_properties,
+ WIMStruct *wim, int image, bool *any_changes_ret)
+{
+ bool any_changes = false;
+ for (unsigned i = 0; i < image_properties->num_strings; i++) {
+ tchar *name, *value;
+ const tchar *current_value;
+ int ret;
+
+ name = image_properties->strings[i];
+ value = tstrchr(name, '=');
+ *value++ = '\0';
+
+ current_value = wimlib_get_image_property(wim, image, name);
+ if (current_value && !tstrcmp(current_value, value)) {
+ imagex_printf(T("The %"TS" property of image %d "
+ "already has value \"%"TS"\".\n"),
+ name, image, value);
+ } else {
+ imagex_printf(T("Setting the %"TS" property of image "
+ "%d to \"%"TS"\".\n"),
+ name, image, value);
+ ret = wimlib_set_image_property(wim, image, name, value);
+ if (ret)
+ return ret;
+ any_changes = true;
+ }
+ }
+ if (any_changes_ret)
+ *any_changes_ret = any_changes;
+ return 0;
+}
+
+static void
+do_resource_not_found_warning(const tchar *wimfile,
+ const struct wimlib_wim_info *info,
+ const struct string_set *refglobs)
+{
+ if (info->total_parts > 1) {
+ if (refglobs->num_strings == 0) {
+ imagex_error(T("\"%"TS"\" is part of a split WIM. "
+ "Use --ref to specify the other parts."),
+ wimfile);
+ } else {
+ imagex_error(T("Perhaps the '--ref' argument did not "
+ "specify all other parts of the split "
+ "WIM?"));
+ }
+ } else {
+ imagex_error(T("If this is a delta WIM, use the --ref argument "
+ "to specify the WIM(s) on which it is based."));
+ }
+}
+
+static void
+do_metadata_not_found_warning(const tchar *wimfile,
+ const struct wimlib_wim_info *info)
+{
+ if (info->part_number != 1) {
+ imagex_error(T("\"%"TS"\" is not the first part of the split WIM.\n"
+ " You must specify the first part."),
+ wimfile);
+ }