Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7196 in orxonox.OLD for trunk/src/lib/util


Ignore:
Timestamp:
Mar 7, 2006, 11:25:58 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: spliced a nice patch from the dylib branche back here with:
svn diff -r 7168 resource_manager.* > ../../../../../trunk/fancy.resource.manager.patch

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

Legend:

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

    r7193 r7196  
    6262  strcpy(this->dataDir, "./");
    6363  this->tryDataDir("./data");
     64
     65  this->_cwd = NULL;
    6466}
    6567
     
    8688
    8789  delete[] this->dataDir;
    88 
     90  if (this->_cwd)
     91    delete[] this->_cwd;
    8992  ResourceManager::singletonRef = NULL;
    9093}
     
    945948
    946949/**
     950 * @param name the relative name of the File/Directory.
     951 * @returns a new char* with the name in abs-dir-format
     952 */
     953char* ResourceManager::getAbsDir(const char* name)
     954{
     955  if (name == NULL)
     956    return NULL;
     957  char* retName;
     958  if (strncmp(name, "/", 1))
     959  {
     960    if (*name == '.' && *(name+1) != '.')
     961      name++;
     962    const char* absDir = ResourceManager::cwd();
     963    retName = new char[strlen(absDir)+strlen(name)+1];
     964    sprintf(retName, "%s%s", absDir, name);
     965  }
     966  else
     967  {
     968    retName = new char[strlen(name)+1];
     969    strcpy(retName, name);
     970  }
     971  return retName;
     972}
     973
     974
     975/**
    947976 * @param fileName the Name of the File to check
    948977 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
     
    964993    return NULL;
    965994  }
     995}
     996
     997#ifdef __unix__
     998  #include <unistd.h>
     999#elif __WIN32__ || _MS_DOS_
     1000  #include <dir.h>
     1001#else
     1002  #include <direct.h> /* Visual C++ */
     1003#endif
     1004/**
     1005 * @returns the Current Woring Directory
     1006 */
     1007const char* ResourceManager::cwd()
     1008{
     1009  if (ResourceManager::getInstance()->_cwd == NULL)
     1010  {
     1011    char cwd[1024];
     1012    char* errorCode = getcwd(cwd, 1024);
     1013    if (errorCode == 0)
     1014      return NULL;
     1015
     1016    ResourceManager::getInstance()->_cwd = new char[strlen(cwd)+1];
     1017    strcpy(ResourceManager::getInstance()->_cwd, cwd);
     1018  }
     1019  return ResourceManager::getInstance()->_cwd;
    9661020}
    9671021
  • trunk/src/lib/util/loading/resource_manager.h

    r7193 r7196  
    137137  static char* getFullName(const char* fileName);
    138138  static bool isInDataDir(const char* fileName);
     139  static char* getAbsDir(const char* fileName);
     140  static const char* cwd();
    139141
    140142  static const char* ResourceTypeToChar(ResourceType type);
     
    149151  static ResourceManager*  singletonRef;       //!< singleton Reference
    150152
     153  char*                    _cwd;               //!< The currend Working directory.
    151154  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
    152155  std::vector<char*>       imageDirs;          //!< A list of directories in which images are stored.
Note: See TracChangeset for help on using the changeset viewer.