Estandaritzats els accessos a fitxers
This commit is contained in:
@@ -66,7 +66,7 @@ Game::~Game()
|
||||
manager->saveToFile(asset->get("score.bin"));
|
||||
delete manager;
|
||||
#ifdef RECORDING
|
||||
saveDemoFile();
|
||||
saveDemoFile(asset->get("demo1.bin"));
|
||||
#endif
|
||||
|
||||
// Elimina todos los objetos contenidos en vectores
|
||||
@@ -642,30 +642,29 @@ void Game::unloadMedia()
|
||||
}
|
||||
|
||||
// Carga el fichero de datos para la demo
|
||||
bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
bool Game::loadDemoFile(std::string filePath, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
{
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
const std::string filename = f.substr(f.find_last_of("\\/") + 1);
|
||||
SDL_RWops *file = SDL_RWFromFile(f.c_str(), "r+b");
|
||||
const std::string fileName = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
|
||||
// El fichero no existe
|
||||
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "r+b");
|
||||
if (file == nullptr)
|
||||
{
|
||||
{ // El fichero no existe
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << fileName.c_str() << " file" << std::endl;
|
||||
}
|
||||
|
||||
// Creamos el fichero para escritura
|
||||
file = SDL_RWFromFile(f.c_str(), "w+b");
|
||||
file = SDL_RWFromFile(filePath.c_str(), "w+b");
|
||||
|
||||
// Si no existe el fichero
|
||||
// Si ha creado el fichero
|
||||
if (file != nullptr)
|
||||
{
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "New file (" << filename.c_str() << ") created!" << std::endl;
|
||||
std::cout << "New file (" << fileName.c_str() << ") created!" << std::endl;
|
||||
}
|
||||
|
||||
// Inicializas los datos y los guarda en el fichero
|
||||
@@ -689,7 +688,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
{ // Si no puede crear el fichero
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Error: Unable to create file " << filename.c_str() << std::endl;
|
||||
std::cout << "Error: Unable to create file " << fileName.c_str() << std::endl;
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
@@ -700,7 +699,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
// Mensaje de proceder a la carga de los datos
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Reading file: " << filename.c_str() << std::endl;
|
||||
std::cout << "Reading file: " << fileName.c_str() << std::endl;
|
||||
}
|
||||
|
||||
// Lee todos los datos del fichero y los deja en el destino
|
||||
@@ -720,13 +719,12 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool Game::saveDemoFile()
|
||||
bool Game::saveDemoFile(std::string filePath)
|
||||
{
|
||||
bool success = true;
|
||||
const std::string p = asset->get("demo1.bin");
|
||||
const std::string filename = p.substr(p.find_last_of("\\/") + 1);
|
||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
|
||||
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b");
|
||||
SDL_RWops *file = SDL_RWFromFile(filePath.c_str(), "w+b");
|
||||
if (file != nullptr)
|
||||
{
|
||||
// Guardamos los datos
|
||||
|
||||
Reference in New Issue
Block a user