Reads the file data from cache. Returns the number of bytes read
| 742 | |
| 743 | // Reads the file data from cache. Returns the number of bytes read |
| 744 | static DWORD ReadFile_Cache(TCascFile * hf, LPBYTE pbBuffer, ULONGLONG StartOffset, ULONGLONG EndOffset) |
| 745 | { |
| 746 | // Is there a file cache at all? |
| 747 | if(hf->pbFileCache != NULL && hf->FileCacheStart <= StartOffset && StartOffset < hf->FileCacheEnd) |
| 748 | { |
| 749 | LPBYTE pbStartBlock = hf->pbFileCache + (size_t)(StartOffset - hf->FileCacheStart); |
| 750 | |
| 751 | // Can we handle the entire request from the cache? |
| 752 | if(EndOffset <= hf->FileCacheEnd) |
| 753 | { |
| 754 | DWORD dwBytesToCopy = (DWORD)(EndOffset - StartOffset); |
| 755 | |
| 756 | memcpy(pbBuffer, pbStartBlock, dwBytesToCopy); |
| 757 | return dwBytesToCopy; |
| 758 | } |
| 759 | |
| 760 | // We copy as much bytes as available. The rest is handled by normal read |
| 761 | else |
| 762 | { |
| 763 | DWORD dwBytesToCopy = (DWORD)(hf->FileCacheEnd - StartOffset); |
| 764 | |
| 765 | memcpy(pbBuffer, pbStartBlock, dwBytesToCopy); |
| 766 | return dwBytesToCopy; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | // Can't handle the request from the cache |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | // No cache at all. The entire file will be read directly to the user buffer |
| 775 | static DWORD ReadFile_WholeFile(TCascFile * hf, LPBYTE pbBuffer) |