Changeset 4122 in orxonox.OLD for orxonox/branches/heightMap/src/util/resource_manager.cc
- Timestamp:
- May 9, 2005, 11:29:19 AM (19 years ago)
- Location:
- orxonox/branches/heightMap
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/heightMap
- Property svn:externals
-
old new 1 data http://svn.orxonox.ethz.ch/data 1
-
- Property svn:externals
-
orxonox/branches/heightMap/src/util/resource_manager.cc
r3883 r4122 92 92 this->dataDir = new char[strlen(dataDir)+1]; 93 93 strcpy(this->dataDir, dataDir); 94 return true; 94 95 } 95 96 else 96 97 { 97 98 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 */ 107 bool 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; 99 121 } 100 122 … … 180 202 // searching if the resource was loaded before. 181 203 Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3); 182 if (tmpResource) // if the resource was notloaded before.204 if (tmpResource) // if the resource was loaded before. 183 205 { 184 206 PRINTF(4)("not loading cached resource %s\n", tmpResource->name); … … 199 221 200 222 // 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); 204 225 // Checking for the type of resource \see ResourceType 205 226 switch(type) … … 211 232 tmpResource->modelSize = 1.0; 212 233 213 if( isFile(fullName))234 if(ResourceManager::isFile(fullName)) 214 235 tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize); 215 236 else … … 508 529 } 509 530 510 stat(tmpDirName, &status); 511 if (status.st_mode & (S_IFDIR 531 if(!stat(tmpDirName, &status)) 532 { 533 if (status.st_mode & (S_IFDIR 512 534 #ifndef __WIN32__ 513 | S_IFLNK535 | S_IFLNK 514 536 #endif 515 )) 516 { 517 delete tmpDirName; 518 return true; 537 )) 538 { 539 delete tmpDirName; 540 return true; 541 } 542 else 543 { 544 delete tmpDirName; 545 return false; 546 } 519 547 } 520 548 else 521 { 522 delete tmpDirName; 523 return false; 524 } 549 return false; 525 550 } 526 551 … … 532 557 bool ResourceManager::isFile(const char* fileName) 533 558 { 559 char* tmpFileName = ResourceManager::homeDirCheck(fileName); 560 // actually checks the File 534 561 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 537 565 #ifndef __WIN32__ 538 | S_IFLNK566 | S_IFLNK 539 567 #endif 540 )) 541 return true; 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 bool ResourceManager::touchFile(const char* fileName) 587 { 588 char* tmpName = ResourceManager::homeDirCheck(fileName); 589 590 FILE* stream; 591 if( (stream = fopen (tmpName, "w")) == NULL) 592 { 593 PRINTF(1)("could not open %s fro writing\n", fileName); 594 return false; 595 } 596 fclose(stream); 597 598 delete tmpName; 599 } 600 601 bool ResourceManager::deleteFile(const char* fileName) 602 { 603 char* tmpName = ResourceManager::homeDirCheck(fileName); 604 unlink(tmpName); 605 delete tmpName; 606 } 607 608 char* ResourceManager::homeDirCheck(const char* name) 609 { 610 char* retName; 611 if (!strncmp(name, "~/", 2)) 612 { 613 char tmpFileName[500]; 614 #ifdef __WIN32__ 615 strcpy(tmpFileName, getenv("USERPROFILE")); 616 #else 617 strcpy(tmpFileName, getenv("HOME")); 618 #endif 619 retName = new char[strlen(tmpFileName)+strlen(name)]; 620 sprintf(retName, "%s%s", tmpFileName, name+1); 621 } 542 622 else 543 return false; 544 } 623 { 624 retName = new char[strlen(name)+1]; 625 strcpy(retName, name); 626 } 627 return retName; 628 } 629 630 545 631 546 632 /**
Note: See TracChangeset
for help on using the changeset viewer.