Changeset 4178 in orxonox.OLD for orxonox/branches/physics/src/util/resource_manager.cc
- Timestamp:
- May 13, 2005, 11:16:33 PM (20 years ago)
- Location:
- orxonox/branches/physics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/physics
- Property svn:externals
-
old new 1 data http://svn.orxonox.ethz.ch/data 1
-
- Property svn:externals
-
orxonox/branches/physics/src/util/resource_manager.cc
r3953 r4178 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; 519 } 520 else 521 { 522 delete tmpDirName; 523 return false; 524 } 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; 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; 542 else 543 return false; 544 } 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 */ 590 bool 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 */ 609 bool 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 */ 621 char* 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 */ 648 char* ResourceManager::getFullName(const char* fileName) 649 { 650 char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir()) + strlen(fileName)+1]; 651 sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName); 652 if (ResourceManager::isFile(retName)) 653 return retName; 654 else 655 { 656 delete retName; 657 return NULL; 658 } 659 } 660 545 661 546 662 /**
Note: See TracChangeset
for help on using the changeset viewer.