several fixes and improvements (combat log) - windows

This commit is contained in:
Ondrej Novak 2025-02-11 11:04:30 +01:00
parent 05726326bd
commit 2d7697174d
15 changed files with 332 additions and 158 deletions

View file

@ -121,21 +121,28 @@ int list_files(const char *directory, int type, LIST_FILES_CALLBACK cb, void *ct
int r = 0;
const auto &entry = *iter;
const char *name;
size_t szortm = 0;
std::string tmp;
if (type & file_type_just_name) {
tmp = entry.path().filename().string();
} else {
tmp = entry.path().string();
}
if (type & file_type_need_timestamp) {
auto tm = std::chrono::clock_cast<std::chrono::system_clock>(entry.last_write_time(ec));
szortm = std::chrono::system_clock::to_time_t(tm);
} else {
szortm = entry.file_size(ec);
}
name = tmp.c_str();
if (entry.is_regular_file(ec) && (type & file_type_normal)) {
r = cb(name, file_type_normal, entry.file_size(ec), ctx);
r = cb(name, file_type_normal, szortm, ctx);
} else if (entry.is_directory(ec)) {
int dot = entry.path().filename() == "." || entry.path().filename() == "..";
if (!dot && (type & file_type_directory)) {
r = cb(name, file_type_directory, 0, ctx);
r = cb(name, file_type_directory, szortm, ctx);
} else if (dot & (type & file_type_dot)) {
r = cb(name, file_type_dot, 0, ctx);
r = cb(name, file_type_dot, szortm, ctx);
}
}
if (r) return r;

View file

@ -17,9 +17,19 @@
#pragma warning(disable: 4457)
#pragma warning(disable: 4702)
#pragma warning(disable: 4100)
//microsoft doesn't support FALLTHROUGH
#define CASE_FALLTHROUGH
//microsoft doesn't support VLA
#define DECL_VLA(type, variable, count) type *variable = (type *)alloca((count)*sizeof(type));
#define GET_VLA_SIZE(variable, count) ((count)*sizeof(*variable))
#else
//support FALLTHROUGH
#define CASE_FALLTHROUGH [[fallthrough]]
//support VLA
#define DECL_VLA(type, variable, count) type variable[count];
#define GET_VLA_SIZE(variable, count) sizeof(variable)
#endif
@ -90,6 +100,7 @@ const char *file_icase_find(const char *pathname);
int istrcmp(const char *a, const char *b);
int istrncmp(const char *a, const char *b, size_t sz);
int imatch(const char *haystack, const char *needle);
#define SAFESTRCOPY(target, source) strcopy_n(target, source, sizeof(target) )
const char *strcopy_n(char *target, const char *source, int target_size);
#define MIN(a, b) ((a)<(b)?(a):(b))
#define MAX(a, b) ((a)>(b)?(a):(b))
@ -104,7 +115,8 @@ typedef enum {
file_type_normal = 1,
file_type_directory = 2,
file_type_dot = 4,
file_type_just_name = 8
file_type_just_name = 8,
file_type_need_timestamp = 16
} LIST_FILE_TYPE;
typedef int (*LIST_FILES_CALLBACK)(const char *, LIST_FILE_TYPE , size_t, void *);