X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=programs%2Fimagex.c;h=fc2dd45ce48e3dcb9c644f200dc40587ce353c5f;hp=c3a08e8e1ff08f6e4f1e26a70afdab2b2032edbb;hb=eefdb393d2fe037989c7e007dea31f399bf935b9;hpb=8cf21d34c68d8d2a1917d7f6a42e01dcdf35208d diff --git a/programs/imagex.c b/programs/imagex.c index c3a08e8e..fc2dd45c 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -48,14 +48,10 @@ #ifdef __WIN32__ # include "imagex-win32.h" -# define OS_PREFERRED_PATH_SEPARATOR L'\\' -# define OS_PREFERRED_PATH_SEPARATOR_STRING L"\\" # define print_security_descriptor win32_print_security_descriptor #else /* __WIN32__ */ # include # include -# define OS_PREFERRED_PATH_SEPARATOR '/' -# define OS_PREFERRED_PATH_SEPARATOR_STRING "/" # define print_security_descriptor default_print_security_descriptor static inline void set_fd_to_binary_mode(int fd) { @@ -201,6 +197,7 @@ enum { IMAGEX_UPDATE_OF_OPTION, IMAGEX_VERBOSE_OPTION, IMAGEX_WIMBOOT_OPTION, + IMAGEX_WIMBOOT_CONFIG_OPTION, IMAGEX_XML_OPTION, }; @@ -387,6 +384,7 @@ static const struct option update_options[] = { {T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION}, {T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION}, {T("command"), required_argument, NULL, IMAGEX_COMMAND_OPTION}, + {T("wimboot-config"), required_argument, NULL, IMAGEX_WIMBOOT_CONFIG_OPTION}, /* Default delete options */ {T("force"), no_argument, NULL, IMAGEX_FORCE_OPTION}, @@ -481,7 +479,9 @@ verify_image_exists_and_is_single(int image, const tchar *image_name, static int get_compression_type(const tchar *optarg) { - if (!tstrcasecmp(optarg, T("maximum")) || !tstrcasecmp(optarg, T("lzx"))) + if (!tstrcasecmp(optarg, T("maximum")) || + !tstrcasecmp(optarg, T("lzx")) || + !tstrcasecmp(optarg, T("max"))) return WIMLIB_COMPRESSION_TYPE_LZX; else if (!tstrcasecmp(optarg, T("fast")) || !tstrcasecmp(optarg, T("xpress"))) return WIMLIB_COMPRESSION_TYPE_XPRESS; @@ -1053,39 +1053,23 @@ imagex_progress_func(enum wimlib_progress_msg msg, percent_done = TO_PERCENT(info->write_streams.completed_bytes, info->write_streams.total_bytes); - if (info->write_streams.total_parts <= 1) { - imagex_printf(T("\r%"PRIu64" %"TS" of %"PRIu64" %"TS" (uncompressed) " - "written (%u%% done)"), - info->write_streams.completed_bytes >> unit_shift, - unit_name, - info->write_streams.total_bytes >> unit_shift, - unit_name, - percent_done); - } else { - imagex_printf(T("\rWriting resources from part %u of %u: " - "%"PRIu64 " %"TS" of %"PRIu64" %"TS" (%u%%) written"), - (info->write_streams.completed_parts == - info->write_streams.total_parts) ? - info->write_streams.completed_parts : - info->write_streams.completed_parts + 1, - info->write_streams.total_parts, - info->write_streams.completed_bytes >> unit_shift, - unit_name, - info->write_streams.total_bytes >> unit_shift, - unit_name, - percent_done); - } + imagex_printf(T("\r%"PRIu64" %"TS" of %"PRIu64" %"TS" (uncompressed) " + "written (%u%% done)"), + info->write_streams.completed_bytes >> unit_shift, + unit_name, + info->write_streams.total_bytes >> unit_shift, + unit_name, + percent_done); if (info->write_streams.completed_bytes >= info->write_streams.total_bytes) imagex_printf(T("\n")); break; case WIMLIB_PROGRESS_MSG_SCAN_BEGIN: imagex_printf(T("Scanning \"%"TS"\""), info->scan.source); - if (*info->scan.wim_target_path) { - imagex_printf(T(" (loading as WIM path: " - "\""WIMLIB_WIM_PATH_SEPARATOR_STRING"%"TS"\")...\n"), - info->scan.wim_target_path); - } else { + if (WIMLIB_IS_WIM_ROOT_PATH(info->scan.wim_target_path)) { imagex_printf(T("\n")); + } else { + imagex_printf(T(" (loading as WIM path: \"%"TS"\")...\n"), + info->scan.wim_target_path); } memset(&last_scan_progress, 0, sizeof(last_scan_progress)); break; @@ -1154,17 +1138,6 @@ imagex_progress_func(enum wimlib_progress_msg msg, T("NTFS volume") : T("directory")), info->extract.target); break; - case WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN: - if (info->extract.extract_root_wim_source_path[0]) { - imagex_printf(T("Extracting \"%"TS"\" from image %d " - "(\"%"TS"\") in \"%"TS"\" to \"%"TS"\"\n"), - info->extract.extract_root_wim_source_path, - info->extract.image, - info->extract.image_name, - info->extract.wimfile_name, - info->extract.target); - } - break; case WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS: percent_done = TO_PERCENT(info->extract.completed_bytes, info->extract.total_bytes); @@ -1187,8 +1160,7 @@ imagex_progress_func(enum wimlib_progress_msg msg, } break; case WIMLIB_PROGRESS_MSG_APPLY_TIMESTAMPS: - if (info->extract.extract_root_wim_source_path[0] == T('\0')) - imagex_printf(T("Setting timestamps on all extracted files...\n")); + imagex_printf(T("Setting timestamps on all extracted files...\n")); break; case WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END: if (info->extract.extract_flags & WIMLIB_EXTRACT_FLAG_NTFS) { @@ -1221,14 +1193,11 @@ imagex_progress_func(enum wimlib_progress_msg msg, case WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND: switch (info->update.command->op) { case WIMLIB_UPDATE_OP_DELETE: - imagex_printf(T("Deleted WIM path " - "\""WIMLIB_WIM_PATH_SEPARATOR_STRING "%"TS"\"\n"), + imagex_printf(T("Deleted WIM path \"%"TS"\"\n"), info->update.command->delete_.wim_path); break; case WIMLIB_UPDATE_OP_RENAME: - imagex_printf(T("Renamed WIM path " - "\""WIMLIB_WIM_PATH_SEPARATOR_STRING "%"TS"\" => " - "\""WIMLIB_WIM_PATH_SEPARATOR_STRING "%"TS"\"\n"), + imagex_printf(T("Renamed WIM path \"%"TS"\" => \"%"TS"\"\n"), info->update.command->rename.wim_source_path, info->update.command->rename.wim_target_path); break; @@ -1241,6 +1210,10 @@ imagex_progress_func(enum wimlib_progress_msg msg, imagex_printf(T("Updating \"%"TS"\" in WIM image\n"), info->replace.path_in_wim); break; + case WIMLIB_PROGRESS_MSG_WIMBOOT_EXCLUDE: + imagex_printf(T("\nExtracting \"%"TS"\" as normal file (not WIMBoot pointer)\n"), + info->wimboot_exclude.path_in_wim); + break; default: break; } @@ -1849,9 +1822,19 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd) if (compression_type == WIMLIB_COMPRESSION_TYPE_INVALID) { + /* No compression type specified. Use the default. */ + if (add_image_flags & WIMLIB_ADD_IMAGE_FLAG_WIMBOOT) { + /* With --wimboot, default to XPRESS compression. */ compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS; + } else if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS) { + /* With --pack-streams or --solid, default to LZMS + * compression. (However, this will not affect packed + * resources!) */ + compression_type = WIMLIB_COMPRESSION_TYPE_LZMS; } else { + /* Otherwise, default to LZX compression in fast mode. + */ compression_type = WIMLIB_COMPRESSION_TYPE_LZX; if (!compress_slow && pack_ctype != WIMLIB_COMPRESSION_TYPE_LZX) { struct wimlib_lzx_compressor_params params = { @@ -1965,7 +1948,7 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd) /* Set up capture source in non-source-list mode. */ capture_sources = alloca(sizeof(struct wimlib_capture_source)); capture_sources[0].fs_source_path = source; - capture_sources[0].wim_target_path = NULL; + capture_sources[0].wim_target_path = WIMLIB_WIM_ROOT_PATH; capture_sources[0].reserved = 0; num_sources = 1; capture_sources_malloced = false; @@ -2492,7 +2475,7 @@ imagex_dir(int argc, tchar **argv, int cmd) WIMStruct *wim = NULL; int image; int ret; - const tchar *path = T(""); + const tchar *path = WIMLIB_WIM_ROOT_PATH; int c; struct print_dentry_options options = { .detailed = false, @@ -2743,9 +2726,13 @@ imagex_export(int argc, tchar **argv, int cmd) if (compression_type == WIMLIB_COMPRESSION_TYPE_INVALID) { /* The user did not specify a compression type; default - * to that of the source WIM. */ + * to that of the source WIM, unless --pack-streams or + * --solid was specified. */ - compression_type = src_info.compression_type; + if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS) + compression_type = WIMLIB_COMPRESSION_TYPE_LZMS; + else + compression_type = src_info.compression_type; } ret = wimlib_create_new_wim(compression_type, &dest_wim); if (ret) @@ -2849,7 +2836,7 @@ imagex_extract(int argc, tchar **argv, int cmd) STRING_SET(refglobs); - tchar *root_path = T(""); + tchar *root_path = WIMLIB_WIM_ROOT_PATH; for_opt(c, extract_options) { switch (c) { @@ -3720,6 +3707,7 @@ imagex_update(int argc, tchar **argv, int cmd) size_t num_cmds; tchar *command_str = NULL; tchar *config_file = NULL; + tchar *wimboot_config = NULL; for_opt(c, update_options) { switch (c) { @@ -3750,6 +3738,9 @@ imagex_update(int argc, tchar **argv, int cmd) goto out_err; } break; + case IMAGEX_WIMBOOT_CONFIG_OPTION: + wimboot_config = optarg; + break; /* Default delete options */ case IMAGEX_FORCE_OPTION: default_delete_flags |= WIMLIB_DELETE_FLAG_FORCE; @@ -3826,7 +3817,11 @@ imagex_update(int argc, tchar **argv, int cmd) cmd_file_contents = NULL; cmds = parse_update_command_file(&command_str, tstrlen(command_str), &num_cmds); - } else { + if (!cmds) { + ret = -1; + goto out_free_cmd_file_contents; + } + } else if (!wimboot_config) { if (isatty(STDIN_FILENO)) { tputs(T("Reading update commands from standard input...")); recommend_man_page(CMD_UPDATE, stdout); @@ -3840,10 +3835,14 @@ imagex_update(int argc, tchar **argv, int cmd) /* Parse the update commands */ cmds = parse_update_command_file(&cmd_file_contents, cmd_file_nchars, &num_cmds); - } - if (!cmds) { - ret = -1; - goto out_free_cmd_file_contents; + if (!cmds) { + ret = -1; + goto out_free_cmd_file_contents; + } + } else { + cmd_file_contents = NULL; + cmds = NULL; + num_cmds = 0; } /* Set default flags and capture config on the update commands */ @@ -3867,6 +3866,24 @@ imagex_update(int argc, tchar **argv, int cmd) if (ret) goto out_free_cmds; + if (wimboot_config) { + /* --wimboot-config=FILE is short for an + * "add FILE /Windows/System32/WimBootCompress.ini" command. + */ + struct wimlib_update_command cmd; + + cmd.op = WIMLIB_UPDATE_OP_ADD; + cmd.add.fs_source_path = wimboot_config; + cmd.add.wim_target_path = T("/Windows/System32/WimBootCompress.ini"); + cmd.add.config_file = NULL; + cmd.add.add_flags = 0; + + ret = wimlib_update_image(wim, image, &cmd, 1, + update_flags, imagex_progress_func); + if (ret) + goto out_free_cmds; + } + /* Overwrite the updated WIM */ ret = wimlib_overwrite(wim, write_flags, num_threads, imagex_progress_func); @@ -3924,7 +3941,7 @@ T( " [--nocheck] [--flags EDITION_ID] [--dereference]\n" " [--config=FILE] [--threads=NUM_THREADS] [--source-list]\n" " [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n" -" [--update-of=[WIMFILE:]IMAGE]\n" +" [--update-of=[WIMFILE:]IMAGE] [--wimboot]\n" ), [CMD_APPLY] = T( @@ -3932,7 +3949,7 @@ T( " (DIRECTORY | NTFS_VOLUME) [--check] [--ref=\"GLOB\"]\n" " [--no-acls] [--strict-acls] [--no-attributes]\n" " [--rpfix] [--norpfix] [--hardlink] [--symlink]\n" -" [--include-invalid-names]\n" +" [--include-invalid-names] [--wimboot]\n" ), [CMD_CAPTURE] = T( @@ -3942,7 +3959,7 @@ T( " [--dereference] [--config=FILE] [--threads=NUM_THREADS]\n" " [--source-list] [--no-acls] [--strict-acls] [--rpfix]\n" " [--norpfix] [--update-of=[WIMFILE:]IMAGE]\n" -" [--delta-from=WIMFILE]\n" +" [--delta-from=WIMFILE] [--wimboot]\n" ), [CMD_DELETE] = T( @@ -4013,7 +4030,8 @@ T( T( " %"TS" WIMFILE [IMAGE_NUM | IMAGE_NAME] [--check] [--rebuild]\n" " [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n" -" [DEFAULT_DELETE_OPTIONS] [--command=STRING] [< CMDFILE]\n" +" [DEFAULT_DELETE_OPTIONS] [--command=STRING]\n" +" [--wimboot-config=FILE| [< CMDFILE]\n" ), };