From 416cd945420969703e7805225fb090a515ab8feb Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Fri, 13 May 2022 00:16:18 +0800 Subject: [PATCH 1/5] single quotation --- .github/workflows/macos-6.2.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu-6.2.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows-6.2.yml | 2 +- .github/workflows/windows.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/macos-6.2.yml b/.github/workflows/macos-6.2.yml index 6d334deb..6950f644 100644 --- a/.github/workflows/macos-6.2.yml +++ b/.github/workflows/macos-6.2.yml @@ -88,7 +88,7 @@ jobs: CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" CHANGELOG="${CHANGELOG//'\"'/'%22'}" - CHANGELOG="${CHANGELOG//"'"/'%20'}" + CHANGELOG="${CHANGELOG//"'"/ }" echo "::set-output name=COMMIT_SUMMARY::$(echo "$CHANGELOG")" # tag 上传Release - name: uploadRelease diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 5029b8e8..3e995733 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -91,7 +91,7 @@ jobs: CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" CHANGELOG="${CHANGELOG//'\"'/'%22'}" - CHANGELOG="${CHANGELOG//"'"/'%20'}" + CHANGELOG="${CHANGELOG//"'"/ }" echo "::set-output name=COMMIT_SUMMARY::$(echo "$CHANGELOG")" # tag 上传Release - name: uploadRelease diff --git a/.github/workflows/ubuntu-6.2.yml b/.github/workflows/ubuntu-6.2.yml index a0e42420..943f4df9 100644 --- a/.github/workflows/ubuntu-6.2.yml +++ b/.github/workflows/ubuntu-6.2.yml @@ -95,7 +95,7 @@ jobs: CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" CHANGELOG="${CHANGELOG//'\"'/'%22'}" - CHANGELOG="${CHANGELOG//"'"/'%20'}" + CHANGELOG="${CHANGELOG//"'"/ }" echo "::set-output name=COMMIT_SUMMARY::$(echo "$CHANGELOG")" - name: uploadRelease # if: startsWith(github.event.ref, 'refs/tags/') diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 5f35e623..9dc1c612 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -92,7 +92,7 @@ jobs: CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" CHANGELOG="${CHANGELOG//'\"'/'%22'}" - CHANGELOG="${CHANGELOG//"'"/'%20'}" + CHANGELOG="${CHANGELOG//"'"/ }" echo "::set-output name=COMMIT_SUMMARY::$(echo "$CHANGELOG")" - name: uploadRelease # if: startsWith(github.event.ref, 'refs/tags/') diff --git a/.github/workflows/windows-6.2.yml b/.github/workflows/windows-6.2.yml index a8ef4e5b..9956c33b 100644 --- a/.github/workflows/windows-6.2.yml +++ b/.github/workflows/windows-6.2.yml @@ -67,7 +67,7 @@ jobs: CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" CHANGELOG="${CHANGELOG//'\"'/'%22'}" - CHANGELOG="${CHANGELOG//"'"/'%20'}" + CHANGELOG="${CHANGELOG//"'"/ }" echo "::set-output name=COMMIT_SUMMARY::$(echo "$CHANGELOG")" # # msvc编译 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6b362d95..7b723851 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -69,7 +69,7 @@ jobs: CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" CHANGELOG="${CHANGELOG//'\"'/'%22'}" - CHANGELOG="${CHANGELOG//"'"/'%20'}" + CHANGELOG="${CHANGELOG//"'"/ }" echo "::set-output name=COMMIT_SUMMARY::$(echo "$CHANGELOG")" - uses: ilammy/msvc-dev-cmd@v1 # msvc编译 From 609cfa74b5b0c329321fe562eb103085381dc7ea Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Fri, 13 May 2022 20:31:51 +0800 Subject: [PATCH 2/5] github: release version extracted into a variable . in the future release , prerelease and release version can share this same variable. reduce the code changes when publish a new release version. --- .github/workflows/AutoTag.yml | 6 ++++-- .github/workflows/macos-6.2.yml | 10 ++++++---- .github/workflows/macos.yml | 10 ++++++---- .github/workflows/ubuntu-6.2.yml | 10 ++++++---- .github/workflows/ubuntu-PR-check.yml | 4 +++- .github/workflows/ubuntu.yml | 10 ++++++---- .github/workflows/windows-6.2.yml | 22 ++++++++++++---------- .github/workflows/windows-PR-check.yml | 4 +++- .github/workflows/windows.yml | 22 ++++++++++++---------- 9 files changed, 58 insertions(+), 40 deletions(-) diff --git a/.github/workflows/AutoTag.yml b/.github/workflows/AutoTag.yml index f82d3c16..eb7d9863 100644 --- a/.github/workflows/AutoTag.yml +++ b/.github/workflows/AutoTag.yml @@ -22,7 +22,9 @@ jobs: runs-on: ubuntu-latest env: - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: - uses: actions/checkout@v3 @@ -37,7 +39,7 @@ jobs: uses: mathieudutour/github-tag-action@v6.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} - custom_tag: ${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + custom_tag: ${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} diff --git a/.github/workflows/macos-6.2.yml b/.github/workflows/macos-6.2.yml index 6950f644..752fd6b6 100644 --- a/.github/workflows/macos-6.2.yml +++ b/.github/workflows/macos-6.2.yml @@ -29,7 +29,9 @@ jobs: qt_arch: [clang_64] env: targetName: GoldenDict - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: # macos 11.0 默认环境变了,要指定 @@ -97,10 +99,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ env.targetName }}.dmg asset_name: ${{ matrix.qt_ver }}-${{ env.targetName }}_${{ matrix.os }}_${{ steps.vars.outputs.sha_short }}.dmg - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} body: | release on date: ${{steps.vars.outputs.release_date}} time: ${{steps.vars.outputs.release_time_clock}} branch: ${{ github.ref_name }} diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 3e995733..069efdfc 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -30,7 +30,9 @@ jobs: qt_arch: [clang_64] env: targetName: GoldenDict - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: # macos 11.0 默认环境变了,要指定 @@ -100,10 +102,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ env.targetName }}.dmg asset_name: ${{ matrix.qt_ver }}-${{ env.targetName }}_${{ matrix.os }}_${{ steps.vars.outputs.sha_short }}.dmg - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} body: | release on date: ${{steps.vars.outputs.release_date}} time: ${{steps.vars.outputs.release_time_clock}} branch: ${{ github.ref_name }} diff --git a/.github/workflows/ubuntu-6.2.yml b/.github/workflows/ubuntu-6.2.yml index 943f4df9..0bd27809 100644 --- a/.github/workflows/ubuntu-6.2.yml +++ b/.github/workflows/ubuntu-6.2.yml @@ -30,7 +30,9 @@ jobs: qt_ver: [6.2.4,6.3.0] qt_arch: [gcc_64] env: - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: - name: Install Qt uses: jurplel/install-qt-action@v3 @@ -104,10 +106,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ steps.vars.outputs.appname }} asset_name: ${{ matrix.qt_ver }}-${{ steps.vars.outputs.appname }} - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} body: | release on date: ${{steps.vars.outputs.release_date}} time: ${{steps.vars.outputs.release_time_clock}} branch: ${{ github.ref_name }} diff --git a/.github/workflows/ubuntu-PR-check.yml b/.github/workflows/ubuntu-PR-check.yml index d0ed72da..3ab651bb 100644 --- a/.github/workflows/ubuntu-PR-check.yml +++ b/.github/workflows/ubuntu-PR-check.yml @@ -24,7 +24,9 @@ jobs: qt_ver: [5.15.2,6.2.4] qt_arch: [gcc_64] env: - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: - uses: actions/setup-python@v3 with: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 9dc1c612..2b9f8144 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -30,7 +30,9 @@ jobs: qt_ver: [5.15.2] qt_arch: [gcc_64] env: - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: - name: Install Qt uses: jurplel/install-qt-action@v3 @@ -101,10 +103,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ steps.vars.outputs.appname }} asset_name: ${{ matrix.qt_ver }}-${{ steps.vars.outputs.appname }} - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} body: | release on date: ${{steps.vars.outputs.release_date}} time: ${{steps.vars.outputs.release_time_clock}} branch: ${{ github.ref_name }} diff --git a/.github/workflows/windows-6.2.yml b/.github/workflows/windows-6.2.yml index 9956c33b..78cb9ee2 100644 --- a/.github/workflows/windows-6.2.yml +++ b/.github/workflows/windows-6.2.yml @@ -31,7 +31,9 @@ jobs: qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: - uses: actions/setup-python@v3 with: @@ -111,10 +113,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ steps.package.outputs.packageName }}.zip asset_name: ${{ matrix.qt_ver }}-${{ steps.package.outputs.packageName }}.zip - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} body: | release on date: ${{steps.vars.outputs.release_date}} time: ${{steps.vars.outputs.release_time_clock}} branch: ${{ github.ref_name }} @@ -131,10 +133,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: release/${{ env.targetName }} asset_name: ${{ matrix.qt_ver }}-${{ env.targetName }} - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} - name: copy nsis shell: bash @@ -156,7 +158,7 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ steps.package.outputs.packageName }}/GoldenDict-v22-Install.exe asset_name: ${{ matrix.qt_ver }}-GoldenDict-v22-Install.exe - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true \ No newline at end of file + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} \ No newline at end of file diff --git a/.github/workflows/windows-PR-check.yml b/.github/workflows/windows-PR-check.yml index 264ee662..ff2258cd 100644 --- a/.github/workflows/windows-PR-check.yml +++ b/.github/workflows/windows-PR-check.yml @@ -27,7 +27,9 @@ jobs: env: targetName: GoldenDict.exe - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true steps: - uses: actions/setup-python@v3 with: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7b723851..6a09f258 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -32,7 +32,9 @@ jobs: qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe - version: 22.4.24-alpha + version: 22.4.24 + version-suffix: alpha + prerelease: true # 步骤 steps: # 安装Qt @@ -106,10 +108,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ steps.package.outputs.packageName }}.zip asset_name: ${{ matrix.qt_ver }}-${{ steps.package.outputs.packageName }}.zip - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} body: | release on date: ${{steps.vars.outputs.release_date}} time: ${{steps.vars.outputs.release_time_clock}} branch: ${{ github.ref_name }} @@ -131,10 +133,10 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: release/${{ env.targetName }} asset_name: ${{ matrix.qt_ver }}-${{ env.targetName }} - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} - name: copy nsis @@ -159,8 +161,8 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ steps.package.outputs.packageName }}/GoldenDict-v22-Install.exe asset_name: ${{ matrix.qt_ver }}-GoldenDict-v22-Install.exe - tag: v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + tag: v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} overwrite: true - release_name: GoldenDict-v${{env.version}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} - prerelease: true + release_name: GoldenDict-v${{env.version}}-${{env.version-suffix}}.${{ steps.vars.outputs.release_hm }}.${{ steps.vars.outputs.sha_short }} + prerelease: ${{env.prerelease}} \ No newline at end of file From dab5885b02a167db38641bc08644bd87dd18d39b Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 15 May 2022 12:41:24 +0800 Subject: [PATCH 3/5] opt: debug log message convert GDPRINTF macro to gdDebug internal --- gddebug.cc | 24 ++++++++++++------------ gddebug.hh | 2 +- mdictparser.cc | 2 +- mdx.cc | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gddebug.cc b/gddebug.cc index 157ff5c4..a295c93b 100644 --- a/gddebug.cc +++ b/gddebug.cc @@ -42,23 +42,23 @@ void gdDebug(const char *msg, ...) { va_list ap; va_start(ap, msg); -QTextCodec *localeCodec = 0; +// QTextCodec *localeCodec = 0; - if( logFilePtr && logFilePtr->isOpen() ) - { - if( utf8Codec == 0 ) - utf8Codec = QTextCodec::codecForName( "UTF8" ); + // if( logFilePtr && logFilePtr->isOpen() ) + // { + // if( utf8Codec == 0 ) + // utf8Codec = QTextCodec::codecForName( "UTF8" ); - localeCodec = QTextCodec::codecForLocale(); - QTextCodec::setCodecForLocale( utf8Codec ); - } + // localeCodec = QTextCodec::codecForLocale(); + // QTextCodec::setCodecForLocale( utf8Codec ); + // } qDebug()<< QString().vasprintf( msg, ap ); - if( logFilePtr && logFilePtr->isOpen() ) - { - QTextCodec::setCodecForLocale( localeCodec ); - } + // if( logFilePtr && logFilePtr->isOpen() ) + // { + // QTextCodec::setCodecForLocale( localeCodec ); + // } va_end(ap); } diff --git a/gddebug.hh b/gddebug.hh index e8148e0d..5e1dfe26 100644 --- a/gddebug.hh +++ b/gddebug.hh @@ -7,7 +7,7 @@ #define GD_DPRINTF(...) do {} while( 0 ) #define GD_FDPRINTF(...) do {} while( 0 ) #else -#define GD_DPRINTF(...) printf(__VA_ARGS__) +#define GD_DPRINTF(...) gdDebug(__VA_ARGS__) #define GD_FDPRINTF(...) fprintf(__VA_ARGS__) #endif diff --git a/mdictparser.cc b/mdictparser.cc index d2366f7a..f3124a46 100644 --- a/mdictparser.cc +++ b/mdictparser.cc @@ -120,7 +120,7 @@ bool MdictParser::open( const char * filename ) filename_ = QString::fromUtf8( filename ); file_ = new QFile( filename_ ); - GD_DPRINTF( "MdictParser: open %s\n", filename ); + gdDebug( "MdictParser: open %s", filename ); if ( file_.isNull() || !file_->exists() ) return false; diff --git a/mdx.cc b/mdx.cc index 69271c86..b19558f5 100644 --- a/mdx.cc +++ b/mdx.cc @@ -523,7 +523,7 @@ void MdxDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration if( firstIteration && getArticleCount() > FTS::MaxDictionarySizeForFastSearch ) return; - gdDebug( "MDict: Building the full-text index for dictionary: %s\n", + gdDebug( "MDict: Building the full-text index for dictionary: %s", getName().c_str() ); try @@ -533,7 +533,7 @@ void MdxDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration } catch( std::exception &ex ) { - gdWarning( "MDict: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() ); + gdWarning( "MDict: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); QFile::remove( FsEncoding::decode( ftsIdxName.c_str() ) ); } } @@ -550,7 +550,7 @@ void MdxDictionary::getArticleText( uint32_t articleAddress, QString & headword, } catch( std::exception &ex ) { - gdWarning( "MDict: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() ); + gdWarning( "MDict: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); } } From eda434f38e3cb7d8b6a61c66cb99353308912009 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sat, 14 May 2022 17:22:34 +0800 Subject: [PATCH 4/5] opt: rename emitDicts signal to dictionaryChanges --- article_maker.cc | 6 +++--- articleview.cc | 2 +- globalbroadcaster.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/article_maker.cc b/article_maker.cc index e18b63fb..5df14417 100644 --- a/article_maker.cc +++ b/article_maker.cc @@ -733,19 +733,19 @@ void ArticleRequest::bodyFinished() { update(); qDebug() << "send dicts(stemmed):" << word << ":" << dictIds; - emit GlobalBroadcaster::instance()->emitDictIds(ActiveDictIds{word, dictIds}); + emit GlobalBroadcaster::instance()->dictionaryChanges(ActiveDictIds{word, dictIds}); dictIds.clear(); } else { finish(); qDebug() << "send dicts(finished):" << word << ":" << dictIds; - emit GlobalBroadcaster::instance()->emitDictIds(ActiveDictIds{word, dictIds}); + emit GlobalBroadcaster::instance()->dictionaryChanges(ActiveDictIds{word, dictIds}); dictIds.clear(); } } else if (wasUpdated) { update(); qDebug() << "send dicts(updated):" << word << ":" << dictIds; - emit GlobalBroadcaster::instance()->emitDictIds(ActiveDictIds{word, dictIds}); + emit GlobalBroadcaster::instance()->dictionaryChanges(ActiveDictIds{word, dictIds}); dictIds.clear(); } } diff --git a/articleview.cc b/articleview.cc index 3c14acc1..f366129d 100644 --- a/articleview.cc +++ b/articleview.cc @@ -347,7 +347,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, Au // Variable name for store current selection range rangeVarName = QString( "sr_%1" ).arg( QString::number( (quint64)this, 16 ) ); - connect(GlobalBroadcaster::instance(), SIGNAL( emitDictIds(ActiveDictIds)), this, + connect(GlobalBroadcaster::instance(), SIGNAL( dictionaryChanges(ActiveDictIds)), this, SLOT(setActiveDictIds(ActiveDictIds))); channel = new QWebChannel(ui.definition->page()); diff --git a/globalbroadcaster.h b/globalbroadcaster.h index 7298e3a6..f2597c29 100644 --- a/globalbroadcaster.h +++ b/globalbroadcaster.h @@ -22,7 +22,7 @@ public: GlobalBroadcaster( QObject * parent = nullptr ); static GlobalBroadcaster * instance(); signals: - void emitDictIds( ActiveDictIds ad ); + void dictionaryChanges( ActiveDictIds ad ); }; #endif // GLOBAL_GLOBALBROADCASTER_H From e6ab87ca73bce197522da009045c36525205b93a Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sat, 14 May 2022 00:00:23 +0800 Subject: [PATCH 5/5] fix:add ifr local scheme due to iframe security policy and x-frame-option . the website online dictionary can not work in qt 5.15.2+ version. this is a workaround to pass through the restriction. --- article_netmgr.cc | 69 ++++++++++++----------- article_netmgr.hh | 3 +- globalbroadcaster.cpp | 7 +++ globalbroadcaster.h | 5 +- goldendict.pro | 2 + iframeschemehandler.cpp | 104 +++++++++++++++++++++++++++++++++++ iframeschemehandler.h | 19 +++++++ main.cc | 2 +- mainwindow.cc | 19 ++++--- mainwindow.hh | 6 +- website.cc | 7 ++- weburlrequestinterceptor.cpp | 9 +++ 12 files changed, 204 insertions(+), 48 deletions(-) create mode 100644 iframeschemehandler.cpp create mode 100644 iframeschemehandler.h diff --git a/article_netmgr.cc b/article_netmgr.cc index b39a3eeb..9a3edc6b 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -29,7 +29,7 @@ using std::string; connect( baseReply, SIGNAL( errorOccurred( QNetworkReply::NetworkError) ), this, SLOT( applyError( QNetworkReply::NetworkError ) ) ); - connect( baseReply, SIGNAL( readyRead() ), this, SLOT( readDataFromBase() ) ); + connect( baseReply, SIGNAL( readyRead() ), this, SIGNAL( readyRead() ) ); // Redirect QNetworkReply signals @@ -68,7 +68,8 @@ using std::string; QList< QByteArray > rawHeaders = baseReply->rawHeaderList(); for( QList< QByteArray >::iterator it = rawHeaders.begin(); it != rawHeaders.end(); ++it ) { - if( it->toLower() != "x-frame-options" ) + auto headerName = it->toLower(); + if( headerName != "x-frame-options" && headerName != "content-security-policy") setRawHeader( *it, baseReply->rawHeader( *it ) ); } @@ -121,7 +122,7 @@ using std::string; qint64 AllowFrameReply::bytesAvailable() const { - return buffer.size() + QNetworkReply::bytesAvailable(); + return baseReply->bytesAvailable(); } void AllowFrameReply::applyError( QNetworkReply::NetworkError code ) @@ -130,20 +131,22 @@ using std::string; emit errorOccurred( code ); } - void AllowFrameReply::readDataFromBase() - { - QByteArray data; - data.resize( baseReply->bytesAvailable() ); - baseReply->read( data.data(), data.size() ); - buffer += data; - emit readyRead(); - } +// void AllowFrameReply::readDataFromBase() +// { +//// QByteArray data; +//// data.resize( baseReply->bytesAvailable() ); +//// baseReply->read( data.data(), data.size() ); +//// buffer += data; +// emit readyRead(); +// } qint64 AllowFrameReply::readData( char * data, qint64 maxSize ) { - qint64 size = qMin( maxSize, qint64( buffer.size() ) ); - memcpy( data, buffer.data(), size ); - buffer.remove( 0, size ); + auto bytesAvailable= baseReply->bytesAvailable(); + qint64 size = qMin( maxSize, bytesAvailable ); + baseReply->read( data, size ); +// memcpy( data, buffer.data(), size ); +// buffer.remove( 0, size ); return size; } @@ -151,6 +154,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, QNetworkRequest const & req, QIODevice * outgoingData ) { + QUrl url; if ( op == GetOperation ) { if ( req.url().scheme() == "qrcx" ) @@ -168,7 +172,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, return QNetworkAccessManager::createRequest( op, newReq, outgoingData ); } - QUrl url=req.url(); + url=req.url(); QMimeType mineType=db.mimeTypeForUrl (url); QString contentType=mineType.name(); @@ -178,7 +182,6 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, Utils::Url::addQueryItem(url,"word",path.mid(1)); url.setPath(""); Utils::Url::addQueryItem(url,"group","1"); - } } @@ -193,7 +196,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, //can not match dictionary in the above code,means the url must be external links. //if not external url,can be blocked from here. no need to continue execute the following code. //such as bres://upload.wikimedia.... etc . - if (!Utils::isExternalLink(req.url())) { + if (!Utils::isExternalLink(url)) { gdWarning( "Blocking element \"%s\" as built-in link ", req.url().toEncoded().data() ); return new BlockedNetworkReply( this ); } @@ -205,17 +208,15 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, { QByteArray referer = req.rawHeader( "Referer" ); - //GD_DPRINTF( "Referer: %s\n", referer.data() ); - QUrl refererUrl = QUrl::fromEncoded( referer ); //GD_DPRINTF( "Considering %s vs %s\n", getHostBase( req.url() ).toUtf8().data(), // getHostBase( refererUrl ).toUtf8().data() ); - if ( !req.url().host().endsWith( refererUrl.host() ) && - getHostBase( req.url() ) != getHostBase( refererUrl ) && !req.url().scheme().startsWith("data") ) + if ( !url.host().endsWith( refererUrl.host() ) && + getHostBase( url ) != getHostBase( refererUrl ) && !url.scheme().startsWith("data") ) { - gdWarning( "Blocking element \"%s\" due to not same domain", req.url().toEncoded().data() ); + gdWarning( "Blocking element \"%s\" due to not same domain", url.toEncoded().data() ); return new BlockedNetworkReply( this ); } @@ -241,15 +242,17 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op, } // spoof User-Agent - QNetworkRequest newReq(req); - if ( hideGoldenDictHeader && req.url().scheme().startsWith("http", Qt::CaseInsensitive)) + QNetworkRequest newReq; + newReq.setUrl(url); + newReq.setAttribute( QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy ); + if ( hideGoldenDictHeader && url.scheme().startsWith("http", Qt::CaseInsensitive)) { newReq.setRawHeader("User-Agent", req.rawHeader("User-Agent").replace(qApp->applicationName().toUtf8(), "")); } QNetworkReply * reply = QNetworkAccessManager::createRequest( op, newReq, outgoingData ); - if( req.url().scheme() == "https") + if( url.scheme() == "https") { #ifndef QT_NO_OPENSSL connect( reply, SIGNAL( sslErrors( QList< QSslError > ) ), @@ -521,15 +524,11 @@ LocalSchemeHandler::LocalSchemeHandler(ArticleNetworkAccessManager& articleNetMg void LocalSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) { - QUrl url = requestJob->requestUrl(); + QUrl url = requestJob->requestUrl(); + QNetworkRequest request; + request.setUrl( url ); - QNetworkRequest request; - request.setUrl( url ); - - QNetworkReply* reply=this->mManager.createRequest(QNetworkAccessManager::GetOperation,request); - connect(reply,&QNetworkReply::finished,requestJob,[=](){ - requestJob->reply("text/html",reply); - }); - connect(requestJob, &QObject::destroyed, reply, &QObject::deleteLater); + QNetworkReply * reply = this->mManager.createRequest( QNetworkAccessManager::GetOperation, request ); + connect( reply, &QNetworkReply::finished, requestJob, [ = ]() { requestJob->reply( "text/html", reply ); } ); + connect( requestJob, &QObject::destroyed, reply, &QObject::deleteLater ); } - diff --git a/article_netmgr.hh b/article_netmgr.hh index 4400df99..2e881b28 100644 --- a/article_netmgr.hh +++ b/article_netmgr.hh @@ -66,7 +66,7 @@ public slots: // Own AllowFrameReply slots void applyMetaData(); void applyError( QNetworkReply::NetworkError code ); - void readDataFromBase(); +// void readDataFromBase(); // Redirect QNetworkReply slots virtual void abort() @@ -214,5 +214,6 @@ protected: private: ArticleNetworkAccessManager& mManager; + QNetworkAccessManager mgr; }; #endif diff --git a/globalbroadcaster.cpp b/globalbroadcaster.cpp index 9d58a2df..761e2682 100644 --- a/globalbroadcaster.cpp +++ b/globalbroadcaster.cpp @@ -19,4 +19,11 @@ Config::Preferences * GlobalBroadcaster::getPreference() return preference; } +void GlobalBroadcaster::addWhitelist(QString url){ + whitelist.push_back(url); +} + +bool GlobalBroadcaster::existedInWhitelist(QString url){ + return std::find(whitelist.begin(), whitelist.end(), url) != whitelist.end(); +} // namespace global diff --git a/globalbroadcaster.h b/globalbroadcaster.h index f2597c29..3014a46e 100644 --- a/globalbroadcaster.h +++ b/globalbroadcaster.h @@ -2,6 +2,7 @@ #define GLOBAL_GLOBALBROADCASTER_H #include +#include #include "config.hh" struct ActiveDictIds @@ -15,11 +16,13 @@ class GlobalBroadcaster : public QObject Q_OBJECT private: Config::Preferences * preference; - + std::vector whitelist; public: void setPreference( Config::Preferences * _pre ); Config::Preferences * getPreference(); GlobalBroadcaster( QObject * parent = nullptr ); + void addWhitelist(QString host); + bool existedInWhitelist(QString host); static GlobalBroadcaster * instance(); signals: void dictionaryChanges( ActiveDictIds ad ); diff --git a/goldendict.pro b/goldendict.pro index 8c119681..02d69efe 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -226,6 +226,7 @@ DEFINES += PROGRAM_VERSION=\\\"$$VERSION\\\" HEADERS += folding.hh \ article_inspect.h \ globalbroadcaster.h \ + iframeschemehandler.h \ inc_case_folding.hh \ inc_diacritic_folding.hh \ mainwindow.hh \ @@ -366,6 +367,7 @@ FORMS += groups.ui \ SOURCES += folding.cc \ article_inspect.cpp \ globalbroadcaster.cpp \ + iframeschemehandler.cpp \ main.cc \ dictionary.cc \ config.cc \ diff --git a/iframeschemehandler.cpp b/iframeschemehandler.cpp new file mode 100644 index 00000000..cc1d6d5e --- /dev/null +++ b/iframeschemehandler.cpp @@ -0,0 +1,104 @@ +#include "iframeschemehandler.h" + +#include + +IframeSchemeHandler::IframeSchemeHandler(QObject * parent):QWebEngineUrlSchemeHandler(parent){ + +} +void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) +{ + QUrl url = requestJob->requestUrl(); + + // website dictionary iframe url + url = QUrl( Utils::Url::queryItemValue( url, "url" ) ); + QNetworkRequest request; + request.setUrl( url ); + + QNetworkReply * reply = mgr.get( request ); + auto finishAction = [ = ]() -> void + { + // Handle reply data + + QByteArray replyData = reply->readAll(); + QString articleString; + + QTextCodec * codec = QTextCodec::codecForHtml( replyData ); + if( codec ) + articleString = codec->toUnicode( replyData ); + else + articleString = QString::fromUtf8( replyData ); + + // Change links from relative to absolute + + QString root = reply->url().scheme() + "://" + reply->url().host(); + QString base = root + reply->url().path(); + while( !base.isEmpty() && !base.endsWith( "/" ) ) + base.chop( 1 ); + + QRegularExpression tags( "<\\s*(a|link|img|script)\\s+[^>]*(src|href)\\s*=\\s*['\"][^>]+>", + QRegularExpression::CaseInsensitiveOption ); + QRegularExpression links( "\\b(src|href)\\s*=\\s*(['\"])([^'\"]+['\"])", + QRegularExpression::CaseInsensitiveOption ); + int pos = 0; + QString articleNewString; + QRegularExpressionMatchIterator it = tags.globalMatch( articleString ); + while( it.hasNext() ) + { + QRegularExpressionMatch match = it.next(); + articleNewString += articleString.mid( pos, match.capturedStart() - pos ); + pos = match.capturedEnd(); + + QString tag = match.captured(); + + QRegularExpressionMatch match_links = links.match( tag ); + if( !match_links.hasMatch() ) + { + articleNewString += tag; + continue; + } + + QString url = match_links.captured( 3 ); + + if( url.indexOf( ":/" ) >= 0 || url.indexOf( "data:" ) >= 0 || url.indexOf( "mailto:" ) >= 0 || + url.startsWith( "#" ) || url.startsWith( "javascript:" ) ) + { + // External link, anchor or base64-encoded data + articleNewString += tag; + continue; + } + + QString newUrl = match_links.captured( 1 ) + "=" + match_links.captured( 2 ); + if( url.startsWith( "//" ) ) + newUrl += reply->url().scheme() + ":"; + else if( url.startsWith( "/" ) ) + newUrl += root; + else + newUrl += base; + newUrl += match_links.captured( 3 ); + + tag.replace( match_links.capturedStart(), match_links.capturedLength(), newUrl ); + articleNewString += tag; + } + if( pos ) + { + articleNewString += articleString.mid( pos ); + articleString = articleNewString; + articleNewString.clear(); + } + + sptr< Dictionary::DataRequestInstant > response = new Dictionary::DataRequestInstant( true ); + + auto content = articleString.toStdString(); + response->getData().resize( content.size() ); + memcpy( &( response->getData().front() ), content.data(), content.size() ); + + auto contentType="text/html"; + auto newReply = new ArticleResourceReply( this, request, response, contentType ); + + requestJob->reply( contentType, newReply ); + connect( requestJob, &QObject::destroyed, newReply, &QObject::deleteLater ); + }; + connect( reply, &QNetworkReply::finished, requestJob, finishAction ); + + connect( requestJob, &QObject::destroyed, reply, &QObject::deleteLater ); +} diff --git a/iframeschemehandler.h b/iframeschemehandler.h new file mode 100644 index 00000000..2b8005a8 --- /dev/null +++ b/iframeschemehandler.h @@ -0,0 +1,19 @@ +#ifndef IFRAMESCHEMEHANDLER_H +#define IFRAMESCHEMEHANDLER_H + +#include"article_netmgr.hh" + +class IframeSchemeHandler : public QWebEngineUrlSchemeHandler +{ + Q_OBJECT +public: + IframeSchemeHandler(QObject * parent=nullptr); + void requestStarted(QWebEngineUrlRequestJob *requestJob); + +protected: + +private: + QNetworkAccessManager mgr; +}; + +#endif // IFRAMESCHEMEHANDLER_H diff --git a/main.cc b/main.cc index 316ed352..958e2b5d 100644 --- a/main.cc +++ b/main.cc @@ -253,7 +253,7 @@ int main( int argc, char ** argv ) #endif - QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres","bword","gdprg","gdvideo","gdpicture","gdtts"}; + QStringList localSchemes={"gdlookup","gdau","gico","qrcx","bres","bword","gdprg","gdvideo","gdpicture","gdtts","ifr"}; for (int i = 0; i < localSchemes.size(); ++i) { diff --git a/mainwindow.cc b/mainwindow.cc index c4716e54..cb9e3410 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -145,14 +145,19 @@ MainWindow::MainWindow( Config::Class & cfg_ ): GlobalBroadcaster::instance()->setPreference(&cfg.preferences); - localSchemeHandler = new LocalSchemeHandler(articleNetMgr); - QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", localSchemeHandler); - QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("bword", localSchemeHandler); + localSchemeHandler = new LocalSchemeHandler( articleNetMgr ); + QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "gdlookup", localSchemeHandler ); + QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "bword", localSchemeHandler ); - QStringList localSchemes={"gdau","gico","qrcx","bres","gdprg","gdvideo","gdpicture","gdtts"}; - resourceSchemeHandler = new ResourceSchemeHandler(articleNetMgr); - for(int i=0;iinstallUrlSchemeHandler(localSchemes.at(i).toLatin1(), resourceSchemeHandler); + iframeSchemeHandler = new IframeSchemeHandler( this ); + QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "ifr", iframeSchemeHandler ); + + QStringList localSchemes = { "gdau", "gico", "qrcx", "bres", "gdprg", "gdvideo", "gdpicture", "gdtts" }; + resourceSchemeHandler = new ResourceSchemeHandler( articleNetMgr ); + for( int i = 0; i < localSchemes.size(); i++ ) + { + QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( localSchemes.at( i ).toLatin1(), + resourceSchemeHandler ); } wuri = new WebUrlRequestInterceptor(); diff --git a/mainwindow.hh b/mainwindow.hh index 3867c1b0..05a30436 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -34,6 +34,7 @@ #include "hotkeywrapper.hh" #include "weburlrequestinterceptor.h" #include "resourceschemehandler.h" +#include "iframeschemehandler.h" #ifdef HAVE_X11 #include #endif @@ -176,8 +177,9 @@ private: QIcon starIcon, blueStarIcon; - LocalSchemeHandler *localSchemeHandler; - ResourceSchemeHandler *resourceSchemeHandler; + LocalSchemeHandler * localSchemeHandler; + IframeSchemeHandler * iframeSchemeHandler; + ResourceSchemeHandler * resourceSchemeHandler; /// Applies the qt's stylesheet, given the style's name. void applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle ); diff --git a/website.cc b/website.cc index d7048cc0..6534626e 100644 --- a/website.cc +++ b/website.cc @@ -9,6 +9,7 @@ #include #include #include "gddebug.hh" +#include "globalbroadcaster.h" #include @@ -371,8 +372,12 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, string result = "
"; + //permissive add url to global whitelist. + QUrl url(urlString); + GlobalBroadcaster::instance()->addWhitelist(url.host()); + result += string( "