diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8caee0f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.gif filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.nupkg filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text diff --git a/.github/actions/cmake-build/action.yml b/.github/actions/cmake-build/action.yml index 22c6f30..bc4a2b2 100644 --- a/.github/actions/cmake-build/action.yml +++ b/.github/actions/cmake-build/action.yml @@ -20,6 +20,9 @@ inputs: platform: description: 'OS platform' required: true + src-dir: + description: 'The directory with the sources' + required: true runs: using: "composite" steps: @@ -33,11 +36,13 @@ runs: - name: Set toolchain path shell: bash + working-directory: ${{inputs.src-dir}} run: echo "TOOLCHAIN_PATH=${{inputs.path-toolchain}}" >> "$GITHUB_ENV" - name: Install dependencies if: inputs.package == 'ON' shell: bash + working-directory: ${{inputs.src-dir}} run: | # We install the following packages: eigen3, catch2, cli11. Installing them with vcpkg (and caching them) # is faster than downloading and building them from source (which is the default behavior of the CZICompress-build-system). @@ -45,6 +50,7 @@ runs: - name: Configure CMake shell: bash + working-directory: ${{inputs.src-dir}} # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type # @@ -53,5 +59,6 @@ runs: - name: Build software shell: bash + working-directory: ${{inputs.src-dir}} # Build your program with the given configuration run: cmake --build build --config ${{inputs.build-type}} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..1fb8a36 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# yamllint disable rule:document-start +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "nuget" + directory: "/czishrink" + schedule: + interval: "weekly" + day: "wednesday" diff --git a/.github/workflows/cmake.yml b/.github/workflows/czicompress_cmake.yml similarity index 89% rename from .github/workflows/cmake.yml rename to .github/workflows/czicompress_cmake.yml index ff299c1..7447d00 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/czicompress_cmake.yml @@ -1,11 +1,12 @@ --- -name: CMake Build +name: CMake Build (czicompress) on: push: branches: ["main"] # run only when merge with main branch pull_request: branches: ["main"] # run only when merge with main branch + workflow_dispatch: {} permissions: contents: read @@ -17,6 +18,9 @@ env: jobs: build-tests: + defaults: + run: + working-directory: ${{github.workspace}}/czicompress name: ${{matrix.config.name}} runs-on: ${{matrix.config.os}} @@ -46,16 +50,16 @@ jobs: package: ON, path-cache: '${{ github.workspace }}\vcpkg\installed', path-toolchain: 'C:/vcpkg/scripts/buildsystems/vcpkg.cmake', - os-id: 'windows' + os-id: 'windows', } - { name: ubuntu-release-package-on, os: ubuntu-20.04, # we want to use an older version in order to increase likelihood that binaries work on other distros platform: x64-linux, - package: ON, + package: OFF, path-cache: '/usr/local/share/vcpkg/installed', path-toolchain: '/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake', - os-id: 'linux' + os-id: 'linux', } steps: @@ -71,17 +75,18 @@ jobs: build-type: ${{env.BUILD_TYPE}} package: ${{matrix.config.package}} platform: ${{matrix.config.platform}} + src-dir: '${{github.workspace}}/czicompress' - name: Run unit tests - working-directory: ${{github.workspace}}/build + working-directory: ${{github.workspace}}/czicompress/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C ${{env.BUILD_TYPE}} - name: Prepare licenses - working-directory: ${{github.workspace}} shell: bash run: | + set -e mkdir ./czicompress-${{matrix.config.name}} cp -R ./THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt ./czicompress-${{matrix.config.name}}/ cp -R ./build/app/THIRD_PARTY_LICENSES.txt ./czicompress-${{matrix.config.name}}/ @@ -89,14 +94,12 @@ jobs: # gather the binaries - name: Prepare Linux binaries if: matrix.config.os == 'ubuntu-20.04' - working-directory: ${{github.workspace}} shell: bash run: | cp ./build/app/czicompress ./build/capi/libczicompressc.so ./czicompress-${{matrix.config.name}}/ - name: Prepare Windows binaries if: matrix.config.os == 'windows-latest' - working-directory: ${{github.workspace}} shell: bash run: | cp ./build/app/${{env.BUILD_TYPE}}/*.exe ./build/capi/${{env.BUILD_TYPE}}/libczicompressc.dll ./czicompress-${{matrix.config.name}}/ @@ -106,4 +109,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: czicompress-${{matrix.config.name}} - path: czicompress-${{matrix.config.name}}/ + path: czicompress/czicompress-${{matrix.config.name}}/ diff --git a/.github/workflows/codeql.yml b/.github/workflows/czicompress_codeql.yml similarity index 88% rename from .github/workflows/codeql.yml rename to .github/workflows/czicompress_codeql.yml index f1c435e..00bfad7 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/czicompress_codeql.yml @@ -1,14 +1,14 @@ --- -name: "CodeQL" +name: "CodeQL (czicompress)" on: push: branches: ["main"] pull_request: - # The branches below must be a subset of the branches above branches: ["main"] schedule: - cron: "22 16 * * 4" + workflow_dispatch: {} permissions: actions: read @@ -17,7 +17,10 @@ permissions: jobs: analyze: - name: Analyze + name: Analyze CPP + defaults: + run: + working-directory: ${{github.workspace}}/czicompress runs-on: ubuntu-latest strategy: @@ -50,6 +53,7 @@ jobs: build-type: Release package: ON platform: x64-linux + src-dir: '${{github.workspace}}/czicompress' - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/czishrink_codeql.yml b/.github/workflows/czishrink_codeql.yml new file mode 100644 index 0000000..28ef76c --- /dev/null +++ b/.github/workflows/czishrink_codeql.yml @@ -0,0 +1,58 @@ +--- +name: "CodeQL (CziShrink)" + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + # ┌───────────── minute (0 - 59) + # │ ┌───────────── hour (0 - 23) + # │ │ ┌───────────── day of the month (1 - 31) + # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) + # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) + # │ │ │ │ │ + # │ │ │ │ │ + # │ │ │ │ │ + # * * * * * + - cron: '30 2 * * 2' + workflow_dispatch: {} + +permissions: read-all + +jobs: + analyze: + name: Analyze CziShrink + defaults: + run: + working-directory: czishrink + runs-on: ubuntu-latest + permissions: + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + lfs: true + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: csharp + queries: security-and-quality + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --no-restore -c Release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/czishrink_dotnet.yml b/.github/workflows/czishrink_dotnet.yml new file mode 100644 index 0000000..67f43d7 --- /dev/null +++ b/.github/workflows/czishrink_dotnet.yml @@ -0,0 +1,135 @@ +--- +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net +permissions: + pull-requests: write + contents: read + +name: .NET Build (CziShrink) + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + workflow_dispatch: {} + +jobs: + build: + defaults: + run: + working-directory: czishrink + name: ${{matrix.config.name}} + runs-on: ${{matrix.config.os}} + + strategy: + fail-fast: false + matrix: + config: + - { + name: windows, + os: windows-latest, + osfamily: win, + } + - { + name: ubuntu, + os: ubuntu-latest, + osfamily: linux, + } + + steps: + - uses: actions/checkout@v3 + with: + lfs: true + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.x + + - name: Get Version from Directory.Build.props + id: getversion + run: | + $xml = [xml](Get-Content -Path "Directory.Build.props") + $version = $xml.SelectSingleNode('//VersionPrefix').'#text' + "-" + $xml.SelectSingleNode('//VersionSuffix').'#text' + "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + shell: pwsh + + - name: Add build ID to version in Directory.Build.props + run: | + Write-Output "Add build ID ${{ github.run_id }} to VersionSuffix in Directory.Build.props" + $file = Get-Item "Directory.Build.props" + $xml = [xml](Get-Content -Path $file.FullName) + $versionElement = $xml.SelectSingleNode('//VersionSuffix') + $versionElement.'#text' += '+${{ github.run_id }}' + $xml.Save($file.FullName) + shell: pwsh + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --no-restore -c Release + + - name: Test + run: > + dotnet test + -c Release + --no-build + --verbosity normal + --logger trx + --results-directory "TestResults" + -p:CollectCoverage=true + -p:CoverletOutputFormat=cobertura + -p:CoverletOutput=${{ github.workspace }}/TestResults/coverage.cobertura.xml + -p:ExcludeByAttribute=GeneratedCodeAttribute%2cObsoleteAttribute + -p:ExcludeByFile=**/*.axaml%2c**/*.g.cs + -p:Exclude='[netczicompress]netczicompress.Views.*' + + - name: Upload dotnet test results + uses: actions/upload-artifact@v3 + with: + name: dotnet-results-${{ matrix.config.name }} + path: TestResults + # Use always() to also publish test results when there are test failures + if: ${{ always() }} + + - name: Code Coverage Report + uses: irongut/CodeCoverageSummary@v1.3.0 + if: matrix.config.name == 'ubuntu' + with: + filename: TestResults/coverage.cobertura.xml + badge: true + fail_below_min: false + format: markdown + hide_branch_rate: false + hide_complexity: false + indicators: true + output: both + thresholds: '60 80' + + - name: Add Coverage PR Comment + uses: marocchino/sticky-pull-request-comment@v2 + if: github.event_name == 'pull_request' && matrix.config.name == 'ubuntu' + with: + recreate: true + path: code-coverage-results.md + + - name: Publish + if: github.event_name == 'push' + run: > + dotnet publish netczicompress.Desktop/netczicompress.Desktop.csproj + -c Release + -a x64 + --self-contained + -p:PublishSingleFile=true + -p:PublishReadyToRun=true + -p:PublishReadyToRunShowWarnings=true + -o ${{ github.workspace }}/publish + + - name: Upload published binaries + uses: actions/upload-artifact@v3 + if: github.event_name == 'push' + with: + name: CziShrink_${{ steps.getversion.outputs.version }}_${{ matrix.config.osfamily}}-x64 + path: publish diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml index 9c21664..cc86c78 100644 --- a/.github/workflows/mega-linter.yml +++ b/.github/workflows/mega-linter.yml @@ -8,6 +8,7 @@ on: branches: ["main"] # run only when merge with main branch pull_request: branches: ["main"] # run only when merge with main branch + workflow_dispatch: {} concurrency: group: ${{ github.ref }}-${{ github.workflow }} diff --git a/.github/workflows/reuse.yml b/.github/workflows/reuse.yml index bf0ae35..7cc344e 100644 --- a/.github/workflows/reuse.yml +++ b/.github/workflows/reuse.yml @@ -6,6 +6,7 @@ on: branches: ["main"] pull_request: branches: ["main"] + workflow_dispatch: {} permissions: contents: read diff --git a/.gitignore b/.gitignore index 930b51f..ef0b4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -11,15 +11,6 @@ *.gch *.pch -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - # Compiled Static libraries *.lai *.la @@ -31,8 +22,413 @@ *.out *.app -.vs/ out/ build/ megalinter-reports/ + +#################################### +### BEGIN VisualStudio.gitignore ### +#################################### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +################################## +### END VisualStudio.gitignore ### +################################## \ No newline at end of file diff --git a/.jsonlintrc.yml b/.jsonlintrc.yml new file mode 100644 index 0000000..0ad9eb6 --- /dev/null +++ b/.jsonlintrc.yml @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +# +# SPDX-License-Identifier: MIT +--- +comments: true diff --git a/.reuse/dep5 b/.reuse/dep5 index 7ad3a9f..793be8c 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -3,10 +3,18 @@ Upstream-Name: czicompress Upstream-Contact: Carl Zeiss Microscopy GmbH Source: https://github.com/ZEISS/czicompress -Files: cla_*.txt CMakeSettings.json CODE_OF_CONDUCT.md CONTRIBUTING.md README.md SECURITY.md THIRD_PARTY_LICENSES*.txt +Files: cla_*.txt czicompress/CMakeSettings.json CODE_OF_CONDUCT.md CONTRIBUTING.md README.md SECURITY.md czicompress/THIRD_PARTY_LICENSES*.txt czicompress/README.md Copyright: 2023 Carl Zeiss Microscopy GmbH License: MIT -Files: .github/* .gitignore .editorconfig .runsettings CPPLINT.cfg .clang-format +Files: .github/* .gitignore .gitattributes czicompress/.editorconfig czicompress/.runsettings czicompress/CPPLINT.cfg czicompress/.clang-format Copyright: 2023 Carl Zeiss Microscopy GmbH License: CC0-1.0 + +Files: czishrink/*.axaml czishrink/*.json czishrink/*.nuspec czishrink/*.txt czishrink/*.ico czishrink/*.png czishrink/*.props czishrink/*.targets czishrink/*.sh czishrink/*.svg czishrink/*.csproj czishrink/*.gitattributes czishrink/*.nupkg czishrink/*.md czishrink/*.pdf czishrink/*.config czishrink/*.ruleset czishrink/*.ps1 czishrink/*.czi czishrink/*.xml czishrink/*.sln czishrink/*.manifest README.md +Copyright: 2023 Carl Zeiss Microscopy GmbH +License: GPL-3.0-or-later + +Files: czishrink/*/mandelbrot.czi +Copyright: 2023 Carl Zeiss Microscopy GmbH +License: CC0-1.0 \ No newline at end of file diff --git a/LICENSES/GPL-3.0-or-later.txt b/LICENSES/GPL-3.0-or-later.txt new file mode 100644 index 0000000..f6cdd22 --- /dev/null +++ b/LICENSES/GPL-3.0-or-later.txt @@ -0,0 +1,232 @@ +GNU GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS + +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. + + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. + +14. Revised Versions of this License. +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . + +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . diff --git a/README.md b/README.md index 48d1b06..97ac11b 100644 --- a/README.md +++ b/README.md @@ -1,291 +1,26 @@ # czicompress -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![REUSE status](https://api.reuse.software/badge/github.com/ZEISS/czicompress)](https://api.reuse.software/info/github.com/ZEISS/czicompress) -[![CMake](https://github.com/ZEISS/czicompress/actions/workflows/cmake.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/cmake.yml) -[![CodeQL](https://github.com/ZEISS/czicompress/actions/workflows/codeql.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/codeql.yml) [![MegaLinter](https://github.com/ZEISS/czicompress/actions/workflows/mega-linter.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/mega-linter.yml) Reduce the size of existing CZI files by converting them to zstd-compressed CZI files. -Copies the content of a CZI-file into another CZI-file changing the compression of the image data. -With the 'compress' command, uncompressed image data is converted to Zstd-compressed image data. -With the 'decompress' command, compressed image data is converted to uncompressed data. - -The tool is based on [libczi](https://github.com/ZEISS/libczi.git). - -## Table of contents - -- [Download](#download) -- [Usage](#usage) - - [Examples](#examples) - - [Single file](#single-file) - - [Multiple files (bash shell)](#multiple-files-bash-shell) - - [Multiple files (Powershell)](#multiple-files-powershell) -- [Build and Test](#build-and-test) - - [Pre-requisites](#pre-requisites) - - [Build in Visual Studio](#build-in-visual-studio) - - [Build in command line](#build-in-command-line) - - [Quick build](#quick-build) - - [Build with preferred compiler](#build-with-preferred-compiler) - - [Tests](#tests) -- [Known issues](#known-issues) -- [Guidelines](#guidelines) -- [Versioning](#versioning) -- [Licensing](#licensing) -- [Credits to Third Party Components](#credits-to-third-party-components) -- [Disclaimer](#disclaimer) - -## Download -We have not yet published any Releases. Meanwhile, you can download binaries from the artifacts of the latest [Build workflow run](https://github.com/zeissmicroscopy/czicompress/actions/workflows/cmake.yml?query=branch%3Amain). -Click on the topmost successful run and download the binaries for your platform: -* czicompress-windows-64-release-msvc-package-off for Windows -* czicompress-ubuntu-release-llvm-package-off for Linux - -Clicking on these artifacts will download a ZIP file with the executable. The executable is a stand-alone binary. You can put it anywhere you like. - -## Usage - -Start the executable from the command line, providing the required command line arguments. - -``` -Usage: czicompress.exe [OPTIONS] - -Options: - -h,--help Print this help message and exit - - -c,--command COMMAND - Specifies the mode of operation: 'compress' to convert to a - zstd-compressed CZI, 'decompress' to convert to a CZI - containing only uncompressed data. - - -i,--input SOURCE_FILE - The source CZI-file to be processed. - - -o,--output DESTINATION_FILE - The destination CZI-file to be written. - - -s,--strategy STRATEGY - Choose which subblocks of the source file are compressed. - STRATEGY can be one of 'all', 'uncompressed', - 'uncompressed_and_zstd'. The default is 'uncompressed'. - - -t,--compression_options COMPRESSION_OPTIONS - Specify compression parameters. The default is - 'zstd1:ExplicitLevel=1;PreProcess=HiLoByteUnpack'. - - -w,--overwrite If the output file exists, try to overwrite it. - - --ignore_duplicate_subblocks BOOLEAN - If this option is enabled, the operation will ignore if - duplicate subblocks are encountered in the source document. - Otherwise, an error will be reported. The default is 'on'. - - -Copies the content of a CZI-file into another CZI-file changing the compression -of the image data. -With the 'compress' command, uncompressed image data is converted to -Zstd-compressed image data. This can reduce the file size substantially. With -the 'decompress' command, compressed image data is converted to uncompressed -data. -For the 'compress' command, a compression strategy can be specified with the -'--strategy' option. It controls which subblocks of the source file will be -compressed. The source document may already contain compressed data (possibly -with a lossy compression scheme). In this case it is undesirable to compress the -data with lossless zstd, as that will almost certainly increase the file size. -Therefore, the "uncompressed" strategy compresses only uncompressed subblocks. -The "uncompressed_and_zstd" strategy compresses the subblocks that are -uncompressed OR compressed with Zstd, and the "all" strategy compresses all -subblocks, regardless of their current compression status. Some compression -schemes that can occur in a CZI-file cannot be decompressed by this tool. Data -compressed with such a scheme will be copied verbatim to the destination file, -regardless of the command and strategy chosen. -``` - -### Examples - -#### Single file -~~~ -czicompress -c compress -i MyImage.czi -o MyImage.zstd.czi -~~~ - -#### Multiple files (bash shell) -* Put czicompress on the PATH -~~~cs -export PATH="${PATH}:/dir/of/czicompress" -~~~ -* Put the following lines into a file called czicompress.sh: -~~~sh -#!/bin/bash -f="$1" -output="${f%%czi}zstd.czi" -echo -n "${f} -> ${output}: " -if [[ -f "$output" ]] -then - echo "Output file already exists." - rm -i "$output" -fi - -if [[ -f "$output" ]] -then - exit 1 -fi - -czicompress --command compress -i "$f" -o "$output" -status=$? -if [[ $status -eq 0 ]] -then - echo OK -fi - -exit $status -~~~ -* Then run -~~~sh -find -type f -name '*.czi' -not -iname '*.zstd.czi' -exec bash czicompress.sh '{}' \; -~~~ - -#### Multiple files (Powershell) -* Put czicompress on the PATH -~~~powershell -$env:Path += ";/dir/of/czicompress" -~~~ -* Put the following lines into a file called czicompress.ps1: -~~~powershell -param( - [Parameter(Mandatory=$true)] - [string]$directory, - [Parameter(Mandatory=$false)] - [string]$command = "compress", - [Parameter(Mandatory=$false)] - [string]$fileExtension = "czi", - [Parameter(Mandatory=$false)] - [string]$outputSuffix = ".zstd", - [Parameter(Mandatory=$false)] - [switch]$recursive = $false -) - -$cziCompressExe = "czicompress.exe" - -$filterString = "*.$($fileExtension)" - -if ($recursive) { - $files = Get-ChildItem -Path $directory -Filter $filterString -Recurse -} else { - $files = Get-ChildItem -Path $directory -Filter $filterString -} - -$files = $files | Where-Object { - $_.Name -notlike "*$outputSuffix$filterString" -} - -$files | ForEach-Object { - $outFileName = "$($_.DirectoryName)\$($_.BaseName)$outputSuffix$($_.Extension)" - Write-Host "$($_) -> $($outFileName)" - if ((Test-Path -Path $outFileName)) { - Write-Host "Output file already exists... Removing" - Remove-Item $outFileName - } - if ((Test-Path -Path $outFileName)) { - Write-Host "Unable to remove file" - # This will act as a continue because this code is executed as a script block and not like a classic for-each loop - return - } - - # The backticks here are to escape the double quotes which exist in case we have spaces in file path. - $execArguments = "& $($cziCompressExe) -i `"$_`" -o `"$($outFileName)`" --command $($command)" - iex $execArguments -} - -exit 0 -~~~ -* Then run -~~~powershell -./czicompress.ps1 -Directory . -~~~ - -## Build and Test - -Build either with Visual Studio or with CMake in command line. - -### Pre-requisites - -The `CZICompress` source codes are implemented using C++17 standard and can be compiled on Windows or Linux and with multiple compilers. You can compile codes by using IDE like Microsoft Visual Studio (MSVS), Visual Studio Code (VSCode) or any other IDE that works with `CMake`. Make sure that on your machine you have one of these tools: - -| | Windows | Linux | -| ---------- | ------------------- | ------------- | -| Build tool | CMake | CMake | -| Compilers | MSVC | GNU, LLVM | -| IDE | MSVS, VSCode, CLion | VSCode, CLion | - - -### Build in Visual Studio - -To build `czicompress` in *Microsoft Visual Studio* (or in *Visual Studio Code*) follow these steps: -1. Open `czicompress` folder in Visual Studio. -2. In the *Solution Explorer* select `CMakeLists.txt` file and make right click. -3. In the popped up menu select `Configure czicompress` (`Configure All Projects` in VSCode). -4. When configuration is finished, right click on `CMakeLists.txt` and the popped up menu select `Build` (`Build All Projects` in the VSCode). - -This configures and builds software using default compilers. - -### Build in command line - -#### Quick build - -On Windows or Linux platform, open the command line window in the cloned `czicompress` directory and type this to configure and build the sources: - -```bash -cmake -B build -DCMAKE_BUILD_TYPE=Release -cmake --build build -j 10 -``` - -This configures `Release` build using system default compiler. After the build, for the Windows platform the `czicompress.exe` executable is located in the `.\build\app\Release\` subdirectory of `czicompress` project directory and for the Linux it is located in the `./build/app/` subdirectory of `czicompress` project directory. - -#### Build with preferred compiler - -If you want to compile using a specific preferred compiler, either set environment variables `CXX` for the C++ compiler and `CC` for the C compiler, or specify compilers as `cmake` options. - -**Example 1:** if you want to compile under Linux or WSL ([Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/about) with LLVM compilers, before configuring build with `cmake` set environment variables. -```bash -export CC=/usr/bin/clang && export CXX=/usr/bin/clang++ -cmake -B ./build -DCMAKE_BUILD_TYPE=Release -``` - -**Example 2:** set the preferred C/C++ compilers as `cmake` options -```bash -cmake -B ./build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -``` - -When the configuration is finished, make a build and via parameter `-j` specify the number of parallel jobs you want to run: -```bash -cmake --build ./build --config Release -j 10 -``` - -After the build, the `czicompress` executable will be in `./build/app/czicompress`. - -### Tests - -After the build, run the tests by executing `./build/tests/czicompress_tests`. +# Command line tool and C/C++ libraries +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![CMake](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_cmake.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_cmake.yml) +[![CodeQL](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_codeql.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_codeql.yml) -## Known issues +[czicompress](czicompress/README.md) is a cross-platform command line tool to compress CZIs. czicompress and its source code are provided under the [MIT license](czicompress/LICENSE). -When compiling in Visual Studio for the first time, you may need to double compile. The Visual Studio is using "Ninja" for building and for some reason it is reporting a linker error `LINK: Fatal error LNK1168: cannot open app\czicompress.exe for writing` despite the fact that the `czicompress.exe` is created. +# CziShrink desktop app +[![License: GPL](https://img.shields.io/badge/License-GPL%203+-yellow.svg)](https://spdx.org/licenses/GPL-3.0-or-later.html) +[![Build](https://github.com/ZEISS/czicompress/actions/workflows/czishrink_dotnet.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/czishrink_dotnet.yml) +[![CodeQL](https://github.com/ZEISS/czicompress/actions/workflows/czishrink_codeql.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/czishrink_codeql.yml) +[czishrink](czishrink/README.md) is a desktop app to compress CZIs. CziShrink is provided under the [GPLv3 license](czishrink/LICENSE.txt). ## Guidelines [Code of Conduct](./CODE_OF_CONDUCT.md) [Contributing](./CONTRIBUTING.md) -## Versioning -For czicompress the [semantic versioning scheme 2.0](https://semver.org/) is to be applied. The version number is defined in the top-level [CMakeLists.txt](./CMakeLists.txt). This is the only place where the version number is defined. When making changes, this version number needs to be updated accordingly. For determining whether a change is a breaking one, the source code level is decisive; i.e. not binary compatibility (of the resulting static or dynamic library) is to be considered, but the case of re-compiling with the changed sources. A borderline case are maybe changes in the CMake-files - here the best judgement is to be applied whether a change in the compilation result will occur. - -## Licensing -Carl Zeiss Microscopy GmbH provides czicompress under the [MIT License](./LICENSE). - -## Credits to Third Party Components -As part of our CI/CD, the following 3rd party components are re-distributed: -- [libCZI + 3rd Party Source Code Components](https://github.com/ZEISS/libczi/tree/main#credits-to-third-party-components) -- [libCZI Linked Dependencies + czicompress Linked Dependencies](./THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt) - ## Disclaimer ZEISS, ZEISS.com are registered trademarks of Carl Zeiss AG. diff --git a/.clang-format b/czicompress/.clang-format similarity index 100% rename from .clang-format rename to czicompress/.clang-format diff --git a/.runsettings b/czicompress/.runsettings similarity index 100% rename from .runsettings rename to czicompress/.runsettings diff --git a/CMakeLists.txt b/czicompress/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to czicompress/CMakeLists.txt diff --git a/CMakeSettings.json b/czicompress/CMakeSettings.json similarity index 100% rename from CMakeSettings.json rename to czicompress/CMakeSettings.json diff --git a/CPPLINT.cfg b/czicompress/CPPLINT.cfg similarity index 100% rename from CPPLINT.cfg rename to czicompress/CPPLINT.cfg diff --git a/LICENSE b/czicompress/LICENSE similarity index 100% rename from LICENSE rename to czicompress/LICENSE diff --git a/czicompress/README.md b/czicompress/README.md new file mode 100644 index 0000000..46df990 --- /dev/null +++ b/czicompress/README.md @@ -0,0 +1,290 @@ +# czicompress +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![REUSE status](https://api.reuse.software/badge/github.com/ZEISS/czicompress)](https://api.reuse.software/info/github.com/ZEISS/czicompress) +[![CMake](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_cmake.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_cmake.yml) +[![CodeQL](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_codeql.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_codeql.yml) +[![MegaLinter](https://github.com/ZEISS/czicompress/actions/workflows/mega-linter.yml/badge.svg?branch=main&event=push)](https://github.com/ZEISS/czicompress/actions/workflows/mega-linter.yml) + +Reduce the size of existing CZI files by converting them to zstd-compressed CZI files. + +Copies the content of a CZI-file into another CZI-file changing the compression of the image data. +With the 'compress' command, uncompressed image data is converted to Zstd-compressed image data. +With the 'decompress' command, compressed image data is converted to uncompressed data. + +The tool is based on [libczi](https://github.com/ZEISS/libczi.git). + +## Table of contents + +- [Download](#download) +- [Usage](#usage) + - [Examples](#examples) + - [Single file](#single-file) + - [Multiple files (bash shell)](#multiple-files-bash-shell) + - [Multiple files (Powershell)](#multiple-files-powershell) +- [Build and Test](#build-and-test) + - [Pre-requisites](#pre-requisites) + - [Build in Visual Studio](#build-in-visual-studio) + - [Build in command line](#build-in-command-line) + - [Quick build](#quick-build) + - [Build with preferred compiler](#build-with-preferred-compiler) + - [Tests](#tests) +- [Known issues](#known-issues) +- [Guidelines](#guidelines) +- [Versioning](#versioning) +- [Licensing](#licensing) +- [Credits to Third Party Components](#credits-to-third-party-components) +- [Disclaimer](#disclaimer) + +## Download +We have not yet published any Releases. Meanwhile, you can download binaries from the artifacts of the latest [Build workflow run](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_cmake.yml?query=branch%3Amain). +Click on the topmost successful run and download the binaries for your platform: +* czicompress-windows-64-release-msvc-package-off for Windows +* czicompress-ubuntu-release-llvm-package-off for Linux + +Clicking on these artifacts will download a ZIP file with the executable. The executable is a stand-alone binary. You can put it anywhere you like. + +## Usage + +Start the executable from the command line, providing the required command line arguments. + +``` +Usage: czicompress.exe [OPTIONS] + +Options: + -h,--help Print this help message and exit + + -c,--command COMMAND + Specifies the mode of operation: 'compress' to convert to a + zstd-compressed CZI, 'decompress' to convert to a CZI + containing only uncompressed data. + + -i,--input SOURCE_FILE + The source CZI-file to be processed. + + -o,--output DESTINATION_FILE + The destination CZI-file to be written. + + -s,--strategy STRATEGY + Choose which subblocks of the source file are compressed. + STRATEGY can be one of 'all', 'uncompressed', + 'uncompressed_and_zstd'. The default is 'uncompressed'. + + -t,--compression_options COMPRESSION_OPTIONS + Specify compression parameters. The default is + 'zstd1:ExplicitLevel=1;PreProcess=HiLoByteUnpack'. + + -w,--overwrite If the output file exists, try to overwrite it. + + --ignore_duplicate_subblocks BOOLEAN + If this option is enabled, the operation will ignore if + duplicate subblocks are encountered in the source document. + Otherwise, an error will be reported. The default is 'on'. + + +Copies the content of a CZI-file into another CZI-file changing the compression +of the image data. +With the 'compress' command, uncompressed image data is converted to +Zstd-compressed image data. This can reduce the file size substantially. With +the 'decompress' command, compressed image data is converted to uncompressed +data. +For the 'compress' command, a compression strategy can be specified with the +'--strategy' option. It controls which subblocks of the source file will be +compressed. The source document may already contain compressed data (possibly +with a lossy compression scheme). In this case it is undesirable to compress the +data with lossless zstd, as that will almost certainly increase the file size. +Therefore, the "uncompressed" strategy compresses only uncompressed subblocks. +The "uncompressed_and_zstd" strategy compresses the subblocks that are +uncompressed OR compressed with Zstd, and the "all" strategy compresses all +subblocks, regardless of their current compression status. Some compression +schemes that can occur in a CZI-file cannot be decompressed by this tool. Data +compressed with such a scheme will be copied verbatim to the destination file, +regardless of the command and strategy chosen. +``` + +### Examples + +#### Single file +~~~ +czicompress -c compress -i MyImage.czi -o MyImage.zstd.czi +~~~ + +#### Multiple files (bash shell) +* Put czicompress on the PATH +~~~cs +export PATH="${PATH}:/dir/of/czicompress" +~~~ +* Put the following lines into a file called czicompress.sh: +~~~sh +#!/bin/bash +f="$1" +output="${f%%czi}zstd.czi" +echo -n "${f} -> ${output}: " +if [[ -f "$output" ]] +then + echo "Output file already exists." + rm -i "$output" +fi + +if [[ -f "$output" ]] +then + exit 1 +fi + +czicompress --command compress -i "$f" -o "$output" +status=$? +if [[ $status -eq 0 ]] +then + echo OK +fi + +exit $status +~~~ +* Then run +~~~sh +find -type f -name '*.czi' -not -iname '*.zstd.czi' -exec bash czicompress.sh '{}' \; +~~~ + +#### Multiple files (Powershell) +* Put czicompress on the PATH +~~~powershell +$env:Path += ";/dir/of/czicompress" +~~~ +* Put the following lines into a file called czicompress.ps1: +~~~powershell +param( + [Parameter(Mandatory=$true)] + [string]$directory, + [Parameter(Mandatory=$false)] + [string]$command = "compress", + [Parameter(Mandatory=$false)] + [string]$fileExtension = "czi", + [Parameter(Mandatory=$false)] + [string]$outputSuffix = ".zstd", + [Parameter(Mandatory=$false)] + [switch]$recursive = $false +) + +$cziCompressExe = "czicompress.exe" + +$filterString = "*.$($fileExtension)" + +if ($recursive) { + $files = Get-ChildItem -Path $directory -Filter $filterString -Recurse +} else { + $files = Get-ChildItem -Path $directory -Filter $filterString +} + +$files = $files | Where-Object { + $_.Name -notlike "*$outputSuffix$filterString" +} + +$files | ForEach-Object { + $outFileName = "$($_.DirectoryName)\$($_.BaseName)$outputSuffix$($_.Extension)" + Write-Host "$($_) -> $($outFileName)" + if ((Test-Path -Path $outFileName)) { + Write-Host "Output file already exists... Removing" + Remove-Item $outFileName + } + if ((Test-Path -Path $outFileName)) { + Write-Host "Unable to remove file" + # This will act as a continue because this code is executed as a script block and not like a classic for-each loop + return + } + + # The backticks here are to escape the double quotes which exist in case we have spaces in file path. + $execArguments = "& $($cziCompressExe) -i `"$_`" -o `"$($outFileName)`" --command $($command)" + iex $execArguments +} + +exit 0 +~~~ +* Then run +~~~powershell +./czicompress.ps1 -Directory . +~~~ + +## Build and Test + +Build either with Visual Studio or with CMake in command line. + +### Pre-requisites + +The `CZICompress` source codes are implemented using C++17 standard and can be compiled on Windows or Linux and with multiple compilers. You can compile codes by using IDE like Microsoft Visual Studio (MSVS), Visual Studio Code (VSCode) or any other IDE that works with `CMake`. Make sure that on your machine you have one of these tools: + +| | Windows | Linux | +| ---------- | ------------------- | ------------- | +| Build tool | CMake | CMake | +| Compilers | MSVC | GNU, LLVM | +| IDE | MSVS, VSCode, CLion | VSCode, CLion | + + +### Build in Visual Studio + +To build `czicompress` in *Microsoft Visual Studio* (or in *Visual Studio Code*) follow these steps: +1. Open `czicompress` folder in Visual Studio. +2. In the *Solution Explorer* select `CMakeLists.txt` file and make right click. +3. In the popped up menu select `Configure czicompress` (`Configure All Projects` in VSCode). +4. When configuration is finished, right click on `CMakeLists.txt` and the popped up menu select `Build` (`Build All Projects` in the VSCode). + +This configures and builds software using default compilers. + +### Build in command line + +#### Quick build + +On Windows or Linux platform, open the command line window in the cloned `czicompress` directory and type this to configure and build the sources: + +```bash +cmake -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build -j 10 +``` + +This configures `Release` build using system default compiler. After the build, for the Windows platform the `czicompress.exe` executable is located in the `.\build\app\Release\` subdirectory of `czicompress` project directory and for the Linux it is located in the `./build/app/` subdirectory of `czicompress` project directory. + +#### Build with preferred compiler + +If you want to compile using a specific preferred compiler, either set environment variables `CXX` for the C++ compiler and `CC` for the C compiler, or specify compilers as `cmake` options. + +**Example 1:** if you want to compile under Linux or WSL ([Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/about) with LLVM compilers, before configuring build with `cmake` set environment variables. +```bash +export CC=/usr/bin/clang && export CXX=/usr/bin/clang++ +cmake -B ./build -DCMAKE_BUILD_TYPE=Release +``` + +**Example 2:** set the preferred C/C++ compilers as `cmake` options +```bash +cmake -B ./build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ +``` + +When the configuration is finished, make a build and via parameter `-j` specify the number of parallel jobs you want to run: +```bash +cmake --build ./build --config Release -j 10 +``` + +After the build, the `czicompress` executable will be in `./build/app/czicompress`. + +### Tests + +After the build, run the tests by executing `./build/tests/czicompress_tests`. + +## Known issues + +When compiling in Visual Studio for the first time, you may need to double compile. The Visual Studio is using "Ninja" for building and for some reason it is reporting a linker error `LINK: Fatal error LNK1168: cannot open app\czicompress.exe for writing` despite the fact that the `czicompress.exe` is created. + +## Guidelines +[Code of Conduct](./CODE_OF_CONDUCT.md) +[Contributing](./CONTRIBUTING.md) + +## Versioning +For czicompress the [semantic versioning scheme 2.0](https://semver.org/) is to be applied. The version number is defined in the top-level [CMakeLists.txt](./CMakeLists.txt). This is the only place where the version number is defined. When making changes, this version number needs to be updated accordingly. For determining whether a change is a breaking one, the source code level is decisive; i.e. not binary compatibility (of the resulting static or dynamic library) is to be considered, but the case of re-compiling with the changed sources. A borderline case are maybe changes in the CMake-files - here the best judgement is to be applied whether a change in the compilation result will occur. + +## Licensing +Carl Zeiss Microscopy GmbH provides czicompress under the [MIT License](./LICENSE). + +## Credits to Third Party Components +As part of our CI/CD, the following 3rd party components are re-distributed: +- [libCZI + 3rd Party Source Code Components](https://github.com/ZEISS/libczi/tree/main#credits-to-third-party-components) +- [libCZI Linked Dependencies + czicompress Linked Dependencies](./THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt) + +## Disclaimer +ZEISS, ZEISS.com are registered trademarks of Carl Zeiss AG. diff --git a/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt b/czicompress/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt similarity index 100% rename from THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt rename to czicompress/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt diff --git a/app/CMakeLists.txt b/czicompress/app/CMakeLists.txt similarity index 100% rename from app/CMakeLists.txt rename to czicompress/app/CMakeLists.txt diff --git a/app/CZICompress_Config.h.in b/czicompress/app/CZICompress_Config.h.in similarity index 100% rename from app/CZICompress_Config.h.in rename to czicompress/app/CZICompress_Config.h.in diff --git a/app/CZIcompress.cpp b/czicompress/app/CZIcompress.cpp similarity index 100% rename from app/CZIcompress.cpp rename to czicompress/app/CZIcompress.cpp diff --git a/app/commandlineargshelper.cpp b/czicompress/app/commandlineargshelper.cpp similarity index 100% rename from app/commandlineargshelper.cpp rename to czicompress/app/commandlineargshelper.cpp diff --git a/app/commandlineargshelper.h b/czicompress/app/commandlineargshelper.h similarity index 100% rename from app/commandlineargshelper.h rename to czicompress/app/commandlineargshelper.h diff --git a/app/czicompress-longpaths.manifest b/czicompress/app/czicompress-longpaths.manifest similarity index 100% rename from app/czicompress-longpaths.manifest rename to czicompress/app/czicompress-longpaths.manifest diff --git a/app/czicompress-longpaths.manifest.license b/czicompress/app/czicompress-longpaths.manifest.license similarity index 100% rename from app/czicompress-longpaths.manifest.license rename to czicompress/app/czicompress-longpaths.manifest.license diff --git a/capi/CMakeLists.txt b/czicompress/capi/CMakeLists.txt similarity index 100% rename from capi/CMakeLists.txt rename to czicompress/capi/CMakeLists.txt diff --git a/capi/CZICompress_Config.h.in b/czicompress/capi/CZICompress_Config.h.in similarity index 100% rename from capi/CZICompress_Config.h.in rename to czicompress/capi/CZICompress_Config.h.in diff --git a/capi/CZICompress_Resource.rc.in b/czicompress/capi/CZICompress_Resource.rc.in similarity index 100% rename from capi/CZICompress_Resource.rc.in rename to czicompress/capi/CZICompress_Resource.rc.in diff --git a/capi/capi.cpp b/czicompress/capi/capi.cpp similarity index 100% rename from capi/capi.cpp rename to czicompress/capi/capi.cpp diff --git a/capi/capi.h b/czicompress/capi/capi.h similarity index 100% rename from capi/capi.h rename to czicompress/capi/capi.h diff --git a/cmake/SemVer.cmake b/czicompress/cmake/SemVer.cmake similarity index 100% rename from cmake/SemVer.cmake rename to czicompress/cmake/SemVer.cmake diff --git a/lib/CMakeLists.txt b/czicompress/lib/CMakeLists.txt similarity index 100% rename from lib/CMakeLists.txt rename to czicompress/lib/CMakeLists.txt diff --git a/lib/CZICompress_Config.h.in b/czicompress/lib/CZICompress_Config.h.in similarity index 100% rename from lib/CZICompress_Config.h.in rename to czicompress/lib/CZICompress_Config.h.in diff --git a/lib/inc_libCZI.h b/czicompress/lib/inc_libCZI.h similarity index 100% rename from lib/inc_libCZI.h rename to czicompress/lib/inc_libCZI.h diff --git a/lib/include/IConsoleio.h b/czicompress/lib/include/IConsoleio.h similarity index 100% rename from lib/include/IConsoleio.h rename to czicompress/lib/include/IConsoleio.h diff --git a/lib/include/IOperation.h b/czicompress/lib/include/IOperation.h similarity index 100% rename from lib/include/IOperation.h rename to czicompress/lib/include/IOperation.h diff --git a/lib/include/command.h b/czicompress/lib/include/command.h similarity index 100% rename from lib/include/command.h rename to czicompress/lib/include/command.h diff --git a/lib/include/commandlineoptions.h b/czicompress/lib/include/commandlineoptions.h similarity index 100% rename from lib/include/commandlineoptions.h rename to czicompress/lib/include/commandlineoptions.h diff --git a/lib/include/compressionstrategy.h b/czicompress/lib/include/compressionstrategy.h similarity index 100% rename from lib/include/compressionstrategy.h rename to czicompress/lib/include/compressionstrategy.h diff --git a/lib/include/progressinfo.h b/czicompress/lib/include/progressinfo.h similarity index 100% rename from lib/include/progressinfo.h rename to czicompress/lib/include/progressinfo.h diff --git a/lib/include/utils/errorhandling/winerrorformatting.h b/czicompress/lib/include/utils/errorhandling/winerrorformatting.h similarity index 100% rename from lib/include/utils/errorhandling/winerrorformatting.h rename to czicompress/lib/include/utils/errorhandling/winerrorformatting.h diff --git a/lib/include/utils/utf8/utf8converter.h b/czicompress/lib/include/utils/utf8/utf8converter.h similarity index 100% rename from lib/include/utils/utf8/utf8converter.h rename to czicompress/lib/include/utils/utf8/utf8converter.h diff --git a/lib/src/actionwithsubblockstatistics.h b/czicompress/lib/src/actionwithsubblockstatistics.h similarity index 100% rename from lib/src/actionwithsubblockstatistics.h rename to czicompress/lib/src/actionwithsubblockstatistics.h diff --git a/lib/src/commandlineoptions.cpp b/czicompress/lib/src/commandlineoptions.cpp similarity index 100% rename from lib/src/commandlineoptions.cpp rename to czicompress/lib/src/commandlineoptions.cpp diff --git a/lib/src/consoleio.cpp b/czicompress/lib/src/consoleio.cpp similarity index 100% rename from lib/src/consoleio.cpp rename to czicompress/lib/src/consoleio.cpp diff --git a/lib/src/consoleio.h b/czicompress/lib/src/consoleio.h similarity index 100% rename from lib/src/consoleio.h rename to czicompress/lib/src/consoleio.h diff --git a/lib/src/copyczi.cpp b/czicompress/lib/src/copyczi.cpp similarity index 100% rename from lib/src/copyczi.cpp rename to czicompress/lib/src/copyczi.cpp diff --git a/lib/src/copyczi.h b/czicompress/lib/src/copyczi.h similarity index 100% rename from lib/src/copyczi.h rename to czicompress/lib/src/copyczi.h diff --git a/lib/src/operation.cpp b/czicompress/lib/src/operation.cpp similarity index 100% rename from lib/src/operation.cpp rename to czicompress/lib/src/operation.cpp diff --git a/lib/src/operation.h b/czicompress/lib/src/operation.h similarity index 100% rename from lib/src/operation.h rename to czicompress/lib/src/operation.h diff --git a/lib/src/progressinfo.cpp b/czicompress/lib/src/progressinfo.cpp similarity index 100% rename from lib/src/progressinfo.cpp rename to czicompress/lib/src/progressinfo.cpp diff --git a/lib/src/utils/errorhandling/winerrorformatting.cpp b/czicompress/lib/src/utils/errorhandling/winerrorformatting.cpp similarity index 100% rename from lib/src/utils/errorhandling/winerrorformatting.cpp rename to czicompress/lib/src/utils/errorhandling/winerrorformatting.cpp diff --git a/lib/src/utils/utf8/platforms/posix/utf8converter.cpp b/czicompress/lib/src/utils/utf8/platforms/posix/utf8converter.cpp similarity index 100% rename from lib/src/utils/utf8/platforms/posix/utf8converter.cpp rename to czicompress/lib/src/utils/utf8/platforms/posix/utf8converter.cpp diff --git a/lib/src/utils/utf8/platforms/windows/utf8converter.cpp b/czicompress/lib/src/utils/utf8/platforms/windows/utf8converter.cpp similarity index 100% rename from lib/src/utils/utf8/platforms/windows/utf8converter.cpp rename to czicompress/lib/src/utils/utf8/platforms/windows/utf8converter.cpp diff --git a/tests/CMakeLists.txt b/czicompress/tests/CMakeLists.txt similarity index 100% rename from tests/CMakeLists.txt rename to czicompress/tests/CMakeLists.txt diff --git a/tests/libczi_utils.cpp b/czicompress/tests/libczi_utils.cpp similarity index 100% rename from tests/libczi_utils.cpp rename to czicompress/tests/libczi_utils.cpp diff --git a/tests/libczi_utils.h b/czicompress/tests/libczi_utils.h similarity index 100% rename from tests/libczi_utils.h rename to czicompress/tests/libczi_utils.h diff --git a/tests/test_commandlineparsing.cpp b/czicompress/tests/test_commandlineparsing.cpp similarity index 100% rename from tests/test_commandlineparsing.cpp rename to czicompress/tests/test_commandlineparsing.cpp diff --git a/tests/test_copyoperation.cpp b/czicompress/tests/test_copyoperation.cpp similarity index 100% rename from tests/test_copyoperation.cpp rename to czicompress/tests/test_copyoperation.cpp diff --git a/tests/test_utf8_utils.cpp b/czicompress/tests/test_utf8_utils.cpp similarity index 100% rename from tests/test_utf8_utils.cpp rename to czicompress/tests/test_utf8_utils.cpp diff --git a/czishrink/.images/CompressionStatistics.gif b/czishrink/.images/CompressionStatistics.gif new file mode 100644 index 0000000..39f9b7f --- /dev/null +++ b/czishrink/.images/CompressionStatistics.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:726be9bd09cacdfd49e01b58f6d80156a5efc67a30627c39c23efb2de7a0d1f5 +size 133010 diff --git a/czishrink/.images/CompressionStatistics.gif.license b/czishrink/.images/CompressionStatistics.gif.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/CompressionStatistics.gif.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.images/CompressionStatistics.png b/czishrink/.images/CompressionStatistics.png new file mode 100644 index 0000000..922dbd7 --- /dev/null +++ b/czishrink/.images/CompressionStatistics.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b40420e046216d79b71590b7f483710bbd145dd9faab31f27f8aed727afcf27 +size 37074 diff --git a/czishrink/.images/CompressionStatistics.png.license b/czishrink/.images/CompressionStatistics.png.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/CompressionStatistics.png.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.images/CziShrink_DarkTheme.png b/czishrink/.images/CziShrink_DarkTheme.png new file mode 100644 index 0000000..c13d78a --- /dev/null +++ b/czishrink/.images/CziShrink_DarkTheme.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30e8a384b90d46641b5fc90f71811ddf1253be598a25b95a2fc9da36f827c183 +size 58582 diff --git a/czishrink/.images/CziShrink_DarkTheme.png.license b/czishrink/.images/CziShrink_DarkTheme.png.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/CziShrink_DarkTheme.png.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.images/CziShrink_LightTheme.png b/czishrink/.images/CziShrink_LightTheme.png new file mode 100644 index 0000000..c928c86 --- /dev/null +++ b/czishrink/.images/CziShrink_LightTheme.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c29c18cb7ca1fa56cf428552f53700a87c3e8a40e1b503a535d9e6d9a445a26 +size 58426 diff --git a/czishrink/.images/CziShrink_LightTheme.png.license b/czishrink/.images/CziShrink_LightTheme.png.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/CziShrink_LightTheme.png.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.images/ErrorFileOptions.png b/czishrink/.images/ErrorFileOptions.png new file mode 100644 index 0000000..aa9fd64 --- /dev/null +++ b/czishrink/.images/ErrorFileOptions.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:722d6b25afc98772bc955585e812447d7d8e38fe69b0b15751417e920f0201c3 +size 29773 diff --git a/czishrink/.images/ErrorFileOptions.png.license b/czishrink/.images/ErrorFileOptions.png.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/ErrorFileOptions.png.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.images/Progress.png b/czishrink/.images/Progress.png new file mode 100644 index 0000000..9a0cdf2 --- /dev/null +++ b/czishrink/.images/Progress.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6c38065cdaabfbc3583032eb687c3d595087d90ec60a99315614d194188d001 +size 41259 diff --git a/czishrink/.images/Progress.png.license b/czishrink/.images/Progress.png.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/Progress.png.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.images/ProgressAnimation.gif b/czishrink/.images/ProgressAnimation.gif new file mode 100644 index 0000000..58f839d --- /dev/null +++ b/czishrink/.images/ProgressAnimation.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e025a74d53bf41cdff7a48aa17516e811a43b92aa4c48fcc8c6c62f804b1865 +size 1208046 diff --git a/czishrink/.images/ProgressAnimation.gif.license b/czishrink/.images/ProgressAnimation.gif.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/ProgressAnimation.gif.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.images/ShareBadgeExample.png b/czishrink/.images/ShareBadgeExample.png new file mode 100644 index 0000000..479e66a --- /dev/null +++ b/czishrink/.images/ShareBadgeExample.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0ffafc2a5a56e8e30c349828f7e3a7d213776444e4febdfa9bc4698b35110f8 +size 5055 diff --git a/czishrink/.images/ShareBadgeExample.png.license b/czishrink/.images/ShareBadgeExample.png.license new file mode 100644 index 0000000..cfacb07 --- /dev/null +++ b/czishrink/.images/ShareBadgeExample.png.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH + +SPDX-License-Identifier: GPL-3.0-or-later diff --git a/czishrink/.vscode/launch.json b/czishrink/.vscode/launch.json new file mode 100644 index 0000000..42947bb --- /dev/null +++ b/czishrink/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/netczicompress.Desktop/bin/x64/Debug/net7.0/CziShrink", + "args": [], + "cwd": "${workspaceFolder}/netczicompress.Desktop", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/czishrink/.vscode/settings.json b/czishrink/.vscode/settings.json new file mode 100644 index 0000000..d09b546 --- /dev/null +++ b/czishrink/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dotnet.defaultSolution": "netczicompress.sln" +} \ No newline at end of file diff --git a/czishrink/.vscode/tasks.json b/czishrink/.vscode/tasks.json new file mode 100644 index 0000000..2b17345 --- /dev/null +++ b/czishrink/.vscode/tasks.json @@ -0,0 +1,70 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/netczicompress.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/netczicompress.Desktop/netczicompress.Desktop.csproj", + "-c", "Release", + "--use-current-runtime", "true", + "--self-contained", + "-p:PublishSingleFile=true", + "-p:PublishReadyToRun=true", + "-p:PublishReadyToRunShowWarnings=true" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "Watch (Tests)", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "test", + "--project", + "netczicompressTests" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "Test with Coverage", + "command": "dotnet", + "type": "process", + "args": [ + "test", + "/p:CollectCoverage=true", + "/p:CoverletOutputFormat=lcov%2ccobertura", + "/p:CoverletOutput=${workspaceFolder}/coverage/", + "/p:ExcludeByAttribute=GeneratedCodeAttribute%2cObsoleteAttribute", + "/p:ExcludeByFile=**/*.axaml%2c**/*.g.cs", + "/p:Exclude=[netczicompress]netczicompress.Views.*" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "Generate coverage report", + "command": "reportgenerator", + "type": "shell", + "args": [ + "-reports:${workspaceFolder}/coverage/coverage.info", + "-targetdir:${workspaceFolder}/coverage/covstats" + ], + "problemMatcher": [] + } + ] +} diff --git a/czishrink/CodeAnalysis.ruleset b/czishrink/CodeAnalysis.ruleset new file mode 100644 index 0000000..f0d70a0 --- /dev/null +++ b/czishrink/CodeAnalysis.ruleset @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/Directory.Build.props b/czishrink/Directory.Build.props new file mode 100644 index 0000000..d154d14 --- /dev/null +++ b/czishrink/Directory.Build.props @@ -0,0 +1,16 @@ + + + net7.0 + latest + enable + True + enable + true + $(MSBuildThisFileDirectory)CodeAnalysis.ruleset + True + true + + 1.0.0 + alpha.46 + + diff --git a/czishrink/Directory.Build.targets b/czishrink/Directory.Build.targets new file mode 100644 index 0000000..7976089 --- /dev/null +++ b/czishrink/Directory.Build.targets @@ -0,0 +1,11 @@ + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/czishrink/Directory.Packages.props b/czishrink/Directory.Packages.props new file mode 100644 index 0000000..626af95 --- /dev/null +++ b/czishrink/Directory.Packages.props @@ -0,0 +1,40 @@ + + + 4.18.0 + 11.0.5 + 19.5.1 + 19.2.69 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/czishrink/LICENSE.txt b/czishrink/LICENSE.txt new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/czishrink/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/czishrink/NuGet.config b/czishrink/NuGet.config new file mode 100644 index 0000000..1475046 --- /dev/null +++ b/czishrink/NuGet.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/czishrink/README.md b/czishrink/README.md new file mode 100644 index 0000000..d913df3 --- /dev/null +++ b/czishrink/README.md @@ -0,0 +1,152 @@ +# CziShrink +An open source and cross-platform GUI for [CziCompress](https://github.com/ZEISS/czicompress), made with Avalonia UI and .NET. + +## Table of contents + + - [Overview](#overview) + - [Download](#download) + - [System Requirements](#system-requirements) + - [Theme Support](#theme-support) + - [I/O](#io) + - [Parameters](#parameters) + - [Operations](#operations) + - [Progress Update](#progress-update) + - [Compression Statistics](#compression-statistics) + - [Sharing](#sharing) + - [Errors](#errors) + - [Logs](#logs) + - [FAQ](#faq) + - [Known Issues](#known-issues) + - [Potential Future Enhancements](#potential-future-enhancements) + - [Feedback](#feedback) + +## Overview + +## System Requirements + +### Windows + - Windows 10 or later +### Linux + - Supported OS: + - Debian 9 (Stretch) and higher + - Ubuntu 16.04 and higher + - X11 + - Clipboad functionality requires xclip to be installed + +## Theme Support +Dark and a light themes are set automatically based on your OS settings. +There is currently no way to manually set this. + +![Light Theme](.images/CziShrink_LightTheme.png)![Dark Theme](.images/CziShrink_DarkTheme.png) + +## I/O + +Input and output folders are selected, and the tool will operate on all CZI-documents within the input folder. +The intent of the tool is to be a bulk-compression utility. + +## Parameters + +### Operations + +| Operation | Description | +|-----------|-------------| +| Compress uncompressed data |Compresses only uncompressed subblocks and copies others.| +| Compress uncompressed and Zstd-compressed data|Compresses subblocks that were originally uncompressed or compressed with zstd. | +| Compress all data |Compresses all subblocks regardless of current compression method (if possible). | +| Decompress all data |Decompresses all possible subblocks. | +| Dry Run |Finds all CZI files in the input folder but does not create any output CZI files. Like the other operations, it creates a CSV report in the output folder.| + +## Progress Update +CZI Shrink scans the input folder for CZI files. +And whenever it finds one, the file is immediately queued for processing. +CZI Shrink will usually process several files in parallel, depending on the state of the queue and the number of CPUs in your computer. +Progress is displayed for all files that are currently being processed. + +![Progress Updates](.images/Progress.png) + +## Compression Statistics + +Compression statistics are updated during the operation. +They provide some insight about what is going on. + +![Compression Statistics](.images/CompressionStatistics.png) + +### Sharing + +Upon completing an operation a new button should appear which will copy a bitmap to your clipboard containing a badge showing off how much the application was able to compress your files. + +![Compression Statistics Badge](.images/ShareBadgeExample.png) + +## Errors + +Files that are unable to be (un)compressed will appear in the bottom dialog with their error message. These entries can also be found in the [log file](#logs). +The error list also allows navigating directly to the files in question. + +![Error List](.images/ErrorFileOptions.png) + + +## Logs + +Logs are saved in the output directory. +The filename of this log is constructed as `CziShrink__`. +The timestamp itself is in the form of `T` while the `COMPRESSION_OPTION` will correspond +to the operation selected in the UI. + +Logs are produced during operation, however flushing of buffer to file does not occur as fast +as possible, so you may notice/experience a latency between the tasks that appear on the UI and +the actual entries written. +In some cases you may see no log output until the operation has completed if a reasonably constrained input directory is chosen. + +### Format +| InputFile | SizeInput | SizeOutput | SizeRatio | SizeDelta | TimeToProcess | Status | ErrorMessage| +| ----------|-----------|------------|-----------|-----------|---------------|--------|-------------| +| Sample_file.czi | 696480 | 564992 |0.811210659| 131488 | 00:00:00.0672709 |SUCCESS|| +| Sample_file2.czi| 1107888032 | 0 | 0 | -1 | |ERROR | Illegal data detected at offset 235352768 -> Invalid SubBlock-magic | +## FAQ +- Is the compression lossy? + - The tool uses [Zstandard](https://github.com/facebook/zstd) which is a fast and lossless compression algorithm. +- What happens to files that the tool is not able to compress? Are they still copied to the output folder? + - The file is not copied to the output folder and a log entry detailing the error is produced. + + +## Known Issues + +- Folder enumeration fails on network drives if connection drops. +- Non-X-Y-subblock CZIs will produce an error when attempting to compress. +- Multi-file CZI can't be converted. + - Ensure file is not currently opened in ZEN. +- Error encountered while compression file rarely causes creation of a corrupted output czi file. + +## Potential Future Enhancements + +This is a list of possible future enhancements based on feedback. +Any item on this list may be added or removed at any point in time based on prioritization. +There is no guarantee that any items on this list will be added, rather it is just to show what topics are on the radar. +- Localization +- Cache/Remember previously used options (folders, compression, etc) per-user + +## Contributing + +### Notes for Contributors +* Test changes at least on Linux and Windows. +* Note that the app will change appearance when the system theme is changed (Windows: Settings -> Personalization -> Colors -> Choose your colors: Light/Dark/Custom). Make sure that GUI changes look good both in the Light and in the Dark Theme. See https://docs.avaloniaui.net/docs/next/guides/styles-and-resources/how-to-use-theme-variants + +## How to upgrade libczicompressc automatically +1. Create a 'classic' personal access token at https://github.com/settings/tokens, authorize it for the ZEISS organization via the "Configure SSO" button, and store it in a GITHUB_TOKEN environment variable. +2. Open a Powershell terminal and run [./upgrade-libczicompressc.ps1](./upgrade-libczicompressc.ps1). Run `get-help ./upgrade-libczicompressc.ps1` for more info. + +## How to upgrade libczicompressc manually +1. Build libczicompressc.so on linux-x64 and libczicompressc.dll on win-x64 in release mode, or (preferred) get them from the [github CI build](https://github.com/ZEISS/czicompress/actions/workflows/czicompress_cmake.yml). +1. Put the binaries into [libczicompressc/runtimes/linux-x64/native](libczicompressc/runtimes/linux-x64/native) and [libczicompressc/runtimes/win-x64/native](libczicompressc/runtimes/win-x64/native) +1. Update the nuspec file [libczicompressc/libczicompressc.nuspec](libczicompressc/libczicompressc.nuspec): + * `package/metadata/version` must be the 'ProductVersion' of libczicompressc.dll (explorer: Properties/Details) + * `package/metadata/repository[@commit]` must be the git commit from which the binaries were built +1. [Install nuget if necessary](https://learn.microsoft.com/en-us/nuget/install-nuget-client-tools#cli-tools). +1. Open a shell in [libczicompressc](libczicompressc), and run `path/to/nuget pack libczicompressc.nuspec` +1. Move the resulting nupkg into [packages_local](packages_local) and delete the old package from there. +1. Change the version of libczicompressc in [Directory.Packages.props](Directory.Packages.props) +1. If major or minor version has changed, change the expected version number in [PInvokeFileProcessor](netczicompress/Models/PInvokeFileProcessor.cs). +1. Rebuild netczicompress.sln +1. Run netczicompressTests +1. Undo git changes to the libczicompressc.dll and libczicompressc.so files (no need to commit them, they are in the nupkg). +1. Commit the remaining changes with message "Upgrade libczicompressc to new version: x.y.z" diff --git a/czishrink/README.pdf b/czishrink/README.pdf new file mode 100644 index 0000000..ee9c7f5 Binary files /dev/null and b/czishrink/README.pdf differ diff --git a/czishrink/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt b/czishrink/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt new file mode 100644 index 0000000..5c2321b --- /dev/null +++ b/czishrink/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt @@ -0,0 +1,2289 @@ +============= Free and Open Source Software Disclosure Statement ============== + +For czishrink + +This product includes copyrighted software from third parties that may be +distributed under different licenses than this product as given below. + +In case we missed to list a specific software and/or underlying license, +we appreciate your upfront notice. + +This product may include copyrighted software that is distributed under a +license that requires us to provide the source code of that software and +instructions on how to build and install it, such as the GNU GPL or GNU +LGPL or other reciprocal licenses. Unless otherwise stated the original +source code of such software has not been modified. As recipient and user of +this product you may obtain the complete source code for such copyrighted +software as well as build and install instructions from us for a period of +three years starting with the reception of the product and valid for as +long as we offer spare parts or customer support for that product model +and at no charge. + +In any of such cases, please send an email to opensource@zeiss.com +referencing your product's name, version, and manufacturing ZEISS entity. + + +List of third-party software: +----------------------------------- + +=============================================================================== + +------------------------------------------------------------------------------- +| Avalonia (used under MIT License) https://github.com/AvaloniaUI/Avalonia +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) .NET Foundation and Contributors All Rights Reserved + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Copyright (c) .NET Foundation and Contributors All Rights Reserved + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Splat (used under MIT License) https://github.com/reactiveui/splat +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) .NET Foundation and Contributors + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| System.IO.Abstractions (used under MIT License) https://github.com/TestableIO/System.IO.Abstractions +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Tatham Oddie and Contributors + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| MicroCom (used under MIT License) https://github.com/kekekeks/MicroCom +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2021 Nikita Tsukanov + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Markdown.Avalonia (used under MIT License) https://github.com/whistyun/Markdown.Avalonia +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2010 Bevan Arps, 2020 Whistyun + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Icons.Avalonia (used under MIT License) https://github.com/Projektanker/Icons.Avalonia +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2020 Projektanker + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| MessageBox.Avalonia (used under MIT License) https://github.com/AvaloniaCommunity/MessageBox.Avalonia +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2019 CreateLab + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Reactive.UI (used under MIT License) https://github.com/reactiveui/reactiveui +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) .NET Foundation and Contributors + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Fody (used under MIT License) https://github.com/Fody/Fody +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Simon Cropp + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| InlineIL.Fody (used under MIT License) https://github.com/ltrzesniewski/InlineIL.Fody +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2018 Lucas Trzesniewski + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| SkiaSharp (used under MIT License) https://github.com/mono/SkiaSharp +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2015-2016 Xamarin, Inc. +Copyright (c) 2017-2018 Microsoft Corporation. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Tmds.DBus (used under MIT License) https://github.com/tmds/Tmds.DBus +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright 2006 Alp Toker +Copyright 2010 Other Contributors +Copyright 2016 Tom Deseyn + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Newtonsoft.Json (used under MIT License) https://github.com/JamesNK/Newtonsoft.Json +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2007 James Newton-King + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +------------------------------------------------------------------------------- +| WPF (used under MIT License) https://github.com/dotnet/wpf +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) .NET Foundation and Contributors All Rights Reserved + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Copyright (c) .NET Foundation and Contributors All Rights Reserved + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| SharpDX (used under MIT License) https://github.com/sharpdx/SharpDX +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2010-2014 SharpDX - Alexandre Mutel + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Copyright (c) 2010-2014 SharpDX - Alexandre Mutel + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Silverlight Toolkit (used under Microsoft Public License) https://github.com/microsoftarchive/SilverlightToolkit +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Microsoft Public License (MS-PL) + +This license governs use of the accompanying software. If you use the software, +you accept this license. If you do not accept the license, do not use the software. + +Definitions The terms "reproduce," "reproduction," "derivative works," and +"distribution" have the same meaning here as under U.S. copyright law. A +"contribution" is the original software, or any additions or changes to the +software. A "contributor" is any person that distributes its contribution under +this license. "Licensed patents" are a contributor's patent claims that read +directly on its contribution. + +Grant of Rights (A) Copyright Grant- Subject to the terms of this license, +including the license conditions and limitations in section 3, each contributor +grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce +its contribution, prepare derivative works of its contribution, and distribute its +contribution or any derivative works that you create. (B) Patent Grant- Subject +to the terms of this license, including the license conditions and limitations in +section 3, each contributor grants you a non-exclusive, worldwide, royalty-free +license under its licensed patents to make, have made, use, sell, offer for sale, +import, and/or otherwise dispose of its contribution in the software or derivative +works of the contribution in the software. + +Conditions and Limitations (A) No Trademark License- This license does not grant +you rights to use any contributors' name, logo, or trademarks. (B) If you bring a +patent claim against any contributor over patents that you claim are infringed by +the software, your patent license from such contributor to the software ends +automatically. (C) If you distribute any portion of the software, you must retain +all copyright, patent, trademark, and attribution notices that are present in the +software. (D) If you distribute any portion of the software in source code form, +you may do so only under this license by including a complete copy of this license +with your distribution. If you distribute any portion of the software in compiled +or object code form, you may only do so under a license that complies with this +license. (E) The software is licensed "as-is." You bear the risk of using it. +The contributors give no express warranties, guarantees or conditions. You may +have additional consumer rights under your local laws which this license cannot +change. To the extent permitted under your local laws, the contributors exclude +the implied warranties of merchantability, fitness for a particular purpose +and non-infringement. + +------------------------------------------------------------------------------- +| wayland-protocols (used under MIT License) https://github.com/wayland-project/wayland-protocols +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright © 2008-2013 Kristian Høgsberg +Copyright © 2010-2013 Intel Corporation +Copyright © 2013 Rafael Antognolli +Copyright © 2013 Jasper St. Pierre +Copyright © 2014 Jonas Ådahl +Copyright © 2014 Jason Ekstrand +Copyright © 2014-2015 Collabora, Ltd. +Copyright © 2015 Red Hat Inc.l + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Metsys.Bson +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2010, Karl Seguin - https://www.openmymind.net/ All rights reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: * Redistributions +of source code must retain the above copyright notice, this list of conditions +and the following disclaimer. * Redistributions in binary form must reproduce +the above copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the distribution. +* Neither the name of the nor the names of its contributors may be used to +endorse or promote products derived from this software without specific prior +written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| RichTextKit (used under Apache License, Version 2.0) https://github.com/toptensoftware/RichTextKit +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright © 2019 Topten Software. All Rights Reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this product except in compliance with the License. You may obtain a copy of the +License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +------------------------------------------------------------------------------- +| Mono (used under MIT License) https://github.com/mono/mono +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Collections.Pooled (used under MIT License) https://github.com/jtmueller/Collections.Pooled +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Joel Mueller + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| EllipticalArc.java (used under MIT License) http://www.spaceroots.org/documents/ellipse/EllipticalArc.java +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2003-2004, Luc Maisonobe All rights reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| WinUI (used under MIT License) https://github.com/microsoft/microsoft-ui-xaml +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Microsoft Corporation. All rights reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Chromium (used under BSD 3-Clause) https://github.com/chromium/chromium +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright 2015 The Chromium Authors. All rights reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google LLC nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| Flutter (used under BSD 3-Clause) https://github.com/flutter/flutter +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright 2014 The Flutter Authors. All rights reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google LLC nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| Reactive Extensions (used under MIT License) https://github.com/dotnet/reactive +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) .NET Foundation and Contributors + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| CziCompress (used under MIT License) https://github.com/ZEISS/czicompress +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2023 Carl Zeiss Microscopy GmbH + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| Catch2 3.4.0 (used under Boost Software License 1.0) https://discord.gg/4CWS9zD +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Boost Software License - Version 1.0 +==================================== + + +August 17th, 2003 +----------------- + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| CLIUtils/CLI11 v2.3.2 (used under BSD 3-clause "New" or "Revised" License) https://cliutils.gitlab.io/CLI11Tutorial +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2017-2023 University of Cincinnati, developed by Henry Schreiner under NSF AWARD 1414736. All Rights Reserved. +Copyright (c) 2012 - 2017, Lars Bilke. All Rights Reserved. +Copyright (c) 2017-2023 University of Cincinnati, developed by Henry Schreiner. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| D3.js 3.5.17 (used under BSD 3-clause "New" or "Revised" License) http://d3js.org/ +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2010 Stanford Visualization Group. All Rights Reserved. +Copyright (c) 2011 Jason Davies. All Rights Reserved. +Copyright 2001 Robert Penner. All Rights Reserved. +Copyright (c) 2008-2012 Charles Karney. +Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State. +Copyright (c) 2010 SimpleGeo and Stamen Design. All Rights Reserved. +Copyright (c) 2010-2016 Michael Bostock. All Rights Reserved. +Copyright (C) 2010-2013 Raymond Hill. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) 2010, Stanford Visualization Group +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of Stanford University nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + +------------------------------------------------------------------------------- +| gmdh 1.0 (used under MIT License) https://github.com/bauman-team/GMDH +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright 2001-2009 Kitware, Inc. +Copyright (C) 2018 David Hyde. +Copyright (C) 2009 Benjamin Schindler. +Copyright 2012 Continuum Analytics, Inc. All Rights Reserved. +Copyright (C) 2002-2007 Yves Renard This file is a part of GETFEM++. +Copyright (C) 2021 Chip Kerchner (chip. kerchner@ibm.com). +Copyright (C) 2011 Timothy E. Holy. +Copyright (c) 2021 NVIDIA CORPORATION. All Rights Reserved. +Copyright (C) 2020 Jens Wehner. +Copyright 2017 The TensorFlow Authors. All Rights Reserved. +Copyright 2013-2016 Florent Pruvost. +Copyright (C) EDF R. +Copyright (C) 2012 Desire Nuentsa Wakam. +Copyright (C) 2009-2013 Jitse Niesen. +Copyright (C) 2009 Ilya Baran. +(C) William Swanson, Paul Fultz define PYBIND11_EVAL0(...) __VA_ARGS__ define PYBIND11_EVAL1(...) PYBIND11_EVAL0(PYBIND11_EVAL0(PYBIND11_EVAL0(__VA_ARGS__))) define PYBIND11_EVAL2( +Copyright (C) 2018 Mehdi Goli Codeplay Software Ltd. +Copyright (C) 2013 Pavel Holoborodko. +Copyright (c) 2016-2017, 2020 Wenzel Jakob. All Rights Reserved. +Copyright : EDF 2001 $Header$. +Copyright (C) 2014 yoco. +Copyright (C) 2013 Jean Ceccato. +Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved. +Copyright (C) 2011-2013 Chen-Pang He. +Copyright (C) 2006-2011, 2015 Benoit Jacob. +copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All Rights Reserved. +Copyright (c) 2019 Dawid Pilarski. +Copyright (C) 2013 Pierre Zoppitelli. +Copyright (C) 2020 Everton Constantino. +Copyright (C) 2019 David Tellenbach. +(C) Desire NUENTSA WAKAM, INRIA include include include include include include include +Copyright (C) 2008 Gael Guennebaud Adapted from FindEigen. cmake:. +Copyright (c) 2016 Sergey Lyskov and Wenzel Jakob. +(C) Desire NUENTSA WAKAM, INRIA include include include include include include ifd +Copyright (c) Fabian Giesen, 2016. All Rights Reserved. +Copyright (c) 1994 by Xerox Corporation. All Rights Reserved. +Copyright (C) 2012 Alexey Korepanov. +Copyright (C) 1998-2010, 2015-2016. +Copyright (c) 2020 Wenzel Jakob and Henry Schreiner. +Copyright (C) 2015-2016 Eugene Brevdo. +Copyright (C) 2011 Andreas Platen. +Copyright (C) 2017 Viktor Csomor. +Copyright (C) 2020 Antonio Sanchez. +Copyright (c) 2017 Henry F. Schreiner. +Copyright (C) 2017 Kyle Macfarlan. +Copyright (C) 2012-2013 D. +Copyright (C) 2009 Thomas Capricelli This code initially comes from MINPACK whose original authors are:. +Copyright (C) 2008 Daniel Gomez Ferro. +Copyright (C) 2013 Nicolas Carre. +Copyright (C) 2012 David Harmon. +Copyright (c) 2014-2015 Open Source Robotics Foundation. All Rights Reserved. +Copyright (c) 2021 Laramie Leavitt (Google LLC). +Copyright (C) 2014, 2016 Benoit Steiner (benoit. steiner.goog@gmail.com). +Copyright (c) 2019 Roland Dreier. +copyright (c) 2009-2014 The University of Tennessee and The University of Tennessee Research Foundation. All Rights Reserved. +Copyright (C) 2016 Dmitry Vyukov. +Copyright (c) 2007 Allen Winter. +Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd. +Copyright (c) 2006-2007 Montel Laurent. +Copyright (C) 2009 Mark Borgerding mark a borgerding net. +Copyright (C) 2014, 2016 Pedro Gonnet (pedro. gonnet@gmail.com). +Copyright (C) 2009 Ricard Marxer. +Copyright (c) 2016 Sergey Lyskov. +Copyright 2003-2009 Mark Borgerding template struct kiss_cpx_fft. +Copyright 2012-2013 Mathieu Faverge. +Copyright (C) 2016 Igor Babuschkin. +Copyright (C) 2009 Kenneth Riddile. +Copyright (C) 1989, 1991, 1999, 2007 Free Software Foundation, Inc. +Copyright (C) 2005 the Regents of the University of Minnesota. +Copyright (c) 2007 Alexander Neundorf. +Copyright 2018-2019, 2022 Google LLC. All Rights Reserved. +Copyright (C) 2019 Joel Holdsworth. +Copyright (c) 1998-2003 by the University of Florida. All Rights Reserved. +Copyright (c) 2001, 2011 Intel Corporation. All Rights Reserved. Permition is granted to use, copy, distribute and prepare derivative works of this library for any purpose and without fee, provided, that the above. +Copyright (C) 2020 Jan van Dijk. +Copyright (C) 2009 Rohit Garg. +Copyright (c) 2017 Borja Zarco (Google LLC). +Copyright (C) 2009-2010 Thomas Capricelli. +Copyright (C) 2020 Arm Limited and Contributors. +Copyright (C) 2015 Vijay Vasudevan. +Copyright (C) 2009 Claire Maurice. +Copyright (C) 2017 Codeplay Software Limited. +Copyright (C) 2014-2015 Jianwei Cui. +Copyright (C) 2009-2013 Hauke Heibel. +Copyright (C) 2010 Vincent Lejeune. +Copyright (C) 2008-2009 Guillaume Saupin. +Copyright (C) 2020 Sebastien Boisvert. +Copyright (C) 2009 Mathieu Gautier. +Copyright (C) 2013 Christoph Hertzberg. +Copyright (C) 2008 Gael Guennebaud NOTE The functions of this file have been adapted from the GMM++ library. +Copyright (C) 2012-2013 Desire Nuentsa. +Copyright (C) 2017 Gagan Goel. +Copyright (C) 2014-2017 Benoit Steiner. +Copyright (C) 2020-2021 C. Antonio Sanchez. +Copyright (c) 2018 Hudson River Trading LLC. +Copyright (C) 2014-2015 Navdeep Jaitly. +Copyright (C) 2009 Thomas Capricelli include. +Copyright (c) 2016-2017 Jason Rhinelander. +Copyright (c) 2016 Pim Schellart. +Copyright (C) 2012 The Android Open Source Project. +Copyright (C) 2016, 2018-2019 Rasmus Munk Larsen. +Copyright (c) 2016 Ivan Smirnov. +Copyright (C) 2007 Michael Olbrich. +Copyright (c) 2020 The Eigen Authors. +Copyright (c) 2009 Boudewijn Rempt. +Copyright (C) 2012 desire Nuentsa. +(C) Copyright .. +Copyright 2012 Cedric Castagnede. +Copyright (C) 2012 Desire Nuentsa This code initially comes from MINPACK whose original authors are:. +Copyright (C) 2008-2019 Gael Guennebaud. +Copyright (C) 2012 Giacomo Po. +Copyright (c) 2016 Ben North. +copyright: (c) 2013 by Ihor Kalnytskyi +Copyright (C) 2018 Andy Davis. +Copyright 1984-1985, 1987, 1992, 2000 by Stephen L. Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140 const Scalar zero = 0; const Scalar one = 1; const Scalar nan = Moshier Permission has been kindly provided by the original author to incorporate the Cephes software into the Eigen codebase: Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140. +Copyright 2012-2016 Inria. All Rights Reserved. +Copyright (C) 2008-2009 Gael Guennebaud NOTE The class IterationController has been adapted from the iteration. +Copyright (C) 2013 Christian Seiler. +Copyright (C) 2009, 2012 Keir Mierle. +Copyright (c) 2016 Klemens D. Morgenstern. +Copyright (c) 2010 Intel Corp. All Rights Reserved. +Copyright (C) 2015 Gael Guennebaud Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditio. +Copyright (C) 2008-2016 Konstantinos Margaritis. +Copyright (c) 2006 Timothy A. Davis. +Copyright (c) 2011-2014 Willow Garage, Inc. +Copyright (C) 2016 Tobias Wood. +Copyright (C) 2011-2012, 2014 Kolja Brix. +Copyright (C) 2010 Manuel Yguel. +Copyright (C) 2015 Tal Hadad. +Copyright (C) 1997-2001 Authors: Andrew Lumsdaine Lie-Quan Lee This file is part of the Iterative Template Library. +Copyright (C) 2015 Ke Yang. +Copyright 2005-2010, 2013, 2015, 2018-2021 Google Inc. All Rights Reserved. +Copyright (C) 2018 Eugene Zhulenev. +Copyright (C) 2007 Julien Pommier. +Copyright (C) 2018 Wave Computing, Inc. Written by:. +Copyright 2016-2018 Codeplay Software Ltd. +Copyright (C) 2012 Desire Nuentsa The algorithm of this. +Copyright (c) 2016 Klemens Morgenstern and. +Copyright (C) 2012 Desire NUENTSA WAKAM. +Copyright (c) 2012 Erik Edlund Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions a. +Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google. com). +Copyright (C) 2018 Deven Desai. +Copyright (C) 2020 Chris Schoutrop. +Copyright (C) 2010 Daniel Lowengrub. +Copyright 2012-2013 Emmanuel Agullo. +Copyright (C) 2014 Eric Martin. +Copyright (c) 2016 Trent Houliston and. +Copyright (C) 2020 Everton Constantino (everton. constantino@ibm.com). +Copyright (c) 2019 Pranav. +Copyright (C) 2013 Gauthier Brun. +Copyright (c) 2021 The Pybind Development Team. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License +=============== + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| libeigen/eigen 3.4.0 (used under (GNU Lesser General Public License v2.1 or later AND BSD 3-clause "New" or "Revised" License AND Mozilla Public License 2.0)) https://gitlab.com/libeigen/eigen.git +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (C) 2018 David Hyde. +Copyright (C) 2009 Benjamin Schindler. +Copyright (C) 2021 Chip Kerchner (chip. kerchner@ibm.com). +Copyright (C) 2011 Timothy E. Holy. +Copyright (c) 2021 NVIDIA CORPORATION. All Rights Reserved. +Copyright (C) 2020 Jens Wehner. +Copyright 2017 The TensorFlow Authors. All Rights Reserved. +Copyright 2013-2016 Florent Pruvost. +Copyright (C) EDF R. +Copyright (C) 2012 Desire Nuentsa Wakam. +Copyright (C) 2009-2013 Jitse Niesen. +Copyright (C) 2009 Ilya Baran. +Copyright (C) 2018 Mehdi Goli Codeplay Software Ltd. +Copyright (C) 2013 Pavel Holoborodko. +Copyright : EDF 2001 $Header$. +Copyright (C) 2014 yoco. +Copyright (C) 2013 Jean Ceccato. +Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved. +Copyright (C) 2011-2013 Chen-Pang He. +Copyright (C) 2006-2011, 2015 Benoit Jacob. +copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All Rights Reserved. +Copyright (C) 2013 Pierre Zoppitelli. +Copyright (C) 2020 Everton Constantino. +Copyright (C) 2019 David Tellenbach. +Copyright (C) 2008 Gael Guennebaud Adapted from FindEigen. cmake:. +Copyright (c) Fabian Giesen, 2016. All Rights Reserved. +Copyright (c) 1994 by Xerox Corporation. All Rights Reserved. +Copyright (C) 2012 Alexey Korepanov. +Copyright (C) 1998-2010, 2015-2016. +Copyright (C) 2015-2016 Eugene Brevdo. +Copyright (C) 2011 Andreas Platen. +Copyright (C) 2017 Viktor Csomor. +Copyright (C) 2020 Antonio Sanchez. +Copyright 2003-2009 Mark Borgerding. +Copyright (C) 2017 Kyle Macfarlan. +Copyright (C) 2012-2013 D. +Copyright (C) 2008 Daniel Gomez Ferro. +Copyright (C) 2013 Nicolas Carre. +Copyright (C) 2012 David Harmon. +Copyright (c) 2014-2015 Open Source Robotics Foundation. All Rights Reserved. +Copyright (C) 2014, 2016 Benoit Steiner (benoit. steiner.goog@gmail.com). +Copyright (C) 2015 Gael Guennebaud Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions. +copyright (c) 2009-2014 The University of Tennessee and The University of Tennessee Research Foundation. All Rights Reserved. +Copyright (C) 2016 Dmitry Vyukov. +Copyright (c) 2007 Allen Winter. +Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd. +Copyright (c) 2006-2007 Montel Laurent. +Copyright (C) 2009 Mark Borgerding mark a borgerding net. +Copyright (C) 2014, 2016 Pedro Gonnet (pedro. gonnet@gmail.com). +Copyright (C) 2009 Ricard Marxer. +Copyright 2012-2013 Mathieu Faverge. +Copyright (C) 2016 Igor Babuschkin. +Copyright (C) 2009 Kenneth Riddile. +Copyright (C) 1989, 1991, 1999, 2007 Free Software Foundation, Inc. +Copyright (C) 2005 the Regents of the University of Minnesota. +Copyright (c) 2007 Alexander Neundorf. +Copyright (C) 2019 Joel Holdsworth. +Copyright (c) 1998-2003 by the University of Florida. All Rights Reserved. +Copyright (C) 2002-2007 Yves Renard. +Copyright (C) 2020 Jan van Dijk. +Copyright (C) 2008-2019, 20013, 20015 Gael Guennebaud. +Copyright (C) 2009 Rohit Garg. +Copyright (C) 2009-2010 Thomas Capricelli. +Copyright (C) 2020 Arm Limited and Contributors. +Copyright (C) 2015 Vijay Vasudevan. +Copyright (C) 2009 Claire Maurice. +Copyright (C) 2017 Codeplay Software Limited. +Copyright (C) 2014-2015 Jianwei Cui. +Copyright 1984-1985, 1987, 1992, 2000 by Stephen L. Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140 Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140 const Scalar zero = 0; const Scalar one = 1; const Scalar nan = NumTr Moshier. +Copyright (C) 2009-2013 Hauke Heibel. +Copyright (C) 2010 Vincent Lejeune. +Copyright (C) 2008-2009 Guillaume Saupin. +Copyright (C) 2020 Sebastien Boisvert. +Copyright (C) 2009 Mathieu Gautier. +Copyright (C) 2013 Christoph Hertzberg. +Copyright (C) 2012-2013 Desire Nuentsa. +Copyright (C) 2017 Gagan Goel. +Copyright (C) 2014-2017 Benoit Steiner. +Copyright (C) 2020-2021 C. Antonio Sanchez. +Copyright (C) 2014-2015 Navdeep Jaitly. +Copyright (C) 1997-2001 Authors: Andrew Lumsdaine Lie-Quan Lee. +Copyright (C) 2012 The Android Open Source Project. +Copyright (C) 2016, 2018-2019 Rasmus Munk Larsen. +Copyright (c) 2001, 2011 Intel Corporation. All Rights Reserved. +Copyright (C) 2007 Michael Olbrich. +Copyright (c) 2020 The Eigen Authors. +Copyright (c) 2009 Boudewijn Rempt. +Copyright (C) 2012 desire Nuentsa. +Copyright 2012 Cedric Castagnede. +Copyright (C) 2012 Giacomo Po. +Copyright (C) 2018 Andy Davis. +Copyright 2012-2016 Inria. All Rights Reserved. +Copyright (C) 2013 Christian Seiler. +Copyright (C) 2009, 2012 Keir Mierle. +Copyright 2007-2009 Kitware, Inc. +Copyright (C) 2008-2016 Konstantinos Margaritis. +Copyright (c) 2006 Timothy A. Davis. +Copyright (c) 2011-2014 Willow Garage, Inc. +Copyright (C) 2016 Tobias Wood. +Copyright (C) 2011-2012, 2014 Kolja Brix. +Copyright (C) 2010 Manuel Yguel. +Copyright (C) 2015 Tal Hadad. +Copyright (C) 2015 Ke Yang. +Copyright (C) 2018 Eugene Zhulenev. +Copyright (C) 2007 Julien Pommier. +Copyright (C) 2018 Wave Computing, Inc. Written by:. +Copyright 2016-2018 Codeplay Software Ltd. +Copyright (C) 2012 Desire NUENTSA WAKAM. +Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google. com). +Copyright (C) 2018 Deven Desai. +Copyright (C) 2020 Chris Schoutrop. +(C) Desire NUENTSA WAKAM, INRIA +Copyright (C) 2010 Daniel Lowengrub. +Copyright 2012-2013 Emmanuel Agullo. +Copyright (C) 2014 Eric Martin. +Copyright (C) 2020 Everton Constantino (everton. constantino@ibm.com). +Copyright (C) 2013 Gauthier Brun. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +GNU Lesser General Public License +================================= + +Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Everyone is permitted to copy and distribute verbatim copies + + of this license document, but changing it is not allowed. + + [This is the first released version of the Lesser GPL. It also counts + + as the successor of the GNU Library Public License, version 2, hence + + the version number 2.1.] + + +Preamble +-------- + +The licenses for most software are designed to take away your freedom to share +and change it. By contrast, the GNU General Public Licenses are intended to +guarantee your freedom to share and change free software--to make sure the +software is free for all its users. + +This license, the Lesser General Public License, applies to some specially +designated software packages--typically libraries--of the Free Software +Foundation and other authors who decide to use it. You can use it too, but we +suggest you first think carefully about whether this license or the ordinary +General Public License is the better strategy to use in any particular case, +based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. +Our General Public Licenses are designed to make sure that you have the freedom +to distribute copies of free software (and charge for this service if you wish); +that you receive source code or can get it if you want it; that you can change +the software and use pieces of it in new free programs; and that you are informed +that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to +deny you these rights or to ask you to surrender these rights. These restrictions +translate to certain responsibilities for you if you distribute copies of the +library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a +fee, you must give the recipients all the rights that we gave you. You must make +sure that they, too, receive or can get the source code. If you link other code +with the library, you must provide complete object files to the recipients, so +that they can relink them with the library after making changes to the library +and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and +(2) we offer you this license, which gives you legal permission to copy, +distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no +warranty for the free library. Also, if the library is modified by someone else +and passed on, the recipients should know that what they have is not the original +version, so that the original author's reputation will not be affected by +problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free +program. We wish to make sure that a company cannot effectively restrict the +users of a free program by obtaining a restrictive license from a patent holder. +Therefore, we insist that any patent license obtained for a version of the +library must be consistent with the full freedom of use specified in this +license. + +Most GNU software, including some libraries, is covered by the ordinary GNU +General Public License. This license, the GNU Lesser General Public License, +applies to certain designated libraries, and is quite different from the ordinary +General Public License. We use this license for certain libraries in order to +permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared +library, the combination of the two is legally speaking a combined work, a +derivative of the original library. The ordinary General Public License therefore +permits such linking only if the entire combination fits its criteria of freedom. +The Lesser General Public License permits more lax criteria for linking other +code with the library. + +We call this license the "Lesser" General Public License because it does Less to +protect the user's freedom than the ordinary General Public License. It also +provides other free software developers Less of an advantage over competing +non-free programs. These disadvantages are the reason we use the ordinary General +Public License for many libraries. However, the Lesser license provides +advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the +widest possible use of a certain library, so that it becomes a de-facto standard. +To achieve this, non-free programs must be allowed to use the library. A more +frequent case is that a free library does the same job as widely used non-free +libraries. In this case, there is little to gain by limiting the free library to +free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs +enables a greater number of people to use a large body of free software. For +example, permission to use the GNU C Library in non-free programs enables many +more people to use the whole GNU operating system, as well as its variant, the +GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' +freedom, it does ensure that the user of a program that is linked with the +Library has the freedom and the wherewithal to run that program using a modified +version of the Library. + +The precise terms and conditions for copying, distribution and modification +follow. Pay close attention to the difference between a "work based on the +library" and a "work that uses the library". The former contains code derived +from the library, whereas the latter must be combined with the library in order +to run. + + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +--------------------------------------------------------------- + +0. This License Agreement applies to any software library or other program which +contains a notice placed by the copyright holder or other authorized party saying +it may be distributed under the terms of this Lesser General Public License (also +called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as +to be conveniently linked with application programs (which use some of those +functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been +distributed under these terms. A "work based on the Library" means either the +Library or any derivative work under copyright law: that is to say, a work +containing the Library or a portion of it, either verbatim or with modifications +and/or translated straightforwardly into another language. (Hereinafter, +translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making +modifications to it. For a library, complete source code means all the source +code for all modules it contains, plus any associated interface definition files, +plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by +this License; they are outside its scope. The act of running a program using the +Library is not restricted, and output from such a program is covered only if its +contents constitute a work based on the Library (independent of the use of the +Library in a tool for writing it). Whether that is true depends on what the +Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and disclaimer +of warranty; keep intact all the notices that refer to this License and to the +absence of any warranty; and distribute a copy of this License along with the +Library. + +You may charge a fee for the physical act of transferring a copy, and you may at +your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus +forming a work based on the Library, and copy and distribute such modifications +or work under the terms of Section 1 above, provided that you also meet all of +these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices stating + that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no charge to all + third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a table of + data to be supplied by an application program that uses the facility, other + than as an argument passed when the facility is invoked, then you must make + a good faith effort to ensure that, in the event an application does not + supply such function or table, the facility still operates, and performs + whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose + that is entirely well-defined independent of the application. Therefore, + Subsection 2d requires that any application-supplied function or table used + by this function must be optional: if the application does not supply it, + the square root function must still compute square roots.) + + These requirements apply to the modified work as a whole. If identifiable + sections of that work are not derived from the Library, and can be + reasonably considered independent and separate works in themselves, then + this License, and its terms, do not apply to those sections when you + distribute them as separate works. But when you distribute the same + sections as part of a whole which is a work based on the Library, the + distribution of the whole must be on the terms of this License, whose + permissions for other licensees extend to the entire whole, and thus to + each and every part regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or contest your + rights to work written entirely by you; rather, the intent is to exercise + the right to control the distribution of derivative or collective works + based on the Library. + + In addition, mere aggregation of another work not based on the Library with + the Library (or with a work based on the Library) on a volume of a storage + or distribution medium does not bring the other work under the scope of + this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License +instead of this License to a given copy of the Library. To do this, you must +alter all the notices that refer to this License, so that they refer to the +ordinary GNU General Public License, version 2, instead of to this License. (If a +newer version than version 2 of the ordinary GNU General Public License has +appeared, then you can specify that version instead if you wish.) Do not make any +other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so +the ordinary GNU General Public License applies to all subsequent copies and +derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into +a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, +under Section 2) in object code or executable form under the terms of Sections 1 +and 2 above provided that you accompany it with the complete corresponding +machine-readable source code, which must be distributed under the terms of +Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a +designated place, then offering equivalent access to copy the source code from +the same place satisfies the requirement to distribute the source code, even +though third parties are not compelled to copy the source along with the object +code. + +5. A program that contains no derivative of any portion of the Library, but is +designed to work with the Library by being compiled or linked with it, is called +a "work that uses the Library". Such a work, in isolation, is not a derivative +work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an +executable that is a derivative of the Library (because it contains portions of +the Library), rather than a "work that uses the library". The executable is +therefore covered by this License. Section 6 states terms for distribution of +such executables. + +When a "work that uses the Library" uses material from a header file that is part +of the Library, the object code for the work may be a derivative work of the +Library even though the source code is not. Whether this is true is especially +significant if the work can be linked without the Library, or if the work is +itself a library. The threshold for this to be true is not precisely defined by +law. + +If such an object file uses only numerical parameters, data structure layouts and +accessors, and small macros and small inline functions (ten lines or less in +length), then the use of the object file is unrestricted, regardless of whether +it is legally a derivative work. (Executables containing this object code plus +portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the +object code for the work under the terms of Section 6. Any executables containing +that work also fall under Section 6, whether or not they are linked directly with +the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work +that uses the Library" with the Library to produce a work containing portions of +the Library, and distribute that work under terms of your choice, provided that +the terms permit modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is +used in it and that the Library and its use are covered by this License. You must +supply a copy of this License. If the work during execution displays copyright +notices, you must include the copyright notice for the Library among them, as +well as a reference directing the user to the copy of this License. Also, you +must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable + source code for the Library including whatever changes were used in the + work (which must be distributed under Sections 1 and 2 above); and, if the + work is an executable linked with the Library, with the complete + machine-readable "work that uses the Library", as object code and/or source + code, so that the user can modify the Library and then relink to produce a + modified executable containing the modified Library. (It is understood that + the user who changes the contents of definitions files in the Library will + not necessarily be able to recompile the application to use the modified + definitions.) + + b) Use a suitable shared library mechanism for linking with the Library. A + suitable mechanism is one that (1) uses at run time a copy of the library + already present on the user's computer system, rather than copying library + functions into the executable, and (2) will operate properly with a + modified version of the library, if the user installs one, as long as the + modified version is interface-compatible with the version that the work was + made with. + + c) Accompany the work with a written offer, valid for at least three years, + to give the same user the materials specified in Subsection 6a, above, for + a charge no more than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy from a + designated place, offer equivalent access to copy the above specified + materials from the same place. + + e) Verify that the user has already received a copy of these materials or + that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must +include any data and utility programs needed for reproducing the executable from +it. However, as a special exception, the materials to be distributed need not +include anything that is normally distributed (in either source or binary form) +with the major components (compiler, kernel, and so on) of the operating system +on which the executable runs, unless that component itself accompanies the +executable. + +It may happen that this requirement contradicts the license restrictions of other +proprietary libraries that do not normally accompany the operating system. Such a +contradiction means you cannot use both them and the Library together in an +executable that you distribute. + +7. You may place library facilities that are a work based on the Library +side-by-side in a single library together with other library facilities not +covered by this License, and distribute such a combined library, provided that +the separate distribution of the work based on the Library and of the other +library facilities is otherwise permitted, and provided that you do these two +things: + + a) Accompany the combined library with a copy of the same work based on the + Library, uncombined with any other library facilities. This must be + distributed under the terms of the Sections above. + + b) Give prominent notice with the combined library of the fact that part of + it is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library +except as expressly provided under this License. Any attempt otherwise to copy, +modify, sublicense, link with, or distribute the Library is void, and will +automatically terminate your rights under this License. However, parties who have +received copies, or rights, from you under this License will not have their +licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. +However, nothing else grants you permission to modify or distribute the Library +or its derivative works. These actions are prohibited by law if you do not accept +this License. Therefore, by modifying or distributing the Library (or any work +based on the Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying the Library +or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), +the recipient automatically receives a license from the original licensor to +copy, distribute, link with or modify the Library subject to these terms and +conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement +or for any other reason (not limited to patent issues), conditions are imposed on +you (whether by court order, agreement or otherwise) that contradict the +conditions of this License, they do not excuse you from the conditions of this +License. If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, then as a +consequence you may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by all those +who receive copies directly or indirectly through you, then the only way you +could satisfy both it and this License would be to refrain entirely from +distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, and the +section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or +other property right claims or to contest validity of any such claims; this +section has the sole purpose of protecting the integrity of the free software +distribution system which is implemented by public license practices. Many people +have made generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that system; it is +up to the author/donor to decide if he or she is willing to distribute software +through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Library under this License may add an explicit geographical +distribution limitation excluding those countries, so that distribution is +permitted only in or among countries not thus excluded. In such case, this +License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the +Lesser General Public License from time to time. Such new versions will be +similar in spirit to the present version, but may differ in detail to address new +problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a +version number of this License which applies to it and "any later version", you +have the option of following the terms and conditions either of that version or +of any later version published by the Free Software Foundation. If the Library +does not specify a license version number, you may choose any version ever +published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs +whose distribution conditions are incompatible with these, write to the author to +ask for permission. For software which is copyrighted by the Free Software +Foundation, write to the Free Software Foundation; we sometimes make exceptions +for this. Our decision will be guided by the two goals of preserving the free +status of all derivatives of our free software and of promoting the sharing and +reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE +LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED +IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" +WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL +ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE +LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, +SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY +TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF +THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +END OF TERMS AND CONDITIONS + + +How to Apply These Terms to Your New Libraries +---------------------------------------------- + +If you develop a new library, and you want it to be of the greatest possible use +to the public, we recommend making it free software that everyone can +redistribute and change. You can do so by permitting redistribution under these +terms (or, alternatively, under the terms of the ordinary General Public +License). + +To apply these terms, attach the following notices to the library. It is safest +to attach them to the start of each source file to most effectively convey the +exclusion of warranty; and each file should have at least the "copyright" line +and a pointer to where the full notice is found. + + one line to give the library's name and an idea of what it does. + + Copyright (C) year name of author + + This library is free software; you can redistribute it and/or + + modify it under the terms of the GNU Lesser General Public + + License as published by the Free Software Foundation; either + + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + + but WITHOUT ANY WARRANTY; without even the implied warranty of + + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + + License along with this library; if not, write to the Free Software + + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, +if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a +sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in + + the library `Frob' (a library for tweaking knobs) written + + by James Random Hacker. + + signature of Ty Coon, 1 April 1990 + + Ty Coon, President of Vice + +That's all there is to it! + + +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Mozilla Public License +Version 2.0 +====================== + + +1. Definitions +-------------- + + 1.1. "Contributor" + + means each individual or legal entity that creates, contributes to the creation + of, or owns Covered Software. + + 1.2. "Contributor Version" + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. + + 1.3. "Contribution" + + means Covered Software of a particular Contributor. + + 1.4. "Covered Software" + + means Source Code Form to which the initial Contributor has attached the notice + in Exhibit A, the Executable Form of such Source Code Form, and Modifications + of such Source Code Form, in each case including portions thereof. + + 1.5. "Incompatible With Secondary Licenses" + + means + + a. + + that the initial Contributor has attached the notice described in Exhibit B + to the Covered Software; or + + b. + + that the Covered Software was made available under the terms of version 1.1 + or earlier of the License, but not also under the terms of a Secondary + License. + + 1.6. "Executable Form" + + means any form of the work other than Source Code Form. + + 1.7. "Larger Work" + + means a work that combines Covered Software with other material, in a separate + file or files, that is not Covered Software. + + 1.8. "License" + + means this document. + + 1.9. "Licensable" + + means having the right to grant, to the maximum extent possible, whether at the + time of the initial grant or subsequently, any and all of the rights conveyed + by this License. + + 1.10. "Modifications" + + means any of the following: + + a. + + any file in Source Code Form that results from an addition to, deletion + from, or modification of the contents of Covered Software; or + + b. + + any new file in Source Code Form that contains any Covered Software. + + 1.11. "Patent Claims" of a Contributor + + means any patent claim(s), including without limitation, method, process, and + apparatus claims, in any patent Licensable by such Contributor that would be + infringed, but for the grant of the License, by the making, using, selling, + offering for sale, having made, import, or transfer of either its Contributions + or its Contributor Version. + + 1.12. "Secondary License" + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public License, + Version 3.0, or any later versions of those licenses. + + 1.13. "Source Code Form" + + means the form of the work preferred for making modifications. + + 1.14. "You" (or "Your") + + means an individual or a legal entity exercising rights under this License. For + legal entities, "You" includes any entity that controls, is controlled by, or + is under common control with You. For purposes of this definition, "control" + means (a) the power, direct or indirect, to cause the direction or management + of such entity, whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial ownership of such + entity. + + +2. License Grants and Conditions +-------------------------------- + + + 2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive + license: + + a. + + under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, modify, + display, perform, distribute, and otherwise exploit its Contributions, + either on an unmodified basis, with Modifications, or as part of a Larger + Work; and + + b. + + under Patent Claims of such Contributor to make, use, sell, offer for sale, + have made, import, and otherwise transfer either its Contributions or its + Contributor Version. + + + 2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution become + effective for each Contribution on the date the Contributor first distributes + such Contribution. + + + 2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under this + License. No additional rights or licenses will be implied from the distribution + or licensing of Covered Software under this License. Notwithstanding + Section 2.1(b) above, no patent license is granted by a Contributor: + + a. + + for any code that a Contributor has removed from Covered Software; or + + b. + + for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. + + under Patent Claims infringed by Covered Software in the absence of its + Contributions. + + This License does not grant any rights in the trademarks, service marks, or + logos of any Contributor (except as may be necessary to comply with the notice + requirements in Section 3.4). + + + 2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to distribute + the Covered Software under a subsequent version of this License (see + Section 10.2) or under the terms of a Secondary License (if permitted under the + terms of Section 3.3). + + + 2.5. Representation + + Each Contributor represents that the Contributor believes its Contributions are + its original creation(s) or it has sufficient rights to grant the rights to its + Contributions conveyed by this License. + + + 2.6. Fair Use + + This License is not intended to limit any rights You have under applicable + copyright doctrines of fair use, fair dealing, or other equivalents. + + + 2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities +------------------- + + + 3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under the + terms of this License. You must inform recipients that the Source Code Form of + the Covered Software is governed by the terms of this License, and how they can + obtain a copy of this License. You may not attempt to alter or restrict the + recipients' rights in the Source Code Form. + + + 3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. + + such Covered Software must also be made available in Source Code Form, as + described in Section 3.1, and You must inform recipients of the Executable + Form how they can obtain a copy of such Source Code Form by reasonable + means in a timely manner, at a charge no more than the cost of distribution + to the recipient; and + + b. + + You may distribute such Executable Form under the terms of this License, or + sublicense it under different terms, provided that the license for the + Executable Form does not attempt to limit or alter the recipients' rights + in the Source Code Form under this License. + + + 3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for the + Covered Software. If the Larger Work is a combination of Covered Software with + a work governed by one or more Secondary Licenses, and the Covered Software is + not Incompatible With Secondary Licenses, this License permits You to + additionally distribute such Covered Software under the terms of such Secondary + License(s), so that the recipient of the Larger Work may, at their option, + further distribute the Covered Software under the terms of either this License + or such Secondary License(s). + + + 3.4. Notices + + You may not remove or alter the substance of any license notices (including + copyright notices, patent notices, disclaimers of warranty, or limitations of + liability) contained within the Source Code Form of the Covered Software, + except that You may alter any license notices to the extent required to remedy + known factual inaccuracies. + + + 3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, indemnity + or liability obligations to one or more recipients of Covered Software. + However, You may do so only on Your own behalf, and not on behalf of any + Contributor. You must make it absolutely clear that any such warranty, support, + indemnity, or liability obligation is offered by You alone, and You hereby + agree to indemnify every Contributor for any liability incurred by such + Contributor as a result of warranty, support, indemnity or liability terms You + offer. You may include additional disclaimers of warranty and limitations of + liability specific to any jurisdiction. + + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this License with +respect to some or all of the Covered Software due to statute, judicial order, or +regulation then You must: (a) comply with the terms of this License to the +maximum extent possible; and (b) describe the limitations and the code they +affect. Such description must be placed in a text file included with all +distributions of the Covered Software under this License. Except to the extent +prohibited by statute or regulation, such description must be sufficiently +detailed for a recipient of ordinary skill to be able to understand it. + + +5. Termination +-------------- + + 5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, then + the rights granted under this License from a particular Contributor are + reinstated (a) provisionally, unless and until such Contributor explicitly and + finally terminates Your grants, and (b) on an ongoing basis, if such + Contributor fails to notify You of the non-compliance by some reasonable means + prior to 60 days after You have come back into compliance. Moreover, Your + grants from a particular Contributor are reinstated on an ongoing basis if such + Contributor notifies You of the non-compliance by some reasonable means, this + is the first time You have received notice of non-compliance with this License + from such Contributor, and You become compliant prior to 30 days after Your + receipt of the notice. + + 5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, counter-claims, and + cross-claims) alleging that a Contributor Version directly or indirectly + infringes any patent, then the rights granted to You by any and all + Contributors for the Covered Software under Section 2.1 of this License shall + terminate. + + 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + + +6. Disclaimer of Warranty +------------------------- + +Covered Software is provided under this License on an "as is" basis, without +warranty of any kind, either expressed, implied, or statutory, including, without +limitation, warranties that the Covered Software is free of defects, +merchantable, fit for a particular purpose or non-infringing. The entire risk as +to the quality and performance of the Covered Software is with You. Should any +Covered Software prove defective in any respect, You (not any Contributor) assume +the cost of any necessary servicing, repair, or correction. This disclaimer of +warranty constitutes an essential part of this License. No use of any Covered +Software is authorized under this License except under this disclaimer. + + +7. Limitation of Liability +-------------------------- + +Under no circumstances and under no legal theory, whether tort (including +negligence), contract, or otherwise, shall any Contributor, or anyone who +distributes Covered Software as permitted above, be liable to You for any direct, +indirect, special, incidental, or consequential damages of any character +including, without limitation, damages for lost profits, loss of goodwill, work +stoppage, computer failure or malfunction, or any and all other commercial +damages or losses, even if such party shall have been informed of the possibility +of such damages. This limitation of liability shall not apply to liability for +death or personal injury resulting from such party's negligence to the extent +applicable law prohibits such limitation. Some jurisdictions do not allow the +exclusion or limitation of incidental or consequential damages, so this exclusion +and limitation may not apply to You. + + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the courts of a +jurisdiction where the defendant maintains its principal place of business and +such litigation shall be governed by laws of that jurisdiction, without reference +to its conflict-of-law provisions. Nothing in this Section shall prevent a +party's ability to bring cross-claims or counter-claims. + + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject matter +hereof. If any provision of this License is held to be unenforceable, such +provision shall be reformed only to the extent necessary to make it enforceable. +Any law or regulation which provides that the language of a contract shall be +construed against the drafter shall not be used to construe this License against +a Contributor. + + +10. Versions of the License +--------------------------- + + + 10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section 10.3, + no one other than the license steward has the right to modify or publish new + versions of this License. Each version will be given a distinguishing version + number. + + + 10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version of the + License under which You originally received the Covered Software, or under the + terms of any subsequent version published by the license steward. + + + 10.3. Modified Versions + + If you create software not governed by this License, and you want to create a + new license for such software, you may create and use a modified version of + this License if you rename the license and remove any references to the name of + the license steward (except to note that such modified license differs from + this License). + + + 10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses + + If You choose to distribute Source Code Form that is Incompatible With + Secondary Licenses under the terms of this version of the License, the notice + described in Exhibit B of this License must be attached. + + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public License, + v. 2.0. If a copy of the MPL was not distributed with this file, You can + obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, then +You may include the notice in a location (such as a LICENSE file in a relevant +directory) where a recipient would be likely to look for such a notice. + +You may add additional accurate notices of copyright ownership. + + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as defined + by the Mozilla Public License, v. 2.0. + +------------------------------------------------------------------------------- +| libzstd-dev 1.5.4 (used under BSD 3-clause "New" or "Revised" License) https://github.com/Cyan4973/zstd +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Meta Platforms, Inc. and affiliates. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| libzstd-dev 1.5.5 (used under BSD 3-clause "New" or "Revised" License) https://github.com/Cyan4973/zstd +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| roboticstoolbox-python 1.0.2 (used under MIT License) https://github.com/petercorke/robotics-toolbox-python +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License +=============== + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| zstd 1.5.5 (used under BSD 3-clause "New" or "Revised" License) http://www.zstd.net +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Martin Liska, SUSE, Meta Platforms, Inc. and affiliates. +Copyright (C) 2012-2016 Yann Collet. +Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates. +Copyright 2020 Jan Tojnar. +Copyright (c) 1995-2006, 2010-2011 Jean-loup Gailly. +Copyright (c) 2018-present lzutao +Copyright (C) 2004-2017 Mark Adler. +Copyright (c) 2003-2008 Yuta Mori. All Rights Reserved. +Copyright (c) Meta Platforms, Inc. and affiliates. You can contact the author at : and affiliates and affiliates. All Rights Reserved. +Copyright (C) 1989, 1991, 2000-2016 Free Software Foundation, Inc. +Copyright (c) 2016 Tino Reichardt. All Rights Reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- \ No newline at end of file diff --git a/czishrink/icon-source/convert-to-ico.sh b/czishrink/icon-source/convert-to-ico.sh new file mode 100644 index 0000000..2955790 --- /dev/null +++ b/czishrink/icon-source/convert-to-ico.sh @@ -0,0 +1,2 @@ +#!/bin/bash +magick mogrify -path . -format ico -density 600 -define icon:auto-resize=256,128,64,48,40,32,24,16 -background none netczicompress.svg \ No newline at end of file diff --git a/czishrink/icon-source/netczicompress.svg b/czishrink/icon-source/netczicompress.svg new file mode 100644 index 0000000..03de992 --- /dev/null +++ b/czishrink/icon-source/netczicompress.svg @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/czishrink/libczicompressc/LICENSE.txt b/czishrink/libczicompressc/LICENSE.txt new file mode 100644 index 0000000..1749d76 --- /dev/null +++ b/czishrink/libczicompressc/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Carl Zeiss Microscopy GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/czishrink/libczicompressc/THIRD_PARTY_LICENSES.txt b/czishrink/libczicompressc/THIRD_PARTY_LICENSES.txt new file mode 100644 index 0000000..1b833ba --- /dev/null +++ b/czishrink/libczicompressc/THIRD_PARTY_LICENSES.txt @@ -0,0 +1,128 @@ +============= Free and Open Source Software Disclosure Statement ============== + +For libCZI + +This project includes copyrighted software from third parties that may be +distributed under different licenses than this project as given below. + +In case we missed to list a specific software and/or underlying license, +we appreciate your upfront notice. + +This project may include copyrighted software that is distributed under a +license that requires us to provide the source code of that software and +instructions on how to build and install it, such as the GNU GPL or GNU +LGPL or other reciprocal licenses. Unless otherwise stated the original +source code of such software has not been modified. As recipient and user of +this project you may obtain the complete source code for such copyrighted +software as well as build and install instructions from us for a period of +three years starting with the reception of the project and at no charge. + +In any of such cases, please send an email to opensource@zeiss.com +referencing this project's name and version. + + +List of third-party software: +----------------------------------- + +=============================================================================== + +------------------------------------------------------------------------------- +| jxrlib 1.1 (used under BSD 3-clause "New" or "Revised" License) https://github.com/4creators/jxrlib +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright 2013 Microsoft Corporation + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| md5sum (used under RSA MD4 or MD5 Message-Digest Algorithm License) +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +RSA MD4 or MD5 Message-Digest Algorithm License +=============================================== + +License to copy and use this software is granted provided that it is identified +as the "RSA Data Security, Inc. MD4 or MD5 Message-Digest Algorithm" in all +material mentioning or referencing this software or this function. + +License is also granted to make and use derivative works provided that such works +are identified as "derived from the RSA Data Security, Inc. MD4 or MD5 +Message-Digest Algorithm" in all material mentioning or referencing the derived +work. + +RSA Data Security, Inc. makes no representations concerning either the +merchantability of this software or the suitability of this software for any +particular purpose. It is provided "as is" without express or implied warranty of +any kind. + +These notices must be retained in any copies of any part of this documentation +and/or software. + +------------------------------------------------------------------------------- +| pugixml 1.10 (used under MIT License) http://pugixml.org/ +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (C) 2006-2019, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) +Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +This library is distributed under the MIT License: + +Copyright (c) 2006-2019 Arseny Kapoulkine + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE + + +--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + +Generated on Thu, 29 Sep 2022 07:40:42 +0200 using Black Duck 2022.4.2. \ No newline at end of file diff --git a/czishrink/libczicompressc/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt b/czishrink/libczicompressc/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt new file mode 100644 index 0000000..6686074 --- /dev/null +++ b/czishrink/libczicompressc/THIRD_PARTY_LICENSES_ARTIFACT_DISTRIBUTION.txt @@ -0,0 +1,1524 @@ +============= Free and Open Source Software Disclosure Statement ============== + +For czicompress + +This product includes copyrighted software from third parties that may be +distributed under different licenses than this product as given below. + +In case we missed to list a specific software and/or underlying license, +we appreciate your upfront notice. + +This product may include copyrighted software that is distributed under a +license that requires us to provide the source code of that software and +instructions on how to build and install it, such as the GNU GPL or GNU +LGPL or other reciprocal licenses. Unless otherwise stated the original +source code of such software has not been modified. As recipient and user of +this product you may obtain the complete source code for such copyrighted +software as well as build and install instructions from us for a period of +three years starting with the reception of the product and valid for as +long as we offer spare parts or customer support for that product model +and at no charge. + +In any of such cases, please send an email to opensource@zeiss.com +referencing your product's name, version, and manufacturing ZEISS entity. + + +List of third-party software: +----------------------------------- + +=============================================================================== + +------------------------------------------------------------------------------- +| Catch2 3.4.0 (used under Boost Software License 1.0) https://discord.gg/4CWS9zD +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Boost Software License - Version 1.0 +==================================== + + +August 17th, 2003 +----------------- + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| CLIUtils/CLI11 v2.3.2 (used under BSD 3-clause "New" or "Revised" License) https://cliutils.gitlab.io/CLI11Tutorial +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2017-2023 University of Cincinnati, developed by Henry Schreiner under NSF AWARD 1414736. All Rights Reserved. +Copyright (c) 2012 - 2017, Lars Bilke. All Rights Reserved. +Copyright (c) 2017-2023 University of Cincinnati, developed by Henry Schreiner. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| D3.js 3.5.17 (used under BSD 3-clause "New" or "Revised" License) http://d3js.org/ +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) 2010 Stanford Visualization Group. All Rights Reserved. +Copyright (c) 2011 Jason Davies. All Rights Reserved. +Copyright 2001 Robert Penner. All Rights Reserved. +Copyright (c) 2008-2012 Charles Karney. +Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State. +Copyright (c) 2010 SimpleGeo and Stamen Design. All Rights Reserved. +Copyright (c) 2010-2016 Michael Bostock. All Rights Reserved. +Copyright (C) 2010-2013 Raymond Hill. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) 2010, Stanford Visualization Group +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of Stanford University nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + +------------------------------------------------------------------------------- +| gmdh 1.0 (used under MIT License) https://github.com/bauman-team/GMDH +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright 2001-2009 Kitware, Inc. +Copyright (C) 2018 David Hyde. +Copyright (C) 2009 Benjamin Schindler. +Copyright 2012 Continuum Analytics, Inc. All Rights Reserved. +Copyright (C) 2002-2007 Yves Renard This file is a part of GETFEM++. +Copyright (C) 2021 Chip Kerchner (chip. kerchner@ibm.com). +Copyright (C) 2011 Timothy E. Holy. +Copyright (c) 2021 NVIDIA CORPORATION. All Rights Reserved. +Copyright (C) 2020 Jens Wehner. +Copyright 2017 The TensorFlow Authors. All Rights Reserved. +Copyright 2013-2016 Florent Pruvost. +Copyright (C) EDF R. +Copyright (C) 2012 Desire Nuentsa Wakam. +Copyright (C) 2009-2013 Jitse Niesen. +Copyright (C) 2009 Ilya Baran. +(C) William Swanson, Paul Fultz define PYBIND11_EVAL0(...) __VA_ARGS__ define PYBIND11_EVAL1(...) PYBIND11_EVAL0(PYBIND11_EVAL0(PYBIND11_EVAL0(__VA_ARGS__))) define PYBIND11_EVAL2( +Copyright (C) 2018 Mehdi Goli Codeplay Software Ltd. +Copyright (C) 2013 Pavel Holoborodko. +Copyright (c) 2016-2017, 2020 Wenzel Jakob. All Rights Reserved. +Copyright : EDF 2001 $Header$. +Copyright (C) 2014 yoco. +Copyright (C) 2013 Jean Ceccato. +Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved. +Copyright (C) 2011-2013 Chen-Pang He. +Copyright (C) 2006-2011, 2015 Benoit Jacob. +copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All Rights Reserved. +Copyright (c) 2019 Dawid Pilarski. +Copyright (C) 2013 Pierre Zoppitelli. +Copyright (C) 2020 Everton Constantino. +Copyright (C) 2019 David Tellenbach. +(C) Desire NUENTSA WAKAM, INRIA include include include include include include include +Copyright (C) 2008 Gael Guennebaud Adapted from FindEigen. cmake:. +Copyright (c) 2016 Sergey Lyskov and Wenzel Jakob. +(C) Desire NUENTSA WAKAM, INRIA include include include include include include ifd +Copyright (c) Fabian Giesen, 2016. All Rights Reserved. +Copyright (c) 1994 by Xerox Corporation. All Rights Reserved. +Copyright (C) 2012 Alexey Korepanov. +Copyright (C) 1998-2010, 2015-2016. +Copyright (c) 2020 Wenzel Jakob and Henry Schreiner. +Copyright (C) 2015-2016 Eugene Brevdo. +Copyright (C) 2011 Andreas Platen. +Copyright (C) 2017 Viktor Csomor. +Copyright (C) 2020 Antonio Sanchez. +Copyright (c) 2017 Henry F. Schreiner. +Copyright (C) 2017 Kyle Macfarlan. +Copyright (C) 2012-2013 D. +Copyright (C) 2009 Thomas Capricelli This code initially comes from MINPACK whose original authors are:. +Copyright (C) 2008 Daniel Gomez Ferro. +Copyright (C) 2013 Nicolas Carre. +Copyright (C) 2012 David Harmon. +Copyright (c) 2014-2015 Open Source Robotics Foundation. All Rights Reserved. +Copyright (c) 2021 Laramie Leavitt (Google LLC). +Copyright (C) 2014, 2016 Benoit Steiner (benoit. steiner.goog@gmail.com). +Copyright (c) 2019 Roland Dreier. +copyright (c) 2009-2014 The University of Tennessee and The University of Tennessee Research Foundation. All Rights Reserved. +Copyright (C) 2016 Dmitry Vyukov. +Copyright (c) 2007 Allen Winter. +Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd. +Copyright (c) 2006-2007 Montel Laurent. +Copyright (C) 2009 Mark Borgerding mark a borgerding net. +Copyright (C) 2014, 2016 Pedro Gonnet (pedro. gonnet@gmail.com). +Copyright (C) 2009 Ricard Marxer. +Copyright (c) 2016 Sergey Lyskov. +Copyright 2003-2009 Mark Borgerding template struct kiss_cpx_fft. +Copyright 2012-2013 Mathieu Faverge. +Copyright (C) 2016 Igor Babuschkin. +Copyright (C) 2009 Kenneth Riddile. +Copyright (C) 1989, 1991, 1999, 2007 Free Software Foundation, Inc. +Copyright (C) 2005 the Regents of the University of Minnesota. +Copyright (c) 2007 Alexander Neundorf. +Copyright 2018-2019, 2022 Google LLC. All Rights Reserved. +Copyright (C) 2019 Joel Holdsworth. +Copyright (c) 1998-2003 by the University of Florida. All Rights Reserved. +Copyright (c) 2001, 2011 Intel Corporation. All Rights Reserved. Permition is granted to use, copy, distribute and prepare derivative works of this library for any purpose and without fee, provided, that the above. +Copyright (C) 2020 Jan van Dijk. +Copyright (C) 2009 Rohit Garg. +Copyright (c) 2017 Borja Zarco (Google LLC). +Copyright (C) 2009-2010 Thomas Capricelli. +Copyright (C) 2020 Arm Limited and Contributors. +Copyright (C) 2015 Vijay Vasudevan. +Copyright (C) 2009 Claire Maurice. +Copyright (C) 2017 Codeplay Software Limited. +Copyright (C) 2014-2015 Jianwei Cui. +Copyright (C) 2009-2013 Hauke Heibel. +Copyright (C) 2010 Vincent Lejeune. +Copyright (C) 2008-2009 Guillaume Saupin. +Copyright (C) 2020 Sebastien Boisvert. +Copyright (C) 2009 Mathieu Gautier. +Copyright (C) 2013 Christoph Hertzberg. +Copyright (C) 2008 Gael Guennebaud NOTE The functions of this file have been adapted from the GMM++ library. +Copyright (C) 2012-2013 Desire Nuentsa. +Copyright (C) 2017 Gagan Goel. +Copyright (C) 2014-2017 Benoit Steiner. +Copyright (C) 2020-2021 C. Antonio Sanchez. +Copyright (c) 2018 Hudson River Trading LLC. +Copyright (C) 2014-2015 Navdeep Jaitly. +Copyright (C) 2009 Thomas Capricelli include. +Copyright (c) 2016-2017 Jason Rhinelander. +Copyright (c) 2016 Pim Schellart. +Copyright (C) 2012 The Android Open Source Project. +Copyright (C) 2016, 2018-2019 Rasmus Munk Larsen. +Copyright (c) 2016 Ivan Smirnov. +Copyright (C) 2007 Michael Olbrich. +Copyright (c) 2020 The Eigen Authors. +Copyright (c) 2009 Boudewijn Rempt. +Copyright (C) 2012 desire Nuentsa. +(C) Copyright .. +Copyright 2012 Cedric Castagnede. +Copyright (C) 2012 Desire Nuentsa This code initially comes from MINPACK whose original authors are:. +Copyright (C) 2008-2019 Gael Guennebaud. +Copyright (C) 2012 Giacomo Po. +Copyright (c) 2016 Ben North. +copyright: (c) 2013 by Ihor Kalnytskyi +Copyright (C) 2018 Andy Davis. +Copyright 1984-1985, 1987, 1992, 2000 by Stephen L. Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140 const Scalar zero = 0; const Scalar one = 1; const Scalar nan = Moshier Permission has been kindly provided by the original author to incorporate the Cephes software into the Eigen codebase: Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140. +Copyright 2012-2016 Inria. All Rights Reserved. +Copyright (C) 2008-2009 Gael Guennebaud NOTE The class IterationController has been adapted from the iteration. +Copyright (C) 2013 Christian Seiler. +Copyright (C) 2009, 2012 Keir Mierle. +Copyright (c) 2016 Klemens D. Morgenstern. +Copyright (c) 2010 Intel Corp. All Rights Reserved. +Copyright (C) 2015 Gael Guennebaud Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditio. +Copyright (C) 2008-2016 Konstantinos Margaritis. +Copyright (c) 2006 Timothy A. Davis. +Copyright (c) 2011-2014 Willow Garage, Inc. +Copyright (C) 2016 Tobias Wood. +Copyright (C) 2011-2012, 2014 Kolja Brix. +Copyright (C) 2010 Manuel Yguel. +Copyright (C) 2015 Tal Hadad. +Copyright (C) 1997-2001 Authors: Andrew Lumsdaine Lie-Quan Lee This file is part of the Iterative Template Library. +Copyright (C) 2015 Ke Yang. +Copyright 2005-2010, 2013, 2015, 2018-2021 Google Inc. All Rights Reserved. +Copyright (C) 2018 Eugene Zhulenev. +Copyright (C) 2007 Julien Pommier. +Copyright (C) 2018 Wave Computing, Inc. Written by:. +Copyright 2016-2018 Codeplay Software Ltd. +Copyright (C) 2012 Desire Nuentsa The algorithm of this. +Copyright (c) 2016 Klemens Morgenstern and. +Copyright (C) 2012 Desire NUENTSA WAKAM. +Copyright (c) 2012 Erik Edlund Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions a. +Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google. com). +Copyright (C) 2018 Deven Desai. +Copyright (C) 2020 Chris Schoutrop. +Copyright (C) 2010 Daniel Lowengrub. +Copyright 2012-2013 Emmanuel Agullo. +Copyright (C) 2014 Eric Martin. +Copyright (c) 2016 Trent Houliston and. +Copyright (C) 2020 Everton Constantino (everton. constantino@ibm.com). +Copyright (c) 2019 Pranav. +Copyright (C) 2013 Gauthier Brun. +Copyright (c) 2021 The Pybind Development Team. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License +=============== + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| libeigen/eigen 3.4.0 (used under (GNU Lesser General Public License v2.1 or later AND BSD 3-clause "New" or "Revised" License AND Mozilla Public License 2.0)) https://gitlab.com/libeigen/eigen.git +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (C) 2018 David Hyde. +Copyright (C) 2009 Benjamin Schindler. +Copyright (C) 2021 Chip Kerchner (chip. kerchner@ibm.com). +Copyright (C) 2011 Timothy E. Holy. +Copyright (c) 2021 NVIDIA CORPORATION. All Rights Reserved. +Copyright (C) 2020 Jens Wehner. +Copyright 2017 The TensorFlow Authors. All Rights Reserved. +Copyright 2013-2016 Florent Pruvost. +Copyright (C) EDF R. +Copyright (C) 2012 Desire Nuentsa Wakam. +Copyright (C) 2009-2013 Jitse Niesen. +Copyright (C) 2009 Ilya Baran. +Copyright (C) 2018 Mehdi Goli Codeplay Software Ltd. +Copyright (C) 2013 Pavel Holoborodko. +Copyright : EDF 2001 $Header$. +Copyright (C) 2014 yoco. +Copyright (C) 2013 Jean Ceccato. +Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved. +Copyright (C) 2011-2013 Chen-Pang He. +Copyright (C) 2006-2011, 2015 Benoit Jacob. +copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All Rights Reserved. +Copyright (C) 2013 Pierre Zoppitelli. +Copyright (C) 2020 Everton Constantino. +Copyright (C) 2019 David Tellenbach. +Copyright (C) 2008 Gael Guennebaud Adapted from FindEigen. cmake:. +Copyright (c) Fabian Giesen, 2016. All Rights Reserved. +Copyright (c) 1994 by Xerox Corporation. All Rights Reserved. +Copyright (C) 2012 Alexey Korepanov. +Copyright (C) 1998-2010, 2015-2016. +Copyright (C) 2015-2016 Eugene Brevdo. +Copyright (C) 2011 Andreas Platen. +Copyright (C) 2017 Viktor Csomor. +Copyright (C) 2020 Antonio Sanchez. +Copyright 2003-2009 Mark Borgerding. +Copyright (C) 2017 Kyle Macfarlan. +Copyright (C) 2012-2013 D. +Copyright (C) 2008 Daniel Gomez Ferro. +Copyright (C) 2013 Nicolas Carre. +Copyright (C) 2012 David Harmon. +Copyright (c) 2014-2015 Open Source Robotics Foundation. All Rights Reserved. +Copyright (C) 2014, 2016 Benoit Steiner (benoit. steiner.goog@gmail.com). +Copyright (C) 2015 Gael Guennebaud Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions. +copyright (c) 2009-2014 The University of Tennessee and The University of Tennessee Research Foundation. All Rights Reserved. +Copyright (C) 2016 Dmitry Vyukov. +Copyright (c) 2007 Allen Winter. +Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd. +Copyright (c) 2006-2007 Montel Laurent. +Copyright (C) 2009 Mark Borgerding mark a borgerding net. +Copyright (C) 2014, 2016 Pedro Gonnet (pedro. gonnet@gmail.com). +Copyright (C) 2009 Ricard Marxer. +Copyright 2012-2013 Mathieu Faverge. +Copyright (C) 2016 Igor Babuschkin. +Copyright (C) 2009 Kenneth Riddile. +Copyright (C) 1989, 1991, 1999, 2007 Free Software Foundation, Inc. +Copyright (C) 2005 the Regents of the University of Minnesota. +Copyright (c) 2007 Alexander Neundorf. +Copyright (C) 2019 Joel Holdsworth. +Copyright (c) 1998-2003 by the University of Florida. All Rights Reserved. +Copyright (C) 2002-2007 Yves Renard. +Copyright (C) 2020 Jan van Dijk. +Copyright (C) 2008-2019, 20013, 20015 Gael Guennebaud. +Copyright (C) 2009 Rohit Garg. +Copyright (C) 2009-2010 Thomas Capricelli. +Copyright (C) 2020 Arm Limited and Contributors. +Copyright (C) 2015 Vijay Vasudevan. +Copyright (C) 2009 Claire Maurice. +Copyright (C) 2017 Codeplay Software Limited. +Copyright (C) 2014-2015 Jianwei Cui. +Copyright 1984-1985, 1987, 1992, 2000 by Stephen L. Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140 Moshier Direct inquiries to 30 Frost Street, Cambridge, MA 02140 const Scalar zero = 0; const Scalar one = 1; const Scalar nan = NumTr Moshier. +Copyright (C) 2009-2013 Hauke Heibel. +Copyright (C) 2010 Vincent Lejeune. +Copyright (C) 2008-2009 Guillaume Saupin. +Copyright (C) 2020 Sebastien Boisvert. +Copyright (C) 2009 Mathieu Gautier. +Copyright (C) 2013 Christoph Hertzberg. +Copyright (C) 2012-2013 Desire Nuentsa. +Copyright (C) 2017 Gagan Goel. +Copyright (C) 2014-2017 Benoit Steiner. +Copyright (C) 2020-2021 C. Antonio Sanchez. +Copyright (C) 2014-2015 Navdeep Jaitly. +Copyright (C) 1997-2001 Authors: Andrew Lumsdaine Lie-Quan Lee. +Copyright (C) 2012 The Android Open Source Project. +Copyright (C) 2016, 2018-2019 Rasmus Munk Larsen. +Copyright (c) 2001, 2011 Intel Corporation. All Rights Reserved. +Copyright (C) 2007 Michael Olbrich. +Copyright (c) 2020 The Eigen Authors. +Copyright (c) 2009 Boudewijn Rempt. +Copyright (C) 2012 desire Nuentsa. +Copyright 2012 Cedric Castagnede. +Copyright (C) 2012 Giacomo Po. +Copyright (C) 2018 Andy Davis. +Copyright 2012-2016 Inria. All Rights Reserved. +Copyright (C) 2013 Christian Seiler. +Copyright (C) 2009, 2012 Keir Mierle. +Copyright 2007-2009 Kitware, Inc. +Copyright (C) 2008-2016 Konstantinos Margaritis. +Copyright (c) 2006 Timothy A. Davis. +Copyright (c) 2011-2014 Willow Garage, Inc. +Copyright (C) 2016 Tobias Wood. +Copyright (C) 2011-2012, 2014 Kolja Brix. +Copyright (C) 2010 Manuel Yguel. +Copyright (C) 2015 Tal Hadad. +Copyright (C) 2015 Ke Yang. +Copyright (C) 2018 Eugene Zhulenev. +Copyright (C) 2007 Julien Pommier. +Copyright (C) 2018 Wave Computing, Inc. Written by:. +Copyright 2016-2018 Codeplay Software Ltd. +Copyright (C) 2012 Desire NUENTSA WAKAM. +Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google. com). +Copyright (C) 2018 Deven Desai. +Copyright (C) 2020 Chris Schoutrop. +(C) Desire NUENTSA WAKAM, INRIA +Copyright (C) 2010 Daniel Lowengrub. +Copyright 2012-2013 Emmanuel Agullo. +Copyright (C) 2014 Eric Martin. +Copyright (C) 2020 Everton Constantino (everton. constantino@ibm.com). +Copyright (C) 2013 Gauthier Brun. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +GNU Lesser General Public License +================================= + +Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Everyone is permitted to copy and distribute verbatim copies + + of this license document, but changing it is not allowed. + + [This is the first released version of the Lesser GPL. It also counts + + as the successor of the GNU Library Public License, version 2, hence + + the version number 2.1.] + + +Preamble +-------- + +The licenses for most software are designed to take away your freedom to share +and change it. By contrast, the GNU General Public Licenses are intended to +guarantee your freedom to share and change free software--to make sure the +software is free for all its users. + +This license, the Lesser General Public License, applies to some specially +designated software packages--typically libraries--of the Free Software +Foundation and other authors who decide to use it. You can use it too, but we +suggest you first think carefully about whether this license or the ordinary +General Public License is the better strategy to use in any particular case, +based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. +Our General Public Licenses are designed to make sure that you have the freedom +to distribute copies of free software (and charge for this service if you wish); +that you receive source code or can get it if you want it; that you can change +the software and use pieces of it in new free programs; and that you are informed +that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to +deny you these rights or to ask you to surrender these rights. These restrictions +translate to certain responsibilities for you if you distribute copies of the +library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a +fee, you must give the recipients all the rights that we gave you. You must make +sure that they, too, receive or can get the source code. If you link other code +with the library, you must provide complete object files to the recipients, so +that they can relink them with the library after making changes to the library +and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and +(2) we offer you this license, which gives you legal permission to copy, +distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no +warranty for the free library. Also, if the library is modified by someone else +and passed on, the recipients should know that what they have is not the original +version, so that the original author's reputation will not be affected by +problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free +program. We wish to make sure that a company cannot effectively restrict the +users of a free program by obtaining a restrictive license from a patent holder. +Therefore, we insist that any patent license obtained for a version of the +library must be consistent with the full freedom of use specified in this +license. + +Most GNU software, including some libraries, is covered by the ordinary GNU +General Public License. This license, the GNU Lesser General Public License, +applies to certain designated libraries, and is quite different from the ordinary +General Public License. We use this license for certain libraries in order to +permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared +library, the combination of the two is legally speaking a combined work, a +derivative of the original library. The ordinary General Public License therefore +permits such linking only if the entire combination fits its criteria of freedom. +The Lesser General Public License permits more lax criteria for linking other +code with the library. + +We call this license the "Lesser" General Public License because it does Less to +protect the user's freedom than the ordinary General Public License. It also +provides other free software developers Less of an advantage over competing +non-free programs. These disadvantages are the reason we use the ordinary General +Public License for many libraries. However, the Lesser license provides +advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the +widest possible use of a certain library, so that it becomes a de-facto standard. +To achieve this, non-free programs must be allowed to use the library. A more +frequent case is that a free library does the same job as widely used non-free +libraries. In this case, there is little to gain by limiting the free library to +free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs +enables a greater number of people to use a large body of free software. For +example, permission to use the GNU C Library in non-free programs enables many +more people to use the whole GNU operating system, as well as its variant, the +GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' +freedom, it does ensure that the user of a program that is linked with the +Library has the freedom and the wherewithal to run that program using a modified +version of the Library. + +The precise terms and conditions for copying, distribution and modification +follow. Pay close attention to the difference between a "work based on the +library" and a "work that uses the library". The former contains code derived +from the library, whereas the latter must be combined with the library in order +to run. + + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +--------------------------------------------------------------- + +0. This License Agreement applies to any software library or other program which +contains a notice placed by the copyright holder or other authorized party saying +it may be distributed under the terms of this Lesser General Public License (also +called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as +to be conveniently linked with application programs (which use some of those +functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been +distributed under these terms. A "work based on the Library" means either the +Library or any derivative work under copyright law: that is to say, a work +containing the Library or a portion of it, either verbatim or with modifications +and/or translated straightforwardly into another language. (Hereinafter, +translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making +modifications to it. For a library, complete source code means all the source +code for all modules it contains, plus any associated interface definition files, +plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by +this License; they are outside its scope. The act of running a program using the +Library is not restricted, and output from such a program is covered only if its +contents constitute a work based on the Library (independent of the use of the +Library in a tool for writing it). Whether that is true depends on what the +Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and disclaimer +of warranty; keep intact all the notices that refer to this License and to the +absence of any warranty; and distribute a copy of this License along with the +Library. + +You may charge a fee for the physical act of transferring a copy, and you may at +your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus +forming a work based on the Library, and copy and distribute such modifications +or work under the terms of Section 1 above, provided that you also meet all of +these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices stating + that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no charge to all + third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a table of + data to be supplied by an application program that uses the facility, other + than as an argument passed when the facility is invoked, then you must make + a good faith effort to ensure that, in the event an application does not + supply such function or table, the facility still operates, and performs + whatever part of its purpose remains meaningful. + + (For example, a function in a library to compute square roots has a purpose + that is entirely well-defined independent of the application. Therefore, + Subsection 2d requires that any application-supplied function or table used + by this function must be optional: if the application does not supply it, + the square root function must still compute square roots.) + + These requirements apply to the modified work as a whole. If identifiable + sections of that work are not derived from the Library, and can be + reasonably considered independent and separate works in themselves, then + this License, and its terms, do not apply to those sections when you + distribute them as separate works. But when you distribute the same + sections as part of a whole which is a work based on the Library, the + distribution of the whole must be on the terms of this License, whose + permissions for other licensees extend to the entire whole, and thus to + each and every part regardless of who wrote it. + + Thus, it is not the intent of this section to claim rights or contest your + rights to work written entirely by you; rather, the intent is to exercise + the right to control the distribution of derivative or collective works + based on the Library. + + In addition, mere aggregation of another work not based on the Library with + the Library (or with a work based on the Library) on a volume of a storage + or distribution medium does not bring the other work under the scope of + this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License +instead of this License to a given copy of the Library. To do this, you must +alter all the notices that refer to this License, so that they refer to the +ordinary GNU General Public License, version 2, instead of to this License. (If a +newer version than version 2 of the ordinary GNU General Public License has +appeared, then you can specify that version instead if you wish.) Do not make any +other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so +the ordinary GNU General Public License applies to all subsequent copies and +derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into +a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, +under Section 2) in object code or executable form under the terms of Sections 1 +and 2 above provided that you accompany it with the complete corresponding +machine-readable source code, which must be distributed under the terms of +Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a +designated place, then offering equivalent access to copy the source code from +the same place satisfies the requirement to distribute the source code, even +though third parties are not compelled to copy the source along with the object +code. + +5. A program that contains no derivative of any portion of the Library, but is +designed to work with the Library by being compiled or linked with it, is called +a "work that uses the Library". Such a work, in isolation, is not a derivative +work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an +executable that is a derivative of the Library (because it contains portions of +the Library), rather than a "work that uses the library". The executable is +therefore covered by this License. Section 6 states terms for distribution of +such executables. + +When a "work that uses the Library" uses material from a header file that is part +of the Library, the object code for the work may be a derivative work of the +Library even though the source code is not. Whether this is true is especially +significant if the work can be linked without the Library, or if the work is +itself a library. The threshold for this to be true is not precisely defined by +law. + +If such an object file uses only numerical parameters, data structure layouts and +accessors, and small macros and small inline functions (ten lines or less in +length), then the use of the object file is unrestricted, regardless of whether +it is legally a derivative work. (Executables containing this object code plus +portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the +object code for the work under the terms of Section 6. Any executables containing +that work also fall under Section 6, whether or not they are linked directly with +the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work +that uses the Library" with the Library to produce a work containing portions of +the Library, and distribute that work under terms of your choice, provided that +the terms permit modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is +used in it and that the Library and its use are covered by this License. You must +supply a copy of this License. If the work during execution displays copyright +notices, you must include the copyright notice for the Library among them, as +well as a reference directing the user to the copy of this License. Also, you +must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable + source code for the Library including whatever changes were used in the + work (which must be distributed under Sections 1 and 2 above); and, if the + work is an executable linked with the Library, with the complete + machine-readable "work that uses the Library", as object code and/or source + code, so that the user can modify the Library and then relink to produce a + modified executable containing the modified Library. (It is understood that + the user who changes the contents of definitions files in the Library will + not necessarily be able to recompile the application to use the modified + definitions.) + + b) Use a suitable shared library mechanism for linking with the Library. A + suitable mechanism is one that (1) uses at run time a copy of the library + already present on the user's computer system, rather than copying library + functions into the executable, and (2) will operate properly with a + modified version of the library, if the user installs one, as long as the + modified version is interface-compatible with the version that the work was + made with. + + c) Accompany the work with a written offer, valid for at least three years, + to give the same user the materials specified in Subsection 6a, above, for + a charge no more than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy from a + designated place, offer equivalent access to copy the above specified + materials from the same place. + + e) Verify that the user has already received a copy of these materials or + that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must +include any data and utility programs needed for reproducing the executable from +it. However, as a special exception, the materials to be distributed need not +include anything that is normally distributed (in either source or binary form) +with the major components (compiler, kernel, and so on) of the operating system +on which the executable runs, unless that component itself accompanies the +executable. + +It may happen that this requirement contradicts the license restrictions of other +proprietary libraries that do not normally accompany the operating system. Such a +contradiction means you cannot use both them and the Library together in an +executable that you distribute. + +7. You may place library facilities that are a work based on the Library +side-by-side in a single library together with other library facilities not +covered by this License, and distribute such a combined library, provided that +the separate distribution of the work based on the Library and of the other +library facilities is otherwise permitted, and provided that you do these two +things: + + a) Accompany the combined library with a copy of the same work based on the + Library, uncombined with any other library facilities. This must be + distributed under the terms of the Sections above. + + b) Give prominent notice with the combined library of the fact that part of + it is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library +except as expressly provided under this License. Any attempt otherwise to copy, +modify, sublicense, link with, or distribute the Library is void, and will +automatically terminate your rights under this License. However, parties who have +received copies, or rights, from you under this License will not have their +licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. +However, nothing else grants you permission to modify or distribute the Library +or its derivative works. These actions are prohibited by law if you do not accept +this License. Therefore, by modifying or distributing the Library (or any work +based on the Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying the Library +or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), +the recipient automatically receives a license from the original licensor to +copy, distribute, link with or modify the Library subject to these terms and +conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement +or for any other reason (not limited to patent issues), conditions are imposed on +you (whether by court order, agreement or otherwise) that contradict the +conditions of this License, they do not excuse you from the conditions of this +License. If you cannot distribute so as to satisfy simultaneously your +obligations under this License and any other pertinent obligations, then as a +consequence you may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by all those +who receive copies directly or indirectly through you, then the only way you +could satisfy both it and this License would be to refrain entirely from +distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, and the +section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or +other property right claims or to contest validity of any such claims; this +section has the sole purpose of protecting the integrity of the free software +distribution system which is implemented by public license practices. Many people +have made generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that system; it is +up to the author/donor to decide if he or she is willing to distribute software +through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Library under this License may add an explicit geographical +distribution limitation excluding those countries, so that distribution is +permitted only in or among countries not thus excluded. In such case, this +License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the +Lesser General Public License from time to time. Such new versions will be +similar in spirit to the present version, but may differ in detail to address new +problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a +version number of this License which applies to it and "any later version", you +have the option of following the terms and conditions either of that version or +of any later version published by the Free Software Foundation. If the Library +does not specify a license version number, you may choose any version ever +published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs +whose distribution conditions are incompatible with these, write to the author to +ask for permission. For software which is copyrighted by the Free Software +Foundation, write to the Free Software Foundation; we sometimes make exceptions +for this. Our decision will be guided by the two goals of preserving the free +status of all derivatives of our free software and of promoting the sharing and +reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE +LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED +IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" +WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL +ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE +LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, +SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY +TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF +THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER +PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +END OF TERMS AND CONDITIONS + + +How to Apply These Terms to Your New Libraries +---------------------------------------------- + +If you develop a new library, and you want it to be of the greatest possible use +to the public, we recommend making it free software that everyone can +redistribute and change. You can do so by permitting redistribution under these +terms (or, alternatively, under the terms of the ordinary General Public +License). + +To apply these terms, attach the following notices to the library. It is safest +to attach them to the start of each source file to most effectively convey the +exclusion of warranty; and each file should have at least the "copyright" line +and a pointer to where the full notice is found. + + one line to give the library's name and an idea of what it does. + + Copyright (C) year name of author + + This library is free software; you can redistribute it and/or + + modify it under the terms of the GNU Lesser General Public + + License as published by the Free Software Foundation; either + + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + + but WITHOUT ANY WARRANTY; without even the implied warranty of + + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + + License along with this library; if not, write to the Free Software + + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, +if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a +sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in + + the library `Frob' (a library for tweaking knobs) written + + by James Random Hacker. + + signature of Ty Coon, 1 April 1990 + + Ty Coon, President of Vice + +That's all there is to it! + + +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Mozilla Public License +Version 2.0 +====================== + + +1. Definitions +-------------- + + 1.1. "Contributor" + + means each individual or legal entity that creates, contributes to the creation + of, or owns Covered Software. + + 1.2. "Contributor Version" + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. + + 1.3. "Contribution" + + means Covered Software of a particular Contributor. + + 1.4. "Covered Software" + + means Source Code Form to which the initial Contributor has attached the notice + in Exhibit A, the Executable Form of such Source Code Form, and Modifications + of such Source Code Form, in each case including portions thereof. + + 1.5. "Incompatible With Secondary Licenses" + + means + + a. + + that the initial Contributor has attached the notice described in Exhibit B + to the Covered Software; or + + b. + + that the Covered Software was made available under the terms of version 1.1 + or earlier of the License, but not also under the terms of a Secondary + License. + + 1.6. "Executable Form" + + means any form of the work other than Source Code Form. + + 1.7. "Larger Work" + + means a work that combines Covered Software with other material, in a separate + file or files, that is not Covered Software. + + 1.8. "License" + + means this document. + + 1.9. "Licensable" + + means having the right to grant, to the maximum extent possible, whether at the + time of the initial grant or subsequently, any and all of the rights conveyed + by this License. + + 1.10. "Modifications" + + means any of the following: + + a. + + any file in Source Code Form that results from an addition to, deletion + from, or modification of the contents of Covered Software; or + + b. + + any new file in Source Code Form that contains any Covered Software. + + 1.11. "Patent Claims" of a Contributor + + means any patent claim(s), including without limitation, method, process, and + apparatus claims, in any patent Licensable by such Contributor that would be + infringed, but for the grant of the License, by the making, using, selling, + offering for sale, having made, import, or transfer of either its Contributions + or its Contributor Version. + + 1.12. "Secondary License" + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public License, + Version 3.0, or any later versions of those licenses. + + 1.13. "Source Code Form" + + means the form of the work preferred for making modifications. + + 1.14. "You" (or "Your") + + means an individual or a legal entity exercising rights under this License. For + legal entities, "You" includes any entity that controls, is controlled by, or + is under common control with You. For purposes of this definition, "control" + means (a) the power, direct or indirect, to cause the direction or management + of such entity, whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial ownership of such + entity. + + +2. License Grants and Conditions +-------------------------------- + + + 2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive + license: + + a. + + under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, modify, + display, perform, distribute, and otherwise exploit its Contributions, + either on an unmodified basis, with Modifications, or as part of a Larger + Work; and + + b. + + under Patent Claims of such Contributor to make, use, sell, offer for sale, + have made, import, and otherwise transfer either its Contributions or its + Contributor Version. + + + 2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution become + effective for each Contribution on the date the Contributor first distributes + such Contribution. + + + 2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under this + License. No additional rights or licenses will be implied from the distribution + or licensing of Covered Software under this License. Notwithstanding + Section 2.1(b) above, no patent license is granted by a Contributor: + + a. + + for any code that a Contributor has removed from Covered Software; or + + b. + + for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. + + under Patent Claims infringed by Covered Software in the absence of its + Contributions. + + This License does not grant any rights in the trademarks, service marks, or + logos of any Contributor (except as may be necessary to comply with the notice + requirements in Section 3.4). + + + 2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to distribute + the Covered Software under a subsequent version of this License (see + Section 10.2) or under the terms of a Secondary License (if permitted under the + terms of Section 3.3). + + + 2.5. Representation + + Each Contributor represents that the Contributor believes its Contributions are + its original creation(s) or it has sufficient rights to grant the rights to its + Contributions conveyed by this License. + + + 2.6. Fair Use + + This License is not intended to limit any rights You have under applicable + copyright doctrines of fair use, fair dealing, or other equivalents. + + + 2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities +------------------- + + + 3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under the + terms of this License. You must inform recipients that the Source Code Form of + the Covered Software is governed by the terms of this License, and how they can + obtain a copy of this License. You may not attempt to alter or restrict the + recipients' rights in the Source Code Form. + + + 3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. + + such Covered Software must also be made available in Source Code Form, as + described in Section 3.1, and You must inform recipients of the Executable + Form how they can obtain a copy of such Source Code Form by reasonable + means in a timely manner, at a charge no more than the cost of distribution + to the recipient; and + + b. + + You may distribute such Executable Form under the terms of this License, or + sublicense it under different terms, provided that the license for the + Executable Form does not attempt to limit or alter the recipients' rights + in the Source Code Form under this License. + + + 3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for the + Covered Software. If the Larger Work is a combination of Covered Software with + a work governed by one or more Secondary Licenses, and the Covered Software is + not Incompatible With Secondary Licenses, this License permits You to + additionally distribute such Covered Software under the terms of such Secondary + License(s), so that the recipient of the Larger Work may, at their option, + further distribute the Covered Software under the terms of either this License + or such Secondary License(s). + + + 3.4. Notices + + You may not remove or alter the substance of any license notices (including + copyright notices, patent notices, disclaimers of warranty, or limitations of + liability) contained within the Source Code Form of the Covered Software, + except that You may alter any license notices to the extent required to remedy + known factual inaccuracies. + + + 3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, indemnity + or liability obligations to one or more recipients of Covered Software. + However, You may do so only on Your own behalf, and not on behalf of any + Contributor. You must make it absolutely clear that any such warranty, support, + indemnity, or liability obligation is offered by You alone, and You hereby + agree to indemnify every Contributor for any liability incurred by such + Contributor as a result of warranty, support, indemnity or liability terms You + offer. You may include additional disclaimers of warranty and limitations of + liability specific to any jurisdiction. + + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this License with +respect to some or all of the Covered Software due to statute, judicial order, or +regulation then You must: (a) comply with the terms of this License to the +maximum extent possible; and (b) describe the limitations and the code they +affect. Such description must be placed in a text file included with all +distributions of the Covered Software under this License. Except to the extent +prohibited by statute or regulation, such description must be sufficiently +detailed for a recipient of ordinary skill to be able to understand it. + + +5. Termination +-------------- + + 5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, then + the rights granted under this License from a particular Contributor are + reinstated (a) provisionally, unless and until such Contributor explicitly and + finally terminates Your grants, and (b) on an ongoing basis, if such + Contributor fails to notify You of the non-compliance by some reasonable means + prior to 60 days after You have come back into compliance. Moreover, Your + grants from a particular Contributor are reinstated on an ongoing basis if such + Contributor notifies You of the non-compliance by some reasonable means, this + is the first time You have received notice of non-compliance with this License + from such Contributor, and You become compliant prior to 30 days after Your + receipt of the notice. + + 5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, counter-claims, and + cross-claims) alleging that a Contributor Version directly or indirectly + infringes any patent, then the rights granted to You by any and all + Contributors for the Covered Software under Section 2.1 of this License shall + terminate. + + 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + + +6. Disclaimer of Warranty +------------------------- + +Covered Software is provided under this License on an "as is" basis, without +warranty of any kind, either expressed, implied, or statutory, including, without +limitation, warranties that the Covered Software is free of defects, +merchantable, fit for a particular purpose or non-infringing. The entire risk as +to the quality and performance of the Covered Software is with You. Should any +Covered Software prove defective in any respect, You (not any Contributor) assume +the cost of any necessary servicing, repair, or correction. This disclaimer of +warranty constitutes an essential part of this License. No use of any Covered +Software is authorized under this License except under this disclaimer. + + +7. Limitation of Liability +-------------------------- + +Under no circumstances and under no legal theory, whether tort (including +negligence), contract, or otherwise, shall any Contributor, or anyone who +distributes Covered Software as permitted above, be liable to You for any direct, +indirect, special, incidental, or consequential damages of any character +including, without limitation, damages for lost profits, loss of goodwill, work +stoppage, computer failure or malfunction, or any and all other commercial +damages or losses, even if such party shall have been informed of the possibility +of such damages. This limitation of liability shall not apply to liability for +death or personal injury resulting from such party's negligence to the extent +applicable law prohibits such limitation. Some jurisdictions do not allow the +exclusion or limitation of incidental or consequential damages, so this exclusion +and limitation may not apply to You. + + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the courts of a +jurisdiction where the defendant maintains its principal place of business and +such litigation shall be governed by laws of that jurisdiction, without reference +to its conflict-of-law provisions. Nothing in this Section shall prevent a +party's ability to bring cross-claims or counter-claims. + + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject matter +hereof. If any provision of this License is held to be unenforceable, such +provision shall be reformed only to the extent necessary to make it enforceable. +Any law or regulation which provides that the language of a contract shall be +construed against the drafter shall not be used to construe this License against +a Contributor. + + +10. Versions of the License +--------------------------- + + + 10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section 10.3, + no one other than the license steward has the right to modify or publish new + versions of this License. Each version will be given a distinguishing version + number. + + + 10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version of the + License under which You originally received the Covered Software, or under the + terms of any subsequent version published by the license steward. + + + 10.3. Modified Versions + + If you create software not governed by this License, and you want to create a + new license for such software, you may create and use a modified version of + this License if you rename the license and remove any references to the name of + the license steward (except to note that such modified license differs from + this License). + + + 10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses + + If You choose to distribute Source Code Form that is Incompatible With + Secondary Licenses under the terms of this version of the License, the notice + described in Exhibit B of this License must be attached. + + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public License, + v. 2.0. If a copy of the MPL was not distributed with this file, You can + obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, then +You may include the notice in a location (such as a LICENSE file in a relevant +directory) where a recipient would be likely to look for such a notice. + +You may add additional accurate notices of copyright ownership. + + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as defined + by the Mozilla Public License, v. 2.0. + +------------------------------------------------------------------------------- +| libzstd-dev 1.5.4 (used under BSD 3-clause "New" or "Revised" License) https://github.com/Cyan4973/zstd +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Meta Platforms, Inc. and affiliates. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| libzstd-dev 1.5.5 (used under BSD 3-clause "New" or "Revised" License) https://github.com/Cyan4973/zstd +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +------------------------------------------------------------------------------- +| roboticstoolbox-python 1.0.2 (used under MIT License) https://github.com/petercorke/robotics-toolbox-python +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +The MIT License +=============== + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in the +Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------------------- +| zstd 1.5.5 (used under BSD 3-clause "New" or "Revised" License) http://www.zstd.net +------------------------------------------------------------------------------- + +--- --- --- --- --- --- --- Copyright notice(s) --- --- --- --- --- --- --- --- +Copyright (c) Martin Liska, SUSE, Meta Platforms, Inc. and affiliates. +Copyright (C) 2012-2016 Yann Collet. +Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates. +Copyright 2020 Jan Tojnar. +Copyright (c) 1995-2006, 2010-2011 Jean-loup Gailly. +Copyright (c) 2018-present lzutao +Copyright (C) 2004-2017 Mark Adler. +Copyright (c) 2003-2008 Yuta Mori. All Rights Reserved. +Copyright (c) Meta Platforms, Inc. and affiliates. You can contact the author at : and affiliates and affiliates. All Rights Reserved. +Copyright (C) 1989, 1991, 2000-2016 Free Software Foundation, Inc. +Copyright (c) 2016 Tino Reichardt. All Rights Reserved. + +--- --- --- --- --- --- --- License text(s) --- --- --- --- --- --- --- --- --- +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + +Generated on Fri, 28 Jul 2023 15:38:21 +0200 using Black Duck 2023.4.2. \ No newline at end of file diff --git a/czishrink/libczicompressc/libczicompressc.nuspec b/czishrink/libczicompressc/libczicompressc.nuspec new file mode 100644 index 0000000..59332d2 --- /dev/null +++ b/czishrink/libczicompressc/libczicompressc.nuspec @@ -0,0 +1,16 @@ + + + + libczicompressc + 0.5.1-alpha.0 + Native runtimes for CZI ZStd compression + Carl Zeiss Microscopy + Carl Zeiss Microscopy + Native runtimes for CZI ZStd compression + false + MIT + https://github.com/zeissmicroscopy/czicompress/ + © Carl Zeiss Microscopy GmbH and others. All rights reserved. + + + \ No newline at end of file diff --git a/czishrink/libczicompressc/runtimes/linux-x64/native/libczicompressc.so b/czishrink/libczicompressc/runtimes/linux-x64/native/libczicompressc.so new file mode 100644 index 0000000..e69de29 diff --git a/czishrink/libczicompressc/runtimes/win-x64/native/libczicompressc.dll b/czishrink/libczicompressc/runtimes/win-x64/native/libczicompressc.dll new file mode 100644 index 0000000..e69de29 diff --git a/czishrink/netczicompress.Desktop/Program.cs b/czishrink/netczicompress.Desktop/Program.cs new file mode 100644 index 0000000..0af9f69 --- /dev/null +++ b/czishrink/netczicompress.Desktop/Program.cs @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Desktop; + +using System; +using System.Diagnostics; +using Avalonia; +using Avalonia.ReactiveUI; +using Projektanker.Icons.Avalonia; +using Projektanker.Icons.Avalonia.FontAwesome; + +internal class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) + { + // NOTE: when in use, a GUID will be prepended to the filename. + using TextWriterTraceListener listener = CreateTraceListener(); + Trace.Listeners.Add(listener); + Trace.AutoFlush = true; + + try + { + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + } + finally + { + Trace.Flush(); + Trace.Listeners.Remove(listener); + } + } + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + { + IconProvider.Current + .Register(); + + return AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(level: Avalonia.Logging.LogEventLevel.Error) + .UseReactiveUI(); + } + + private static TextWriterTraceListener CreateTraceListener() + { + var progName = typeof(Program).Assembly.GetName().Name ?? "CziShrink"; + var traceLogFolder = System.IO.Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + progName); + if (!Directory.Exists(traceLogFolder)) + { + try + { + Directory.CreateDirectory(traceLogFolder); + } + catch (Exception ex) + { + Trace.TraceError(ex.ToString()); + } + } + + var traceLogFile = System.IO.Path.Combine( + traceLogFolder, + $"{progName}.log"); + var listener = new TextWriterTraceListener(traceLogFile, "logFileListener"); + return listener; + } +} diff --git a/czishrink/netczicompress.Desktop/app.manifest b/czishrink/netczicompress.Desktop/app.manifest new file mode 100644 index 0000000..515802e --- /dev/null +++ b/czishrink/netczicompress.Desktop/app.manifest @@ -0,0 +1,25 @@ + + + + + + + + true + + + + + + + + + + + + + diff --git a/czishrink/netczicompress.Desktop/netczicompress.Desktop.csproj b/czishrink/netczicompress.Desktop/netczicompress.Desktop.csproj new file mode 100644 index 0000000..c863f1e --- /dev/null +++ b/czishrink/netczicompress.Desktop/netczicompress.Desktop.csproj @@ -0,0 +1,27 @@ + + + WinExe + true + app.manifest + ..\netczicompress\Assets\netczicompress.ico + CziShrink + x64 + + + + PreserveNewest + + + PreserveNewest + + + + + + + + + + + + diff --git a/czishrink/netczicompress.sln b/czishrink/netczicompress.sln new file mode 100644 index 0000000..f915d18 --- /dev/null +++ b/czishrink/netczicompress.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33829.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "netczicompress", "netczicompress\netczicompress.csproj", "{886596AD-1451-4567-AC42-76182C9C187B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "netczicompress.Desktop", "netczicompress.Desktop\netczicompress.Desktop.csproj", "{433ABC81-4FAA-4328-9832-4416644391D5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "netczicompressTests", "netczicompressTests\netczicompressTests.csproj", "{8B1A7EB0-48FE-4DF3-B23A-46F520565052}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {886596AD-1451-4567-AC42-76182C9C187B}.Debug|x64.ActiveCfg = Debug|x64 + {886596AD-1451-4567-AC42-76182C9C187B}.Debug|x64.Build.0 = Debug|x64 + {886596AD-1451-4567-AC42-76182C9C187B}.Release|x64.ActiveCfg = Release|x64 + {886596AD-1451-4567-AC42-76182C9C187B}.Release|x64.Build.0 = Release|x64 + {433ABC81-4FAA-4328-9832-4416644391D5}.Debug|x64.ActiveCfg = Debug|x64 + {433ABC81-4FAA-4328-9832-4416644391D5}.Debug|x64.Build.0 = Debug|x64 + {433ABC81-4FAA-4328-9832-4416644391D5}.Release|x64.ActiveCfg = Release|x64 + {433ABC81-4FAA-4328-9832-4416644391D5}.Release|x64.Build.0 = Release|x64 + {8B1A7EB0-48FE-4DF3-B23A-46F520565052}.Debug|x64.ActiveCfg = Debug|x64 + {8B1A7EB0-48FE-4DF3-B23A-46F520565052}.Debug|x64.Build.0 = Debug|x64 + {8B1A7EB0-48FE-4DF3-B23A-46F520565052}.Release|x64.ActiveCfg = Release|x64 + {8B1A7EB0-48FE-4DF3-B23A-46F520565052}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {071D0ED6-64D2-4792-BF50-FA6C27898722} + EndGlobalSection +EndGlobal diff --git a/czishrink/netczicompress/App.axaml b/czishrink/netczicompress/App.axaml new file mode 100644 index 0000000..bbd6f42 --- /dev/null +++ b/czishrink/netczicompress/App.axaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/App.axaml.cs b/czishrink/netczicompress/App.axaml.cs new file mode 100644 index 0000000..cb2d191 --- /dev/null +++ b/czishrink/netczicompress/App.axaml.cs @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress; + +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +/// +/// The application. +/// +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (this.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = AppComposer.ComposeMainWindow(); + } + else if (this.ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + { + singleViewPlatform.MainView = AppComposer.ComposeMainWindow(); + } + + base.OnFrameworkInitializationCompleted(); + } +} diff --git a/czishrink/netczicompress/AppComposer.cs b/czishrink/netczicompress/AppComposer.cs new file mode 100644 index 0000000..b91ae05 --- /dev/null +++ b/czishrink/netczicompress/AppComposer.cs @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress; + +using System.IO.Abstractions; + +using Microsoft.Extensions.Logging; + +using netczicompress.Models; +using netczicompress.Models.Clipboard; +using netczicompress.ViewModels; +using netczicompress.Views; + +using ReactiveUI; + +/// +/// Composes the application with 'Pure DI'. +/// +public class AppComposer +{ + public static MainWindow ComposeMainWindow() + { + var info = new ProgramNameAndVersion(); + var mainViewModel = ComposeMainViewModel(info); + + return new MainWindow + { + DataContext = mainViewModel, + Title = info.Name, + }; + } + + public static MainViewModel ComposeMainViewModel(IProgramNameAndVersion info) + { + // Parameters that we might have to tweak + const int MaxNumberOfErrorsToShow = 1000; + const int ErrorBufferSize = 100; + var errorBufferInterval = TimeSpan.FromSeconds(1); + + var statisticsReportingInterval = TimeSpan.FromSeconds(1); + + // Actual composition code + var fs = new FileSystem(); + string libraryNameAndVersion = PInvokeFileProcessor.GetLibFullName(); + + ILoggerFactory loggerfactory = new TraceLoggerFactory(); + var logger = loggerfactory.CreateLogger(); + logger.LogInformation("Starting {CZI Shrink} using {libczicompressc}", info, libraryNameAndVersion); + + var noOp = new NoOpFileProcessor(); + IFileProcessor CreateFileProcessor(CompressionMode mode, ProcessingOptions options) => mode switch + { + CompressionMode.NoOp => noOp, + _ => PInvokeFileProcessor.Create(mode, options), + }; + IFolderCompressor compressor = new MultiThreadedFolderCompressor(CreateFileProcessor, new FileProcessingFailedHandler()); + + IFileLauncher fileLauncher = new FileLauncher(fs, Environment.GetEnvironmentVariable); + var gui = RxApp.MainThreadScheduler; + var errorList = new ErrorListViewModel( + maxNumberOfErrorsToShow: MaxNumberOfErrorsToShow, + bufferInterval: errorBufferInterval, + bufferCapacity: ErrorBufferSize, + scheduler: gui, + launcher: fileLauncher); + var currentTasks = new CurrentTasksViewModel(scheduler: gui); + var logViewModel = new LogFileViewModel(new CsvLoggingStrategy(fileLauncher), gui); + + var aggregateIndicationViewModel = new AggregateIndicationViewModel(); + var aggregateStatisticsViewModel = new AggregateStatisticsViewModel( + aggregateIndicationViewModel: aggregateIndicationViewModel, + ClipboardHelper.Instance, + logger: loggerfactory.CreateLogger()) + { + OpenLogFileCommand = logViewModel.OpenLogFileCommand, + }; + + var statisticsObserver = CompositeObserver.Create(aggregateStatisticsViewModel, aggregateIndicationViewModel); + var statisticsRunObserver = new StatisticsRunObserver(statisticsObserver, statisticsReportingInterval, gui); + + compressor = compressor.DecorateWithRunObserver(statisticsRunObserver); + compressor = compressor.DecorateWithRunObserver(logViewModel); + compressor = compressor.DecorateWithRunObserver(errorList); + compressor = compressor.DecorateWithObserver(currentTasks, gui); + + var mainViewModel = new MainViewModel( + compressor: compressor, + fileSystem: fs, + errorList: errorList, + currentTasksViewModel: currentTasks, + aggregateStatisticsViewModel: aggregateStatisticsViewModel, + aboutViewModel: new AboutViewModel(fileLauncher, info) { LibraryName = libraryNameAndVersion }, + logger: loggerfactory.CreateLogger()); + + return mainViewModel; + } +} diff --git a/czishrink/netczicompress/Assets/Logo.png b/czishrink/netczicompress/Assets/Logo.png new file mode 100644 index 0000000..cb975df Binary files /dev/null and b/czishrink/netczicompress/Assets/Logo.png differ diff --git a/czishrink/netczicompress/Assets/netczicompress.ico b/czishrink/netczicompress/Assets/netczicompress.ico new file mode 100644 index 0000000..b0c83d0 Binary files /dev/null and b/czishrink/netczicompress/Assets/netczicompress.ico differ diff --git a/czishrink/netczicompress/FodyWeavers.xml b/czishrink/netczicompress/FodyWeavers.xml new file mode 100644 index 0000000..63fc148 --- /dev/null +++ b/czishrink/netczicompress/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Models/AggregateStatistics.cs b/czishrink/netczicompress/Models/AggregateStatistics.cs new file mode 100644 index 0000000..2816af5 --- /dev/null +++ b/czishrink/netczicompress/Models/AggregateStatistics.cs @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; + +/// +/// Cumulative statistics of a compression or decompression operation. +/// +public readonly record struct AggregateStatistics +{ + public static AggregateStatistics Empty { get; } = default; + + public int FilesWithErrors { get; init; } + + public int FilesWithNoErrors { get; init; } + + public TimeSpan Duration { get; init; } + + public long InputBytes { get; init; } + + public long OutputBytes { get; init; } + + public long DeltaBytes => this.OutputBytes - this.InputBytes; + + public float OutputToInputRatio => 1.0f * this.OutputBytes / this.InputBytes; +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/AsyncEnumerableToObservableActionAdapter.cs b/czishrink/netczicompress/Models/AsyncEnumerableToObservableActionAdapter.cs new file mode 100644 index 0000000..b9bd242 --- /dev/null +++ b/czishrink/netczicompress/Models/AsyncEnumerableToObservableActionAdapter.cs @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Collections.Generic; +using System.Reactive.Concurrency; +using System.Reactive.Linq; +using System.Reactive.Subjects; +using System.Threading; +using System.Threading.Tasks; + +/// +/// An adapter from an to an . +/// +/// The type of the produced items. +public class AsyncEnumerableToObservableActionAdapter : IObservableAction +{ + private readonly IAsyncEnumerable enumerable; + private readonly CancellationToken token; + private readonly Subject subject = new(); + private bool started; + + public AsyncEnumerableToObservableActionAdapter(IAsyncEnumerable enumerable, CancellationToken token) + { + this.enumerable = enumerable; + this.token = token; + this.Output = this.subject.AsObservable(); + } + + /// + /// + /// This observable may deliver items on another thread than the thread that calls . + /// + /// Use an appropriate to observe it. + /// + public IObservable Output { get; } + + /// + public void Start() + { + if (this.started) + { + throw new InvalidOperationException($"{nameof(this.Start)} can only be called once."); + } + + this.started = true; + + Core(); + + async void Core() + { + try + { + await foreach (var item in this.enumerable.WithCancellation(this.token).ConfigureAwait(false)) + { + this.subject.OnNext(item); + } + + this.subject.OnCompleted(); + } + catch (Exception ex) + { + this.subject.OnError(ex); + } + } + } +} diff --git a/czishrink/netczicompress/Models/Clipboard/ClipboardHelper.cs b/czishrink/netczicompress/Models/Clipboard/ClipboardHelper.cs new file mode 100644 index 0000000..698a0ed --- /dev/null +++ b/czishrink/netczicompress/Models/Clipboard/ClipboardHelper.cs @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models.Clipboard; + +using System.Runtime.InteropServices; + +internal static class ClipboardHelper +{ + private static readonly IClipboardHelper? InstanceValue; + + static ClipboardHelper() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + InstanceValue = new ClipboardHelperWin32(); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + InstanceValue = new ClipboardHelperLinux(); + } + } + + public static IClipboardHelper? Instance + { + get + { + return InstanceValue; + } + } +} diff --git a/czishrink/netczicompress/Models/Clipboard/ClipboardHelperLinux.cs b/czishrink/netczicompress/Models/Clipboard/ClipboardHelperLinux.cs new file mode 100644 index 0000000..039e265 --- /dev/null +++ b/czishrink/netczicompress/Models/Clipboard/ClipboardHelperLinux.cs @@ -0,0 +1,59 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models.Clipboard; + +using System.Diagnostics; +using Avalonia.Media.Imaging; + +/// +/// This is an implementation of the IClipboardHelper interface for the X-Windows system. We use the +/// utility "xclip" as an external program which we launch and pass to it the bitmap as a PNG. +/// +internal class ClipboardHelperLinux : IClipboardHelper +{ + public void PutBitmapIntoClipboard(Bitmap bitmap) + { + if (bitmap == null) + { + throw new ArgumentNullException(nameof(bitmap)); + } + + using (var memoryStream = new MemoryStream()) + { + bitmap.Save(memoryStream); + memoryStream.Position = 0; + ClipboardHelperLinux.SetImageToClipboard(memoryStream, "image/png"); + } + } + + private static void SetImageToClipboard(Stream imageData, string mimeType) + { + var startInfo = new ProcessStartInfo + { + FileName = "xclip", + ArgumentList = + { + "-selection", "clipboard", + "-t", mimeType, + "-i", + }, + RedirectStandardInput = true, + UseShellExecute = false, + CreateNoWindow = true, + }; + + using (var process = new Process { StartInfo = startInfo }) + { + process.Start(); + + // the png is now written to stdout + imageData.CopyTo(process.StandardInput.BaseStream); + + // then we close stdout, and xclip will start operation + process.StandardInput.Close(); + process.WaitForExit(); + } + } +} diff --git a/czishrink/netczicompress/Models/Clipboard/ClipboardHelperWin32.cs b/czishrink/netczicompress/Models/Clipboard/ClipboardHelperWin32.cs new file mode 100644 index 0000000..b2ad876 --- /dev/null +++ b/czishrink/netczicompress/Models/Clipboard/ClipboardHelperWin32.cs @@ -0,0 +1,331 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models.Clipboard; + +using System.Runtime.InteropServices; +using Avalonia; +using Avalonia.Media.Imaging; +using Avalonia.Platform; + +/// +/// An implementation of the IClipboardHelper interface based on Win32-API. +/// Obviously, this code is only operational if running on Win32 - which is not +/// checked here (i.e. it is assumed that platform specific dispatching is taking +/// place before using this code). +/// +internal partial class ClipboardHelperWin32 : IClipboardHelper +{ + public void PutBitmapIntoClipboard(Bitmap bitmap) + { + if (bitmap == null) + { + throw new ArgumentNullException(nameof(bitmap)); + } + + if (bitmap.Format != PixelFormat.Bgra8888) + { + throw new ArgumentException("Bitmap is expected to be in PixelFormat.Bgra8888, conversion is not implemented"); + } + + nint hBitmap = 0; + nint screenDC = 0; + nint sourceDC = 0; + nint destDC = 0; + nint compatibleBitmap = 0; + bool clipboardOpened = false; + + try + { + hBitmap = ClipboardHelperWin32.CreateHBitmapFromAvalonBitmap(bitmap); + + screenDC = Win32UnmanagedMethods.GetDC(IntPtr.Zero); + if (screenDC == 0) + { + throw new Exception("Error creating screenDC"); + } + + sourceDC = Win32UnmanagedMethods.CreateCompatibleDC(screenDC); + if (sourceDC == 0) + { + throw new Exception("Error creating sourceDC"); + } + + Win32UnmanagedMethods.SelectObject(sourceDC, hBitmap); + + destDC = Win32UnmanagedMethods.CreateCompatibleDC(screenDC); + if (destDC == 0) + { + throw new Exception("Error creating destDC"); + } + + compatibleBitmap = Win32UnmanagedMethods.CreateCompatibleBitmap(screenDC, bitmap.PixelSize.Width, bitmap.PixelSize.Height); + if (compatibleBitmap == 0) + { + throw new Exception("Error creating compatibleBitmap"); + } + + Win32UnmanagedMethods.SelectObject(destDC, compatibleBitmap); + Win32UnmanagedMethods.BitBlt( + destDC, + 0, + 0, + bitmap.PixelSize.Width, + bitmap.PixelSize.Height, + sourceDC, + 0, + 0, + 0x00CC0020); // SRCCOPY + + if (!Win32UnmanagedMethods.OpenClipboard(IntPtr.Zero)) + { + throw new Exception("Error opening the clipboard"); + } + + clipboardOpened = true; + + Win32UnmanagedMethods.EmptyClipboard(); + Win32UnmanagedMethods.SetClipboardData(Win32UnmanagedMethods.ClipboardFormat.CF_BITMAP, compatibleBitmap); + } + finally + { + if (clipboardOpened) + { + Win32UnmanagedMethods.CloseClipboard(); + } + + bool success = false; + if (hBitmap != 0) + { + success = Win32UnmanagedMethods.DeleteObject(hBitmap); + } + + if (compatibleBitmap != 0) + { + success = Win32UnmanagedMethods.DeleteObject(compatibleBitmap); + } + + if (sourceDC != 0) + { + success = Win32UnmanagedMethods.DeleteDC(sourceDC); + } + + if (screenDC != 0) + { + success = Win32UnmanagedMethods.ReleaseDC(IntPtr.Zero, screenDC); + } + + if (destDC != 0) + { + success = Win32UnmanagedMethods.DeleteDC(destDC); + } + + _ = success; + } + } + + private static unsafe nint CreateHBitmapFromAvalonBitmap(Bitmap bitmap) + { + if (bitmap.Format != PixelFormat.Bgra8888) + { + throw new ArgumentException("Bitmap is expected to be in PixelFormat.Bgra8888, conversion is not implemented"); + } + + byte[] buffer = new byte[bitmap.PixelSize.Width * bitmap.PixelSize.Height * 4]; + fixed (byte* p = &buffer[0]) + { + // copy the content of the Avalonia-bitmap into the buffer + bitmap.CopyPixels(new PixelRect(bitmap.PixelSize), new IntPtr(p), buffer.Length, bitmap.PixelSize.Width * 4); + + // now, we allocate an "HBITMAP"-object and copy the data into it + Win32UnmanagedMethods.BITMAPINFO bmi = default; + bmi.bmiHeader.Init(); + bmi.bmiHeader.biWidth = bitmap.PixelSize.Width; + bmi.bmiHeader.biHeight = -bitmap.PixelSize.Height; // top-down + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 32; + bmi.bmiHeader.biCompression = Win32UnmanagedMethods.BitmapCompressionMode.BI_RGB; + IntPtr ptr = IntPtr.Zero; + nint hBitmap = Win32UnmanagedMethods.CreateDIBSection( + IntPtr.Zero, + ref bmi, + 0, /*DIB_RGB_COLORS*/ + out ptr, + IntPtr.Zero, + 0); + if (hBitmap == 0) + { + throw new Exception("CreateDIBSection failed."); + } + + int r = Win32UnmanagedMethods.SetDIBits( + IntPtr.Zero, + hBitmap, + 0, + (uint)bitmap.PixelSize.Height, + new IntPtr(p), + ref bmi, + 0); /*DIB_RGB_COLORS*/ + + if (r == 0) + { + Win32UnmanagedMethods.DeleteObject(hBitmap); + throw new Exception("SetDIBits failed."); + } + + return hBitmap; + } + } +} + +/// +/// This part contains the PInvoke definitions we need in order to "put the bitmap into the clipboard" +/// with the Win32-API. +/// +internal partial class ClipboardHelperWin32 +{ + private class Win32UnmanagedMethods + { + public enum BitmapCompressionMode : uint + { + BI_RGB = 0, + BI_RLE8 = 1, + BI_RLE4 = 2, + BI_BITFIELDS = 3, + BI_JPEG = 4, + BI_PNG = 5, + } + + public enum ClipboardFormat + { + /// + /// Text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. Use this format for ANSI text. + /// + CF_TEXT = 1, + + /// + /// A handle to a bitmap. + /// + CF_BITMAP = 2, + + /// + /// A memory object containing a BITMAPINFO structure followed by the bitmap bits. + /// + CF_DIB = 3, + + /// + /// Unicode text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. + /// + CF_UNICODETEXT = 13, + + /// + /// A handle to type HDROP that identifies a list of files. + /// + CF_HDROP = 15, + } + + [DllImport("gdi32.dll")] + public static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFO pbmi, uint pila, out IntPtr ppvBits, IntPtr hSection, uint dwOffset); + + [DllImport("gdi32.dll")] + public static extern int SetDIBits(IntPtr hdc, nint hbm, uint start, uint cLines, IntPtr lpBits, [In] ref BITMAPINFO pbmi, uint colorUse); + + [DllImport("user32.dll", ExactSpelling = true)] + public static extern IntPtr GetDC(IntPtr hWnd); + + [DllImport("gdi32.dll", EntryPoint = "DeleteDC")] + public static extern bool DeleteDC([In] IntPtr hdc); + + [DllImport("gdi32.dll", ExactSpelling = true)] + public static extern IntPtr CreateCompatibleDC(IntPtr hDC); + + [DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true)] + public static extern IntPtr SelectObject(IntPtr hdc, IntPtr h); + + [DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true)] + public static extern bool BitBlt( + IntPtr hdc, + int x, + int y, + int cx, + int cy, + IntPtr hdcSrc, + int x1, + int y1, + uint rop); + + [DllImport("gdi32.dll", ExactSpelling = true)] + public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int cx, int cy); + + [DllImport("user32.dll", SetLastError = true)] + public static extern bool OpenClipboard(IntPtr hWndOwner); + + [DllImport("user32.dll")] + public static extern bool EmptyClipboard(); + + [DllImport("user32.dll")] + public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC); + + [DllImport("user32.dll")] + public static extern IntPtr SetClipboardData(ClipboardFormat uFormat, IntPtr hMem); + + [DllImport("user32.dll", SetLastError = true)] + public static extern bool CloseClipboard(); + + [DllImport("gdi32.dll", EntryPoint = "DeleteObject")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DeleteObject([In] IntPtr hObject); + + [StructLayout(LayoutKind.Sequential)] + public struct BITMAPINFOHEADER + { +#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter + public uint biSize; + public int biWidth; + public int biHeight; + public ushort biPlanes; + public ushort biBitCount; + public BitmapCompressionMode biCompression; + public uint biSizeImage; + public int biXPelsPerMeter; + public int biYPelsPerMeter; + public uint biClrUsed; + public uint biClrImportant; +#pragma warning restore SA1307 // Accessible fields should begin with upper-case letter + + public void Init() + { + this.biSize = (uint)Marshal.SizeOf(this); + } + } + + [StructLayout(LayoutKind.Sequential)] + public struct RGBQUAD + { +#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter + public byte rgbBlue; + public byte rgbGreen; + public byte rgbRed; + public byte rgbReserved; +#pragma warning restore SA1307 // Accessible fields should begin with upper-case letter + } + + [StructLayoutAttribute(LayoutKind.Sequential)] + public struct BITMAPINFO + { +#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter + /// + /// A BITMAPINFOHEADER structure that contains information about the dimensions of color format. + /// + public BITMAPINFOHEADER bmiHeader; + + /// + /// An array of RGBQUAD. The elements of the array that make up the color table. + /// + [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 1, ArraySubType = UnmanagedType.Struct)] + public RGBQUAD[] bmiColors; +#pragma warning restore SA1307 // Accessible fields should begin with upper-case letter + } + } +} diff --git a/czishrink/netczicompress/Models/Clipboard/IClipboardHelper.cs b/czishrink/netczicompress/Models/Clipboard/IClipboardHelper.cs new file mode 100644 index 0000000..3377885 --- /dev/null +++ b/czishrink/netczicompress/Models/Clipboard/IClipboardHelper.cs @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models.Clipboard; + +using Avalonia.Media.Imaging; + +/// +/// Interface for utilities for interacting with the clipboard. +/// Unfortunately, the platform agnostic support in Avalonia is quite limited at this time, +/// so the idea here is to provide just enough functionality with platform specific implementations. +/// +public interface IClipboardHelper +{ + /// + /// Puts the specified bitmap into the system clipboard. It is a simplistic implementation, + /// the data is copied right away, meaning that the bitmap should not be large in size, a couple of + /// kilobytes is fine. Also, the pixel format of the bitmap must be PixelFormat.Bgra8888, there is + /// no conversion in place currently. + /// + /// The bitmap to put on the clipboard. + void PutBitmapIntoClipboard(Bitmap bitmap); +} diff --git a/czishrink/netczicompress/Models/CompositeObserver.cs b/czishrink/netczicompress/Models/CompositeObserver.cs new file mode 100644 index 0000000..1078ab5 --- /dev/null +++ b/czishrink/netczicompress/Models/CompositeObserver.cs @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; + +/// +/// Static class to create composite observers. +/// +public static class CompositeObserver +{ + public static IObserver Create(params IObserver[] observers) + { + return new CompositeObserverImpl(observers); + } + + /// + /// A composite . + /// + /// The observed type. + public sealed class CompositeObserverImpl : IObserver + { + private readonly IObserver[] observers; + + public CompositeObserverImpl(params IObserver[] observers) + { + this.observers = observers; + } + + public void OnCompleted() + { + this.ForEachObserver(o => o.OnCompleted()); + } + + public void OnError(Exception error) + { + this.ForEachObserver(o => o.OnError(error)); + } + + public void OnNext(T value) + { + this.ForEachObserver(o => o.OnNext(value)); + } + + private void ForEachObserver(Action> action) + { + foreach (var item in this.observers) + { + action(item); + } + } + } +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/CompressionLevel.cs b/czishrink/netczicompress/Models/CompressionLevel.cs new file mode 100644 index 0000000..4bf99cb --- /dev/null +++ b/czishrink/netczicompress/Models/CompressionLevel.cs @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System.ComponentModel.DataAnnotations; + +/// +/// Defines Zstd compression levels. +/// +public record CompressionLevel +{ + private readonly int internalValue = DefaultValue; + + public static readonly CompressionLevel Default; + + static CompressionLevel() + { + Default = new CompressionLevel() { Value = DefaultValue }; + } + + /// + /// Gets the minimum allowed compression level. + /// + /// In this application the value is 0, though Zstd would allow values down to -131072. + public static int Minimum { get; } = 0; + + /// + /// Gets maximum allowed compression level. + /// + /// The value of this property is 22. + public static int Maximum { get; } = 22; + + /// + /// Gets default compression level if not specified. + /// + /// The value of this property is 1. + public static int DefaultValue { get; } = 1; + + [Range(0, 22)] + public int Value + { + get => this.internalValue; + init => + this.internalValue = value > Maximum || value < Minimum + ? throw new ArgumentOutOfRangeException( + paramName: nameof(value), + message: $"{nameof(value)} must be between {Minimum} and {Maximum}, not {value}") + : value; + } +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/CompressionMode.cs b/czishrink/netczicompress/Models/CompressionMode.cs new file mode 100644 index 0000000..83fb124 --- /dev/null +++ b/czishrink/netczicompress/Models/CompressionMode.cs @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +/// +/// The compression modes supported by the application. +/// +public enum CompressionMode +{ + CompressUncompressed, + CompressAll, + CompressUncompressedAndZstd, + Decompress, + NoOp, +} diff --git a/czishrink/netczicompress/Models/CompressorMessage.cs b/czishrink/netczicompress/Models/CompressorMessage.cs new file mode 100644 index 0000000..ebb9a5b --- /dev/null +++ b/czishrink/netczicompress/Models/CompressorMessage.cs @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.IO.Abstractions; + +/// +/// A message containing information about the compression of a file. +/// This is a Union Type. +/// +public record CompressorMessage +{ + private CompressorMessage() + { + } + + /// Message emitted when we have finished processing a file. + /// The file currently being processed. + /// The input size of the file. + /// The output size of the file. + /// The time elapsed processing the file. + /// An optional error message. + public record FileFinished(IFileInfo InputFile, long SizeInput, long SizeOutput, TimeSpan? TimeElapsed, + string? ErrorMessage) + : CompressorMessage + { + public decimal SizeRatio { get; } = SizeInput != 0 ? (decimal)SizeOutput / SizeInput : 0; + + public long SizeDelta { get; } = SizeOutput - SizeInput; + } + + /// + /// Message emitted when we start processing a file. + /// + /// The input file. + /// An observable that reports the progress in percent. + public record FileStarting(IFileInfo InputFile, IObservable ProgressPercent) + : CompressorMessage; +} diff --git a/czishrink/netczicompress/Models/CreateProcessor.cs b/czishrink/netczicompress/Models/CreateProcessor.cs new file mode 100644 index 0000000..b07f1dc --- /dev/null +++ b/czishrink/netczicompress/Models/CreateProcessor.cs @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +public delegate IFileProcessor CreateProcessor(CompressionMode mode, ProcessingOptions options); \ No newline at end of file diff --git a/czishrink/netczicompress/Models/CsvLogFileWriter.cs b/czishrink/netczicompress/Models/CsvLogFileWriter.cs new file mode 100644 index 0000000..8ce02e0 --- /dev/null +++ b/czishrink/netczicompress/Models/CsvLogFileWriter.cs @@ -0,0 +1,88 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Diagnostics; +using System.IO; + +/// +/// Writes a sequence of messages to a CSV file. +/// +public class CsvLogFileWriter : IObserver +{ + private bool isCompleted; + + public CsvLogFileWriter(TextWriter writer) + { + this.Writer = writer; + this.WriteHeader(); + } + + public TextWriter Writer { get; } + + public void OnCompleted() + { + lock (this.Writer) + { + this.isCompleted = true; + this.Writer.Flush(); + this.Writer.Close(); + } + } + + public void OnError(Exception error) + { + this.OnCompleted(); + } + + public void OnNext(CompressorMessage.FileFinished value) + { + this.Write(ToLine(value)); + } + + private static string ToLine(CompressorMessage.FileFinished value) + { + return string.Join( + ',', + Quote(value.InputFile.FullName), + value.SizeInput, + value.SizeOutput, + value.ErrorMessage == null ? value.SizeRatio : string.Empty, + value.ErrorMessage == null ? value.SizeDelta : string.Empty, + value.TimeElapsed?.ToString("c") ?? string.Empty, + value.ErrorMessage == null ? "SUCCESS" : "ERROR", + Quote(value.ErrorMessage)) + "\r\n"; + } + + private static string Quote(string? value) + { + if (value == null) + { + return string.Empty; + } + + return '"' + value.Replace("\"", "\"\"") + '"'; + } + + private void WriteHeader() + { + this.Write("InputFile,SizeInput,SizeOutput,SizeRatio,SizeDelta,TimeToProcess,Status,ErrorMessage\r\n"); + } + + private void Write(string line) + { + lock (this.Writer) + { + if (this.isCompleted) + { + Debug.WriteLine($"{nameof(CsvLogFileWriter)}: received a message after completion..."); + return; + } + + this.Writer.Write(line); + } + } +} diff --git a/czishrink/netczicompress/Models/CsvLoggingStrategy.cs b/czishrink/netczicompress/Models/CsvLoggingStrategy.cs new file mode 100644 index 0000000..feae883 --- /dev/null +++ b/czishrink/netczicompress/Models/CsvLoggingStrategy.cs @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.IO; +using System.IO.Abstractions; +using System.Reactive.Concurrency; + +/// +/// A logging strategy that writes data to a CSV log file. +/// +public class CsvLoggingStrategy : ILoggingStrategy +{ + private readonly IFileLauncher fileLauncher; + + public CsvLoggingStrategy(IFileLauncher fileLauncher) + { + this.fileLauncher = fileLauncher; + } + + /// + /// Gets the scheduler to use for logging. + /// + public IScheduler LoggerScheduler { get; init; } = DefaultScheduler.Instance; + + public IFileInfo CreateLogFile(FolderCompressorParameters run) + { + var outDir = run.OutputDir; + var fs = outDir.FileSystem; + IFileInfo result; + do + { + var outFileName = fs.Path.Combine( + outDir.FullName, + $"CziShrink_{this.LoggerScheduler.Now.ToLocalTime():yyyyMMdd'T'HHmmss}_{run.Mode}.csv"); + + result = fs.FileInfo.New(outFileName); + } + while (result.Exists); + + return result; + } + + public IObserver CreateLogger(TextWriter writer) + { + return new CsvLogFileWriter(writer); + } + + public Task OpenLogFile(IFileInfo logFile) + { + return this.fileLauncher.Launch(logFile.FullName); + } +} diff --git a/czishrink/netczicompress/Models/ExecutionOptions.cs b/czishrink/netczicompress/Models/ExecutionOptions.cs new file mode 100644 index 0000000..4c7033c --- /dev/null +++ b/czishrink/netczicompress/Models/ExecutionOptions.cs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +/// +/// Execution options to apply to operations. +/// +/// The maximum number of threads to use. +public record ExecutionOptions(ThreadCount ThreadCount); \ No newline at end of file diff --git a/czishrink/netczicompress/Models/FileLauncher.cs b/czishrink/netczicompress/Models/FileLauncher.cs new file mode 100644 index 0000000..b9e497c --- /dev/null +++ b/czishrink/netczicompress/Models/FileLauncher.cs @@ -0,0 +1,144 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System.Diagnostics; +using System.IO.Abstractions; + +/// +/// Launches a file with its associated app, +/// or displays a file in its folder with the operating system's file manager. +/// +public class FileLauncher : IFileLauncher +{ + // Cf. https://github.com/dotnet/runtime/blob/52806bc157decf345005249c9ea7969c8b9e7e1b/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs#L14C9-L41C6 + private const string Windows = "WINDOWS"; + private const string Osx = "OSX"; + private const string Linux = "LINUX"; + private const string FreeBsd = "FREEBSD"; + private const string NetBsd = "NETBSD"; + private const string Solaris = "SOLARIS"; + + private const string Unsupported = "UNSUPPORTED"; + private static readonly string[] SupportedPlatforms = + { + Windows, + Osx, + Linux, + FreeBsd, + NetBsd, + Solaris, + }; + + private readonly IFileSystem fs; + private readonly Func getEnvironmentVariable; + + public FileLauncher(IFileSystem fs, Func getEnvironmentVariable) + { + this.fs = fs; + this.getEnvironmentVariable = getEnvironmentVariable; + } + + protected string CurrentPlatform { get; init; } = GetPlatform(); + + public Task Launch(string path) + { + return this.RunAsync(GetLaunchStartInfo(path)); + } + + // Adapted from https://stackoverflow.com/a/73409251 + public async Task Reveal(string path) + { + var startInfo = this.GetRevealStartInfo(path); + var exitCode = await this.RunAsync(startInfo); + + if (exitCode != 0 && startInfo.FileName == "dbus-send") + { + // dbus-send was unsuccessful + await this.RunAsync(this.GetOpenParentFolderStartInfo(path)); + } + } + + protected virtual async Task RunAsync(ProcessStartInfo processStartInfo) + { + using var process = new Process { StartInfo = processStartInfo }; + process.Start(); + await process.WaitForExitAsync(); + return process.ExitCode; + } + + protected virtual string PathToFileUri(string path) + { + return new Uri(path).AbsoluteUri; + } + + private static string GetPlatform() + { + return SupportedPlatforms.FirstOrDefault(x => OperatingSystem.IsOSPlatform(x)) ?? Unsupported; + } + + private static ProcessStartInfo GetRevealStartInfoOsx(string path) + { + return new ProcessStartInfo + { + FileName = "explorer", + Arguments = $"-R \"{path}\"", + }; + } + + private static ProcessStartInfo GetLaunchStartInfo(string? path) + { + return new ProcessStartInfo + { + FileName = path, + UseShellExecute = true, + }; + } + + private ProcessStartInfo GetRevealStartInfoWindows(string path) + { + var fileName = "explorer"; + var sysRoot = this.getEnvironmentVariable("SYSTEMROOT"); + if (sysRoot != null) + { + fileName = this.fs.Path.Combine(sysRoot, fileName); + } + + return new ProcessStartInfo + { + FileName = fileName, + Arguments = $"/select,\"{path}\"", + }; + } + + private ProcessStartInfo GetRevealStartInfoDBus(string path) + { + string fileUri = this.PathToFileUri(path); + return new ProcessStartInfo() + { + FileName = "dbus-send", + Arguments = $"--print-reply --dest=org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:\"{fileUri}\" string:\"\"", + UseShellExecute = true, + }; + } + + private ProcessStartInfo GetOpenParentFolderStartInfo(string path) + { + return GetLaunchStartInfo(this.fs.Path.GetDirectoryName(path)); + } + + private ProcessStartInfo GetRevealStartInfo(string path) + { + Func core = this.CurrentPlatform switch + { + Windows => this.GetRevealStartInfoWindows, + Osx => GetRevealStartInfoOsx, + Unsupported => this.GetOpenParentFolderStartInfo, + _ => this.GetRevealStartInfoDBus, + }; + + return core(path); + } +} diff --git a/czishrink/netczicompress/Models/FileProcessingFailedHandler.cs b/czishrink/netczicompress/Models/FileProcessingFailedHandler.cs new file mode 100644 index 0000000..737caea --- /dev/null +++ b/czishrink/netczicompress/Models/FileProcessingFailedHandler.cs @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System.IO.Abstractions; + +/// +/// A handler which deals with the case when a file processing fails. +/// +public class FileProcessingFailedHandler +{ + public const string SuccessfulCopyMessage = "The file was copied as-is to the output folder."; + public const string FailedCopyMessage = "The file could not be copied to the output folder."; + + /// + /// Handles the case when a file processing has failed. + /// + /// The input file. + /// The output file. + /// The temporary output file. + /// The delegate to report progress. + /// The inner exception, that has occurred. + /// A value indicating whether the failed file should by copied. + /// The cancellation token. + /// A message which described how the failed file processing was handled. + /// Thrown when any argument is null. + public string FileProcessingFailed( + IFileInfo inFile, + IFileInfo outFile, + IFileInfo tempOutFile, + ReportProgress reportProgress, + string innerException, + bool copyFailedFile, + CancellationToken cancellationToken) + { + if (copyFailedFile) + { + return CopyFile(inFile, outFile, tempOutFile, reportProgress, cancellationToken) + ? $"{innerException} {SuccessfulCopyMessage}" + : $"{innerException} {FailedCopyMessage}"; + } + + return innerException; + } + + private static bool TryDelete(IFileInfo fileInfo) + { + try + { + fileInfo.Delete(); + } + catch (Exception) + { + return false; + } + + return true; + } + + private static bool CopyFile( + IFileInfo inFile, + IFileInfo outFile, + IFileInfo tempOutFile, + ReportProgress reportProgress, + CancellationToken cancellationToken) + { + try + { + CopyWithProgress(inFile.FullName, tempOutFile.FullName, reportProgress, cancellationToken); + tempOutFile.Refresh(); + tempOutFile.MoveTo(outFile.FullName); + return true; + } + catch (Exception) + { + // Remove partially written file + _ = TryDelete(outFile); + _ = TryDelete(tempOutFile); + return false; + } + } + + private static void CopyWithProgress( + string inPath, + string outPath, + ReportProgress reportProgress, + CancellationToken cancellationToken) + { + long totalBytesWritten = 0; + int bufferLength = 1024 * 1024; + byte[] buffer = new byte[bufferLength]; + using var inStream = new FileStream(inPath, FileMode.Open); + using var tempOutStream = new FileStream(outPath, FileMode.CreateNew); + + int bytesRead = inStream.Read(buffer, 0, bufferLength); + + do + { + cancellationToken.ThrowIfCancellationRequested(); + + tempOutStream.Write(buffer, 0, bytesRead); + totalBytesWritten += bytesRead; + + int progress = inStream.Length != 0 ? (int)(((totalBytesWritten * 1.0) / inStream.Length) * 100) : 100; + reportProgress.Invoke(progress); + + bytesRead = inStream.Read(buffer, 0, bufferLength); + } + while (bytesRead > 0); + } +} diff --git a/czishrink/netczicompress/Models/FolderCompressorDecorator.cs b/czishrink/netczicompress/Models/FolderCompressorDecorator.cs new file mode 100644 index 0000000..0d2f026 --- /dev/null +++ b/czishrink/netczicompress/Models/FolderCompressorDecorator.cs @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Threading; + +/// +/// Decorates an with configurable output observation. +/// +public class FolderCompressorDecorator : IFolderCompressor +{ + /// + /// Gets the core instance to wrap. + /// + public required IFolderCompressor Core { get; init; } + + /// + /// Gets the action that is used to start observing the output of the folder compressor. + /// + /// The observable that is passed to will terminate if the + /// returned is started. + /// In that case, their is no need to explicitly dispose subscriptions. + /// + public required Action> ObserveRun { get; init; } + + public IFolderCompressorRun PrepareNewRun(FolderCompressorParameters parameters, CancellationToken token) + { + var result = this.Core.PrepareNewRun(parameters, token); + this.ObserveRun(parameters, result.Output); + return result; + } +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/FolderCompressorExtensions.cs b/czishrink/netczicompress/Models/FolderCompressorExtensions.cs new file mode 100644 index 0000000..33c9010 --- /dev/null +++ b/czishrink/netczicompress/Models/FolderCompressorExtensions.cs @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Reactive.Concurrency; +using System.Reactive.Linq; + +/// +/// Extensions for . +/// +public static class FolderCompressorExtensions +{ + public static IFolderCompressor Decorate(this IFolderCompressor self, Action> observeRun) + where TMessage : CompressorMessage + { + return new FolderCompressorDecorator + { + Core = self, + ObserveRun = (parameters, output) => observeRun(parameters, output.OfType()), + }; + } + + public static IFolderCompressor DecorateWithRunObserver(this IFolderCompressor self, IFolderCompressorRunObserver runObserver) + where TMessage : CompressorMessage + { + return self.Decorate(runObserver.ObserveRun); + } + + public static IFolderCompressor DecorateWithObserver(this IFolderCompressor self, IObserver observer, IScheduler scheduler) + where TMessage : CompressorMessage + { + return self.Decorate((parameters, output) => output.ObserveOn(scheduler).Subscribe(observer)); + } +} diff --git a/czishrink/netczicompress/Models/FolderCompressorParameters.cs b/czishrink/netczicompress/Models/FolderCompressorParameters.cs new file mode 100644 index 0000000..008fe52 --- /dev/null +++ b/czishrink/netczicompress/Models/FolderCompressorParameters.cs @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System.IO.Abstractions; + +/// +/// A parameter-object that contains the parameters for . +/// +/// The input directory. +/// The output directory. +/// True if the input directory should be scanned recursively, else false. +/// The compression mode. +/// Execution options to apply to operations. +/// Additional processing options. +public record FolderCompressorParameters( + IDirectoryInfo InputDir, + IDirectoryInfo OutputDir, + bool Recursive, + CompressionMode Mode, + ExecutionOptions ExecutionOptions, + ProcessingOptions ProcessingOptions); \ No newline at end of file diff --git a/czishrink/netczicompress/Models/IFileLauncher.cs b/czishrink/netczicompress/Models/IFileLauncher.cs new file mode 100644 index 0000000..adc5703 --- /dev/null +++ b/czishrink/netczicompress/Models/IFileLauncher.cs @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +/// +/// A service that launches a file with its associated app. +/// +public interface IFileLauncher +{ + /// + /// Launches the specified file or folder with its associated app. + /// + /// The file or folder to launch. + /// A task that represents the operation. + Task Launch(string path); + + /// + /// Shows the specified file or folder in the operating system's file manager. + /// + /// The file or folder to show. + /// A task that represents the operation. + Task Reveal(string path); +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/IFileProcessor.cs b/czishrink/netczicompress/Models/IFileProcessor.cs new file mode 100644 index 0000000..1b74ebc --- /dev/null +++ b/czishrink/netczicompress/Models/IFileProcessor.cs @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Threading; + +/// +/// An object that can process a single file. +/// +public interface IFileProcessor : IDisposable +{ + /// + /// Gets a value indicating whether the file processor needs the output directory to exist when + /// is called. + /// + bool NeedsExistingOutputDirectory { get; } + + /// + /// Processes a single input file to a single output file. + /// + /// The absolute path of the input file. + /// The absolute path of the output file. + /// The progress delegate. + /// The cancellation token. + void ProcessFile(string inputPath, string outputPath, ReportProgress progressReport, CancellationToken token); +} diff --git a/czishrink/netczicompress/Models/IFolderCompressor.cs b/czishrink/netczicompress/Models/IFolderCompressor.cs new file mode 100644 index 0000000..e14de5e --- /dev/null +++ b/czishrink/netczicompress/Models/IFolderCompressor.cs @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System.Threading; + +/// +/// An object that can compress files in an input folder to an output folder. +/// +public interface IFolderCompressor +{ + /// + /// Prepare a new compressor run with the specified parameters. + /// + /// Parameters of the compression operation that is to be performed. + /// The cancellation token. + /// A new compressor run. + /// + /// The actual compression is started when the method is called on the returned object. + /// + IFolderCompressorRun PrepareNewRun(FolderCompressorParameters parameters, CancellationToken token); +} diff --git a/czishrink/netczicompress/Models/IFolderCompressorRunObserver.cs b/czishrink/netczicompress/Models/IFolderCompressorRunObserver.cs new file mode 100644 index 0000000..77cee98 --- /dev/null +++ b/czishrink/netczicompress/Models/IFolderCompressorRunObserver.cs @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; + +/// +/// An object that can observe folder compressor runs. +/// +/// The type of messages to observe. +public interface IFolderCompressorRunObserver + where TMessage : CompressorMessage +{ + void ObserveRun(FolderCompressorParameters runParameters, IObservable runMessages); +} diff --git a/czishrink/netczicompress/Models/ILoggingStrategy.cs b/czishrink/netczicompress/Models/ILoggingStrategy.cs new file mode 100644 index 0000000..24a0dc0 --- /dev/null +++ b/czishrink/netczicompress/Models/ILoggingStrategy.cs @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.IO; +using System.IO.Abstractions; +using System.Reactive.Concurrency; + +/// +/// A text-file-based logging strategy. +/// +public interface ILoggingStrategy +{ + public IScheduler LoggerScheduler { get; } + + public IFileInfo CreateLogFile(FolderCompressorParameters run); + + public IObserver CreateLogger(TextWriter writer); + + public Task OpenLogFile(IFileInfo file); +} diff --git a/czishrink/netczicompress/Models/IObservableAction.cs b/czishrink/netczicompress/Models/IObservableAction.cs new file mode 100644 index 0000000..18be592 --- /dev/null +++ b/czishrink/netczicompress/Models/IObservableAction.cs @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; + +/// +/// An action that produces a sequence of values. +/// +/// The type of the produced items. +public interface IObservableAction +{ + /// + /// Gets the output sequence. + /// + /// + /// This observable will terminate when the action completes. + /// + IObservable Output { get; } + + /// + /// Starts the action. The must complete when the action has finished. + /// + /// + /// This method can only be called once. + /// + /// Thrown when this method is called more than once. + void Start(); +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/IProgramNameAndVersion.cs b/czishrink/netczicompress/Models/IProgramNameAndVersion.cs new file mode 100644 index 0000000..be93afe --- /dev/null +++ b/czishrink/netczicompress/Models/IProgramNameAndVersion.cs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +/// +/// An object that provides program name and version info. +/// +public interface IProgramNameAndVersion +{ + string Name { get; } + + string Version { get; } +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/MultiThreadedFolderCompressor.cs b/czishrink/netczicompress/Models/MultiThreadedFolderCompressor.cs new file mode 100644 index 0000000..37ede24 --- /dev/null +++ b/czishrink/netczicompress/Models/MultiThreadedFolderCompressor.cs @@ -0,0 +1,267 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.IO.Abstractions; +using System.Reactive.Linq; +using System.Reactive.Subjects; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; + +/// +/// A multi-threaded that uses s to do the actual work. +/// +public class MultiThreadedFolderCompressor : IFolderCompressor +{ + private readonly CreateProcessor createProcessor; + private readonly FileProcessingFailedHandler fileProcessingFailedHandler; + private readonly int maxTriesToCreateTemporaryFile; + + public MultiThreadedFolderCompressor( + CreateProcessor createProcessor, + FileProcessingFailedHandler fileProcessingFailedHandler, + int maxTriesToCreateTemporaryFiles = 100) + { + this.createProcessor = createProcessor; + this.fileProcessingFailedHandler = fileProcessingFailedHandler ?? throw new ArgumentNullException(nameof(fileProcessingFailedHandler)); + this.maxTriesToCreateTemporaryFile = maxTriesToCreateTemporaryFiles; + } + + // Public only for testing. MockFileSystem does not support CaseInsensitive + public MatchCasing MatchExtensionCasing { get; init; } = MatchCasing.CaseInsensitive; + + // Public only for testing. MockFileSystem does not support AttributesToSkip + public FileAttributes AttributesToSkip { get; init; } = FileAttributes.Hidden; + + /// + public IFolderCompressorRun PrepareNewRun(FolderCompressorParameters parameters, CancellationToken token) + { + return new AsyncEnumerableToObservableActionAdapter(CoreAsync(token), token); + + async IAsyncEnumerable CoreAsync([EnumeratorCancellation] CancellationToken t = default) + { + var startTime = DateTime.UtcNow; + + var (inputDir, outputDir, recursive, mode, executionOptions, processingOptions) = parameters; + + var maxNumberOfThreads = executionOptions.ThreadCount.Value; + + var processors = new List(maxNumberOfThreads); + try + { + var activeTasks = new List>(maxNumberOfThreads); + await foreach (var file in this.EnumerateCzisAsync(inputDir, recursive, t).WithCancellation(t).ConfigureAwait(false)) + { + if (file.CreationTimeUtc >= startTime) + { + // skip files that we may have created ourselves + continue; + } + + if (t.IsCancellationRequested) + { + // Don't ThrowIfCancellationRequested here, + // we first need to wait for activeTasks to complete. + break; + } + + var thisFile = file; + var progressObservable = new BehaviorSubject(0); + + yield return new CompressorMessage.FileStarting( + thisFile, + progressObservable.DistinctUntilChanged().AsObservable()); + + IFileInfo outFile = GetOutputFileInfo(inputDir, outputDir, file); + + if (activeTasks.Count < maxNumberOfThreads) + { + var processor = this.createProcessor(mode, processingOptions); + processors.Add(processor); + activeTasks.Add(Run(processor)); + } + else + { + int index = await WaitForTaskToComplete(activeTasks).ConfigureAwait(false); + yield return await activeTasks[index].ConfigureAwait(false); + activeTasks[index].Dispose(); + activeTasks[index] = Run(processors[index]); + } + + Task Run(IFileProcessor p) => Task.Run(() => + { + try + { + return this.ProcessFile( + p, + thisFile, + outFile, + processingOptions.CopyFailedFiles, + progressObservable.OnNext, + t); + } + finally + { + // Make sure that we deliver 100 percent progress. + // This is used by observers to detect completion. + progressObservable.OnNext(100); + } + }); + } + + // No more new tasks will be started. + // Now wait for the active tasks to complete. + while (activeTasks.Count != 0) + { + int index = await WaitForTaskToComplete(activeTasks).ConfigureAwait(false); + yield return await activeTasks[index].ConfigureAwait(false); + activeTasks[index].Dispose(); + activeTasks.RemoveAt(index); + } + + t.ThrowIfCancellationRequested(); + } + finally + { + foreach (var processor in processors) + { + processor.Dispose(); + } + } + } + } + + protected virtual IAsyncEnumerable EnumerateCzisAsync( + IDirectoryInfo folder, + bool recursive, + CancellationToken token) + { + var opts = new EnumerationOptions + { + IgnoreInaccessible = true, + MatchCasing = this.MatchExtensionCasing, + RecurseSubdirectories = recursive, + BufferSize = 1 << 16, + AttributesToSkip = this.AttributesToSkip, + }; + + return folder.EnumerateFilesAsync("*.czi", opts, token); + } + + private static void EnsureParentDirectoryExists(IFileInfo outFile) + { + var outputDir = outFile.Directory; + if (outputDir?.Exists == false) + { + outputDir.Create(); + } + } + + private static async Task WaitForTaskToComplete(IReadOnlyList tasks) + { + while (true) + { + for (int i = 0; i < tasks.Count; i++) + { + if (tasks[i].IsCompleted) + { + return i; + } + } + + await Task.WhenAny(tasks).ConfigureAwait(false); + } + } + + private static IFileInfo GetOutputFileInfo(IDirectoryInfo inputDir, IDirectoryInfo outputDir, IFileInfo file) + { + var inputFileSystem = inputDir.FileSystem; + var outputFileSystem = outputDir.FileSystem; + var relativePath = inputFileSystem.Path.GetRelativePath(inputDir.FullName, file.FullName); + var outputPath = outputFileSystem.Path.Combine(outputDir.FullName, relativePath); + var outFile = outputFileSystem.FileInfo.New(outputPath); + return outFile; + } + + private CompressorMessage.FileFinished ProcessFile( + IFileProcessor processor, + IFileInfo inFile, + IFileInfo outFile, + bool copyFailedFile, + ReportProgress reportProgress, + CancellationToken token) + { + TemporaryFile? temporaryFile = null; + bool processedByProcessor = false; + try + { + if (token.IsCancellationRequested) + { + return MakeTheReturnValue(new OperationCanceledException().Message); + } + + if (outFile.Exists) + { + return MakeTheReturnValue( + errorMessage: $"Output file {outFile} already exists."); + } + + if (processor.NeedsExistingOutputDirectory) + { + EnsureParentDirectoryExists(outFile); + } + + temporaryFile = new TemporaryFile(outFile, this.maxTriesToCreateTemporaryFile); + if (temporaryFile.TemporaryFileCreationFailed) + { + var tempOutFile = temporaryFile.Info; + return MakeTheReturnValue( + errorMessage: $"Could not delete existing temporary file {tempOutFile}."); + } + + var temporaryOutFile = temporaryFile.Info; + var startTimestamp = Stopwatch.GetTimestamp(); + processor.ProcessFile(inFile.FullName, temporaryOutFile.FullName, reportProgress, token); + processedByProcessor = true; + var elapsedTime = Stopwatch.GetElapsedTime(startTimestamp); + temporaryFile.MoveToOutFileIfExists(); + return MakeTheReturnValue(timeElapsed: elapsedTime, errorMessage: null); + } + catch (Exception ex) when (ex is IOException or OperationCanceledException) + { + // Remove partially written file + temporaryFile?.DeleteAllOutFiles(); + + if (temporaryFile == null || processedByProcessor || ex is OperationCanceledException) + { + return MakeTheReturnValue(errorMessage: ex.Message); + } + + // We only cover those exceptions, that have been reported when processing the file, i.e. processedByProcessor is false. + var tempOutFile = temporaryFile.Info; + return MakeTheReturnValue( + this.fileProcessingFailedHandler.FileProcessingFailed( + inFile, + outFile, + tempOutFile, + reportProgress, + ex.Message, + copyFailedFile, + token)); + } + + CompressorMessage.FileFinished MakeTheReturnValue(string? errorMessage, TimeSpan? timeElapsed = null) + { + long inSize = inFile.Exists ? inFile.Length : 0; + long outSize = outFile.Exists ? outFile.Length : 0; + return new CompressorMessage.FileFinished(inFile, inSize, outSize, timeElapsed, errorMessage); + } + } +} diff --git a/czishrink/netczicompress/Models/NoOpFileProcessor.cs b/czishrink/netczicompress/Models/NoOpFileProcessor.cs new file mode 100644 index 0000000..3dac416 --- /dev/null +++ b/czishrink/netczicompress/Models/NoOpFileProcessor.cs @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System.Threading; + +/// +/// An that does not do anything. +/// +public sealed class NoOpFileProcessor : IFileProcessor +{ + public bool NeedsExistingOutputDirectory => false; + + public void ProcessFile(string inputPath, string outputPath, ReportProgress progressReport, CancellationToken token) + { + progressReport(100); + } + + public void Dispose() + { + } +} diff --git a/czishrink/netczicompress/Models/ObservableMixin.CompleteOnError.cs b/czishrink/netczicompress/Models/ObservableMixin.CompleteOnError.cs new file mode 100644 index 0000000..f37a52a --- /dev/null +++ b/czishrink/netczicompress/Models/ObservableMixin.CompleteOnError.cs @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +/// +/// Extensions for observable sequences. +/// +public static partial class ObservableMixin +{ + /// + /// Creates an observable that will call + /// when the current sequence is terminated with an error. + /// + /// + /// This should be equivalent to obs.Catch(Observable.Empty<T>), + /// but I had problems (NullReferenceExceptions) with that code in my tests and so chose to + /// write this extension. + /// + /// The type of the items in the sequence. + /// The source sequence. + /// The wrapped source sequence. + public static IObservable CompleteOnError(this IObservable obs) + { + return new CompleteOnErrorDecorator(obs); + } + + public class CompleteOnErrorDecorator : IObservable + { + private readonly IObservable core; + + public CompleteOnErrorDecorator(IObservable core) + { + this.core = core; + } + + public IDisposable Subscribe(IObserver observer) + { + return this.core.Subscribe( + onNext: observer.OnNext, + onCompleted: observer.OnCompleted, + onError: ex => observer.OnCompleted()); + } + } +} diff --git a/czishrink/netczicompress/Models/PInvokeFileProcessor.cs b/czishrink/netczicompress/Models/PInvokeFileProcessor.cs new file mode 100644 index 0000000..8a71f1c --- /dev/null +++ b/czishrink/netczicompress/Models/PInvokeFileProcessor.cs @@ -0,0 +1,222 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Buffers; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; + +/// +/// An that uses the native libczicompressc C API to do the actual work. +/// +public sealed partial class PInvokeFileProcessor : IFileProcessor +{ + private IntPtr nativeFileProcessor; + + /// + /// Initializes a new instance of the class. + /// + /// The compression mode to use, not all modes may be supported. + /// The processing mode to use. + /// Thrown when is . + /// Thrown when the native file processor cannot be created. + public PInvokeFileProcessor(CompressionMode mode, ProcessingOptions options) + { + if (mode == CompressionMode.NoOp) + { + throw new ArgumentOutOfRangeException(nameof(mode)); + } + + NativeMethods.Command cmd = mode switch + { + CompressionMode.Decompress => NativeMethods.Command.Decompress, + _ => NativeMethods.Command.Compress, + }; + + NativeMethods.CompressionStrategy strategy = mode switch + { + CompressionMode.CompressAll => NativeMethods.CompressionStrategy.All, + CompressionMode.CompressUncompressedAndZstd => + NativeMethods.CompressionStrategy.UncompressedAndZStdCompressed, + _ => NativeMethods.CompressionStrategy.OnlyUncompressed, + }; + + this.nativeFileProcessor = NativeMethods.CreateFileProcessor(cmd, strategy, options.CompressionLevel.Value); + + if (this.nativeFileProcessor == IntPtr.Zero) + { + throw new ApplicationException("Failed to create native file processor."); + } + } + + public bool NeedsExistingOutputDirectory => true; + + private bool IsDisposed + { + get => this.nativeFileProcessor == IntPtr.Zero; + } + + public static IFileProcessor Create(CompressionMode mode, ProcessingOptions options) + { + return new PInvokeFileProcessor(mode, options); + } + + public static string GetLibFullName() => NativeMethods.GetLibFullName(); + + public void ProcessFile(string inputPath, string outputPath, ReportProgress progressReport, CancellationToken token) + { + this.CheckDisposed(); + + var errorMessageBuffer = ArrayPool.Shared.Rent(1024); + var errorMessageLength = errorMessageBuffer.Length; + + bool ReportProgressCheckCancelImpl(int progress) + { + progressReport(progress); + + return !token.IsCancellationRequested; + } + + var result = NativeMethods.ProcessFile( + this.nativeFileProcessor, + inputPath, + outputPath, + errorMessageBuffer, + ref errorMessageLength, + ReportProgressCheckCancelImpl); + + GC.KeepAlive(this.nativeFileProcessor); + GC.KeepAlive(errorMessageBuffer); + GC.KeepAlive(errorMessageLength); + GC.KeepAlive(progressReport); + + if (result != 0) + { + var message = Encoding.UTF8.GetString(errorMessageBuffer, 0, errorMessageLength); + throw new IOException(message); + } + + // Make sure that we don't report cancellation as success, even if the native lib returns 0 when canceled. + token.ThrowIfCancellationRequested(); + } + + public void Dispose() + { + if (!this.IsDisposed) + { + NativeMethods.DestroyFileProcessor(this.nativeFileProcessor); + } + + this.nativeFileProcessor = IntPtr.Zero; + } + + private void CheckDisposed() + { + if (this.IsDisposed) + { + throw new ObjectDisposedException(this.ToString()); + } + } + + internal static partial class NativeMethods + { + private const string LibName = "libczicompressc"; + private const StringMarshalling LibStringEncoding = StringMarshalling.Utf8; + + static NativeMethods() + { + GetLibVersion(out int major, out int minor, out int patch); + + var actual = (major, minor); + (int Major, int Minor) expected = (0, 5); + + bool isCompatible = major == 0 + ? actual == expected + : major == expected.Major && minor >= expected.Minor; + + if (!isCompatible) + { + throw new InvalidOperationException($"Expecting {LibName} {nameof(GetLibVersion)} to be compatible with {expected} but found {actual}."); + } + +#if !DEBUG + var fullName = GetLibFullName(); + if (fullName.Contains("DEBUG")) + { + throw new InvalidOperationException($"You must not use {fullName} in a Release build of {nameof(netczicompress)}. Use a Release build of the library."); + } +#endif + } + + /// + /// Delegate that is invoked by processing function to provide updates. + /// + /// The progress in percent. + /// True if operation should continue; false if canceled. + public delegate bool ReportProgressCheckCancel(int progressPercent); + + public enum Command + { + Compress = 1, + Decompress = 2, + } + + public enum CompressionStrategy + { + All = 1, + OnlyUncompressed = 2, + UncompressedAndZStdCompressed = 3, + } + + public static string GetLibFullName(int suggestedBufferLength = 64) + { + checked + { + var buffer = ArrayPool.Shared.Rent(suggestedBufferLength); + ulong bufferLength = (ulong)buffer.Length; + if (NativeMethods.GetLibVersionString(buffer, ref bufferLength)) + { + var version = Encoding.UTF8.GetString(buffer, 0, buffer.Count(b => b != 0)); + return $"{LibName} {version}"; + } + else if (bufferLength > (ulong)suggestedBufferLength) + { + // This means that the buffer was too small + return GetLibFullName((int)bufferLength); + } + else + { + throw new Exception($"Failed to determine version of {LibName}"); + } + } + } + + [LibraryImport(LibName, StringMarshalling = LibStringEncoding)] + [return: MarshalAs(UnmanagedType.U1)] + public static partial bool GetLibVersionString(byte[] buffer, ref ulong bufferLength); + + [LibraryImport(LibName, StringMarshalling = LibStringEncoding)] + public static partial void GetLibVersion(out int major, out int minor, out int patch); + + [LibraryImport(LibName, StringMarshalling = LibStringEncoding)] + public static partial IntPtr CreateFileProcessor(Command command, CompressionStrategy strategy, int compressionLevel); + + [LibraryImport(LibName, StringMarshalling = LibStringEncoding)] + public static partial void DestroyFileProcessor(IntPtr file_processor); + + [LibraryImport(LibName, StringMarshalling = LibStringEncoding)] + public static partial int ProcessFile( + IntPtr file_processor, + string input_path, + string output_path, + byte[] error_message, + ref int error_message_length, + ReportProgressCheckCancel reportProgress); + } +} diff --git a/czishrink/netczicompress/Models/ProcessingOptions.cs b/czishrink/netczicompress/Models/ProcessingOptions.cs new file mode 100644 index 0000000..3601073 --- /dev/null +++ b/czishrink/netczicompress/Models/ProcessingOptions.cs @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +/// +/// Processing options to apply to an operation. +/// +/// Level of compression to use, if applicable. +/// A value indicating whether failed files should be copied to the destination folder. +public record ProcessingOptions(CompressionLevel CompressionLevel, bool CopyFailedFiles = false); diff --git a/czishrink/netczicompress/Models/ProgramNameAndVersion.cs b/czishrink/netczicompress/Models/ProgramNameAndVersion.cs new file mode 100644 index 0000000..3ec8f8e --- /dev/null +++ b/czishrink/netczicompress/Models/ProgramNameAndVersion.cs @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Linq; +using System.Reflection; + +using netczicompress.ViewModels; + +/// +/// Program name and version info. +/// +public record class ProgramNameAndVersion : IProgramNameAndVersion +{ + public ProgramNameAndVersion() + { + var assembly = typeof(AboutViewModel).Assembly; + this.Version = assembly.GetCustomAttributes().Select(att => att.InformationalVersion).FirstOrDefault() ?? + assembly.GetName().Version?.ToString() ?? + throw new ApplicationException("Failed to determine assembly version"); + this.Name = "CZI Shrink"; + } + + public string Name { get; } + + public string Version { get; } + + public override string ToString() + { + return $"{this.Name} {this.Version}"; + } +} diff --git a/czishrink/netczicompress/Models/ReportProgress.cs b/czishrink/netczicompress/Models/ReportProgress.cs new file mode 100644 index 0000000..dcff645 --- /dev/null +++ b/czishrink/netczicompress/Models/ReportProgress.cs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +/// +/// Delegate that is invoked by processing function to provide updates. +/// +/// The percentage of completion in the range 0 .. 100. +public delegate void ReportProgress(int percentComplete); diff --git a/czishrink/netczicompress/Models/StatisticsRunObserver.cs b/czishrink/netczicompress/Models/StatisticsRunObserver.cs new file mode 100644 index 0000000..76441ce --- /dev/null +++ b/czishrink/netczicompress/Models/StatisticsRunObserver.cs @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Reactive.Concurrency; +using System.Reactive.Linq; + +/// +/// An that forwards to an observer of these. +/// +public class StatisticsRunObserver : IFolderCompressorRunObserver +{ + private readonly IObserver statisticsObserver; + private readonly TimeSpan samplingInterval; + private readonly IScheduler scheduler; + + public StatisticsRunObserver( + IObserver statisticsObserver, + TimeSpan samplingInterval, + IScheduler scheduler) + { + this.statisticsObserver = statisticsObserver; + this.samplingInterval = samplingInterval; + this.scheduler = scheduler; + } + + public void ObserveRun(FolderCompressorParameters runParameters, IObservable runMessages) + { + var start = this.scheduler.Now; + + var emptyStats = AggregateStatistics.Empty; + this.statisticsObserver.OnNext(emptyStats); + var cumulativeStatistics = runMessages + .CompleteOnError() + .Scan( + emptyStats, + (stats, msg) => stats.AddData(msg, this.scheduler.Now - start)); + + // Subscriptions will expire upon completion, no need for explicit disposal. + _ = cumulativeStatistics + .Sample(this.samplingInterval) + .ObserveOn(this.scheduler) + .Subscribe(this.statisticsObserver); + } +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/TemporaryFile.cs b/czishrink/netczicompress/Models/TemporaryFile.cs new file mode 100644 index 0000000..d4b8eea --- /dev/null +++ b/czishrink/netczicompress/Models/TemporaryFile.cs @@ -0,0 +1,148 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System.IO.Abstractions; + +/// +/// Creates and handles temporary files according to the following logic: +/// +/// The target filename "outfile_name" is given. +/// The basic temporary filename is "outfile_name" + "~". +/// If the basic temporary filename can be used (file does not yet exist or can be deleted) +/// then it will be used. +/// If it cannot be used, we (now recursively) try with another file name "outfile_name" + "~" + i, +/// with i being an index starting at 1. +/// There is a maximum number of tries, so the index is bounded by "maximum number of tries - 1". +/// +/// +public class TemporaryFile +{ + /// + /// Initializes a new instance of the class. + /// + /// The is set and (not the file on the hard disk) + /// immediately created, if possible. + /// By this is set accordingly. + /// + /// The basic output file name. + /// The maximum number or tries. + public TemporaryFile( + IFileInfo outfile, + int maxNumberOfTriesToCreate = 100) + { + this.OutFile = outfile; + this.MaxNumberOfTriesToCreate = maxNumberOfTriesToCreate; + this.Info = this.TryCreate(); + } + + /// + /// Gets a value indicating whether the temporary file creation failed. + /// + public bool TemporaryFileCreationFailed { get; private set; } + + /// + /// Gets the created temporary file. + /// + public IFileInfo Info { get; } + + /// + /// Gets the created final output file. + /// + protected IFileInfo OutFile { get; } + + /// + /// Gets the maximum number of tries for the temporary file creation. + /// + private int MaxNumberOfTriesToCreate { get; } + + /// + /// If the temporary file exists, moves the temporary file to the final output file. + /// Mind that the attribute of the temporary file will + /// be adapted not the flag. + /// + public void MoveToOutFileIfExists() + { + this.Info.Refresh(); // mind that the file might have not existed when the variable was created. + if (!this.Info.Exists) + { + return; + } + + this.Info.MoveTo(this.OutFile.FullName); + this.Info.Refresh(); // mind that the move changes the full name, not the `Exits` flag. + this.OutFile.Refresh(); + } + + /// + /// Deletes the basic output file and the temporary file. + /// + public void DeleteAllOutFiles() + { + _ = this.TryDelete(this.OutFile); + _ = this.TryDelete(this.Info); + } + + /// + /// Tries to create the temporary file. + /// + /// Create the temporary filename. + /// If it can be used, return it. + /// If not, append an increasing index until the file can be deleted or used. + /// If the maximum number of tries is reached, set "failed" and return the latest try. + /// + /// + /// The temporary file info. + private IFileInfo TryCreate() + { + var outFileName = this.OutFile.FullName; + var tempOutFileName = this.GetBasicTempFileName(outFileName); + IFileInfo temporaryFile = this.OutFile.FileSystem.FileInfo.New(tempOutFileName); + var postfixIndex = 1; + while (temporaryFile.Exists && !this.TryDelete(temporaryFile)) + { + if (postfixIndex + 1 > this.MaxNumberOfTriesToCreate) + { + this.TemporaryFileCreationFailed = true; + return temporaryFile; + } + + temporaryFile = this.CreateWithIndex(this.OutFile, tempOutFileName, postfixIndex); + ++postfixIndex; + } + + this.TemporaryFileCreationFailed = false; + return temporaryFile; + } + + private bool TryDelete(IFileInfo file) + { + try + { + file.Refresh(); + if (file.Exists) + { + file.Delete(); + file.Refresh(); + } + } + catch (Exception) + { + return false; + } + + return true; + } + + private string GetBasicTempFileName(string outFileName) + { + return outFileName + "~"; + } + + private IFileInfo CreateWithIndex(IFileInfo outFile, string tempOutFileName, int index) + { + return outFile.FileSystem.FileInfo.New($"{tempOutFileName}{index}"); + } +} diff --git a/czishrink/netczicompress/Models/ThreadCount.cs b/czishrink/netczicompress/Models/ThreadCount.cs new file mode 100644 index 0000000..1ac5d98 --- /dev/null +++ b/czishrink/netczicompress/Models/ThreadCount.cs @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +public partial record ThreadCount +{ + private readonly int internalValue = Maximum; + + public static readonly ThreadCount Default; + + static ThreadCount() + { + DefaultValue = Maximum; + Default = new ThreadCount { Value = DefaultValue }; + } + + public static int Maximum { get; } = GetMaxProcessorCount(); + + public static int Minimum { get; } = 1; + + /// + /// Gets default thread count if not specified. + /// + public static int DefaultValue { get; } = Maximum; + + public int Value + { + get => this.internalValue; + init => + this.internalValue = value > Maximum || value < Minimum + ? throw new ArgumentOutOfRangeException( + paramName: nameof(value), + $"{nameof(value)} must be between {Minimum} and {Maximum}, not {value}") + : value; + } + + // Note we leave one processor free for the UI thread. + private static int GetMaxProcessorCount() + { + return Environment.ProcessorCount > 4 + ? Environment.ProcessorCount - 1 + : Environment.ProcessorCount; + } +} \ No newline at end of file diff --git a/czishrink/netczicompress/Models/TraceLoggerFactory.cs b/czishrink/netczicompress/Models/TraceLoggerFactory.cs new file mode 100644 index 0000000..9f44d5a --- /dev/null +++ b/czishrink/netczicompress/Models/TraceLoggerFactory.cs @@ -0,0 +1,118 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Diagnostics; + +using Microsoft.Extensions.Logging; + +/// +/// A logger provider and factory that uses to write log messages. +/// +/// +/// Logs levels Information, Warning, Error, and Critical. +/// +/// is not supported. +/// +public sealed class TraceLoggerFactory : ILoggerFactory, ILoggerProvider +{ + private readonly bool useLogLevelsAsTraceLevels; + + public TraceLoggerFactory(bool useLogLevelsAsTraceLevels = false) + { + this.useLogLevelsAsTraceLevels = useLogLevelsAsTraceLevels; + } + + public ILogger CreateLogger(string categoryName) + { + return new TraceLogger(categoryName, this.useLogLevelsAsTraceLevels); + } + + void ILoggerFactory.AddProvider(ILoggerProvider provider) + { + throw new NotSupportedException(); + } + + void IDisposable.Dispose() + { + Trace.Flush(); + } + + private sealed class TraceLogger : ILogger + { + private readonly string categoryName; + private readonly bool useLogLevelsAsTraceLevels; + + public TraceLogger(string categoryName, bool useLogLevelsAsTraceLevels) + { + this.categoryName = categoryName; + this.useLogLevelsAsTraceLevels = useLogLevelsAsTraceLevels; + } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + { + if (this.IsEnabled(logLevel)) + { + var msg = $"{DateTimeOffset.Now:O}|{this.categoryName}|{ToString(logLevel)}|{eventId}|{formatter(state, exception)}"; + if (this.useLogLevelsAsTraceLevels) + { + switch (logLevel) + { + case LogLevel.Error: + case LogLevel.Critical: + Trace.TraceError(msg); + break; + case LogLevel.Information: + Trace.TraceInformation(msg); + break; + case LogLevel.Warning: + Trace.TraceWarning(msg); + break; + default: + break; + } + } + else + { + Trace.WriteLine(msg); + } + } + } + + public bool IsEnabled(LogLevel logLevel) + { + return logLevel switch + { + LogLevel.Trace => false, + LogLevel.Debug => false, + LogLevel.Information => true, + LogLevel.Warning => true, + LogLevel.Error => true, + LogLevel.Critical => true, + LogLevel.None => false, + _ => false, + }; + } + + public IDisposable? BeginScope(TState state) + where TState : notnull + { + return null; + } + + private static string ToString(LogLevel logLevel) + { + return logLevel switch + { + LogLevel.Information => "INFO", + LogLevel.Warning => "WARN", + LogLevel.Error => "ERROR", + LogLevel.Critical => "FATAL", + _ => string.Empty, + }; + } + } +} diff --git a/czishrink/netczicompress/Models/VariousExtensions.cs b/czishrink/netczicompress/Models/VariousExtensions.cs new file mode 100644 index 0000000..31a38ed --- /dev/null +++ b/czishrink/netczicompress/Models/VariousExtensions.cs @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Models; + +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Abstractions; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; + +public static class VariousExtensions +{ + public static async IAsyncEnumerable EnumerateFilesAsync( + this IDirectoryInfo folder, + string searchPattern, + EnumerationOptions opts, + [EnumeratorCancellation] CancellationToken token = default) + { + var files = await Task.Run(() => folder.EnumerateFiles(searchPattern, opts)).ConfigureAwait(false); + using var e = files.GetEnumerator(); + while (await Task.Run(() => e.MoveNext()).ConfigureAwait(false)) + { + if (token.IsCancellationRequested) + { + yield break; + } + + yield return e.Current; + } + } + + public static AggregateStatistics AddData(this AggregateStatistics aggregateStatistics, CompressorMessage.FileFinished msg, TimeSpan elapsed) + { + if (msg.ErrorMessage == null) + { + return aggregateStatistics with + { + FilesWithNoErrors = aggregateStatistics.FilesWithNoErrors + 1, + InputBytes = aggregateStatistics.InputBytes + msg.SizeInput, + OutputBytes = aggregateStatistics.OutputBytes + msg.SizeOutput, + Duration = elapsed, + }; + } + else + { + return aggregateStatistics with + { + FilesWithErrors = aggregateStatistics.FilesWithErrors + 1, + Duration = elapsed, + }; + } + } +} diff --git a/czishrink/netczicompress/Styles/Border.axaml b/czishrink/netczicompress/Styles/Border.axaml new file mode 100644 index 0000000..20ebe7d --- /dev/null +++ b/czishrink/netczicompress/Styles/Border.axaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Styles/Button_Unused.axaml b/czishrink/netczicompress/Styles/Button_Unused.axaml new file mode 100644 index 0000000..0e07304 --- /dev/null +++ b/czishrink/netczicompress/Styles/Button_Unused.axaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Styles/ComboBox.axaml b/czishrink/netczicompress/Styles/ComboBox.axaml new file mode 100644 index 0000000..8d64252 --- /dev/null +++ b/czishrink/netczicompress/Styles/ComboBox.axaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Styles/DataGrid.axaml b/czishrink/netczicompress/Styles/DataGrid.axaml new file mode 100644 index 0000000..ef3dc0f --- /dev/null +++ b/czishrink/netczicompress/Styles/DataGrid.axaml @@ -0,0 +1,50 @@ + + + + + + + + + 18 + 12 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Styles/GridSplitter.axaml b/czishrink/netczicompress/Styles/GridSplitter.axaml new file mode 100644 index 0000000..629ed83 --- /dev/null +++ b/czishrink/netczicompress/Styles/GridSplitter.axaml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/czishrink/netczicompress/Styles/ProgressBar.axaml b/czishrink/netczicompress/Styles/ProgressBar.axaml new file mode 100644 index 0000000..3cb514b --- /dev/null +++ b/czishrink/netczicompress/Styles/ProgressBar.axaml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/czishrink/netczicompress/Styles/TextBox.axaml b/czishrink/netczicompress/Styles/TextBox.axaml new file mode 100644 index 0000000..d3647ea --- /dev/null +++ b/czishrink/netczicompress/Styles/TextBox.axaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Styles/Themes/ControlThemeButton.axaml b/czishrink/netczicompress/Styles/Themes/ControlThemeButton.axaml new file mode 100644 index 0000000..71f18dd --- /dev/null +++ b/czishrink/netczicompress/Styles/Themes/ControlThemeButton.axaml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + + + + + + diff --git a/czishrink/netczicompress/Views/AboutView.axaml.cs b/czishrink/netczicompress/Views/AboutView.axaml.cs new file mode 100644 index 0000000..5bcd1e2 --- /dev/null +++ b/czishrink/netczicompress/Views/AboutView.axaml.cs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +/// +/// An about box and commands to show and close it. +/// +public partial class AboutView : UserControl +{ + public AboutView() => this.InitializeComponent(); +} diff --git a/czishrink/netczicompress/Views/AdvancedOptionsView.axaml b/czishrink/netczicompress/Views/AdvancedOptionsView.axaml new file mode 100644 index 0000000..ce39dba --- /dev/null +++ b/czishrink/netczicompress/Views/AdvancedOptionsView.axaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/czishrink/netczicompress/Views/AdvancedOptionsView.axaml.cs b/czishrink/netczicompress/Views/AdvancedOptionsView.axaml.cs new file mode 100644 index 0000000..b72e589 --- /dev/null +++ b/czishrink/netczicompress/Views/AdvancedOptionsView.axaml.cs @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +public partial class AdvancedOptionsView : UserControl +{ + public AdvancedOptionsView() => this.InitializeComponent(); +} \ No newline at end of file diff --git a/czishrink/netczicompress/Views/AggregateIndicationView.axaml b/czishrink/netczicompress/Views/AggregateIndicationView.axaml new file mode 100644 index 0000000..1bf3abd --- /dev/null +++ b/czishrink/netczicompress/Views/AggregateIndicationView.axaml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/AggregateIndicationView.axaml.cs b/czishrink/netczicompress/Views/AggregateIndicationView.axaml.cs new file mode 100644 index 0000000..87ba22e --- /dev/null +++ b/czishrink/netczicompress/Views/AggregateIndicationView.axaml.cs @@ -0,0 +1,11 @@ +namespace netczicompress.Views; + +using Avalonia.Controls; + +/// +/// A control that visualizes with an icon and a label. +/// +public partial class AggregateIndicationView : UserControl +{ + public AggregateIndicationView() => this.InitializeComponent(); +} diff --git a/czishrink/netczicompress/Views/AggregateStatisticsView.axaml b/czishrink/netczicompress/Views/AggregateStatisticsView.axaml new file mode 100644 index 0000000..f94323c --- /dev/null +++ b/czishrink/netczicompress/Views/AggregateStatisticsView.axaml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/AggregateStatisticsView.axaml.cs b/czishrink/netczicompress/Views/AggregateStatisticsView.axaml.cs new file mode 100644 index 0000000..342f6f6 --- /dev/null +++ b/czishrink/netczicompress/Views/AggregateStatisticsView.axaml.cs @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; +using Avalonia.Controls.Notifications; + +using netczicompress.ViewModels; + +/// +/// A control that visualizes . +/// +public partial class AggregateStatisticsView : UserControl +{ + public AggregateStatisticsView() => this.InitializeComponent(); + + protected override void OnDataContextChanged(EventArgs e) + { + base.OnDataContextChanged(e); + + // Subscribe to the new ViewModels event + if (this.DataContext is IAggregateStatisticsViewModel newViewModel) + { + newViewModel.BadgeCopiedToClipboardRaised += this.OnNotificationBadgeCopiedToClipboardRaised; + } + } + + private void OnNotificationBadgeCopiedToClipboardRaised() + { + var notification = + new Notification( + title: "Badge copied to clipboard", + message: null, + type: NotificationType.Success, + expiration: TimeSpan.FromSeconds(1.5)); + this.RaiseEvent( + new NotificationEventArgs(notification) + { + RoutedEvent = MainWindow.NotificationRequestedEvent, + Source = this, + }); + } +} diff --git a/czishrink/netczicompress/Views/CompressionResultBadge.axaml b/czishrink/netczicompress/Views/CompressionResultBadge.axaml new file mode 100644 index 0000000..95b0b0e --- /dev/null +++ b/czishrink/netczicompress/Views/CompressionResultBadge.axaml @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/czishrink/netczicompress/Views/CompressionResultBadge.axaml.cs b/czishrink/netczicompress/Views/CompressionResultBadge.axaml.cs new file mode 100644 index 0000000..b04fe78 --- /dev/null +++ b/czishrink/netczicompress/Views/CompressionResultBadge.axaml.cs @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +public partial class CompressionResultBadge : Panel +{ + public CompressionResultBadge() => this.InitializeComponent(); +} diff --git a/czishrink/netczicompress/Views/CurrentTasksView.axaml b/czishrink/netczicompress/Views/CurrentTasksView.axaml new file mode 100644 index 0000000..858f058 --- /dev/null +++ b/czishrink/netczicompress/Views/CurrentTasksView.axaml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/CurrentTasksView.axaml.cs b/czishrink/netczicompress/Views/CurrentTasksView.axaml.cs new file mode 100644 index 0000000..1d4c6c1 --- /dev/null +++ b/czishrink/netczicompress/Views/CurrentTasksView.axaml.cs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +/// +/// A control that visualizes currently running tasks. +/// +public partial class CurrentTasksView : UserControl +{ + public CurrentTasksView() => this.InitializeComponent(); +} diff --git a/czishrink/netczicompress/Views/ErrorListView.axaml b/czishrink/netczicompress/Views/ErrorListView.axaml new file mode 100644 index 0000000..007659a --- /dev/null +++ b/czishrink/netczicompress/Views/ErrorListView.axaml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/ErrorListView.axaml.cs b/czishrink/netczicompress/Views/ErrorListView.axaml.cs new file mode 100644 index 0000000..56b936c --- /dev/null +++ b/czishrink/netczicompress/Views/ErrorListView.axaml.cs @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; +using Avalonia.Controls.Notifications; +using Avalonia.Input.Platform; +using Avalonia.Interactivity; + +using netczicompress.ViewModels; + +/// +/// A control that visualizes a list of errors. +/// +public partial class ErrorListView : UserControl +{ + public ErrorListView() => this.InitializeComponent(); + + private void ErrorListDataGrid_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) + { + if (sender is DataGrid dataGrid && e.AddedItems.Count > 0) + { + dataGrid.ScrollIntoView(e.AddedItems[0], null); + } + + // SelectedItems is not bindable. So for simplicity's sake, we set IsEnabled in this event handler. + bool isExactlyOneFileSelected = this.dataGrid.SelectedItems.Count == 1; + this.showSelectedFileMenuItem.IsEnabled = isExactlyOneFileSelected; + this.openSelectedFileMenuItem.IsEnabled = isExactlyOneFileSelected; + } + + private async void CopySelectedFilePaths(object? sender, RoutedEventArgs e) + { + var clipboard = TopLevel.GetTopLevel(this)?.Clipboard; + if (clipboard != null) + { + await this.CopySelectedFilePaths(clipboard); + this.NotifySelectedFilePathsCopied(); + } + } + + private async Task CopySelectedFilePaths(IClipboard clipboard) + { + var paths = this.dataGrid.SelectedItems.OfType().Select(x => x.File); + var text = string.Join(Environment.NewLine, paths); + await clipboard.SetTextAsync(text); + } + + private void NotifySelectedFilePathsCopied() + { + var notification = + new Notification( + title: "Path copied to clipboard", + message: null, + type: NotificationType.Success, + expiration: TimeSpan.FromSeconds(1.5)); + this.RaiseEvent( + new NotificationEventArgs(notification) + { + RoutedEvent = MainWindow.NotificationRequestedEvent, + Source = this, + }); + } +} diff --git a/czishrink/netczicompress/Views/FolderInputOutputView.axaml b/czishrink/netczicompress/Views/FolderInputOutputView.axaml new file mode 100644 index 0000000..0a05d7b --- /dev/null +++ b/czishrink/netczicompress/Views/FolderInputOutputView.axaml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + diff --git a/czishrink/netczicompress/Views/FolderInputOutputView.axaml.cs b/czishrink/netczicompress/Views/FolderInputOutputView.axaml.cs new file mode 100644 index 0000000..a160655 --- /dev/null +++ b/czishrink/netczicompress/Views/FolderInputOutputView.axaml.cs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +/// +/// Folder input/output view. +/// +public partial class FolderInputOutputView : UserControl +{ + public FolderInputOutputView() => this.InitializeComponent(); +} \ No newline at end of file diff --git a/czishrink/netczicompress/Views/FolderPicker.axaml b/czishrink/netczicompress/Views/FolderPicker.axaml new file mode 100644 index 0000000..e7e4a3b --- /dev/null +++ b/czishrink/netczicompress/Views/FolderPicker.axaml @@ -0,0 +1,27 @@ + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/FolderPicker.axaml.cs b/czishrink/netczicompress/Views/FolderPicker.axaml.cs new file mode 100644 index 0000000..0c21d6f --- /dev/null +++ b/czishrink/netczicompress/Views/FolderPicker.axaml.cs @@ -0,0 +1,85 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using System.Diagnostics; + +using Avalonia; +using Avalonia.Controls; +using Avalonia.Data; +using Avalonia.Interactivity; +using Avalonia.Platform.Storage; + +/// +/// A control that allows the user to pick a folder. +/// +public partial class FolderPicker : UserControl +{ + public static readonly StyledProperty FolderProperty = + AvaloniaProperty.Register(nameof(Folder), defaultBindingMode: BindingMode.TwoWay); + + public static readonly StyledProperty TitleProperty = + AvaloniaProperty.Register(nameof(Title)); + + public FolderPicker() => this.InitializeComponent(); + + public string Folder + { + get => this.GetValue(FolderProperty); + set => this.SetValue(FolderProperty, value); + } + + public string Title + { + get => this.GetValue(TitleProperty); + set => this.SetValue(TitleProperty, value); + } + + private async void OnButtonClicked(object source, RoutedEventArgs args) + { + try + { + await this.OpenFolderPicker(); + } + catch (Exception ex) + { + Trace.TraceError(ex.ToString()); + } + } + + private async Task OpenFolderPicker() + { + // Get top level from the current control. Alternatively, you can use Window reference instead. + var topLevel = TopLevel.GetTopLevel(this); + + if (topLevel == null) + { + return; + } + + IStorageFolder? startLocation; + try + { + startLocation = await topLevel.StorageProvider.TryGetFolderFromPathAsync(this.Folder); + } + catch + { + startLocation = null; + } + + // Start async operation to open the dialog. + var folders = await topLevel.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions + { + Title = this.Title, + AllowMultiple = false, + SuggestedStartLocation = startLocation, + }); + + if (folders.Count >= 1) + { + this.Folder = folders[0].TryGetLocalPath() ?? folders[0].Path.ToString(); + } + } +} diff --git a/czishrink/netczicompress/Views/MainView.axaml b/czishrink/netczicompress/Views/MainView.axaml new file mode 100644 index 0000000..5c6e3b0 --- /dev/null +++ b/czishrink/netczicompress/Views/MainView.axaml @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/MainView.axaml.cs b/czishrink/netczicompress/Views/MainView.axaml.cs new file mode 100644 index 0000000..2738c9d --- /dev/null +++ b/czishrink/netczicompress/Views/MainView.axaml.cs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +/// +/// The main view of the application. +/// +public partial class MainView : UserControl +{ + public MainView() => this.InitializeComponent(); +} diff --git a/czishrink/netczicompress/Views/MainWindow.axaml b/czishrink/netczicompress/Views/MainWindow.axaml new file mode 100644 index 0000000..28f5de8 --- /dev/null +++ b/czishrink/netczicompress/Views/MainWindow.axaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/MainWindow.axaml.cs b/czishrink/netczicompress/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..6c6e74c --- /dev/null +++ b/czishrink/netczicompress/Views/MainWindow.axaml.cs @@ -0,0 +1,147 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using System.Reactive; +using System.Reactive.Linq; +using System.Windows.Input; + +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Notifications; +using Avalonia.Interactivity; + +using MsBox.Avalonia; +using MsBox.Avalonia.Dto; +using MsBox.Avalonia.Models; + +using AsyncCommand = ReactiveUI.ReactiveCommand; + +/// +/// The main window of the application. +/// +public partial class MainWindow : Window +{ + public static readonly StyledProperty StopRunningTasksCommandProperty = + AvaloniaProperty.Register(nameof(StopRunningTasksCommand)); + + /// + /// A routed event that requests a notification to be shown. + /// + public static readonly RoutedEvent NotificationRequestedEvent = + RoutedEvent.Register( + nameof(NotificationRequested), + RoutingStrategies.Bubble, + typeof(MainWindow)); + + private INotificationManager? manager; + + public MainWindow() + { + this.InitializeComponent(); + + this.Closing += this.OnClosing; + this.NotificationRequested += this.OnNotificationRequested; + } + + /// + /// Occurs when a notification is requested on this control or one of its children. + /// + public event EventHandler NotificationRequested + { + add => this.AddHandler(NotificationRequestedEvent, value); + remove => this.RemoveHandler(NotificationRequestedEvent, value); + } + + public AsyncCommand? StopRunningTasksCommand + { + get => this.GetValue(StopRunningTasksCommandProperty); + set => this.SetValue(StopRunningTasksCommandProperty, value); + } + + private INotificationManager NotificationManager + { + get + { + if (this.manager == null) + { + var newInstance = new WindowNotificationManager(this) + { + Position = NotificationPosition.BottomRight, + }; + + // If we do not call ApplyTemplate + // the first notification will not be shown. + newInstance.ApplyTemplate(); + + this.manager = newInstance; + } + + return this.manager; + } + } + + private async void OnClosing(object? sender, WindowClosingEventArgs args) + { + if (!this.HasRunningTasks()) + { + // OK to close immediately + return; + } + + // We cannot close right now => cancel this call to Close() + args.Cancel = true; + + if (await this.UserConfirmsStopRunningTasksAndClose()) + { + this.IsEnabled = false; + await this.StopRunningTasksAsync(); + this.Close(); + } + } + + private async Task StopRunningTasksAsync() + { + if (this.HasRunningTasks()) + { + await this.StopRunningTasksCommand!.Execute(Unit.Default); + } + } + + private bool HasRunningTasks() + { + ICommand? synchronousCommand = this.StopRunningTasksCommand; + return synchronousCommand?.CanExecute(null) ?? false; + } + + private async Task UserConfirmsStopRunningTasksAndClose() + { + var contentMessage = $"Do you want to stop the running task and close {this.Title}?"; + + var box = MessageBoxManager.GetMessageBoxCustom( + new MessageBoxCustomParams + { + Icon = MsBox.Avalonia.Enums.Icon.Stop, + ContentTitle = "Folder Operation in Progress", + ContentHeader = "Stop the current operation?", + ContentMessage = contentMessage, + WindowStartupLocation = WindowStartupLocation.CenterOwner, + ButtonDefinitions = new[] + { + new ButtonDefinition { Name = "Yes", IsDefault = false }, + new ButtonDefinition { Name = "No", IsDefault = true, IsCancel = true }, + }, + WindowIcon = this.Icon, + }); + + var result = await box.ShowWindowDialogAsync(this); + return result == "Yes"; + } + + private void OnNotificationRequested(object? sender, NotificationEventArgs e) + { + this.NotificationManager.Show(e.Notification); + } +} diff --git a/czishrink/netczicompress/Views/NotificationEventArgs.cs b/czishrink/netczicompress/Views/NotificationEventArgs.cs new file mode 100644 index 0000000..61d19d0 --- /dev/null +++ b/czishrink/netczicompress/Views/NotificationEventArgs.cs @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls.Notifications; +using Avalonia.Interactivity; + +/// +/// Routed event arguments with an payload. +/// +/// +/// +public class NotificationEventArgs : RoutedEventArgs +{ + public NotificationEventArgs(INotification notification) + { + this.Notification = notification; + } + + public INotification Notification { get; } +} \ No newline at end of file diff --git a/czishrink/netczicompress/Views/SettingsView.axaml b/czishrink/netczicompress/Views/SettingsView.axaml new file mode 100644 index 0000000..a556e9a --- /dev/null +++ b/czishrink/netczicompress/Views/SettingsView.axaml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/SettingsView.axaml.cs b/czishrink/netczicompress/Views/SettingsView.axaml.cs new file mode 100644 index 0000000..7ba5ea2 --- /dev/null +++ b/czishrink/netczicompress/Views/SettingsView.axaml.cs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +/// +/// View for operation settings. +/// +public partial class SettingsView : UserControl +{ + public SettingsView() => this.InitializeComponent(); +} \ No newline at end of file diff --git a/czishrink/netczicompress/Views/StartStopBarView.axaml b/czishrink/netczicompress/Views/StartStopBarView.axaml new file mode 100644 index 0000000..3ca926f --- /dev/null +++ b/czishrink/netczicompress/Views/StartStopBarView.axaml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file diff --git a/czishrink/netczicompress/Views/StartStopBarView.axaml.cs b/czishrink/netczicompress/Views/StartStopBarView.axaml.cs new file mode 100644 index 0000000..202bb0a --- /dev/null +++ b/czishrink/netczicompress/Views/StartStopBarView.axaml.cs @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompress.Views; + +using Avalonia.Controls; + +/// +/// Execution Buttons View. +/// +public partial class StartStopBarView : UserControl +{ + public StartStopBarView() => this.InitializeComponent(); +} \ No newline at end of file diff --git a/czishrink/netczicompress/netczicompress.csproj b/czishrink/netczicompress/netczicompress.csproj new file mode 100644 index 0000000..930dde8 --- /dev/null +++ b/czishrink/netczicompress/netczicompress.csproj @@ -0,0 +1,32 @@ + + + true + True + true + copyused + true + true + true + true + x64 + + + + + + + + + + + + + + + + + + + + + diff --git a/czishrink/netczicompressTests/AppComposerTests.cs b/czishrink/netczicompressTests/AppComposerTests.cs new file mode 100644 index 0000000..cae75d8 --- /dev/null +++ b/czishrink/netczicompressTests/AppComposerTests.cs @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests; + +using System.Diagnostics; +using System.Reactive.Disposables; +using System.Text.RegularExpressions; + +using netczicompress; +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +public partial class AppComposerTests +{ + [Fact] + public void ComposeMainViewModel_WhenCalledDoesNotThrow_AndLogsMessage() + { + var listenerMock = new Mock(); + var listener = listenerMock.Object; + using var cleanup = Disposable.Create(() => Trace.Listeners.Remove(listener)); + Trace.Listeners.Add(listener); + + // ACT + var actual = AppComposer.ComposeMainViewModel(new ProgramNameAndVersion()); + + // ASSERT + actual.Should().NotBeNull(); + var re = ExpectedLogMessagePattern(); + listenerMock.Verify(x => x.WriteLine(It.Is(msg => re.IsMatch(msg))), Times.Once); + + // check composition + actual.About.Should().BeOfType(); + actual.ErrorList.Should().BeOfType(); + actual.CurrentTasks.Should().BeOfType(); + + // check initial state + actual.InputDirectory.Should().BeNull(); + actual.OutputDirectory.Should().BeNull(); + actual.Recursive.Should().BeTrue(); + actual.SelectedMode.Value.Should().Be(CompressionMode.CompressUncompressed); + actual.OverallStatus.Should().BeEmpty(); + } + + [GeneratedRegex(@"^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+?[+-]\d\d:\d\d\|netczicompress.App\|INFO\|0\|Starting CZI Shrink \d+\.\d+\.\d+.*? using libczicompressc \d+\.\d+\.\d+.*")] + private static partial Regex ExpectedLogMessagePattern(); +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Customizations/CompressionLevelSpecimenBuilder.cs b/czishrink/netczicompressTests/Customizations/CompressionLevelSpecimenBuilder.cs new file mode 100644 index 0000000..440c3b7 --- /dev/null +++ b/czishrink/netczicompressTests/Customizations/CompressionLevelSpecimenBuilder.cs @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Customizations; + +using AutoFixture.Kernel; + +/// +/// CompressionLevel specimen builder that will create only valid CompressionLevels. +/// +/// +/// This builder depends on Min/Max values of CompressionLevel being public to avoid magic values. +/// +public class CompressionLevelSpecimenBuilder : ISpecimenBuilder +{ + public object Create(object request, ISpecimenContext context) + { + if (request is Type type && type == typeof(CompressionLevel)) + { + var value = new Random().Next(CompressionLevel.Minimum, CompressionLevel.Maximum + 1); + return new CompressionLevel { Value = value }; + } + + return new NoSpecimen(); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Customizations/CorrectValueObjectAutoDataAttribute.cs b/czishrink/netczicompressTests/Customizations/CorrectValueObjectAutoDataAttribute.cs new file mode 100644 index 0000000..8a943c6 --- /dev/null +++ b/czishrink/netczicompressTests/Customizations/CorrectValueObjectAutoDataAttribute.cs @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Customizations; + +public class CorrectValueObjectAutoDataAttribute : AutoDataAttribute +{ + public CorrectValueObjectAutoDataAttribute() + : base(() => + { + var fixture = new Fixture(); + fixture.Customizations.Add(new CompressionLevelSpecimenBuilder()); + fixture.Customizations.Add(new ThreadCountSpecimenBuilder()); + return fixture; + }) + { + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Customizations/ThreadCountSpecimenBuilder.cs b/czishrink/netczicompressTests/Customizations/ThreadCountSpecimenBuilder.cs new file mode 100644 index 0000000..334958c --- /dev/null +++ b/czishrink/netczicompressTests/Customizations/ThreadCountSpecimenBuilder.cs @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Customizations; + +using AutoFixture.Kernel; + +/// +/// specimen builder that will create only valid s. +/// +/// +/// This builder depends on Min/Max values of being public to avoid magic values. +/// +public class ThreadCountSpecimenBuilder : ISpecimenBuilder +{ + public object Create(object request, ISpecimenContext context) + { + if (request is Type type && type == typeof(ThreadCount)) + { + var value = new Random().Next(ThreadCount.Minimum, ThreadCount.Maximum + 1); + return new ThreadCount { Value = value }; + } + + return new NoSpecimen(); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Customizations/ValidInlineAutoData.cs b/czishrink/netczicompressTests/Customizations/ValidInlineAutoData.cs new file mode 100644 index 0000000..8e9ae2d --- /dev/null +++ b/czishrink/netczicompressTests/Customizations/ValidInlineAutoData.cs @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Customizations; + +using Xunit.Sdk; + +public class ValidInlineAutoData : CompositeDataAttribute +{ + public ValidInlineAutoData(params object[] values) + : base(new DataAttribute[] + { + new InlineDataAttribute(values), + new CorrectValueObjectAutoDataAttribute(), + }) + { + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/ExcludePropertiesByAttributeSelectionRule.cs b/czishrink/netczicompressTests/ExcludePropertiesByAttributeSelectionRule.cs new file mode 100644 index 0000000..7733fd0 --- /dev/null +++ b/czishrink/netczicompressTests/ExcludePropertiesByAttributeSelectionRule.cs @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests; + +using System.Collections.Generic; +using System.Reflection; +using global::FluentAssertions.Equivalency; + +/// +/// A selection rule that excludes all properties with a particular attribute. +/// +public class ExcludePropertiesByAttributeSelectionRule : IMemberSelectionRule +{ + private readonly Type attributeType; + + public ExcludePropertiesByAttributeSelectionRule(Type attributeType) + { + this.attributeType = attributeType; + } + + public bool IncludesMembers => false; + + public IEnumerable SelectMembers( + INode currentNode, + IEnumerable selectedMembers, + MemberSelectionContext context) + { + return from m in selectedMembers + where !this.IsPropertyWithExcludedAttribute(m) + select m; + } + + private bool IsPropertyWithExcludedAttribute(IMember member) + { + var prop = member.ReflectedType.GetProperty(member.Name); + var result = prop?.GetCustomAttributes(this.attributeType).Any() == true; + return result; + } +} diff --git a/czishrink/netczicompressTests/FluentAssertionsConfig.cs b/czishrink/netczicompressTests/FluentAssertionsConfig.cs new file mode 100644 index 0000000..6df4203 --- /dev/null +++ b/czishrink/netczicompressTests/FluentAssertionsConfig.cs @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests; + +using System.Runtime.CompilerServices; +using System.Runtime.Versioning; + +internal static class FluentAssertionsConfig +{ + [ModuleInitializer] + public static void SetDefaults() + { + AssertionOptions.AssertEquivalencyUsing( + options => options + .WithStrictOrdering() + .Using( + new ExcludePropertiesByAttributeSelectionRule( + typeof(OSPlatformAttribute)))); + } +} diff --git a/czishrink/netczicompressTests/Models/AggregateStatisticsTests.cs b/czishrink/netczicompressTests/Models/AggregateStatisticsTests.cs new file mode 100644 index 0000000..e451048 --- /dev/null +++ b/czishrink/netczicompressTests/Models/AggregateStatisticsTests.cs @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +/// +/// Tests for . +/// +public class AggregateStatisticsTests +{ + [Fact] + public void Empty_EqualsDefault() + { + AggregateStatistics.Empty.Should().Be(default(AggregateStatistics)); + } + + [Fact] + public void Empty_HasExpectedPropertyValues() + { + AggregateStatistics sut = AggregateStatistics.Empty; + sut.Should().BeEquivalentTo( + new AggregateStatistics + { + FilesWithErrors = 0, + FilesWithNoErrors = 0, + Duration = TimeSpan.Zero, + InputBytes = 0, + OutputBytes = 0, + }, + cfg => cfg.ComparingByMembers()); + + sut.DeltaBytes.Should().Be(0); + float.IsNaN(sut.OutputToInputRatio).Should().BeTrue(); + } + + [Theory] + [AutoData] + public void NonEmpty_HasExpectedCalculatedPropertyValues(AggregateStatistics sut) + { + sut.DeltaBytes.Should().Be(sut.OutputBytes - sut.InputBytes); + sut.OutputToInputRatio.Should().Be(1.0f * sut.OutputBytes / sut.InputBytes); + } + + [Fact] + public void ConcreteExample_HasExpectedCalculatedPropertyValues() + { + var sut = new AggregateStatistics + { + OutputBytes = 1500, + InputBytes = 2000, + }; + sut.DeltaBytes.Should().Be(-500); + sut.OutputToInputRatio.Should().Be(0.75f); + } +} diff --git a/czishrink/netczicompressTests/Models/AsyncEnumerableToObservableActionAdapterTests.cs b/czishrink/netczicompressTests/Models/AsyncEnumerableToObservableActionAdapterTests.cs new file mode 100644 index 0000000..4a03d6e --- /dev/null +++ b/czishrink/netczicompressTests/Models/AsyncEnumerableToObservableActionAdapterTests.cs @@ -0,0 +1,131 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Reactive.Threading.Tasks; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +using netczicompressTests.Models.Mocks; + +/// +/// Tests for . +/// +public class AsyncEnumerableToObservableActionAdapterTests +{ + [Theory] + [AutoData] + public async Task Start_WhenCalled_ReturnsItemsInSequenceAndCompletes(int[] data) + { + // ARRANGE + var sut = CreateSut(data); + + var recorder = new Recorder(); + sut.Output.Subscribe(recorder); + + // ACT + var task = sut.Output.ToTask(); + sut.Start(); + await task; + + // ASSERT + recorder.Data.Should().BeEquivalentTo(data); + } + + [Theory] + [AutoData] + public async Task Start_WhenCalledTwice_ThrowsInvalidOperationException(int[] data) + { + // ARRANGE + var sut = CreateSut(data); + var task = sut.Output.ToTask(); + sut.Start(); + + // ACT + Action act = () => sut.Start(); + + // ASSERT + act.Should().Throw().WithMessage("Start can only be called once."); + + // CLEANUP + await task; + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task Start_WhenCanceled_StopsAndReportsErrorInOutput(bool enumerableThrowsWhenCanceled) + { + // ARRANGE + using var cts = new CancellationTokenSource(); + var sut = CreateSut(Enumerable.Range(1, 10), enumerableThrowsWhenCanceled, cts.Token); + + Recorder recorder = new(); + sut.Output.Subscribe(recorder); + sut.Output.Subscribe( + onNext: x => + { + if (x == 5) + { + cts.Cancel(); + } + }, + onError: ex => { }); + + // ACT + var task = sut.Output.ToTask(); + sut.Start(); + + // ASSERT + if (enumerableThrowsWhenCanceled) + { + Func checkError = () => task; + await checkError.Should().ThrowAsync(); + recorder.Error.Should().BeOfType(); + } + else + { + await task; + recorder.Error.Should().BeNull(); + } + + recorder.Data.Should().BeEquivalentTo( + Enumerable.Range(1, 5)); + } + + private static AsyncEnumerableToObservableActionAdapter CreateSut( + IEnumerable data, + bool throwWhenCanceled = false, + CancellationToken? cancellationToken = null) + { + var token = cancellationToken ?? CancellationToken.None; + var sut = new AsyncEnumerableToObservableActionAdapter( + AsAsync(data, throwWhenCanceled, token), + token); + return sut; + } + + private static async IAsyncEnumerable AsAsync( + IEnumerable data, + bool throwWhenCanceled, + [EnumeratorCancellation] CancellationToken token) + { + await Task.Yield(); + foreach (var item in data) + { + if (throwWhenCanceled) + { + token.ThrowIfCancellationRequested(); + } + else if (token.IsCancellationRequested) + { + yield break; + } + + yield return item; + await Task.Yield(); + } + } +} diff --git a/czishrink/netczicompressTests/Models/CompositeObserverTests.cs b/czishrink/netczicompressTests/Models/CompositeObserverTests.cs new file mode 100644 index 0000000..e3e7ab7 --- /dev/null +++ b/czishrink/netczicompressTests/Models/CompositeObserverTests.cs @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +/// +/// Tests for . +/// +public class CompositeObserverTests +{ + [Fact] + public void OnCompleted_IsForwardedToAllObservers() + { + var observerMocks = CreateObserverMocks(); + + var sut = CompositeObserver.Create( + observerMocks.Select(x => x.Object).ToArray()); + + sut.OnCompleted(); + + foreach (var mock in observerMocks) + { + mock.Verify(x => x.OnCompleted(), Times.Once); + mock.VerifyNoOtherCalls(); + } + } + + [Fact] + public void OnNext_IsForwardedToAllObservers() + { + var observerMocks = CreateObserverMocks(); + + var sut = CompositeObserver.Create( + observerMocks.Select(x => x.Object).ToArray()); + + sut.OnNext(17); + sut.OnNext(17); + + foreach (var mock in observerMocks) + { + mock.Verify(x => x.OnNext(17), Times.Exactly(2)); + mock.VerifyNoOtherCalls(); + } + } + + [Fact] + public void OnError_IsForwardedToAllObservers() + { + var observerMocks = CreateObserverMocks(); + + var sut = CompositeObserver.Create( + observerMocks.Select(x => x.Object).ToArray()); + + var ex = new Exception("bla"); + sut.OnError(ex); + + foreach (var mock in observerMocks) + { + mock.Verify(x => x.OnError(ex), Times.Once); + mock.VerifyNoOtherCalls(); + } + } + + private static Mock>[] CreateObserverMocks() + { + var observerMocks = Enumerable.Range(1, 5).Select(i => new Mock>()).ToArray(); + return observerMocks; + } +} diff --git a/czishrink/netczicompressTests/Models/CompressionLevelTests.cs b/czishrink/netczicompressTests/Models/CompressionLevelTests.cs new file mode 100644 index 0000000..1a0cd70 --- /dev/null +++ b/czishrink/netczicompressTests/Models/CompressionLevelTests.cs @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +/// +/// Tests for . +/// +public class CompressionLevelTests +{ + [Fact] + public void DefaultConstructor_HasDefaultValue() + { + var sut = new CompressionLevel(); + sut.Value.Should().Be(CompressionLevel.DefaultValue); + } + + [Theory] + [InlineData(-1)] + [InlineData(23)] + [InlineData(-100)] + [InlineData(230)] + public void OutOfRange_ShouldThrowOutOfRangeException(int value) + { + var act = () => _ = new CompressionLevel { Value = value }; + + act.Should().Throw(); + } + + [Theory] + [InlineData(22)] + [InlineData(9)] + [InlineData(0)] + public void InRangeValue_ShouldBeEqual(int value) + { + var sut = new CompressionLevel { Value = value }; + sut.Value.Should().Be(value); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Models/CompressorMessageTests.cs b/czishrink/netczicompressTests/Models/CompressorMessageTests.cs new file mode 100644 index 0000000..6d4204a --- /dev/null +++ b/czishrink/netczicompressTests/Models/CompressorMessageTests.cs @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.IO.Abstractions; + +/// +/// Tests for and its subclasses. +/// +public class CompressorMessageTests +{ + [Theory] + [InlineAutoData(0)] + public void SetZeroSizeInput_HasZeroSizeRatioAndDelta(long input, long output) + { + var fixture = new Fixture().Customize(new AutoMoqCustomization()); + var sut = new CompressorMessage.FileFinished( + fixture.Create(), + input, + output, + fixture.Create(), + null); + + sut.SizeDelta.Should().Be(output); + sut.SizeRatio.Should().Be(0); + } + + [Theory] + [AutoData] + public void CreateCompressionLevel_CalculatedPropertiesAreValid(long input, long output) + { + var fixture = new Fixture().Customize(new AutoMoqCustomization()); + var sut = new CompressorMessage.FileFinished( + fixture.Create(), + input, + output, + fixture.Create(), + null); + + sut.SizeInput.Should().Be(input); + sut.SizeOutput.Should().Be(output); + sut.SizeDelta.Should().Be(output - input); + sut.SizeRatio.Should().Be(input == 0 ? 0 : (decimal)output / input); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Models/CsvLogFileWriterTests.cs b/czishrink/netczicompressTests/Models/CsvLogFileWriterTests.cs new file mode 100644 index 0000000..f125fb4 --- /dev/null +++ b/czishrink/netczicompressTests/Models/CsvLogFileWriterTests.cs @@ -0,0 +1,103 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.IO.Abstractions; + +/// +/// Tests for . +/// +public class CsvLogFileWriterTests +{ + [Theory] + [InlineData(true)] + [InlineData(false)] + public void FullRun_ProducesExpectedText(bool error) + { + // ARRANGE + var data = new (string Path, long SizeIn, long SizeOut, TimeSpan? TimeElapsed, string? Error)[] + { + ("foo/bla/bla.czi", 100, 16, TimeSpan.Zero, null), + ("foo/bla/blub.czi", 1000, 1600, TimeSpan.Zero, null), + ("bar/bla/baz,; .CZI", 1000, 1600, null, "oops\nHere's another line."), + }; + + using var writer = new StringWriter(); + + var sut = new CsvLogFileWriter(writer); + + var messages = from item in data + select new CompressorMessage.FileFinished( + Mock.Of(x => x.FullName == item.Path), + item.SizeIn, + item.SizeOut, + item.TimeElapsed, + item.Error); + + // ACT + foreach (var item in messages) + { + sut.OnNext(item); + } + + if (error) + { + sut.OnError(new Exception()); + } + else + { + sut.OnCompleted(); + } + + // ASSERT + var csvFileContents = writer.ToString(); + var csvFileRows = csvFileContents.Split("\r\n"); + + csvFileRows.Should().BeEquivalentTo( + new[] + { + "InputFile,SizeInput,SizeOutput,SizeRatio,SizeDelta,TimeToProcess,Status,ErrorMessage", + "\"foo/bla/bla.czi\",100,16,0.16,-84,00:00:00,SUCCESS,", + "\"foo/bla/blub.czi\",1000,1600,1.6,600,00:00:00,SUCCESS,", + "\"bar/bla/baz,; .CZI\",1000,1600,,,,ERROR,\"oops\nHere's another line.\"", + string.Empty, + }); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void OnNext_WhenCalledAfterCompletion_ProducesNoResult(bool error) + { + // ARRANGE + using var writer = new StringWriter(); + + var sut = new CsvLogFileWriter(writer); + + if (error) + { + sut.OnError(new Exception()); + } + else + { + sut.OnCompleted(); + } + + // ACT + var message = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }).Create(); + sut.OnNext(message); + + // ASSERT + var csvFileContents = writer.ToString(); + var csvFileRows = csvFileContents.Split("\r\n"); + + csvFileRows.Should().BeEquivalentTo( + new[] + { + "InputFile,SizeInput,SizeOutput,SizeRatio,SizeDelta,TimeToProcess,Status,ErrorMessage", + string.Empty, + }); + } +} diff --git a/czishrink/netczicompressTests/Models/CsvLoggingStrategyTests.cs b/czishrink/netczicompressTests/Models/CsvLoggingStrategyTests.cs new file mode 100644 index 0000000..94fea65 --- /dev/null +++ b/czishrink/netczicompressTests/Models/CsvLoggingStrategyTests.cs @@ -0,0 +1,152 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Diagnostics; +using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; + +/// +/// Tests for . +/// +public class CsvLoggingStrategyTests +{ + [Fact] + public void LoggerScheduler_WhenNotSet_ReturnsDefaultScheduler() + { + var sut = new CsvLoggingStrategy(Mock.Of()); + + sut.LoggerScheduler.Should().BeSameAs(DefaultScheduler.Instance); + } + + [Theory] + [AutoData] + public void CreateLogFile_WhenCalled_ProducesExpectedFileName(bool recursive, CompressionMode mode) + { + // ARRANGE + var schedulerMock = new Mock(MockBehavior.Strict); + + var sut = new CsvLoggingStrategy(Mock.Of()) + { + LoggerScheduler = schedulerMock.Object, + }; + + var fs = new MockFileSystem(new MockFileSystemOptions { CreateDefaultTempDir = true }); + + var outputDir = fs.Path.Combine(fs.Path.GetTempPath(), "foo"); + var runParameters = new FolderCompressorParameters( + new Mock(MockBehavior.Strict).Object, + fs.DirectoryInfo.New(outputDir), + recursive, + mode, + new ExecutionOptions(ThreadCount.Default), + new ProcessingOptions(CompressionLevel.Default)); + + schedulerMock.SetupGet(x => x.Now).Returns( + DateTimeOffset.Parse($"3067-11-14T23:59:59.1234")); + + // ACT + var actual = sut.CreateLogFile(runParameters); + + // ASSERT + var expected = fs.Path.Combine(outputDir, $"CziShrink_30671114T235959_{mode}.csv"); + actual.FullName.Should().Be(expected); + actual.Exists.Should().BeFalse(); + } + + [Theory] + [AutoData] + public async Task CreateLogFile_WhenCalled_ProducesUniqueFileName(bool recursive, CompressionMode mode) + { + // ARRANGE + DateTimeOffset now = DateTimeOffset.Parse($"3067-11-14T23:59:59.1234"); + var schedulerMock = new Mock(MockBehavior.Strict); + schedulerMock.SetupGet(x => x.Now).Returns(() => + { + lock (schedulerMock) + { + return now; + } + }); + + var sut = new CsvLoggingStrategy(Mock.Of()) + { + LoggerScheduler = schedulerMock.Object, + }; + + var fs = new MockFileSystem(new MockFileSystemOptions { CreateDefaultTempDir = true }); + + var outputDir = fs.Path.Combine(fs.Path.GetTempPath(), "foo"); + var runParameters = new FolderCompressorParameters( + new Mock(MockBehavior.Strict).Object, + fs.DirectoryInfo.New(outputDir), + recursive, + mode, + new ExecutionOptions(ThreadCount.Default), + new ProcessingOptions(CompressionLevel.Default)); + CreateFile(sut.CreateLogFile(runParameters)); + + // ACT + Task actTask = Task.Run(() => sut.CreateLogFile(runParameters)); + SpinWait.SpinUntil(() => actTask.Status == TaskStatus.Running); + await Task.Delay(10); + actTask.Status.Should().Be(TaskStatus.Running); + + lock (schedulerMock) + { + now += TimeSpan.FromSeconds(1.5); + } + + // ASSERT + var expected = fs.Path.Combine(outputDir, $"CziShrink_30671115T000000_{mode}.csv"); + var actual = await actTask; + actual.FullName.Should().Be(expected); + actual.Exists.Should().BeFalse(); + } + + [Fact] + public void CreateLogger_WhenCalled_CreatesCsvLogWriter() + { + // ARRANGE + var sut = new CsvLoggingStrategy(Mock.Of()); + + using var writer = Mock.Of(); + + // ACT + var actual = sut.CreateLogger(writer); + + // ASSERT + var result = actual.Should().BeOfType().Subject; + result.Writer.Should().BeSameAs(writer); + } + + [Fact] + public void OpenLogFile_WhenCalled_UsesFileLauncher() + { + // ARRANGE + var fileLauncherMock = new Mock(); + var sut = new CsvLoggingStrategy(fileLauncherMock.Object); + var fileInfo = Mock.Of(f => f.FullName == "/foo/bar/baz.CSV"); + + // ACT + sut.OpenLogFile(fileInfo); + + // ASSERT + fileLauncherMock.Verify(l => l.Launch("/foo/bar/baz.CSV"), Times.Once); + fileLauncherMock.VerifyNoOtherCalls(); + } + + private static void CreateFile(IFileInfo firstFile) + { + firstFile.Directory!.Create(); + using (var firstFileHandle = firstFile.AppendText()) + { + firstFileHandle.WriteLine("foo"); + } + + firstFile.Refresh(); + Debug.Assert(firstFile.Exists, "Error in ARRANGE"); + } +} diff --git a/czishrink/netczicompressTests/Models/FileLauncherTests.cs b/czishrink/netczicompressTests/Models/FileLauncherTests.cs new file mode 100644 index 0000000..76126d9 --- /dev/null +++ b/czishrink/netczicompressTests/Models/FileLauncherTests.cs @@ -0,0 +1,279 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Diagnostics; +using System.IO.Abstractions; +using System.Linq.Expressions; +using System.Runtime.InteropServices; + +/// +/// Tests for . +/// +public class FileLauncherTests +{ + [Fact] + public async Task Launch_WhenCalled_RunsExpectedProcess() + { + // ARRANGE + var sut = new TestableFileLauncher(); + var path = "/foo/bar/baz"; + + // ACT + await sut.Launch(path); + + // ASSERT + var runAsyncInvocationArgs = sut.GetRunAsyncInvocationsArgs(); + runAsyncInvocationArgs.Should().BeEquivalentTo( + new[] + { + new ProcessStartInfo + { + FileName = "/foo/bar/baz", + UseShellExecute = true, + }, + }); + } + + [Theory] + [InlineData(null, "explorer")] + [InlineData(@"C:\Fenster", @"C:\Fenster\explorer")] + public async Task Reveal_WhenWindows_RunsExpectedProcess( + string? systemRootEnvironmentVariableValue, + string expectedFileName) + { + // ARRANGE + string? overridePlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + ? null + : "WINDOWS"; + + var getEnv = Mock.Of>( + x => x("SYSTEMROOT") == systemRootEnvironmentVariableValue); + + var sut = new TestableFileLauncher( + overridePlatform: overridePlatform, + fs: Mock.Of(x => x.Path == MockPathCombineWindows()), + getEnvironmentVariable: getEnv); + + var path = @"C:\foo bar\baz"; + + // ACT + await sut.Reveal(path); + + // ASSERT + var runAsyncInvocationArgs = sut.GetRunAsyncInvocationsArgs(); + runAsyncInvocationArgs.Should().BeEquivalentTo( + new[] + { + new ProcessStartInfo + { + FileName = expectedFileName, + Arguments = @"/select,""C:\foo bar\baz""", + }, + }); + } + + [Fact] + public async Task Reveal_WhenOsx_RunsExpectedProcess() + { + // ARRANGE + string? overridePlatform = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) + ? null + : "OSX"; + + var sut = new TestableFileLauncher( + overridePlatform: overridePlatform); + + var path = @"/foo bar/baz"; + + // ACT + await sut.Reveal(path); + + // ASSERT + var runAsyncInvocationArgs = sut.GetRunAsyncInvocationsArgs(); + runAsyncInvocationArgs.Should().BeEquivalentTo( + new[] + { + new ProcessStartInfo + { + FileName = "explorer", + Arguments = @"-R ""/foo bar/baz""", + }, + }); + } + + [Theory] + [InlineData("LINUX")] + [InlineData("SOLARIS")] + [InlineData("FREEBSD")] + [InlineData("NETBSD")] + public async Task Reveal_WhenLinux_RunsExpectedProcess(string platform) + { + // ARRANGE + string? overridePlatform = OperatingSystem.IsOSPlatform(platform) + ? null + : platform; + + var path = @"/foo/bar baz/xyz.czi"; + Func? overridePathToFileUri = OperatingSystem.IsOSPlatform(platform) + ? null + : Mock.Of>(f => f(path) == "file:///foo/bar%20baz/xyz.czi"); + + var sut = new TestableFileLauncher( + overridePathToFileUri: overridePathToFileUri, + overridePlatform: overridePlatform); + + // ACT + await sut.Reveal(path); + + // ASSERT + var runAsyncInvocationArgs = sut.GetRunAsyncInvocationsArgs(); + runAsyncInvocationArgs.Should().BeEquivalentTo( + new[] + { + new ProcessStartInfo + { + FileName = "dbus-send", + Arguments = @"--print-reply --dest=org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:""file:///foo/bar%20baz/xyz.czi"" string:""""", + UseShellExecute = true, + }, + }); + } + + [Theory] + [InlineData("LINUX")] + [InlineData("SOLARIS")] + [InlineData("FREEBSD")] + [InlineData("NETBSD")] + public async Task Reveal_WhenDbusSendReturnsNonZero_RunsExpectedProcess(string platform) + { + // ARRANGE + string? overridePlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && platform == "LINUX" + ? null + : platform; + + var path = "/foo/bar baz/xyz.czi"; + Func? pathToFileUri = OperatingSystem.IsOSPlatform(platform) + ? null + : Mock.Of>(f => f(path) == "file:///foo/bar%20baz/xyz.czi"); + + var sut = new TestableFileLauncher( + fs: Mock.Of(x => x.Path.GetDirectoryName(path) == "/path/of/parent/dir"), + overridePathToFileUri: pathToFileUri, + overridePlatform: overridePlatform); + + var nonZeroExitCode = new Fixture().CreateMany().First(x => x != 0); + sut.SetupExitCode(p => p.FileName == "dbus-send", nonZeroExitCode); + + // ACT + await sut.Reveal(path); + + // ASSERT + var runAsyncInvocationArgs = sut.GetRunAsyncInvocationsArgs(); + runAsyncInvocationArgs.Should().BeEquivalentTo( + new[] + { + new ProcessStartInfo + { + FileName = "dbus-send", + Arguments = @"--print-reply --dest=org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:""file:///foo/bar%20baz/xyz.czi"" string:""""", + UseShellExecute = true, + }, + new ProcessStartInfo + { + FileName = "/path/of/parent/dir", + UseShellExecute = true, + }, + }); + } + + [Fact] + public async Task Reveal_WhenOtherOs_LaunchesParentFolder() + { + // ARRANGE + var path = "/foo/bar baz/xyz.czi"; + + var sut = new TestableFileLauncher( + fs: Mock.Of(x => x.Path.GetDirectoryName(path) == "/path/of/parent/dir"), + overridePlatform: "UNSUPPORTED"); + + // ACT + await sut.Reveal(path); + + // ASSERT + var runAsyncInvocationArgs = sut.GetRunAsyncInvocationsArgs(); + runAsyncInvocationArgs.Should().BeEquivalentTo( + new[] + { + new ProcessStartInfo + { + FileName = "/path/of/parent/dir", + UseShellExecute = true, + }, + }); + } + + private static IPath MockPathCombineWindows() + { + var pathMock = new Mock(); + pathMock + .Setup( + x => x.Combine(It.IsAny(), It.IsAny())) + .Returns( + (string a, string b) => $"{a}\\{b}"); + var pathMockObject = pathMock.Object; + return pathMockObject; + } + + private class TestableFileLauncher : FileLauncher + { + private readonly Func? pathToFileUri; + + public TestableFileLauncher( + IFileSystem? fs = null, + string? overridePlatform = null, + Func? overridePathToFileUri = null, + Func? getEnvironmentVariable = null) + : base( + fs ?? Mock.Of(), + getEnvironmentVariable ?? Mock.Of>()) + { + this.pathToFileUri = overridePathToFileUri; + this.CurrentPlatform = overridePlatform ?? this.CurrentPlatform; + this.RunAsyncMock = new Mock>>(); + this.RunAsyncMock + .Setup(x => x.Invoke(It.IsAny())) + .Returns(Task.FromResult(0)); + } + + public Mock>> RunAsyncMock { get; } + + public ProcessStartInfo[] GetRunAsyncInvocationsArgs() + { + var result = from invocation in this.RunAsyncMock.Invocations + select invocation.Arguments.Cast().Single(); + return result.ToArray(); + } + + public void SetupExitCode(Expression> processStartInfoSelector, int exitCode) + { + this.RunAsyncMock + .Setup( + x => x.Invoke(It.Is(processStartInfoSelector))) + .Returns(Task.FromResult(exitCode)); + } + + protected override Task RunAsync(ProcessStartInfo processStartInfo) + { + return this.RunAsyncMock.Object.Invoke(processStartInfo); + } + + protected override string PathToFileUri(string path) + { + return this.pathToFileUri?.Invoke(path) + ?? base.PathToFileUri(path); + } + } +} diff --git a/czishrink/netczicompressTests/Models/FileProcessingFailedHandlerTests.cs b/czishrink/netczicompressTests/Models/FileProcessingFailedHandlerTests.cs new file mode 100644 index 0000000..5a4ebb1 --- /dev/null +++ b/czishrink/netczicompressTests/Models/FileProcessingFailedHandlerTests.cs @@ -0,0 +1,88 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.IO.Abstractions; +using System.Reactive.Disposables; + +/// +/// Unit tests for the class. +/// +public class FileProcessingFailedHandlerTests +{ + [Theory] + [InlineData(true)] + [InlineData(false)] + public void OnFileProcessingFailed_WithDifferentOptions_ReturnsCorrectValue(bool copyFailedFiles) + { + // Arrange + string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + var inputFileName = $"{fileName}.czi"; + using var deleteInput = DeleteLater(inputFileName); + var inputFile = CreateFileInfo(inputFileName); + var inputFileInfo = new FileInfo(inputFileName); + using var inputStream = inputFileInfo.Create(); + inputStream.WriteByte(5); + inputStream.Close(); + + var outputFileName = $"{fileName}_out.czi"; + using var deleteOutput = DeleteLater(outputFileName); + + var tempOutputFileName = $"{fileName}_temp.czi"; + using var deleteTempOutput = DeleteLater(tempOutputFileName); + + var target = new FileProcessingFailedHandler(); + string innerException = "Something bad happened."; + int reportedProgress = -1; + + // Act + var result = target.FileProcessingFailed( + inputFile, + CreateFileInfo(outputFileName), + CreateFileInfo(tempOutputFileName), + progress => reportedProgress = progress, + innerException, + copyFailedFiles, + CancellationToken.None); + + // Assert + result.Should().Be(copyFailedFiles ? $"{innerException} {FileProcessingFailedHandler.SuccessfulCopyMessage}" : innerException); + reportedProgress.Should().Be(copyFailedFiles ? 100 : -1); + } + + [Fact] + public void OnFileProcessingFailed_WithCopyOptionAndFailedCopyOperation_ReturnsCorrectValue() + { + // Arrange + var target = new FileProcessingFailedHandler(); + var inFile = new Mock(); + inFile.Setup(x => x.CopyTo(It.IsAny(), It.IsAny())).Throws(); + var outFile = new Mock(); + var tempOutFile = new Mock(); + string innerException = "Something bad happened."; + + // Act + var result = target.FileProcessingFailed( + inFile.Object, + outFile.Object, + tempOutFile.Object, + _ => { }, + innerException, + true, + CancellationToken.None); + + // Assert + result.Should().Be($"{innerException} {FileProcessingFailedHandler.FailedCopyMessage}"); + } + + private static IFileInfo CreateFileInfo(string fileName) + { + var fileInfo = new Mock(); + fileInfo.Setup(x => x.FullName).Returns(fileName); + return fileInfo.Object; + } + + private static IDisposable DeleteLater(string path) => Disposable.Create(() => File.Delete(path)); +} diff --git a/czishrink/netczicompressTests/Models/FolderCompressorDecoratorTests.cs b/czishrink/netczicompressTests/Models/FolderCompressorDecoratorTests.cs new file mode 100644 index 0000000..98a6c3e --- /dev/null +++ b/czishrink/netczicompressTests/Models/FolderCompressorDecoratorTests.cs @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using netczicompressTests.Customizations; + +using IFolderCompressorRun = netczicompress.Models.IObservableAction; + +/// +/// Tests for . +/// +public class FolderCompressorDecoratorTests +{ + [Fact] + public void PrepareNewRun_WhenCalled_CallsObserveRunWithExpectedArgs() + { + // ARRANGE + var strictMocks = new MockRepository(MockBehavior.Strict); + var coreMock = strictMocks.Create(); + var observeRun = new Mock>>(); + var coreOutput = strictMocks.OneOf>(); + var observableAction = strictMocks.OneOf( + x => x.Output == coreOutput); + + var fixture = new Fixture().Customize(new AutoMoqCustomization()); + fixture.Customizations.Add(new CompressionLevelSpecimenBuilder()); + fixture.Customizations.Add(new ThreadCountSpecimenBuilder()); + var p = fixture.Create(); + var t = fixture.Create(); + coreMock + .Setup(x => x.PrepareNewRun(p, t)) + .Returns(observableAction) + .Verifiable(Times.Once); + + var sut = new FolderCompressorDecorator + { + Core = coreMock.Object, + ObserveRun = observeRun.Object, + }; + + // ACT + var actual = sut.PrepareNewRun(p, t); + + // ASSERT + actual.Should().BeSameAs(observableAction); + coreMock.Verify(); + observeRun.Verify(d => d.Invoke(p, coreOutput), Times.Once); + observeRun.VerifyNoOtherCalls(); + } +} diff --git a/czishrink/netczicompressTests/Models/FolderCompressorExtensionsTests.cs b/czishrink/netczicompressTests/Models/FolderCompressorExtensionsTests.cs new file mode 100644 index 0000000..b3eacf3 --- /dev/null +++ b/czishrink/netczicompressTests/Models/FolderCompressorExtensionsTests.cs @@ -0,0 +1,98 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using netczicompressTests.Customizations; +using netczicompressTests.Models.Mocks; +using static netczicompress.Models.CompressorMessage; +using IFolderCompressorRun = netczicompress.Models.IObservableAction; + +/// +/// Tests for . +/// +public class FolderCompressorExtensionsTests +{ + [Fact] + public void DecorateWithRunObserver_WhenCalled_ReportsMessagesFromRunToObserver() + { + // ARRANGE + var fixture = new Fixture().Customize(new AutoMoqCustomization()); + fixture.Customizations.Add(new ThreadCountSpecimenBuilder()); + var p = fixture.Create(); + var t = fixture.Create(); + + IEnumerable runData = CreateMixedMessages(fixture); + + var runMock = new Mock().WithData(runData); + + var coreMock = new Mock(); + coreMock + .Setup(x => x.PrepareNewRun(p, t)) + .Returns(runMock.Object) + .Verifiable(Times.Once); + + var recorder = new Recorder(); + var runObserverMock = new Mock>(); + runObserverMock + .Setup( + x => x.ObserveRun(p, It.IsAny>())) + .Callback>( + (pp, obs) => obs.Subscribe(recorder)) + .Verifiable(Times.Once); + + var sut = coreMock.Object.DecorateWithRunObserver(runObserverMock.Object); + + // ACT + sut.PrepareNewRun(p, t).Start(); + + // ASSERT + coreMock.Verify(); + runObserverMock.Verify(); + recorder.Data.Should().BeEquivalentTo( + runData.OfType(), + cfg => cfg.WithoutStrictOrdering()); + } + + [Fact] + public void DecorateWithObserver_WhenCalled_ReportsMessagesFromRunToObserver() + { + // ARRANGE + var fixture = new Fixture().Customize(new AutoMoqCustomization()); + fixture.Customizations.Add(new ThreadCountSpecimenBuilder()); + var p = fixture.Create(); + var t = fixture.Create(); + + var runData = CreateMixedMessages(fixture); + + var runMock = new Mock().WithData(runData); + + var coreMock = new Mock(); + coreMock + .Setup(x => x.PrepareNewRun(p, t)) + .Returns(runMock.Object) + .Verifiable(Times.Once); + + var recorder = new Recorder(); + + var sut = coreMock.Object.DecorateWithObserver(recorder, Scheduler.Immediate); + + // ACT + sut.PrepareNewRun(p, t).Start(); + + // ASSERT + coreMock.Verify(); + recorder.Data.Should().BeEquivalentTo( + runData.OfType(), + cfg => cfg.WithoutStrictOrdering()); + } + + private static IEnumerable CreateMixedMessages(IFixture fixture) + { + return fixture.CreateMany(5).Cast() + .Concat(fixture.CreateMany(3)) + .Concat(fixture.CreateMany(5)) + .Concat(fixture.CreateMany(8)).ToArray(); + } +} diff --git a/czishrink/netczicompressTests/Models/Mocks/FileProcessorMockExtensions.cs b/czishrink/netczicompressTests/Models/Mocks/FileProcessorMockExtensions.cs new file mode 100644 index 0000000..0edb8fa --- /dev/null +++ b/czishrink/netczicompressTests/Models/Mocks/FileProcessorMockExtensions.cs @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models.Mocks; + +/// +/// Extension method for mocks of and collections thereof. +/// +internal static class FileProcessorMockExtensions +{ + public static Mock WithProcessFile( + this Mock mock, + Action processFile) + { + mock + .Setup(x => x.ProcessFile(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback(processFile); + return mock; + } + + public static T CheckCount(this T listOfCreatedProcessors, int maxCount) + where T : IReadOnlyCollection> + { + listOfCreatedProcessors.Count.Should().BeLessThanOrEqualTo(maxCount); + return listOfCreatedProcessors; + } + + public static IEnumerable<(string InputFile, string OutputFile)> GetProcessedFileArgs(this Mock p) + { + var allArgses = from invocation in p.Invocations + where invocation.Method.Name == nameof(IFileProcessor.ProcessFile) + select invocation.Arguments; + + var filenameArgses = from args in allArgses + select ((string)args[0], (string)args[1]); + + return filenameArgses; + } + + public static T CheckDisposed(this T processors) + where T : IEnumerable> + { + // check all disposables have been disposed + foreach (var d in processors) + { + d.Verify(x => x.Dispose(), Times.Once); + } + + return processors; + } +} diff --git a/czishrink/netczicompressTests/Models/Mocks/FolderCompressorMockExtensions.cs b/czishrink/netczicompressTests/Models/Mocks/FolderCompressorMockExtensions.cs new file mode 100644 index 0000000..d393efe --- /dev/null +++ b/czishrink/netczicompressTests/Models/Mocks/FolderCompressorMockExtensions.cs @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models.Mocks; + +using AutoFixture; + +using IFolderCompressorRun = netczicompress.Models.IObservableAction; + +public static class FolderCompressorMockExtensions +{ + public static Mock WithRun(this Mock self, IFolderCompressorRun run) + { + self + .Setup(x => x.PrepareNewRun(It.IsAny(), It.IsAny())) + .Returns(run); + return self; + } + + public static Mock WithData(this Mock self, IEnumerable messages) + { + var runMock = new Mock().WithData(messages); + return self.WithRun(runMock.Object); + } + + public static Mock WithAutoData(this Mock self, IFixture fixture) + { + IEnumerable messages = + fixture.CreateMany(); + messages = messages.Concat( + fixture.CreateMany()); + + var runMock = new Mock().WithData(messages); + return self.WithRun(runMock.Object); + } + + public static Mock WithException(this Mock self, Exception ex) + { + var runMock = new Mock().WithException(ex); + return self.WithRun(runMock.Object); + } + + public static Mock WithWaitForCancellation(this Mock self) + { + self + .Setup( + x => x.PrepareNewRun(It.IsAny(), It.IsAny())) + .Returns( + (_, token) => new Mock().WithWaitForCancellation(token).Object); + return self; + } +} diff --git a/czishrink/netczicompressTests/Models/Mocks/FolderCompressorRunMockExtensions.cs b/czishrink/netczicompressTests/Models/Mocks/FolderCompressorRunMockExtensions.cs new file mode 100644 index 0000000..0c73082 --- /dev/null +++ b/czishrink/netczicompressTests/Models/Mocks/FolderCompressorRunMockExtensions.cs @@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models.Mocks; + +using System.Reactive.Subjects; + +using IFolderCompressorRun = netczicompress.Models.IObservableAction; + +public static class FolderCompressorRunMockExtensions +{ + public static Mock> WithData(this Mock> runMock, IEnumerable messages) + { + var subject = new Subject(); + runMock.SetupGet(x => x.Output).Returns(subject.AsObservable()); + runMock + .Setup(x => x.Start()) + .Callback(() => subject.OnNextAllAndComplete(messages)); + return runMock; + } + + public static Mock WithException(this Mock runMock, Exception ex) + { + var subject = new Subject(); + runMock.SetupGet(x => x.Output).Returns(subject.AsObservable()); + runMock + .Setup(x => x.Start()) + .Callback(() => subject.OnError(ex)); + return runMock; + } + + public static Mock WithWaitForCancellation( + this Mock runMock, + CancellationToken token) + { + var subject = new Subject(); + runMock.SetupGet(x => x.Output).Returns(subject.AsObservable()); + runMock + .Setup(x => x.Start()) + .Callback(() => + { + token.Register(() => + { + try + { + token.ThrowIfCancellationRequested(); + } + catch (OperationCanceledException ex) + { + subject.OnError(ex); + } + }); + }); + return runMock; + } + + public static IObservableAction ToObservableAction(this IEnumerable messages) + { + return new Mock>().WithData(messages).Object; + } +} diff --git a/czishrink/netczicompressTests/Models/Mocks/ObservableExtensions.cs b/czishrink/netczicompressTests/Models/Mocks/ObservableExtensions.cs new file mode 100644 index 0000000..67bc023 --- /dev/null +++ b/czishrink/netczicompressTests/Models/Mocks/ObservableExtensions.cs @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models.Mocks; + +public static class ObservableExtensions +{ + public static Recorder StartRecording(this IObservable source) + { + var result = new Recorder(); + _ = source.Subscribe(result); + return result; + } + + public static void OnNextAll(this IObserver observer, IEnumerable values) + { + foreach (var item in values) + { + observer.OnNext(item); + } + } + + public static void OnNextAllAndComplete(this IObserver observer, IEnumerable values) + { + observer.OnNextAll(values); + observer.OnCompleted(); + } +} diff --git a/czishrink/netczicompressTests/Models/Mocks/ProgressRecorder.cs b/czishrink/netczicompressTests/Models/Mocks/ProgressRecorder.cs new file mode 100644 index 0000000..0bccf58 --- /dev/null +++ b/czishrink/netczicompressTests/Models/Mocks/ProgressRecorder.cs @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models.Mocks; + +using System.Collections.Concurrent; + +/// +/// Records all progress messages from an run. +/// +internal class ProgressRecorder : IObserver +{ + public ConcurrentDictionary> ProgressValuesByFile { get; } = new(); + + public void OnCompleted() + { + } + + public void OnError(Exception error) + { + } + + public void OnNext(CompressorMessage.FileStarting value) + { + this.RecordProgress(value); + } + + private void RecordProgressValue(string file, int p) + { + var progressValuesForFile = this.ProgressValuesByFile.GetOrAdd(file, new List()); + progressValuesForFile.Add(p); + } + + private void RecordProgress(CompressorMessage.FileStarting fileStarting) + { + fileStarting.ProgressPercent.Subscribe( + p => this.RecordProgressValue(fileStarting.InputFile.FullName, p)); + } +} diff --git a/czishrink/netczicompressTests/Models/Mocks/Recorder{T}.cs b/czishrink/netczicompressTests/Models/Mocks/Recorder{T}.cs new file mode 100644 index 0000000..d6f5dbb --- /dev/null +++ b/czishrink/netczicompressTests/Models/Mocks/Recorder{T}.cs @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models.Mocks; + +public class Recorder : IObserver +{ + public List Data { get; } = new(); + + public bool Completed { get; private set; } + + public Exception? Error { get; private set; } + + public void OnCompleted() + { + this.Completed = true; + } + + public void OnError(Exception error) + { + this.Error = error; + } + + public void OnNext(T value) + { + if (this.Completed || this.Error != null) + { + throw new InvalidOperationException(); + } + + this.Data.Add(value); + } +} diff --git a/czishrink/netczicompressTests/Models/Mocks/SchedulerMock.cs b/czishrink/netczicompressTests/Models/Mocks/SchedulerMock.cs new file mode 100644 index 0000000..18fef00 --- /dev/null +++ b/czishrink/netczicompressTests/Models/Mocks/SchedulerMock.cs @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models.Mocks; + +using System.Reactive.Concurrency; +using System.Reactive.Disposables; + +/// +/// A scheduler whose queue must be run explicitly. +/// +public class SchedulerMock : IScheduler +{ + public DateTimeOffset Now => DateTimeOffset.Now; + + private Queue Queue { get; } = new(); + + public void RunQueuedActions() + { + while (this.Queue.TryDequeue(out var action)) + { + action(); + } + } + + public IDisposable Schedule(TState state, Func action) + { + this.Queue.Enqueue(() => _ = action(this, state)); + return Disposable.Empty; + } + + public IDisposable Schedule(TState state, TimeSpan dueTime, Func action) + { + throw new NotImplementedException(); + } + + public IDisposable Schedule(TState state, DateTimeOffset dueTime, Func action) + { + throw new NotImplementedException(); + } +} diff --git a/czishrink/netczicompressTests/Models/MultiThreadedFolderCompressorTests.cs b/czishrink/netczicompressTests/Models/MultiThreadedFolderCompressorTests.cs new file mode 100644 index 0000000..aaca2b1 --- /dev/null +++ b/czishrink/netczicompressTests/Models/MultiThreadedFolderCompressorTests.cs @@ -0,0 +1,622 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; +using System.Reactive.Threading.Tasks; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; + +using netczicompressTests.Customizations; + +using netczicompressTests.Models.Mocks; + +/// +/// Tests for . +/// +public class MultiThreadedFolderCompressorTests +{ + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task WhenProcessorNeedsOutputDirs_RunCreatesOutputDirs(bool needsOutputDir) + { + // ARRANGE + var processor = Mock.Of(x => x.NeedsExistingOutputDirectory == needsOutputDir); + var ff = new FoldersAndFiles( + @"C:\inputDir", + @"X:\outputDir", + @"C:\inputDir\subDir\image-1.czi", + @"C:\inputDir\subDir\image-2.czi", + @"X:\outputDir\blabla.text"); + + var sut = CreateSut((_, _) => processor); + + var run = sut.PrepareNewRun( + ff.GetFolderCompressorParameters(), + CancellationToken.None); + + // ACT + Task t = run.Output.ToTask(); + run.Start(); + await t; + + // ASSERT + var fs = ff.FileSystem; + var outputSubDir = fs.DirectoryInfo.New( + fs.Path.Combine(ff.OutputDir.FullName, "subDir")); + outputSubDir.Exists.Should().Be(needsOutputDir); + } + + [Theory] + [CorrectValueObjectAutoData] + public async Task WhenRunCompletes_ThenProcessFileHasBeenCalledWithCorrectFileArgs(CompressionMode mode, ExecutionOptions executionOptions, ProcessingOptions processingOptions) + { + var ff = new FoldersAndFiles( + @"C:\inputDir", + @"D:\outputDir", + @"C:\inputDir\subDir\image-1.czi", + @"C:\inputDir\subDir\image-2.czi", + @"C:\inputDir\subDir\image-3.czi", + @"C:\inputDir\subDir2\image-4.czi", + @"C:\inputDir\subDir3\image-5.czi", + @"C:\inputDir\subDir4\ € 123,;!.czi", + @"C:\inputDir\subDir4\image-6.tiff", + @"C:\inputDir\subDir\image-7.czi", + @"D:\outputDir\blabla.czi"); + + await WhenRunCompletes_ThenProcessFileHasBeenCalledWithCorrectFileArgsImpl(mode, executionOptions, processingOptions, ff); + } + + [Theory] + [CorrectValueObjectAutoData] + public async Task WhenRunCompletes_ThenProgressHasBeenReportedForAllFiles( + CompressionMode mode, + ExecutionOptions executionOptions, + ProcessingOptions processingOptions) + { + // ARRANGE + int ProgressForFile(string inputPath) => 1 + (Math.Abs(inputPath.GetHashCode()) % 99); + + var progressRecorder = new ProgressRecorder(); + var processorFactory = CreateProcessorFactory( + mode, + processingOptions, + onMockCreated: m => m.WithProcessFile((inputPath, _, reportProgress, _) => + reportProgress(ProgressForFile(inputPath)))); + + var ff = new FoldersAndFiles( + @"C:\inputDir", + @"C:\outputDir", + @"C:\inputDir\subDir\image.czi", + @"C:\inputDir\subDir\image-2.czi", + @"C:\inputDir\subDir\image-3.czi", + @"C:\inputDir\subDir2\image.czi", + @"C:\inputDir\subDir3\image-5.czi", + @"C:\inputDir\subDir4\image-6.czi", + @"C:\inputDir\subDir\image-7.czi", + @"C:\outputDir\blabla.text"); + var czis = ff.InitialFiles.Where(f => f.EndsWith(".czi")).ToArray(); + + var sut = CreateSut(processorFactory); + + var run = sut.PrepareNewRun( + ff.GetFolderCompressorParameters(mode, executionOptions, processingOptions), + CancellationToken.None); + + run + .Output + .OfType() + .Subscribe(progressRecorder); + + // ACT + Task t = run.Output.ToTask(); + run.Start(); + await t; + + // ASSERT + progressRecorder.ProgressValuesByFile.Count.Should().Be(czis.Length); + foreach (var file in czis) + { + progressRecorder.ProgressValuesByFile[file] + .Should() + .BeEquivalentTo( + new[] { 0, ProgressForFile(file), 100 }); + } + } + + [Theory] + [CorrectValueObjectAutoData] + public async Task WhenRunCompletes_ThenHasNotProcessedAnyFilesCreatedDuringTheRun( + CompressionMode mode, ExecutionOptions executionOptions, ProcessingOptions processingOptions) + { + // Now outputDir is a subdirectory of inputDir. Files created there must not be processed. + var ff = new FoldersAndFiles( + @"C:\inputDir", + @"C:\inputDir\subDir4\outputDir", + @"C:\inputDir\subDir\image-1.czi", + @"C:\inputDir\subDir\image-2.czi", + @"C:\inputDir\subDir\image-3.czi", + @"C:\inputDir\subDir2\image-4.czi", + @"C:\inputDir\subDir3\image-5.czi", + @"C:\inputDir\subDir4\image-6.czi", + @"C:\inputDir\subDir\image-7.czi", + @"D:\outputDir\blabla.text"); + + void ConfigureProcessor(Mock mock) + { + mock.WithProcessFile((inp, outp, _, _) => ff.FileSystem.File.Copy(inp, outp)); + mock.SetupGet(p => p.NeedsExistingOutputDirectory).Returns(true); + } + + await WhenRunCompletes_ThenProcessFileHasBeenCalledWithCorrectFileArgsImpl(mode, executionOptions, processingOptions, ff, ConfigureProcessor, true); + } + + [Theory] + [ValidInlineAutoData(true)] + [ValidInlineAutoData(false)] + public async Task WhenCanceled_ThenDisposesAllProcessorsAndThrows( + bool processFileThrows, + CompressionMode mode, + ExecutionOptions executionOptions, + ProcessingOptions processingOptions) + { + var ff = new FoldersAndFiles( + @"C:\inputDir", + @"C:\outputDir", + @"C:\inputDir\subDir\image.czi", + @"C:\inputDir\subDir\image-2.czi", + @"C:\inputDir\subDir\image-3.czi", + @"C:\inputDir\subDir2\image.czi", + @"C:\inputDir\subDir3\image-5.czi", + @"C:\inputDir\subDir4\image-6.czi", + @"C:\inputDir\subDir\image-7.czi", + @"C:\outputDir\blabla.text"); + + // Auto-data does not work here without adaption. + // In the gitlab runners the maximum thread number is 2, on local machines there might be 28 threads or more + // available. + // We need to bound the number of threads by the number of czi-files, mind that one of the initial files is no czi. + var numOfCziFiles = ff.InitialFiles.Length - 1; + executionOptions = new ExecutionOptions(new ThreadCount() + { Value = Math.Min(executionOptions.ThreadCount.Value, numOfCziFiles) }); + + // ARRANGE + using var cts = new CancellationTokenSource(); + ConcurrentBag> processors = new(); + bool disposedDuringProcessing = false; + var processorFactory = CreateProcessorFactory(mode, processingOptions, onMockCreated: p => + { + processors.Add(p); + p.WithProcessFile((_, _, _, cancellationToken) => + { + cancellationToken.WaitHandle.WaitOne(); + Thread.Sleep(20); + if (p.Invocations.Any(inv => inv.Method.Name == nameof(IDisposable.Dispose))) + { + disposedDuringProcessing = true; + } + + if (processFileThrows) + { + cancellationToken.ThrowIfCancellationRequested(); + } + }); + + if (processors.Count == executionOptions.ThreadCount.Value) + { + cts.Cancel(); + } + }); + + var sut = CreateSut(processorFactory); + + var run = sut.PrepareNewRun( + ff.GetFolderCompressorParameters(mode, executionOptions, processingOptions), + cts.Token); + + // ACT + Task t = run.Output.ToTask(); + run.Start(); + Func act = () => t; + await act.Should().ThrowAsync(); + + // ASSERT + disposedDuringProcessing.Should().BeFalse(); + processors + .CheckCount(maxCount: executionOptions.ThreadCount.Value) + .CheckDisposed(); + } + + [Theory] + [CorrectValueObjectAutoData] + public async Task WhenNoTemporaryOutputFileCouldBeCreated_ThenProducesExpectedMessages( + CompressionMode mode, + ProcessingOptions processingOptions) + { + // ARRANGE + // this does not work on my local machine with other tested values than 1. + ExecutionOptions executionOptions = new ExecutionOptions(new ThreadCount() { Value = 1 }); + var ff = new FoldersAndFiles( + @"C:\inputDir", + @"C:\outputDir", + true, + @"C:\inputDir\image.czi", + @"C:\outputDir\image.czi~", + @"C:\outputDir\image.czi~1", + @"C:\outputDir\image.czi~2", + @"C:\outputDir\image.czi~3", + @"C:\outputDir\subDir\image.czi~4"); + + var processorFactory = CreateProcessorFactory( + mode, + processingOptions, + onMockCreated: m => { }); + + var sut = CreateSut(processorFactory); + + var run = sut.PrepareNewRun( + ff.GetFolderCompressorParameters(mode, executionOptions, processingOptions), + CancellationToken.None); + + var task = run.Output.ToTask(); + var recorder = new Recorder(); + using var subscription = run.Output + .OfType() + .Subscribe(recorder); + + // ACT + run.Start(); + await task; + + // ASSERT + CompressorMessage.FileFinished GetExpectation(IFileInfo inputInfo) + { + var filename = FoldersAndFiles.ToPlatformPath(@"C:\outputDir\image.czi~3"); + var error = $@"Could not delete existing temporary file {filename}."; + long expectedOutputSize = 0; + + return new CompressorMessage.FileFinished( + inputInfo, + inputInfo.Length, + expectedOutputSize, + null, + error); + } + + var inputFileName = FoldersAndFiles.ToPlatformPath(@"C:\inputDir\image.czi"); + var inputFile = ff!.FileSystem.FileInfo.New(inputFileName); + + var expectation = GetExpectation(inputFile); + + var actualAsStrings = from item in recorder.Data select item.ToString(); + var actualAsStringsWithoutTimeElapsed = actualAsStrings.Select(x => RemoveTimeStamp(x)); + Collection expectationAsStrings = new(); + expectationAsStrings.Add(expectation.ToString()); + + // TODO: debug this, this seems to fail sometimes as the order of files/outputs seems not to be fixed. + actualAsStringsWithoutTimeElapsed.Should().BeEquivalentTo( + expectationAsStrings, + compare => compare.WithoutStrictOrdering()); + } + + [Theory] + [CorrectValueObjectAutoData] + public async Task WhenOneOutputFileExists_ThenProducesExpectedMessages( + CompressionMode mode, + ProcessingOptions processingOptions) + { + // ARRANGE + // this does not work on my local machine with other tested values than 1. + ExecutionOptions executionOptions = new ExecutionOptions(new ThreadCount() { Value = 1 }); + var ff = new FoldersAndFiles( + @"C:\inputDir", + @"C:\outputDir", + @"C:\inputDir\subDir\image.czi", + @"C:\inputDir\subDir\image-3.czi", + @"C:\inputDir\subDir2\image.czi", + @"C:\inputDir\subDir3\image-6.czi", + @"C:\inputDir\subDir4\image-6.czi", + @"C:\outputDir\subDir\image-3.czi"); + + static IOException? GetErrorForFile(string path) => + path.EndsWith("6.czi") ? new IOException("FooBar " + path) : null; + + var processorFactory = CreateProcessorFactory( + mode, + processingOptions, + onMockCreated: m => + { + m.WithProcessFile( + (inputPath, outputPath, _, _) => + { + var ex = GetErrorForFile(inputPath); + if (ex != null) + { + throw ex; + } + + lock (ff.FileSystem) + { + ff.FileSystem.File.AppendAllText( + outputPath, + inputPath + inputPath); + } + }); + m.SetupGet(x => x.NeedsExistingOutputDirectory).Returns(true); + }); + + var sut = CreateSut(processorFactory); + + var run = sut.PrepareNewRun( + ff.GetFolderCompressorParameters(mode, executionOptions, processingOptions), + CancellationToken.None); + + var task = run.Output.ToTask(); + var recorder = new Recorder(); + using var subscription = run.Output + .OfType() + .Subscribe(recorder); + + // ACT + run.Start(); + await task; + + // ASSERT + CompressorMessage.FileFinished GetExpectation(string inputFile) + { + var fileInfo = ff!.FileSystem.FileInfo.New(inputFile); + var error = GetErrorForFile(inputFile)?.Message; + long expectedOutputSize = error == null ? fileInfo.Length * 2 : 0; + + if (inputFile.EndsWith("image-3.czi")) + { + // output file exists + var outputFile = inputFile.Replace(ff.InputDir.FullName, ff.OutputDir.FullName); + error = $"Output file {outputFile} already exists."; + expectedOutputSize = fileInfo.Length + 1; // unchanged from initial file + } + + return new CompressorMessage.FileFinished( + fileInfo, + fileInfo.Length, + expectedOutputSize, + null, + error); + } + + var expectation = from path in ff.InitialFiles + where path.EndsWith(".czi") && path.StartsWith(ff.InputDir.FullName) + select GetExpectation(path); + + var actualAsStrings = from item in recorder.Data select item.ToString(); + var actualAsStringsWithoutTimeElapsed = actualAsStrings.Select(x => RemoveTimeStamp(x)); + var expectationAsStrings = from item in expectation select item.ToString(); + + // TODO: debug this, this seems to fail sometimes as the order of files/outputs seems not to be fixed. + actualAsStringsWithoutTimeElapsed.Should().BeEquivalentTo( + expectationAsStrings, + compare => compare.WithoutStrictOrdering()); + } + + private static string RemoveTimeStamp(string target) + { + const string timeElapsedPattern = $"\\b{nameof(CompressorMessage.FileFinished.TimeElapsed)}[^\\r\\n,]*,"; + const string timeElapsedReplacement = $"{nameof(CompressorMessage.FileFinished.TimeElapsed)} = ,"; + return Regex.Replace(target, timeElapsedPattern, timeElapsedReplacement); + } + + private static async Task WhenRunCompletes_ThenProcessFileHasBeenCalledWithCorrectFileArgsImpl( + CompressionMode mode, + ExecutionOptions executionOptions, + ProcessingOptions processingOptions, + FoldersAndFiles ff, + Action>? configureProcessor = null, + bool forceLazyFileSystemEnumeration = false) + { + // ARRANGE + ConcurrentBag> processors = new(); + var processorFactory = CreateProcessorFactory( + mode, + processingOptions, + onMockCreated: p => + { + processors.Add(p); + configureProcessor?.Invoke(p); + }); + string GetExpectedOutputPath(string f) => f.Replace(ff.InputDir.FullName, ff.OutputDir.FullName); + + MultiThreadedFolderCompressor sut; + if (forceLazyFileSystemEnumeration) + { + sut = new LazyEnumerateCziSut(processorFactory) + { + MatchExtensionCasing = MatchCasing.PlatformDefault, // CaseInsensitive is currently not supported by MockFileSystem + AttributesToSkip = FileAttributes.Hidden | FileAttributes.System, // AttributesToSkip is currently not supported by MockFileSystem + }; + } + else + { + sut = CreateSut(processorFactory); + } + + var run = sut.PrepareNewRun( + ff.GetFolderCompressorParameters(mode, executionOptions, processingOptions), + CancellationToken.None); + + // ACT + Task t = run.Output.ToTask(); + run.Start(); + await t; + + // ASSERT + processors + .CheckCount(maxCount: executionOptions.ThreadCount.Value) + .CheckDisposed(); + + var actualFileNamePairs = + from p in processors + from argsPair in p.GetProcessedFileArgs() + select argsPair; + + var expectedFileNamePairs = + from f in ff.InitialFiles + where f.EndsWith(".czi") && f.StartsWith(ff.InputDir.FullName) + select (f, GetExpectedOutputPath(f) + "~"); + + actualFileNamePairs.Should().BeEquivalentTo( + expectedFileNamePairs, + compare => compare.WithoutStrictOrdering()); + } + + private static MultiThreadedFolderCompressor CreateSut( + CreateProcessor processorFactory, + int maxTriesToCreateTemporaryFiles = 4) + { + var sut = new MultiThreadedFolderCompressor( + processorFactory, + new FileProcessingFailedHandler(), + maxTriesToCreateTemporaryFiles) + { + MatchExtensionCasing = + MatchCasing.PlatformDefault, // CaseInsensitive is currently not supported by MockFileSystem + AttributesToSkip = FileAttributes.System | FileAttributes.Hidden, // AttributesToSkip is not supported by MockFileSystem + }; + return sut; + } + + private static CreateProcessor CreateProcessorFactory( + CompressionMode expectedMode, + ProcessingOptions expectedProcessingOptions, + Action>? onMockCreated = null) + { + // Strict mock behavior checks that we are receiving the correct mode argument. + var createProcessor = new Mock(MockBehavior.Strict); + createProcessor.Setup(x => x.Invoke(expectedMode, expectedProcessingOptions)).Returns( + (_, _) => + { + var p = new Mock().WithProcessFile((_, _, _, c) => c.ThrowIfCancellationRequested()); + + onMockCreated?.Invoke(p); + + return p.Object; + }); + + return createProcessor.Object; + } + + private class FoldersAndFiles + { + public FoldersAndFiles(string inputDir, string outputDir, params string[] files) + : this(inputDir, outputDir, false, files) + { + } + + public FoldersAndFiles(string inputDir, string outputDir, bool allFilesReadonly, params string[] files) + { + this.InitialFiles = files.Select(ToPlatformPath).ToArray(); + this.FileSystem = CreateFileSystem(this.InitialFiles, allFilesReadonly); + this.InputDir = this.FileSystem.DirectoryInfo.New(ToPlatformPath(inputDir)); + this.OutputDir = this.FileSystem.DirectoryInfo.New(ToPlatformPath(outputDir)); + } + + public IFileSystem FileSystem { get; } + + public string[] InitialFiles { get; } + + public IDirectoryInfo InputDir { get; } + + public IDirectoryInfo OutputDir { get; } + + public static string ToPlatformPath(string path) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return path; + } + + var posixPath = path.Replace('\\', '/'); + posixPath = posixPath.Replace(":", string.Empty); + posixPath = "/cygdrive/" + posixPath; + return posixPath; + } + + public FolderCompressorParameters GetFolderCompressorParameters( + CompressionMode mode = CompressionMode.CompressUncompressed, + ExecutionOptions? executionOptions = null, + ProcessingOptions? processingOptions = null, + bool recursive = true) + { + processingOptions ??= new ProcessingOptions(CompressionLevel.Default); + executionOptions ??= new ExecutionOptions(ThreadCount.Default); + return new FolderCompressorParameters( + this.InputDir, + this.OutputDir, + recursive, + mode, + executionOptions, + processingOptions); + } + + private static MockFileSystem CreateFileSystem(string[] files, bool allFilesReadonly = false) + { + var filesDict = files.ToDictionary(f => f, f => new MockFileData(f)); + if (allFilesReadonly) + { + foreach (var file in filesDict.Values) + { + file.Attributes = FileAttributes.ReadOnly; + } + } + + var result = new MockFileSystem(filesDict); + return result; + } + } + + // Overrides EnumerateCzisAsync to first return files and then look into subdirectories. + // This is necessary when we want to test that output files placed into a subdirectory + // of the input directory are skipped. It seems that MockFileSystem collects all files + // immediately (in GetEnumerator() not in MoveNext()). + private class LazyEnumerateCziSut : MultiThreadedFolderCompressor + { + public LazyEnumerateCziSut(CreateProcessor createProcessor) + : base(createProcessor, new FileProcessingFailedHandler()) + { + } + + protected override IAsyncEnumerable EnumerateCzisAsync(IDirectoryInfo folder, bool recursive, CancellationToken token) + { + return recursive + ? LazyEnumerateCzisAsync(folder, token) + : base.EnumerateCzisAsync(folder, false, token); + + async IAsyncEnumerable LazyEnumerateCzisAsync( + IDirectoryInfo folder, + [EnumeratorCancellation] CancellationToken token) + { + await foreach (var item in base.EnumerateCzisAsync(folder, false, token) + .WithCancellation(token)) + { + yield return item; + } + + foreach (var dir in folder.EnumerateDirectories()) + { + await foreach (var item in LazyEnumerateCzisAsync(dir, token) + .WithCancellation(token)) + { + yield return item; + } + } + } + } + } +} diff --git a/czishrink/netczicompressTests/Models/NoOpFileProcessorTests.cs b/czishrink/netczicompressTests/Models/NoOpFileProcessorTests.cs new file mode 100644 index 0000000..91584ef --- /dev/null +++ b/czishrink/netczicompressTests/Models/NoOpFileProcessorTests.cs @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +/// +/// Tests for . +/// +public class NoOpFileProcessorTests +{ + [Fact] + public void NeedsExistingOutputDirectory_ShouldBeFalse() + { + using var target = new NoOpFileProcessor(); + target.NeedsExistingOutputDirectory.Should().BeFalse(); + } + + [Fact] + public void ProcessFile_WhenCalled_ReportsProgress100() + { + // ARRANGE + var fixture = new Fixture().Customize(new AutoMoqCustomization()); + var mock = fixture.Freeze>(); + + var sut = new NoOpFileProcessor(); + + // ACT + sut.ProcessFile( + fixture.Create(), + fixture.Create(), + mock.Object, + fixture.Create()); + + // ASSERT + mock.Verify(x => x.Invoke(100), Times.Once); + mock.VerifyNoOtherCalls(); + } +} diff --git a/czishrink/netczicompressTests/Models/PInvokeFileProcessorTests.cs b/czishrink/netczicompressTests/Models/PInvokeFileProcessorTests.cs new file mode 100644 index 0000000..c89cc99 --- /dev/null +++ b/czishrink/netczicompressTests/Models/PInvokeFileProcessorTests.cs @@ -0,0 +1,163 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Reactive.Disposables; + +/// +/// Tests for . +/// +public class PInvokeFileProcessorTests +{ + [Fact] + public void Ctr_WhenCalledWithNoOp_Throws() + { + Action act = () => _ = new PInvokeFileProcessor(CompressionMode.NoOp, new ProcessingOptions(new CompressionLevel())); + + act.Should().Throw().WithParameterName("mode"); + } + + [Theory] + [InlineData(CompressionMode.CompressUncompressed)] + [InlineData(CompressionMode.CompressAll)] + [InlineData(CompressionMode.CompressUncompressedAndZstd)] + public void CompressAndDecompressOneFile_FilesHaveCorrectSize( + CompressionMode mode) + { + // ARRANGE + var testFile = GetTestFilePath(); + + var compressed = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".czi"); + using var deleteCompressed = DeleteLater(compressed); + + var uncompressed = compressed + "-decompressed.czi"; + using var deleteUncompressed = Disposable.Create(() => File.Delete(uncompressed)); + + // ACT + using var compressor = new PInvokeFileProcessor(mode, new ProcessingOptions(new CompressionLevel())); + compressor.ProcessFile(testFile, compressed, _ => { }, CancellationToken.None); + + using var decompressor = new PInvokeFileProcessor(CompressionMode.Decompress, new ProcessingOptions(new CompressionLevel())); + decompressor.ProcessFile(compressed, uncompressed, _ => { }, CancellationToken.None); + + var compressedSize = GetLength(compressed); + var decompressedSize = GetLength(uncompressed); + var originalSize = GetLength(testFile); + + // ASSERT + compressedSize.Should().Be(58432L); + decompressedSize.Should().BeCloseTo(originalSize, 2048); + decompressedSize.Should().Be(99552L); + } + + [Theory] + [InlineData(CompressionMode.CompressUncompressed)] + [InlineData(CompressionMode.CompressAll)] + [InlineData(CompressionMode.CompressUncompressedAndZstd)] + [InlineData(CompressionMode.Decompress)] + public void NeedsExistingOutputDirectory_ShouldBeTrue( + CompressionMode mode) + { + using var target = new PInvokeFileProcessor(mode, new ProcessingOptions(new CompressionLevel())); + target.NeedsExistingOutputDirectory.Should().BeTrue(); + } + + [Theory] + [InlineData(CompressionMode.CompressUncompressed)] + [InlineData(CompressionMode.CompressAll)] + [InlineData(CompressionMode.CompressUncompressedAndZstd)] + [InlineData(CompressionMode.Decompress)] + public void ProcessFile_WhenCancelled_Throws( + CompressionMode mode) + { + // ARRANGE + string testFile = GetTestFilePath(); + + var compressed = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".czi"); + using var deleteCompressed = DeleteLater(compressed); + + // ACT + using var compressor = PInvokeFileProcessor.Create(mode, new ProcessingOptions(new CompressionLevel())); + var token = new CancellationToken(true); + Action act = () => compressor.ProcessFile(testFile, compressed, _ => { }, token); + + // ASSERT + act.Should().Throw() + .Which + .CancellationToken.Should().Be(token); + } + + [Theory] + [InlineData(CompressionMode.CompressUncompressed)] + [InlineData(CompressionMode.CompressAll)] + [InlineData(CompressionMode.CompressUncompressedAndZstd)] + [InlineData(CompressionMode.Decompress)] + public void ProcessFile_WhenDisposed_Throws( + CompressionMode mode) + { + // ARRANGE + using var compressor = PInvokeFileProcessor.Create(mode, new ProcessingOptions(new CompressionLevel())); + compressor.Dispose(); + + Action act = () => compressor.ProcessFile("foo", "bar", _ => { }, CancellationToken.None); + + // ASSERT + act.Should().Throw(); + } + + [Fact] + public void GetLibFullName_WhenCalled_ReturnsExpected() + { + PInvokeFileProcessor.GetLibFullName().Should().Match("libczicompressc 0.*.*"); + } + + [Theory] + [InlineData(0, 99552L, 57760L)] + [InlineData(2, 99552L, 57920L)] + [InlineData(4, 99552L, 57472L)] + public void CompressWithLevel_FilesHaveCorrectSize( + int compressionLevel, long expectedUncompressedSize, long expectedCompressedSize) + { + // ARRANGE + var testFile = GetTestFilePath(); + + var compressed = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".czi"); + using var deleteCompressed = DeleteLater(compressed); + + var uncompressed = compressed + "-decompressed.czi"; + using var deleteUncompressed = Disposable.Create(() => File.Delete(uncompressed)); + + // ACT + using var compressor = new PInvokeFileProcessor( + CompressionMode.CompressAll, + new ProcessingOptions(new CompressionLevel() + { + Value = compressionLevel, + })); + compressor.ProcessFile(testFile, compressed, _ => { }, CancellationToken.None); + + using var decompressor = new PInvokeFileProcessor(CompressionMode.Decompress, new ProcessingOptions(new CompressionLevel())); + decompressor.ProcessFile(compressed, uncompressed, _ => { }, CancellationToken.None); + + var compressedSize = GetLength(compressed); + var decompressedSize = GetLength(uncompressed); + + // ASSERT + compressedSize.Should().Be(expectedCompressedSize); + decompressedSize.Should().Be(expectedUncompressedSize); + } + + private static long GetLength(string path) => new FileInfo(path).Length; + + private static IDisposable DeleteLater(string path) => Disposable.Create(() => File.Delete(path)); + + private static string GetTestFilePath() + { + var dirname = Path.GetDirectoryName(typeof(PInvokeFileProcessorTests).Assembly.Location); + dirname.Should().NotBeNull(); + var testFile = Path.Combine(dirname ?? ".", "mandelbrot.czi"); + return testFile; + } +} diff --git a/czishrink/netczicompressTests/Models/ProgramNameAndVersionTests.cs b/czishrink/netczicompressTests/Models/ProgramNameAndVersionTests.cs new file mode 100644 index 0000000..1c15d3f --- /dev/null +++ b/czishrink/netczicompressTests/Models/ProgramNameAndVersionTests.cs @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Text.RegularExpressions; + +/// +/// Tests for . +/// +public class ProgramNameAndVersionTests +{ + [Fact] + public void ToString_WhenCalled_ReturnsExpected() + { + // ACT + var actual = new ProgramNameAndVersion().ToString(); + + // ASSERT + var re = new Regex(@"^CZI Shrink 1\.0\.0-alpha\.[1-9]\d\d*(\+\d+)?$"); + re.IsMatch(actual).Should().BeTrue(); + } + + [Fact] + public void Name_WhenCalled_ReturnsExpected() + { + // ACT + var actual = new ProgramNameAndVersion().Name; + + // ASSERT + actual.Should().Be("CZI Shrink"); + } + + [Fact] + public void Version_WhenCalled_ReturnsExpected() + { + // ACT + var actual = new ProgramNameAndVersion().Version; + + // ASSERT + var re = new Regex(@"^1\.0\.0-alpha\.[1-9]\d\d*(\+\d+)?$"); + re.IsMatch(actual).Should().BeTrue(); + } +} diff --git a/czishrink/netczicompressTests/Models/StatisticsRunObserverTests.cs b/czishrink/netczicompressTests/Models/StatisticsRunObserverTests.cs new file mode 100644 index 0000000..223bade --- /dev/null +++ b/czishrink/netczicompressTests/Models/StatisticsRunObserverTests.cs @@ -0,0 +1,109 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Collections.Generic; +using System.Diagnostics; +using System.IO.Abstractions; +using System.Reactive.Subjects; + +using netczicompressTests.Customizations; +using netczicompressTests.Models.Mocks; +using static netczicompress.Models.CompressorMessage; + +/// +/// Tests for . +/// +public class StatisticsRunObserverTests +{ + [Theory] + [InlineData(0)] + [InlineData(1)] + [InlineData(5)] + [InlineData(15)] + public void ObserveRun_WhenRunCompletes_CorrectFirstAndFinalResult(int scanTimeMillis) + { + // ARRANGE + var f = new Fixture().Customize(new AutoMoqCustomization()); + f.Customizations.Add(new ThreadCountSpecimenBuilder()); + var parameters = f.Create(); + + var recorder = new Recorder(); + var fileMock = new Mock(MockBehavior.Strict).Object; + + var data = new FileFinished[] + { + new(fileMock, 20, 10, null, null), + new(fileMock, 20, 10, null, null), + new(fileMock, 20, 10, null, null), + new(fileMock, 20, 10, null, null), + new(fileMock, 20, 10, null, null), + new(fileMock, 500, 400, null, null), + new(fileMock, 10, 1000, null, "Failed"), + new(fileMock, 10, 1000, null, "Failed"), + }; + + using var observable = new Subject(); + var watch = Stopwatch.StartNew(); + + var sut = new StatisticsRunObserver( + recorder, + TimeSpan.FromMilliseconds(scanTimeMillis), + DefaultScheduler.Instance); + + // ACT + sut.ObserveRun(parameters, observable.AsObservable()); + + foreach (var item in data) + { + Thread.Sleep(scanTimeMillis / 2); + observable.OnNext(item); + } + + observable.OnCompleted(); + + var durationUpperLimit = watch.Elapsed + + TimeSpan.FromMilliseconds(2); + + SpinWait.SpinUntil(() => recorder.Completed); + + // ASSERT + recorder.Data.Count.Should().BeInRange(2, data.Length + 1); + AssertMonotonicity(recorder.Data); + + recorder.Data[0].Should().Be(AggregateStatistics.Empty); + + var lastStats = recorder.Data[^1]; + + lastStats.FilesWithErrors.Should().Be(2); + lastStats.FilesWithNoErrors.Should().Be(6); + lastStats.OutputToInputRatio.Should().Be(450.0f / 600); + lastStats.DeltaBytes.Should().Be(450 - 600); + lastStats.InputBytes.Should().Be(600); + lastStats.OutputBytes.Should().Be(450); + lastStats.Duration.Should().BeGreaterThan(TimeSpan.Zero); + lastStats.Duration.Should().BeLessThan(durationUpperLimit); + } + + private static void AssertMonotonicity( + IReadOnlyList data) + { + for (int i = 1; i < data.Count; i++) + { + var current = data[i]; + var previous = data[i - 1]; + + current.FilesWithErrors.Should().BeGreaterThanOrEqualTo( + previous.FilesWithErrors); + current.FilesWithNoErrors.Should().BeGreaterThanOrEqualTo( + previous.FilesWithNoErrors); + current.InputBytes.Should().BeGreaterThanOrEqualTo( + previous.InputBytes); + current.OutputBytes.Should().BeGreaterThanOrEqualTo( + previous.OutputBytes); + current.Duration.Should().BeGreaterThan(previous.Duration); + } + } +} diff --git a/czishrink/netczicompressTests/Models/TemporaryFileTests.cs b/czishrink/netczicompressTests/Models/TemporaryFileTests.cs new file mode 100644 index 0000000..cd384ff --- /dev/null +++ b/czishrink/netczicompressTests/Models/TemporaryFileTests.cs @@ -0,0 +1,239 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; + +/// +/// Tests for . +/// +public class TemporaryFileTests +{ + [Fact] + public void WhenNoOutputFileExist_CreationOfTemporaryOutputDirSucceeds() + { + // ARRANGE + var fileSystem = new MockFileSystem(new Dictionary()); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + + // ASSERT + var expectedOutFileName = fileSystem.Path.GetFullPath("outFile"); + var expectedTempOutFileName = expectedOutFileName + "~"; + sut.GetFullOutFileName().Should().Be(expectedOutFileName); + sut.TemporaryFileCreationFailed.Should().BeFalse(); + sut.Info.FullName.Should().Be(expectedTempOutFileName); + sut.Info.Exists.Should().BeFalse(); + } + + [Fact] + public void WhenNoOutputFileExistAndTemporaryFilesAreWritten_TemporaryFileShouldExistAndOutputFileNotYet() + { + // ARRANGE + var fileSystem = new MockFileSystem(new Dictionary()); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + sut.Info.Create(); // simulates the compression processing + + // ASSERT + sut.GetOutputFile().Exists.Should().BeFalse(); + sut.MoveToOutFileIfExists(); + sut.GetOutputFile().Exists.Should().BeTrue(); + } + + [Fact] + public void WhenNoOutputFileExistAndTemporaryFilesAreWrittenAndMoved_OutFileShouldExistAndTemporaryFileNotMore() + { + // ARRANGE + var fileSystem = new MockFileSystem(new Dictionary()); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + sut.Info.Create(); // simulates the compression processing + sut.MoveToOutFileIfExists(); // simulates the compression processing + + // ASSERT + var expectedTempOutFileName = fileSystem.Path.GetFullPath("outFile") + "~"; + + // the sut's temporary output file will be renamed upon the move, + // so we need to create a new file info from the original file name. + var tempOutFile = fileSystem.FileInfo.New(expectedTempOutFileName); + tempOutFile.Exists.Should().BeFalse(); + sut.DeleteAllOutFiles(); + sut.GetOutputFile().Exists.Should().BeFalse(); + } + + [Fact] + public void WhenOutputFileExistsAndCanBeDeleted_CreationOfTemporaryOutputFileSucceeds() + { + // ARRANGE + var fileSystem = CreateFileSystem(); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + + // ASSERT + var expectedOutFileName = fileSystem.Path.GetFullPath("outFile"); + var expectedTempOutFileName = expectedOutFileName + "~"; + sut.GetFullOutFileName().Should().Be(expectedOutFileName); + sut.TemporaryFileCreationFailed.Should().BeFalse(); + sut.Info.FullName.Should().Be(expectedTempOutFileName); + sut.Info.Exists.Should().BeFalse(); + } + + [Fact] + public void WhenFourTemporaryOutputFileExistAndCannotBeDeleted_CreationOfTemporaryOutputFileSucceeds() + { + // ARRANGE + var fileSystem = CreateFileSystem(readOnlyLevel: 2); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + + // ASSERT + var expectedOutFileName = fileSystem.Path.GetFullPath("outFile"); + var expectedTempOutFileName = expectedOutFileName + "~4"; + sut.GetFullOutFileName().Should().Be(expectedOutFileName); + sut.TemporaryFileCreationFailed.Should().BeFalse(); + sut.Info.FullName.Should().Be(expectedTempOutFileName); + sut.Info.Exists.Should().BeFalse(); + } + + [Fact] + public void WhenFourTemporaryOutputFileExistAndCannotBeDeletedAfterMove_OutputFileShouldExistAndTemporaryFileNoMote() + { + // ARRANGE + var fileSystem = CreateFileSystem(readOnlyLevel: 2); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + sut.Info.Create(); // simulates the compression processing + var tempOutFileName = sut.Info.FullName; + sut.MoveToOutFileIfExists(); + + // ASSERT + sut.GetOutputFile().Exists.Should().BeTrue(); + + // the sut's temporary output file will be renamed upon the move, + // so we need to create a new file info from the original file name. + fileSystem.FileInfo.New(tempOutFileName).Exists.Should().BeFalse(); + } + + [Fact] + public void WhenFourTemporaryOutputFileExistAndTwoCannotBeDeleted_CreationOfTemporaryOutputFileSucceeds() + { + // ARRANGE + var fileSystem = CreateFileSystem(readOnlyLevel: 1); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + + // ASSERT + var expectedOutFileName = fileSystem.Path.GetFullPath("outFile"); + var expectedTempOutFileName = expectedOutFileName + "~2"; + sut.GetFullOutFileName().Should().Be(expectedOutFileName); + sut.TemporaryFileCreationFailed.Should().BeFalse(); + sut.Info.FullName.Should().Be(expectedTempOutFileName); + sut.Info.Exists.Should().BeFalse(); + } + + [Fact] + public void WhenFourTemporaryOutputFileExistAndTwoCannotBeDeletedAfterMove_OutputFileShouldExistAndTemporaryFileNoMote() + { + // ARRANGE + var fileSystem = CreateFileSystem(readOnlyLevel: 1); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile); + sut.Info.Create(); // simulates the compression processing + var tempOutFileName = sut.Info.FullName; + sut.MoveToOutFileIfExists(); + + // ASSERT + sut.GetOutputFile().Exists.Should().BeTrue(); + fileSystem.FileInfo.New(tempOutFileName).Exists.Should().BeFalse(); + } + + [Fact] + public void WhenMaximumTriesToCreateTemporaryFileAreReached_CreationOfTemporaryOutputFileFails() + { + // ARRANGE + var fileSystem = CreateFileSystem(readOnlyLevel: 2); + var outFile = fileSystem.FileInfo.New("outFile"); + + // ACT + var sut = new TemporaryFileOverridenDelete(outFile, 4); + + // ASSERT + sut.TemporaryFileCreationFailed.Should().BeTrue(); + } + + private static MockFileSystem CreateFileSystem(uint readOnlyLevel = 0) + { + // var outFileName = "outFile"; + var tempOutFile = "outFile~"; + var tempOutFile1 = "outFile~1"; + var tempOutFile2 = "outFile~2"; + var tempOutFile3 = "outFile~3"; + + // var outFileMock = new MockFileData("this is the outfile."); + var tempOutFileMock = new MockFileData("this is the temporary outfile."); + var tempOutFileMock1 = new MockFileData("this is the temporary outfile 1."); + var tempOutFileMock2 = new MockFileData("this is the temporary outfile 2."); + var tempOutFileMock3 = new MockFileData("this is the temporary outfile 3."); + + if (readOnlyLevel >= 1) + { + tempOutFileMock.Attributes = FileAttributes.ReadOnly; + tempOutFileMock1.Attributes = FileAttributes.ReadOnly; + } + + if (readOnlyLevel >= 2) + { + tempOutFileMock2.Attributes = FileAttributes.ReadOnly; + tempOutFileMock3.Attributes = FileAttributes.ReadOnly; + } + + var files = new Dictionary + { + { tempOutFile, tempOutFileMock }, + { tempOutFile1, tempOutFileMock1 }, + { tempOutFile2, tempOutFileMock2 }, + { tempOutFile3, tempOutFileMock3 }, + }; + + var result = new MockFileSystem(files); + return result; + } + + private class TemporaryFileOverridenDelete : TemporaryFile + { + public TemporaryFileOverridenDelete(IFileInfo outfile, int maxNumberOfTriesToCreate = 5) + : base(outfile, maxNumberOfTriesToCreate) + { + } + + public IFileInfo GetOutputFile() + { + return this.OutFile; + } + + public string GetFullOutFileName() + { + return this.OutFile.FullName; + } + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Models/ThreadCountTests.cs b/czishrink/netczicompressTests/Models/ThreadCountTests.cs new file mode 100644 index 0000000..bb7466e --- /dev/null +++ b/czishrink/netczicompressTests/Models/ThreadCountTests.cs @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +/// +/// Tests for . +/// +public class ThreadCountTests +{ + [Fact] + public void DefaultConstructor_HasDefaultValue() + { + var sut = new ThreadCount(); + sut.Value.Should().Be(ThreadCount.DefaultValue); + } + + [Theory] + [InlineData(0)] + [InlineData(-100)] + [InlineData(230)] + public void OutOfRange_ShouldThrowOutOfRangeException(int value) + { + var act = () => _ = new ThreadCount { Value = value }; + + act.Should().Throw(); + } + + [Theory] + [InlineData(1)] + public void InRangeValue_ShouldBeEqual(int value) + { + var sut = new ThreadCount() { Value = value }; + sut.Value.Should().Be(value); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/Models/TraceLoggerFactoryTests.cs b/czishrink/netczicompressTests/Models/TraceLoggerFactoryTests.cs new file mode 100644 index 0000000..018b7d6 --- /dev/null +++ b/czishrink/netczicompressTests/Models/TraceLoggerFactoryTests.cs @@ -0,0 +1,182 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.Models; + +using System.Diagnostics; +using System.Text; +using Microsoft.Extensions.Logging; + +/// +/// Tests for . +/// +public sealed class TraceLoggerFactoryTests : IDisposable +{ + private readonly MemoryTraceListener listener = new(); + + public TraceLoggerFactoryTests() + { + Trace.Listeners.Add(this.listener); + this.listener.Reset(); + } + + [Fact] + public void AddProvider_WhenCalled_Throws() + { + // ARRANGE + using ILoggerFactory sut = new TraceLoggerFactory(); + + // ACT + Action act = () => sut.AddProvider(Mock.Of()); + + // ASSERT + act.Should().Throw(); + } + + [Theory] + [InlineData(true, LogLevel.Information, "Information", "INFO")] + [InlineData(false, LogLevel.Information, "Information", "INFO")] + [InlineData(true, LogLevel.Warning, "Warning", "WARN")] + [InlineData(false, LogLevel.Warning, "Warning", "WARN")] + [InlineData(true, LogLevel.Error, "Error", "ERROR")] + [InlineData(false, LogLevel.Error, "Error", "ERROR")] + [InlineData(true, LogLevel.Critical, "Error", "FATAL")] + [InlineData(false, LogLevel.Critical, "Error", "FATAL")] + public void LogHighLevel_WhenCalled_TracesExpected( + bool useLogLevels, + LogLevel level, + string expectedTraceLevel, + string expectedLogLevel) + { + // ARRANGE + using ILoggerFactory sut = new TraceLoggerFactory(useLogLevels); + var logger = sut.CreateLogger(); + + // ACT + DateTimeOffset before = DateTimeOffset.Now; + logger.Log(level, "Bla {eins} {zwei}", 1, 2); + + // ASSERT + var trace = this.listener.ToString(); + if (useLogLevels) + { + trace = CheckAndSkipPrefix(trace, expectedTraceLevel); + } + + CheckLogMessage(trace, before, expectedLogLevel, "Bla 1 2"); + } + + [Theory] + [InlineAutoData(LogLevel.None)] + [InlineAutoData(LogLevel.Debug)] + [InlineAutoData(LogLevel.Trace)] + [InlineAutoData((LogLevel)int.MaxValue)] + public void LogLowLevel_WhenCalled_TracesNothing(LogLevel level, bool useLogLevels) + { + // ARRANGE + using ILoggerFactory sut = new TraceLoggerFactory(useLogLevels); + var logger = sut.CreateLogger(); + + // ACT + logger.Log(level, "Bla {eins} {zwei}", 1, 2); + + // ASSERT + var trace = this.listener.ToString(); + trace.Should().BeEmpty(); + } + + [Theory] + [InlineAutoData(LogLevel.None, false)] + [InlineAutoData(LogLevel.Debug, false)] + [InlineAutoData(LogLevel.Trace, false)] + [InlineAutoData((LogLevel)int.MaxValue, false)] + [InlineAutoData(LogLevel.Information, true)] + [InlineAutoData(LogLevel.Warning, true)] + [InlineAutoData(LogLevel.Error, true)] + [InlineAutoData(LogLevel.Critical, true)] + public void LoggerIsEnabled_WhenCalled_ReturnsExpected(LogLevel level, bool expected, bool useLogLevels) + { + // ARRANGE + using ILoggerFactory sut = new TraceLoggerFactory(useLogLevels); + var logger = sut.CreateLogger(); + + // ACT + var actual = logger.IsEnabled(level); + + // ASSERT + actual.Should().Be(expected); + } + + [Theory] + [AutoData] + public void LoggerBeginScope_WhenCalled_ReturnsNull(bool useLogLevels) + { + // ARRANGE + using ILoggerFactory sut = new TraceLoggerFactory(useLogLevels); + var logger = sut.CreateLogger(); + + // ACT + var actual = logger.BeginScope("bla"); + + // ASSERT + actual.Should().BeNull(); + this.listener.ToString().Should().BeEmpty(); + } + + public void Dispose() + { + Trace.Listeners.Remove(this.listener); + } + + private static string CheckAndSkipPrefix(string trace, string level) + { + // we expect that the trace-text starts with something like " {level}: 0 : ", + // and we want to remove this part from the string + var levelText = $"{level}: 0 : "; + int index = trace.IndexOf(levelText, StringComparison.Ordinal); + index.Should().BePositive(); + trace = trace[(index + levelText.Length)..]; + return trace; + } + + private static void CheckLogMessage(string logLine, DateTimeOffset before, string expectedLevel, string expectedMessage) + { + var traceTokens = logLine.Split('|'); + traceTokens.Length.Should().Be(5); + var loggedDate = DateTimeOffset.Parse(traceTokens[0]); + loggedDate.Should().BeBefore(DateTimeOffset.Now); + loggedDate.Should().BeAfter(before); + traceTokens[1].Should().Be(typeof(TraceLoggerFactoryTests).FullName); + traceTokens[2].Should().Be(expectedLevel); + traceTokens[3].Should().Be("0"); + traceTokens[4].Should().Be(expectedMessage + "\n"); + } + + private class MemoryTraceListener : TraceListener + { + private readonly StringBuilder result = new(); + + public void Reset() + { + Trace.Flush(); + this.result.Clear(); + } + + public override void Write(string? message) + { + this.result.Append(message); + } + + public override void WriteLine(string? message) + { + this.result.Append(message).Append('\n'); + } + + public override string ToString() + { + Trace.Flush(); + return this.result.ToString(); + } + } +} diff --git a/czishrink/netczicompressTests/Usings.cs b/czishrink/netczicompressTests/Usings.cs new file mode 100644 index 0000000..8befff0 --- /dev/null +++ b/czishrink/netczicompressTests/Usings.cs @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma warning disable SA1200 // Using directives should be placed correctly + +global using System; +global using System.Collections.Generic; +global using System.Reactive.Concurrency; +global using System.Reactive.Linq; + +global using AutoFixture; +global using AutoFixture.AutoMoq; +global using AutoFixture.Xunit2; + +global using FluentAssertions; + +global using Moq; + +global using netczicompress.Models; + +global using Xunit; \ No newline at end of file diff --git a/czishrink/netczicompressTests/ViewModels/AboutViewModelTests.cs b/czishrink/netczicompressTests/ViewModels/AboutViewModelTests.cs new file mode 100644 index 0000000..48105f0 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/AboutViewModelTests.cs @@ -0,0 +1,114 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +public class AboutViewModelTests +{ + [Fact] + public void AfterConstruction_HasExpectedProperties() + { + // ARRANGE + IFixture fixture = CreateFixture(); + var launcher = fixture.Create(); + var versionInfo = fixture.Create>(); + var libname = fixture.Create(); + versionInfo.Setup(x => x.ToString()).Returns("FooBar 99.3.7"); + + // ACT + var sut = new AboutViewModel(launcher, versionInfo.Object) { LibraryName = libname }; + + // ASSERT + sut.IsVisible.Should().BeFalse(); + sut.LibraryName.Should().BeSameAs(libname); + sut.ProgramVersionAndCopyRight.Should().Be("FooBar 99.3.7, © 2023 Carl Zeiss Microscopy GmbH and others"); + } + + [Theory] + [AutoData] + public void IsVisible_WhenSet_RaisesEvent(bool initialValue) + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + sut.IsVisible = initialValue; + using var monitor = sut.Monitor(); + + // ACT + sut.IsVisible = !initialValue; + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.IsVisible); + sut.IsVisible.Should().Be(!initialValue); + } + + [Fact] + public void ShowAboutCommand_WhenNotVisible_SetsVisibleToTrue() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + sut.IsVisible = false; + using var monitor = sut.Monitor(); + + // ACT + sut.ShowAboutCommand.CanExecute(null).Should().BeTrue(); + sut.ShowAboutCommand.Execute(null); + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.IsVisible); + sut.IsVisible.Should().BeTrue(); + } + + [Fact] + public void CloseAboutCommand_WhenVisible_SetsVisibleToFalse() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + sut.IsVisible = true; + using var monitor = sut.Monitor(); + + // ACT + sut.CloseAboutCommand.CanExecute(null).Should().BeTrue(); + sut.CloseAboutCommand.Execute(null); + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.IsVisible); + sut.IsVisible.Should().BeFalse(); + } + + [Fact] + public void ShowTextFileCommand_WhenCalled_LaunchesFileFromBaseDirectory() + { + // ARRANGE + IFixture fixture = CreateFixture(); + var launcherMock = fixture.Freeze>(); + + var sut = fixture.Create(); + const string file = "foobar.ext"; + + // ACT + sut.ShowTextFileCommand.CanExecute(file).Should().BeTrue(); + sut.ShowTextFileCommand.Execute(file); + + // ASSERT + var expectedFileName = System.IO.Path.Combine(AppContext.BaseDirectory, file); + launcherMock.Verify(x => x.Launch(expectedFileName), Times.Once); + } + + private static IFixture CreateFixture() + { + // ARRANGE + return new Fixture().Customize(new AutoMoqCustomization()); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/AggregateIndicationViewModelTests.cs b/czishrink/netczicompressTests/ViewModels/AggregateIndicationViewModelTests.cs new file mode 100644 index 0000000..69d567f --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/AggregateIndicationViewModelTests.cs @@ -0,0 +1,106 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +public class AggregateIndicationViewModelTests +{ + [Fact] + public void Properties_AfterCreation_HaveExpectedValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + // ACT + var sut = fixture.Create(); + + // ASSERT + sut.IndicationStatus.Should().Be(AggregateIndicationStatus.NotStarted); + } + + [Fact] + public void OnNext_WhenCalled_ChangesPropertyValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + var newValue = fixture.Create(); + using var monitor = sut.Monitor(); + + // ACT + sut.OnNext(newValue); + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.IndicationStatus); + sut.IndicationStatus.Should().Be(AggregateIndicationStatus.Started); + } + + [Theory] + [InlineData(0, AggregateIndicationStatus.Success)] + [InlineData(-1, AggregateIndicationStatus.Success)] + [InlineData(int.MinValue, AggregateIndicationStatus.Success)] + [InlineData(1, AggregateIndicationStatus.Error)] + [InlineData(100, AggregateIndicationStatus.Error)] + [InlineData(int.MaxValue, AggregateIndicationStatus.Error)] + public void OnCompleted_WhenCalled_ChangesIndicationStatus(int filesWithErrors, AggregateIndicationStatus expectation) + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + var newValue = fixture.Create(); + newValue = newValue with { FilesWithErrors = filesWithErrors }; + sut.OnNext(newValue); + using var monitor = sut.Monitor(); + + // ACT + sut.OnCompleted(); + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.IndicationStatus); + sut.IndicationStatus.Should().Be(expectation); + } + + [Fact] + public void OnError_WhenExceptionIsOperationCancelledException_ChangesStatusToCancelled() + { + OnError_WhenExceptionIsOfType_ChangesStatusTo(AggregateIndicationStatus.Cancelled); + } + + [Fact] + public void OnError_WhenExceptionIsNotOperationCancelledException_ChangesStatusToError() + { + OnError_WhenExceptionIsOfType_ChangesStatusTo( + AggregateIndicationStatus.Error); + } + + private static void OnError_WhenExceptionIsOfType_ChangesStatusTo(AggregateIndicationStatus expectation) + where T : Exception + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + using var monitor = sut.Monitor(); + + // ACT + sut.OnError(Mock.Of()); + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.IndicationStatus); + sut.IndicationStatus.Should().Be(expectation); + } + + private static IFixture CreateFixture() + { + // ARRANGE + return new Fixture().Customize(new AutoMoqCustomization()); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/AggregateStatisticsViewModelTests.cs b/czishrink/netczicompressTests/ViewModels/AggregateStatisticsViewModelTests.cs new file mode 100644 index 0000000..07a659e --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/AggregateStatisticsViewModelTests.cs @@ -0,0 +1,102 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.ComponentModel; + +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +public class AggregateStatisticsViewModelTests +{ + [Fact] + public void Properties_AfterCreation_HaveExpectedValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + // ACT + var sut = fixture.Create(); + + // ASSERT + sut.Should().BeEquivalentTo(AggregateStatistics.Empty); + } + + [Fact] + public void OnNext_WhenCalled_ChangesPropertyValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + var newValue = fixture.Create(); + var propertyListener = new Mock(); + sut.PropertyChanged += propertyListener.Object; + + // ACT + sut.OnNext(newValue); + + // ASSERT + propertyListener.Verify( + x => x.Invoke( + sut, + It.Is(e => e.PropertyName == string.Empty)), + Times.Once); + propertyListener.VerifyNoOtherCalls(); + + sut.Should().BeEquivalentTo(newValue); + } + + [Fact] + public void OnCompleted_WhenCalled_DoesNotDoAnything() + { + WhenCalled_DoesNotDoAnything((sut, _) => sut.OnCompleted()); + } + + [Fact] + public void OnError_WhenCalled_DoesNotDoAnything() + { + WhenCalled_DoesNotDoAnything((sut, fixture) => sut.OnError(fixture.Create())); + } + + [Fact] + public void AggregateIndicationViewModel_WhenGot_IsInjectedInstance() + { + // ARRANGE + IFixture fixture = CreateFixture(); + var injected = fixture.Freeze(); + + // ACT + var sut = fixture.Create(); + + // ASSERT + sut.AggregateIndicationViewModel.Should().BeSameAs(injected); + } + + private static void WhenCalled_DoesNotDoAnything(Action, IFixture> act) + { + // ARRANGE + IFixture fixture = CreateFixture(); + var oldValue = fixture.Create(); + var sut = fixture.Create(); + sut.OnNext(oldValue); + + // ACT + using var monitor = sut.Monitor(); + act(sut, fixture); + + // ASSERT + monitor.OccurredEvents.Should().BeEmpty(); + sut.Should().BeEquivalentTo(oldValue); + } + + private static IFixture CreateFixture() + { + // ARRANGE + return new Fixture().Customize(new AutoMoqCustomization()); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/CompressionTaskViewModelTests.cs b/czishrink/netczicompressTests/ViewModels/CompressionTaskViewModelTests.cs new file mode 100644 index 0000000..24bb369 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/CompressionTaskViewModelTests.cs @@ -0,0 +1,81 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.Reactive.Subjects; + +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +/// +/// Note that +/// is tested via . +/// +public class CompressionTaskViewModelTests +{ + [Fact] + public void PublicProperties_WhenGot_HaveExpectedValues() + { + // ARRANGE + var fileName = CreateFixture().Create(); + using var progress = new BehaviorSubject(0); + var sut = new CompressionTaskViewModel( + fileName, + progress); + + List<(int Progress, (string FileName, int ProgressPercent, bool IsIndeterminateProgress, bool IsCompleted, string ChangedProps))> data = new(); + var changedProperties = new List(); + sut.PropertyChanged += (s, e) => changedProperties.Add(e.PropertyName); + + void Collect(int p) + { + changedProperties.Clear(); + progress.OnNext(p); + changedProperties.Sort(); + data.Add( + (p, + (sut.FileName, + sut.ProgressPercent, + sut.IsIndeterminateProgress, + sut.IsCompleted, + string.Join(",", changedProperties)))); + } + + // ACT + Collect(0); + Collect(1); + Collect(2); + Collect(2); + Collect(10); + Collect(50); + Collect(99); + Collect(100); + + // ASSERT + const string ProgressPercent = nameof(sut.ProgressPercent); + const string IsIndeterminateProgress = nameof(sut.IsIndeterminateProgress); + const string IsCompleted = nameof(sut.IsCompleted); + static string Cat(params string[] args) => string.Join(",", args); + data.Should().BeEquivalentTo( + new[] + { + (0, (fileName, 0, true, false, string.Empty)), + (1, (fileName, 1, true, false, ProgressPercent)), + (2, (fileName, 2, false, false, Cat(IsIndeterminateProgress, ProgressPercent))), + (2, (fileName, 2, false, false, string.Empty)), + (10, (fileName, 10, false, false, ProgressPercent)), + (50, (fileName, 50, false, false, ProgressPercent)), + (99, (fileName, 99, false, false, ProgressPercent)), + (100, (fileName, 100, false, true, Cat(IsCompleted, ProgressPercent))), + }); + } + + private static IFixture CreateFixture() + { + return new Fixture().Customize(new AutoMoqCustomization()); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToAnimationConverterTests.cs b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToAnimationConverterTests.cs new file mode 100644 index 0000000..0b2afbe --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToAnimationConverterTests.cs @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels.Converters; + +using System.Globalization; + +using netczicompress.ViewModels; +using netczicompress.ViewModels.Converters; + +using Projektanker.Icons.Avalonia; + +/// +/// Tests for . +/// +public class AggregateStatusToAnimationConverterTests +{ + [Theory] + [InlineData(AggregateIndicationStatus.Started, IconAnimation.Spin)] + [InlineData(AggregateIndicationStatus.Cancelled, IconAnimation.None)] + [InlineData(AggregateIndicationStatus.NotStarted, IconAnimation.None)] + [InlineData(AggregateIndicationStatus.Error, IconAnimation.None)] + [InlineData(AggregateIndicationStatus.Success, IconAnimation.None)] + public void ConversionWorks(AggregateIndicationStatus status, IconAnimation expected) + { + var converter = new AggregateStatusToAnimationConverter(); + var result = converter.Convert(status, typeof(IconAnimation), null, CultureInfo.CurrentCulture); + result.Should().Be(expected); + } + + [Fact] + public void BackConversion_Throws() + { + var converter = new AggregateStatusToAnimationConverter(); + Action act = () => converter.ConvertBack(null, typeof(void), null, CultureInfo.CurrentCulture); + act.Should().Throw(); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToForegroundConverterTests.cs b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToForegroundConverterTests.cs new file mode 100644 index 0000000..45c4dee --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToForegroundConverterTests.cs @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels.Converters; + +using System.Globalization; + +using Avalonia.Media; + +using netczicompress.ViewModels; +using netczicompress.ViewModels.Converters; + +using Projektanker.Icons.Avalonia; + +/// +/// Tests for . +/// +public class AggregateStatusToForegroundConverterTests +{ + public static IEnumerable DataWithStatusInput => + new List + { + new object[] { AggregateIndicationStatus.NotStarted, Colors.Black }, + new object[] { AggregateIndicationStatus.Started, Colors.CadetBlue }, + new object[] { AggregateIndicationStatus.Success, Colors.Green }, + new object[] { AggregateIndicationStatus.Error, Colors.Red }, + new object[] { AggregateIndicationStatus.Cancelled, Colors.LightGray }, + }; + + public static IEnumerable DataWithOtherInput => + new List + { + new object[] { 999, Colors.Red }, + new object[] { true, Colors.Red }, + new object[] { new(), Colors.Red }, + }; + + [Theory] + [MemberData(nameof(DataWithStatusInput))] + public void ForStatusInput_ConversionWorks(AggregateIndicationStatus status, Color expected) + { + var converter = new AggregateStatusToForegroundConverter(); + var result = converter.Convert(status, typeof(IconAnimation), null, CultureInfo.CurrentCulture); + IImmutableSolidColorBrush? brush = result as IImmutableSolidColorBrush; + brush.Should().NotBeNull(); + brush?.Color.Should().Be(expected); + } + + [Theory] + [MemberData(nameof(DataWithOtherInput))] + public void ForArbitraryInput_ConversionWorks(object status, Color expected) + { + var converter = new AggregateStatusToForegroundConverter(); + var result = converter.Convert(status, typeof(IconAnimation), null, CultureInfo.CurrentCulture); + IImmutableSolidColorBrush? brush = result as IImmutableSolidColorBrush; + brush.Should().NotBeNull(); + brush?.Color.Should().Be(expected); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToIconConverterTests.cs b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToIconConverterTests.cs new file mode 100644 index 0000000..2c0dbe2 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToIconConverterTests.cs @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels.Converters; + +using System.Globalization; +using netczicompress.ViewModels; +using netczicompress.ViewModels.Converters; +using Projektanker.Icons.Avalonia; + +/// +/// Tests for . +/// +public class AggregateStatusToIconConverterTests +{ + [Theory] + [InlineData(AggregateIndicationStatus.Started, "fa-sync")] + [InlineData(AggregateIndicationStatus.Cancelled, "fa-solid fa-circle-info")] + [InlineData(AggregateIndicationStatus.NotStarted, "fa-solid fa-circle-info")] + [InlineData(AggregateIndicationStatus.Error, "fa-solid fa-circle-info")] + [InlineData(AggregateIndicationStatus.Success, "fa-solid fa-circle-info")] + public void ConversionWorks(AggregateIndicationStatus status, string expected) + { + var converter = new AggregateStatusToIconConverter(); + var result = converter.Convert(status, typeof(IconAnimation), null, CultureInfo.CurrentCulture); + result.Should().Be(expected); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToTextConverterTests.cs b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToTextConverterTests.cs new file mode 100644 index 0000000..8556c85 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/Converters/AggregateStatusToTextConverterTests.cs @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels.Converters; + +using System.Globalization; +using netczicompress.ViewModels; +using netczicompress.ViewModels.Converters; +using Projektanker.Icons.Avalonia; + +/// +/// Tests for . +/// +public class AggregateStatusToTextConverterTests +{ + [Theory] + [InlineData(AggregateIndicationStatus.NotStarted, "Compression not started")] + [InlineData(AggregateIndicationStatus.Started, "Compression in progress")] + [InlineData(AggregateIndicationStatus.Success, "Compression succeeded")] + [InlineData(AggregateIndicationStatus.Error, "Compression had errors")] + [InlineData(AggregateIndicationStatus.Cancelled, "Compression was cancelled")] + public void ConversionWorks_ForStatusInput(AggregateIndicationStatus status, string expected) + { + var converter = new AggregateStatusToTextConverter(); + var result = converter.Convert(status, typeof(IconAnimation), null, CultureInfo.CurrentCulture); + result.Should().Be(expected); + } + + [Theory] + [InlineData(7)] + [InlineData(true)] + [InlineData("nonsense")] + public void ConversionReturnsEmptyString_ForOtherInput(object input) + { + var converter = new AggregateStatusToTextConverter(); + var result = converter.Convert(input, typeof(IconAnimation), null, CultureInfo.CurrentCulture); + result.Should().Be(string.Empty); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/ViewModels/Converters/BytesToStringConverterTests.cs b/czishrink/netczicompressTests/ViewModels/Converters/BytesToStringConverterTests.cs new file mode 100644 index 0000000..cd55cb9 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/Converters/BytesToStringConverterTests.cs @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels.Converters; + +using System.Globalization; +using netczicompress.ViewModels.Converters; +using Projektanker.Icons.Avalonia; + +/// +/// Tests for . +/// +public class BytesToStringConverterTests +{ + [Theory] + [InlineData(0, "0 bytes")] + [InlineData(1000, "1.00 kB")] + [InlineData(1234, "1.23 kB")] + [InlineData(2345, "2.35 kB")] + [InlineData(1e6, "1.00 MB")] + [InlineData(1e9, "1.00 GB")] + [InlineData(1e12, "1.00 TB")] + [InlineData(1e15, "1.00 PB")] + [InlineData(1e18, "1.00 EB")] + public void ConversionWorksWithLong(long byteCount, string expected) + { + var converter = new BytesToStringConverter(); + var result = converter.Convert(byteCount, typeof(IconAnimation), null, CultureInfo.InvariantCulture); + result.Should().Be(expected); + } + + [Theory] + [InlineData(0, "0 bytes")] + [InlineData(1000, "1.00 kB")] + [InlineData(1234, "1.23 kB")] + [InlineData(2345, "2.35 kB")] + [InlineData(1e6, "1.00 MB")] + [InlineData(1e9, "1.00 GB")] + public void ConversionWorksWithInt(int byteCount, string expected) + { + var converter = new BytesToStringConverter(); + var result = converter.Convert(byteCount, typeof(IconAnimation), null, CultureInfo.InvariantCulture); + result.Should().Be(expected); + } + + [Theory] + [InlineData(1e6, 0)] + [InlineData(true, 0)] + [InlineData(null, 0)] + public void ConversionWithArbitraryInput_Returns0(object byteCount, object expected) + { + var converter = new BytesToStringConverter(); + var result = converter.Convert(byteCount, typeof(IconAnimation), null, CultureInfo.InvariantCulture); + result.Should().Be(expected); + } +} \ No newline at end of file diff --git a/czishrink/netczicompressTests/ViewModels/Converters/FloatToCompressionRatioStringConverterTests.cs b/czishrink/netczicompressTests/ViewModels/Converters/FloatToCompressionRatioStringConverterTests.cs new file mode 100644 index 0000000..f4b4a87 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/Converters/FloatToCompressionRatioStringConverterTests.cs @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels.Converters; + +using System.Globalization; +using netczicompress.ViewModels.Converters; + +/// +/// Tests for . +/// +public class FloatToCompressionRatioStringConverterTests +{ + [Theory] + [InlineData(0, "0.000")] + [InlineData(1.23f, "1.230")] + [InlineData(float.NaN, "")] + public void CheckConversionWorksWithFloats(float value, string expected) + { + var converter = new FloatToCompressionRatioStringConverter(); + var result = converter.Convert(value, typeof(float), null, CultureInfo.InvariantCulture); + result.Should().Be(expected); + } + + [Theory] + [InlineData(0, "0.000")] + [InlineData(1.23, "1.230")] + [InlineData(double.NaN, "")] + public void CheckConversionWorksWithDoubles(double value, string expected) + { + var converter = new FloatToCompressionRatioStringConverter(); + var result = converter.Convert(value, typeof(double), null, CultureInfo.InvariantCulture); + result.Should().Be(expected); + } + + [Theory] + [InlineData("foo")] + [InlineData(null)] + [InlineData(typeof(string))] + public void Convert_WhenCalledOnSomethingThatIsNeitherFloatNorDouble_ReturnsEmptyString(object value) + { + var converter = new FloatToCompressionRatioStringConverter(); + var result = converter.Convert(value, typeof(double), null, CultureInfo.InvariantCulture); + result.Should().Be(string.Empty); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/CurrentTasksViewModelTests.cs b/czishrink/netczicompressTests/ViewModels/CurrentTasksViewModelTests.cs new file mode 100644 index 0000000..424e005 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/CurrentTasksViewModelTests.cs @@ -0,0 +1,127 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.Diagnostics; +using System.IO.Abstractions; +using System.Reactive.Subjects; + +using netczicompress.ViewModels; + +using netczicompressTests.Models.Mocks; + +using static netczicompress.Models.CompressorMessage; + +/// +/// Tests for . +/// +public class CurrentTasksViewModelTests +{ + [Fact] + public void OnNext_WhenTaskNotFinished_AddsTaskToList() + { + // ARRANGE + var sut = new CurrentTasksViewModel(ImmediateScheduler.Instance); + + for (int i = 0; i < 10; i++) + { + var message = CreateFixture().Create(); + + // ACT + sut.OnNext(message); + + // ASSERT + sut.CompressionTasks.Count().Should().Be(i + 1); + sut.CompressionTasks[i].FileName.Should().Be(message.InputFile.FullName); + } + } + + [Fact] + public void OnNext_WhenTaskFinished_DoesNotAddTaskToList() + { + // ARRANGE + var sut = new CurrentTasksViewModel(ImmediateScheduler.Instance); + + using var progress = new BehaviorSubject(100); + var message = new FileStarting(Mock.Of(), progress); + + // ACT + sut.OnNext(message); + + // ASSERT + sut.CompressionTasks.Should().BeEmpty(); + } + + [Fact] + public void OnCompleted_WhenCalled_ClearsTaskList() + { + // ARRANGE + var sut = new CurrentTasksViewModel(ImmediateScheduler.Instance); + + sut.OnNextAll(CreateFixture().CreateMany(10)); + Debug.Assert(sut.CompressionTasks.Count == 10, "Error in ARRANGE"); + + // ACT + sut.OnCompleted(); + + // ASSERT + sut.CompressionTasks.Should().BeEmpty(); + } + + [Fact] + public void OnError_WhenCalled_ClearsTaskList() + { + // ARRANGE + var sut = new CurrentTasksViewModel(ImmediateScheduler.Instance); + + sut.OnNextAll(CreateFixture().CreateMany(10)); + Debug.Assert(sut.CompressionTasks.Count == 10, "Error in ARRANGE"); + + // ACT + sut.OnError(new Exception()); + + // ASSERT + sut.CompressionTasks.Should().BeEmpty(); + } + + [Fact] + public void WhenTaskCompletes_TaskIsRemovedFromListOnGuiScheduler() + { + // ARRANGE + var guiScheduler = new SchedulerMock(); + var sut = new CurrentTasksViewModel(guiScheduler); + + sut.OnNextAll(CreateFixture().CreateMany(5)); + using var progress = new BehaviorSubject(0); + var completingTask = new FileStarting( + Mock.Of(f => f.FullName == "Foo_Bar_Baz"), + progress); + sut.OnNext(completingTask); + sut.OnNextAll(CreateFixture().CreateMany(5)); + + var taskViewModel = sut.CompressionTasks[5]; + var initialTasks = sut.CompressionTasks.ToArray(); + Debug.Assert(initialTasks.Length == 11, "Error in ARRANGE"); + Debug.Assert(taskViewModel.FileName == "Foo_Bar_Baz", "Error in ARRANGE"); + + // ACT + progress.OnNext(100); + var beforeSchedulerRun = sut.CompressionTasks.ToArray(); + guiScheduler.RunQueuedActions(); + var afterSchedulerRun = sut.CompressionTasks.ToArray(); + + // ASSERT + beforeSchedulerRun.Should().HaveCount(11); + beforeSchedulerRun.SequenceEqual(initialTasks).Should().BeTrue(); + + afterSchedulerRun.Should().HaveCount(10); + afterSchedulerRun.SequenceEqual(initialTasks.Where(t => !object.ReferenceEquals(t, taskViewModel))).Should().BeTrue(); + } + + private static IFixture CreateFixture() + { + return new Fixture().Customize(new AutoMoqCustomization()); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/ErrorItemTests.cs b/czishrink/netczicompressTests/ViewModels/ErrorItemTests.cs new file mode 100644 index 0000000..d0f8e18 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/ErrorItemTests.cs @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.ComponentModel; +using System.Reflection; +using System.Runtime.CompilerServices; + +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +public class ErrorItemTests +{ + /// + /// Tests that is indeed immutable. + /// + [Fact] + public void WritableProperties_AreInitOnly() + { + var writablePropertySetters = from p in WritableProperties() + select p.SetMethod; + + foreach (var setMethod in writablePropertySetters) + { + // Get the modifiers applied to the return parameter. + var setMethodReturnParameterModifiers = setMethod!.ReturnParameter.GetRequiredCustomModifiers(); + + // Init-only properties are marked with the IsExternalInit type. + bool isInitOnly = setMethodReturnParameterModifiers.Any(x => + x.FullName == + "System.Runtime.CompilerServices.IsExternalInit"); + + isInitOnly.Should().BeTrue(); + } + } + + /// + /// Tests that is indeed immutable. + /// + [Fact] + public void WritableProperties_AreRequired() + { + foreach (var property in WritableProperties()) + { + property.GetCustomAttributes(false).OfType().Should().NotBeEmpty(); + } + } + + [Fact] + public void ImplementsINotifyPropertyChanged() + { + INotifyPropertyChanged sut = new ErrorItem { File = "foo", ErrorMessage = "bar" }; + var handler = new Mock(MockBehavior.Strict).Object; + + sut.PropertyChanged += handler; + sut.ToString().Should().Be("foo : bar"); + sut.PropertyChanged -= handler; + } + + private static IEnumerable WritableProperties() + { + return typeof(ErrorItem).GetProperties().Where(p => p.CanWrite); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/ErrorListViewModelTests.cs b/czishrink/netczicompressTests/ViewModels/ErrorListViewModelTests.cs new file mode 100644 index 0000000..7a7dbec --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/ErrorListViewModelTests.cs @@ -0,0 +1,446 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.Collections; +using System.Collections.Specialized; +using System.Diagnostics; +using System.IO.Abstractions; +using System.Windows.Input; + +using netczicompress.Models; +using netczicompress.ViewModels; +using netczicompressTests.Customizations; +using netczicompressTests.Models.Mocks; +using ReactiveUI; +using static netczicompress.Models.CompressorMessage; + +/// +/// Tests for . +/// +public class ErrorListViewModelTests +{ + [Fact] + public void SelectedErrorItem_WhenSet_RaisesPropertyChanged() + { + var sut = CreateSut(); + var fixture = new Fixture(); + + using (var m = sut.Monitor()) + { + sut.SelectedErrorItem = fixture.Create(); + m.Should().RaisePropertyChangeFor(x => x.SelectedErrorItem); + } + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(5)] + [InlineData(7)] + [InlineData(20)] + [InlineData(100)] + public void ObserveRun_WhenItemsAddedBelowBulkAddThreshold_PerformsSingleAdds(int bufferCap) + { + // ARRANGE + const int MaxItemsToShow = 10; + ErrorListViewModel sut = CreateSut(bufferCap, MaxItemsToShow); + Debug.Assert( + sut.BulkAddThreshold > Math.Min(bufferCap, MaxItemsToShow), + "ItemsAddedBelowResetThreshold"); + + var errorListChangesRecorder = ObserveErrorListChanges(sut).StartRecording(); + IFixture fixture = CreateFixture(); + var input = GenerateMessages(fixture).Take(54).ToArray(); + var run = input.ToObservableAction(); + + // ACT + sut.ObserveRun( + fixture.Create(), + run.Output); + run.Start(); + + // ASSERT + // Number of changes: 1 Reset + 1 Add per Item + 1 Add of Truncation Notice + // Changes + var expectedChanges = GetExpectedErrorListChangesForSingleAdds(input, MaxItemsToShow); + errorListChangesRecorder.Data.Count.Should().Be(expectedChanges.Length); + errorListChangesRecorder.Data.Should().BeEquivalentTo(expectedChanges); + + // Final state + sut.Errors.Should().BeEquivalentTo(expectedChanges[^1].SnapShot); + } + + [Fact] + public void ObserveRun_WhenItemsAddedExceedBulkAddThreshold_PerformsBulkAdd() + { + // ARRANGE + const int MaxItemsToShow = 30; + const int BufferCapacity = 30; + ErrorListViewModel sut = CreateSut(BufferCapacity, MaxItemsToShow); + Debug.Assert( + sut.BulkAddThreshold < Math.Min(MaxItemsToShow, BufferCapacity), + "ItemsAddedExceedResetThreshold"); + + var errorListChangesRecorder = ObserveErrorListChanges(sut).StartRecording(); + var fixture = CreateFixture(); + var input = GenerateMessages(fixture).Take(61).ToArray(); + var run = input.ToObservableAction(); + + // ACT + sut.ObserveRun( + fixture.Create(), + run.Output); + run.Start(); + + // ASSERT + // Changes + var expectedRealErrorItems = GetExpectedErrorItems(input).Take(MaxItemsToShow).ToArray(); + var expectedErrorItems = expectedRealErrorItems.Append(GetExpectedTruncationItem()).ToArray(); + var expectation = new[] + { + (Array.Empty(), "Reset"), + (expectedRealErrorItems, "Reset"), + GetExpectedAddLastChange(expectedErrorItems), + }; + + errorListChangesRecorder.Data.Count.Should().Be(expectation.Length); + errorListChangesRecorder.Data.Should().BeEquivalentTo(expectation); + + // Final state + sut.Errors.Should().BeEquivalentTo(expectedErrorItems); + sut.SelectedErrorItem.Should().BeEquivalentTo(expectedRealErrorItems[^1]); + } + + [Theory] + [InlineData(0.2)] + [InlineData(0.5)] + [InlineData(1)] + [InlineData(5)] + public void ObserveRun_WhenRunIsErrored_HasCorrectFinalState(double bufferTimeMillis) + { + // ARRANGE + ErrorListViewModel sut = CreateSut( + bufferCap: 30, + maxItemsToShow: int.MaxValue, + bufferTimeout: TimeSpan.FromMilliseconds(bufferTimeMillis), + scheduler: ImmediateScheduler.Instance); + + var fixture = CreateFixture(); + var input = GenerateMessages(fixture).Take(125).ToArray(); + var observableMock = new Mock>(); + IObserver? subscriber = null; + observableMock + .Setup(x => x.Subscribe(It.IsAny>())) + .Callback>(obs => subscriber = obs); + + // ACT + sut.ObserveRun( + fixture.Create(), + observableMock.Object); + subscriber?.OnNextAll(input); + subscriber?.OnError(new Exception()); + + // ASSERT + var expectedErrorItems = GetExpectedErrorItems(input).ToArray(); + sut.Errors.Should().BeEquivalentTo(expectedErrorItems); + sut.SelectedErrorItem.Should().BeEquivalentTo(expectedErrorItems[^1]); + } + + [Theory] + [InlineData(0.2)] + [InlineData(0.5)] + [InlineData(1)] + [InlineData(5)] + public void ObserveRun_WhenSchedulerIsSlow_HasCorrectFinalState(double bufferTimeMillis) + { + // ARRANGE + var scheduler = new SchedulerMock(); + ErrorListViewModel sut = CreateSut( + bufferCap: 30, + maxItemsToShow: int.MaxValue, + bufferTimeout: TimeSpan.FromMilliseconds(bufferTimeMillis), + scheduler: scheduler); + + var fixture = CreateFixture(); + var input = GenerateMessages(fixture).Take(125).ToArray(); + var run = input.ToObservableAction(); + + // ACT + sut.ObserveRun( + fixture.Create(), + run.Output); + run.Start(); + + scheduler.RunQueuedActions(); + + // ASSERT + var expectedErrorItems = GetExpectedErrorItems(input).ToArray(); + sut.Errors.Should().BeEquivalentTo(expectedErrorItems); + sut.SelectedErrorItem.Should().BeEquivalentTo(expectedErrorItems[^1]); + } + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(5)] + [InlineData(10)] + [InlineData(20)] + [InlineData(100)] + public void ObserveRun_AsItemsAreDelivered_SelectsLastRealItem(int bufferCap) + { + // ARRANGE + const int MaxItemsToShow = 10; + ErrorListViewModel sut = CreateSut(bufferCap, MaxItemsToShow); + + var recorder = ObserveSelectedItemChanges(sut).StartRecording(); + var fixture = CreateFixture(); + var input = GenerateMessages(fixture, 54).ToArray(); + var run = input.ToObservableAction(); + + // ACT + sut.ObserveRun( + fixture.Create(), + run.Output); + run.Start(); + + // ASSERT + // Number of changes: we expect only one update per buffer + int expectedNumberOfUpdates = (int)Math.Ceiling(1.0 * MaxItemsToShow / bufferCap); + recorder.Data.Count.Should().Be(expectedNumberOfUpdates); + + // State after each change + foreach (var (snapshot, selectedItem) in recorder.Data) + { + selectedItem.Should().BeSameAs(snapshot.LastOrDefault()); + } + + // Final state: Truncation Notice is not selected, last 'real' error remains selected + sut.SelectedErrorItem.Should().BeSameAs(sut.Errors[^2]); + } + + [Fact] + public void ShowSelectedFileCommand_CanExecuteWhenSelectedErrorItemIsNotNull() + { + var sut = CreateSut(); + Command_CanExecuteWhenSelectedErrorItemIsNotNull(sut, sut.ShowSelectedFileCommand); + } + + [Fact] + public void ShowSelectedFileCommand_WhenSelectedErrorItemIsNotNull_RevealsFile() + { + // ARRANGE + var launcherMock = new Mock(); + var sut = CreateSut(launcher: launcherMock.Object); + var fixture = new Fixture(); + var errorItem = fixture.Create(); + sut.SelectedErrorItem = errorItem; + + // ACT + sut.ShowSelectedFileCommand.Execute(null); + + // ASSERT + launcherMock.Verify(x => x.Reveal(errorItem.File), Times.Once); + launcherMock.VerifyNoOtherCalls(); + } + + [Fact] + public void ShowSelectedFileCommand_WhenSelectedErrorItemIsNull_NoError() + { + // ARRANGE + var launcherMock = new Mock(); + var sut = CreateSut(launcher: launcherMock.Object); + sut.SelectedErrorItem = null; + + // ACT + sut.ShowSelectedFileCommand.Execute(null); + + // ASSERT + launcherMock.VerifyNoOtherCalls(); + } + + [Fact] + public void OpenSelectedFileCommand_WhenSelectedErrorItemIsNull_NoError() + { + // ARRANGE + var launcherMock = new Mock(); + var sut = CreateSut(launcher: launcherMock.Object); + sut.SelectedErrorItem = null; + + // ACT + sut.OpenSelectedFileCommand.Execute(null); + + // ASSERT + launcherMock.VerifyNoOtherCalls(); + } + + [Fact] + public void OpenSelectedFileCommand_WhenSelectedErrorItemIsNotNull_OpensFile() + { + // ARRANGE + var launcherMock = new Mock(); + var sut = CreateSut(launcher: launcherMock.Object); + var fixture = new Fixture(); + var errorItem = fixture.Create(); + sut.SelectedErrorItem = errorItem; + + // ACT + sut.OpenSelectedFileCommand.Execute(null); + + // ASSERT + launcherMock.Verify(x => x.Launch(errorItem.File), Times.Once); + launcherMock.VerifyNoOtherCalls(); + } + + [Fact] + public void OpenSelectedFileCommand_CanExecuteWhenSelectedErrorItemIsNotNull() + { + var sut = CreateSut(); + Command_CanExecuteWhenSelectedErrorItemIsNotNull(sut, sut.OpenSelectedFileCommand); + } + + private static void Command_CanExecuteWhenSelectedErrorItemIsNotNull(ErrorListViewModel sut, ICommand command) + { + sut.SelectedErrorItem.Should().BeNull(); + command.CanExecute(null).Should().BeFalse(); + + using (var m = command.Monitor()) + { + var fixture = new Fixture(); + sut.SelectedErrorItem = fixture.Create(); + command.CanExecute(null).Should().BeTrue(); + m.Should().Raise(nameof(ICommand.CanExecuteChanged)); + } + + using (var m = command.Monitor()) + { + sut.SelectedErrorItem = null; + command.CanExecute(null).Should().BeFalse(); + m.Should().Raise(nameof(ICommand.CanExecuteChanged)); + } + } + + private static IFixture CreateFixture() + { + var f = new Fixture().Customize(new AutoMoqCustomization()); + f.Customizations.Add(new ThreadCountSpecimenBuilder()); + return f; + } + + private static ErrorListViewModel CreateSut( + int bufferCap = 50, + int maxItemsToShow = int.MaxValue, + TimeSpan? bufferTimeout = null, + IScheduler? scheduler = null, + IFileLauncher? launcher = null) + { + return new ErrorListViewModel( + maxNumberOfErrorsToShow: maxItemsToShow, + bufferInterval: bufferTimeout ?? TimeSpan.FromMinutes(5), + bufferCapacity: bufferCap, + scheduler: scheduler ?? ImmediateScheduler.Instance, + launcher: launcher ?? Mock.Of()); + } + + private static IEnumerable GenerateMessages(IFixture fixture, int count = int.MaxValue) + { + return from i in Enumerable.Range(0, count) + let error = i % 2 == 0 ? $"E{i}" : null + select new FileFinished( + Mock.Of(f => f.FullName == $"F{i}"), + fixture.Create(), + fixture.Create(), + fixture.Create(), + error); + } + + private static IObservable<(ErrorItem[] Snapshot, string Change)> ObserveErrorListChanges( + ErrorListViewModel sut) + { + INotifyCollectionChanged errorsColl = sut.Errors; + var changes = Observable.FromEventPattern( + e => errorsColl.CollectionChanged += e, + e => errorsColl.CollectionChanged -= e); + var resultSnapshotObservable = from change in changes + select (sut.Errors.ToArray(), ToString(change.EventArgs)); + return resultSnapshotObservable; + } + + private static (IReadOnlyList SnapShot, string Change)[] GetExpectedErrorListChangesForSingleAdds( + IEnumerable inputData, + int maxItemsToShow) + { + int expectedChangeCount = maxItemsToShow + 2; + var changeIndices = Enumerable.Range(0, expectedChangeCount); + + // Changes + var expectedChanges = from changeIndex in changeIndices + select GetExpectedErrorListChangeForSingleAdds(changeIndex, inputData, maxItemsToShow); + return expectedChanges.ToArray(); + } + + private static (IReadOnlyList SnapShot, string Change) GetExpectedErrorListChangeForSingleAdds( + int changeIndex, + IEnumerable inputData, + int maxItemsToShow) + { + if (changeIndex == 0) + { + // First snapshot is the clearing of the list. + return (Array.Empty(), "Reset"); + } + + IEnumerable allExpected = GetExpectedErrorItems(inputData); + var truncatedExpectation = allExpected.Take(maxItemsToShow).Append(GetExpectedTruncationItem()); + var list = truncatedExpectation.Take(changeIndex).ToList(); + return GetExpectedAddLastChange(list); + } + + private static ErrorItem GetExpectedTruncationItem() + { + return new ErrorItem { File = "…", ErrorMessage = "See log file for further errors." }; + } + + private static IEnumerable GetExpectedErrorItems(IEnumerable inputData) + { + return from m in inputData + let e = m.ErrorMessage + where e != null + select new ErrorItem { File = m.InputFile.FullName, ErrorMessage = e }; + } + + private static IObservable<(ErrorItem[] Snapshot, ErrorItem? SelectedItem)> ObserveSelectedItemChanges(ErrorListViewModel sut) + { + var changes = sut.ObservableForProperty(vm => vm.SelectedErrorItem); + + return from change in changes select (sut.Errors.ToArray(), change.Value); + } + + private static string ToString(NotifyCollectionChangedEventArgs e) + { + return e.Action switch + { + NotifyCollectionChangedAction.Add => FormatAdd(e.NewStartingIndex, ToString(e.NewItems)), + _ => e.Action.ToString(), + }; + + static string ToString(IEnumerable? newItems) + { + var errorItems = newItems!.Cast(); + return string.Join("\t", errorItems); + } + } + + private static string FormatAdd(int addIndex, object? newItems) + { + return $"Add {newItems} at {addIndex}"; + } + + private static (IReadOnlyList SnapShot, string Change) GetExpectedAddLastChange(IReadOnlyList list) + { + string addLastChange = FormatAdd(list.Count - 1, list[^1]); + return (list, addLastChange); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/LogFileViewModelTests.cs b/czishrink/netczicompressTests/ViewModels/LogFileViewModelTests.cs new file mode 100644 index 0000000..656c063 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/LogFileViewModelTests.cs @@ -0,0 +1,367 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.Collections.Immutable; +using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; +using System.Reactive.Concurrency; +using System.Reactive.Subjects; + +using netczicompress.ViewModels; +using netczicompressTests.Customizations; +using netczicompressTests.Models.Mocks; + +/// +/// Tests for . +/// +public class LogFileViewModelTests +{ + [Theory] + [InlineData(true)] + [InlineData(false)] + public void ObserveRun_WhenCalled_LogsMessages(bool exception) + { + // ARRANGE + var fixture = CreateFixture(); + var p = fixture.Create(); + + fixture.Inject(ImmediateScheduler.Instance); + + var strategyMock = fixture.Freeze>(); + var recorder = new Recorder(); + using var writer = new StreamWriter(new MemoryStream()); + strategyMock.Setup(x => x.CreateLogFile(p)).Returns(Mock.Of(x => x.CreateText() == writer)); + strategyMock.Setup(x => x.CreateLogger(writer)).Returns(recorder); + strategyMock.Setup(x => x.LoggerScheduler).Returns(ImmediateScheduler.Instance); + + var sut = fixture.Create(); + + var subject = new Subject(); + + // ACT + sut.ObserveRun(p, subject); + + var messages = fixture.CreateMany(); + subject.OnNextAll(messages); + + var messagesLoggedBeforeTermination = recorder.Data.ToImmutableArray(); + Complete(subject, exception); + + // ASSERT + recorder.Completed.Should().BeTrue(); + recorder.Data.Should().BeEquivalentTo(messages); + messagesLoggedBeforeTermination.Should().BeEquivalentTo(messages); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void ObserveRun_UsesLoggerSchedulerToLogMessages(bool exception) + { + // ARRANGE + var fixture = CreateFixture(); + var p = fixture.Create(); + + fixture.Inject(ImmediateScheduler.Instance); + + var strategyMock = fixture.Freeze>(); + var recorder = new Recorder(); + var loggerScheduler = new SchedulerMock(); + using var writer = new StreamWriter(new MemoryStream()); + strategyMock.Setup(x => x.CreateLogFile(p)).Returns(Mock.Of(x => x.CreateText() == writer)); + strategyMock.Setup(x => x.CreateLogger(writer)).Returns(recorder); + strategyMock.Setup(x => x.LoggerScheduler).Returns(loggerScheduler); + + var sut = fixture.Create(); + + List<(string, ImmutableArray LoggedMessages, bool Completed)> data = new(); + void StoreDataPoint(string name) + { + recorder.Error.Should().BeNull(); + data.Add((name, recorder.Data.ToImmutableArray(), recorder.Completed)); + } + + // ACT + using var subject = new Subject(); + sut.ObserveRun(p, subject.AsObservable()); + var messages = fixture.CreateMany(); + subject.OnNextAll(messages); + + Complete(subject, exception); + StoreDataPoint("Completed"); + + loggerScheduler.RunQueuedActions(); + StoreDataPoint("Completed and Scheduler Queue Run"); + + // ASSERT + var allMessages = messages.ToImmutableArray(); + var noMessages = ImmutableArray.Empty; + + data.Should().BeEquivalentTo( + new[] + { + ("Completed", noMessages, false), + ("Completed and Scheduler Queue Run", allMessages, true), + }); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void ObserveRun_WhenCalled_CorrectlyPublishesLogFile(bool exception) + { + // ARRANGE + var fixture = CreateFixture(); + var p = fixture.Create(); + + fixture.Inject(ImmediateScheduler.Instance); + + var fs = new MockFileSystem(new MockFileSystemOptions { CreateDefaultTempDir = true }); + IFileInfo? logFile = null; + var strategyMock = fixture.Freeze>(); + strategyMock.Setup(x => x.CreateLogFile(p)).Returns(_ => + { + var result = fs.FileInfo.New(fs.Path.GetTempFileName()); + logFile = result; + return result; + }); + strategyMock.Setup(x => x.LoggerScheduler).Returns(ImmediateScheduler.Instance); + + var sut = fixture.Create(); + + Dictionary data = new(); + void LogDataPoint(string name) + { + data[name] = (sut.LogFileOfLastRun, sut.OpenLogFileCommand.CanExecute(null)); + } + + LogDataPoint("Never Run"); + for (int i = 0; i < 2; i++) + { + // ACT + var subject = new Subject(); + sut.ObserveRun(p, subject); + LogDataPoint("Before Run"); + + var messages = fixture.CreateMany(); + subject.OnNextAll(messages); + + LogDataPoint("During Run"); + + using (var monitor = sut.Monitor()) + { + Complete(subject, exception); + monitor.Should().RaisePropertyChangeFor(x => x.LogFileOfLastRun); + } + + LogDataPoint("After Run"); + + // ASSERT + data["Never Run"].Should().Be((null, false)); + data["Before Run"].Should().Be((null, false)); + data["During Run"].Should().Be((null, false)); + data["After Run"].Should().Be((logFile, true)); + } + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void ObserveRun_WhenCalled_UsesGuiSchedulerToPublishLogFile(bool exception) + { + // ARRANGE + var fixture = CreateFixture(); + var p = fixture.Create(); + var guiScheduler = new SchedulerMock(); + fixture.Inject(guiScheduler); + + var fs = new MockFileSystem(new MockFileSystemOptions { CreateDefaultTempDir = true }); + var strategyMock = fixture.Freeze>(); + strategyMock.Setup(x => x.CreateLogFile(p)).Returns(_ => + { + return fs.FileInfo.New(fs.Path.GetTempFileName()); + }); + strategyMock.Setup(x => x.LoggerScheduler).Returns(ImmediateScheduler.Instance); + + var sut = fixture.Create(); + + Dictionary data = new(); + void LogDataPoint(string name) + { + data[name] = (sut.LogFileOfLastRun, sut.OpenLogFileCommand.CanExecute(null)); + } + + for (int i = 0; i < 2; i++) + { + // ACT + var subject = new Subject(); + sut.ObserveRun(p, subject); + + var messages = fixture.CreateMany(); + subject.OnNextAll(messages); + + using (var monitor = sut.Monitor()) + { + Complete(subject, exception); + monitor.Should().NotRaisePropertyChangeFor(x => x.LogFileOfLastRun); + LogDataPoint("Before scheduler queue has run"); + + guiScheduler.RunQueuedActions(); + monitor.Should().RaisePropertyChangeFor(x => x.LogFileOfLastRun); + LogDataPoint("After scheduler queue has run"); + } + + // ASSERT + data["Before scheduler queue has run"].Should().Be((null, false)); + var after = data["After scheduler queue has run"]; + after.LogFileOfLastRun.Should().NotBeNull(); + after.CanShowLogFile.Should().BeTrue(); + } + } + + [Fact] + public void ShowLogFileCommand_WhenCannotExecute_ExecuteDoesNothing() + { + // ARRANGE + var fixture = CreateFixture(); + fixture.Inject(ImmediateScheduler.Instance); + var loggingStrategyMock = fixture.Freeze>(); + var sut = fixture.Create(); + + // ACT + sut.OpenLogFileCommand.Execute(null); + + // ASSERT + loggingStrategyMock.Verify(x => x.OpenLogFile(It.IsAny()), Times.Never); + } + + [Fact] + public void ShowLogFile_WhenLogFileExists_OpensLogFile() + { + // ARRANGE + var fixture = CreateFixture(); + fixture.Inject(ImmediateScheduler.Instance); + var loggingStrategyMock = fixture.Freeze>(); + var logFileMock = new Mock(); + var sut = fixture.Create(); + + var p = fixture.Create(); + + loggingStrategyMock.Setup(x => x.CreateLogFile(p)).Returns(logFileMock.Object); + var messages = fixture.CreateMany(); + var run = messages.ToObservableAction(); + + sut.ObserveRun(p, run.Output); + run.Start(); + logFileMock + .Setup( + x => x.Refresh()) + .Callback( + () => logFileMock + .SetupGet( + x => x.Exists) + .Returns( + true)); + sut.LogFileOfLastRun.Should().BeSameAs(logFileMock.Object); + sut.LogFileOfLastRun!.Exists.Should().BeFalse(); + sut.OpenLogFileCommand.CanExecute(null).Should().BeTrue(); + + // ACT + sut.OpenLogFileCommand.Execute(null); + + // ASSERT + loggingStrategyMock.Verify(x => x.OpenLogFile(logFileMock.Object), Times.Once); + sut.LogFileOfLastRun.Should().BeSameAs(logFileMock.Object); + sut.LogFileOfLastRun!.Exists.Should().BeTrue(); + sut.OpenLogFileCommand.CanExecute(null).Should().BeTrue(); + } + + [Fact] + public void ShowLogFile_WhenLogFileDoesNotExist_UpdatesCanExecute() + { + // ARRANGE + var fixture = CreateFixture(); + fixture.Inject(ImmediateScheduler.Instance); + var loggingStrategyMock = fixture.Freeze>(); + var logFileMock = new Mock(); + var sut = fixture.Create(); + + var p = fixture.Create(); + + loggingStrategyMock.Setup(x => x.CreateLogFile(p)).Returns(logFileMock.Object); + var messages = fixture.CreateMany(); + var run = messages.ToObservableAction(); + + sut.ObserveRun(p, run.Output); + run.Start(); + sut.LogFileOfLastRun.Should().BeSameAs(logFileMock.Object); + sut.LogFileOfLastRun!.Exists.Should().BeFalse(); + sut.OpenLogFileCommand.CanExecute(null).Should().BeTrue(); + + // ACT + sut.OpenLogFileCommand.Execute(null); + + // ASSERT + loggingStrategyMock.Verify(x => x.OpenLogFile(logFileMock.Object), Times.Never); + sut.LogFileOfLastRun.Should().BeNull(); + sut.OpenLogFileCommand.CanExecute(null).Should().BeFalse(); + } + + [Fact] + public void ShowLogFile_WhenOpeningTheLogFileFails_UpdatesCanExecute() + { + // ARRANGE + var fixture = CreateFixture(); + fixture.Inject(ImmediateScheduler.Instance); + var loggingStrategyMock = fixture.Freeze>(); + var logFile = Mock.Of(x => x.Exists); + var sut = fixture.Create(); + + var p = fixture.Create(); + + loggingStrategyMock.Setup(x => x.CreateLogFile(p)).Returns(logFile); + var messages = fixture.CreateMany(); + var run = messages.ToObservableAction(); + + sut.ObserveRun(p, run.Output); + run.Start(); + sut.LogFileOfLastRun.Should().BeSameAs(logFile); + sut.LogFileOfLastRun!.Exists.Should().BeTrue(); + sut.OpenLogFileCommand.CanExecute(null).Should().BeTrue(); + loggingStrategyMock + .Setup( + x => x.OpenLogFile(logFile)) + .Throws(); + + // ACT + sut.OpenLogFileCommand.Execute(null); + + // ASSERT + loggingStrategyMock.Verify(x => x.OpenLogFile(logFile), Times.Once); + sut.LogFileOfLastRun.Should().BeNull(); + sut.OpenLogFileCommand.CanExecute(null).Should().BeFalse(); + } + + private static IFixture CreateFixture() + { + var result = new Fixture().Customize(new AutoMoqCustomization()); + result.Customizations.Add(new ThreadCountSpecimenBuilder()); + return result; + } + + private static void Complete(IObserver subject, bool exception) + { + if (exception) + { + var ex = new Exception(); + subject.OnError(ex); + } + else + { + subject.OnCompleted(); + } + } +} diff --git a/czishrink/netczicompressTests/ViewModels/MainViewModelTests.ChildViewModels.cs b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.ChildViewModels.cs new file mode 100644 index 0000000..7a08f41 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.ChildViewModels.cs @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using AutoFixture; + +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +/// Tests for child view models. +public partial class MainViewModelTests +{ + [Fact] + public void ChildViewModels_AreThoseInjected() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var errorList = fixture.Freeze(); + var currentTasks = fixture.Freeze(); + var aggregateStatistics = fixture.Freeze(); + var about = fixture.Freeze(); + + // ACT + var sut = fixture.Create(); + + // ASSERT + sut.About.Should().BeSameAs(about); + sut.AggregateStatisticsViewModel.Should().BeSameAs(aggregateStatistics); + sut.CurrentTasks.Should().BeSameAs(currentTasks); + sut.ErrorList.Should().BeSameAs(errorList); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/MainViewModelTests.Modes.cs b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.Modes.cs new file mode 100644 index 0000000..cff3d8c --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.Modes.cs @@ -0,0 +1,104 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.IO.Abstractions; +using System.Reactive; + +using AutoFixture; + +using netczicompress.Models; +using netczicompress.ViewModels; + +using netczicompressTests.Models.Mocks; + +/// +/// Tests for . +/// +/// Tests for members related to mode selection. +public partial class MainViewModelTests +{ + [Fact] + public void Modes_WhenGot_HaveExpectedValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + + // ACT + var actual = sut.Modes.Cast().ToArray(); + + // ASSERT + actual.Should().BeEquivalentTo(new OperationMode[] + { + new(CompressionMode.CompressUncompressed, "Compress uncompressed data", "Compress only uncompressed subblocks and copy others."), + new(CompressionMode.CompressUncompressedAndZstd, "Compress uncompressed and Zstd-compressed data", "Compress subblocks that were originally compressed with zstd or uncompressed."), + new(CompressionMode.CompressAll, "Compress all data", "Compress all subblocks regardless of current compression method (if possible)."), + new(CompressionMode.Decompress, "Decompress all data", "Decompress all possible subblocks."), + new(CompressionMode.NoOp, "Dry Run (enumerate and log files)", "Do not compress/decompress rather just enumerate and log files that would be affected."), + }); + } + + [Fact] + public void SelectedMode_WhenGot_HasExpectedValue() + { + // ARRANGE + IFixture fixture = CreateFixture(); + + var sut = fixture.Create(); + + // ACT + var actual = sut.SelectedMode; + + // ASSERT + actual.Should().BeSameAs(sut.Modes.Cast().First()); + actual.Value.Should().Be(CompressionMode.CompressUncompressed); + } + + [Theory] + [AutoData] + public async Task Start_WhenCalled_UsesSelectedMode(ushort selectedModeIndex) + { + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + var compressorMock = fixture.Freeze>().WithAutoData(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs); + + var modes = sut.Modes.Cast().ToArray(); + var selectedIndex = selectedModeIndex % modes.Length; + var selectedMode = modes[selectedIndex]; + + // ACT + sut.SelectedMode = selectedMode; + await sut.StartCommand.Execute(Unit.Default); + + // ASSERT + compressorMock.Verify( + x => + x.PrepareNewRun( + It.Is(x => x.Mode == selectedMode.Value), + It.Is(c => !c.IsCancellationRequested)), + Times.Once); + } + + [Theory] + [AutoData] + public void OperationMode_ToString_ReturnsDisplayText(CompressionMode mode, string displayText, string tooltipText) + { + var sut = new OperationMode(mode, displayText, tooltipText); + + sut.ToString().Should().BeSameAs(displayText); + } + + private static IFixture CreateFixture(bool omitAutoProperties = true) + { + // ARRANGE + return new Fixture { OmitAutoProperties = omitAutoProperties }.Customize(new AutoMoqCustomization()); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/MainViewModelTests.OverallStatus.cs b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.OverallStatus.cs new file mode 100644 index 0000000..ecbda7a --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.OverallStatus.cs @@ -0,0 +1,310 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; +using System.Reactive; +using System.Reactive.Threading.Tasks; + +using AutoFixture; + +using Microsoft.Extensions.Logging; + +using netczicompress.Models; +using netczicompress.ViewModels; + +using netczicompressTests.Models.Mocks; + +/// +/// Tests for . +/// +/// Tests for members related to overall status. +public partial class MainViewModelTests +{ + [Fact] + public void OverallStatus_WhenNotRun_IsEmpty() + { + // ARRANGE + var fixture = CreateFixture(); + + var sut = fixture.Create(); + + // ACT + var actual = sut.OverallStatus; + + // ASSERT + actual.Should().BeEmpty(); + } + + [Fact] + public async Task OverallStatus_WhenRunSuccessful_IsExpected() + { + // ARRANGE + var fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + _ = fixture.Freeze>().WithAutoData(fixture); + var loggerMock = new LoggerMock().Inject(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs); + + // ACT + await sut.StartCommand.Execute(Unit.Default); + + // ASSERT + sut.OverallStatus.Should().Be("Finished"); + loggerMock.VerifyEntryCount(2); + loggerMock.VerifyEntry(^1, LogLevel.Information, "Run finished normally."); + } + + [Fact] + public async Task OverallStatus_WhenRunCanceled_IsExceptionMessage() + { + // ARRANGE + var fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + var opCanceled = new OperationCanceledException("CaNcElEd"); + _ = fixture.Freeze>().WithException(opCanceled); + var loggerMock = new LoggerMock().Inject(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs); + + // ACT + await sut.StartCommand.Execute(Unit.Default); + + // ASSERT + sut.OverallStatus.Should().Be(opCanceled.Message); + loggerMock.VerifyEntryCount(2); + loggerMock.VerifyEntry(1, LogLevel.Warning, "Run canceled."); + } + + [Fact] + public async Task OverallStatus_WhenOtherException_IsExceptionMessageWithWarningSign() + { + // ARRANGE + var fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + var invalidOp = new InvalidOperationException("Foo bar baz."); + _ = fixture.Freeze>().WithException(invalidOp); + var loggerMock = new LoggerMock().Inject(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs); + + // ACT + await sut.StartCommand.Execute(Unit.Default); + + // ASSERT + sut.OverallStatus.Should().Be("⚠ Foo bar baz."); + loggerMock.VerifyEntryCount(2); + loggerMock.VerifyEntry(^1, LogLevel.Error, "Run failed: " + invalidOp); + } + + [Fact] + public async Task OverallStatus_WhenInputDirectoryNotSet_IsExpected() + { + // ARRANGE + var fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + var compressorMock = fixture.Freeze>(); + var loggerMock = new LoggerMock().Inject(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs, setInput: false); + + // ACT + await sut.StartCommand.Execute(Unit.Default); + + // ASSERT + sut.OverallStatus.Should().Be("⚠ Input folder is not set."); + + loggerMock.VerifySingleEntry(LogLevel.Error, "Run failed: System.InvalidOperationException: Input folder is not set.*at*"); + + compressorMock.VerifyNoOtherCalls(); + } + + [Fact] + public async Task OverallStatus_WhenOutputDirectoryNotSet_IsExpected() + { + // ARRANGE + var fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + var compressorMock = fixture.Freeze>(); + var loggerMock = new LoggerMock().Inject(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs, setOutput: false); + + // ACT + await sut.StartCommand.Execute(Unit.Default); + + // ASSERT + sut.OverallStatus.Should().Be("⚠ Output folder is not set."); + + loggerMock.VerifySingleEntry(LogLevel.Error, "Run failed: System.InvalidOperationException: Output folder is not set.*at*"); + + compressorMock.VerifyNoOtherCalls(); + } + + [Fact] + public async Task OverallStatus_WhenInputDirectoryDoesNotExist_IsExpected() + { + // ARRANGE + var fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + var compressorMock = fixture.Freeze>(); + var loggerMock = new LoggerMock().Inject(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs); + string inputDir = fs.Path.Join(fs.Path.GetTempPath(), "Input"); + sut.InputDirectory = inputDir; + + // ACT + await sut.StartCommand.Execute(Unit.Default); + + // ASSERT + sut.OverallStatus.Should().Be($"⚠ Directory {inputDir} does not exist."); + loggerMock.VerifySingleEntry(LogLevel.Error, $"Run failed: System.IO.DirectoryNotFoundException: Directory {inputDir} does not exist.*at*"); + compressorMock.VerifyNoOtherCalls(); + } + + [Fact] + public async Task OverallStatus_WhenProcessing_HasExpectedValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + _ = fixture.Freeze>().WithWaitForCancellation(); + + var sut = fixture.Create(); + SetFolders(sut, fs); + + Dictionary overallStatusWhen = new(); + + void AddDataPoint(string timePoint) + { + overallStatusWhen[timePoint] = sut.OverallStatus; + } + + // ACT + AddDataPoint("ready to run"); + + for (int i = 0; i < 2; i++) + { + Task startCommandTask; + using (var monitor = sut.Monitor()) + { + startCommandTask = sut.StartCommand.Execute(default).ToTask(); + AddDataPoint("running" + i); + + if (i == 0) + { + monitor.Should().NotRaisePropertyChangeFor(mvm => mvm.OverallStatus); + } + else + { + monitor.Should().RaisePropertyChangeFor(mvm => mvm.OverallStatus); + } + } + + Task stopCommandTask; + using (var monitor = sut.Monitor()) + { + stopCommandTask = sut.StopCommand.Execute(default).ToTask(); + + await startCommandTask; + await stopCommandTask; + + AddDataPoint("stopped" + i); + monitor.Should().RaisePropertyChangeFor(mvm => mvm.OverallStatus); + } + } + + // ASSERT + overallStatusWhen["ready to run"].Should().BeEmpty(); + overallStatusWhen["running0"].Should().BeEmpty(); + overallStatusWhen["stopped0"].Should().Be(new OperationCanceledException().Message); + overallStatusWhen["running1"].Should().BeEmpty(); + overallStatusWhen["stopped1"].Should().Be(new OperationCanceledException().Message); + } + + private static MockFileSystem NewMockFileSystem() + { + return new MockFileSystem( + new MockFileSystemOptions { CreateDefaultTempDir = true }); + } + + private static void SetFolders(MainViewModel sut, IFileSystem fs, bool setInput = true, bool setOutput = true) + { + string someExistingDir = fs.Path.GetTempPath(); + if (setInput) + { + sut.InputDirectory = someExistingDir; + } + + if (setOutput) + { + sut.OutputDirectory = fs.Path.Join(someExistingDir, "output"); + } + } + + private class LoggerMock : ILogger + { + private static readonly EventId Zero = (EventId)0; + + private List<(LogLevel Level, EventId Event, string Message)> LogEntries { get; } = new(); + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + { + lock (this.LogEntries) + { + this.LogEntries.Add(new(logLevel, eventId, formatter.Invoke(state, exception))); + } + } + + public void VerifyEntryCount(int count) + { + this.LogEntries.Should().HaveCount(count); + } + + public void VerifyEntry(Index index, LogLevel expectedLevel, string messageWildcardPattern) + { + (LogLevel level, EventId eventId, string message) = this.LogEntries[index]; + level.Should().Be(expectedLevel); + eventId.Should().Be(Zero); + message.Should().Match(messageWildcardPattern); + } + + public void VerifySingleEntry(LogLevel expectedLevel, string messageWildcardPattern) + { + this.VerifyEntryCount(1); + this.VerifyEntry(0, expectedLevel, messageWildcardPattern); + } + + public LoggerMock Inject(IFixture fixture) + { + fixture.Inject>(this); + return this; + } + + public bool IsEnabled(LogLevel logLevel) => true; + + public IDisposable? BeginScope(TState state) + where TState : notnull + { + return null; + } + } +} diff --git a/czishrink/netczicompressTests/ViewModels/MainViewModelTests.PropertyChanged.cs b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.PropertyChanged.cs new file mode 100644 index 0000000..64cf707 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.PropertyChanged.cs @@ -0,0 +1,79 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.ComponentModel; + +using AutoFixture; + +using netczicompress.ViewModels; + +/// +/// Tests for . +/// +/// Tests for . +public partial class MainViewModelTests +{ + [Fact] + public void InputDirectory_WhenSet_RaisesPropertyChanged() + { + // ARRANGE + var fixture = CreateFixture(); + var sut = fixture.Create(); + + // ACT + using var monitor = sut.Monitor(); + sut.InputDirectory = "foo"; + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.InputDirectory); + } + + [Fact] + public void OutputDirectory_WhenSet_RaisesPropertyChanged() + { + // ARRANGE + var fixture = CreateFixture(); + var sut = fixture.Create(); + + // ACT + using var monitor = sut.Monitor(); + sut.OutputDirectory = "foo"; + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.OutputDirectory); + } + + [Fact] + public void Recursive_WhenSet_RaisesPropertyChanged() + { + // ARRANGE + var fixture = CreateFixture(); + var sut = fixture.Create(); + + // ACT + using var monitor = sut.Monitor(); + sut.Recursive = !sut.Recursive; + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.Recursive); + } + + [Theory] + [AutoData] + public void SelectedMode_WhenSet_RaisesPropertyChanged(OperationMode mode) + { + // ARRANGE + var fixture = CreateFixture(); + var sut = fixture.Create(); + + // ACT + using var monitor = sut.Monitor(); + sut.SelectedMode = mode; + + // ASSERT + monitor.Should().RaisePropertyChangeFor(x => x.SelectedMode); + } +} diff --git a/czishrink/netczicompressTests/ViewModels/MainViewModelTests.StartCommand.cs b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.StartCommand.cs new file mode 100644 index 0000000..3ac05ff --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.StartCommand.cs @@ -0,0 +1,232 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.IO.Abstractions; +using System.Reactive.Threading.Tasks; +using System.Windows.Input; + +using AutoFixture; + +using netczicompress.ViewModels; + +using netczicompressTests.Models.Mocks; + +/// +/// Tests for . +/// +/// Tests for . +public partial class MainViewModelTests +{ + [Fact] + public void StartCommand_WhenInputFolderNotSet_CannotExecute() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + + // ACT + var sut = fixture.Create(); + SetFolders(sut, fs, setInput: false); + + // ASSERT + ICommand command = sut.StartCommand; + command.CanExecute(null).Should().BeFalse(); + } + + [Fact] + public void StartCommand_WhenOutputFolderNotSet_CannotExecute() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + + // ACT + var sut = fixture.Create(); + SetFolders(sut, fs, setOutput: false); + + // ASSERT + ICommand command = sut.StartCommand; + command.CanExecute(null).Should().BeFalse(); + } + + [Fact] + public void StartCommand_WhenBothFoldersSet_CanExecute() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + + bool expectCanExecute = false; + List<(bool Expectation, bool Actual)> data = new(); + + var sut = fixture.Create(); + sut.StartCommand.CanExecute.Subscribe(onNext: + canExec => data.Add((expectCanExecute, canExec))); + + // ACT + SetFolders(sut, fs, setOutput: false); + + expectCanExecute = true; + SetFolders(sut, fs, setInput: false); + + // ASSERT + ICommand start = sut.StartCommand; + start.CanExecute(null).Should().BeTrue(); + + data.Count.Should().Be(2); + foreach (var (expectation, actual) in data) + { + actual.Should().Be(expectation); + } + } + + [Fact] + public async Task StartCommand_WhenProcessing_CanExecuteHasExpectedValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + _ = fixture.Freeze>().WithWaitForCancellation(); + + var sut = fixture.Create(); + ICommand start = sut.StartCommand; + SetFolders(sut, fs); + + Dictionary canStartWhen = new(); + + void AddDataPoint(string timePoint) + { + Thread.MemoryBarrier(); + canStartWhen[timePoint] = start.CanExecute(null); + } + + // ACT + AddDataPoint("ready to run"); + + var startCommandTask = sut.StartCommand.Execute(default).ToTask(); + AddDataPoint("running"); + + var stopCommandTask = sut.StopCommand.Execute(default).ToTask(); + await startCommandTask; + await stopCommandTask; + AddDataPoint("stopped"); + + for (int k = 0; !canStartWhen["stopped"] && k < 100; k++) + { + // canStartWhen["stopped"] has sporadically been false, + // e. g. in https://github.com/m-ringler/netczicompress/actions/runs/6195449563/job/16820188169?pr=47 + // This is probably due to the fact that ReactiveCommand overrides the passed in CanExecute observable + // with false while it is executing. So, CanExecute becomes true again only _after_ the command has + // stopped executing, i. e. _after_ startCommandTask completes. Thus, we have a race condition. + // => Wait a bit and try again. + await Task.Delay(10); + AddDataPoint("stopped"); + } + + // ASSERT + canStartWhen["ready to run"].Should().BeTrue(); + canStartWhen["running"].Should().BeFalse(); + try + { + canStartWhen["stopped"].Should().BeTrue(); + } + catch (Exception ex) + { + throw new Exception(canStartWhen["stopped"].ToString(), ex); + } + } + + [Fact] + public async Task StartCommands_WhenProcessingCompletes_CanExecuteIsTrue() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + _ = fixture.Freeze>().WithAutoData(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs); + + // ACT + var startCommandTask = sut.StartCommand.Execute(default).ToTask(); + await startCommandTask; + + // ASSERT + ICommand start = sut.StartCommand; + start.CanExecute(null).Should().BeTrue(); + } + + [Theory] + [AutoData] + public async Task StartCommands_WhenProcessingStarts_UsesCorrectParameters(OperationMode selectedMode, bool recursive) + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + var folderCompressorMock = fixture.Freeze>().WithWaitForCancellation(); + + var sut = fixture.Create(); + SetFolders(sut, fs); + sut.SelectedMode = selectedMode; + sut.Recursive = recursive; + + // ACT + var startCommandTask = sut.StartCommand.Execute(default).ToTask(); + + // ASSERT + folderCompressorMock.Verify( + x => x.PrepareNewRun( + It.Is( + x => x.InputDir.FullName == sut.InputDirectory && + x.OutputDir.FullName == sut.OutputDirectory && + object.ReferenceEquals(x.InputDir.FileSystem, fs) && + object.ReferenceEquals(x.OutputDir.FileSystem, fs) && + x.Recursive == recursive && + x.Mode == selectedMode.Value), + It.Is(t => !t.IsCancellationRequested)), + Times.Once); + + // CLEANUP + await sut.StopCommand.Execute(default); + await startCommandTask; + folderCompressorMock.VerifyNoOtherCalls(); + } + + [Theory] + [AutoData] + public async Task StartCommands_WhenProcessingStarts_LogsCorrectParameters(OperationMode selectedMode, bool recursive) + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + _ = fixture.Freeze>().WithWaitForCancellation(); + var loggerMock = new LoggerMock().Inject(fixture); + + var sut = fixture.Create(); + SetFolders(sut, fs); + sut.SelectedMode = selectedMode; + sut.Recursive = recursive; + + // ACT + var startCommandTask = sut.StartCommand.Execute(default).ToTask(); + + // ASSERT + loggerMock.VerifySingleEntry( + Microsoft.Extensions.Logging.LogLevel.Information, + $"Starting run: FolderCompressorParameters {{ InputDir = {sut.InputDirectory}, OutputDir = {sut.OutputDirectory}, Recursive = {recursive}, Mode = {selectedMode.Value}, ExecutionOptions = ExecutionOptions {{ ThreadCount = {sut.ThreadCount} }}, ProcessingOptions = ProcessingOptions {{ CompressionLevel = {sut.CompressionLevel}, CopyFailedFiles = {sut.CopyFailedFiles} }} }}"); + + // CLEANUP + await sut.StopCommand.Execute(default); + await startCommandTask; + } +} diff --git a/czishrink/netczicompressTests/ViewModels/MainViewModelTests.StopCommand.cs b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.StopCommand.cs new file mode 100644 index 0000000..de8be12 --- /dev/null +++ b/czishrink/netczicompressTests/ViewModels/MainViewModelTests.StopCommand.cs @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH +// +// SPDX-License-Identifier: GPL-3.0-or-later + +namespace netczicompressTests.ViewModels; + +using System.IO.Abstractions; +using System.Reactive.Threading.Tasks; +using System.Windows.Input; + +using AutoFixture; + +using netczicompress.ViewModels; + +using netczicompressTests.Models.Mocks; + +/// +/// Tests for . +/// +/// Tests for . +public partial class MainViewModelTests +{ + [Fact] + public async Task StopCommand_WhenProcessing_CanExecuteHasExpectedValues() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + _ = fixture.Freeze>().WithWaitForCancellation(); + + var sut = fixture.Create(); + ICommand stop = sut.StopCommand; + SetFolders(sut, fs); + + Dictionary canStopWhen = new(); + + void AddDataPoint(string timePoint) + { + var canStop = stop.CanExecute(null); + canStopWhen[timePoint] = stop.CanExecute(null); + sut.CanStop.Should().Be(canStop); + } + + // ACT + AddDataPoint("ready to run"); + + Task startCommandTask; + using (var monitor = sut.Monitor()) + { + startCommandTask = sut.StartCommand.Execute(default).ToTask(); + monitor.Should().RaisePropertyChangeFor(mvm => mvm.CanStop); + AddDataPoint("running"); + } + + Task stopCommandTask; + using (var monitor = sut.Monitor()) + { + stopCommandTask = sut.StopCommand.Execute(default).ToTask(); + monitor.Should().RaisePropertyChangeFor(mvm => mvm.CanStop); + AddDataPoint("stopping"); + } + + await startCommandTask; + await stopCommandTask; + AddDataPoint("stopped"); + + // ASSERT + canStopWhen["ready to run"].Should().BeFalse(); + canStopWhen["running"].Should().BeTrue(); + canStopWhen["stopping"].Should().BeFalse(); + canStopWhen["stopped"].Should().BeFalse(); + } + + [Fact] + public async Task StartCommands_WhenProcessingCompletes_CanExecuteIsFalse() + { + // ARRANGE + IFixture fixture = CreateFixture(); + IFileSystem fs = NewMockFileSystem(); + fixture.Inject(fs); + _ = fixture.Freeze>().WithAutoData(fixture); + + var sut = fixture.Create(); + ICommand stop = sut.StopCommand; + SetFolders(sut, fs); + + // ACT + var startCommandTask = sut.StartCommand.Execute(default).ToTask(); + await startCommandTask; + + // ASSERT + stop.CanExecute(null).Should().BeFalse(); + } +} diff --git a/czishrink/netczicompressTests/mandelbrot.czi b/czishrink/netczicompressTests/mandelbrot.czi new file mode 100644 index 0000000..94600ac Binary files /dev/null and b/czishrink/netczicompressTests/mandelbrot.czi differ diff --git a/czishrink/netczicompressTests/netczicompressTests.csproj b/czishrink/netczicompressTests/netczicompressTests.csproj new file mode 100644 index 0000000..a074900 --- /dev/null +++ b/czishrink/netczicompressTests/netczicompressTests.csproj @@ -0,0 +1,48 @@ + + + false + true + x64 + + + + + + + + + PreserveNewest + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + diff --git a/czishrink/packages_local/libczicompressc.0.5.1-alpha.0.nupkg b/czishrink/packages_local/libczicompressc.0.5.1-alpha.0.nupkg new file mode 100644 index 0000000..f0ad1f7 --- /dev/null +++ b/czishrink/packages_local/libczicompressc.0.5.1-alpha.0.nupkg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:552d2554704d6964e3900a80bcee3d73b6f688aafda0981d7c1d8110fa7560bc +size 2039939 diff --git a/czishrink/stylecop.json b/czishrink/stylecop.json new file mode 100644 index 0000000..11eedfa --- /dev/null +++ b/czishrink/stylecop.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + + "settings": { + "namingRules": { + "allowedNamespaceComponents": [ + "netczicompress", + "netczicompressTests" + ] + } + } +} \ No newline at end of file diff --git a/czishrink/upgrade-libczicompressc.ps1 b/czishrink/upgrade-libczicompressc.ps1 new file mode 100644 index 0000000..09da8d8 --- /dev/null +++ b/czishrink/upgrade-libczicompressc.ps1 @@ -0,0 +1,363 @@ +<# +.SYNOPSIS + +Upgrades libczicompressc.nupkg in CziShrink with the latest cmake build of the main branch of czicompress. + +.DESCRIPTION + +This script should be run in the czishrink directory of a clone of https://github.com/ZEISS/czicompress. +Make sure that you do not have any uncommited changes before you run the script. Otherwise the script will stash such changes. + +You must have git and dotnet on your path. + +The script needs to have access to the https://github.com/ZEISS/czicompress github repo (or your fork of that repo), +you need to + * create a 'classic' personal access token at https://github.com/settings/tokens or with github cli, + * and authorize it for the ZEISS organization via the "Configure SSO" button, + * and store it in a GITHUB_TOKEN environment variable or pass it as the -GithubToken parameter to this script. + +If you specify a -DownloadFolder the script will reuse data downloaded to that folder in a previous run. This provides rudimentary resume-on-error functionality. + +.EXAMPLE + +PS> ./upgrade-libczicompressc.ps1 -DownloadFolder "$env:TEMP/libczicompress/cache" -NoPullRequest + +.PARAMETER DownloadFolder + +The folder where downloads are stored and cached. Defaults to "$env:Temp/libczicompressc/$(Get-Date -Format FileDate)". +Downloads in that folder will be reused unless you use -NoCache. +The folder is created if necessary. +The folder will not be deleted or emptied at the end of the script. + +.PARAMETER NugetExePath + +The path to Nuget.exe. If this is not specified and nuget.exe is found on the $env:PATH we use that nuget.exe. +Otherwise defaults to DownloadFolder/nuget.exe. If nuget.exe is not found it is downloaded and stored at this path. + +.PARAMETER GithubToken + +The github personal access token to use. Can be created at https://github.com/settings/tokens or with github cli (gh auth token). +Defaults to the value of $env:GITHUB_TOKEN. + +.PARAMETER NoPR + +This switch prevents a pull request from being created. + +.PARAMETER NoCache + +This switch prevents previous downloads in the DownloadFolder from being reused. + +.PARAMETER OverwriteExistingBranch + +Overwrites an existing upgrade branch. This can be useful if a previous run of the script has failed. Applies to local and remote. + +#> + +param( + [Parameter(Mandatory=$false)] + [AllowNull()] + [string]$DownloadFolder = $null, + + [Parameter(Mandatory=$false)] + [string]$NugetExePath = $null, + + [Parameter(Mandatory=$false)] + [string]$GithubToken = $env:GITHUB_TOKEN, + + [Parameter(Mandatory=$false)] + [switch]$NoPR, + + [Parameter(Mandatory=$false)] + [switch]$NoCache, + + [Parameter(Mandatory=$false)] + [switch]$OverwriteExistingBranch +) + +$CreatePullRequest = !$NoPR +$UseCache = !$NoCache + +Import-Module -Name Microsoft.PowerShell.Utility +Import-Module -Name Microsoft.PowerShell.Archive + +$ErrorActionPreference = "Stop" + +# The name of the CziCompress repo +$CziCompress = "ZEISS/czicompress" +########################################################## +# PART 1: Download latest CmakeBuild artifacts from GitHub +########################################################## + +if ($null -eq $GithubToken) { + throw "You must set the GITHUB_TOKEN environment variable to a personal access token of yours: https://github.com/settings/tokens. See also: https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on" +} + +$GithubApiHeaders = @{ + 'Accept' = 'application/vnd.github+json' + 'X-GitHub-Api-Version' = '2022-11-28' + 'Authorization' = "Bearer $GithubToken" +} + +if (!$DownloadFolder) { + $DownloadFolder = "$env:Temp/libczicompressc/$(Get-Date -Format FileDate)" +} + +Write-Output "INFO: Using DownloadFolder $DownloadFolder" +if (!(Test-Path $DownloadFolder)) { + mkdir $DownloadFolder +} + +# We'll use the following properties +# artifacts_url -> download dll/so +# head_sha -> nuspec git commit +$LatestRunJson = "$DownloadFolder/LatestRunOfCMakeBuild.json" + +if ($UseCache -and (Test-Path -Path $LatestRunJson)) { + Write-Output "INFO: Using previously downloaded build info from $LatestRunJson." + $LatestRunOfCMakeBuild = Get-Content $LatestRunJson | ConvertFrom-Json +} else { + # Get latest run + Write-Output "INFO: Getting build info from github.com/$CziCompress." + $ActionRunsUri = "https://api.github.com/repos/$CziCompress/actions/runs?branch=main&status=success&per_page=10" + $ServerResponse = Invoke-WebRequest -Uri $ActionRunsUri -Headers $GithubApiHeaders | ConvertFrom-Json + $RunsOfCmakeBuild = $ServerResponse.workflow_runs | Where-Object Name -eq 'CMake Build (czicompress)' + + $LatestRunOfCMakeBuild = $RunsOfCmakeBuild | Sort-Object -Property 'run_number' | Select-Object -Last 1 + $LatestRunOfCMakeBuild | ConvertTo-Json | Set-Content -Path $LatestRunJson +} + +$LinuxArtifactZip = "$DownloadFolder/linux.zip" +$WindowsArtifactZip = "$DownloadFolder/win.zip" +$DownloadLinux = $NoCache -or !(Test-Path $LinuxArtifactZip) +$DownloadWindows = $NoCache -or !(Test-Path $WindowsArtifactZip) + +if ($DownloadWindows -or $DownloadLinux) +{ + # Download the artifacts + Write-Output "INFO: Downloading artifacts from $($LatestRunOfCMakeBuild.artifacts_url)" + $ServerResponse = Invoke-WebRequest -Uri $LatestRunOfCMakeBuild.artifacts_url -Headers $GithubApiHeaders | ConvertFrom-Json + + $LinuxArtifact = $ServerResponse.artifacts | Where-Object name -eq "czicompress-ubuntu-release-package-on" + $WindowsArtifact = $ServerResponse.artifacts | Where-Object name -eq "czicompress-windows-64-release-msvc-package-on" + + if ($ServerResponse.total_count -eq 0) { + throw "No artifacts found." + } + + try { + if ($DownloadLinux) + { + Invoke-WebRequest -Uri $LinuxArtifact.archive_download_url -Headers $GithubApiHeaders -OutFile $LinuxArtifactZip + } + + if ($DownloadWindows) + { + Invoke-WebRequest -Uri $WindowsArtifact.archive_download_url -Headers $GithubApiHeaders -OutFile $WindowsArtifactZip + } + } catch { + Write-Output "ERROR: unable to download artifacts." + throw + } +} else { + Write-Output "INFO: Using previously download artifact ZIP files in $DownloadFolder" +} + +# Extract libczicompressc binaries +Expand-Archive -Path $LinuxArtifactZip -Force -DestinationPath "$DownloadFolder" +Expand-Archive -Path $WindowsArtifactZip -Force -DestinationPath "$DownloadFolder" + +############################################# +# Part 2: Build and use the new nuget package +############################################# + +# Get the new library version +$NewLibVersion = (Get-Item "$DownloadFolder/libczicompressc.dll").VersionInfo.ProductVersion.Replace(",", ".") +$NewLibVersion_ = $NewLibVersion.Replace(".", "_") +$NewFileVersion = (Get-Item "$DownloadFolder/libczicompressc.dll").VersionInfo.FileVersionRaw + +$BranchName = "feature/upgrade-libczicompressc-$NewLibVersion_" +Write-Output "INFO: The new library version is $NewLibVersion => Create branch $BranchName and switch to it." + +if (![string]::IsNullOrEmpty($PSScriptRoot)) { + Set-Location "$PSScriptRoot/libczicompressc" +} else { + $current_dir_name = Get-Location | Split-Path -Leaf + if ("czishrink" -eq $current_dir_name) + { + Set-Location "libczicompressc" + } elseif ("libczicompress" -ne $current_dir_name) { + throw "Please CD to the /czishrink directory of a czicompress clone." + } +} + +# Stash any local changes +$GitStatus = git status --porcelain +if($LASTEXITCODE -ne 0) { + throw "git status failed" +} + +if (![string]::IsNullOrEmpty($GitStatus)) { + Write-Output "INFO: Stashing local changes" + git stash --include-untracked + if($LASTEXITCODE -ne 0) { + throw "git stash failed" + } +} + +# Switch to main and pull +git switch main +if($LASTEXITCODE -ne 0) { + throw "git switch failed" +} + +git pull +if($LASTEXITCODE -ne 0) { + throw "git pull failed" +} + +# Create a new branch +$gitSwitchCreateFlag = "-c" +if ($OverwriteExistingBranch) { + $gitSwitchCreateFlag = "-C" +} + +git switch $gitSwitchCreateFlag $BranchName +if($LASTEXITCODE -ne 0) { + throw "Failed to create branch $BranchName. Please delete the branch if it exists." +} + +# Put the binaries into the nuget folder structure +Write-Output "INFO: Creating the new nuget package..." +$libname="libczicompressc" +$LinuxRuntime="runtimes\linux-x64\native\$libname.so" +$WindowsRuntime="runtimes\win-x64\native\$libname.dll" +Copy-Item -Path "$DownloadFolder/$libname.so" -Destination $LinuxRuntime +Copy-Item -Path "$DownloadFolder/$libname.dll" -Destination $WindowsRuntime + +# Modify the nuspec +$nuspec=Get-Item "libczicompressc.nuspec" +$xml = [xml](Get-Content -Path $nuspec.FullName) +$xml.package.metadata.version = $NewLibVersion +$xml.package.metadata.repository.commit = $LatestRunOfCMakeBuild.head_sha +$xml.Save($nuspec.FullName) + +# Download nuget.exe if necessary and run nuget pack +if (!$NugetExePath) { + try { + $NugetExePath = (Get-Command "nuget.exe").Source + } catch { + $NugetExePath = "$DownloadFolder/nuget.exe" + } +} + +if (!(Test-Path -Path $NugetExePath)) { + Write-Output "INFO: Downloading nuget.exe to $NugetExePath" + Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $NugetExePath +} else { + Write-Output "INFO: Using nuget.exe at $NugetExePath" +} + +& $NugetExePath pack "libczicompressc.nuspec" +if($LASTEXITCODE -ne 0) { + throw "nuget failed" +} + +# Revert changes to so/dll +git checkout -- $LinuxRuntime +if($LASTEXITCODE -ne 0) { + throw "git checkout failed" +} + +git checkout -- $WindowsRuntime +if($LASTEXITCODE -ne 0) { + throw "git checkout failed" +} + +# Exchange the nupkg and update version in Directory.Packages.props +Remove-Item ../packages_local/*.nupkg +Move-Item -Path "libczicompressc.$NewLibVersion.nupkg" -Destination ../packages_local + +Write-Output "INFO: Updating Directory.Packages.props" +Set-Location .. +$file = Get-Item "Directory.Packages.props" +$xml = [xml](Get-Content -Path $file.FullName) +$versionElement = $xml.SelectSingleNode('//PackageVersion[@Include="libczicompressc"]') +$versionElement.Version = $NewLibVersion +$xml.Save($file.FullName) + +################################################ +# Part 3: Update, build, and test netczicompress +################################################ + +# Update PInvokeFileProcessor.cs +Write-Output "INFO: Updating PInvokeFileProcessor.cs" +$SourceCode = Get-Content -Path netczicompress/Models/PInvokeFileProcessor.cs +$NewVersionTuple="($($NewFileVersion.Major), $($NewFileVersion.Minor))" +$AlteredSourceCode = $SourceCode -replace '^( *\(int Major, int Minor\) expected = ).*?;$',('$1' + $NewVersionTuple + ";") +Set-Content -Path netczicompress/Models/PInvokeFileProcessor.cs -Value $AlteredSourceCode + +# Increment VersionSuffix +Write-Output "INFO: Incrementing VersionSuffix in Directory.Build.props" +$file = Get-Item "Directory.Build.props" +$xml = [xml](Get-Content -Path $file.FullName) +$versionElement = $xml.SelectSingleNode('//VersionSuffix') +$VersionTokens = $versionElement.'#text'.split(".") +$versionElement.'#comment' = $BranchName +$VersionTokens[1] = [string]([int]($VersionTokens.split(".")[1]) + 1) +$versionElement.'#text' = "$($VersionTokens[0]).$($VersionTokens[1])" +$xml.Save($file.FullName) + +# Git commit everything +Write-Output "INFO: Committing all changes" +$CommitMessage = "Upgrade $libname to $NewLibVersion" +git add . +if($LASTEXITCODE -ne 0) { + throw "git add failed" +} +git commit -m $CommitMessage +if($LASTEXITCODE -ne 0) { + throw "git commit failed" +} + +# Run tests +Write-Output "INFO: Run tests" +dotnet test +if($LASTEXITCODE -ne 0) { + throw "dotnet test failed" +} + +# Git Push +Write-Output "INFO: Push changes" + +$gitForceFlag = "" +if ($OverwriteExistingBranch) { + $gitForceFlag = "--force" +} + +git push $gitForceFlag --set-upstream origin $BranchName +if($LASTEXITCODE -ne 0) { + throw "git push failed" +} + +# Create a pull request +if ($CreatePullRequest) { + $remote = git config --get remote.origin.url + if($LASTEXITCODE -ne 0) { + throw "git config failed" + } + + $CziShrinkRepo = $remote.Replace("https://github.com/", "") -replace "\.git$", "" + + Write-Output "INFO: Create a Pull Request" + $postParams = @{ + 'title'=$CommitMessage + 'body'="Automatic upgrade of $libname" + 'head'=$BranchName + 'base'='main' + } | ConvertTo-Json + + $ServerResponse = Invoke-WebRequest -Headers $GithubApiHeaders -Uri https://api.github.com/repos/$CziShrinkRepo/pulls -Method POST -Body $postParams + $PullRequestUrl = ($ServerResponse | ConvertFrom-Json).html_url + Write-Output "Opened a PR at $PullRequestUrl" + Start-Process $PullRequestUrl +}