]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
imagex_update skeleton
[wimlib] / programs / imagex.c
index 275f48d1d051549dd5f2dde8b46e89aa5d1a2408..31a9a3a960fe32b34dd1caad66ca95f369f047d0 100644 (file)
@@ -76,11 +76,14 @@ enum imagex_op_type {
        OPTIMIZE,
        SPLIT,
        UNMOUNT,
+       UPDATE,
 };
 
 static void usage(int cmd_type);
 static void usage_all();
 
+static bool imagex_be_quiet = false;
+
 
 static const tchar *usage_strings[] = {
 [APPEND] =
@@ -125,9 +128,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(
@@ -164,6 +167,17 @@ IMAGEX_PROGNAME" split WIMFILE SPLIT_WIMFILE PART_SIZE_MB [--check]\n"
 T(
 IMAGEX_PROGNAME" unmount DIRECTORY [--commit] [--check] [--rebuild]\n"
 ),
+[UPDATE] =
+T(
+IMAGEX_PROGNAME" update WIMFILE IMAGE [--check] [--rebuild]\n"
+"                      [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n"
+"                      [DEFAULT_DELETE_OPTIONS] [CMD...] [< CMDFILE]\n"
+"               ... where each CMD is:\n"
+"               add [--unix-data] [--no-acls] [--strict-acls] [--dereference]\n"
+"                   [--verbose] FILE_OR_DIRECTORY DEST_WIM_PATH\n"
+"               delete [--force] [--recursive] WIM_PATH\n"
+"               rename SRC_PATH_IN_WIM DEST_PATH_IN_WIM\n"
+),
 };
 
 enum {
@@ -952,6 +966,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 +1868,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 +1891,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 +1910,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 +1934,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 +1968,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 +2023,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
@@ -2635,6 +2658,41 @@ imagex_unmount(int argc, tchar **argv)
        return ret;
 }
 
+static int
+imagex_update(int argc, tchar **argv)
+{
+       const tchar *wimfile;
+       const tchar *image_num_or_name;
+       int image;
+       WIMStruct *wim;
+       int ret;
+       int open_flags = 0;
+       int write_flags = 0;
+       unsigned num_threads = 0;
+
+       if (argc < 3)
+               goto out_usage;
+       wimfile = argv[1];
+       image_num_or_name = argv[2];
+
+       ret = wimlib_open_wim(wimfile, open_flags, &wim, imagex_progress_func);
+       if (ret)
+               goto out;
+
+       /*wimlib_update_image();*/
+
+       ret = wimlib_overwrite(wim, write_flags, num_threads,
+                              imagex_progress_func);
+out_wimlib_free:
+       wimlib_free(wim);
+out:
+       return ret;
+out_usage:
+       usage(UPDATE);
+       ret = -1;
+       goto out;
+}
+
 struct imagex_command {
        const tchar *name;
        int (*func)(int , tchar **);
@@ -2660,6 +2718,7 @@ static const struct imagex_command imagex_commands[] = {
        {T("optimize"),imagex_optimize,          OPTIMIZE},
        {T("split"),   imagex_split,             SPLIT},
        {T("unmount"), imagex_unmount,           UNMOUNT},
+       {T("update"),  imagex_update,            UPDATE},
 };
 
 static void