| 814 | } |
| 815 | |
| 816 | DWORD WINAPI SFileSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * plFilePosHigh, DWORD dwMoveMethod) |
| 817 | { |
| 818 | TMPQFile * hf = (TMPQFile *)hFile; |
| 819 | ULONGLONG OldPosition; |
| 820 | ULONGLONG NewPosition; |
| 821 | ULONGLONG FileSize; |
| 822 | ULONGLONG DeltaPos; |
| 823 | |
| 824 | // If the hFile is not a valid file handle, return an error. |
| 825 | if(!IsValidFileHandle(hFile)) |
| 826 | { |
| 827 | SetLastError(ERROR_INVALID_HANDLE); |
| 828 | return SFILE_INVALID_POS; |
| 829 | } |
| 830 | |
| 831 | // Retrieve the file size for handling the limits |
| 832 | if(hf->pStream != NULL) |
| 833 | { |
| 834 | FileStream_GetSize(hf->pStream, &FileSize); |
| 835 | } |
| 836 | else |
| 837 | { |
| 838 | FileSize = SFileGetFileSize(hFile, NULL); |
| 839 | } |
| 840 | |
| 841 | // Handle the NULL and non-NULL values of plFilePosHigh |
| 842 | // Non-NULL: The DeltaPos is combined from lFilePos and *lpFilePosHigh |
| 843 | // NULL: The DeltaPos is sign-extended value of lFilePos |
| 844 | DeltaPos = (plFilePosHigh != NULL) ? MAKE_OFFSET64(plFilePosHigh[0], lFilePos) : (ULONGLONG)(LONGLONG)lFilePos; |
| 845 | |
| 846 | // Get the relative point where to move from |
| 847 | switch(dwMoveMethod) |
| 848 | { |
| 849 | case FILE_BEGIN: |
| 850 | |
| 851 | // Move relative to the file begin. |
| 852 | OldPosition = 0; |
| 853 | break; |
| 854 | |
| 855 | case FILE_CURRENT: |
| 856 | |
| 857 | // Retrieve the current file position |
| 858 | if(hf->pStream != NULL) |
| 859 | { |
| 860 | FileStream_GetPos(hf->pStream, &OldPosition); |
| 861 | } |
| 862 | else |
| 863 | { |
| 864 | OldPosition = hf->dwFilePos; |
| 865 | } |
| 866 | break; |
| 867 | |
| 868 | case FILE_END: |
| 869 | |
| 870 | // Move relative to the end of the file |
| 871 | OldPosition = FileSize; |
| 872 | break; |
| 873 | |