--- wormux/wormux/src/avatar.cpp 2004/05/29 18:25:46 1.7 +++ wormux/wormux/src/avatar.cpp 2004/06/02 15:45:05 1.8 @@ -32,6 +32,7 @@ #include "graphisme.h" #include "gst_fichier.h" #include +#include using namespace Wormux; using namespace std; @@ -84,41 +85,6 @@ //----------------------------------------------------------------------------- -void InitAvatars() -{ - Avatar avatar; - std::string repertoire = DATADIR+"avatar/"; - std::string nom_avatar, nomfich, rep_avatar; - struct dirent *fichier; - DIR *dir; - - dir = opendir(repertoire.c_str()); - if (dir == NULL) - Erreur ("Impossible d'ouvrir le répertoire des avatars ("+repertoire+")"); - - // Parcours le répertoire des avatars - while ((fichier = readdir(dir)) != NULL) - { - // On a trouvé un répertoire ? - if ((fichier -> d_type == DT_DIR) && (fichier -> d_name[0] != '.')) - { - nom_avatar = fichier -> d_name; - rep_avatar = repertoire+nom_avatar+'/'; - - // Si on arrive à le charger correctement, l'ajoute à la liste - if (FichierExiste(rep_avatar+NOMFICH_CONFIG) - && avatar.Charge (nom_avatar, rep_avatar)) - { - lst_avatar.insert (paire_avatar(nom_avatar, avatar)); - } - } - } - - closedir (dir); -} - -//----------------------------------------------------------------------------- - bool Avatar::Charge (const std::string &nom, const std::string &repertoire) { try @@ -221,6 +187,44 @@ Xml_LitArme (baseball, LitDocXml::AccesBalise (armes, "baseball")); } return true; +} + +//----------------------------------------------------------------------------- + +void InitAvatars() +{ + Avatar avatar; + std::string repertoire = DATADIR+"avatar/"; + struct dirent *fichier; + DIR *dir; + + dir = opendir(repertoire.c_str()); + if (dir == NULL) + Erreur ("Impossible d'ouvrir le répertoire des avatars ("+repertoire+")"); + + // Parcours le répertoire des avatars + while ((fichier = readdir(dir)) != NULL) + { + std::string nomfich_complet = repertoire+fichier -> d_name; + struct stat stat_file; + + // On a trouvé un répertoire ? + if ((fichier -> d_name[0] != '.') + && (stat(nomfich_complet.c_str(), &stat_file) == 0) + && (S_ISDIR(stat_file.st_mode))) + { + std::string rep_avatar = nomfich_complet+'/'; + + // Si on arrive à le charger correctement, l'ajoute à la liste + if (FichierExiste(rep_avatar+NOMFICH_CONFIG) + && avatar.Charge (fichier -> d_name, rep_avatar)) + { + lst_avatar.insert (paire_avatar(fichier -> d_name, avatar)); + } + } + } + + closedir (dir); } //----------------------------------------------------------------------------- --- wormux/wormux/src/gst_equipes.cpp 2004/06/01 17:07:35 1.2 +++ wormux/wormux/src/gst_equipes.cpp 2004/06/02 15:45:05 1.3 @@ -24,6 +24,7 @@ #include "constante.h" #include "gst_fichier.h" #include +#include #include //----------------------------------------------------------------------------- GestionEquipes gst_equipes; @@ -76,8 +77,7 @@ void GestionEquipes::ChargeListe() { - std::string repertoire = DATADIR+"equipe/"; - std::string nom_equipe, nomfich, rep_equipe ; + const std::string repertoire = DATADIR+"equipe/"; struct dirent *fichier; DIR *dir; @@ -89,13 +89,24 @@ liste.clear() ; while ((fichier = readdir(dir)) != NULL) { + std::string nomfich_complet = repertoire+fichier -> d_name; + struct stat stat_file; + // On a trouvé un fichier normal ? - if ((fichier -> d_type == DT_DIR) && (fichier -> d_name[0] != '.')) + if ((fichier -> d_name[0] != '.') + && (stat(nomfich_complet.c_str(), &stat_file) == 0) + && (S_ISDIR(stat_file.st_mode))) { + // Ajoute l'équipe à la liste Equipe nv_equipe; liste_complete.push_back(nv_equipe); - std::string nomfich = fichier -> d_name; - if (!liste_complete.back().Init (-1, nomfich)) liste_complete.pop_back(); + + // Charge les données de l'équipe, + // en cas d'erreur retire l'équipe de la liste + if (!liste_complete.back().Init (-1, fichier -> d_name)) + { + liste_complete.pop_back(); + } } } closedir (dir); --- wormux/wormux/src/lst_terrain.cpp 2004/06/01 17:07:35 1.1 +++ wormux/wormux/src/lst_terrain.cpp 2004/06/02 15:45:05 1.2 @@ -25,6 +25,7 @@ #include "monde.h" #include "gst_fichier.h" #include +#include //----------------------------------------------------------------------------- ListeTerrain lst_terrain; //----------------------------------------------------------------------------- @@ -96,8 +97,12 @@ struct dirent *fichier; while ((fichier = readdir(dir)) != NULL) { - // On a trouvé un répertoire ? - if ((fichier -> d_type == DT_DIR) && (fichier -> d_name[0] != '.')) + std::string nomfich_complet = repertoire+fichier -> d_name; + struct stat stat_file; + + if ((fichier -> d_name[0] != '.') + && (stat(nomfich_complet.c_str(), &stat_file) == 0) + && (S_ISDIR(stat_file.st_mode))) { InfoTerrain nv_terrain; bool ok = nv_terrain.Init (fichier -> d_name);