#include "asset.h" // Constructor Asset::Asset(std::string path) { mExecutablePath = path; } // Destructor Asset::~Asset() { } // AƱade un elemento a la lista void Asset::add(std::string file, enum assetType type, bool required) { item_t temp; temp.file = mExecutablePath + "/.." + file; temp.type = type; temp.required = required; mFileList.push_back(temp); } // Devuelve un elemento de la lista a partir de una cadena std::string Asset::get(std::string text) { for (int i = 0; i < mFileList.size(); i++) if (mFileList[i].file.find(text) != std::string::npos) return mFileList[i].file; return ""; } // Comprueba que existen todos los elementos bool Asset::check() { bool success = true; for (int i = 0; i < mFileList.size(); i++) if (mFileList[i].required) success &= checkFile(mFileList[i].file); return success; } // Comprueba que existe un fichero bool Asset::checkFile(std::string path) { bool success = true; // Comprueba si existe el fichero const std::string filename = path.substr(path.find_last_of("\\/") + 1); SDL_RWops *file = SDL_RWFromFile(path.c_str(), "r+b"); if (file != NULL) { printf("Checking file %-20s [OK]\n", filename.c_str()); SDL_RWclose(file); } else { printf("Checking file %-20s [ERROR]\n", filename.c_str()); success = false; } return success; }