From bd6807d655d47f23e92a16680cf35aaf0e37a355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Wed, 19 Feb 2025 19:43:56 +0100 Subject: [PATCH] Update: createSystemFolder() ja crea la carpeta on toca en Linux --- source/director.cpp | 23 +++++++++++++++++------ source/director.h | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 8ca8c9d..a630060 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -421,10 +421,10 @@ bool Director::saveConfig() } // Crea la carpeta del sistema donde guardar datos -void Director::createSystemFolder(std::string folder) +void Director::createSystemFolder(const std::string &folder) { #ifdef _WIN32 - systemFolder = std::string(getenv("APPDATA")) + "/" + folder; + system_folder_ = std::string(getenv("APPDATA")) + "/" + folder; #elif __APPLE__ struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; @@ -432,17 +432,28 @@ void Director::createSystemFolder(std::string folder) #elif __linux__ struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; - systemFolder = std::string(homedir) + "/." + folder; + system_folder_ = std::string(homedir) + "/.config/" + folder; + + { + // Intenta crear ".config", per si no existeix + std::string config_base_folder = std::string(homedir) + "/.config"; + int ret = mkdir(config_base_folder.c_str(), S_IRWXU); + if (ret == -1 && errno != EEXIST) + { + printf("ERROR CREATING CONFIG BASE FOLDER."); + exit(EXIT_FAILURE); + } + } #endif struct stat st = {0}; - if (stat(systemFolder.c_str(), &st) == -1) + if (stat(system_folder_.c_str(), &st) == -1) { errno = 0; #ifdef _WIN32 - int ret = mkdir(systemFolder.c_str()); + int ret = mkdir(system_folder_.c_str()); #else - int ret = mkdir(systemFolder.c_str(), S_IRWXU); + int ret = mkdir(system_folder_.c_str(), S_IRWXU); #endif if (ret == -1) diff --git a/source/director.h b/source/director.h index ce82f25..d66c85d 100644 --- a/source/director.h +++ b/source/director.h @@ -70,7 +70,7 @@ private: bool saveConfig(); // Crea la carpeta del sistema donde guardar datos - void createSystemFolder(std::string folder); + void createSystemFolder(const std::string &folder); // Carga los recursos void loadResources(section_t *section);