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

Method createBlockIndex

src/cceditor/filemanager.cpp:1216–1314  ·  view source on GitHub ↗

创建大文件编辑模式的索引文件。0 成功,-1取消

Source from the content-addressed store, hash-verified

1214
1215//创建大文件编辑模式的索引文件。0 成功,-1取消
1216int FileManager::createBlockIndex(BigTextEditFileMgr* txtFile)
1217{
1218 //每次filePtr 4M的速度进行建块
1219 qint64 fileSize = txtFile->file->size();
1220
1221 qint64 curOffset = 0;
1222
1223 uchar* curPtr = txtFile->filePtr;
1224
1225 //检测是否为unicode_le编码,要特殊对待。
1226 //bool isUnLeCode = CmpareMode::isUnicodeLeBomFile(curPtr, 2);
1227
1228 CODE_ID code = CmpareMode::getTextFileEncodeType(curPtr, fileSize, txtFile->filePath, true);
1229 txtFile->loadWithCode = code;
1230
1231 const int blockBytes = BigTextEditFileMgr::BLOCK_SIZE * 1024 * 1024;
1232
1233 int lineEndPos = 0;
1234
1235 int steps = fileSize / blockBytes;
1236
1237 txtFile->blocks.reserve(steps + 10);
1238
1239 ProgressWin* loadFileProcessWin = nullptr;
1240
1241 if (steps > 200)
1242 {
1243 loadFileProcessWin = new ProgressWin(nullptr);
1244
1245 loadFileProcessWin->setWindowModality(Qt::ApplicationModal);
1246
1247 loadFileProcessWin->info(tr("load bit text file tree in progress\nfile size %1, please wait ...").arg(tranFileSize(fileSize)));
1248
1249 loadFileProcessWin->setTotalSteps(steps);
1250
1251 loadFileProcessWin->show();
1252 }
1253
1254 quint32 lineNumStart = 0;
1255 quint32 lineNum = 0;
1256
1257 while ((curOffset + blockBytes) < fileSize)
1258 {
1259 BlockIndex bi;
1260 bi.fileOffset = curOffset;
1261
1262 curOffset += blockBytes;
1263
1264 lineEndPos = findLineEndPos((char*)curPtr+ bi.fileOffset, blockBytes, code);
1265
1266 bi.fileSize = blockBytes - lineEndPos;
1267
1268 lineNum = getLineNumInBuf((char*)curPtr + bi.fileOffset, bi.fileSize, code);
1269
1270 curOffset -= lineEndPos;
1271
1272 bi.lineNum = lineNum;
1273 bi.lineNumStart = lineNumStart;

Callers

nothing calls this directly

Calls 10

tranFileSizeFunction · 0.85
findLineEndPosFunction · 0.85
getLineNumInBufFunction · 0.85
infoMethod · 0.80
setTotalStepsMethod · 0.80
appendMethod · 0.80
isCancelMethod · 0.80
moveStepMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected