From bb3a0f263bd80aff41d647f838a10a911bd5eed1 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 18 Nov 2022 10:35:15 +0100 Subject: [PATCH] Ya crea la carpeta de sistema en MacOS y Windows --- source/director.cpp | 49 +++++++++------------------------------------ 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 9857dec..f986c69 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -2,7 +2,6 @@ #include "director.h" #include #include -#include #include #include #include @@ -10,6 +9,10 @@ #include #include +#ifndef _WIN32 +#include +#endif + // Constructor Director::Director(int argc, char *argv[]) { @@ -277,55 +280,24 @@ bool Director::saveConfig() void Director::createSystemFolder() { #ifdef _WIN32 - systemFolder = "/%APPDATA/%/jaildoctors_dilemma"; - if (CreateDirectory(systemFolder.c_str(), NULL) || ERROR_ALREADY_EXISTS == GetLastError()) - { - std::cout << "System directory created" << std::endl; - } - else - { - // Failed to create directory. - std::cout << "Failed to create system directory" << std::endl; - } + systemFolder = std::string(getenv("APPDATA")) + "/jaildoctors_dilemma"; #elif __APPLE__ struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; systemFolder = std::string(homedir) + "/Library/Application Support/jaildoctors_dilemma"; - struct stat st = {0}; - - if (stat(systemFolder.c_str(), &st) == -1) - { - errno = 0; - int ret = mkdir(systemFolder.c_str(), S_IRWXU); - if (ret == -1) - { - switch (errno) - { - case EACCES: - printf("the parent directory does not allow write"); - exit(EXIT_FAILURE); - case EEXIST: - printf("pathname already exists"); - exit(EXIT_FAILURE); - case ENAMETOOLONG: - printf("pathname is too long"); - exit(EXIT_FAILURE); - default: - perror("mkdir"); - exit(EXIT_FAILURE); - } - } - } #elif __linux__ struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; systemFolder = std::string(homedir) + "/.jaildoctors_dilemma"; - struct stat st = {0}; +#endif + struct stat st = {0}; if (stat(systemFolder.c_str(), &st) == -1) { errno = 0; - int ret = mkdir(systemFolder.c_str(), S_IRWXU); + int ret = mkdir(systemFolder.c_str()); + //int ret = mkdir(systemFolder.c_str(), S_IRWXU); + if (ret == -1) { switch (errno) @@ -345,7 +317,6 @@ void Director::createSystemFolder() } } } -#endif } // Carga los recursos