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 e021906..44008c7 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 {
@@ -795,6 +832,14 @@ struct wimlib_capture_config {
 #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 646fdaf..7b3e724 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 1a3cbbd..5d7aa23 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 f9de6bf..9becb21 100644 (file)
@@ -25,6 +25,7 @@
 #  include "config.h"
 #endif
 
+#include "wimlib.h"
 #include "wimlib/paths.h"
 #include "wimlib/util.h"
 
index 763f4dc..dd63854 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;