forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya crea la carpeta de sistema en Linux
This commit is contained in:
@@ -10,10 +10,10 @@ Asset::Asset(std::string executablePath)
|
||||
}
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void Asset::add(std::string file, enum assetType type, bool required)
|
||||
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
||||
{
|
||||
item_t temp;
|
||||
temp.file = executablePath + file;
|
||||
temp.file = absolute ? file : executablePath + file;
|
||||
temp.type = type;
|
||||
temp.required = required;
|
||||
fileList.push_back(temp);
|
||||
|
||||
@@ -31,6 +31,7 @@ private:
|
||||
std::string file; // Ruta del fichero desde la raiz del directorio
|
||||
enum assetType type; // Indica el tipo de recurso
|
||||
bool required; // Indica si es un fichero que debe de existir
|
||||
//bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
|
||||
};
|
||||
|
||||
// Variables
|
||||
@@ -50,7 +51,7 @@ public:
|
||||
Asset(std::string path);
|
||||
|
||||
// Añade un elemento a la lista
|
||||
void add(std::string file, enum assetType type, bool required = true);
|
||||
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
||||
|
||||
// Devuelve un elemento de la lista a partir de una cadena
|
||||
std::string get(std::string text);
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
#include "director.h"
|
||||
#include "common/utils.h"
|
||||
#include "director.h"
|
||||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, char *argv[])
|
||||
@@ -19,6 +26,9 @@ Director::Director(int argc, char *argv[])
|
||||
// Comprueba los parametros del programa
|
||||
checkProgramArguments(argc, argv);
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
createSystemFolder();
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
asset = new Asset(executablePath);
|
||||
asset->setVerbose(options->console);
|
||||
@@ -26,7 +36,7 @@ Director::Director(int argc, char *argv[])
|
||||
// Si falta algún fichero no inicia el programa
|
||||
if (!setFileList())
|
||||
{
|
||||
section.name = SECTION_PROG_QUIT;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Inicializa variables desde el fichero de configuración
|
||||
@@ -263,6 +273,81 @@ bool Director::saveConfig()
|
||||
return success;
|
||||
}
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
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;
|
||||
}
|
||||
#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};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Carga los recursos
|
||||
void Director::loadResources(section_t section)
|
||||
{
|
||||
@@ -1055,17 +1140,8 @@ bool Director::setFileList()
|
||||
|
||||
// Configuración
|
||||
asset->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);
|
||||
|
||||
#ifdef _WIN32
|
||||
asset->add("\%APPDATA\%/jaildoctors_dilemma/config.txt", t_data, false);
|
||||
asset->add("\%APPDATA\%/jaildoctors_dilemma/stats.txt", t_data, false);
|
||||
#elif __APPLE__
|
||||
asset->add("~/Library/Application Support/jaildoctors_dilemma/config.txt", t_data, false);
|
||||
asset->add("~/Library/Application Support/jaildoctors_dilemma/stats.txt", t_data, false);
|
||||
#elif __linux__
|
||||
asset->add("~/.jaildoctors_dilemma/config.txt", t_data, false);
|
||||
asset->add("~/.jaildoctors_dilemma/stats.txt", t_data, false);
|
||||
#endif
|
||||
asset->add(prefix + "/data/config/config.txt", t_data, false);
|
||||
asset->add(systemFolder + "/stats.txt", t_data, false, true);
|
||||
|
||||
// Habitaciones
|
||||
asset->add(prefix + "/data/room/01.room", t_room);
|
||||
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
Credits *credits; // Objeto para gestionar los creditos del juego
|
||||
Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
|
||||
Ending *ending; // Objeto para gestionar el final del juego
|
||||
Ending2 *ending2; // Objeto para gestionar el final del juego
|
||||
Ending2 *ending2; // Objeto para gestionar el final del juego
|
||||
GameOver *gameOver; // Objeto para gestionar el final de la partida
|
||||
Debug *debug; // Objeto para getsionar la información de debug
|
||||
struct options_t *options; // Variable con todas las opciones del programa
|
||||
@@ -49,6 +49,7 @@ private:
|
||||
JA_Music music; // Musica del titulo
|
||||
std::string executablePath; // Path del ejecutable
|
||||
section_t section; // Sección y subsección actual del programa;
|
||||
std::string systemFolder; // Carpeta del sistema donde guardar datos
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
void iniOptions();
|
||||
@@ -62,6 +63,9 @@ private:
|
||||
// Guarda el fichero de configuración
|
||||
bool saveConfig();
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
void createSystemFolder();
|
||||
|
||||
// Carga los recursos
|
||||
void loadResources(section_t section);
|
||||
|
||||
|
||||
@@ -135,6 +135,15 @@ void Stats::saveToFile()
|
||||
// Crea y abre el fichero de texto
|
||||
std::ofstream file(filePath);
|
||||
|
||||
if (file.good())
|
||||
{
|
||||
std::cout << filePath << " open for writing" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << filePath << " can't be opened" << std::endl;
|
||||
}
|
||||
|
||||
// Escribe en el fichero
|
||||
file << "# NOMBRE DE LA HABITACION;VISITAS;MUERTES" << std::endl;
|
||||
for (auto item : list)
|
||||
|
||||
Reference in New Issue
Block a user