b746578bc8
Sustituye en bloque las cabeceras de los archivos por una sola línea de copyright. Cero rastro de "Visente", "Sergi" o "1999" en el árbol del proyecto. Se eliminan también las variantes "© 2025 Port a C++20", "© 2025 Port a C++20 con SDL3" y "© 2025 Orni Attack" (con todas sus colas descriptivas como "Arquitectura de entidades" o "Sistema de física"), que en este punto eran ruido histórico. Aplicado con un par de sed (find -type f, excluyendo source/external y source/legacy): 1. \|^// © 1999 Visente i Sergi (versión Pascal)$|d 2. s|^// © 2025 (Port a C++20.*|Orni Attack.*)$|// © 2026 JailDesigner| Verificado: la única variante de cabecera tras el sweep es "// © 2026 JailDesigner". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
2.5 KiB
C++
91 lines
2.5 KiB
C++
// path_utils.cpp - Implementació de utilitats de rutes
|
|
// © 2026 JailDesigner
|
|
|
|
#include "path_utils.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
|
|
namespace Utils {
|
|
|
|
// Variables globals per guardar argv[0]
|
|
static std::string executable_path_;
|
|
static std::string executable_directory_;
|
|
|
|
// Inicialitzar el sistema de rutes con argv[0]
|
|
void initializePathSystem(const char* argv0) {
|
|
if (argv0 == nullptr) {
|
|
std::cerr << "[PathUtils] ADVERTÈNCIA: argv[0] es nullptr\n";
|
|
executable_path_ = "";
|
|
executable_directory_ = ".";
|
|
return;
|
|
}
|
|
|
|
executable_path_ = argv0;
|
|
|
|
// Extreure el directori
|
|
std::filesystem::path path(argv0);
|
|
executable_directory_ = path.parent_path().string();
|
|
|
|
if (executable_directory_.empty()) {
|
|
executable_directory_ = ".";
|
|
}
|
|
|
|
std::cout << "[PathUtils] Executable: " << executable_path_ << "\n";
|
|
std::cout << "[PathUtils] Directori: " << executable_directory_ << "\n";
|
|
}
|
|
|
|
// Obtenir el directori de l'executable
|
|
std::string getExecutableDirectory() {
|
|
if (executable_directory_.empty()) {
|
|
std::cerr << "[PathUtils] ADVERTÈNCIA: Sistema de rutes no inicialitzat\n";
|
|
return ".";
|
|
}
|
|
return executable_directory_;
|
|
}
|
|
|
|
// Detectar si estem dins un bundle de macOS
|
|
bool isMacOSBundle() {
|
|
#ifdef MACOS_BUNDLE
|
|
return true;
|
|
#else
|
|
// Detecció en time de execució
|
|
// Cercar ".app/Contents/MacOS" a la ruta de l'executable
|
|
std::string exe_dir = getExecutableDirectory();
|
|
return exe_dir.find(".app/Contents/MacOS") != std::string::npos;
|
|
#endif
|
|
}
|
|
|
|
// Obtenir la ruta base dels recursos
|
|
std::string getResourceBasePath() {
|
|
std::string exe_dir = getExecutableDirectory();
|
|
|
|
if (isMacOSBundle()) {
|
|
// Bundle de macOS: recursos a ../Resources desde MacOS/
|
|
std::cout << "[PathUtils] Detectat bundle de macOS\n";
|
|
return exe_dir + "/../Resources";
|
|
} // Executable normal: recursos al mismo directori
|
|
return exe_dir;
|
|
}
|
|
|
|
// Normalitzar ruta (convertir barres, etc.)
|
|
std::string normalizePath(const std::string& path) {
|
|
std::string normalized = path;
|
|
|
|
// Convertir barres invertides a normals
|
|
std::ranges::replace(normalized, '\\', '/');
|
|
|
|
// Simplificar rutes con filesystem
|
|
try {
|
|
std::filesystem::path fs_path(normalized);
|
|
normalized = fs_path.lexically_normal().string();
|
|
} catch (const std::exception& e) {
|
|
std::cerr << "[PathUtils] Error normalitzant ruta: " << e.what() << "\n";
|
|
}
|
|
|
|
return normalized;
|
|
}
|
|
|
|
} // namespace Utils
|