Prints the date / time at the start, the end and on any error message
Signed-off-by: Florian Eder others.meder@gmail.com --- programs/robocopy/main.c | 43 +++++++++++++++++++++++++++++++---- programs/robocopy/robocopy.h | 2 ++ programs/robocopy/robocopy.rc | 2 ++ 3 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/programs/robocopy/main.c b/programs/robocopy/main.c index a7c419e37d7..c54d7d9360c 100644 --- a/programs/robocopy/main.c +++ b/programs/robocopy/main.c @@ -69,17 +69,44 @@ static void output_message(UINT format_string_id, ...) LocalFree(string); }
+static WCHAR* get_date_time_string(BOOL log_format) +{ + SYSTEMTIME current_time; + WCHAR *date_time_string, temp_string[128]; + + date_time_string = calloc(128, sizeof(WCHAR)); + + GetLocalTime(¤t_time); + + /* Local time / date format is ignored, to enable scripted extraction of parts of the date / time from the log output */ + if (log_format) + GetDateFormatW(LOCALE_USER_DEFAULT, 0, ¤t_time, L"yyyy/MM/dd ", temp_string, ARRAY_SIZE(temp_string)); + else + GetDateFormatW(LOCALE_USER_DEFAULT, 0, ¤t_time, L"ddd MMM dd ", temp_string, ARRAY_SIZE(temp_string)); + + wcscpy(date_time_string, temp_string); + GetTimeFormatW(LOCALE_USER_DEFAULT, 0, ¤t_time, L"hh:mm:ss", temp_string, ARRAY_SIZE(temp_string)); + wcscat(date_time_string, temp_string); + if (!log_format) + { + GetDateFormatW(LOCALE_USER_DEFAULT, 0, ¤t_time, L" yyyy", temp_string, ARRAY_SIZE(temp_string)); + wcscat(date_time_string, temp_string); + } + return date_time_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]; + WCHAR *error_string, error_code_long[64], error_code_short[64], *date_time_string;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, error_code, 0, (LPWSTR)&error_string, 0, NULL); + date_time_string = get_date_time_string(TRUE);
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); + output_message(format_string_id, date_time_string, error_code_short, error_code_long, path, error_string);
LocalFree(error_string); } @@ -732,10 +759,13 @@ static WCHAR *get_option_string(void) static void print_header(void) { UINT i; - WCHAR *options_string; + WCHAR *options_string, *date_time_string;
output_message(STRING_HEADER);
+ date_time_string = get_date_time_string(FALSE); + if (date_time_string) output_message(STRING_DATE_TIME_START, date_time_string); + if (!options.source) output_message(STRING_SOURCE, L"-"); else output_message(STRING_SOURCE, strip_path_prefix(options.source));
@@ -762,7 +792,7 @@ int __cdecl wmain(int argc, WCHAR *argv[]) { struct robocopy_statistics statistics; int exit_code; - WCHAR dirs_copied[64], files_copied[64]; + WCHAR dirs_copied[64], files_copied[64], *date_time_string;
parse_arguments(argc, argv);
@@ -791,6 +821,11 @@ int __cdecl wmain(int argc, WCHAR *argv[]) swprintf(files_copied, ARRAY_SIZE(files_copied), L"%u", statistics.copied_files); output_message(STRING_STATISTICS, dirs_copied, files_copied);
+ date_time_string = get_date_time_string(FALSE); + if (!date_time_string) + return ROBOCOPY_ERROR_NO_FILES_COPIED; + output_message(STRING_DATE_TIME_END, date_time_string); + exit_code = ROBOCOPY_NO_ERROR_NO_COPY; if (statistics.copied_files) exit_code += ROBOCOPY_NO_ERROR_FILES_COPIED; if (statistics.extra_files) exit_code += ROBOCOPY_EXTRA_FILES_IN_DESTINATION; diff --git a/programs/robocopy/robocopy.h b/programs/robocopy/robocopy.h index 67fbd9eb822..459e5a7f8f7 100644 --- a/programs/robocopy/robocopy.h +++ b/programs/robocopy/robocopy.h @@ -71,6 +71,8 @@ struct robocopy_statistics {
/* Resource strings */ #define STRING_HEADER 1000 +#define STRING_DATE_TIME_START 1001 +#define STRING_DATE_TIME_END 1002 #define STRING_SOURCE 1003 #define STRING_DESTINATION 1004 #define STRING_FILES 1005 diff --git a/programs/robocopy/robocopy.rc b/programs/robocopy/robocopy.rc index 315dce5f947..df66753ca6b 100644 --- a/programs/robocopy/robocopy.rc +++ b/programs/robocopy/robocopy.rc @@ -26,6 +26,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT STRINGTABLE { STRING_HEADER, "Robocopy for Wine\n\n" + STRING_DATE_TIME_START, " Started: %1\n\n" + STRING_DATE_TIME_END, "\n Ended: %1\n\n" STRING_SOURCE, " Source: %1\n" STRING_DESTINATION, " Destination: %1\n\n" STRING_FILES, " Files: %1\n"