From c0b0897d906c2e1ffc91b5f2684cbdec35ec3b8f Mon Sep 17 00:00:00 2001 From: YeMuXingKong <3476758756@qq.com> Date: Thu, 12 Nov 2026 01:54:56 +0800 Subject: [PATCH 01/18] Inspect extracted LibreOffice dependencies for an offline conversion bundle --- .github/workflows/conversion-bundle.yml | 22 ++++++++++++++ scripts/inspect-conversion-bundle.ps1 | 39 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/conversion-bundle.yml create mode 100644 scripts/inspect-conversion-bundle.ps1 diff --git a/.github/workflows/conversion-bundle.yml b/.github/workflows/conversion-bundle.yml new file mode 100644 index 0000000..f87c2ac --- /dev/null +++ b/.github/workflows/conversion-bundle.yml @@ -0,0 +1,22 @@ +name: Inspect conversion bundle +on: + push: + branches: [codex/bundle-offline-conversion] +permissions: + contents: read +jobs: + inspect: + runs-on: windows-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - shell: pwsh + run: ./scripts/inspect-conversion-bundle.ps1 + - uses: actions/upload-artifact@v7 + if: always() + with: + name: conversion-bundle-inspection + path: .local/conversion-bundle-inspection/** + retention-days: 7 diff --git a/scripts/inspect-conversion-bundle.ps1 b/scripts/inspect-conversion-bundle.ps1 new file mode 100644 index 0000000..5475bb2 --- /dev/null +++ b/scripts/inspect-conversion-bundle.ps1 @@ -0,0 +1,39 @@ +$ErrorActionPreference = 'Stop' +if ($env:CI -ne 'true' -or -not $IsWindows) { throw 'Disposable Windows CI only.' } +$root = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) +$evidence = Join-Path $root '.local/conversion-bundle-inspection' +New-Item -ItemType Directory -Path $evidence -Force | Out-Null +$version = '26.2.6' +$url = "https://download.documentfoundation.org/libreoffice/stable/$version/win/x86_64/LibreOffice_${version}_Win_x86-64.msi" +[xml]$meta = (Invoke-WebRequest ($url + '.meta4') -TimeoutSec 60).Content +$hash = @($meta.metalink.file.hash | Where-Object type -eq 'sha-256')[0].InnerText.ToLowerInvariant() +if ($hash -notmatch '^[a-f0-9]{64}$') { throw 'Missing official SHA-256.' } +Write-Host "Official LibreOffice MSI SHA-256: $hash" +$msi = Join-Path $env:RUNNER_TEMP 'DailyToolkit-LibreOffice.msi' +$downloaded = $false +foreach ($mirror in @($meta.metalink.file.url | Where-Object { $_.InnerText.StartsWith('https://') } | Sort-Object { [int]$_.priority } | Select-Object -First 4)) { + & curl.exe --fail --silent --show-error --location --connect-timeout 15 --max-time 90 --output $msi $mirror.InnerText + if ($LASTEXITCODE -eq 0 -and (Get-FileHash $msi).Hash.ToLowerInvariant() -eq $hash) { $downloaded = $true; break } +} +if (-not $downloaded) { throw 'Official download failed.' } +$extract = Join-Path $env:RUNNER_TEMP 'DailyToolkit-LibreOffice-admin' +$log = Join-Path $evidence 'extract.log' +$p = Start-Process msiexec.exe -ArgumentList @('/a', ('"' + $msi + '"'), '/qn', '/norestart', ('TARGETDIR="' + $extract + '"'), '/L*v', ('"' + $log + '"')) -PassThru +if (-not $p.WaitForExit(240000)) { throw 'Administrative extraction timed out.' } +if ($p.ExitCode -notin @(0,3010)) { throw "Administrative extraction failed: $($p.ExitCode)" } +$office = @(Get-ChildItem $extract -Recurse -File -Filter soffice.com) +if ($office.Count -ne 1) { throw 'Expected one extracted LibreOffice console entry.' } +$install = $office[0].Directory.Parent.FullName +$files = @(Get-ChildItem $install -Recurse -File | ForEach-Object { + @{ path = [IO.Path]::GetRelativePath($install,$_.FullName).Replace('\','/'); bytes = $_.Length } +}) +@{ version=$version; sha256=$hash; files=$files } | ConvertTo-Json -Depth 5 | Set-Content (Join-Path $evidence 'files.json') +$files | Group-Object { ($_.path -split '/')[0..([Math]::Min(1,($_.path -split '/').Length-1))] -join '/' } | ForEach-Object { + [pscustomobject]@{ directory=$_.Name; files=$_.Count; bytes=($_.Group | Measure-Object bytes -Sum).Sum } +} | Sort-Object bytes -Descending | Select-Object -First 60 | Format-Table -AutoSize | Out-String -Width 180 | Write-Host +Write-Host 'PROGRAM FILES' +$files | Where-Object path -Like 'program/*' | ForEach-Object { Write-Host "$($_.path) $($_.bytes)" } +Write-Host 'ROOT FILES' +$files | Where-Object { $_.path -notlike '*/*' } | ForEach-Object { Write-Host "$($_.path) $($_.bytes)" } +& $office[0].FullName --version +if ($LASTEXITCODE -ne 0) { throw 'Extracted LibreOffice could not start.' } From 8de157f162765f5b922d1341bcb82a5fde877a88 Mon Sep 17 00:00:00 2001 From: YeMuXingKong <3476758756@qq.com> Date: Thu, 12 Nov 2026 02:02:26 +0800 Subject: [PATCH 02/18] Cross-build a minimal offline FFmpeg with pinned source and codecs --- .github/workflows/conversion-bundle.yml | 26 +++++ scripts/build-conversion-ffmpeg.sh | 142 ++++++++++++++++++++++++ scripts/conversion-sources.json | 65 +++++++++++ 3 files changed, 233 insertions(+) create mode 100644 scripts/build-conversion-ffmpeg.sh create mode 100644 scripts/conversion-sources.json diff --git a/.github/workflows/conversion-bundle.yml b/.github/workflows/conversion-bundle.yml index f87c2ac..9732c8c 100644 --- a/.github/workflows/conversion-bundle.yml +++ b/.github/workflows/conversion-bundle.yml @@ -5,6 +5,32 @@ on: permissions: contents: read jobs: + ffmpeg: + runs-on: ubuntu-latest + timeout-minutes: 35 + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Prepare cross compiler + run: | + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix nasm cmake ninja-build meson pkg-config make + - name: Build only the conversion engine + run: bash scripts/build-conversion-ffmpeg.sh + - uses: actions/upload-artifact@v7 + with: + name: conversion-ffmpeg-win-x64 + path: .local/conversion-tools/tools/ffmpeg/** + retention-days: 14 + - uses: actions/upload-artifact@v7 + if: failure() + with: + name: conversion-ffmpeg-build-logs + path: | + .local/conversion-ffmpeg/**/*.log + .local/conversion-ffmpeg/**/config.log + retention-days: 7 inspect: runs-on: windows-latest timeout-minutes: 15 diff --git a/scripts/build-conversion-ffmpeg.sh b/scripts/build-conversion-ffmpeg.sh new file mode 100644 index 0000000..884f8f3 --- /dev/null +++ b/scripts/build-conversion-ffmpeg.sh @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +# Cross-build the local converter, never a player, downloader or system install. +set -euo pipefail +root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) +work="$root/.local/conversion-ffmpeg" +mkdir -p "$work" +build=$(mktemp -d "$work/build-XXXXXX") +prefix="$build/prefix" +out="$build/output" +mkdir -p "$prefix" "$out/licenses" "$out/sources" +jobs=${CONVERSION_BUILD_JOBS:-2} +export CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ +export AR=x86_64-w64-mingw32-ar RANLIB=x86_64-w64-mingw32-ranlib STRIP=x86_64-w64-mingw32-strip +export PKG_CONFIG_LIBDIR="$prefix/lib/pkgconfig" PKG_CONFIG_PATH="$prefix/lib/pkgconfig" +export CFLAGS='-O2' CXXFLAGS='-O2' + +python3 - "$root/scripts/conversion-sources.json" "$build" <<'PY' +import hashlib,json,pathlib,subprocess,sys,tarfile +spec=pathlib.Path(sys.argv[1]); root=pathlib.Path(sys.argv[2]) +for item in json.loads(spec.read_text()): + name=item['name']; archive=root/'output'/'sources'/(name+'.tar.gz') + subprocess.run(['curl','--fail','--silent','--show-error','--location','--connect-timeout','20','--max-time','180','--output',str(archive),item['url']],check=True) + if hashlib.sha256(archive.read_bytes()).hexdigest()!=item['sha256']: raise RuntimeError('Source checksum mismatch: '+name) + target=root/name; target.mkdir() + subprocess.run(['tar','-xzf',str(archive),'--strip-components=1','-C',str(target)],check=True) + notices=[p for p in target.iterdir() if p.is_file() and (p.name.upper().startswith(('COPYING','LICENSE','PATENT','NOTICE','AUTHORS')))] + destination=root/'output'/'licenses'/name; destination.mkdir() + for p in notices: (destination/p.name).write_bytes(p.read_bytes()) + if not notices: raise RuntimeError('No source license: '+name) +PY +cat > "$build/windows.cmake" < "$build/windows.meson" <"$build/$label.log" 2>&1; then tail -n 100 "$build/$label.log"; return 1; fi +} +cmake_lib() { + local name=$1; shift + run "$name-configure" cmake -S "$build/$name" -B "$build/$name-build" -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE="$build/windows.cmake" -DCMAKE_INSTALL_PREFIX="$prefix" \ + -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF "$@" + run "$name-build" cmake --build "$build/$name-build" --parallel "$jobs" + run "$name-install" cmake --install "$build/$name-build" +} +cmake_lib ogg -DINSTALL_DOCS=OFF +cmake_lib vorbis +cmake_lib opus -DOPUS_BUILD_TESTING=OFF -DOPUS_BUILD_PROGRAMS=OFF -DOPUS_DRED=OFF -DOPUS_DEEP_PLC=OFF -DOPUS_OSCE=OFF +cmake_lib webp -DWEBP_BUILD_ANIM_UTILS=OFF -DWEBP_BUILD_CWEBP=OFF -DWEBP_BUILD_DWEBP=OFF \ + -DWEBP_BUILD_GIF2WEBP=OFF -DWEBP_BUILD_IMG2WEBP=OFF -DWEBP_BUILD_VWEBP=OFF \ + -DWEBP_BUILD_WEBPINFO=OFF -DWEBP_BUILD_LIBWEBPMUX=OFF -DWEBP_BUILD_WEBPMUX=OFF -DWEBP_BUILD_EXTRAS=OFF +run dav1d-configure meson setup "$build/dav1d-build" "$build/dav1d" --cross-file "$build/windows.meson" \ + --prefix "$prefix" --libdir lib --buildtype release --default-library static -Denable_tools=false -Denable_tests=false +run dav1d-build ninja -C "$build/dav1d-build" -j "$jobs" +run dav1d-install meson install -C "$build/dav1d-build" +( + cd "$build/lame" + run lame-configure ./configure --host=x86_64-w64-mingw32 --prefix="$prefix" --disable-shared --enable-static --disable-frontend --disable-decoder --disable-nasm + run lame-build make -j "$jobs" + run lame-install make install +) +( + cd "$build/x264" + run x264-configure ./configure --host=x86_64-w64-mingw32 --cross-prefix=x86_64-w64-mingw32- --prefix="$prefix" \ + --enable-static --disable-cli --disable-opencl --disable-avs --disable-lavf --disable-swscale --disable-ffms + run x264-build make -j "$jobs" + run x264-install make install-lib-static install-lib-dev +) +( + cd "$build/vpx" + run vpx-configure ./configure --target=x86_64-win64-gcc --prefix="$prefix" --as=nasm \ + --enable-static --disable-shared --disable-examples --disable-tools --disable-docs --disable-unit-tests \ + --disable-vp8-encoder --disable-vp8-decoder --disable-vp9-decoder + run vpx-build make -j "$jobs" + run vpx-install make install +) +( + cd "$build/ffmpeg" + # Keep decoding broad within the advertised containers; only encode our + # exposed targets. There is no network protocol, capture device or AI filter. + decoders='aac,aac_fixed,ac3,eac3,alac,mp1,mp1float,mp2,mp2float,mp3,mp3float,flac,vorbis,opus,wmav1,wmav2,wmapro,wmalossless,pcm_s16le,pcm_s16be,pcm_s24le,pcm_s24be,pcm_s32le,pcm_s32be,pcm_f32le,pcm_f32be,pcm_f64le,pcm_f64be,pcm_u8,pcm_alaw,pcm_mulaw,adpcm_ms,adpcm_ima_wav,h264,hevc,mpeg1video,mpeg2video,mpeg4,msmpeg4v1,msmpeg4v2,msmpeg4v3,wmv1,wmv2,wmv3,vc1,vp8,vp9,libdav1d,prores,ffv1,dvvideo,mjpeg,png,bmp,tiff,gif,webp,rawvideo,qtrle' + run ffmpeg-configure ./configure --target-os=mingw32 --arch=x86_64 --enable-cross-compile \ + --cross-prefix=x86_64-w64-mingw32- --cc="$CC" --cxx="$CXX" --pkg-config=pkg-config --pkg-config-flags=--static \ + --extra-cflags="-I$prefix/include" --extra-ldflags="-L$prefix/lib -static" \ + --enable-static --disable-shared --enable-gpl --disable-autodetect --disable-debug --disable-doc \ + --disable-network --disable-devices --disable-hwaccels --disable-avdevice --disable-everything \ + --enable-ffmpeg --disable-ffplay --disable-ffprobe \ + --enable-libx264 --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libvpx --enable-libwebp --enable-libdav1d \ + --enable-protocol=file,pipe --enable-decoder="$decoders" \ + --enable-encoder=libmp3lame,aac,pcm_s16le,flac,libvorbis,libvpx_vp9,libopus,libx264,wmv2,wmav2,png,libwebp \ + --enable-demuxer=aac,mov,matroska,avi,asf,mpegps,mpegts,mp3,wav,flac,ogg,image2,image2pipe,png_pipe,webp_pipe,jpeg_pipe,bmp_pipe,tiff_pipe,gif,rawvideo \ + --enable-muxer=image2,image2pipe,mp3,ipod,wav,flac,ogg,mp4,asf,matroska,webm,null \ + --enable-parser=aac,ac3,flac,h264,hevc,mjpeg,mpeg4video,mpegaudio,mpegvideo,opus,vorbis,vp8,vp9,av1,png \ + --enable-bsf=aac_adtstoasc,h264_mp4toannexb,hevc_mp4toannexb,extract_extradata \ + --enable-filter=pad,format,scale,aresample,aformat,null,anull,trim,atrim,setpts,asetpts,fps + run ffmpeg-build make -j "$jobs" ffmpeg.exe + "$STRIP" ffmpeg.exe + cp ffmpeg.exe "$out/ffmpeg.exe" + cp config.h config_components.h ffbuild/config.mak "$out/sources/" + cp COPYING.GPLv2 "$out/LICENSE.txt" +) +# Full preferred source and exact build recipe travel with the executable. +cp "$root/scripts/build-conversion-ffmpeg.sh" "$root/scripts/conversion-sources.json" "$out/sources/" +printf '%s\n' 'FFmpeg 9.0.2, GPL-2.0-or-later, with x264 and the codecs listed in sources/conversion-sources.json.' \ + 'Unmodified upstream source archives, notices and the cross-build recipe are included in sources/ and licenses/.' \ + 'No ffplay, ffprobe, network protocols, capture devices, neural audio options or AI filters are built.' \ + 'Build dependencies on Ubuntu: gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix nasm cmake ninja-build meson pkg-config make curl python3.' \ + 'Rebuild from the DailyToolkit repository with: bash scripts/build-conversion-ffmpeg.sh' > "$out/SOURCE.txt" +x86_64-w64-mingw32-objdump -p "$out/ffmpeg.exe" | sed -n 's/.*DLL Name: //p' > "$out/system-dependencies.txt" +if grep -Eiq 'libgcc|libstdc|libwinpthread|libav|\.dll[^[:space:]]' "$out/system-dependencies.txt"; then + echo 'Unexpected external runtime DLL'; cat "$out/system-dependencies.txt"; exit 1 +fi +mkdir -p "$root/.local/conversion-tools/tools" +if [[ -e "$root/.local/conversion-tools/tools/ffmpeg" ]]; then echo 'Refuse to replace an existing engine directory'; exit 1; fi +mv "$out" "$root/.local/conversion-tools/tools/ffmpeg" +echo 'FFmpeg bundle ready:' +du -sh "$root/.local/conversion-tools/tools/ffmpeg" +cat "$root/.local/conversion-tools/tools/ffmpeg/system-dependencies.txt" diff --git a/scripts/conversion-sources.json b/scripts/conversion-sources.json new file mode 100644 index 0000000..79d6da9 --- /dev/null +++ b/scripts/conversion-sources.json @@ -0,0 +1,65 @@ +[ + { + "name": "ffmpeg", + "version": "9.0.2", + "revision": "946fcce07b6dcd0331c8cc609192aeff5e1924f8", + "url": "https://codeload.github.com/FFmpeg/FFmpeg/tar.gz/946fcce07b6dcd0331c8cc609192aeff5e1924f8", + "sha256": "0aa2b1de2a5698b20a23e93d539a9a8e82ca0117496c5bdf05d198805f42bb3b" + }, + { + "name": "x264", + "version": "stable-2026", + "revision": "31e19f92f00c7003fa115047ce50978bc98c3a0d", + "url": "https://codeload.github.com/mirror/x264/tar.gz/31e19f92f00c7003fa115047ce50978bc98c3a0d", + "sha256": "d053c9d86988d6bc78237ca5205865c5ddf99c98ef4cd9927eec8f6d388f6dd9" + }, + { + "name": "vpx", + "version": "1.17.0", + "revision": "6df3ec34557879fff673706f4a1d9fbd0f3a6f0e", + "url": "https://codeload.github.com/webmproject/libvpx/tar.gz/6df3ec34557879fff673706f4a1d9fbd0f3a6f0e", + "sha256": "073bd6202e4c55c8cb759abbb123aecd4cc8d99f52ba27af790178cfb1108423" + }, + { + "name": "opus", + "version": "1.6.1", + "revision": "22244de5a79bd1d6d623c32e72bf1954b56235be", + "url": "https://codeload.github.com/xiph/opus/tar.gz/22244de5a79bd1d6d623c32e72bf1954b56235be", + "sha256": "3267aa969b2b26542417f57819a5bc25d5079355300307dd2dddc7c704aed418" + }, + { + "name": "ogg", + "version": "1.3.6", + "revision": "be05b13e98b048f0b5a0f5fa8ce514d56db5f822", + "url": "https://codeload.github.com/xiph/ogg/tar.gz/be05b13e98b048f0b5a0f5fa8ce514d56db5f822", + "sha256": "b2ff5c003e5697507169f7d614d64dc4e8bf030c85ad081bec75c164566f8246" + }, + { + "name": "vorbis", + "version": "1.3.7", + "revision": "0657aee69dec8508a0011f47f3b69d7538e9d262", + "url": "https://codeload.github.com/xiph/vorbis/tar.gz/0657aee69dec8508a0011f47f3b69d7538e9d262", + "sha256": "6ccc3fa4cfd3072f9a772025cc8fd712098d081c00171b09b6627ffced7faa88" + }, + { + "name": "webp", + "version": "1.6.0", + "revision": "4fa21912338357f89e4fd51cf2368325b59e9bd9", + "url": "https://codeload.github.com/webmproject/libwebp/tar.gz/4fa21912338357f89e4fd51cf2368325b59e9bd9", + "sha256": "923f3382a47a2af185c3240c954cf004428b237bd7317413a95146d01eb4b94b" + }, + { + "name": "dav1d", + "version": "1.5.2", + "revision": "c720f4d3556a01916324aea155555d3efba842e8", + "url": "https://codeload.github.com/videolan/dav1d/tar.gz/c720f4d3556a01916324aea155555d3efba842e8", + "sha256": "6b15b0df3c10a60ae912b12e64f731888346d39fdc35d58966f2f26cca95745d" + }, + { + "name": "lame", + "version": "3.100", + "revision": "", + "url": "https://deb.debian.org/debian/pool/main/l/lame/lame_3.100.orig.tar.gz", + "sha256": "ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e" + } +] From 4ed01251d3f31c15767aad4804aeece58b0385aa Mon Sep 17 00:00:00 2001 From: YeMuXingKong <3476758756@qq.com> Date: Thu, 12 Nov 2026 02:08:38 +0800 Subject: [PATCH 03/18] Stage checksum-pinned app-local office dependencies and fix source build compatibility --- .github/workflows/conversion-bundle.yml | 6 +- scripts/build-conversion-ffmpeg.sh | 7 +- scripts/conversion-sources.json | 7 ++ scripts/prepare-conversion-office.ps1 | 63 ++++++++++++ scripts/stage-conversion-office.py | 128 ++++++++++++++++++++++++ 5 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 scripts/prepare-conversion-office.ps1 create mode 100644 scripts/stage-conversion-office.py diff --git a/.github/workflows/conversion-bundle.yml b/.github/workflows/conversion-bundle.yml index 9732c8c..ea5aaf8 100644 --- a/.github/workflows/conversion-bundle.yml +++ b/.github/workflows/conversion-bundle.yml @@ -39,10 +39,12 @@ jobs: with: persist-credentials: false - shell: pwsh - run: ./scripts/inspect-conversion-bundle.ps1 + run: ./scripts/prepare-conversion-office.ps1 - uses: actions/upload-artifact@v7 if: always() with: name: conversion-bundle-inspection - path: .local/conversion-bundle-inspection/** + path: | + .local/conversion-office/**/*.json + .local/conversion-office/**/*.log retention-days: 7 diff --git a/scripts/build-conversion-ffmpeg.sh b/scripts/build-conversion-ffmpeg.sh index 884f8f3..1aea693 100644 --- a/scripts/build-conversion-ffmpeg.sh +++ b/scripts/build-conversion-ffmpeg.sh @@ -63,11 +63,12 @@ cmake_lib() { local name=$1; shift run "$name-configure" cmake -S "$build/$name" -B "$build/$name-build" -G Ninja \ -DCMAKE_TOOLCHAIN_FILE="$build/windows.cmake" -DCMAKE_INSTALL_PREFIX="$prefix" \ - -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF "$@" + -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF "$@" run "$name-build" cmake --build "$build/$name-build" --parallel "$jobs" run "$name-install" cmake --install "$build/$name-build" } cmake_lib ogg -DINSTALL_DOCS=OFF +cmake_lib zlib -DZLIB_BUILD_EXAMPLES=OFF -DZLIB_BUILD_TESTING=OFF -DZLIB_BUILD_SHARED=OFF cmake_lib vorbis cmake_lib opus -DOPUS_BUILD_TESTING=OFF -DOPUS_BUILD_PROGRAMS=OFF -DOPUS_DRED=OFF -DOPUS_DEEP_PLC=OFF -DOPUS_OSCE=OFF cmake_lib webp -DWEBP_BUILD_ANIM_UTILS=OFF -DWEBP_BUILD_CWEBP=OFF -DWEBP_BUILD_DWEBP=OFF \ @@ -109,9 +110,9 @@ run dav1d-install meson install -C "$build/dav1d-build" --enable-static --disable-shared --enable-gpl --disable-autodetect --disable-debug --disable-doc \ --disable-network --disable-devices --disable-hwaccels --disable-avdevice --disable-everything \ --enable-ffmpeg --disable-ffplay --disable-ffprobe \ - --enable-libx264 --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libvpx --enable-libwebp --enable-libdav1d \ + --enable-zlib --enable-libx264 --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libvpx --enable-libwebp --enable-libdav1d \ --enable-protocol=file,pipe --enable-decoder="$decoders" \ - --enable-encoder=libmp3lame,aac,pcm_s16le,flac,libvorbis,libvpx_vp9,libopus,libx264,wmv2,wmav2,png,libwebp \ + --enable-encoder=libmp3lame,aac,pcm_s16le,flac,libvorbis,libvpx_vp9,libopus,libx264,wmv2,wmav2,png,libwebp,ffv1 \ --enable-demuxer=aac,mov,matroska,avi,asf,mpegps,mpegts,mp3,wav,flac,ogg,image2,image2pipe,png_pipe,webp_pipe,jpeg_pipe,bmp_pipe,tiff_pipe,gif,rawvideo \ --enable-muxer=image2,image2pipe,mp3,ipod,wav,flac,ogg,mp4,asf,matroska,webm,null \ --enable-parser=aac,ac3,flac,h264,hevc,mjpeg,mpeg4video,mpegaudio,mpegvideo,opus,vorbis,vp8,vp9,av1,png \ diff --git a/scripts/conversion-sources.json b/scripts/conversion-sources.json index 79d6da9..e38935b 100644 --- a/scripts/conversion-sources.json +++ b/scripts/conversion-sources.json @@ -61,5 +61,12 @@ "revision": "", "url": "https://deb.debian.org/debian/pool/main/l/lame/lame_3.100.orig.tar.gz", "sha256": "ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e" + }, + { + "name": "zlib", + "version": "1.4", + "revision": "99623ef7097352da7993ba614161fd6a311e046e", + "url": "https://codeload.github.com/madler/zlib/tar.gz/99623ef7097352da7993ba614161fd6a311e046e", + "sha256": "f0d590dd90243a12f551ee13359bf6c634249c55b316fa2b7dbecabe7ae9a904" } ] diff --git a/scripts/prepare-conversion-office.ps1 b/scripts/prepare-conversion-office.ps1 new file mode 100644 index 0000000..926c8db --- /dev/null +++ b/scripts/prepare-conversion-office.ps1 @@ -0,0 +1,63 @@ +param([string]$OutputDirectory) +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $false +if (-not $IsWindows) { throw 'LibreOffice staging requires Windows; it never installs LibreOffice.' } +$root = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) +if (-not $OutputDirectory) { $OutputDirectory = Join-Path $root '.local/conversion-tools/tools/libreoffice' } +$OutputDirectory = [IO.Path]::GetFullPath($OutputDirectory) +if (Test-Path -LiteralPath $OutputDirectory) { throw 'Refuse to replace an existing staged office engine.' } +$version = '26.2.6' +$hash = 'f9877032fd908beb9c0ddf06df4af5c2e85f419c42e14876c4cce5aae5fb2660' +$url = "https://download.documentfoundation.org/libreoffice/stable/$version/win/x86_64/LibreOffice_${version}_Win_x86-64.msi" +$work = Join-Path $root ('.local/conversion-office/' + [guid]::NewGuid().ToString('N')) +New-Item -ItemType Directory -Path $work -Force | Out-Null +$msi = Join-Path $work "LibreOffice-$version.msi" +[xml]$meta = (Invoke-WebRequest ($url + '.meta4') -TimeoutSec 60).Content +$officialHash = @($meta.metalink.file.hash | Where-Object type -eq 'sha-256')[0].InnerText.ToLowerInvariant() +if ($officialHash -ne $hash) { throw 'Official office metadata differs from the pinned source; review before updating.' } +$downloaded = $false +foreach ($mirror in @($meta.metalink.file.url | Where-Object { $_.InnerText.StartsWith('https://') } | Sort-Object { [int]$_.priority } | Select-Object -First 4)) { + & curl.exe --fail --silent --show-error --location --connect-timeout 15 --max-time 90 --output $msi $mirror.InnerText + if ($LASTEXITCODE -eq 0 -and (Get-FileHash -LiteralPath $msi).Hash.ToLowerInvariant() -eq $hash) { $downloaded = $true; break } +} +if (-not $downloaded) { throw 'No official mirror returned the checksum-verified archive in time.' } +$extract = Join-Path $work 'extracted' +$p = Start-Process msiexec.exe -ArgumentList @('/a', ('"' + $msi + '"'), '/qn', '/norestart', ('TARGETDIR="' + $extract + '"'), '/L*v', ('"' + (Join-Path $work 'extract.log') + '"')) -PassThru +if (-not $p.WaitForExit(240000)) { throw 'Administrative archive extraction timed out; no installed application was changed.' } +if ($p.ExitCode -notin @(0,3010)) { throw "Administrative archive extraction failed: $($p.ExitCode)" } +$entry = @(Get-ChildItem -LiteralPath $extract -Recurse -Filter soffice.com -File) +if ($entry.Count -ne 1) { throw 'Expected one upstream office console entry.' } +$source = $entry[0].Directory.Parent.FullName +$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio/Installer/vswhere.exe' +$vs = & $vswhere -latest -products '*' -property installationPath +if ($LASTEXITCODE -ne 0 -or -not $vs) { throw 'A licensed Visual C++ app-local CRT is required when preparing the bundle.' } +$crt = Get-ChildItem -LiteralPath (Join-Path $vs 'VC/Redist/MSVC') -Recurse -Directory -Filter 'Microsoft.VC*.CRT' | + Where-Object { $_.Parent.Name -eq 'x64' } | Sort-Object FullName -Descending | Select-Object -First 1 +if (-not $crt) { throw 'The Microsoft x64 app-local CRT was not found.' } +$metrics = & python (Join-Path $PSScriptRoot 'stage-conversion-office.py') $source $OutputDirectory $crt.FullName +if ($LASTEXITCODE -ne 0) { throw 'Office dependency staging failed.' } +$metrics | Set-Content -LiteralPath (Join-Path $work 'selection.json') -Encoding utf8 +$summary = $metrics | ConvertFrom-Json +Write-Host ("Office: selected {0:N1} MiB / {1:N1} MiB; {2} files; {3} checked binaries" -f ($summary.selectedBytes/1MB),($summary.upstreamBytes/1MB),$summary.selectedFiles,$summary.checkedBinaries) +Write-Host ('App-local CRT: ' + ($summary.microsoftRuntime -join ', ')) +@" +LibreOffice 26.2.6.3, The Document Foundation and contributors. +Unmodified upstream runtime files selected for Writer, Calc and Impress conversion. +MPL-2.0 and third-party licenses: license.txt, LICENSE.html and NOTICE in this folder. +Official binary archive: $url +SHA-256: $hash +Corresponding source and external dependency manifests: +https://download.documentfoundation.org/libreoffice/src/26.2.6/libreoffice-26.2.6.3.tar.xz +https://github.com/LibreOffice/core/tree/libreoffice-26.2.6.3 +The source archive includes download.lst and external/ with versions, checksums and build recipes. +This selection does not change upstream binaries. Selection recipe: scripts/stage-conversion-office.py in DailyToolkit source. +Microsoft Visual C++ CRT files are included app-local; no runtime installer or system registration is used. +Copyright (C) Microsoft Corporation. All rights reserved. +Runtime terms: https://visualstudio.microsoft.com/license-terms/vs2022-cruntime/ +"@ | Set-Content -LiteralPath (Join-Path $OutputDirectory 'SOURCE.txt') -Encoding utf8 +$profile = Join-Path $work 'probe-profile' +$input = Join-Path $work '离线检查.txt' +[IO.File]::WriteAllText($input, '格式转换离线检查', [Text.UTF8Encoding]::new($false)) +& (Join-Path $OutputDirectory 'program/soffice.com') ('-env:UserInstallation=' + ([uri]($profile + '\')).AbsoluteUri) --headless --nologo --nodefault --nofirststartwizard --norestore --convert-to pdf --outdir $work $input +if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath (Join-Path $work '离线检查.pdf'))) { throw 'Selected app-local office runtime did not convert Unicode text to PDF.' } +Write-Host 'PASS Selected app-local LibreOffice: Unicode TXT to PDF without installation.' diff --git a/scripts/stage-conversion-office.py b/scripts/stage-conversion-office.py new file mode 100644 index 0000000..ed8e36c --- /dev/null +++ b/scripts/stage-conversion-office.py @@ -0,0 +1,128 @@ +"""Stage only the local Writer/Calc/Impress conversion runtime; no installer runs here.""" +import fnmatch +import hashlib +import json +import pathlib +import shutil +import struct +import sys + + +def imports(path): + data = path.read_bytes() + if data[:2] != b'MZ': + return [] + pe = struct.unpack_from(' Date: Thu, 12 Nov 2026 02:14:41 +0800 Subject: [PATCH 04/18] Verify prepared engine inventories and resolve static zlib and Windows font dependencies --- scripts/build-conversion-ffmpeg.sh | 26 ++++++++++++++--- scripts/conversion-manifest.py | 41 +++++++++++++++++++++++++++ scripts/prepare-conversion-office.ps1 | 2 ++ scripts/stage-conversion-office.py | 7 +++-- 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 scripts/conversion-manifest.py diff --git a/scripts/build-conversion-ffmpeg.sh b/scripts/build-conversion-ffmpeg.sh index 1aea693..b4e5198 100644 --- a/scripts/build-conversion-ffmpeg.sh +++ b/scripts/build-conversion-ffmpeg.sh @@ -15,11 +15,13 @@ export PKG_CONFIG_LIBDIR="$prefix/lib/pkgconfig" PKG_CONFIG_PATH="$prefix/lib/pk export CFLAGS='-O2' CXXFLAGS='-O2' python3 - "$root/scripts/conversion-sources.json" "$build" <<'PY' -import hashlib,json,pathlib,subprocess,sys,tarfile +import hashlib,json,os,pathlib,shutil,subprocess,sys,tarfile spec=pathlib.Path(sys.argv[1]); root=pathlib.Path(sys.argv[2]) for item in json.loads(spec.read_text()): name=item['name']; archive=root/'output'/'sources'/(name+'.tar.gz') - subprocess.run(['curl','--fail','--silent','--show-error','--location','--connect-timeout','20','--max-time','180','--output',str(archive),item['url']],check=True) + local=pathlib.Path(os.environ.get('CONVERSION_SOURCE_DIRECTORY',str(root)))/(name+'.tar.gz') + if local.is_file(): shutil.copyfile(local,archive) + else: subprocess.run(['curl','--fail','--silent','--show-error','--location','--connect-timeout','20','--max-time','180','--output',str(archive),item['url']],check=True) if hashlib.sha256(archive.read_bytes()).hexdigest()!=item['sha256']: raise RuntimeError('Source checksum mismatch: '+name) target=root/name; target.mkdir() subprocess.run(['tar','-xzf',str(archive),'--strip-components=1','-C',str(target)],check=True) @@ -57,7 +59,11 @@ EOF run() { local label=$1; shift echo "Building $label" - if ! "$@" >"$build/$label.log" 2>&1; then tail -n 100 "$build/$label.log"; return 1; fi + if ! "$@" >"$build/$label.log" 2>&1; then + tail -n 100 "$build/$label.log" + if [[ "$label" == ffmpeg-configure ]]; then tail -n 100 "$build/ffmpeg/ffbuild/config.log"; fi + return 1 + fi } cmake_lib() { local name=$1; shift @@ -69,6 +75,10 @@ cmake_lib() { } cmake_lib ogg -DINSTALL_DOCS=OFF cmake_lib zlib -DZLIB_BUILD_EXAMPLES=OFF -DZLIB_BUILD_TESTING=OFF -DZLIB_BUILD_SHARED=OFF +# Upstream's Windows static archive has a suffix while its pkg-config file +# advertises -lz. Keep a link inside this private cross-build prefix only. +if [[ ! -f "$prefix/lib/libz.a" && -f "$prefix/lib/libzs.a" ]]; then ln -s libzs.a "$prefix/lib/libz.a"; fi +if [[ ! -f "$prefix/lib/libz.a" && -f "$prefix/lib/libzstatic.a" ]]; then ln -s libzstatic.a "$prefix/lib/libz.a"; fi cmake_lib vorbis cmake_lib opus -DOPUS_BUILD_TESTING=OFF -DOPUS_BUILD_PROGRAMS=OFF -DOPUS_DRED=OFF -DOPUS_DEEP_PLC=OFF -DOPUS_OSCE=OFF cmake_lib webp -DWEBP_BUILD_ANIM_UTILS=OFF -DWEBP_BUILD_CWEBP=OFF -DWEBP_BUILD_DWEBP=OFF \ @@ -126,11 +136,17 @@ run dav1d-install meson install -C "$build/dav1d-build" ) # Full preferred source and exact build recipe travel with the executable. cp "$root/scripts/build-conversion-ffmpeg.sh" "$root/scripts/conversion-sources.json" "$out/sources/" +mkdir -p "$out/licenses/toolchain" +for notice in /usr/share/doc/gcc-mingw-w64-base/copyright /usr/share/doc/mingw-w64-common/copyright; do + [[ -f "$notice" ]] || { echo "Missing toolchain notice: $notice"; exit 1; } + cp "$notice" "$out/licenses/toolchain/$(basename "$(dirname "$notice")").txt" +done printf '%s\n' 'FFmpeg 9.0.2, GPL-2.0-or-later, with x264 and the codecs listed in sources/conversion-sources.json.' \ 'Unmodified upstream source archives, notices and the cross-build recipe are included in sources/ and licenses/.' \ 'No ffplay, ffprobe, network protocols, capture devices, neural audio options or AI filters are built.' \ 'Build dependencies on Ubuntu: gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix nasm cmake ninja-build meson pkg-config make curl python3.' \ - 'Rebuild from the DailyToolkit repository with: bash scripts/build-conversion-ffmpeg.sh' > "$out/SOURCE.txt" + 'Rebuild from the DailyToolkit repository with: bash scripts/build-conversion-ffmpeg.sh' \ + 'For source-only rebuilding, copy the two recipe files to an empty scripts/ directory and set CONVERSION_SOURCE_DIRECTORY to this sources/ directory.' > "$out/SOURCE.txt" x86_64-w64-mingw32-objdump -p "$out/ffmpeg.exe" | sed -n 's/.*DLL Name: //p' > "$out/system-dependencies.txt" if grep -Eiq 'libgcc|libstdc|libwinpthread|libav|\.dll[^[:space:]]' "$out/system-dependencies.txt"; then echo 'Unexpected external runtime DLL'; cat "$out/system-dependencies.txt"; exit 1 @@ -138,6 +154,8 @@ fi mkdir -p "$root/.local/conversion-tools/tools" if [[ -e "$root/.local/conversion-tools/tools/ffmpeg" ]]; then echo 'Refuse to replace an existing engine directory'; exit 1; fi mv "$out" "$root/.local/conversion-tools/tools/ffmpeg" +python3 "$root/scripts/conversion-manifest.py" create "$root/.local/conversion-tools/tools/ffmpeg" ffmpeg \ + "$root/scripts/build-conversion-ffmpeg.sh" "$root/scripts/conversion-sources.json" echo 'FFmpeg bundle ready:' du -sh "$root/.local/conversion-tools/tools/ffmpeg" cat "$root/.local/conversion-tools/tools/ffmpeg/system-dependencies.txt" diff --git a/scripts/conversion-manifest.py b/scripts/conversion-manifest.py new file mode 100644 index 0000000..951cf8c --- /dev/null +++ b/scripts/conversion-manifest.py @@ -0,0 +1,41 @@ +"""Create/verify the exact prepared component inventory, excluding the manifest itself.""" +import hashlib +import json +import pathlib +import sys + + +def digest(path): + with path.open('rb') as stream: + return hashlib.file_digest(stream, 'sha256').hexdigest() + + +def inventory(root): + files = [] + for path in sorted(root.rglob('*')): + if path.is_symlink(): + raise ValueError('A bundle cannot include links: ' + str(path)) + if path.is_file() and path != root / 'bundle.json': + rel = path.relative_to(root).as_posix() + if any(part.startswith('.') for part in pathlib.PurePosixPath(rel).parts): + raise ValueError('A bundle cannot include hidden development files: ' + rel) + files.append(dict(path=rel, bytes=path.stat().st_size, sha256=digest(path))) + return files + + +if __name__ == '__main__': + mode, directory, component, *recipes = sys.argv[1:] + root = pathlib.Path(directory) + manifest = root / 'bundle.json' + recipe = {pathlib.Path(p).name: digest(pathlib.Path(p)) for p in recipes} + value = dict(schema=1, component=component, recipe=recipe, files=inventory(root)) + if mode == 'create': + if manifest.exists(): + raise ValueError('Refuse to replace a component manifest') + manifest.write_text(json.dumps(value, indent=2) + '\n', encoding='utf-8') + elif mode == 'verify': + expected = json.loads(manifest.read_text(encoding='utf-8')) + if value != expected: + raise ValueError('Prepared component differs from its pinned recipe or inventory: ' + component) + else: + raise ValueError('Expected create or verify') diff --git a/scripts/prepare-conversion-office.ps1 b/scripts/prepare-conversion-office.ps1 index 926c8db..d019719 100644 --- a/scripts/prepare-conversion-office.ps1 +++ b/scripts/prepare-conversion-office.ps1 @@ -61,3 +61,5 @@ $input = Join-Path $work '离线检查.txt' & (Join-Path $OutputDirectory 'program/soffice.com') ('-env:UserInstallation=' + ([uri]($profile + '\')).AbsoluteUri) --headless --nologo --nodefault --nofirststartwizard --norestore --convert-to pdf --outdir $work $input if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath (Join-Path $work '离线检查.pdf'))) { throw 'Selected app-local office runtime did not convert Unicode text to PDF.' } Write-Host 'PASS Selected app-local LibreOffice: Unicode TXT to PDF without installation.' +& python (Join-Path $PSScriptRoot 'conversion-manifest.py') create $OutputDirectory libreoffice $PSCommandPath (Join-Path $PSScriptRoot 'stage-conversion-office.py') +if ($LASTEXITCODE -ne 0) { throw 'Office component manifest creation failed.' } diff --git a/scripts/stage-conversion-office.py b/scripts/stage-conversion-office.py index ed8e36c..32b8815 100644 --- a/scripts/stage-conversion-office.py +++ b/scripts/stage-conversion-office.py @@ -93,8 +93,9 @@ def stage(source, target, crt): crt_files = {p.name.lower(): p for p in crt.glob('*.dll')} additional = {} checked = set() - system = set('advapi32 avrt bcrypt cabinet cfgmgr32 comctl32 comdlg32 credui crypt32 cryptbase cryptsp d2d1 d3d11 d3d12 d3d9 d3dcompiler_47 dcomp dhcpcsvc dnsapi dsound dwmapi dwrite dxgi dxva2 faultrep gdi32 gdiplus glu32 hid imagehlp imm32 iphlpapi kernel32 mpr mprapi msimg32 msvcrt mswsock msxml6 ncrypt netapi32 ntdll ole32 oleacc oleaut32 opengl32 powrprof propsys psapi rasapi32 rpcrt4 secur32 setupapi shcore shell32 shlwapi urlmon user32 userenv usp10 uxtheme version winhttp wininet winmm winscard winspool.drv wintrust wlanapi wldap32 ws2_32 wtsapi32'.split()) + system = set('advapi32 avrt bcrypt cabinet cfgmgr32 comctl32 comdlg32 combase credui crypt32 cryptbase cryptsp d2d1 d3d11 d3d12 d3d9 d3dcompiler_47 dcomp dhcpcsvc dnsapi dsound dwmapi dwrite dxgi dxva2 faultrep fontsub gdi32 gdiplus glu32 hid imagehlp imm32 iphlpapi kernel32 kernelbase mpr mprapi msimg32 msvcrt mswsock msxml6 ncrypt netapi32 ntdll ole32 oleacc oleaut32 opengl32 powrprof profapi propsys psapi rasapi32 rpcrt4 secur32 setupapi shcore shell32 shlwapi sspicli ucrtbase urlmon user32 userenv usp10 uxtheme version winhttp wininet winmm winscard winspool.drv wintrust wlanapi wldap32 ws2_32 wtsapi32'.split()) system = {x if '.' in x else x + '.dll' for x in system} + missing = set() while True: pending = {rel: source_files[rel] for rel in chosen if rel not in checked and pathlib.PurePosixPath(rel).suffix.lower() in ('.dll', '.exe', '.com', '.bin')} pending.update({rel: p for rel, p in additional.items() if rel not in checked}) @@ -108,7 +109,9 @@ def stage(source, target, crt): elif dep in crt_files: additional['program/' + dep] = crt_files[dep] elif dep not in system and not dep.startswith(('api-ms-win-', 'ext-ms-win-')): - raise ValueError(f'Unresolved dependency {dep} imported by {rel}') + missing.add(f'{dep} imported by {rel}') + if missing: + raise ValueError('Unresolved dependencies:\n' + '\n'.join(sorted(missing))) for rel in sorted(chosen): dest = target / rel if rel.startswith('Fonts/'): From 724e00f03ddb1faedc915e68ad4d12b9110fc810 Mon Sep 17 00:00:00 2001 From: YeMuXingKong <3476758756@qq.com> Date: Thu, 12 Nov 2026 02:24:13 +0800 Subject: [PATCH 05/18] Bundle offline conversion engines and verify portable and installed payloads --- .github/workflows/build.yml | 19 +++++- .github/workflows/conversion-bundle.yml | 34 ++++++++-- Directory.Build.props | 2 +- README.md | 2 +- THIRD_PARTY_NOTICES.txt | 19 ++++++ docs/FORMAT_CONVERSION.md | 28 ++++---- docs/INSTALLER_README.txt | 2 +- docs/PORTABLE_README.txt | 2 +- installer/DailyToolkit.iss | 2 + scripts/build-conversion-ffmpeg.sh | 2 +- scripts/conversion-payload.ps1 | 27 ++++++++ scripts/inspect-conversion-bundle.ps1 | 39 ----------- scripts/package-installer.ps1 | 11 ++++ scripts/prepare-conversion-checks.ps1 | 57 +++++----------- scripts/prepare-conversion-office.ps1 | 12 ++++ scripts/publish.ps1 | 15 +++++ scripts/stage-conversion-office.py | 4 +- scripts/test-conversion-bundle.ps1 | 33 ++++++++++ scripts/test-installer.ps1 | 9 +++ .../Conversion/BundledConversionEngines.cs | 22 +++++++ .../Conversion/ExternalConversionBackend.cs | 6 ++ .../Conversion/ConversionView.xaml | 12 +--- .../Conversion/ConversionView.xaml.cs | 8 --- .../Conversion/ConversionViewModel.cs | 24 ++++--- .../Conversion/LocalConversionBackend.cs | 13 ++++ .../BundledConversionTests.cs | 65 +++++++++++++++++++ .../ConversionTests.cs | 14 ++-- tests/DailyToolkit.Desktop.Tests/Program.cs | 4 +- tests/DailyToolkit.Tests/ConversionTests.cs | 15 ++++- 29 files changed, 353 insertions(+), 149 deletions(-) create mode 100644 scripts/conversion-payload.ps1 delete mode 100644 scripts/inspect-conversion-bundle.ps1 create mode 100644 scripts/test-conversion-bundle.ps1 create mode 100644 src/DailyToolkit.Core/Conversion/BundledConversionEngines.cs create mode 100644 tests/DailyToolkit.Desktop.Tests/BundledConversionTests.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index efaecb4..bda15ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,11 @@ permissions: contents: read jobs: + conversion-engines: + if: github.event_name != 'schedule' + uses: ./.github/workflows/conversion-bundle.yml windows: + needs: conversion-engines if: github.event_name != 'schedule' runs-on: windows-latest timeout-minutes: 30 @@ -39,7 +43,15 @@ jobs: & ./tests/DailyToolkit.Desktop.Tests/bin/Release/net10.0-windows10.0.26100.0/DailyToolkit.Desktop.Tests.exe --clipboard-native-filepack-ipc-checks if ($LASTEXITCODE -ne 0) { throw 'Explorer IPC fixture failed; see its bounded protocol trace.' } } - - name: Prepare local conversion test engines + - uses: actions/download-artifact@v8 + with: + name: conversion-ffmpeg-win-x64 + path: .local/conversion-tools/tools/ffmpeg + - uses: actions/download-artifact@v8 + with: + name: conversion-office-win-x64 + path: .local/conversion-tools/tools/libreoffice + - name: Prepare bundled conversion test engines timeout-minutes: 12 shell: pwsh run: ./scripts/prepare-conversion-checks.ps1 @@ -69,6 +81,11 @@ jobs: - name: Package portable app shell: pwsh run: ./scripts/publish.ps1 + - name: Check actual portable engines offline + shell: pwsh + run: | + [xml]$properties = Get-Content -LiteralPath Directory.Build.props -Raw + ./scripts/test-conversion-bundle.ps1 -PayloadDirectory "artifacts/DailyToolkit-$($properties.Project.PropertyGroup.Version)-win-x64" - name: Package installer shell: pwsh run: ./scripts/package-installer.ps1 -Compiler (Join-Path ${env:ProgramFiles(x86)} 'Inno Setup 6\ISCC.exe') diff --git a/.github/workflows/conversion-bundle.yml b/.github/workflows/conversion-bundle.yml index ea5aaf8..266bc26 100644 --- a/.github/workflows/conversion-bundle.yml +++ b/.github/workflows/conversion-bundle.yml @@ -1,7 +1,6 @@ -name: Inspect conversion bundle +name: Prepare offline conversion engines on: - push: - branches: [codex/bundle-offline-conversion] + workflow_call: permissions: contents: read jobs: @@ -12,12 +11,21 @@ jobs: - uses: actions/checkout@v7 with: persist-credentials: false + - uses: actions/cache@v5 + id: cache + with: + path: .local/conversion-tools/tools/ffmpeg + key: conversion-ffmpeg-x64-${{ runner.os }}-${{ hashFiles('scripts/build-conversion-ffmpeg.sh', 'scripts/conversion-sources.json', 'scripts/conversion-manifest.py') }} - name: Prepare cross compiler + if: steps.cache.outputs.cache-hit != 'true' run: | sudo apt-get update -qq sudo apt-get install -y --no-install-recommends gcc-mingw-w64-x86-64-posix g++-mingw-w64-x86-64-posix nasm cmake ninja-build meson pkg-config make - name: Build only the conversion engine + if: steps.cache.outputs.cache-hit != 'true' run: bash scripts/build-conversion-ffmpeg.sh + - name: Verify engine source and inventory + run: python3 scripts/conversion-manifest.py verify .local/conversion-tools/tools/ffmpeg ffmpeg scripts/build-conversion-ffmpeg.sh scripts/conversion-sources.json - uses: actions/upload-artifact@v7 with: name: conversion-ffmpeg-win-x64 @@ -31,19 +39,35 @@ jobs: .local/conversion-ffmpeg/**/*.log .local/conversion-ffmpeg/**/config.log retention-days: 7 - inspect: + office: runs-on: windows-latest timeout-minutes: 15 steps: - uses: actions/checkout@v7 with: persist-credentials: false + - uses: actions/cache@v5 + id: cache + with: + path: .local/conversion-tools/tools/libreoffice + key: conversion-office-x64-${{ runner.os }}-${{ hashFiles('scripts/prepare-conversion-office.ps1', 'scripts/stage-conversion-office.py', 'scripts/conversion-manifest.py') }} - shell: pwsh + if: steps.cache.outputs.cache-hit != 'true' run: ./scripts/prepare-conversion-office.ps1 + - name: Verify office source and inventory + shell: pwsh + run: | + python scripts/conversion-manifest.py verify .local/conversion-tools/tools/libreoffice libreoffice scripts/prepare-conversion-office.ps1 scripts/stage-conversion-office.py + if ($LASTEXITCODE -ne 0) { throw 'Prepared office component verification failed.' } + - uses: actions/upload-artifact@v7 + with: + name: conversion-office-win-x64 + path: .local/conversion-tools/tools/libreoffice/** + retention-days: 14 - uses: actions/upload-artifact@v7 if: always() with: - name: conversion-bundle-inspection + name: conversion-office-selection path: | .local/conversion-office/**/*.json .local/conversion-office/**/*.log diff --git a/Directory.Build.props b/Directory.Build.props index b4546d0..e09b77d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ enable true true - 0.9.1 + 0.9.2 YMXKNebula Windows 桌面工具集,提供放大镜、浮笺、剪贴回溯、文件集装箱、格式转换和电脑信息查看。 https://github.com/YMXKNebula/DailyToolkit diff --git a/README.md b/README.md index 309d603..a6ab77f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Windows 桌面工具集:放大镜、浮笺、剪贴回溯、文件集装箱、 剪贴回溯默认关闭,开启后持续记录剪贴板,仅在本机加密保存。复制敏感内容前请暂停记录或排除来源应用,无法自动识别所有密码。文件默认只记路径,开启缓存后可保存文件副本。 -格式转换不调用在线服务或 AI,原文件保留。文档转换需要本机 LibreOffice,WebP 和部分音视频格式需要 FFmpeg;引擎不随程序捆绑,也不会自动下载。 +格式转换组件已内置,无需另装程序,不调用在线服务或 AI。原文件保留,携带时保留完整软件目录。 > 放大镜用于带反作弊的游戏时可能导致封号,请谨慎使用。 diff --git a/THIRD_PARTY_NOTICES.txt b/THIRD_PARTY_NOTICES.txt index 21fceb7..fe7681c 100644 --- a/THIRD_PARTY_NOTICES.txt +++ b/THIRD_PARTY_NOTICES.txt @@ -10,6 +10,25 @@ https://www.7-zip.org/ https://github.com/ip7z/7zip/releases/tag/26.04 Corresponding source: https://github.com/ip7z/7zip/releases/download/26.04/7z2604-src.7z +FFmpeg 9.0.2 (custom Windows x64 conversion build, separate process) +Copyright (c) the FFmpeg developers and codec library contributors. +GPL-2.0-or-later; x264 GPL, LAME LGPL, and BSD/Zlib codec libraries. +Only the exposed conversion targets are included; no player, ffprobe, network +protocols, capture devices or neural/AI processing is built. +License: tools/ffmpeg/LICENSE.txt and tools/ffmpeg/licenses/. +Complete pinned source archives and build recipe: tools/ffmpeg/sources/. +https://ffmpeg.org/ +https://github.com/FFmpeg/FFmpeg/commit/946fcce07b6dcd0331c8cc609192aeff5e1924f8 + +LibreOffice 26.2.6.3 (selected unmodified local conversion runtime) +Copyright (c) The Document Foundation and contributors. +MPL-2.0 and third-party licenses; includes the app-local Microsoft Visual C++ CRT. +No LibreOffice installation, updater, shell integration, Java/Python runtime, +dictionaries, help package or independent office entry points are installed. +Original notices: tools/libreoffice/license.txt, LICENSE.html and NOTICE. +Exact upstream binary, source access and runtime terms: tools/libreoffice/SOURCE.txt. +https://www.libreoffice.org/licenses/ + The application packages include the following components under the MIT License: AMD FidelityFX Contrast Adaptive Sharpening (adapted CAS filter weights) diff --git a/docs/FORMAT_CONVERSION.md b/docs/FORMAT_CONVERSION.md index 7f6429c..ddb22b2 100644 --- a/docs/FORMAT_CONVERSION.md +++ b/docs/FORMAT_CONVERSION.md @@ -6,26 +6,24 @@ 在左侧启用“格式转换”,选择类型和输出格式,添加或拖入文件,选择保存位置后开始。每批最多 100 个文件,依次转换;原文件只读,同名输出自动更名。失败或取消的项目可以再次点击“开始转换”重试,已经完成的项目不重复执行。 -文件清单保留在本次运行中,重启后不恢复转换历史;输出位置、格式和本地引擎设置可以保存。 +文件清单保留在本次运行中,重启后不恢复转换历史;输出位置、格式和画质可以保存。 关闭或收起主窗口不打断已经提交的转换。停用功能会取消本批剩余任务,等待本次转换释放文件、流、编解码对象和自有进程;已经完成的结果保留。退出软件沿用现有任务确认与保存保护流程。 -## 格式与本地依赖 +## 支持格式 | 类型 | 输入 | 输出与说明 | | --- | --- | --- | | 图片 | PNG、JPG/JPEG、BMP、TIFF、静态 GIF | PNG、JPG、BMP、TIFF、PDF;使用 Windows 图片组件 | -| WebP | 静态 WebP,以及上述图片 | WebP 与其他图片格式互转,需要本地 FFmpeg | +| WebP | 静态 WebP,以及上述图片 | WebP 与其他图片格式互转 | | PDF | PDF | 每页输出 PNG 或 JPG,可选 72–300 DPI;使用 Windows PDF 组件 | -| 音频 | MP3、M4A、AAC、WAV、FLAC、OGG、WMA、Opus 及受支持视频中的音轨 | MP3、M4A、WAV 可使用 Windows 编解码器;FLAC、OGG 需要 FFmpeg | -| 视频 | MP4、M4V、MKV、MOV、AVI、WebM、WMV、MPEG | MP4、WMV 可使用 Windows 编解码器;MKV、WebM 需要 FFmpeg。实际输入支持取决于系统或所选引擎的解码器 | -| 文字 | DOCX、ODT、TXT | PDF、DOCX、ODT、TXT,需要 LibreOffice | -| 表格 | XLSX、ODS、CSV | PDF、XLSX、ODS、CSV,需要 LibreOffice;CSV 是单表文本格式,不保留多表、公式和样式 | -| 演示文稿 | PPTX、ODP | PDF、PPTX、ODP,需要 LibreOffice | +| 音频 | MP3、M4A、AAC、WAV、FLAC、OGG、WMA、Opus 及受支持视频中的音轨 | MP3、M4A、WAV、FLAC、OGG | +| 视频 | MP4、M4V、MKV、MOV、AVI、WebM、WMV、MPEG | MP4、WMV、MKV、WebM;支持常见 H.264、HEVC、AV1、VP8/VP9 等编码 | +| 文字 | DOCX、ODT、TXT | PDF、DOCX、ODT、TXT | +| 表格 | XLSX、ODS、CSV | PDF、XLSX、ODS、CSV;CSV 是单表文本格式,不保留多表、公式和样式 | +| 演示文稿 | PPTX、ODP | PDF、PPTX、ODP | -Windows N 等缺少媒体组件的系统,以及系统无法解码的输入,可以选择本地 FFmpeg。FFmpeg 构建需要包含所选编码器,例如 MP4 使用 libx264、WebP 使用 libwebp、WebM 使用 libvpx-vp9/libopus。配置 FFmpeg 后,音视频统一使用该引擎。 - -“本地引擎”只选择本机已有的 `ffmpeg.exe`、LibreOffice `program/soffice.exe` 或 `soffice.com`,不下载、安装或自动更新引擎。当前程序没有捆绑这两项依赖;准备好本地引擎后,转换过程不需要互联网。参考 [FFmpeg 官方下载说明](https://ffmpeg.org/download.html)和 [LibreOffice 官方下载](https://www.libreoffice.org/download/download-libreoffice/)。 +转换组件随软件提供,无需另装 FFmpeg、LibreOffice、.NET 或 Java。保留完整软件目录即可携带,转换时不下载程序、模型或插件。内置组件的许可和源码说明位于 `tools/`。 ## 结果与限制 @@ -33,10 +31,10 @@ Windows N 等缺少媒体组件的系统,以及系统无法解码的输入, - 尊重常见 EXIF 方向。多页 TIFF 转图片会逐页输出,转 TIFF/PDF 保留页序;动态图明确拒绝,不静默丢帧。 - 图片 PDF 每个输入文件生成一个 PDF,多页 TIFF 生成多页 PDF;不是 OCR,不提取或重建文字。PDF 转图片也不等于 PDF 转 Word。 - 单张图片或 PDF 页面最多 4000 万像素,图片输入不超过 512 MB,最多 500 页;多页 TIFF 输出总计最多 8000 万像素。 -- 音视频保留一个主要视频轨和一个主要音轨,不保留字幕、附件及全部原始元数据。系统转换保持源视频尺寸和帧率;不同编码器、色彩空间和 HDR 的效果仍需按实际素材检查。 +- 音视频保留一个主要视频轨和一个主要音轨,不保留字幕、附件及全部原始元数据。转换保持源视频尺寸和帧率,奇数宽高补到偶数;不同编码器、色彩空间和 HDR 的效果仍需按实际素材检查。 - Office 转换使用 LibreOffice 的格式实现,字体、复杂排版、公式和动画可能变化,不能承诺与 Microsoft Office 完全一致。旧二进制 DOC/XLS/PPT、受密码保护文件及 PDF 转可编辑 Office 文档不在本次范围。 - Office 使用本任务独立的配置和输入副本,禁用宏与更新检查,不接入已有用户窗口。带宏、需读取外部内容或外部数据公式的文档明确拒绝;普通网页超链接可以保留。 -- 输入、输出和引擎路径必须是本机磁盘路径;不接受 URL、UNC 或映射网络盘。不是任意第三方程序的网络沙箱,应选择可信的本地引擎。 +- 输入、输出必须是本机磁盘路径;不接受 URL、UNC 或映射网络盘。 ## 实现与检查 @@ -44,7 +42,7 @@ Windows N 等缺少媒体组件的系统,以及系统无法解码的输入, 每个输入使用输出目录内的独立临时目录,完成并校验后提交,拒绝覆盖;同一输入的多页结果在发布前统一校验,失败回滚本次已提交结果。FFmpeg 结果在提交前完整解码验证。LibreOffice 的独立配置放在较短的系统临时目录,避免 Windows 下的深层缓存路径问题,用完后清理。 -系统音视频转换在本程序按任务启动的独立进程内执行,完成后退出,释放编解码对象持有的文件句柄。外部引擎和系统转换进程均使用独立 Windows Job,取消只终止本次进程树;没有全局轮询或常驻转换进程。不依赖强制回收整个应用的托管堆来解锁文件。 +正式软件的音视频由内置 FFmpeg 处理。保留的系统编解码回归夹具在本程序按任务启动的独立进程内执行,完成后退出,释放编解码对象持有的文件句柄。外部引擎和系统转换进程均使用独立 Windows Job,取消只终止本次进程树;没有全局轮询或常驻转换进程。不依赖强制回收整个应用的托管堆来解锁文件。 引擎标准输出和错误输出由本次任务的专用线程读取,避免同步管道等待占用共享线程池;进程结束、管道关闭后,读取线程随任务退出。 @@ -58,6 +56,6 @@ Windows 隔离验收入口: DailyToolkit.Desktop.Tests.exe --clipboard-native-conversion-checks <图片输出目录> ``` -已接入 `scripts/check-quality.ps1 -IsolatedCi`,覆盖图片透明度、TIFF 多页、图片/PDF 往返、动态图拒绝、原件保护、停用取消、失败保存,以及深浅主题、宽窄页面和 100/150/200% DPI 渲染。CI 准备经过摘要校验的本地测试引擎,实际检查文字、表格、演示文稿往返及 PDF 渲染;引擎不进入软件载荷。系统音视频检查包含 MP3/M4A/WAV、MP4/WMV、尺寸与帧率保留、进程取消和文件独占重开。渲染检查不代替实际屏幕与混合 DPI 验收。 +已接入 `scripts/check-quality.ps1 -IsolatedCi`,覆盖图片透明度、TIFF 多页、图片/PDF 往返、动态图拒绝、原件保护、停用取消、失败保存,以及深浅主题、宽窄页面和 100/150/200% DPI 渲染。CI 从固定版本源码构建 FFmpeg,从校验摘要的官方包提取 LibreOffice,实际检查文字、表格、演示文稿往返及 PDF 渲染。另用实际便携目录与安装目录检查内置组件,阻止测试程序出站联网并清除 PATH 中的外部程序目录。系统音视频检查包含 MP3/M4A/WAV、MP4/WMV、尺寸与帧率保留、进程取消和文件独占重开。渲染检查不代替实际屏幕与混合 DPI 验收。 Linux 可进行 Core 检查、配置引擎的实际转换与 Windows 交叉编译;这些结果不能表述为已完成 Windows 桌面、系统编解码、真实拖放、用户数据、安装或本机内存验收。每次实际执行结果以本次日志为准。 diff --git a/docs/INSTALLER_README.txt b/docs/INSTALLER_README.txt index 91b10c4..615c031 100644 --- a/docs/INSTALLER_README.txt +++ b/docs/INSTALLER_README.txt @@ -25,7 +25,7 @@ Windows x64,已在 Windows 11 测试,Windows 10 尚未完整验证。 关闭窗口不停止已提交任务;关闭功能会停止任务,保留记录供重新开始。 清理工作区会删除其中全部文件,请先移出要保留的内容。 格式转换支持图片、PDF、音视频和文档,本地处理,不使用在线服务或 AI。 -文档需要本机 LibreOffice;WebP 和部分音视频格式需要 FFmpeg,不自动下载引擎。 +转换组件已内置,无需另装程序,可离线使用。携带时保留完整软件目录。 原文件保留,同名输出自动更名;停用功能会取消本批剩余任务。 配色预设点击即保存,自定义颜色保存后应用。 diff --git a/docs/PORTABLE_README.txt b/docs/PORTABLE_README.txt index 6c7876f..382b617 100644 --- a/docs/PORTABLE_README.txt +++ b/docs/PORTABLE_README.txt @@ -25,7 +25,7 @@ DailyToolkit 外部工作区清理会删除其中全部文件,请先移出要保留的内容。 格式转换支持图片、PDF、音视频和文档,本地处理,不使用在线服务或 AI。 -文档需要本机 LibreOffice;WebP 和部分音视频格式需要 FFmpeg,不自动下载引擎。 +转换组件已内置,无需另装程序,可离线使用。携带时保留完整软件目录。 原文件保留,同名输出自动更名;停用功能会取消本批剩余任务。 配色预设点击即保存,自定义颜色保存后应用。 diff --git a/installer/DailyToolkit.iss b/installer/DailyToolkit.iss index 8327043..a71523a 100644 --- a/installer/DailyToolkit.iss +++ b/installer/DailyToolkit.iss @@ -75,6 +75,8 @@ Source: "{#PayloadDir}\tools\7zip\Readme.txt"; DestDir: "{app}\tools\7zip"; Flag Source: "{#PayloadDir}\tools\7zip\SOURCE.txt"; DestDir: "{app}\tools\7zip"; Flags: ignoreversion Source: "{#PayloadDir}\tools\7zip\COPYING.txt"; DestDir: "{app}\tools\7zip"; Flags: ignoreversion Source: "{#PayloadDir}\tools\7zip\7z2604-src.7z"; DestDir: "{app}\tools\7zip"; Flags: ignoreversion +Source: "{#PayloadDir}\tools\ffmpeg\*"; DestDir: "{app}\tools\ffmpeg"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "{#PayloadDir}\tools\libreoffice\*"; DestDir: "{app}\tools\libreoffice"; Flags: ignoreversion recursesubdirs createallsubdirs Source: "..\docs\INSTALLER_README.txt"; DestDir: "{app}"; DestName: "README.txt"; Flags: ignoreversion [Icons] diff --git a/scripts/build-conversion-ffmpeg.sh b/scripts/build-conversion-ffmpeg.sh index b4e5198..80cc2ed 100644 --- a/scripts/build-conversion-ffmpeg.sh +++ b/scripts/build-conversion-ffmpeg.sh @@ -122,7 +122,7 @@ run dav1d-install meson install -C "$build/dav1d-build" --enable-ffmpeg --disable-ffplay --disable-ffprobe \ --enable-zlib --enable-libx264 --enable-libmp3lame --enable-libvorbis --enable-libopus --enable-libvpx --enable-libwebp --enable-libdav1d \ --enable-protocol=file,pipe --enable-decoder="$decoders" \ - --enable-encoder=libmp3lame,aac,pcm_s16le,flac,libvorbis,libvpx_vp9,libopus,libx264,wmv2,wmav2,png,libwebp,ffv1 \ + --enable-encoder=libmp3lame,aac,pcm_s16le,flac,libvorbis,libvpx_vp9,libopus,libx264,wmv2,wmav2,png,libwebp,ffv1,wrapped_avframe \ --enable-demuxer=aac,mov,matroska,avi,asf,mpegps,mpegts,mp3,wav,flac,ogg,image2,image2pipe,png_pipe,webp_pipe,jpeg_pipe,bmp_pipe,tiff_pipe,gif,rawvideo \ --enable-muxer=image2,image2pipe,mp3,ipod,wav,flac,ogg,mp4,asf,matroska,webm,null \ --enable-parser=aac,ac3,flac,h264,hevc,mjpeg,mpeg4video,mpegaudio,mpegvideo,opus,vorbis,vp8,vp9,av1,png \ diff --git a/scripts/conversion-payload.ps1 b/scripts/conversion-payload.ps1 new file mode 100644 index 0000000..d2925da --- /dev/null +++ b/scripts/conversion-payload.ps1 @@ -0,0 +1,27 @@ +# Dot-source from publish/package/test scripts. No downloads or system changes. +function Get-ConversionPayloadFiles([string]$Directory) { + $result = [Collections.Generic.List[string]]::new() + foreach ($engine in @('ffmpeg','libreoffice')) { + $prefix = "tools/$engine/" + $base = Join-Path $Directory $prefix + $manifest = Join-Path $base 'bundle.json' + if (-not (Test-Path -LiteralPath $manifest)) { throw "Missing prepared $engine inventory." } + $spec = Get-Content -LiteralPath $manifest -Raw | ConvertFrom-Json + if ($spec.schema -ne 1 -or $spec.component -ne $engine -or $spec.files.Count -lt 3) { throw "Invalid $engine inventory." } + foreach ($entry in $spec.files) { + if ($entry.path -notmatch '^[A-Za-z0-9_\-/ .+]+$' -or $entry.path.StartsWith('/') -or + @($entry.path.Split('/') | Where-Object { $_ -in @('','.', '..') }).Count -or + $entry.sha256 -notmatch '^[a-f0-9]{64}$') { throw 'Invalid component inventory entry.' } + $file = Join-Path $base $entry.path + $item = Get-Item -LiteralPath $file -Force + if ($item.PSIsContainer -or $item.Attributes.HasFlag([IO.FileAttributes]::ReparsePoint) -or + $item.Length -ne $entry.bytes -or (Get-FileHash -LiteralPath $file).Hash.ToLowerInvariant() -ne $entry.sha256) { + throw "Component inventory mismatch: $($entry.path)" + } + $result.Add(($prefix + $entry.path).Replace('/', '\')) + } + $result.Add(($prefix + 'bundle.json').Replace('/', '\')) + } + if (@($result | Sort-Object -Unique).Count -ne $result.Count) { throw 'Duplicate component inventory paths.' } + $result.ToArray() +} diff --git a/scripts/inspect-conversion-bundle.ps1 b/scripts/inspect-conversion-bundle.ps1 deleted file mode 100644 index 5475bb2..0000000 --- a/scripts/inspect-conversion-bundle.ps1 +++ /dev/null @@ -1,39 +0,0 @@ -$ErrorActionPreference = 'Stop' -if ($env:CI -ne 'true' -or -not $IsWindows) { throw 'Disposable Windows CI only.' } -$root = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) -$evidence = Join-Path $root '.local/conversion-bundle-inspection' -New-Item -ItemType Directory -Path $evidence -Force | Out-Null -$version = '26.2.6' -$url = "https://download.documentfoundation.org/libreoffice/stable/$version/win/x86_64/LibreOffice_${version}_Win_x86-64.msi" -[xml]$meta = (Invoke-WebRequest ($url + '.meta4') -TimeoutSec 60).Content -$hash = @($meta.metalink.file.hash | Where-Object type -eq 'sha-256')[0].InnerText.ToLowerInvariant() -if ($hash -notmatch '^[a-f0-9]{64}$') { throw 'Missing official SHA-256.' } -Write-Host "Official LibreOffice MSI SHA-256: $hash" -$msi = Join-Path $env:RUNNER_TEMP 'DailyToolkit-LibreOffice.msi' -$downloaded = $false -foreach ($mirror in @($meta.metalink.file.url | Where-Object { $_.InnerText.StartsWith('https://') } | Sort-Object { [int]$_.priority } | Select-Object -First 4)) { - & curl.exe --fail --silent --show-error --location --connect-timeout 15 --max-time 90 --output $msi $mirror.InnerText - if ($LASTEXITCODE -eq 0 -and (Get-FileHash $msi).Hash.ToLowerInvariant() -eq $hash) { $downloaded = $true; break } -} -if (-not $downloaded) { throw 'Official download failed.' } -$extract = Join-Path $env:RUNNER_TEMP 'DailyToolkit-LibreOffice-admin' -$log = Join-Path $evidence 'extract.log' -$p = Start-Process msiexec.exe -ArgumentList @('/a', ('"' + $msi + '"'), '/qn', '/norestart', ('TARGETDIR="' + $extract + '"'), '/L*v', ('"' + $log + '"')) -PassThru -if (-not $p.WaitForExit(240000)) { throw 'Administrative extraction timed out.' } -if ($p.ExitCode -notin @(0,3010)) { throw "Administrative extraction failed: $($p.ExitCode)" } -$office = @(Get-ChildItem $extract -Recurse -File -Filter soffice.com) -if ($office.Count -ne 1) { throw 'Expected one extracted LibreOffice console entry.' } -$install = $office[0].Directory.Parent.FullName -$files = @(Get-ChildItem $install -Recurse -File | ForEach-Object { - @{ path = [IO.Path]::GetRelativePath($install,$_.FullName).Replace('\','/'); bytes = $_.Length } -}) -@{ version=$version; sha256=$hash; files=$files } | ConvertTo-Json -Depth 5 | Set-Content (Join-Path $evidence 'files.json') -$files | Group-Object { ($_.path -split '/')[0..([Math]::Min(1,($_.path -split '/').Length-1))] -join '/' } | ForEach-Object { - [pscustomobject]@{ directory=$_.Name; files=$_.Count; bytes=($_.Group | Measure-Object bytes -Sum).Sum } -} | Sort-Object bytes -Descending | Select-Object -First 60 | Format-Table -AutoSize | Out-String -Width 180 | Write-Host -Write-Host 'PROGRAM FILES' -$files | Where-Object path -Like 'program/*' | ForEach-Object { Write-Host "$($_.path) $($_.bytes)" } -Write-Host 'ROOT FILES' -$files | Where-Object { $_.path -notlike '*/*' } | ForEach-Object { Write-Host "$($_.path) $($_.bytes)" } -& $office[0].FullName --version -if ($LASTEXITCODE -ne 0) { throw 'Extracted LibreOffice could not start.' } diff --git a/scripts/package-installer.ps1 b/scripts/package-installer.ps1 index 47eb682..a63542b 100644 --- a/scripts/package-installer.ps1 +++ b/scripts/package-installer.ps1 @@ -6,6 +6,7 @@ $version = [string]$properties.Project.PropertyGroup.Version if ($version -notmatch '^\d+\.\d+\.\d+$') { throw 'The Windows installer requires a three-part release version.' } if (-not $PayloadDirectory) { $PayloadDirectory = Join-Path $projectRoot "artifacts\DailyToolkit-$version-win-x64" } $PayloadDirectory = [IO.Path]::GetFullPath($PayloadDirectory) +. (Join-Path $PSScriptRoot 'conversion-payload.ps1') $executable = Join-Path $PayloadDirectory 'DailyToolkit.exe' if (-not (Test-Path -LiteralPath $executable)) { throw 'Run scripts/publish.ps1 before packaging the installer.' } if ((Get-Item -LiteralPath $executable).VersionInfo.ProductVersion -notmatch ('^' + [regex]::Escape($version) + '(?:\+|$)')) { @@ -16,6 +17,7 @@ $expected = @('DailyToolkit.exe','LICENSE-DailyToolkit.txt','README.txt','THIRD_ 'microsoft.windowsdesktop.app.runtime-LICENSE','licenses\Windows-SDK-License.rtf', 'tools\7zip\7za.exe','tools\7zip\License.txt','tools\7zip\Readme.txt','tools\7zip\SOURCE.txt', 'tools\7zip\COPYING.txt','tools\7zip\7z2604-src.7z') +$expected += @(Get-ConversionPayloadFiles $PayloadDirectory) $actual = @(Get-ChildItem -LiteralPath $PayloadDirectory -Recurse -File | ForEach-Object { [IO.Path]::GetRelativePath($PayloadDirectory, $_.FullName) }) @@ -32,6 +34,15 @@ try { try { $zipExeHash = [Convert]::ToHexString($sha.ComputeHash($stream)) } finally { $sha.Dispose(); $stream.Dispose() } if ($zipExeHash -ne (Get-FileHash -LiteralPath $executable).Hash) { throw 'The ZIP and installer payload must contain the exact same application.' } + foreach ($relative in $expected | Where-Object { $_.StartsWith('tools\ffmpeg\') -or $_.StartsWith('tools\libreoffice\') }) { + $entry = $archive.GetEntry($relative.Replace('\','/')) + if (-not $entry) { $entry = $archive.GetEntry($relative) } + if (-not $entry) { throw "Missing portable component: $relative" } + $input = $entry.Open(); $algorithm = [Security.Cryptography.SHA256]::Create() + try { $checksum = [Convert]::ToHexString($algorithm.ComputeHash($input)) } + finally { $algorithm.Dispose(); $input.Dispose() } + if ($checksum -ne (Get-FileHash -LiteralPath (Join-Path $PayloadDirectory $relative)).Hash) { throw "ZIP component differs from installer: $relative" } + } } finally { $archive.Dispose() } if (-not $Compiler) { $Compiler = Join-Path $projectRoot '.local\inno-setup\7.1.0\ISCC.exe' diff --git a/scripts/prepare-conversion-checks.ps1 b/scripts/prepare-conversion-checks.ps1 index 6ec8e38..dfefe08 100644 --- a/scripts/prepare-conversion-checks.ps1 +++ b/scripts/prepare-conversion-checks.ps1 @@ -1,44 +1,17 @@ -# Disposable Windows CI only. These engines are test dependencies, not payload. +# Disposable Windows CI. Use precisely the prepared portable engines; no installs. $ErrorActionPreference = 'Stop' -$PSNativeCommandUseErrorActionPreference = $false -if ($env:CI -ne 'true' -or -not $IsWindows) { throw 'Conversion engine preparation requires disposable Windows CI.' } -$ffmpeg = Get-Command ffmpeg.exe -ErrorAction SilentlyContinue -if (-not $ffmpeg) { - choco install ffmpeg --version=9.0.2 --yes --no-progress --limit-output - if ($LASTEXITCODE -ne 0) { throw 'FFmpeg test dependency installation failed.' } - $ffmpeg = Get-Command ffmpeg.exe -ErrorAction Stop -} -$office = Join-Path $env:ProgramFiles 'LibreOffice/program/soffice.com' -if (-not (Test-Path -LiteralPath $office)) { - $version = '26.2.6' - $url = "https://download.documentfoundation.org/libreoffice/stable/$version/win/x86_64/LibreOffice_${version}_Win_x86-64.msi" - $evidence = Join-Path $PSScriptRoot '../.local/conversion-test-engines' - New-Item -ItemType Directory -Path $evidence -Force | Out-Null - [xml]$metalink = (Invoke-WebRequest -Uri ($url + '.meta4') -TimeoutSec 60).Content - $entry = $metalink.metalink.file - $hash = @($entry.hash | Where-Object type -eq 'sha-256')[0].InnerText.ToLowerInvariant() - if ($hash -notmatch '^[a-f0-9]{64}$') { throw 'Official LibreOffice SHA-256 metadata was not found.' } - $urls = @($entry.url | Where-Object { $_.InnerText.StartsWith('https://') } | Sort-Object { [int]$_.priority } | Select-Object -First 4) - if ($urls.Count -eq 0) { throw 'Official HTTPS mirrors were not found.' } - $msi = Join-Path $env:RUNNER_TEMP "LibreOffice-$version.msi" - $downloaded = $false - foreach ($mirror in $urls) { - Write-Host ('Trying official LibreOffice mirror: ' + ([uri]$mirror.InnerText).Host) - & curl.exe --silent --show-error --fail --location --connect-timeout 15 --max-time 90 --output $msi $mirror.InnerText - if ($LASTEXITCODE -eq 0 -and (Get-FileHash -LiteralPath $msi -Algorithm SHA256).Hash.ToLowerInvariant() -eq $hash) { - $downloaded = $true; break - } - } - if (-not $downloaded) { throw 'No official mirror supplied the checksum-verified LibreOffice installer within its time limit.' } - @{ version = $version; sha256 = $hash; mirror = $mirror.InnerText } | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $evidence 'libreoffice-download.json') -Encoding utf8 - $log = Join-Path ([IO.Path]::GetFullPath($evidence)) 'libreoffice-install.log' - $install = Start-Process msiexec.exe -ArgumentList @('/i', $msi, '/qn', '/norestart', '/L*v', $log) -PassThru - if (-not $install.WaitForExit(240000)) { Stop-Process -Id $install.Id; throw 'The disposable CI LibreOffice install exceeded four minutes.' } - if ($install.ExitCode -notin @(0, 3010)) { throw "LibreOffice test dependency installation failed: $($install.ExitCode)." } -} -if (-not (Test-Path -LiteralPath $office)) { throw 'LibreOffice console entry was not found.' } -"DAILYTOOLKIT_TEST_FFMPEG=$($ffmpeg.Source)" | Out-File -LiteralPath $env:GITHUB_ENV -Append -Encoding utf8 +if ($env:CI -ne 'true' -or -not $IsWindows) { throw 'Conversion engine checks require disposable Windows CI.' } +$root = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) +$bundle = Join-Path $root '.local/conversion-tools' +. (Join-Path $PSScriptRoot 'conversion-payload.ps1') +$files = @(Get-ConversionPayloadFiles $bundle) +$ffmpeg = Join-Path $bundle 'tools/ffmpeg/ffmpeg.exe' +$office = Join-Path $bundle 'tools/libreoffice/program/soffice.com' +"DAILYTOOLKIT_TEST_FFMPEG=$ffmpeg" | Out-File -LiteralPath $env:GITHUB_ENV -Append -Encoding utf8 "DAILYTOOLKIT_TEST_LIBREOFFICE=$office" | Out-File -LiteralPath $env:GITHUB_ENV -Append -Encoding utf8 -& $ffmpeg.Source -version | Select-Object -First 1 -& $office --version -Get-FileHash -LiteralPath $ffmpeg.Source, $office -Algorithm SHA256 | Format-Table -AutoSize +& $ffmpeg -version | Select-Object -First 1 +if ($LASTEXITCODE -ne 0) { throw 'Bundled FFmpeg could not start.' } +$protocols = (& $ffmpeg -hide_banner -protocols 2>&1 | Out-String) +if ($LASTEXITCODE -ne 0 -or $protocols -match '(?m)^\s+(https?|ftp|tcp|udp|tls|crypto)\s*$') { throw 'The converter must not contain network protocols.' } +Write-Host $protocols +Write-Host "Verified $($files.Count) prepared conversion component files; no program was installed." diff --git a/scripts/prepare-conversion-office.ps1 b/scripts/prepare-conversion-office.ps1 index d019719..bc71069 100644 --- a/scripts/prepare-conversion-office.ps1 +++ b/scripts/prepare-conversion-office.ps1 @@ -40,6 +40,15 @@ $metrics | Set-Content -LiteralPath (Join-Path $work 'selection.json') -Encoding $summary = $metrics | ConvertFrom-Json Write-Host ("Office: selected {0:N1} MiB / {1:N1} MiB; {2} files; {3} checked binaries" -f ($summary.selectedBytes/1MB),($summary.upstreamBytes/1MB),$summary.selectedFiles,$summary.checkedBinaries) Write-Host ('App-local CRT: ' + ($summary.microsoftRuntime -join ', ')) +$fontRevision = '523d033d6cb47f4a80c58a35753646f5c3608a78' +$fontDirectory = Join-Path $OutputDirectory 'share/fonts/truetype' +New-Item -ItemType Directory -Path $fontDirectory -Force | Out-Null +$font = Join-Path $fontDirectory 'NotoSansCJKsc-Regular.otf' +& curl.exe --fail --silent --show-error --location --connect-timeout 15 --max-time 90 --output $font "https://raw.githubusercontent.com/notofonts/noto-cjk/$fontRevision/Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Regular.otf" +if ($LASTEXITCODE -ne 0 -or (Get-FileHash -LiteralPath $font).Hash.ToLowerInvariant() -ne '2c76254f6fc379fddfce0a7e84fb5385bb135d3e399294f6eeb6680d0365b74b') { throw 'Bundled Chinese font checksum mismatch.' } +$fontLicense = Join-Path $OutputDirectory 'LICENSE-NotoSansCJK.txt' +& curl.exe --fail --silent --show-error --location --connect-timeout 15 --max-time 60 --output $fontLicense "https://raw.githubusercontent.com/notofonts/noto-cjk/$fontRevision/LICENSE" +if ($LASTEXITCODE -ne 0 -or (Get-FileHash -LiteralPath $fontLicense).Hash.ToLowerInvariant() -ne '6a73f9541c2de74158c0e7cf6b0a58ef774f5a780bf191f2d7ec9cc53efe2bf2') { throw 'Bundled Chinese font license checksum mismatch.' } @" LibreOffice 26.2.6.3, The Document Foundation and contributors. Unmodified upstream runtime files selected for Writer, Calc and Impress conversion. @@ -54,6 +63,9 @@ This selection does not change upstream binaries. Selection recipe: scripts/stag Microsoft Visual C++ CRT files are included app-local; no runtime installer or system registration is used. Copyright (C) Microsoft Corporation. All rights reserved. Runtime terms: https://visualstudio.microsoft.com/license-terms/vs2022-cruntime/ +Noto Sans CJK SC 2.004 is included as a private document font, with no system font registration. +Copyright 2014-2021 Adobe and Noto contributors; SIL Open Font License 1.1 in LICENSE-NotoSansCJK.txt. +Font source: https://github.com/notofonts/noto-cjk/tree/$fontRevision "@ | Set-Content -LiteralPath (Join-Path $OutputDirectory 'SOURCE.txt') -Encoding utf8 $profile = Join-Path $work 'probe-profile' $input = Join-Path $work '离线检查.txt' diff --git a/scripts/publish.ps1 b/scripts/publish.ps1 index 88e7bc9..9077044 100644 --- a/scripts/publish.ps1 +++ b/scripts/publish.ps1 @@ -4,6 +4,16 @@ $projectRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) $dotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue $dotnetPath = if ($dotnetCommand) { $dotnetCommand.Source } else { Join-Path $env:ProgramFiles 'dotnet\dotnet.exe' } if (-not (Test-Path -LiteralPath $dotnetPath)) { throw 'Install the .NET 10 SDK before publishing.' } +if ($Runtime -ne 'win-x64') { throw 'The offline conversion payload is validated for Windows x64 only.' } +. (Join-Path $PSScriptRoot 'conversion-payload.ps1') +$conversionDirectory = Join-Path $projectRoot '.local/conversion-tools' +foreach ($engine in @('ffmpeg','libreoffice')) { + $recipes = if ($engine -eq 'ffmpeg') { @('build-conversion-ffmpeg.sh','conversion-sources.json') } else { @('prepare-conversion-office.ps1','stage-conversion-office.py') } + $recipePaths = @($recipes | ForEach-Object { Join-Path $PSScriptRoot $_ }) + & python (Join-Path $PSScriptRoot 'conversion-manifest.py') verify (Join-Path $conversionDirectory "tools/$engine") $engine @recipePaths + if ($LASTEXITCODE -ne 0) { throw "Prepare the matching $engine bundle before publishing." } +} +$conversionFiles = @(Get-ConversionPayloadFiles $conversionDirectory) $env:DOTNET_CLI_HOME = Join-Path $projectRoot '.local\dotnet' $env:NUGET_PACKAGES = Join-Path $projectRoot '.local\nuget' $env:DOTNET_CLI_TELEMETRY_OPTOUT = '1' @@ -20,6 +30,11 @@ Push-Location -LiteralPath $projectRoot try { & $dotnetPath publish src/DailyToolkit.Desktop/DailyToolkit.Desktop.csproj -c Release -r $Runtime --self-contained true --disable-build-servers -m:1 --nologo -o $outputDirectory -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=None -p:DebugSymbols=false @versionArguments if ($LASTEXITCODE -ne 0) { throw 'Publish failed.' } + foreach ($relative in $conversionFiles) { + $destination = Join-Path $outputDirectory $relative + New-Item -ItemType Directory -Path ([IO.Path]::GetDirectoryName($destination)) -Force | Out-Null + Copy-Item -LiteralPath (Join-Path $conversionDirectory $relative) -Destination $destination + } Copy-Item -LiteralPath (Join-Path $projectRoot 'LICENSE') -Destination (Join-Path $outputDirectory 'LICENSE-DailyToolkit.txt') Copy-Item -LiteralPath (Join-Path $projectRoot 'docs\PORTABLE_README.txt') -Destination (Join-Path $outputDirectory 'README.txt') Copy-Item -LiteralPath (Join-Path $projectRoot 'THIRD_PARTY_NOTICES.txt') -Destination (Join-Path $outputDirectory 'THIRD_PARTY_NOTICES.txt') diff --git a/scripts/stage-conversion-office.py b/scripts/stage-conversion-office.py index 32b8815..47d9170 100644 --- a/scripts/stage-conversion-office.py +++ b/scripts/stage-conversion-office.py @@ -81,7 +81,7 @@ def stage(source, target, crt): chosen.add(rel) elif rel.startswith(('share/registry/res/en-US/', 'share/registry/res/zh-CN/')): chosen.add(rel) - elif rel.startswith('Fonts/') or p.name in ('license.txt', 'LICENSE.html', 'NOTICE', 'CREDITS.fodt'): + elif rel.startswith('Fonts/') or (p.parent.as_posix() == '.' and p.name in ('license.txt', 'LICENSE.html', 'NOTICE', 'CREDITS.fodt')): chosen.add(rel) for required in ('program/soffice.com', 'program/soffice.bin', 'program/mergedlo.dll', 'license.txt', 'NOTICE'): if required not in chosen: @@ -93,7 +93,7 @@ def stage(source, target, crt): crt_files = {p.name.lower(): p for p in crt.glob('*.dll')} additional = {} checked = set() - system = set('advapi32 avrt bcrypt cabinet cfgmgr32 comctl32 comdlg32 combase credui crypt32 cryptbase cryptsp d2d1 d3d11 d3d12 d3d9 d3dcompiler_47 dcomp dhcpcsvc dnsapi dsound dwmapi dwrite dxgi dxva2 faultrep fontsub gdi32 gdiplus glu32 hid imagehlp imm32 iphlpapi kernel32 kernelbase mpr mprapi msimg32 msvcrt mswsock msxml6 ncrypt netapi32 ntdll ole32 oleacc oleaut32 opengl32 powrprof profapi propsys psapi rasapi32 rpcrt4 secur32 setupapi shcore shell32 shlwapi sspicli ucrtbase urlmon user32 userenv usp10 uxtheme version winhttp wininet winmm winscard winspool.drv wintrust wlanapi wldap32 ws2_32 wtsapi32'.split()) + system = set('activeds dbghelp httpapi mfplat mfplay mfreadwrite oledlg wer wsock32 advapi32 avrt bcrypt cabinet cfgmgr32 comctl32 comdlg32 combase credui crypt32 cryptbase cryptsp d2d1 d3d11 d3d12 d3d9 d3dcompiler_47 dcomp dhcpcsvc dnsapi dsound dwmapi dwrite dxgi dxva2 faultrep fontsub gdi32 gdiplus glu32 hid imagehlp imm32 iphlpapi kernel32 kernelbase mpr mprapi msimg32 msvcrt mswsock msxml6 ncrypt netapi32 ntdll ole32 oleacc oleaut32 opengl32 powrprof profapi propsys psapi rasapi32 rpcrt4 secur32 setupapi shcore shell32 shlwapi sspicli ucrtbase urlmon user32 userenv usp10 uxtheme version winhttp wininet winmm winscard winspool.drv wintrust wlanapi wldap32 ws2_32 wtsapi32'.split()) system = {x if '.' in x else x + '.dll' for x in system} missing = set() while True: diff --git a/scripts/test-conversion-bundle.ps1 b/scripts/test-conversion-bundle.ps1 new file mode 100644 index 0000000..ecb17f9 --- /dev/null +++ b/scripts/test-conversion-bundle.ps1 @@ -0,0 +1,33 @@ +param([Parameter(Mandatory)][string]$PayloadDirectory) +$ErrorActionPreference = 'Stop' +if (-not $IsWindows -or $env:CI -ne 'true') { throw 'Network isolation checks run only in disposable Windows CI.' } +$root = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) +$PayloadDirectory = [IO.Path]::GetFullPath($PayloadDirectory) +. (Join-Path $PSScriptRoot 'conversion-payload.ps1') +$files = @(Get-ConversionPayloadFiles $PayloadDirectory) +if ($files.Count -lt 10) { throw 'Incomplete component inventory.' } +$test = Join-Path $root 'tests/DailyToolkit.Desktop.Tests/bin/Release/net10.0-windows10.0.26100.0/DailyToolkit.Desktop.Tests.exe' +if (-not (Test-Path -LiteralPath $test)) { throw 'Build the desktop fixture runner before this check.' } +$savedPath = $env:PATH +$rules = [Collections.Generic.List[string]]::new() +try { + # Only these test-owned processes are denied outbound traffic, never the + # user's machine or the runner's package/download/artifact services. + if (@(Get-NetFirewallProfile | Where-Object Enabled -eq $false).Count) { throw 'The disposable CI firewall must be enabled for an offline check.' } + $programs = @($test, (Join-Path $PayloadDirectory 'DailyToolkit.exe'), + (Join-Path $PayloadDirectory 'tools/ffmpeg/ffmpeg.exe'), + (Join-Path $PayloadDirectory 'tools/libreoffice/program/soffice.com'), + (Join-Path $PayloadDirectory 'tools/libreoffice/program/soffice.exe'), + (Join-Path $PayloadDirectory 'tools/libreoffice/program/soffice.bin')) + foreach ($program in $programs) { + $id = 'DailyToolkit.Conversion.Test.' + [guid]::NewGuid().ToString('N') + New-NetFirewallRule -Name $id -DisplayName $id -Direction Outbound -Action Block -Program $program -Profile Any | Out-Null + $rules.Add($id) + } + $env:PATH = "$env:SystemRoot\System32;$env:SystemRoot" + & $test --clipboard-native-bundled-conversion-checks $PayloadDirectory + if ($LASTEXITCODE -ne 0) { throw 'Offline packaged conversion checks failed.' } +} finally { + $env:PATH = $savedPath + foreach ($id in $rules) { Remove-NetFirewallRule -Name $id } +} diff --git a/scripts/test-installer.ps1 b/scripts/test-installer.ps1 index 6953ea2..c2fc9af 100644 --- a/scripts/test-installer.ps1 +++ b/scripts/test-installer.ps1 @@ -1,6 +1,7 @@ param([Parameter(Mandatory)][string]$Compiler, [string]$PayloadDirectory) $ErrorActionPreference = 'Stop' $root = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) +. (Join-Path $PSScriptRoot 'conversion-payload.ps1') [xml]$properties = Get-Content -LiteralPath (Join-Path $root 'Directory.Build.props') -Raw $newerVersion = [version]$properties.Project.PropertyGroup.Version if ($newerVersion.Build -gt 0) { $olderVersion = [version]::new($newerVersion.Major, $newerVersion.Minor, $newerVersion.Build - 1) } @@ -125,6 +126,13 @@ try { Assert-Installer ((Test-Path -LiteralPath $shortcut) -and $shell.CreateShortcut($shortcut).TargetPath -eq $installedExe) 'Start Menu shortcut does not target the installed application.' Assert-Installer (Test-Path -LiteralPath (Join-Path $destination 'microsoft.windowsdesktop.app.runtime-LICENSE')) 'Desktop runtime license is missing.' $checks.Add('fresh install, Windows registration, shortcut, exact payload, runtime license') + $installedConversionFiles = @(Get-ConversionPayloadFiles $destination) + foreach ($relative in $installedConversionFiles) { + Assert-Installer ((Get-FileHash -LiteralPath (Join-Path $destination $relative)).Hash -eq (Get-FileHash -LiteralPath (Join-Path $PayloadDirectory $relative)).Hash) "Installed conversion component differs: $relative" + } + & (Join-Path $PSScriptRoot 'build.ps1') -SkipTests + & (Join-Path $PSScriptRoot 'test-conversion-bundle.ps1') -PayloadDirectory $destination + $checks.Add('installed component inventory and actual offline conversion without external engine paths') $ready = Start-TestHost 'refuse' 'refused-upgrade' $before = (Get-FileHash -LiteralPath $installedExe).Hash @@ -161,6 +169,7 @@ try { Register-TestTask ('DailyToolkit automatic startup. Owner: ' + $sid) $installedExe [IO.File]::WriteAllText((Join-Path $destination 'keep-user-file.txt'), 'retain') Assert-Installer ((Invoke-TestSetup (Get-TestUninstaller) 'owned-uninstall') -eq 0) 'Owned-startup uninstall failed.' + Assert-Installer (-not (Test-Path -LiteralPath (Join-Path $destination 'tools/ffmpeg')) -and -not (Test-Path -LiteralPath (Join-Path $destination 'tools/libreoffice'))) 'Uninstall retained bundled conversion components.' [pscustomobject]@{Run=(Get-ItemProperty -LiteralPath $runKey -Name $testName -ErrorAction SilentlyContinue).$testName;Task=Test-TaskExists} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $work 'owned-cleanup-observed.json') -Encoding utf8 Assert-Installer (-not (Test-Path -LiteralPath $installedExe) -and -not (Test-Path -LiteralPath $uninstallKey)) 'Uninstall left the program or Windows registration.' diff --git a/src/DailyToolkit.Core/Conversion/BundledConversionEngines.cs b/src/DailyToolkit.Core/Conversion/BundledConversionEngines.cs new file mode 100644 index 0000000..08e6614 --- /dev/null +++ b/src/DailyToolkit.Core/Conversion/BundledConversionEngines.cs @@ -0,0 +1,22 @@ +namespace DailyToolkit.Core.Conversion; + +public static class BundledConversionEngines +{ + // Resolve on use so moving the complete portable folder needs no saved path. + // Old absolute paths remain readable settings, but never override the bundle. + public static ConversionOptions Resolve(ConversionOptions options, string? applicationDirectory = null) + { + var root = ConversionRunner.LocalPath(applicationDirectory ?? AppContext.BaseDirectory); + return options with + { + FFmpegPath = Path.Combine(root, "tools", "ffmpeg", "ffmpeg.exe"), + LibreOfficePath = Path.Combine(root, "tools", "libreoffice", "program", "soffice.com") + }; + } + + public static void Require(string path) + { + if (!File.Exists(path)) + throw new FileNotFoundException("转换组件缺失,请重新解压完整软件包。", path); + } +} diff --git a/src/DailyToolkit.Core/Conversion/ExternalConversionBackend.cs b/src/DailyToolkit.Core/Conversion/ExternalConversionBackend.cs index 1d32e14..f6201f4 100644 --- a/src/DailyToolkit.Core/Conversion/ExternalConversionBackend.cs +++ b/src/DailyToolkit.Core/Conversion/ExternalConversionBackend.cs @@ -137,6 +137,12 @@ private static async Task RunProcessAsync(string executable, IReadOnlyLi RedirectStandardOutput = true, RedirectStandardError = true, WorkingDirectory = Path.GetDirectoryName(executable)! }; + if (Path.GetFileName(executable).Equals("soffice.com", StringComparison.OrdinalIgnoreCase) || + Path.GetFileName(executable).Equals("soffice.exe", StringComparison.OrdinalIgnoreCase)) + { + foreach (var name in new[] { "URE_BOOTSTRAP", "UNO_PATH", "UNO_SERVICES", "UNO_TYPES", "PYTHONHOME", "PYTHONPATH" }) + start.Environment.Remove(name); + } foreach (var arg in arguments) start.ArgumentList.Add(arg); using var process = new Process { StartInfo = start }; using var job = CreateProcessJob(); diff --git a/src/DailyToolkit.Desktop/Conversion/ConversionView.xaml b/src/DailyToolkit.Desktop/Conversion/ConversionView.xaml index 599ecf5..3b8b506 100644 --- a/src/DailyToolkit.Desktop/Conversion/ConversionView.xaml +++ b/src/DailyToolkit.Desktop/Conversion/ConversionView.xaml @@ -64,17 +64,7 @@ - - -