]> wimlib.net Git - wimlib/commitdiff
Send progress messages for WIM updates
authorEric Biggers <ebiggers3@gmail.com>
Tue, 21 May 2013 17:57:19 +0000 (12:57 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 21 May 2013 17:57:19 +0000 (12:57 -0500)
include/wimlib.h
include/wimlib/util.h
programs/imagex.c
src/paths.c
src/update_image.c

index e021906106e75465e2465db482693a50770fdc3c..44008c789070797aaf4e895b58139cf64a48323e 100644 (file)
@@ -191,6 +191,15 @@ typedef wchar_t wimlib_tchar;
 typedef char wimlib_tchar;
 #endif
 
+#ifdef __WIN32__
+/** Path separator for WIM paths passed back to progress callbacks. */
+#  define WIMLIB_WIM_PATH_SEPARATOR '\\'
+#  define WIMLIB_WIM_PATH_SEPARATOR_STRING L"\\"
+#else
+/** Path separator for WIM paths passed back to progress callbacks. */
+#  define WIMLIB_WIM_PATH_SEPARATOR '/'
+#  define WIMLIB_WIM_PATH_SEPARATOR_STRING "/"
+#endif
 /**
  * Specifies the compression type of a WIM file.
  */
@@ -290,6 +299,18 @@ enum wimlib_progress_msg {
         * @a info will point to ::wimlib_progress_info.rename. */
        WIMLIB_PROGRESS_MSG_RENAME,
 
+       /**
+        * A WIM update command is just about to be executed; @a info will point
+        * to ::wimlib_progress_info.update.
+        */
+       WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND,
+
+       /**
+        * A WIM update command is just about to be executed; @a info will point
+        * to ::wimlib_progress_info.update.
+        */
+       WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND,
+
        /** The contents of the WIM are being checked against the integrity
         * table.  Only happens when wimlib_open_wim() is called with the
         * ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY flag.  @a info will point to
@@ -438,6 +459,22 @@ union wimlib_progress_info {
                const wimlib_tchar *to;
        } rename;
 
+       /** Valid on messages ::WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND and
+        * ::WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND. */
+       struct wimlib_progress_info_update {
+               /** Pointer to the update command that will be executed or has
+                * just been executed. */
+               const struct wimlib_update_command *command;
+
+               /** Number of update commands that have been completed so far.
+                */
+               size_t completed_commands;
+
+               /** Number of update commands that are being executed as part of
+                * this call to wimlib_update_image(). */
+               size_t total_commands;
+       } update;
+
        /** Valid on messages ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY and
         * ::WIMLIB_PROGRESS_MSG_CALC_INTEGRITY. */
        struct wimlib_progress_info_integrity {
@@ -794,6 +831,14 @@ struct wimlib_capture_config {
 /** Do a "lazy" unmount (detach filesystem immediately, even if busy) */
 #define WIMLIB_UNMOUNT_FLAG_LAZY                       0x00000010
 
+/******************************
+ * WIMLIB_UPDATE_FLAG_*
+ ******************************/
+
+/** Send ::WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND and
+ * ::WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND messages. */
+#define WIMLIB_UPDATE_FLAG_SEND_PROGRESS               0x00000001
+
 /******************************
  * WIMLIB_WRITE_FLAG_*
  ******************************/
@@ -2484,7 +2529,7 @@ wimlib_unmount_image(const wimlib_tchar *dir,
  * @param num_cmds
  *     Number of commands in @a cmds.
  * @param update_flags
- *     Reserved; must be 0.
+ *     ::WIMLIB_UPDATE_FLAG_SEND_PROGRESS or 0.
  * @param progress_func
  *     If non-NULL, a function that will be called periodically with the
  *     progress of the current operation.
index 646fdafc768b6b98560d8364eee236e8bdbe5ed9..7b3e724a68ce677859eaa44ddf552cdf3ca1c6c0 100644 (file)
@@ -143,7 +143,6 @@ hash_u64(u64 n)
 #  define is_any_path_separator(c) ((c) == '/' || (c) == '\\')
 #endif
 
-#define WIM_PATH_SEPARATOR OS_PREFERRED_PATH_SEPARATOR
-
+#define WIM_PATH_SEPARATOR WIMLIB_WIM_PATH_SEPARATOR
 
 #endif /* _WIMLIB_UTIL_H */
index 1a3cbbd5a05176975e22ea78764d7b8e43bdbeb6..5d7aa233236443b34d9526d7bcce689b3eb4e43e 100644 (file)
 #  include "imagex-win32.h"
 #  define tbasename    win32_wbasename
 #  define tglob                win32_wglob
+#  define OS_PREFERRED_PATH_SEPARATOR L'\\'
+#  define OS_PREFERRED_PATH_SEPARATOR_STRING L"\\"
 #else /* __WIN32__ */
 #  include <glob.h>
 #  include <getopt.h>
 #  include <langinfo.h>
 #  define tbasename    basename
 #  define tglob                glob
+#  define OS_PREFERRED_PATH_SEPARATOR '/'
+#  define OS_PREFERRED_PATH_SEPARATOR_STRING "/"
 #endif /* !__WIN32 */
 
 
@@ -1065,7 +1069,8 @@ imagex_progress_func(enum wimlib_progress_msg msg,
        case WIMLIB_PROGRESS_MSG_SCAN_BEGIN:
                tprintf(T("Scanning \"%"TS"\""), info->scan.source);
                if (*info->scan.wim_target_path) {
-                       tprintf(T(" (loading as WIM path: \"/%"TS"\")...\n"),
+                       tprintf(T(" (loading as WIM path: "
+                                 "\""WIMLIB_WIM_PATH_SEPARATOR_STRING"%"TS"\")...\n"),
                               info->scan.wim_target_path);
                } else {
                        tprintf(T(" (loading as root of WIM image)...\n"));
@@ -1119,7 +1124,8 @@ imagex_progress_func(enum wimlib_progress_msg msg,
                        info->extract.target);
                break;
        case WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN:
-               tprintf(T("Extracting \"%"TS"\" from image %d (\"%"TS"\") "
+               tprintf(T("Extracting "
+                         "\""WIMLIB_WIM_PATH_SEPARATOR_STRING"%"TS"\" from image %d (\"%"TS"\") "
                          "in \"%"TS"\" to \"%"TS"\"\n"),
                        info->extract.extract_root_wim_source_path,
                        info->extract.image,
@@ -1192,6 +1198,25 @@ imagex_progress_func(enum wimlib_progress_msg msg,
                                info->split.cur_part_number);
                }
                break;
+       case WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND:
+               switch (info->update.command->op) {
+               case WIMLIB_UPDATE_OP_DELETE:
+                       tprintf(T("Deleted WIM path "
+                                 "\""WIMLIB_WIM_PATH_SEPARATOR_STRING "%"TS"\"\n"),
+                               info->update.command->delete.wim_path);
+                       break;
+               case WIMLIB_UPDATE_OP_RENAME:
+                       tprintf(T("Renamed WIM path "
+                                 "\""WIMLIB_WIM_PATH_SEPARATOR_STRING "%"TS"\" => "
+                                 "\""WIMLIB_WIM_PATH_SEPARATOR_STRING "%"TS"\"\n"),
+                               info->update.command->rename.wim_source_path,
+                               info->update.command->rename.wim_target_path);
+                       break;
+               case WIMLIB_UPDATE_OP_ADD:
+               default:
+                       break;
+               }
+               break;
        default:
                break;
        }
@@ -2233,8 +2258,8 @@ prepare_extract_commands(tchar **paths, unsigned num_paths,
                                free_extract_commands(cmds, num_cmds, dest_dir);
                                return NULL;
                        }
-                       tsprintf(cmds[i].fs_dest_path, T("%"TS"/%"TS), dest_dir,
-                                tbasename(paths[i]));
+                       tsprintf(cmds[i].fs_dest_path, T("%"TS""OS_PREFERRED_PATH_SEPARATOR_STRING"%"TS),
+                                dest_dir, tbasename(paths[i]));
                }
        }
        *num_cmds_ret = num_cmds;
@@ -3001,7 +3026,7 @@ imagex_update(int argc, tchar **argv)
        int ret;
        int open_flags = 0;
        int write_flags = 0;
-       int update_flags = 0;
+       int update_flags = WIMLIB_UPDATE_FLAG_SEND_PROGRESS;
        int default_add_flags = WIMLIB_ADD_IMAGE_FLAG_EXCLUDE_VERBOSE;
        int default_delete_flags = 0;
        unsigned num_threads = 0;
index f9de6bfe6e997ae80511275edb6c61e86b38aaef..9becb2128185d6dddc06c5251332c9ca4bf53bca 100644 (file)
@@ -25,6 +25,7 @@
 #  include "config.h"
 #endif
 
+#include "wimlib.h"
 #include "wimlib/paths.h"
 #include "wimlib/util.h"
 
index 763f4dc410948e95251537cf6c8cf6705980df3d..dd63854e80eab1a58dae6bbc2fe68e5cd90a8bec 100644 (file)
@@ -470,12 +470,23 @@ static int
 execute_update_commands(WIMStruct *wim,
                        const struct wimlib_update_command *cmds,
                        size_t num_cmds,
+                       int update_flags,
                        wimlib_progress_func_t progress_func)
 {
        int ret = 0;
+       union wimlib_progress_info info;
+       info.update.completed_commands = 0;
+       info.update.total_commands = num_cmds;
        for (size_t i = 0; i < num_cmds; i++) {
                DEBUG("Executing update command %zu of %zu (op=%"TS")",
                      i + 1, num_cmds, update_op_to_str(cmds[i].op));
+               if (update_flags & WIMLIB_UPDATE_FLAG_SEND_PROGRESS &&
+                   progress_func)
+               {
+                       info.update.command = &cmds[i];
+                       (*progress_func)(WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND,
+                                        &info);
+               }
                switch (cmds[i].op) {
                case WIMLIB_UPDATE_OP_ADD:
                        ret = execute_add_command(wim, &cmds[i], progress_func);
@@ -491,6 +502,13 @@ execute_update_commands(WIMStruct *wim,
                }
                if (ret)
                        break;
+               info.update.completed_commands++;
+               if (update_flags & WIMLIB_UPDATE_FLAG_SEND_PROGRESS &&
+                   progress_func)
+               {
+                       (*progress_func)(WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND,
+                                        &info);
+               }
        }
        return ret;
 }
@@ -737,7 +755,8 @@ wimlib_update_image(WIMStruct *wim,
 
        /* Actually execute the update commands. */
        DEBUG("Executing %zu update commands", num_cmds);
-       ret = execute_update_commands(wim, cmds_copy, num_cmds, progress_func);
+       ret = execute_update_commands(wim, cmds_copy, num_cmds, update_flags,
+                                     progress_func);
        if (ret)
                goto out_free_cmds_copy;