corregit: asset::checkFile() fallava desde fora del directori
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
|
||||
|
||||
#include <cstddef> // Para size_t
|
||||
#include <exception> // Para exception
|
||||
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
|
||||
#include <sstream> // Para basic_istringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <cstddef> // Para size_t
|
||||
#include <exception> // Para exception
|
||||
#include <filesystem> // Para std::filesystem
|
||||
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
|
||||
#include <sstream> // Para basic_istringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
|
||||
#include "resource_helper.h" // Para ResourceHelper
|
||||
#include "utils.h" // Para getFileName
|
||||
@@ -205,25 +206,28 @@ auto Asset::check() const -> bool {
|
||||
}
|
||||
|
||||
// Comprueba que existe un fichero
|
||||
auto Asset::checkFile(const std::string &path) -> bool {
|
||||
// Intentar primero con ResourceHelper
|
||||
auto data = ResourceHelper::loadFile(path);
|
||||
bool success = !data.empty();
|
||||
auto Asset::checkFile(const std::string &path) const -> bool {
|
||||
// Construir ruta del pack usando executable_path_
|
||||
std::string pack_path = executable_path_ + "resources.pack";
|
||||
bool pack_exists = std::filesystem::exists(pack_path);
|
||||
|
||||
// Si no se encuentra en el pack, intentar con filesystem directo
|
||||
if (!success) {
|
||||
if (pack_exists) {
|
||||
// MODO PACK: Usar ResourceHelper (igual que la carga real)
|
||||
auto data = ResourceHelper::loadFile(path);
|
||||
return !data.empty();
|
||||
} else {
|
||||
// MODO FILESYSTEM: Verificación directa (modo desarrollo)
|
||||
std::ifstream file(path);
|
||||
success = file.good();
|
||||
bool success = file.good();
|
||||
file.close();
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Checking file: %s [ ERROR ]",
|
||||
getFileName(path).c_str());
|
||||
}
|
||||
if (!success) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Error: Could not open file: %s", path.c_str());
|
||||
}
|
||||
|
||||
return success;
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Parsea string a Type
|
||||
|
||||
Reference in New Issue
Block a user