From c0f7461eabb4ee758f3b8d05d61c72e1582b0d6e Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 26 Aug 2023 19:14:11 +0200 Subject: [PATCH] added .config directory existence check --- include/chat/flags.h | 3 ++- src/chat/config.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/chat/flags.h b/include/chat/flags.h index 44a1987..a712a7f 100644 --- a/include/chat/flags.h +++ b/include/chat/flags.h @@ -29,7 +29,8 @@ along with this program. If not, see . #define WHY2_INVALID_POINTER (void*) 0xffffffffffffffff -#define WHY2_CHAT_CONFIG_DIR "/home/{USER}/.config/WHY2" +#define WHY2_CONFIG_DIR "/home/{USER}/.config" +#define WHY2_CHAT_CONFIG_DIR WHY2_CONFIG_DIR "/WHY2" #define WHY2_CHAT_CONFIG_URL "https://raw.githubusercontent.com/ENGO150/WHY2/development/src/chat/" #define WHY2_CHAT_CONFIG_SERVER "server.yml" #define WHY2_CHAT_CONFIG_CLIENT "client.yml" diff --git a/src/chat/config.c b/src/chat/config.c index c065632..d078f60 100644 --- a/src/chat/config.c +++ b/src/chat/config.c @@ -34,6 +34,14 @@ along with this program. If not, see . //LOCAL void init_config(char *filename) { + struct stat st; + + //CREATE USER CONFIG FOLDER [THIS SHOULDN'T HAPPEN ON CLIENT, BUT IT'S NEEDED ON FRESH SERVERS] + if (stat(WHY2_CONFIG_DIR, &st) == -1) + { + mkdir(WHY2_CONFIG_DIR, 0700); + } + //GET THE CONFIG TYPE char *buffer = why2_malloc(strlen(WHY2_CHAT_CONFIG_DIR) + strlen(filename) + 2); sprintf(buffer, "%s/%s", WHY2_CHAT_CONFIG_DIR, filename);