Estandaritzats els accessos a fitxers

This commit is contained in:
2024-09-27 19:41:45 +02:00
parent 20de9e4b72
commit 0a8d0479a0
5 changed files with 33 additions and 36 deletions

View File

@@ -94,7 +94,7 @@ bool loadOptionsFile(std::string filePath)
bool success = true;
// Variables para manejar el fichero
std::string line;
const std::string fileName = filePath.substr(filePath.find_last_of("\\/") + 1);
std::ifstream file(filePath);
// Si el fichero se puede abrir
@@ -103,8 +103,9 @@ bool loadOptionsFile(std::string filePath)
// Procesa el fichero linea a linea
if (options.console)
{
std::cout << "Reading file: " << filePath << std::endl;
std::cout << "Reading file: " << fileName << std::endl;
}
std::string line;
while (std::getline(file, line))
{
// Comprueba que la linea no sea un comentario
@@ -117,7 +118,7 @@ bool loadOptionsFile(std::string filePath)
{
if (options.console)
{
std::cout << "Warning: file " << filePath << std::endl;
std::cout << "Warning: file " << fileName << std::endl;
std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl;
}
success = false;
@@ -160,21 +161,21 @@ bool loadOptionsFile(std::string filePath)
// Guarda el fichero de configuración
bool saveOptionsFile(std::string filePath)
{
const std::string filename = filePath;
const std::string fileName = filePath.substr(filePath.find_last_of("\\/") + 1);
std::ofstream file(filePath);
if (!file.good())
{
if (options.console)
{
std::cout << filename << " can't be opened" << std::endl;
std::cout << fileName << " can't be opened" << std::endl;
}
return false;
}
if (options.console)
{
std::cout << "Writing file: " << filename << std::endl;
std::cout << "Writing file: " << fileName << std::endl;
}
// Opciones de video