Outputs error messages with the affected file / directory, the error code and its meaning
Signed-off-by: Florian Eder others.meder@gmail.com --- programs/robocopy/main.c | 23 +++++++++++++++++++---- programs/robocopy/robocopy.h | 3 +++ programs/robocopy/robocopy.rc | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/programs/robocopy/main.c b/programs/robocopy/main.c index a28b008a8fa..050258ddab2 100644 --- a/programs/robocopy/main.c +++ b/programs/robocopy/main.c @@ -69,6 +69,21 @@ static void output_message(UINT format_string_id, ...) LocalFree(string); }
+static void output_error(UINT format_string_id, HRESULT error_code, WCHAR* path) +{ + WCHAR *error_string, error_code_long[64], error_code_short[64]; + + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, error_code, 0, (LPWSTR)&error_string, 0, NULL); + + swprintf(error_code_long, ARRAY_SIZE(error_code_long), L"0x%08x", error_code); + swprintf(error_code_short, ARRAY_SIZE(error_code_short), L"%u", error_code); + + output_message(format_string_id, L"", error_code_short, error_code_long, path, error_string); + + LocalFree(error_string); +} + static BOOL is_valid_robocopy_flag(WCHAR *string) { /* @@ -194,7 +209,7 @@ static BOOL create_directory_path(WCHAR *path) { if (GetLastError() != ERROR_ALREADY_EXISTS) { - WINE_FIXME("error create directory %S %d", current_folder, GetLastError()); + output_error(STRING_ERROR_WRITE_DIRECTORY, GetLastError(), strip_path_prefix(current_folder)); return FALSE; } } @@ -265,7 +280,7 @@ static BOOL perform_copy(void)
if (!PathIsDirectoryW(options.source)) { - WINE_FIXME("error read directory %S %d", options.source, GetLastError()); + output_error(STRING_ERROR_READ_DIRECTORY, ERROR_FILE_NOT_FOUND, strip_path_prefix(options.source)); return FALSE; }
@@ -288,12 +303,12 @@ static BOOL perform_copy(void) { /* Create the directory path and then create the directory itself */ if (!create_directory_path(target_path)) - WINE_FIXME("error write directory %S %d", target_path, GetLastError()); + output_error(STRING_ERROR_WRITE_DIRECTORY, GetLastError(), strip_path_prefix(target_path)); } else { if (!CopyFileW(current_absolute_path, target_path, FALSE)) - WINE_FIXME("error write file %S %d", target_path, GetLastError()); + output_error(STRING_ERROR_WRITE_FILE, GetLastError(), strip_path_prefix(target_path)); else { output_message(STRING_CREATE_FILE, strip_path_prefix(target_path)); diff --git a/programs/robocopy/robocopy.h b/programs/robocopy/robocopy.h index 22c7406e0ea..1cd0a427c03 100644 --- a/programs/robocopy/robocopy.h +++ b/programs/robocopy/robocopy.h @@ -42,5 +42,8 @@ struct robocopy_options { #define STRING_DESTINATION 1004 #define STRING_FILES 1005 #define STRING_ADDITIONAL_INFO 1008 +#define STRING_ERROR_READ_DIRECTORY 1011 +#define STRING_ERROR_WRITE_DIRECTORY 1012 +#define STRING_ERROR_WRITE_FILE 1014 #define STRING_CREATE_DIRECTORY 1019 #define STRING_CREATE_FILE 1022 \ No newline at end of file diff --git a/programs/robocopy/robocopy.rc b/programs/robocopy/robocopy.rc index 92f3b8efe63..45d7bdacd69 100644 --- a/programs/robocopy/robocopy.rc +++ b/programs/robocopy/robocopy.rc @@ -30,6 +30,9 @@ STRINGTABLE STRING_DESTINATION, " Destination: %1\n\n" STRING_FILES, " Files: %1\n" STRING_ADDITIONAL_INFO, " %1\n" + STRING_ERROR_READ_DIRECTORY, "[%1] Error %2 (%3) occurred reading directory "%4":\n%5\n" + STRING_ERROR_WRITE_DIRECTORY, "[%1] Error %2 (%3) occurred writing directory "%4":\n%5\n" + STRING_ERROR_WRITE_FILE, "[%1] Error %2 (%3) occurred writing file "%4":\n%5\n" STRING_CREATE_DIRECTORY, " Created Dir: %1\n" STRING_CREATE_FILE, " Copied File: %1\n" }