c45e524109
Pase automático de clang-tidy --fix sobre el conjunto de checks que son puro transform de sintaxis y no rompen API. Invocado con --format-style=none para que clang-tidy NO arrastre clang-format sobre las líneas tocadas (evita la regla NamespaceIndentation: All del .clang-format reformateando solo trozos del archivo). Checks aplicados: - modernize-use-trailing-return-type (193 hits): 'int foo()' → 'auto foo() -> int'. Estilo coherente con la convención del proyecto. - modernize-use-default-member-init (36 hits): inicialización de miembros pasa de la lista del constructor a la declaración. Reduce duplicación cuando hay varios constructores con los mismos defaults. - modernize-use-auto (6 hits): tipos largos sustituidos por auto donde el tipo es evidente del contexto (new T, dynamic_cast, etc). - modernize-use-starts-ends-with (2 hits): s.rfind(x) == 0 → s.starts_with(x), aprovechando C++20. - performance-enum-size (10 hits): enums pequeños declaran tipo subyacente (uint8_t / similar) para reducir tamaño y precisar layout. NO aplicado en este pase (riesgo de cambios semánticos o de API): - readability-identifier-naming (renames pueden romper callsites parciales) - readability-convert-member-functions-to-static (cambia firma) - readability-use-anyofallof (reescribe loops, side effects) - readability-function-cognitive-complexity (requiere refactor manual) - bugs reales (bugprone-*, clang-diagnostic-*) → uno a uno Cambios manuales asociados: - SDLManager::clear() ahora devuelve bool: propaga el resultado de beginFrame al caller para que Director::runFrameLoop salte draw+present cuando la swapchain no esté disponible (ventana minimizada). Antes la función ignoraba el [[nodiscard]] del beginFrame y los vértices se acumulaban en el batch sin nadie que los consumiera. - vector_text.cpp: borrada la línea suelta "// Test pre-commit hook" que quedó como cruft. clang-tidy crashea en LLVM 19.1 con performance-noexcept-move-constructor (recursión infinita en ExceptionSpecAnalyzer al procesar std::set); check deshabilitado en .clang-tidy con comentario explicativo. Build limpio, smoke test OK. 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
|
|
auto getExecutableDirectory() -> std::string {
|
|
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
|
|
auto isMacOSBundle() -> bool {
|
|
#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
|
|
auto getResourceBasePath() -> std::string {
|
|
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.)
|
|
auto normalizePath(const std::string& path) -> std::string {
|
|
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
|