]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
imagex_extract(): Set WIMLIB_EXTRACT_FLAG_NORPFIX
[wimlib] / programs / imagex.c
index 275f48d1d051549dd5f2dde8b46e89aa5d1a2408..59335996c57b7bf9a9d3950d7ef61dc073be59e6 100644 (file)
@@ -81,6 +81,8 @@ enum imagex_op_type {
 static void usage(int cmd_type);
 static void usage_all();
 
+static bool imagex_be_quiet = false;
+
 
 static const tchar *usage_strings[] = {
 [APPEND] =
@@ -125,9 +127,9 @@ IMAGEX_PROGNAME" export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n"
 ),
 [EXTRACT] =
 T(
-IMAGEX_PROGNAME" extract SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME) [PATH...]\n"
-"              [--check] [--ref=\"GLOB\"] [--verbose] [--unix-data] [--no-acls]\n"
-"              [--strict-acls] [--to-stdout] [--dest-dir=DIR]\n"
+IMAGEX_PROGNAME" extract WIMFILE (IMAGE_NUM | IMAGE_NAME) [PATH...]\n"
+"              [--check] [--ref=\"GLOB\"] [--verbose] [--unix-data]\n"
+"              [--no-acls] [--strict-acls] [--to-stdout] [--dest-dir=DIR]\n"
 ),
 [INFO] =
 T(
@@ -952,6 +954,8 @@ imagex_progress_func(enum wimlib_progress_msg msg,
                     const union wimlib_progress_info *info)
 {
        unsigned percent_done;
+       if (imagex_be_quiet)
+               return 0;
        switch (msg) {
        case WIMLIB_PROGRESS_MSG_WRITE_STREAMS:
                percent_done = TO_PERCENT(info->write_streams.completed_bytes,
@@ -1852,18 +1856,18 @@ is_root_wim_path(const tchar *path)
 {
        const tchar *p;
        for (p = path; *p; p++)
-               if (*p != T('\\') && *p != T('\\'))
+               if (*p != T('\\') && *p != T('/'))
                        return false;
        return true;
 }
 
 static void
 free_extract_commands(struct wimlib_extract_command *cmds, size_t num_cmds,
-                     tchar *dest_dir)
+                     const tchar *dest_dir)
 {
        for (size_t i = 0; i < num_cmds; i++)
                if (cmds[i].fs_dest_path != dest_dir)
-                               free(cmds[i].fs_dest_path);
+                       free(cmds[i].fs_dest_path);
        free(cmds);
 }
 
@@ -1875,14 +1879,14 @@ prepare_extract_commands(tchar **argv, int argc, int extract_flags,
        size_t num_cmds;
        tchar *emptystr = T("");
 
-       num_cmds = argc;
        if (argc == 0) {
-               num_cmds = 1;
+               argc = 1;
                argv = &emptystr;
        }
+       num_cmds = argc;
        cmds = calloc(num_cmds, sizeof(cmds[0]));
        if (!cmds) {
-               imagex_error("Out of memory!");
+               imagex_error(T("Out of memory!"));
                return NULL;
        }
 
@@ -1894,19 +1898,19 @@ prepare_extract_commands(tchar **argv, int argc, int extract_flags,
                } else {
                        size_t len = tstrlen(dest_dir) + 1 + tstrlen(argv[i]);
                        cmds[i].fs_dest_path = malloc((len + 1) * sizeof(tchar));
-                       if (!cmds[i].fs_dest_path)
-                               goto oom;
-                       tsprintf(cmds[i].fs_dest_path, "%"TS"/%"TS, dest_dir, tbasename(argv[i]));
+                       if (!cmds[i].fs_dest_path) {
+                               free_extract_commands(cmds, num_cmds, dest_dir);
+                               return NULL;
+                       }
+                       tsprintf(cmds[i].fs_dest_path, T("%"TS"/%"TS), dest_dir,
+                                tbasename(argv[i]));
                }
        }
-
        *num_cmds_ret = num_cmds;
        return cmds;
-oom:
-       free_extract_commands(cmds, num_cmds, dest_dir);
-       return NULL;
 }
 
+/* Extract files or directories from a WIM image */
 static int
 imagex_extract(int argc, tchar **argv)
 {
@@ -1918,7 +1922,7 @@ imagex_extract(int argc, tchar **argv)
        const tchar *wimfile;
        const tchar *image_num_or_name;
        tchar *dest_dir = T(".");
-       int extract_flags = WIMLIB_EXTRACT_FLAG_SEQUENTIAL;
+       int extract_flags = WIMLIB_EXTRACT_FLAG_SEQUENTIAL | WIMLIB_EXTRACT_FLAG_NORPFIX;
 
        const tchar *swm_glob = NULL;
        WIMStruct **additional_swms = NULL;
@@ -1952,6 +1956,7 @@ imagex_extract(int argc, tchar **argv)
                        break;
                case IMAGEX_TO_STDOUT_OPTION:
                        extract_flags |= WIMLIB_EXTRACT_FLAG_TO_STDOUT;
+                       imagex_be_quiet = true;
                        break;
                default:
                        usage(EXTRACT);
@@ -2006,8 +2011,14 @@ imagex_extract(int argc, tchar **argv)
        ret = wimlib_extract_files(wim, image, 0, cmds, num_cmds,
                                   additional_swms, num_additional_swms,
                                   imagex_progress_func);
-       if (ret == 0)
-               tprintf(T("Done extracting files.\n"));
+       if (ret == 0) {
+               if (!imagex_be_quiet)
+                       tprintf(T("Done extracting files.\n"));
+       } else if (ret == WIMLIB_ERR_PATH_DOES_NOT_EXIST) {
+               tfprintf(stderr, T("Note: You can use `"IMAGEX_PROGNAME" dir' to see what "
+                                  "files and directories\n"
+                                  "      are in the WIM image.\n"));
+       }
 #ifdef __WIN32__
        win32_release_restore_privileges();
 #endif