Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 16, 2005, 1:33:19 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/openAL: merged trunk back to openAL
merged with command:

svn merge ../trunk/ openAL/ -r 3920:HEAD

no conflicts at all

Location:
orxonox/branches/openAL
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/openAL

    • Property svn:externals
      •  

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

    r3883 r4194  
    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;
    519     }
    520   else
    521     {
    522       delete tmpDirName;
    523       return false;
    524     }
     537                            ))
     538        {
     539          delete tmpDirName;
     540          return true;
     541        }
     542      else
     543        {
     544          delete tmpDirName;
     545          return false;
     546        }
     547    }
     548  else
     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;
    542   else
    543     return false;
    544 }
     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
     586/**
     587   \brief touches a File on the disk (thereby creating it)
     588   \param fileName The file to touch
     589*/
     590bool ResourceManager::touchFile(const char* fileName)
     591{
     592  char* tmpName = ResourceManager::homeDirCheck(fileName);
     593
     594  FILE* stream;
     595  if( (stream = fopen (tmpName, "w")) == NULL)
     596    {
     597      PRINTF(1)("could not open %s fro writing\n", fileName);
     598      return false;
     599    }
     600  fclose(stream);
     601   
     602  delete tmpName;
     603}
     604
     605/**
     606   \brief deletes a File from disk
     607   \param fileName the File to delete
     608*/
     609bool ResourceManager::deleteFile(const char* fileName)
     610{
     611  char* tmpName = ResourceManager::homeDirCheck(fileName);
     612  unlink(tmpName);
     613  delete tmpName;
     614}
     615
     616/**
     617    \param fileName the Name of the file to check
     618    \returns The name of the file, including the HomeDir
     619    IMPORTANT: this has to be deleted from the outside
     620*/
     621char* ResourceManager::homeDirCheck(const char* name)
     622{
     623  char* retName;
     624  if (!strncmp(name, "~/", 2))
     625    {
     626      char tmpFileName[500];
     627#ifdef __WIN32__
     628      strcpy(tmpFileName, getenv("USERPROFILE"));
     629#else
     630      strcpy(tmpFileName, getenv("HOME"));
     631#endif
     632      retName = new char[strlen(tmpFileName)+strlen(name)];
     633      sprintf(retName, "%s%s", tmpFileName, name+1);
     634    }
     635  else
     636    {
     637      retName = new char[strlen(name)+1];
     638      strcpy(retName, name);
     639    }
     640  return retName;
     641}
     642
     643/**
     644    \param fileName the Name of the File to check
     645    \returns The full name of the file, including the DataDir, and NULL if the file does not exist
     646    IMPORTANT: this has to be deleted from the outside
     647*/
     648char* ResourceManager::getFullName(const char* fileName)
     649{
     650  char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(fileName)+1];
     651  sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
     652  if (ResourceManager::isFile(retName))
     653    return retName;
     654  else
     655    {
     656      delete retName;
     657      return NULL;
     658    }
     659}
     660
    545661
    546662/**
Note: See TracChangeset for help on using the changeset viewer.