MCPcopy Create free account
hub / github.com/cxasm/notepad-- / loadFileFromAddr

Method loadFileFromAddr

src/cceditor/filemanager.cpp:880–920  ·  view source on GitHub ↗

从指定地址开始加载文件

Source from the content-addressed store, hash-verified

878
879//从指定地址开始加载文件
880int 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//从指定地址开始加载文本文件
923int FileManager::loadFileFromAddr(QString filePath, qint64 addr, TextFileMgr* & textFileOut)

Callers 1

slot_hexGotoFileMethod · 0.80

Calls 6

findLineEndPosFunction · 0.85
findLineStartPosFunction · 0.85
readMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
posMethod · 0.45

Tested by

no test coverage detected