Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5480 in orxonox.OLD for trunk/src/util


Ignore:
Timestamp:
Nov 3, 2005, 9:08:19 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: better check for data-dir

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

Legend:

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

    r5479 r5480  
    6060  this->dataDir = new char[3];
    6161  strcpy(this->dataDir, "./");
    62   this->setDataDir("./data");
     62  this->tryDataDir("./data");
    6363  this->imageDirs = new tList<char>;
    6464  this->resourceList = new tList<Resource>;
     
    9999 *  sets the data main directory
    100100 * @param dataDir the DataDirectory.
    101 */
     101 */
    102102bool ResourceManager::setDataDir(const char* dataDir)
    103103{
    104104  char* realDir = ResourceManager::homeDirCheck(dataDir);
    105105  if (isDir(realDir))
    106     {
    107       delete[] this->dataDir;
    108       if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\')
    109       {
    110         this->dataDir = new char[strlen(realDir)+1];
    111         strcpy(this->dataDir, realDir);
    112       }
    113       else
    114       {
    115         this->dataDir = new char[strlen(realDir)+2];
    116         strcpy(this->dataDir, realDir);
    117         this->dataDir[strlen(realDir)] = '/';
    118         this->dataDir[strlen(realDir)+1] = '\0';
    119       }
    120       delete[] realDir;
    121       return true;
    122     }
    123   else
    124     {
    125       PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir, this->dataDir);
    126       delete[] realDir;
    127       return false;
    128     }
    129 }
    130 
    131 /**
    132  *  checks for the DataDirectory, by looking if
    133  * @param fileInside is inisde??
    134 */
    135 bool ResourceManager::checkDataDir(const char* fileInside)
     106  {
     107    delete[] this->dataDir;
     108    if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\')
     109    {
     110      this->dataDir = new char[strlen(realDir)+1];
     111      strcpy(this->dataDir, realDir);
     112    }
     113    else
     114    {
     115      this->dataDir = new char[strlen(realDir)+2];
     116      strcpy(this->dataDir, realDir);
     117      this->dataDir[strlen(realDir)] = '/';
     118      this->dataDir[strlen(realDir)+1] = '\0';
     119    }
     120    delete[] realDir;
     121    return true;
     122  }
     123  else
     124  {
     125    PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", realDir, this->dataDir);
     126    delete[] realDir;
     127    return false;
     128  }
     129}
     130
     131/**
     132 * sets the data main directory
     133 * @param dataDir the DataDirectory.
     134 *
     135 * this is essentially the same as setDataDir, but it ommits the error-message
     136 */
     137bool ResourceManager::tryDataDir(const char* dataDir)
     138{
     139  char* realDir = ResourceManager::homeDirCheck(dataDir);
     140  if (isDir(realDir))
     141  {
     142    delete[] this->dataDir;
     143    if (dataDir[strlen(dataDir)-1] == '/' || dataDir[strlen(dataDir)-1] == '\\')
     144    {
     145      this->dataDir = new char[strlen(realDir)+1];
     146      strcpy(this->dataDir, realDir);
     147    }
     148    else
     149    {
     150      this->dataDir = new char[strlen(realDir)+2];
     151      strcpy(this->dataDir, realDir);
     152      this->dataDir[strlen(realDir)] = '/';
     153      this->dataDir[strlen(realDir)+1] = '\0';
     154    }
     155    delete[] realDir;
     156    return true;
     157  }
     158}
     159
     160
     161
     162/**
     163 * checks for the DataDirectory, by looking if
     164 * @param fileInside is iniside of the given directory.
     165*/
     166bool ResourceManager::verifyDataDir(const char* fileInside)
    136167{
    137168  bool retVal;
  • trunk/src/util/loading/resource_manager.h

    r5479 r5480  
    107107  inline const char* getDataDir() const { return this->dataDir; };
    108108
    109   bool checkDataDir(const char* fileInside);
    110  bool addImageDir(const char* imageDir);
     109
     110  bool tryDataDir(const char* dataDir);
     111  bool verifyDataDir(const char* fileInside);
     112  bool addImageDir(const char* imageDir);
    111113  BaseObject* load(const char* fileName, ResourcePriority prio = RP_NO,
    112114               void* param1 = NULL, void* param2 = NULL, void* param3 = NULL);
     
    120122
    121123
    122   // utility functions of this class
     124  // utility functions for handling files in and around the data-directory
    123125  static bool isDir(const char* directory);
    124126  static bool isFile(const char* fileName);
     
    130132
    131133  static const char* ResourceTypeToChar(ResourceType type);
     134
    132135
    133136 private:
Note: See TracChangeset for help on using the changeset viewer.