加载下一页或者上一页。(二进制模式)
| 697 | |
| 698 | //加载下一页或者上一页。(二进制模式) |
| 699 | int FileManager::loadFilePreNextPage(int dir, QString& filePath, HexFileMgr* & hexFileOut) |
| 700 | { |
| 701 | if (m_hexFileMgr.contains(filePath)) |
| 702 | { |
| 703 | hexFileOut = m_hexFileMgr.value(filePath); |
| 704 | |
| 705 | //小于LITTLE_FILE_MAX的已经一次性全部在内存,没有上下页可以翻到 |
| 706 | if (hexFileOut->onetimeRead) |
| 707 | { |
| 708 | return 1; |
| 709 | } |
| 710 | qint64 pos = hexFileOut->fileOffset; |
| 711 | |
| 712 | if (dir == 1 && (pos >= 0)) |
| 713 | { |
| 714 | //上一页 |
| 715 | pos = pos - hexFileOut->contentRealSize - ONE_PAGE_BYTES; |
| 716 | if (pos < 0) |
| 717 | { |
| 718 | pos = 0; |
| 719 | } |
| 720 | } |
| 721 | else if(dir == 2 && (pos < hexFileOut->fileSize)) |
| 722 | { |
| 723 | |
| 724 | } |
| 725 | else |
| 726 | { |
| 727 | return 1;//没有上下页,已经是最后一页或最前一页 |
| 728 | } |
| 729 | |
| 730 | char* buf = new char[ONE_PAGE_BYTES+1]; |
| 731 | |
| 732 | hexFileOut->file->seek(pos); |
| 733 | qint64 ret = hexFileOut->file->read(buf, ONE_PAGE_BYTES); |
| 734 | if (ret <= 0) |
| 735 | { |
| 736 | return -1; |
| 737 | } |
| 738 | else |
| 739 | { |
| 740 | //读取成功 |
| 741 | hexFileOut->fileOffset = hexFileOut->file->pos(); |
| 742 | |
| 743 | if (hexFileOut->contentBuf != nullptr) |
| 744 | { |
| 745 | delete[]hexFileOut->contentBuf; |
| 746 | } |
| 747 | |
| 748 | hexFileOut->contentBuf = buf; |
| 749 | hexFileOut->contentRealSize = ret; |
| 750 | } |
| 751 | return 0; |
| 752 | } |
| 753 | return -1; |
| 754 | } |
| 755 | |
| 756 | const int ONE_PAGE_TEXT_SIZE = 1000 * 1024; |
no test coverage detected