Changeset 4217 in orxonox.OLD for orxonox/branches/movie_player/src/util
- Timestamp:
- May 18, 2005, 11:27:40 AM (20 years ago)
- Location:
- orxonox/branches/movie_player/src/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/movie_player/src/util/resource_manager.cc
r3983 r4217 99 99 return false; 100 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; 101 121 } 102 122 … … 182 202 // searching if the resource was loaded before. 183 203 Resource* tmpResource = this->locateResourceByInfo(fileName, type, param1, param2,param3); 184 if (tmpResource) // if the resource was notloaded before.204 if (tmpResource) // if the resource was loaded before. 185 205 { 186 206 PRINTF(4)("not loading cached resource %s\n", tmpResource->name); … … 201 221 202 222 // creating the full name. (directoryName + FileName) 203 char* fullName = new char[strlen(dataDir)+strlen(fileName)+1]; 204 sprintf(fullName, "%s%s", this->dataDir, fileName); 205 223 char* fullName = new char[strlen(this->getDataDir())+strlen(fileName)+1]; 224 sprintf(fullName, "%s%s", this->getDataDir(), fileName); 206 225 // Checking for the type of resource \see ResourceType 207 226 switch(type) … … 213 232 tmpResource->modelSize = 1.0; 214 233 215 if( isFile(fullName))234 if(ResourceManager::isFile(fullName)) 216 235 tmpResource->pointer = new OBJModel(fullName, tmpResource->modelSize); 217 236 else … … 510 529 } 511 530 512 stat(tmpDirName, &status); 513 if (status.st_mode & (S_IFDIR 531 if(!stat(tmpDirName, &status)) 532 { 533 if (status.st_mode & (S_IFDIR 514 534 #ifndef __WIN32__ 515 | S_IFLNK535 | S_IFLNK 516 536 #endif 517 )) 518 { 519 delete tmpDirName; 520 return true; 521 } 522 else 523 { 524 delete tmpDirName; 525 return false; 526 } 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; 527 550 } 528 551 … … 534 557 bool ResourceManager::isFile(const char* fileName) 535 558 { 559 char* tmpFileName = ResourceManager::homeDirCheck(fileName); 560 // actually checks the File 536 561 struct stat status; 537 stat(fileName, &status); 538 if (status.st_mode & (S_IFREG 562 if (!stat(tmpFileName, &status)) 563 { 564 if (status.st_mode & (S_IFREG 539 565 #ifndef __WIN32__ 540 | S_IFLNK566 | S_IFLNK 541 567 #endif 542 )) 543 return true; 544 else 545 return false; 546 } 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()) 651 + strlen(fileName) + 1]; 652 sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName); 653 if (ResourceManager::isFile(retName)) 654 return retName; 655 else 656 { 657 delete retName; 658 return NULL; 659 } 660 } 661 547 662 548 663 /** -
orxonox/branches/movie_player/src/util/resource_manager.h
r3983 r4217 18 18 19 19 //! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support 20 enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, TTF, IMAGE}; 20 enum ResourceType {OBJ, 21 PRIM, 22 WAV, 23 MP3, 24 OGG, 25 TTF, 26 IMAGE}; 21 27 //! An enumerator for different UNLOAD-types. 22 28 /** … … 26 32 RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox) 27 33 */ 28 enum ResourcePriority {RP_NO = 0, RP_LEVEL = 1, RP_CAMPAIGN = 2, RP_GAME = 3}; 34 enum ResourcePriority {RP_NO = 0, 35 RP_LEVEL = 1, 36 RP_CAMPAIGN = 2, 37 RP_GAME = 3}; 29 38 30 39 //! A Struct that keeps track about A resource its name its Type, and so on … … 65 74 66 75 bool setDataDir(const char* dataDir); 76 /** \returns the Name of the data directory */ 77 inline const char* getDataDir(void) const {return this->dataDir;} 78 79 bool checkDataDir(const char* fileInside); 67 80 bool addImageDir(char* imageDir); 68 81 void* load(const char* fileName, ResourcePriority prio = RP_NO, … … 78 91 // utility functions of this class 79 92 static bool isDir(const char* directory); 80 static bool isFile(const char* directory); 93 static bool isFile(const char* fileName); 94 static bool touchFile(const char* fileName); 95 static bool deleteFile(const char* fileName); 96 static char* homeDirCheck(const char* fileName); 97 static char* getFullName(const char* fileName); 81 98 82 99 private:
Note: See TracChangeset
for help on using the changeset viewer.