Actualizada la clase asset

This commit is contained in:
2022-08-29 20:04:53 +02:00
parent 9c2140b274
commit 05311f7a00
2 changed files with 30 additions and 10 deletions

View File

@@ -4,6 +4,7 @@
Asset::Asset(std::string path) Asset::Asset(std::string path)
{ {
mExecutablePath = path; mExecutablePath = path;
longest_name = 0;
} }
// Destructor // Destructor
@@ -19,6 +20,9 @@ void Asset::add(std::string file, enum assetType type, bool required)
temp.type = type; temp.type = type;
temp.required = required; temp.required = required;
mFileList.push_back(temp); mFileList.push_back(temp);
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
longest_name = SDL_max(longest_name, filename.size());
} }
// Devuelve el fichero de un elemento de la lista a partir de una cadena // Devuelve el fichero de un elemento de la lista a partir de una cadena
@@ -37,14 +41,27 @@ bool Asset::check()
{ {
bool success = true; bool success = true;
printf("\n** Checking files.\n");
// Comprueba la lista de ficheros clasificandolos por tipo // Comprueba la lista de ficheros clasificandolos por tipo
for (int type = 0; type < maxAssetType; type++) for (int type = 0; type < maxAssetType; type++)
{ {
printf("\n>> %s FILES\n", getTypeName(type).c_str()); // Comprueba si hay ficheros de ese tipo
bool any = false;
for (int i = 0; i < mFileList.size(); i++) for (int i = 0; i < mFileList.size(); i++)
if ((mFileList[i].required) && (mFileList[i].type == type)) if ((mFileList[i].required) && (mFileList[i].type == type))
success &= checkFile(mFileList[i].file); any = true;
// Si hay ficheros de ese tipo, comprueba si existen
if (any)
{
printf("\n>> %s FILES\n", getTypeName(type).c_str());
for (int i = 0; i < mFileList.size(); i++)
if ((mFileList[i].required) && (mFileList[i].type == type))
success &= checkFile(mFileList[i].file);
}
} }
// Resultado // Resultado
@@ -59,7 +76,8 @@ bool Asset::check()
// Comprueba que existe un fichero // Comprueba que existe un fichero
bool Asset::checkFile(std::string path) bool Asset::checkFile(std::string path)
{ {
bool success = true; bool success = false;
std::string result = "ERROR";
// Comprueba si existe el fichero // Comprueba si existe el fichero
const std::string filename = path.substr(path.find_last_of("\\/") + 1); const std::string filename = path.substr(path.find_last_of("\\/") + 1);
@@ -67,14 +85,13 @@ bool Asset::checkFile(std::string path)
if (file != NULL) if (file != NULL)
{ {
printf("Checking file %-20s [OK]\n", filename.c_str()); result = "OK";
success = true;
SDL_RWclose(file); SDL_RWclose(file);
} }
else
{ const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
printf("Checking file %-20s [ERROR]\n", filename.c_str()); printf(s.c_str(), filename.c_str());
success = false;
}
return success; return success;
} }

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "ifdefs.h"
#include <SDL2/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -32,6 +33,8 @@ private:
bool required; // Indica si es un fichero que debe de existir bool required; // Indica si es un fichero que debe de existir
}; };
int longest_name; // Contiene la longitud del nombre de fichero mas largo
std::vector<item_t> mFileList; std::vector<item_t> mFileList;
std::string mExecutablePath; std::string mExecutablePath;