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)
{
mExecutablePath = path;
longest_name = 0;
}
// Destructor
@@ -19,6 +20,9 @@ void Asset::add(std::string file, enum assetType type, bool required)
temp.type = type;
temp.required = required;
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
@@ -37,14 +41,27 @@ bool Asset::check()
{
bool success = true;
printf("\n** Checking files.\n");
// Comprueba la lista de ficheros clasificandolos por tipo
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++)
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
@@ -59,7 +76,8 @@ bool Asset::check()
// Comprueba que existe un fichero
bool Asset::checkFile(std::string path)
{
bool success = true;
bool success = false;
std::string result = "ERROR";
// Comprueba si existe el fichero
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
@@ -67,14 +85,13 @@ bool Asset::checkFile(std::string path)
if (file != NULL)
{
printf("Checking file %-20s [OK]\n", filename.c_str());
result = "OK";
success = true;
SDL_RWclose(file);
}
else
{
printf("Checking file %-20s [ERROR]\n", filename.c_str());
success = false;
}
const std::string s = "Checking file %-" + std::to_string(longest_name) + "s [" + result + "]\n";
printf(s.c_str(), filename.c_str());
return success;
}