Changeset 4063 in orxonox.OLD for orxonox/branches/md2_loader/src/util
- Timestamp:
- May 5, 2005, 2:37:08 PM (20 years ago)
- Location:
- orxonox/branches/md2_loader/src/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/md2_loader/src/util/resource_manager.cc
r3983 r4063 510 510 } 511 511 512 stat(tmpDirName, &status); 513 if (status.st_mode & (S_IFDIR 512 if(!stat(tmpDirName, &status)) 513 { 514 if (status.st_mode & (S_IFDIR 514 515 #ifndef __WIN32__ 515 | S_IFLNK516 | S_IFLNK 516 517 #endif 517 )) 518 { 519 delete tmpDirName; 520 return true; 521 } 522 else 523 { 524 delete tmpDirName; 525 return false; 526 } 518 )) 519 { 520 delete tmpDirName; 521 return true; 522 } 523 else 524 { 525 delete tmpDirName; 526 return false; 527 } 528 } 529 else 530 return false; 527 531 } 528 532 … … 534 538 bool ResourceManager::isFile(const char* fileName) 535 539 { 540 char* tmpFileName = ResourceManager::homeDirCheck(fileName); 541 // actually checks the File 536 542 struct stat status; 537 stat(fileName, &status); 538 if (status.st_mode & (S_IFREG 543 if (!stat(tmpFileName, &status)) 544 { 545 if (status.st_mode & (S_IFREG 539 546 #ifndef __WIN32__ 540 | S_IFLNK547 | S_IFLNK 541 548 #endif 542 )) 543 return true; 544 else 545 return false; 546 } 549 )) 550 { 551 delete tmpFileName; 552 return true; 553 } 554 else 555 { 556 delete tmpFileName; 557 return false; 558 } 559 } 560 else 561 { 562 delete tmpFileName; 563 return false; 564 } 565 } 566 567 bool ResourceManager::touchFile(const char* fileName) 568 { 569 char* tmpName = ResourceManager::homeDirCheck(fileName); 570 571 FILE* stream; 572 if( (stream = fopen (tmpName, "w")) == NULL) 573 { 574 PRINTF(1)("could not open %s fro writing\n", fileName); 575 return false; 576 } 577 fclose(stream); 578 579 delete tmpName; 580 } 581 582 bool ResourceManager::deleteFile(const char* fileName) 583 { 584 char* tmpName = ResourceManager::homeDirCheck(fileName); 585 unlink(tmpName); 586 delete tmpName; 587 } 588 589 char* ResourceManager::homeDirCheck(const char* name) 590 { 591 char* retName; 592 if (!strncmp(name, "~/", 2)) 593 { 594 char tmpFileName[500]; 595 #ifdef __WIN32__ 596 strcpy(tmpFileName, getenv("USERPROFILE")); 597 #else 598 strcpy(tmpFileName, getenv("HOME")); 599 #endif 600 retName = new char[strlen(tmpFileName)+strlen(name)]; 601 sprintf(retName, "%s%s", tmpFileName, name+1); 602 } 603 else 604 { 605 retName = new char[strlen(name)+1]; 606 strcpy(retName, name); 607 } 608 return retName; 609 } 610 611 547 612 548 613 /** -
orxonox/branches/md2_loader/src/util/resource_manager.h
r3983 r4063 78 78 // utility functions of this class 79 79 static bool isDir(const char* directory); 80 static bool isFile(const char* directory); 80 static bool isFile(const char* fileName); 81 static bool touchFile(const char* fileName); 82 static bool deleteFile(const char* fileName); 83 static char* homeDirCheck(const char* name); 81 84 82 85 private:
Note: See TracChangeset
for help on using the changeset viewer.