From 326f8ed071b88196a1c6c18b2aa8ea59891a2a2e Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 8 Jun 2020 08:49:06 +0300 Subject: [PATCH] properly check for basepacks --- src/pc/fs/fs.c | 4 ++-- src/pc/platform.c | 15 +++++++++++---- src/pc/platform.h | 3 ++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pc/fs/fs.c b/src/pc/fs/fs.c index d125a60b..37f85edf 100644 --- a/src/pc/fs/fs.c +++ b/src/pc/fs/fs.c @@ -43,8 +43,8 @@ static inline fs_dir_t *fs_find_dir(const char *realpath) { } static int mount_cmp(const void *p1, const void *p2) { - const char *s1 = *(const char **)p1; - const char *s2 = *(const char **)p2; + const char *s1 = sys_file_name(*(const char **)p1); + const char *s2 = sys_file_name(*(const char **)p2); // check if one or both of these are basepacks const int plen = strlen(FS_BASEPACK_PREFIX); diff --git a/src/pc/platform.c b/src/pc/platform.c index 0aea20fa..d6bfd6e2 100644 --- a/src/pc/platform.c +++ b/src/pc/platform.c @@ -49,15 +49,22 @@ int sys_strcasecmp(const char *s1, const char *s2) { return result; } -const char *sys_file_extension(const char *fname) { +const char *sys_file_extension(const char *fpath) { + const char *fname = sys_file_name(fpath); const char *dot = strrchr(fname, '.'); - const char *sep = strrchr(fname, '/'); - if (!sep) sep = strrchr(fname, '\\'); if (!dot || !dot[1]) return NULL; // no dot - if (dot <= sep + 1) return NULL; // dot is before the last separator or right after it (e.g. /.local) + if (dot == fname) return NULL; // dot is the first char (e.g. .local) return dot + 1; } +const char *sys_file_name(const char *fpath) { + const char *sep1 = strrchr(fpath, '/'); + const char *sep2 = strrchr(fpath, '\\'); + const char *sep = sep1 > sep2 ? sep1 : sep2; + if (!sep) return fpath; + return sep + 1; +} + /* this calls a platform-specific impl function after forming the error message */ static void sys_fatal_impl(const char *msg) __attribute__ ((noreturn)); diff --git a/src/pc/platform.h b/src/pc/platform.h index 53b2ad16..168333d1 100644 --- a/src/pc/platform.h +++ b/src/pc/platform.h @@ -20,7 +20,8 @@ int sys_strcasecmp(const char *s1, const char *s2); // path stuff const char *sys_user_path(void); const char *sys_exe_path(void); -const char *sys_file_extension(const char *fname); +const char *sys_file_extension(const char *fpath); +const char *sys_file_name(const char *fpath); // shows an error message in some way and terminates the game void sys_fatal(const char *fmt, ...) __attribute__ ((noreturn));