| 563 | } |
| 564 | |
| 565 | bool WINAPI SFileGetFileName(HANDLE hFile, char * szFileName) |
| 566 | { |
| 567 | TMPQFile * hf = (TMPQFile *)hFile; // MPQ File handle |
| 568 | DWORD dwErrCode = ERROR_INVALID_HANDLE; |
| 569 | |
| 570 | // Check valid parameters |
| 571 | if(IsValidFileHandle(hFile)) |
| 572 | { |
| 573 | TFileEntry * pFileEntry = hf->pFileEntry; |
| 574 | |
| 575 | // For MPQ files, retrieve the file name from the file entry |
| 576 | if(hf->pStream == NULL) |
| 577 | { |
| 578 | if(pFileEntry != NULL) |
| 579 | { |
| 580 | // If the file name is not there yet, create a pseudo name |
| 581 | if(pFileEntry->szFileName == NULL) |
| 582 | dwErrCode = CreatePseudoFileName(hFile, pFileEntry, szFileName); |
| 583 | |
| 584 | // Copy the file name to the output buffer, if any |
| 585 | if(pFileEntry->szFileName && szFileName) |
| 586 | { |
| 587 | strcpy(szFileName, pFileEntry->szFileName); |
| 588 | dwErrCode = ERROR_SUCCESS; |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | // For local files, copy the file name from the stream |
| 594 | else |
| 595 | { |
| 596 | if(szFileName != NULL) |
| 597 | { |
| 598 | const TCHAR * szStreamName = FileStream_GetFileName(hf->pStream); |
| 599 | StringCopy(szFileName, MAX_PATH, szStreamName); |
| 600 | } |
| 601 | dwErrCode = ERROR_SUCCESS; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | if(dwErrCode != ERROR_SUCCESS) |
| 606 | SetLastError(dwErrCode); |
| 607 | return (dwErrCode == ERROR_SUCCESS); |
| 608 | } |
| 609 | |