Changeset 7196 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Mar 7, 2006, 11:25:58 PM (19 years ago)
- Location:
- trunk/src/lib/util/loading
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/loading/resource_manager.cc
r7193 r7196 62 62 strcpy(this->dataDir, "./"); 63 63 this->tryDataDir("./data"); 64 65 this->_cwd = NULL; 64 66 } 65 67 … … 86 88 87 89 delete[] this->dataDir; 88 90 if (this->_cwd) 91 delete[] this->_cwd; 89 92 ResourceManager::singletonRef = NULL; 90 93 } … … 945 948 946 949 /** 950 * @param name the relative name of the File/Directory. 951 * @returns a new char* with the name in abs-dir-format 952 */ 953 char* 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 /** 947 976 * @param fileName the Name of the File to check 948 977 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist … … 964 993 return NULL; 965 994 } 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 */ 1007 const 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; 966 1020 } 967 1021 -
trunk/src/lib/util/loading/resource_manager.h
r7193 r7196 137 137 static char* getFullName(const char* fileName); 138 138 static bool isInDataDir(const char* fileName); 139 static char* getAbsDir(const char* fileName); 140 static const char* cwd(); 139 141 140 142 static const char* ResourceTypeToChar(ResourceType type); … … 149 151 static ResourceManager* singletonRef; //!< singleton Reference 150 152 153 char* _cwd; //!< The currend Working directory. 151 154 char* dataDir; //!< The Data Directory, where all relevant Data is stored. 152 155 std::vector<char*> imageDirs; //!< A list of directories in which images are stored.
Note: See TracChangeset
for help on using the changeset viewer.