从指定地址开始加载文件
| 878 | |
| 879 | //从指定地址开始加载文件 |
| 880 | int FileManager::loadFileFromAddr(QString filePath, qint64 addr, HexFileMgr* & hexFileOut) |
| 881 | { |
| 882 | if (m_hexFileMgr.contains(filePath)) |
| 883 | { |
| 884 | hexFileOut = m_hexFileMgr.value(filePath); |
| 885 | |
| 886 | //超过文件大小 |
| 887 | if (addr < 0 || addr >= hexFileOut->fileSize) |
| 888 | { |
| 889 | return -2; |
| 890 | } |
| 891 | |
| 892 | //4K对齐 |
| 893 | addr &= 0xfffffffffff0; |
| 894 | |
| 895 | char* buf = new char[ONE_PAGE_BYTES + 1]; |
| 896 | hexFileOut->file->seek(addr); |
| 897 | |
| 898 | qint64 ret = hexFileOut->file->read(buf, ONE_PAGE_BYTES); |
| 899 | if (ret <= 0) |
| 900 | { |
| 901 | return -1; |
| 902 | } |
| 903 | else |
| 904 | { |
| 905 | //读取成功 |
| 906 | hexFileOut->fileOffset = hexFileOut->file->pos(); |
| 907 | |
| 908 | if (hexFileOut->contentBuf != nullptr) |
| 909 | { |
| 910 | delete[]hexFileOut->contentBuf; |
| 911 | } |
| 912 | |
| 913 | hexFileOut->contentBuf = buf; |
| 914 | hexFileOut->contentRealSize = ret; |
| 915 | } |
| 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | return -1; |
| 920 | } |
| 921 | |
| 922 | //从指定地址开始加载文本文件 |
| 923 | int FileManager::loadFileFromAddr(QString filePath, qint64 addr, TextFileMgr* & textFileOut) |
no test coverage detected