Skip to content

Commit 741dafd

Browse files
committed
[FEATURE] Print only file name in the log. Refactored
1 parent f45cb2d commit 741dafd

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

main.cpp

+21-12
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,30 @@
2424
#define VERSION VER_FILEVERSION_STR
2525
#define LOG_FILE_NAME "unpack.log"
2626

27+
void print_log_hdr(std::wofstream &report, const time_t& session_timestamp, const t_params_struct& params)
28+
{
29+
report << "[" << session_timestamp << "] ";
30+
31+
const char* exe_name = get_file_name(params.exe_path);
32+
const char* img_name = get_file_name(params.img_path);
33+
if (exe_name) {
34+
report << exe_name;
35+
}
36+
if (img_name && exe_name &&
37+
strlen(img_name) && strcmp(img_name, exe_name) != 0)
38+
{
39+
report << " (" << img_name << ")";
40+
}
41+
report << " : ";
42+
}
43+
2744
void save_unpack_report(const time_t &session_timestamp, t_params_struct &params, const ScanStats& finalStats)
2845
{
2946
std::wofstream report;
3047
std::string report_name = LOG_FILE_NAME;
3148
report.open(report_name, std::ofstream::out | std::ofstream::app);
32-
report << "[" << session_timestamp << "] ";
33-
report << params.exe_path;
34-
if (strnlen(params.img_path, MAX_PATH) && strncmp(params.img_path,params.exe_path, MAX_PATH) != 0) {
35-
report << " (" << params.img_path << ")";
36-
}
37-
report << " : ";
49+
print_log_hdr(report, session_timestamp, params);
50+
3851
if (finalStats.detected) {
3952
report << "Unpacked in: " << std::dec << finalStats.scanTime << " ms\n";
4053
}
@@ -50,15 +63,11 @@ void save_remaing_files_report(const time_t& session_timestamp, t_params_struct&
5063
if (!scanner.listExistingDroppedFiles(names)) {
5164
return;
5265
}
66+
5367
std::wofstream report;
5468
std::string report_name = LOG_FILE_NAME;
5569
report.open(report_name, std::ofstream::out | std::ofstream::app);
56-
report << "[" << session_timestamp << "] ";
57-
report << params.exe_path;
58-
if (strnlen(params.img_path, MAX_PATH) && strncmp(params.img_path, params.exe_path, MAX_PATH) != 0) {
59-
report << " (" << params.img_path << ")";
60-
}
61-
report << " : ";
70+
print_log_hdr(report, session_timestamp, params);
6271

6372
report << "Failed to delete files (" << std::dec << names.size() << "):\n";
6473
std::map<LONGLONG, std::wstring>::const_iterator itr;

0 commit comments

Comments
 (0)