Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2005, 11:29:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/heightMap: merged the Trunk back into branches/heightMap:
merged with Command
svn merge -r 3918:HEAD trunk branches/heightMap
conflicts resolved in favor of the Trunk

Location:
orxonox/branches/heightMap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/heightMap

    • Property svn:externals
      •  

        old new  
        1 data http://svn.orxonox.ethz.ch/data
         1
  • orxonox/branches/heightMap/src/util/resource_manager.cc

    r3883 r4122  
    9292      this->dataDir = new char[strlen(dataDir)+1];
    9393      strcpy(this->dataDir, dataDir);
     94      return true;
    9495    }
    9596  else
    9697    {
    9798      PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir, this->dataDir);
    98     }
     99      return false;
     100    }
     101}
     102
     103/**
     104   \brief checks for the DataDirectory, by looking if
     105   \param fileInside is inisde??
     106*/
     107bool ResourceManager::checkDataDir(const char* fileInside)
     108{
     109  bool retVal;
     110  if (!isDir(this->dataDir))
     111    {
     112      PRINTF(1)("%s is not a directory\n", this->dataDir);
     113      return false;
     114    }
     115 
     116  char* testFile = new char[strlen(this->dataDir)+strlen(fileInside)+1];
     117  sprintf(testFile, "%s%s", this->dataDir, fileInside);
     118  retVal = isFile(testFile);
     119  delete testFile;
     120  return retVal;
    99121}
    100122
     
    180202  // searching if the resource was loaded before.
    181203  Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3);
    182   if (tmpResource) // if the resource was not loaded before.
     204  if (tmpResource) // if the resource was loaded before.
    183205    {
    184206      PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
     
    199221
    200222      // creating the full name. (directoryName + FileName)
    201       char* fullName = new char[strlen(dataDir)+strlen(fileName)+1];
    202       sprintf(fullName, "%s%s", this->dataDir, fileName);
    203      
     223      char* fullName = new char[strlen(this->getDataDir())+strlen(fileName)+1];
     224      sprintf(fullName, "%s%s", this->getDataDir(), fileName);
    204225      // Checking for the type of resource \see ResourceType
    205226      switch(type)
     
    211232            tmpResource->modelSize = 1.0;
    212233
    213           if(isFile(fullName))
     234          if(ResourceManager::isFile(fullName))
    214235            tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
    215236          else
     
    508529    }
    509530
    510   stat(tmpDirName, &status);
    511   if (status.st_mode & (S_IFDIR
     531  if(!stat(tmpDirName, &status))
     532    {
     533      if (status.st_mode & (S_IFDIR
    512534#ifndef __WIN32__
    513                         | S_IFLNK
     535                            | S_IFLNK
    514536#endif
    515                         ))
    516     {
    517       delete tmpDirName;
    518       return true;
     537                            ))
     538        {
     539          delete tmpDirName;
     540          return true;
     541        }
     542      else
     543        {
     544          delete tmpDirName;
     545          return false;
     546        }
    519547    }
    520548  else
    521     {
    522       delete tmpDirName;
    523       return false;
    524     }
     549    return false;
    525550}
    526551
     
    532557bool ResourceManager::isFile(const char* fileName)
    533558{
     559  char* tmpFileName = ResourceManager::homeDirCheck(fileName);
     560  // actually checks the File
    534561  struct stat status;
    535   stat(fileName, &status);
    536   if (status.st_mode & (S_IFREG
     562  if (!stat(tmpFileName, &status))
     563    {
     564      if (status.st_mode & (S_IFREG
    537565#ifndef __WIN32__
    538                         | S_IFLNK
     566                            | S_IFLNK
    539567#endif
    540                         ))
    541     return true;
     568                            ))
     569        {
     570          delete tmpFileName;
     571          return true;
     572        }
     573      else
     574        {
     575          delete tmpFileName;
     576          return false;
     577        }
     578    }
     579  else
     580    {
     581      delete tmpFileName;
     582      return false;
     583    }
     584}
     585
     586bool ResourceManager::touchFile(const char* fileName)
     587{
     588  char* tmpName = ResourceManager::homeDirCheck(fileName);
     589
     590  FILE* stream;
     591  if( (stream = fopen (tmpName, "w")) == NULL)
     592    {
     593      PRINTF(1)("could not open %s fro writing\n", fileName);
     594      return false;
     595    }
     596  fclose(stream);
     597   
     598  delete tmpName;
     599}
     600
     601bool ResourceManager::deleteFile(const char* fileName)
     602{
     603  char* tmpName = ResourceManager::homeDirCheck(fileName);
     604  unlink(tmpName);
     605  delete tmpName;
     606}
     607
     608char* ResourceManager::homeDirCheck(const char* name)
     609{
     610  char* retName;
     611  if (!strncmp(name, "~/", 2))
     612    {
     613      char tmpFileName[500];
     614#ifdef __WIN32__
     615      strcpy(tmpFileName, getenv("USERPROFILE"));
     616#else
     617      strcpy(tmpFileName, getenv("HOME"));
     618#endif
     619      retName = new char[strlen(tmpFileName)+strlen(name)];
     620      sprintf(retName, "%s%s", tmpFileName, name+1);
     621    }
    542622  else
    543     return false;
    544 }
     623    {
     624      retName = new char[strlen(name)+1];
     625      strcpy(retName, name);
     626    }
     627  return retName;
     628}
     629
     630
    545631
    546632/**
Note: See TracChangeset for help on using the changeset viewer.