]> wimlib.net Git - wimlib/blobdiff - include/wimlib/progress.h
Add helper functions for passing paths to progress callbacks
[wimlib] / include / wimlib / progress.h
index b2754445df323a5867bce8f228fccc28b50c2ad0..6d39b7e49804fb0089c8234985aa51e978108a00 100644 (file)
@@ -2,6 +2,7 @@
 #define _WIMLIB_PROGRESS_H
 
 #include "wimlib.h"
+#include "wimlib/paths.h"
 #include "wimlib/types.h"
 
 /* If specified, call the user-provided progress function and check its result.
@@ -55,4 +56,51 @@ set_next_progress(u64 completed_bytes, u64 total_bytes, u64 *next_progress_p)
        }
 }
 
+/* Windows: temporarily remove the stream name from the path  */
+static inline tchar *
+progress_get_streamless_path(const tchar *path)
+{
+       tchar *cookie = NULL;
+#ifdef __WIN32__
+       cookie = (wchar_t *)path_stream_name(path);
+       if (cookie)
+               *--cookie = L'\0'; /* Overwrite the colon  */
+#endif
+       return cookie;
+}
+
+/* Windows: temporarily replace \??\ with \\?\ (to make an NT namespace path
+ * into a Win32 namespace path)  */
+static inline tchar *
+progress_get_win32_path(const tchar *path)
+{
+#ifdef __WIN32__
+       if (!wcsncmp(path, L"\\??\\", 4)) {
+               ((wchar_t *)path)[1] = L'\\';
+               return (wchar_t *)&path[1];
+       }
+#endif
+       return NULL;
+}
+
+/* Windows: restore the NT namespace path  */
+static inline void
+progress_put_win32_path(tchar *cookie)
+{
+#ifdef __WIN32__
+       if (cookie)
+               *cookie = L'?';
+#endif
+}
+
+/* Windows: restore the stream name part of the path  */
+static inline void
+progress_put_streamless_path(tchar *cookie)
+{
+#ifdef __WIN32__
+       if (cookie)
+               *cookie = L':';
+#endif
+}
+
 #endif /* _WIMLIB_PROGRESS_H */