Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3883 in orxonox.OLD


Ignore:
Timestamp:
Apr 18, 2005, 11:03:16 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: now a check for a directory should return true also in Windows

Location:
orxonox/trunk/src/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/resource_manager.cc

    r3869 r3883  
    3939{
    4040   this->setClassName ("ResourceManager");
    41    this->dataDir = "./";
     41   this->dataDir = NULL;
     42   this->setDataDir("./");
    4243   this->imageDirs = new tList<char>();
    4344   this->resourceList = new tList<Resource>();
     
    8485   \param dataDir the DataDirectory.
    8586*/
    86 bool ResourceManager::setDataDir(char* dataDir)
     87bool ResourceManager::setDataDir(const char* dataDir)
    8788{
    8889  if (isDir(dataDir))
    8990    {
     91      delete this->dataDir;
    9092      this->dataDir = new char[strlen(dataDir)+1];
    9193      strcpy(this->dataDir, dataDir);
     
    9395  else
    9496    {
    95       PRINTF(1)("%s is not a Directory, and can not be the Data Directory\n", dataDir);
     97      PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir, this->dataDir);
    9698    }
    9799}
     
    490492bool ResourceManager::isDir(const char* directoryName)
    491493{
     494  char* tmpDirName = NULL;
    492495  struct stat status;
    493   stat(directoryName, &status);
    494   if (status.st_mode & (S_IFDIR
     496
     497  // checking for the termination of the string given. If there is a "/" at the end cut it away
     498  if (directoryName[strlen(directoryName)-1] == '/')
     499    {
     500      tmpDirName = new char[strlen(directoryName)+1];
     501      strncpy(tmpDirName, directoryName, strlen(directoryName)-1);
     502      tmpDirName[strlen(directoryName)-1] = '\0';
     503    }
     504  else
     505    {
     506      tmpDirName = new char[strlen(directoryName)+1];
     507      strcpy(tmpDirName, directoryName);
     508    }
     509
     510  stat(tmpDirName, &status);
     511  if (status.st_mode & (S_IFDIR
    495512#ifndef __WIN32__
    496513                        | S_IFLNK
    497514#endif
    498515                        ))
    499     return true;
    500   else
    501     return false;
     516    {
     517      delete tmpDirName;
     518      return true;
     519    }
     520  else
     521    {
     522      delete tmpDirName;
     523      return false;
     524    }
    502525}
    503526
  • orxonox/trunk/src/util/resource_manager.h

    r3869 r3883  
    6565  virtual ~ResourceManager();
    6666
    67   bool setDataDir(char* dataDir);
     67  bool setDataDir(const char* dataDir);
    6868  bool addImageDir(char* imageDir);
    6969  void* load(const char* fileName, ResourcePriority prio = RP_NO,
Note: See TracChangeset for help on using the changeset viewer.