diff --git a/CMakeLists.txt b/CMakeLists.txt index 085265d..ce51930 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(ptf) # Inclusion des fichiers d'en-tête et de source include_directories(include) -file(GLOB SOURCES "src/*.cpp") +file(GLOB SOURCES "src/*.cpp" "src/*.c") # Affichage de tous les avertisements if(MSVC) diff --git a/src/resource_manager.cpp b/src/resource_manager.cpp index 3754640..9fde703 100644 --- a/src/resource_manager.cpp +++ b/src/resource_manager.cpp @@ -1,15 +1,10 @@ #include "resource_manager.hpp" +#include "whereami.h" #include -// fonctionnalités cross-platform pour les fichiers -// source: http://stackoverflow.com/a/145309/3452708 -#include #ifdef _WIN32 - #include - #define getcwd _getcwd #define FILE_SEP '\\' #else - #include #define FILE_SEP '/' #endif @@ -18,17 +13,20 @@ ResourceManager::~ResourceManager() { } /** - * Récupère le chemin actuel de l'exécutable - * sous la forme d'une chaîne de caractères + * Récupère le chemin actuel de l'exécutable sous la forme + * d'une chaîne de caractères grâce à la librairie whereami */ std::string getCurrentDirectory() { - char buffer[FILENAME_MAX]; + int length = wai_getExecutablePath(NULL, 0, NULL), dirname_length; + char* buffer = new char[length + 1]; + wai_getExecutablePath(buffer, length, &dirname_length); - if (getcwd(buffer, sizeof(buffer)) != NULL) { - return std::string(buffer); + if (dirname_length == 0) { + throw std::runtime_error("Impossible de déterminer le chemin actuel"); } - throw std::runtime_error("Impossible de déterminer le chemin actuel"); + buffer[length] = '\0'; + return std::string(buffer).substr(0, dirname_length); } sf::Texture& ResourceManager::getTexture(std::string name) {