diff --git a/source/asset.cpp b/source/asset.cpp index 1294567..21f1bba 100644 --- a/source/asset.cpp +++ b/source/asset.cpp @@ -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; } diff --git a/source/asset.h b/source/asset.h index 8ed626d..ba8cb6c 100644 --- a/source/asset.h +++ b/source/asset.h @@ -1,5 +1,6 @@ #pragma once -#include "ifdefs.h" + +#include #include #include @@ -32,6 +33,8 @@ private: 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 mFileList; std::string mExecutablePath;