Ya crea la carpeta de sistema en MacOS y Windows

This commit is contained in:
2022-11-18 10:35:15 +01:00
parent 85d6c48f42
commit bb3a0f263b

View File

@@ -2,7 +2,6 @@
#include "director.h"
#include <errno.h>
#include <iostream>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
@@ -10,6 +9,10 @@
#include <sys/types.h>
#include <unistd.h>
#ifndef _WIN32
#include <pwd.h>
#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