corregit: asset::checkFile() fallava desde fora del directori
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <cstddef> // Para size_t
|
#include <cstddef> // Para size_t
|
||||||
#include <exception> // Para exception
|
#include <exception> // Para exception
|
||||||
|
#include <filesystem> // Para std::filesystem
|
||||||
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
|
#include <fstream> // Para basic_istream, basic_ifstream, ifstream, istringstream
|
||||||
#include <sstream> // Para basic_istringstream
|
#include <sstream> // Para basic_istringstream
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
@@ -205,25 +206,28 @@ auto Asset::check() const -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba que existe un fichero
|
// Comprueba que existe un fichero
|
||||||
auto Asset::checkFile(const std::string &path) -> bool {
|
auto Asset::checkFile(const std::string &path) const -> bool {
|
||||||
// Intentar primero con ResourceHelper
|
// Construir ruta del pack usando executable_path_
|
||||||
auto data = ResourceHelper::loadFile(path);
|
std::string pack_path = executable_path_ + "resources.pack";
|
||||||
bool success = !data.empty();
|
bool pack_exists = std::filesystem::exists(pack_path);
|
||||||
|
|
||||||
// Si no se encuentra en el pack, intentar con filesystem directo
|
if (pack_exists) {
|
||||||
if (!success) {
|
// 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);
|
std::ifstream file(path);
|
||||||
success = file.good();
|
bool success = file.good();
|
||||||
file.close();
|
file.close();
|
||||||
}
|
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Checking file: %s [ ERROR ]",
|
"Error: Could not open file: %s", path.c_str());
|
||||||
getFileName(path).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parsea string a Type
|
// Parsea string a Type
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class Asset {
|
|||||||
std::string executable_path_; // Ruta del ejecutable
|
std::string executable_path_; // Ruta del ejecutable
|
||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
[[nodiscard]] static auto checkFile(const std::string &path) -> bool; // Verifica si un archivo existe
|
[[nodiscard]] auto checkFile(const std::string &path) const -> bool; // Verifica si un archivo existe
|
||||||
[[nodiscard]] static auto getTypeName(Type type) -> std::string; // Obtiene el nombre del tipo
|
[[nodiscard]] static auto getTypeName(Type type) -> std::string; // Obtiene el nombre del tipo
|
||||||
[[nodiscard]] static auto parseAssetType(const std::string &type_str) -> Type; // Convierte string a tipo
|
[[nodiscard]] static auto parseAssetType(const std::string &type_str) -> Type; // Convierte string a tipo
|
||||||
void addToMap(const std::string &file_path, Type type, bool required, bool absolute); // Añade archivo al mapa
|
void addToMap(const std::string &file_path, Type type, bool required, bool absolute); // Añade archivo al mapa
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ void Director::init() {
|
|||||||
Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos
|
Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos
|
||||||
|
|
||||||
#ifdef MACOS_BUNDLE
|
#ifdef MACOS_BUNDLE
|
||||||
ResourceHelper::initializeResourceSystem(executable_path_ + "/../Resources/resources.pack");
|
ResourceHelper::initializeResourceSystem(executable_path_ + "../Resources/resources.pack");
|
||||||
#else
|
#else
|
||||||
ResourceHelper::initializeResourceSystem("resources.pack");
|
ResourceHelper::initializeResourceSystem(executable_path_ + "resources.pack");
|
||||||
#endif
|
#endif
|
||||||
loadAssets(); // Crea el índice de archivos
|
loadAssets(); // Crea el índice de archivos
|
||||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles
|
Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles
|
||||||
@@ -174,8 +174,14 @@ void Director::loadAssets() {
|
|||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void Director::checkProgramArguments(int argc, std::span<char *> argv) {
|
void Director::checkProgramArguments(int argc, std::span<char *> argv) {
|
||||||
// Establece la ruta del programa
|
// Obtener la ruta absoluta del ejecutable
|
||||||
executable_path_ = getPath(argv[0]);
|
std::filesystem::path exe_path = std::filesystem::absolute(argv[0]);
|
||||||
|
executable_path_ = exe_path.parent_path().string();
|
||||||
|
|
||||||
|
// Asegurar que termine con separador de directorio
|
||||||
|
if (!executable_path_.empty() && executable_path_.back() != '/' && executable_path_.back() != '\\') {
|
||||||
|
executable_path_ += "/";
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba el resto de parámetros
|
// Comprueba el resto de parámetros
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user