1 #ifndef _WIMLIB_PROGRESS_H
2 #define _WIMLIB_PROGRESS_H
5 #include "wimlib/paths.h"
6 #include "wimlib/types.h"
8 /* If specified, call the user-provided progress function and check its result.
11 call_progress(wimlib_progress_func_t progfunc,
12 enum wimlib_progress_msg msg,
13 union wimlib_progress_info *info,
17 enum wimlib_progress_status status;
19 status = (*progfunc)(msg, info, progctx);
22 case WIMLIB_PROGRESS_STATUS_CONTINUE:
24 case WIMLIB_PROGRESS_STATUS_ABORT:
25 return WIMLIB_ERR_ABORTED_BY_PROGRESS;
27 return WIMLIB_ERR_UNKNOWN_PROGRESS_STATUS;
34 report_error(wimlib_progress_func_t progfunc,
35 void *progctx, int error_code, const tchar *path);
37 /* Rate-limiting of byte-count based progress messages: update *next_progress_p
38 * to the value that completed_bytes needs to reach before the next progress
39 * message will be sent. */
41 set_next_progress(u64 completed_bytes, u64 total_bytes, u64 *next_progress_p)
43 if (*next_progress_p < total_bytes) {
45 * Send the next message as soon as:
46 * - another 1/128 of the total has been processed;
47 * - OR another 5000000 bytes have been processed;
48 * - OR all bytes have been processed.
50 *next_progress_p = min(min(completed_bytes + total_bytes / 128,
51 completed_bytes + 5000000),
54 /* Last message has been sent. */
55 *next_progress_p = ~0;
59 /* Windows: temporarily remove the stream name from the path */
61 progress_get_streamless_path(const tchar *path)
65 cookie = (wchar_t *)path_stream_name(path);
67 *--cookie = L'\0'; /* Overwrite the colon */
72 /* Windows: temporarily replace \??\ with \\?\ (to make an NT namespace path
73 * into a Win32 namespace path) */
75 progress_get_win32_path(const tchar *path)
78 if (!wcsncmp(path, L"\\??\\", 4)) {
79 ((wchar_t *)path)[1] = L'\\';
80 return (wchar_t *)&path[1];
86 /* Windows: restore the NT namespace path */
88 progress_put_win32_path(tchar *cookie)
96 /* Windows: restore the stream name part of the path */
98 progress_put_streamless_path(tchar *cookie)
106 #endif /* _WIMLIB_PROGRESS_H */