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
+8 -10
View File
@@ -59,14 +59,13 @@ void ManageHiScoreTable::sort()
}
// Carga la tabla con los datos de un fichero
bool ManageHiScoreTable::loadFromFile(std::string filepath)
bool ManageHiScoreTable::loadFromFile(std::string filePath)
{
clear();
bool success = true;
const std::string p = filepath;
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "r+b");
if (file)
{
@@ -116,12 +115,11 @@ bool ManageHiScoreTable::loadFromFile(std::string filepath)
}
// Guarda la tabla en un fichero
bool ManageHiScoreTable::saveToFile(std::string filepath)
bool ManageHiScoreTable::saveToFile(std::string filePath)
{
bool success = true;
const std::string p = filepath;
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
const std::string fileName = filePath.substr(filePath.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "w+b");
if (file)
{
@@ -135,7 +133,7 @@ bool ManageHiScoreTable::saveToFile(std::string filepath)
}
#ifdef DEBUG
std::cout << "Writing file: " << filename.c_str() << std::endl;
std::cout << "Writing file: " << fileName.c_str() << std::endl;
#endif
// Cierra el fichero
SDL_RWclose(file);
@@ -143,7 +141,7 @@ bool ManageHiScoreTable::saveToFile(std::string filepath)
else
{
#ifdef DEBUG
std::cout << "Error: Unable to save " << filename.c_str() << " file! " << SDL_GetError() << std::endl;
std::cout << "Error: Unable to save " << fileName.c_str() << " file! " << SDL_GetError() << std::endl;
#endif
}
return success;