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

Method scanFileCode

src/encodeconvert.cpp:458–513  ·  view source on GitHub ↗

20220114 仅仅使用第一行失败编码还是不行,因为utf8和gbk其实有相同的编码范围。 如果识别第一行为gbk的,则直接使用gbk。但是如果识别为utf8的,则需要识别更多的文本内容,这样会更慢

Source from the content-addressed store, hash-verified

456//20220114 仅仅使用第一行失败编码还是不行,因为utf8和gbk其实有相同的编码范围。
457//如果识别第一行为gbk的,则直接使用gbk。但是如果识别为utf8的,则需要识别更多的文本内容,这样会更慢
458void EncodeConvert::scanFileCode()
459{
460 m_finishCmpFileNums = 0;
461 m_commitCmpFileNums = 0;
462
463 ui.selectFileBt->setEnabled(false);
464 ui.startBt->setEnabled(false);
465 ui.closeBt->setEnabled(false);
466
467 ui.logTextBrowser->clear();
468
469 ui.logTextBrowser->append(tr("start scan file text code, please wait..."));
470
471 for (QList<fileAttriNode>::iterator iter = m_fileAttris.begin(); iter != m_fileAttris.end(); ++iter)
472 {
473 if (iter->type == RC_DIR)
474 {
475 iter->selfItem->setText(2, QString("--"));
476 }
477 //20230304 编码转换这里,不能仅仅只识别已知后缀文件,要失败所有文件
478 else if ((iter->type == RC_FILE) && DocTypeListView::isSupportExt(fileSuffix(iter->relativePath)))
479 {
480 QFutureWatcher<EncodeThreadParameter_*>* futureWatcher = new QFutureWatcher<EncodeThreadParameter_*>();
481
482 QObject::connect(futureWatcher, &QFutureWatcher<EncodeThreadParameter_>::finished, this, &EncodeConvert::slot_scanFileCode);
483
484 futureWatcher->setFuture(this->checkFileCode(iter->relativePath,iter->selfItem));
485
486 ++m_commitCmpFileNums;
487 }
488 else
489 {
490 iter->selfItem->setText(2, tr("ignore"));
491 }
492 }
493
494 int finishProcessRatio = 0;
495
496 while (m_finishCmpFileNums < m_commitCmpFileNums)
497 {
498 int curProcessRatio = m_finishCmpFileNums * 100 / m_commitCmpFileNums;
499
500 //没%5更新一下
501 if (curProcessRatio - finishProcessRatio >= 5)
502 {
503 finishProcessRatio = curProcessRatio;
504 ui.logTextBrowser->append(tr("please wait, total file %1,cur scan index %2, scan finish %3%").arg(m_commitCmpFileNums).arg(m_finishCmpFileNums).arg(curProcessRatio));
505 }
506 QCoreApplication::processEvents();
507 }
508 ui.logTextBrowser->append(tr("scan finished, total file %1").arg(m_commitCmpFileNums));
509
510 ui.selectFileBt->setEnabled(true);
511 ui.startBt->setEnabled(true);
512 ui.closeBt->setEnabled(true);
513}
514
515//文件对比完毕,显示出文件是否意义,不一样则红色字符标识

Callers

nothing calls this directly

Calls 7

checkFileCodeMethod · 0.95
appendMethod · 0.80
setTextMethod · 0.80
fileSuffixFunction · 0.70
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected