Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4217 in orxonox.OLD for orxonox/branches/movie_player/src/util


Ignore:
Timestamp:
May 18, 2005, 11:27:40 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/movie_player: merged the trunk back into the movie_player
merged with command:
svn merge -r 4014:HEAD ../trunk/ movie_player/
no conflicts

Location:
orxonox/branches/movie_player/src/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/movie_player/src/util/resource_manager.cc

    r3983 r4217  
    9999      return false;
    100100    }
     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;
    101121}
    102122
     
    182202  // searching if the resource was loaded before.
    183203  Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3);
    184   if (tmpResource) // if the resource was not loaded before.
     204  if (tmpResource) // if the resource was loaded before.
    185205    {
    186206      PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
     
    201221
    202222      // creating the full name. (directoryName + FileName)
    203       char* fullName = new char[strlen(dataDir)+strlen(fileName)+1];
    204       sprintf(fullName, "%s%s", this->dataDir, fileName);
    205      
     223      char* fullName = new char[strlen(this->getDataDir())+strlen(fileName)+1];
     224      sprintf(fullName, "%s%s", this->getDataDir(), fileName);
    206225      // Checking for the type of resource \see ResourceType
    207226      switch(type)
     
    213232            tmpResource->modelSize = 1.0;
    214233
    215           if(isFile(fullName))
     234          if(ResourceManager::isFile(fullName))
    216235            tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize);
    217236          else
     
    510529    }
    511530
    512   stat(tmpDirName, &status);
    513   if (status.st_mode & (S_IFDIR
     531  if(!stat(tmpDirName, &status))
     532    {
     533      if (status.st_mode & (S_IFDIR
    514534#ifndef __WIN32__
    515                         | S_IFLNK
     535                            | S_IFLNK
    516536#endif
    517                         ))
    518     {
    519       delete tmpDirName;
    520       return true;
    521     }
    522   else
    523     {
    524       delete tmpDirName;
    525       return false;
    526     }
     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;
    527550}
    528551
     
    534557bool ResourceManager::isFile(const char* fileName)
    535558{
     559  char* tmpFileName = ResourceManager::homeDirCheck(fileName);
     560  // actually checks the File
    536561  struct stat status;
    537   stat(fileName, &status);
    538   if (status.st_mode & (S_IFREG
     562  if (!stat(tmpFileName, &status))
     563    {
     564      if (status.st_mode & (S_IFREG
    539565#ifndef __WIN32__
    540                         | S_IFLNK
     566                            | S_IFLNK
    541567#endif
    542                         ))
    543     return true;
    544   else
    545     return false;
    546 }
     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())
     651                           + strlen(fileName) + 1];
     652  sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
     653  if (ResourceManager::isFile(retName))
     654    return retName;
     655  else
     656    {
     657      delete retName;
     658      return NULL;
     659    }
     660}
     661
    547662
    548663/**
  • orxonox/branches/movie_player/src/util/resource_manager.h

    r3983 r4217  
    1818
    1919//! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support
    20 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, TTF, IMAGE};
     20enum ResourceType {OBJ,
     21                   PRIM,
     22                   WAV,
     23                   MP3,
     24                   OGG,
     25                   TTF,
     26                   IMAGE};
    2127//! An enumerator for different UNLOAD-types.
    2228/**
     
    2632   RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox)
    2733*/
    28 enum ResourcePriority {RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, RP_GAME = 3};
     34enum ResourcePriority {RP_NO = 0,
     35                       RP_LEVEL = 1,
     36                       RP_CAMPAIGN = 2,
     37                       RP_GAME = 3};
    2938
    3039//! A Struct that keeps track about A resource its name its Type, and so on
     
    6574
    6675  bool setDataDir(const char* dataDir);
     76  /** \returns the Name of the data directory */
     77  inline const char* getDataDir(void) const {return this->dataDir;}
     78
     79  bool checkDataDir(const char* fileInside);
    6780  bool addImageDir(char* imageDir);
    6881  void* load(const char* fileName, ResourcePriority prio = RP_NO,
     
    7891  // utility functions of this class
    7992  static bool isDir(const char* directory);
    80   static bool isFile(const char* directory);
     93  static bool isFile(const char* fileName);
     94  static bool touchFile(const char* fileName);
     95  static bool deleteFile(const char* fileName);
     96  static char* homeDirCheck(const char* fileName);
     97  static char* getFullName(const char* fileName);
    8198
    8299 private:
Note: See TracChangeset for help on using the changeset viewer.