diff --git a/.ci/Dockerfile.linux b/.ci/Dockerfile.linux deleted file mode 100644 index b46f7ff..0000000 --- a/.ci/Dockerfile.linux +++ /dev/null @@ -1,7 +0,0 @@ -FROM dtmt-ci-base-linux - -COPY . /src/dtmt -COPY --from=dtmt-ci-base-linux /src/*.lib /src/*.so /src/dtmt/lib/oodle/ -RUN --mount=type=cache,id=cargo-registry,target=/cargo/registry \ - --mount=type=cache,id=cargo-target,target=/src/dtmt/target \ - cargo build --release --locked diff --git a/.ci/Dockerfile.msvc b/.ci/Dockerfile.msvc deleted file mode 100644 index e8c9c32..0000000 --- a/.ci/Dockerfile.msvc +++ /dev/null @@ -1,35 +0,0 @@ -FROM dtmt-ci-base-msvc - -# Create dummy crates and copy their Cargo.toml, so that dependencies can be cached -RUN set -e; \ - cargo new --bin crates/dtmt; \ - cargo new --bin crates/dtmm; \ - cargo new --lib lib/dtmt-shared; \ - cargo new --lib lib/nexusmods; \ - cargo new --lib lib/sdk; \ - cargo new --lib lib/serde_sjson; \ - cargo new --lib lib/ansi-parser - -COPY Cargo.toml Cargo.lock /src/dtmt/ -COPY crates/dtmt/Cargo.toml /src/dtmt/crates/dtmt/ -COPY crates/dtmm/Cargo.toml /src/dtmt/crates/dtmm/ -COPY lib/dtmt-shared/Cargo.toml /src/dtmt/lib/dtmt-shared/ -COPY lib/nexusmods/Cargo.toml /src/dtmt/lib/nexusmods/ -COPY lib/sdk/Cargo.toml /src/dtmt/lib/sdk/ -COPY lib/serde_sjson/Cargo.toml /src/dtmt/lib/serde_sjson/ -COPY lib/ansi-parser/Cargo.toml /src/dtmt/lib/ansi-parser/ - -# Crates with build scripts cannot be split that way, but they shouldn't change too often -COPY lib/luajit2-sys /src/dtmt/lib/luajit2-sys -COPY lib/oodle /src/dtmt/lib/oodle -# color-eyre needs to be copied, too, then, as it's used by `oodle` -COPY lib/color-eyre /src/dtmt/lib/color-eyre -COPY --from=dtmt-ci-base-msvc /src/*.lib /src/dtmt/lib/oodle/ - -RUN cargo build --release --target x86_64-pc-windows-msvc --locked -Zbuild-std -RUN rm -r crates lib - -COPY . /src/dtmt -COPY --from=dtmt-ci-base-msvc /src/*.lib /src/dtmt/lib/oodle/ - -RUN cargo build --release --target x86_64-pc-windows-msvc --frozen -Zbuild-std diff --git a/.ci/image/Dockerfile b/.ci/image/Dockerfile deleted file mode 100644 index a95968a..0000000 --- a/.ci/image/Dockerfile +++ /dev/null @@ -1,140 +0,0 @@ -# https://jake-shadle.github.io/xwin/ -FROM debian:bullseye-slim AS xwin - -# renovate: datasource=github-releases depName=xwin packageName=Jake-Shadle/xwin -ARG XWIN_VERSION=0.6.6 -ARG XWIN_PREFIX="xwin-$XWIN_VERSION-x86_64-unknown-linux-musl" -ADD https://github.com/Jake-Shadle/xwin/releases/download/$XWIN_VERSION/$XWIN_PREFIX.tar.gz /root/$XWIN_PREFIX.tar.gz - -RUN set -eux; \ - apt-get update; \ - apt-get install --no-install-recommends -y \ - tar \ - ; \ - # Install xwin to cargo/bin via github release. Note you could also just use `cargo install xwin`. - tar -xzv -f /root/$XWIN_PREFIX.tar.gz -C /usr/bin --strip-components=1 $XWIN_PREFIX/xwin; \ - apt-get remove -y --auto-remove; \ - rm -rf \ - /var/lib/apt/lists/* \ - /root/$XWIN_PREFIX.tar.gz; - -RUN set -eux; \ - # Splat the CRT and SDK files to /xwin/crt and /xwin/sdk respectively - xwin \ - --log-level debug \ - --cache-dir /root/.xwin-cache \ - --manifest-version 16 \ - --accept-license \ - splat \ - --output /xwin; \ - # Even though this build step only exists temporary, to copy the - # final data out of, it still generates a cache entry on the Docker host. - # And to keep that to a minimum, we still delete the stuff we don't need. - rm -rf /root/.xwin-cache; - -FROM rust:slim-bullseye AS linux - -RUN set -eux; \ - apt-get update; \ - apt-get install --no-install-recommends -y \ - build-essential \ - cmake \ - curl \ - git \ - gpg \ - jq \ - libatk1.0-dev \ - libclang-13-dev \ - libglib2.0-dev \ - libgtk-3-dev \ - libpango1.0-dev \ - libssl-dev \ - libzstd-dev \ - pkg-config; \ - apt-get remove -y --auto-remove; \ - rm -rf /var/lib/apt/lists/*; \ - rustup default nightly - -WORKDIR /src/dtmt - -COPY lib/oodle/*.so lib/oodle/*.a /src/ - -FROM linux AS msvc - -# renovate: datasource=github-releases depName=llvm packageName=llvm/llvm-project -ARG LLVM_VERSION=20 -ENV KEYRINGS /usr/local/share/keyrings - -ADD https://apt.llvm.org/llvm-snapshot.gpg.key /root/llvm-snapshot.gpg.key -ADD https://dl.winehq.org/wine-builds/winehq.key /root/winehq.key - -RUN set -eux; \ - mkdir -p $KEYRINGS; \ - # clang/lld/llvm - gpg --dearmor > $KEYRINGS/llvm.gpg < /root/llvm-snapshot.gpg.key; \ - # wine - gpg --dearmor > $KEYRINGS/winehq.gpg < /root/winehq.key; \ - echo "deb [signed-by=$KEYRINGS/llvm.gpg] http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-${LLVM_VERSION} main" > /etc/apt/sources.list.d/llvm.list; \ - echo "deb [signed-by=$KEYRINGS/winehq.gpg] https://dl.winehq.org/wine-builds/debian/ bullseye main" > /etc/apt/sources.list.d/winehq.list; \ - dpkg --add-architecture i386; \ - apt-get update; \ - apt-get install --no-install-recommends -y \ - libclang-${LLVM_VERSION}-dev \ - gcc-mingw-w64-x86-64 \ - clang-${LLVM_VERSION} \ - llvm-${LLVM_VERSION} \ - lld-${LLVM_VERSION} \ - winehq-staging \ - ; \ - # ensure that clang/clang++ are callable directly - ln -s clang-${LLVM_VERSION} /usr/bin/clang && ln -s clang /usr/bin/clang++ && ln -s lld-${LLVM_VERSION} /usr/bin/ld.lld; \ - # We also need to setup symlinks ourselves for the MSVC shims because they aren't in the debian packages - ln -s clang-${LLVM_VERSION} /usr/bin/clang-cl && ln -s llvm-ar-${LLVM_VERSION} /usr/bin/llvm-lib && ln -s lld-link-${LLVM_VERSION} /usr/bin/lld-link; \ - # Verify the symlinks are correct - clang++ -v; \ - ld.lld -v; \ - # Doesn't have an actual -v/--version flag, but it still exits with 0 - llvm-lib -v; \ - clang-cl -v; \ - lld-link --version; \ - # Use clang instead of gcc when compiling and linking binaries targeting the host (eg proc macros, build files) - update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100; \ - update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100; \ - update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld 100; \ - rustup target add x86_64-pc-windows-msvc; \ - rustup component add rust-src; \ - # Remove unneeded files to reduce image size - apt-get remove -y --auto-remove; \ - rm -rf \ - /var/lib/apt/lists/* \ - /root/*.key; - -COPY lib/oodle/*.lib /src -COPY --from=xwin /xwin /xwin - -# Note that we're using the full target triple for each variable instead of the -# simple CC/CXX/AR shorthands to avoid issues when compiling any C/C++ code for -# build dependencies that need to compile and execute in the host environment -ENV CC_x86_64_pc_windows_msvc="clang-cl" \ - CXX_x86_64_pc_windows_msvc="clang-cl" \ - AR_x86_64_pc_windows_msvc="llvm-lib" \ - # wine can be quite spammy with log messages and they're generally uninteresting - WINEDEBUG="-all" \ - # Use wine to run test executables - CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUNNER="wine" \ - # Note that we only disable unused-command-line-argument here since clang-cl - # doesn't implement all of the options supported by cl, but the ones it doesn't - # are _generally_ not interesting. - CL_FLAGS="-Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/xwin/crt/include /imsvc/xwin/sdk/include/ucrt /imsvc/xwin/sdk/include/um /imsvc/xwin/sdk/include/shared" \ - # Let cargo know what linker to invoke if you haven't already specified it - # in a .cargo/config.toml file - CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER="lld-link" \ - CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-Lnative=/xwin/crt/lib/x86_64 -Lnative=/xwin/sdk/lib/um/x86_64 -Lnative=/xwin/sdk/lib/ucrt/x86_64" - -# These are separate since docker/podman won't transform environment variables defined in the same ENV block -ENV CFLAGS_x86_64_pc_windows_msvc="$CL_FLAGS" \ - CXXFLAGS_x86_64_pc_windows_msvc="$CL_FLAGS" - -# Run wineboot just to setup the default WINEPREFIX so we don't do it every -# container run -RUN wine wineboot --init diff --git a/.ci/pipelines/base.yml b/.ci/pipelines/base.yml deleted file mode 100644 index 4e7ed14..0000000 --- a/.ci/pipelines/base.yml +++ /dev/null @@ -1,243 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/Config ---- - -# The actual CI pipeline that is run per branch -resource_types: -- name: gitea-package - type: registry-image - source: - repository: registry.sclu1034.dev/gitea-package - username: ((registry_user)) - password: ((registry_password)) - -- name: gitea-status - type: registry-image - source: - repository: registry.sclu1034.dev/gitea-status - username: ((registry_user)) - password: ((registry_password)) - -- name: gitea-pr - type: registry-image - source: - repository: registry.sclu1034.dev/gitea-pr - username: ((registry_user)) - password: ((registry_password)) - - -resources: -- name: repo - type: git - source: - uri: https://git.sclu1034.dev/bitsquid_dt/dtmt - branch: master - -- name: repo-pr - type: gitea-pr - source: - access_token: ((gitea_api_key)) - owner: ((owner)) - repo: ((repo)) - url: https://git.sclu1034.dev - -- name: gitea-package - type: gitea-package - source: - access_token: ((gitea_api_key)) - url: https://git.sclu1034.dev - owner: bitsquid_dt - type: generic - name: dtmt - - -- name: status-build-msvc - type: gitea-status - source: - access_token: ((gitea_api_key)) - url: https://git.sclu1034.dev - owner: bitsquid_dt - repo: dtmt - context: build/msvc - description: "Build for the target platform: msvc" - -- name: status-build-linux - type: gitea-status - source: - access_token: ((gitea_api_key)) - url: https://git.sclu1034.dev - owner: bitsquid_dt - repo: dtmt - context: build/linux - description: "Build for the target platform: linux" - - -jobs: -- name: set-pipelines - plan: - - in_parallel: - - get: repo-pr - trigger: true - - - get: repo - - - load_var: prs - file: repo-pr/prs.json - - - across: - - var: pr - values: ((.:prs)) - set_pipeline: dtmt-pr - file: repo/.ci/pipelines/pr.yml - public: true - vars: - pr: ((.:pr)) - gitea_api_key: ((gitea_api_key)) - registry_user: ((registry_user)) - registry_password: ((registry_password)) - instance_vars: - number: ((.:pr.number)) - - -- name: build-msvc - on_success: - put: state-success - resource: status-build-msvc - no_get: true - params: - state: success - sha: ((.:git_sha)) - - on_failure: - put: state-failure - resource: status-build-msvc - no_get: true - params: - state: failure - sha: ((.:git_sha)) - - plan: - - get: repo - trigger: true - - - load_var: git_sha - file: repo/.git/ref - - - put: state-pending - resource: status-build-msvc - no_get: true - params: - state: pending - sha: ((.:git_sha)) - - - task: build - file: repo/.ci/tasks/build.yml - vars: - pr: "" - target: msvc - registry_user: ((registry_user)) - registry_password: ((registry_password)) - - - load_var: version_number - reveal: true - file: artifact/version - - - put: package - resource: gitea-package - no_get: true - inputs: - - artifact - params: - version: ((.:version_number)) - fail_fast: true - override: true - globs: - - artifact/*.exe - - artifact/*.exe.sha256 - - - put: package - resource: gitea-package - no_get: true - inputs: - - artifact - params: - version: master - fail_fast: true - override: true - globs: - - artifact/*.exe - - artifact/*.exe.sha256 - -- name: build-linux - on_success: - put: state-success - resource: status-build-linux - no_get: true - params: - state: success - sha: ((.:git_sha)) - - on_failure: - put: state-failure - resource: status-build-linux - no_get: true - params: - state: failure - sha: ((.:git_sha)) - - plan: - - get: repo - trigger: true - - - load_var: git_sha - file: repo/.git/ref - - - put: state-pending - resource: status-build-linux - no_get: true - params: - state: pending - sha: ((.:git_sha)) - - - task: build - file: repo/.ci/tasks/build.yml - vars: - pr: "" - target: linux - gitea_url: https://git.sclu1034.dev - gitea_api_key: ((gitea_api_key)) - registry_user: ((registry_user)) - registry_password: ((registry_password)) - - - load_var: version_number - reveal: true - file: artifact/version - - - put: package - resource: gitea-package - no_get: true - inputs: - - artifact - params: - version: ((.:version_number)) - fail_fast: true - override: true - globs: - - artifact/dtmt - - artifact/dtmm - - artifact/dtmm.sha256 - - artifact/dtmt.sha256 - - - put: package - resource: gitea-package - no_get: true - inputs: - - artifact - params: - version: master - fail_fast: true - override: true - globs: - - artifact/dtmt - - artifact/dtmm - - artifact/dtmm.sha256 - - artifact/dtmt.sha256 diff --git a/.ci/pipelines/check.yml b/.ci/pipelines/check.yml deleted file mode 100644 index c8d5d47..0000000 --- a/.ci/pipelines/check.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- - -# The actual CI pipeline that is run per branch - -resources: -- name: repo - type: git - source: - uri: https://git.sclu1034.dev/bitsquid_dt/dtmt - branch: ((branch)) - -jobs: -- name: build-msvc - plan: - - get: repo - trigger: true - - task: build - file: repo/.ci/tasks/build.yml - vars: - target: msvc - registry_user: ((registry_user)) - registry_password: ((registry_password)) -- name: build-linux - plan: - - get: repo - trigger: true - - task: build - file: repo/.ci/tasks/build.yml - vars: - target: linux - registry_user: ((registry_user)) - registry_password: ((registry_password)) diff --git a/.ci/pipelines/pr.yml b/.ci/pipelines/pr.yml deleted file mode 100644 index 5c8d7cd..0000000 --- a/.ci/pipelines/pr.yml +++ /dev/null @@ -1,227 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/Config ---- - -# The actual CI pipeline that is run per branch -resource_types: -- name: gitea-package - type: registry-image - source: - repository: registry.sclu1034.dev/gitea-package - username: ((registry_user)) - password: ((registry_password)) - -- name: gitea-status - type: registry-image - source: - repository: registry.sclu1034.dev/gitea-status - username: ((registry_user)) - password: ((registry_password)) - - -resources: -- name: repo - type: git - source: - uri: https://git.sclu1034.dev/bitsquid_dt/dtmt - branch: ((pr.head.ref)) - -- name: gitea-package - type: gitea-package - source: - access_token: ((gitea_api_key)) - url: https://git.sclu1034.dev - owner: bitsquid_dt - type: generic - name: dtmt - -- name: pr-status-lint-clippy - type: gitea-status - source: - access_token: ((gitea_api_key)) - url: https://git.sclu1034.dev - owner: bitsquid_dt - repo: dtmt - context: lint/clippy - description: Checking for common mistakes and opportunities for code improvement - -- name: pr-status-build-msvc - type: gitea-status - source: - access_token: ((gitea_api_key)) - url: https://git.sclu1034.dev - owner: bitsquid_dt - repo: dtmt - context: build/msvc - description: "Build for the target platform: msvc" - -- name: pr-status-build-linux - type: gitea-status - source: - access_token: ((gitea_api_key)) - url: https://git.sclu1034.dev - owner: bitsquid_dt - repo: dtmt - context: build/linux - description: "Build for the target platform: linux" - - -jobs: -- name: clippy - on_success: - put: state-success - resource: pr-status-lint-clippy - no_get: true - params: - state: success - sha: ((.:git_sha)) - - on_failure: - put: state-failure - resource: pr-status-lint-clippy - no_get: true - params: - state: failure - sha: ((.:git_sha)) - - plan: - - get: repo - trigger: true - - - load_var: git_sha - file: repo/.git/ref - - - put: state-pending - resource: pr-status-lint-clippy - no_get: true - params: - state: pending - sha: ((.:git_sha)) - - - task: check - file: repo/.ci/tasks/clippy.yml - vars: - gitea_api_key: ((gitea_api_key)) - registry_user: ((registry_user)) - registry_password: ((registry_password)) - - -- name: build-msvc - on_success: - put: state-success - resource: pr-status-build-msvc - no_get: true - params: - state: success - sha: ((.:git_sha)) - - on_failure: - put: state-failure - resource: pr-status-build-msvc - no_get: true - params: - state: failure - sha: ((.:git_sha)) - - plan: - - get: repo - trigger: true - - - load_var: git_sha - file: repo/.git/ref - - - put: state-pending - resource: pr-status-build-msvc - no_get: true - params: - state: pending - sha: ((.:git_sha)) - - - task: build - file: repo/.ci/tasks/build.yml - vars: - target: msvc - pr: ((pr)) - gitea_url: https://git.sclu1034.dev - gitea_api_key: ((gitea_api_key)) - registry_user: ((registry_user)) - registry_password: ((registry_password)) - - - load_var: version_number - reveal: true - file: artifact/version - - - put: package - resource: gitea-package - no_get: true - inputs: - - artifact - params: - version: ((.:version_number)) - fail_fast: true - override: true - globs: - - artifact/dtmt - - artifact/dtmm - - artifact/*.exe - - artifact/*.sha256 - -- name: build-linux - on_success: - put: state-success - resource: pr-status-build-linux - no_get: true - params: - state: success - sha: ((.:git_sha)) - - on_failure: - put: state-failure - resource: pr-status-build-linux - no_get: true - params: - state: failure - sha: ((.:git_sha)) - - plan: - - get: repo - trigger: true - - - load_var: git_sha - file: repo/.git/ref - - - put: state-pending - resource: pr-status-build-linux - no_get: true - params: - state: pending - sha: ((.:git_sha)) - - - task: build - file: repo/.ci/tasks/build.yml - vars: - target: linux - pr: ((pr)) - gitea_url: https://git.sclu1034.dev - gitea_api_key: ((gitea_api_key)) - registry_user: ((registry_user)) - registry_password: ((registry_password)) - - - load_var: version_number - reveal: true - file: artifact/version - - - put: package - resource: gitea-package - no_get: true - inputs: - - artifact - params: - version: ((.:version_number)) - fail_fast: true - override: true - globs: - - artifact/dtmt - - artifact/dtmm - - artifact/*.exe - - artifact/*.sha256 - diff --git a/.ci/tasks/build.sh b/.ci/tasks/build.sh deleted file mode 100755 index b362266..0000000 --- a/.ci/tasks/build.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -set -eu - -if [ -n "$OUTPUT" ]; then - OUTPUT="$PWD/$OUTPUT" -else - OUTPUT=$(mktemp -d) -fi - -title() { - printf "\033[1m%s\033[0m\n" "$1" -} - -install_artifact() { - install -v -t "$OUTPUT/" "$1" - sha256sum "$1" | cut -d' ' -f1 > "$OUTPUT/$(basename "$1").sha256" -} - -cd "repo" - -PR=${PR:-} -ref=$(cat .git/ref || echo "HEAD") - -if [ -n "$PR" ]; then - title "PR: $(echo "$PR" | jq '.number') - $(echo "$PR" | jq '.title')" - ref="pr-$(echo "$PR" | jq '.number')-$(git rev-parse --short "$ref" 2>/dev/null || echo 'manual')" -elif [ -f ".git/branch" ]; then - ref=$(cat .git/branch)-$(git rev-parse --short "$ref") -else - ref=$(git rev-parse --short "$ref") -fi - -title "Version: '$ref'" -echo "$ref" > "$OUTPUT/version" - -case "$TARGET" in - msvc) - cp /src/*.lib ./lib/oodle/ - - title "Building project for target $TARGET" - cargo build --color always --locked --release --target x86_64-pc-windows-msvc -Zbuild-std - - title "Install artifacts" - install_artifact target/x86_64-pc-windows-msvc/release/dtmt.exe - install_artifact target/x86_64-pc-windows-msvc/release/dtmm.exe - ;; - linux) - cp /src/*.a ./lib/oodle/ - - title "Building project for target $TARGET" - cargo build --color always --locked --profile release-lto - - title "Installing artifacts" - install_artifact target/release-lto/dtmt - install_artifact target/release-lto/dtmm - ;; - *) - echo -e "\033[31;1mEnv var 'TARGET' must either be 'msvc' or 'linux'. Got '$TARGET'.\033[0m" >&2 - exit 1 -esac - -title "Done" diff --git a/.ci/tasks/build.yml b/.ci/tasks/build.yml deleted file mode 100644 index 9b9c094..0000000 --- a/.ci/tasks/build.yml +++ /dev/null @@ -1,31 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/TaskConfig ---- -platform: linux - -image_resource: - name: ctmt-bi-base-((target)) - type: registry-image - source: - repository: registry.sclu1034.dev/dtmt-ci-base-((target)) - username: ((registry_user)) - password: ((registry_password)) - tag: latest - -inputs: -- name: repo - -outputs: -- name: artifact - -caches: - - path: repo/target - - path: /usr/local/cargo/registry - -params: - CI: "true" - TARGET: ((target)) - PR: ((pr)) - OUTPUT: artifact - -run: - path: repo/.ci/tasks/build.sh diff --git a/.ci/tasks/clippy.sh b/.ci/tasks/clippy.sh deleted file mode 100755 index 7c27b5f..0000000 --- a/.ci/tasks/clippy.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -set -eu - -title() { - printf "\033[1m%s\033[0m\n" "$1" -} - -title "Install clippy" -rustup component add clippy - -title "Run clippy" -cargo clippy --color always --no-deps -- -D warnings - -title "Done" diff --git a/.ci/tasks/clippy.yml b/.ci/tasks/clippy.yml deleted file mode 100644 index 806dfd4..0000000 --- a/.ci/tasks/clippy.yml +++ /dev/null @@ -1,28 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/TaskConfig ---- -platform: linux - -image_resource: - name: dtmt-ci-base-linux - type: registry-image - source: - repository: registry.sclu1034.dev/dtmt-ci-base-linux - username: ((registry_user)) - password: ((registry_password)) - tag: latest - -inputs: -- name: repo - -caches: - - path: repo/target - - path: /usr/local/cargo/registry - -params: - CI: "true" - GITEA_API_KEY: ((gitea_api_key)) - -run: - path: .ci/tasks/clippy.sh - dir: repo - diff --git a/.ci/util/run.sh b/.ci/util/run.sh deleted file mode 100755 index 60c8112..0000000 --- a/.ci/util/run.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -set -ux - -script="$1" -context="$2" -desc="$3" - -if [ -z "$script" ]; then - echo "No script to run" >&2 - exit 1 -fi - -if [ -z "$context" ]; then - echo "Missing 'context' for CI status report" >&2 - exit 1 -fi - -if [ -z "$REF" ]; then - echo "Environment variable 'REF' must be set to a valid Git ref." >&2 - exit 1 -fi - -if [ -z "$GITEA_API_KEY" ]; then - echo "Environment variable 'GITEA_API_KEY' must be set." >&2 - exit 1 -fi - -notify() { - curl -X 'POST' \ - -H 'Content-Type: application/json' \ - -H 'Accept: application/json' \ - -H "Authorization: token $GITEA_API_KEY" \ - "https://git.sclu1034.dev/api/v1/repos/bitsquid_dt/dtmt/statuses/$REF" \ - --data @- <[a-z-]+?)(?: depName=(?.+?))? packageName=(?.+?)(?: versioning=(?[a-z-]+?))?\\s(?:ENV|ARG) .+?_VERSION=(?.+?)\\s" - ] - } - ], - "packageRules": [ - { - "matchDatasources": [ - "github-releases" - ], - "matchPackageNames": [ - "llvm/llvm-project" - ], - "extractVersion": "^llvmorg-(?\\d+)\\.\\d+\\.\\d+$" - } - ] -} diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1bfb0dd..7c100b3 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -2,33 +2,6 @@ == [Unreleased] -=== Added - -- dtmt: split `build` into `build` and `package` -- dtmt: implement deploying built bundles -- dtmm: indicate when a deployment is necessary -- dtmm: check for Steam game update before deployment -- dtmm: remove unused bundles from previous deployment -- dtmm: show dialog for critical errors -- dtmm: check mod order before deployment -- dtmt: add mod dependencies to config -- dtmm: match mods to Nexus and check for updates -- dtmt: add utility to migrate mod projects -- dtmm: reset dtkit-patch installations -- sdk: implement decompiling Lua files -- dtmm: fetch cover image for Nexus mods -- dtmm: fetch file version for Nexus mods -- dtmm: handle `nxm://` URIs via IPC and import the corresponding mod -- dtmm: Add button to open mod on nexusmods.com -- dtmt: Implement commands to list bundles and contents -- dtmt: Implement command to search for files - -=== Fixed - -- all: force unix path separators for engine values -- dtmt: fix extracing files with non-flattened file names -- oodle: fix static linking - == 2023-03-01 === Added diff --git a/Cargo.lock b/Cargo.lock index efa4c9d..30efb97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ "gimli", ] @@ -18,114 +18,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] -name = "adler2" -version = "2.0.0" +name = "aes" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", + "opaque-debug", +] [[package]] name = "aho-corasick" -version = "1.1.3" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] -[[package]] -name = "ansi-parser" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43e7fd8284f025d0bd143c2855618ecdf697db55bde39211e5c9faec7669173" -dependencies = [ - "heapless", - "nom 7.1.3", -] - -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "anstream" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - -[[package]] -name = "anstyle-parse" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" - -[[package]] -name = "arbitrary" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" -dependencies = [ - "derive_arbitrary", -] - -[[package]] -name = "arrayref" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" +checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" [[package]] name = "arrayvec" -version = "0.7.6" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "associative-cache" @@ -135,13 +58,13 @@ checksum = "46016233fc1bb55c23b856fe556b7db6ccd05119a0a392e04f0b3b7c79058f16" [[package]] name = "async-recursion" -version = "1.1.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" +checksum = "3b015a331cc64ebd1774ba119538573603427eaace0a1950c423ab971f903796" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", + "syn", ] [[package]] @@ -151,7 +74,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39991bc421ddf72f70159011b323ff49b0f783cc676a7287c59453da2e2531cf" dependencies = [ "atk-sys", - "bitflags 1.3.2", + "bitflags", "glib", "libc", ] @@ -168,83 +91,53 @@ dependencies = [ "system-deps", ] -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - [[package]] name = "autocfg" -version = "1.3.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" dependencies = [ "addr2line", "cc", "cfg-if", "libc", - "miniz_oxide 0.7.4", + "miniz_oxide", "object", "rustc-demangle", ] [[package]] -name = "base64" -version = "0.13.1" +name = "base64ct" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "bincode" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740" -dependencies = [ - "bincode_derive", - "serde", - "unty", -] - -[[package]] -name = "bincode_derive" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09" -dependencies = [ - "virtue", -] +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bindgen" -version = "0.72.0" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f72209734318d0b619a5e0f5129918b848c416e122a3c4ce054e03cb87b726f" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ - "bitflags 2.9.1", + "bitflags", "cexpr", "clang-sys", - "itertools", + "lazy_static", + "lazycell", "log", - "prettyplease", + "peeking_take_while", "proc-macro2", "quote", "regex", - "rustc-hash 2.1.0", + "rustc-hash", "shlex", - "syn 2.0.100", + "syn", + "which", ] [[package]] @@ -253,12 +146,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - [[package]] name = "bitmaps" version = "2.1.0" @@ -276,59 +163,67 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "block-buffer" -version = "0.10.4" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] [[package]] -name = "bumpalo" -version = "3.16.0" +name = "bstr" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "5ffdb39cb703212f3c11973452c2861b972f757b021158f3516ba10f2fa8b2c1" +dependencies = [ + "memchr", + "once_cell", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "bytecount" -version = "0.6.8" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" - -[[package]] -name = "bytemuck" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" +checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" [[package]] name = "byteorder" -version = "1.5.0" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.7.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "bzip2" -version = "0.5.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" dependencies = [ "bzip2-sys", + "libc", ] [[package]] name = "bzip2-sys" -version = "0.1.13+1.0.8" +version = "0.1.11+1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" dependencies = [ "cc", + "libc", "pkg-config", ] @@ -338,12 +233,12 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3125b15ec28b84c238f6f476c6034016a5f6cc0221cb514ca46c532139fc97d" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cairo-sys-rs", "glib", "libc", "once_cell", - "thiserror 1.0.63", + "thiserror", ] [[package]] @@ -359,13 +254,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.27" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", - "libc", - "shlex", ] [[package]] @@ -374,17 +267,16 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" dependencies = [ - "nom 7.1.3", + "nom", ] [[package]] name = "cfg-expr" -version = "0.15.8" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" +checksum = "b0357a6402b295ca3a86bc148e84df46c02e41f41fef186bda662557ef6328aa" dependencies = [ "smallvec", - "target-lexicon", ] [[package]] @@ -394,10 +286,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "clang-sys" -version = "1.8.1" +name = "cipher" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +dependencies = [ + "generic-array", +] + +[[package]] +name = "clang-sys" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" dependencies = [ "glob", "libc", @@ -406,66 +307,63 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.40" +version = "4.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" +checksum = "2f3061d6db6d8fcbbd4b05e057f2acace52e64e96b498c08c2d7a4e65addd340" dependencies = [ - "clap_builder", + "bitflags", "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" -dependencies = [ - "anstream", - "anstyle", "clap_lex", + "is-terminal", + "once_cell", "strsim", + "termcolor", "unicase", - "unicode-width 0.2.0", + "unicode-width", ] [[package]] name = "clap_derive" -version = "4.5.40" +version = "4.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" +checksum = "34d122164198950ba84a918270a3bb3f7ededd25e15f7451673d986f55bd2667" dependencies = [ - "heck 0.5.0", + "heck", + "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.100", + "syn", ] [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" +dependencies = [ + "os_str_bytes", +] [[package]] name = "cli-table" -version = "0.5.0" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14da8d951cef7cc4f13ccc9b744d736963d57863c7e6fc33c070ea274546082c" +checksum = "adfbb116d9e2c4be7011360d0c0bee565712c11e969c9609b25b619366dc379d" dependencies = [ "cli-table-derive", "termcolor", - "unicode-width 0.2.0", + "unicode-width", ] [[package]] name = "cli-table-derive" -version = "0.5.0" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7c1b60bae2c3d45228dfb096046aa51ef6c300de70b658d7a13fcb0c4f832e" +checksum = "2af3bfb9da627b0a6c467624fb7963921433774ed435493b5c08a3053e829ad4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", + "syn", ] [[package]] @@ -485,7 +383,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" dependencies = [ - "bitflags 1.3.2", + "bitflags", "block", "cocoa-foundation", "core-foundation", @@ -497,14 +395,15 @@ dependencies = [ [[package]] name = "cocoa-foundation" -version = "0.1.2" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7" +checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" dependencies = [ - "bitflags 1.3.2", + "bitflags", "block", "core-foundation", "core-graphics-types", + "foreign-types", "libc", "objc", ] @@ -512,28 +411,23 @@ dependencies = [ [[package]] name = "color-eyre" version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" dependencies = [ - "ansi-parser", "backtrace", "color-spantrace", "eyre", "indenter", "once_cell", "owo-colors", - "pretty_assertions", - "thiserror 1.0.63", - "tracing", "tracing-error", - "tracing-subscriber", - "url", - "wasm-bindgen-test", ] [[package]] name = "color-spantrace" -version = "0.2.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" dependencies = [ "once_cell", "owo-colors", @@ -541,34 +435,16 @@ dependencies = [ "tracing-error", ] -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - -[[package]] -name = "colorchoice" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" - -[[package]] -name = "colors-transform" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9226dbc05df4fb986f48d730b001532580883c4c06c5d1c213f4b34c1c157178" - [[package]] name = "confy" -version = "1.0.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29222b549d4e3ded127989d523da9e928918d0d0d7f7c1690b439d0d538bae9" +checksum = "e37668cb35145dcfaa1931a5f37fde375eeae8068b4c0d2f289da28a270b2d2c" dependencies = [ "directories", "serde", - "thiserror 2.0.12", - "toml 0.8.19", + "thiserror", + "toml", ] [[package]] @@ -582,10 +458,16 @@ dependencies = [ ] [[package]] -name = "core-foundation" -version = "0.9.4" +name = "constant_time_eq" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys", "libc", @@ -593,9 +475,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.7" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "core-graphics" @@ -603,7 +485,7 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", "core-graphics-types", "foreign-types", @@ -612,12 +494,13 @@ dependencies = [ [[package]] name = "core-graphics-types" -version = "0.1.3" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" +checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", + "foreign-types", "libc", ] @@ -635,33 +518,27 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.13" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] [[package]] -name = "crc" -version = "3.2.1" +name = "crc32fast" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "crc-catalog", + "cfg-if", ] [[package]] -name = "crc-catalog" -version = "2.4.0" +name = "crossbeam-utils" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" - -[[package]] -name = "crc32fast" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ "cfg-if", ] @@ -678,10 +555,11 @@ dependencies = [ [[package]] name = "csv-async" -version = "1.3.1" +version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "888dbb0f640d2c4c04e50f933885c7e9c95995d93cec90aba8735b4c610f26f1" +checksum = "c652d4c48e4dc80b26fadd169c02fb6053d9f57507ddd3e6b8706e7d0242235e" dependencies = [ + "bstr", "cfg-if", "csv-core", "futures", @@ -694,61 +572,29 @@ dependencies = [ [[package]] name = "csv-core" -version = "0.1.11" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" dependencies = [ "memchr", ] -[[package]] -name = "data-url" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d7439c3735f405729d52c3fbbe4de140eaf938a1fe47d227c27f8254d4302a5" - -[[package]] -name = "deranged" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" -dependencies = [ - "powerfmt", - "serde", -] - -[[package]] -name = "derive_arbitrary" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30542c1ad912e0e3d22a1935c290e12e8a29d704a420177a31faad4a601a0800" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", -] - -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - [[package]] name = "digest" -version = "0.10.7" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer", "crypto-common", + "subtle", ] [[package]] name = "directories" -version = "6.0.0" +version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210" dependencies = [ "dirs-sys", ] @@ -765,14 +611,13 @@ dependencies = [ [[package]] name = "dirs-sys" -version = "0.5.0" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", - "option-ext", - "redox_users 0.5.0", - "windows-sys 0.59.0", + "redox_users", + "winapi", ] [[package]] @@ -782,32 +627,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", - "redox_users 0.4.6", + "redox_users", "winapi", ] [[package]] name = "displaydoc" -version = "0.2.5" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +checksum = "3bf95dc3f046b9da4f2d51833c0d3547d8564ef6910f5c1ed130306a75b92886" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", + "syn", ] -[[package]] -name = "doctest-file" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aac81fa3e28d21450aa4d2ac065992ba96a1d7303efbce51a95f4fd175b67562" - [[package]] name = "druid" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ece41814b410c87e6379441caa7316539500b2e387b8d691f2ba5c0f4aff631" +version = "0.8.2" +source = "git+https://github.com/linebender/druid.git#5fa4ce51ed3d74640388de6385f135c50d346c8d" dependencies = [ "console_error_panic_hook", "druid-derive", @@ -818,36 +656,31 @@ dependencies = [ "fnv", "im", "instant", - "resvg", - "tiny-skia", "tracing", "tracing-subscriber", "tracing-wasm", "unic-langid", "unicode-segmentation", - "usvg", "xi-unicode", ] [[package]] name = "druid-derive" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808d664482b1888a2ccb7f4dc9fa24165174d65ba96726315964064bdbc7d6cb" +version = "0.5.0" +source = "git+https://github.com/linebender/druid.git#5fa4ce51ed3d74640388de6385f135c50d346c8d" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "druid-shell" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7682d9c8fbf934504c30970775bfcfba7858a600f2f6e56bed331989958350fc" +version = "0.8.0" +source = "git+https://github.com/linebender/druid.git#5fa4ce51ed3d74640388de6385f135c50d346c8d" dependencies = [ "anyhow", - "bitflags 1.3.2", + "bitflags", "block", "cairo-rs", "cfg-if", @@ -873,53 +706,26 @@ dependencies = [ "wio", ] -[[package]] -name = "druid-widget-nursery" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe4e3cbc027e5c9a4f1c135b339ac92aaf99681a7c1b51ff63111b5719194e5" -dependencies = [ - "druid", - "log", - "tracing", -] - [[package]] name = "dtmm" version = "0.1.0" dependencies = [ - "ansi-parser", - "async-recursion", - "bincode", - "bitflags 2.9.1", + "bitflags", "clap", "color-eyre", - "colors-transform", "confy", "druid", - "druid-widget-nursery", "dtmt-shared", "futures", - "interprocess", - "lazy_static", - "luajit2-sys", - "minijinja", - "nexusmods", "oodle", - "open", - "path-slash", "sdk", "serde", "serde_sjson", - "strip-ansi-escapes", - "time", "tokio", "tokio-stream", "tracing", "tracing-error", "tracing-subscriber", - "usvg", - "winres", "zip", ] @@ -927,7 +733,6 @@ dependencies = [ name = "dtmt" version = "0.3.0" dependencies = [ - "async-recursion", "clap", "cli-table", "color-eyre", @@ -937,19 +742,16 @@ dependencies = [ "futures", "futures-util", "glob", - "luajit2-sys", - "minijinja", + "libloading", "nanorand", - "notify", "oodle", "path-clean", - "path-slash", "pin-project-lite", "promptly", "sdk", "serde", "serde_sjson", - "shlex", + "string_template", "tempfile", "tokio", "tokio-stream", @@ -963,10 +765,7 @@ dependencies = [ name = "dtmt-shared" version = "0.1.0" dependencies = [ - "ansi_term", - "color-eyre", "serde", - "steamlocate", "time", "tracing", "tracing-error", @@ -987,18 +786,9 @@ dependencies = [ [[package]] name = "either" -version = "1.13.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "endian-type" @@ -1007,19 +797,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" [[package]] -name = "equivalent" -version = "1.0.1" +name = "errno" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] [[package]] -name = "errno" -version = "0.3.11" +name = "errno-dragonfly" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ + "cc", "libc", - "windows-sys 0.59.0", ] [[package]] @@ -1034,9 +829,9 @@ dependencies = [ [[package]] name = "eyre" -version = "0.6.12" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" dependencies = [ "indenter", "once_cell", @@ -1044,81 +839,56 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.3.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - -[[package]] -name = "fd-lock" -version = "3.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ - "cfg-if", - "rustix 0.38.34", - "windows-sys 0.48.0", + "instant", ] [[package]] -name = "fdeflate" -version = "0.3.4" +name = "fd-lock" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f9bfee30e4dedf0ab8b422f03af778d9612b63f502710fc500a334ebe2de645" +checksum = "8ef1a30ae415c3a691a4f41afddc2dbcd6d70baf338368d85ebc1e8ed92cedb9" dependencies = [ - "simd-adler32", + "cfg-if", + "rustix", + "windows-sys 0.45.0", ] [[package]] name = "field-offset" -version = "0.3.6" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +checksum = "1e1c54951450cbd39f3dbcf1005ac413b49487dabf18a720ad2383eccfeffb92" dependencies = [ - "memoffset 0.9.1", + "memoffset", "rustc_version", ] -[[package]] -name = "filetime" -version = "0.2.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf401df4a4e3872c4fe8151134cf483738e74b67fc934d6532c882b3d24a4550" -dependencies = [ - "cfg-if", - "libc", - "libredox", - "windows-sys 0.59.0", -] - [[package]] name = "flate2" -version = "1.1.1" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" dependencies = [ "crc32fast", - "libz-rs-sys", - "miniz_oxide 0.8.8", + "miniz_oxide", ] -[[package]] -name = "float-cmp" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" - [[package]] name = "fluent-bundle" -version = "0.15.3" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe0a21ee80050c678013f82edf4b705fe2f26f1f9877593d13198612503f493" +checksum = "e242c601dec9711505f6d5bbff5bedd4b61b2469f2e8bb8e57ee7c9747a87ffd" dependencies = [ "fluent-langneg", "fluent-syntax", "intl-memoizer", "intl_pluralrules", - "rustc-hash 1.1.0", - "self_cell 0.10.3", + "rustc-hash", + "self_cell", "smallvec", "unic-langid", ] @@ -1134,11 +904,11 @@ dependencies = [ [[package]] name = "fluent-syntax" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a530c4694a6a8d528794ee9bbd8ba0122e779629ac908d15ad5a7ae7763a33d" +checksum = "c0abed97648395c902868fee9026de96483933faa54ea3b40d652f7dfe61ca78" dependencies = [ - "thiserror 1.0.63", + "thiserror", ] [[package]] @@ -1147,27 +917,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "fontconfig-parser" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1fcfcd44ca6e90c921fee9fa665d530b21ef1327a4c1a6c5250ea44b776ada7" -dependencies = [ - "roxmltree 0.20.0", -] - -[[package]] -name = "fontdb" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52186a39c335aa6f79fc0bf1c3cf854870b6ad4e50a7bb8a59b4ba1331f478a" -dependencies = [ - "fontconfig-parser", - "log", - "memmap2", - "ttf-parser", -] - [[package]] name = "foreign-types" version = "0.3.2" @@ -1183,35 +932,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - [[package]] name = "fs_extra" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - [[package]] name = "futures" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" dependencies = [ "futures-channel", "futures-core", @@ -1224,9 +955,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", "futures-sink", @@ -1234,15 +965,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-executor" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" dependencies = [ "futures-core", "futures-task", @@ -1251,38 +982,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-macro" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", + "syn", ] [[package]] name = "futures-sink" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-util" -version = "0.3.31" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-channel", "futures-core", @@ -1302,7 +1033,7 @@ version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9cb33da481c6c040404a11f8212d193889e9b435db2c14fd86987f630d3ce1" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cairo-rs", "gdk-pixbuf", "gdk-sys", @@ -1318,7 +1049,7 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3578c60dee9d029ad86593ed88cb40f35c1b83360e12498d055022385dd9a05" dependencies = [ - "bitflags 1.3.2", + "bitflags", "gdk-pixbuf-sys", "gio", "glib", @@ -1357,9 +1088,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.7" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", "version_check", @@ -1367,42 +1098,20 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasi 0.14.2+wasi-0.2.4", -] - -[[package]] -name = "gif" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" -dependencies = [ - "color_quant", - "weezl", + "wasi", ] [[package]] name = "gimli" -version = "0.29.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" [[package]] name = "gio" @@ -1410,7 +1119,7 @@ version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a1c84b4534a290a29160ef5c6eff2a9c95833111472e824fc5cb78b513dd092" dependencies = [ - "bitflags 1.3.2", + "bitflags", "futures-channel", "futures-core", "futures-io", @@ -1421,7 +1130,7 @@ dependencies = [ "once_cell", "pin-project-lite", "smallvec", - "thiserror 1.0.63", + "thiserror", ] [[package]] @@ -1439,11 +1148,11 @@ dependencies = [ [[package]] name = "glib" -version = "0.16.9" +version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16aa2475c9debed5a32832cb5ff2af5a3f9e1ab9e69df58eaadc1ab2004d6eba" +checksum = "ddd4df61a866ed7259d6189b8bcb1464989a77f1d85d25d002279bbe9dd38b2f" dependencies = [ - "bitflags 1.3.2", + "bitflags", "futures-channel", "futures-core", "futures-executor", @@ -1456,22 +1165,22 @@ dependencies = [ "libc", "once_cell", "smallvec", - "thiserror 1.0.63", + "thiserror", ] [[package]] name = "glib-macros" -version = "0.16.8" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb1a9325847aa46f1e96ffea37611b9d51fc4827e67f79e7de502a297560a67b" +checksum = "e084807350b01348b6d9dbabb724d1a0bb987f47a2c85de200e98e12e30733bf" dependencies = [ "anyhow", - "heck 0.4.1", + "heck", "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -1486,9 +1195,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "gobject-sys" @@ -1508,7 +1217,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4d3507d43908c866c805f74c9dd593c0ce7ba5c38e576e41846639cdcd4bee6" dependencies = [ "atk", - "bitflags 1.3.2", + "bitflags", "cairo-rs", "field-offset", "futures-channel", @@ -1544,61 +1253,23 @@ dependencies = [ [[package]] name = "gtk3-macros" -version = "0.16.3" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "096eb63c6fedf03bafe65e5924595785eaf1bcb7200dac0f2cbe9c9738f05ad8" +checksum = "8cfd6557b1018b773e43c8de9d0d13581d6b36190d0501916cbec4731db5ccff" dependencies = [ "anyhow", "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", -] - -[[package]] -name = "h2" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hash32" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" -dependencies = [ - "byteorder", + "syn", ] [[package]] name = "hashbrown" -version = "0.14.5" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - -[[package]] -name = "heapless" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" -dependencies = [ - "hash32", - "stable_deref_trait", -] +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" @@ -1607,282 +1278,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "heck" -version = "0.5.0" +name = "hermit-abi" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] [[package]] name = "hermit-abi" -version = "0.3.9" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] -name = "home" -version = "0.5.11" +name = "hmac" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "windows-sys 0.59.0", -] - -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" -dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" - -[[package]] -name = "hyper" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-rustls" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" -dependencies = [ - "futures-util", - "http", - "hyper", - "hyper-util", - "rustls", - "rustls-pki-types", - "tokio", - "tokio-rustls", - "tower-service", -] - -[[package]] -name = "hyper-tls" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" -dependencies = [ - "bytes", - "http-body-util", - "hyper", - "hyper-util", - "native-tls", - "tokio", - "tokio-native-tls", - "tower-service", -] - -[[package]] -name = "hyper-util" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c293b6b3d21eca78250dc7dbebd6b9210ec5530e038cbfe0661b5c47ab06e8" -dependencies = [ - "base64 0.22.1", - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "http", - "http-body", - "hyper", - "ipnet", - "libc", - "percent-encoding", - "pin-project-lite", - "socket2", - "system-configuration", - "tokio", - "tower-service", - "tracing", - "windows-registry", -] - -[[package]] -name = "icu_collections" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" -dependencies = [ - "displaydoc", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_locid" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_locid_transform" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_locid_transform_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_locid_transform_data" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d" - -[[package]] -name = "icu_normalizer" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_normalizer_data", - "icu_properties", - "icu_provider", - "smallvec", - "utf16_iter", - "utf8_iter", - "write16", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7" - -[[package]] -name = "icu_properties" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_locid_transform", - "icu_properties_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2" - -[[package]] -name = "icu_provider" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_provider_macros", - "stable_deref_trait", - "tinystr", - "writeable", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_provider_macros" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", -] - -[[package]] -name = "idna" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" -dependencies = [ - "idna_adapter", - "smallvec", - "utf8_iter", -] - -[[package]] -name = "idna_adapter" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" -dependencies = [ - "icu_normalizer", - "icu_properties", + "digest", ] [[package]] @@ -1900,20 +1316,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "image" -version = "0.24.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "jpeg-decoder", - "num-traits", - "png", -] - [[package]] name = "indenter" version = "0.3.3" @@ -1922,39 +1324,19 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "2.4.0" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ - "equivalent", + "autocfg", "hashbrown", ] -[[package]] -name = "inotify" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3" -dependencies = [ - "bitflags 2.9.1", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - [[package]] name = "instant" -version = "0.1.13" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", "js-sys", @@ -1962,24 +1344,11 @@ dependencies = [ "web-sys", ] -[[package]] -name = "interprocess" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d941b405bd2322993887859a8ee6ac9134945a24ec5ec763a8a962fc64dfec2d" -dependencies = [ - "doctest-file", - "libc", - "recvmsg", - "widestring", - "windows-sys 0.52.0", -] - [[package]] name = "intl-memoizer" -version = "0.5.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe22e020fce238ae18a6d5d8c502ee76a52a6e880d99477657e6acc30ec57bda" +checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f" dependencies = [ "type-map", "unic-langid", @@ -1995,94 +1364,48 @@ dependencies = [ ] [[package]] -name = "io-uring" -version = "0.7.8" +name = "io-lifetimes" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ - "bitflags 2.9.1", - "cfg-if", "libc", + "windows-sys 0.45.0", ] [[package]] -name = "ipnet" -version = "2.9.0" +name = "is-terminal" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" - -[[package]] -name = "iri-string" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbc5ebe9c3a1a7a5127f920a418f7585e9e758e911d0466ed004f393b0e380b2" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" dependencies = [ - "memchr", - "serde", -] - -[[package]] -name = "is-docker" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" -dependencies = [ - "once_cell", -] - -[[package]] -name = "is-wsl" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" -dependencies = [ - "is-docker", - "once_cell", -] - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", ] [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "jobserver" -version = "0.1.32" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" dependencies = [ "libc", ] -[[package]] -name = "jpeg-decoder" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" - [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ - "once_cell", "wasm-bindgen", ] @@ -2092,65 +1415,14 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7668b7cff6a51fe61cdde64cd27c8a220786f399501b57ebe36f7d8112fd68" dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "keyvalues-parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4c8354918309196302015ac9cae43362f1a13d0d5c5539a33b4c2fd2cd6d25" -dependencies = [ - "pest", - "pest_derive", - "thiserror 1.0.63", -] - -[[package]] -name = "keyvalues-serde" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0447866c47c00f8bd1949618e8f63017cf93e985b4684dc28d784527e2882390" -dependencies = [ - "keyvalues-parser", - "serde", - "thiserror 1.0.63", -] - -[[package]] -name = "kqueue" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" -dependencies = [ - "bitflags 1.3.2", - "libc", + "bitflags", ] [[package]] name = "kurbo" -version = "0.8.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a53776d271cfb873b17c618af0298445c88afc52837f3e948fa3fafd131f449" -dependencies = [ - "arrayvec", -] - -[[package]] -name = "kurbo" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd85a5776cd9500c2e2059c8c76c3b01528566b7fcbaf8098b55a33fc298849b" +checksum = "e119590a03caff1f7a582e8ee8c2164ddcc975791701188132fd1d1b518d3871" dependencies = [ "arrayvec", "serde", @@ -2158,81 +1430,53 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.5.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libloading" -version = "0.8.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", - "windows-targets 0.48.5", -] - -[[package]] -name = "libredox" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" -dependencies = [ - "bitflags 2.9.1", - "libc", - "redox_syscall", -] - -[[package]] -name = "libz-rs-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6489ca9bd760fe9642d7644e827b0c9add07df89857b0416ee15c1cc1a3b8c5a" -dependencies = [ - "zlib-rs", + "winapi", ] [[package]] name = "linux-raw-sys" -version = "0.4.14" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "linux-raw-sys" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" - -[[package]] -name = "litemap" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856" - -[[package]] -name = "lockfree-object-pool" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "log" -version = "0.4.22" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] [[package]] name = "luajit2-sys" version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33bb7acccd5a0224645ba06eba391af5f7194ff1762c2545860b43afcfd41af2" dependencies = [ - "bindgen", "cc", "fs_extra", "libc", @@ -2253,7 +1497,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata 0.1.10", + "regex-automata", ] [[package]] @@ -2264,18 +1508,9 @@ checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "memchr" -version = "2.7.4" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "memmap2" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" -dependencies = [ - "libc", -] +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" @@ -2286,40 +1521,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "memoffset" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" -dependencies = [ - "autocfg", -] - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "minicov" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71e683cd655513b99affab7d317deb690528255a0d5f717f1024093c12b169" -dependencies = [ - "cc", - "walkdir", -] - -[[package]] -name = "minijinja" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e60ac08614cc09062820e51d5d94c2fce16b94ea4e5003bb81b99a95f84e876" -dependencies = [ - "serde", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2328,75 +1529,30 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" dependencies = [ "adler", - "simd-adler32", -] - -[[package]] -name = "miniz_oxide" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" -dependencies = [ - "adler2", ] [[package]] name = "mio" -version = "1.0.2" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ - "hermit-abi", "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.52.0", + "wasi", + "windows-sys 0.45.0", ] [[package]] name = "nanorand" -version = "0.8.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3d189da485332e96ba8a5ef646a311871abd7915bf06ac848a9117f19cf6e4" - -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] -name = "nexusmods" -version = "0.1.0" -dependencies = [ - "futures", - "lazy_static", - "regex", - "reqwest", - "serde", - "serde_json", - "thiserror 2.0.12", - "time", - "tokio", - "tracing", - "url", -] +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" [[package]] name = "nibble_vec" @@ -2413,11 +1569,11 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cc", "cfg-if", "libc", - "memoffset 0.6.5", + "memoffset", ] [[package]] @@ -2430,51 +1586,17 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nom" -version = "8.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" -dependencies = [ - "memchr", -] - [[package]] name = "nom_locate" -version = "5.0.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b577e2d69827c4740cba2b52efaad1c4cc7c73042860b199710b3575c68438d" +checksum = "b1e299bf5ea7b212e811e71174c5d1a5d065c4c0ad0c8691ecb1f97e3e66025e" dependencies = [ "bytecount", "memchr", - "nom 8.0.0", + "nom", ] -[[package]] -name = "notify" -version = "8.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fee8403b3d66ac7b26aee6e40a897d85dc5ce26f44da36b8b73e987cc52e943" -dependencies = [ - "bitflags 2.9.1", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "log", - "mio", - "notify-types", - "walkdir", - "windows-sys 0.59.0", -] - -[[package]] -name = "notify-types" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d" - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2486,25 +1608,20 @@ dependencies = [ ] [[package]] -name = "num-conv" -version = "0.1.0" +name = "num_cpus" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "autocfg", + "hermit-abi 0.2.6", + "libc", ] [[package]] name = "num_threads" -version = "0.1.7" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" dependencies = [ "libc", ] @@ -2520,18 +1637,18 @@ dependencies = [ [[package]] name = "object" -version = "0.36.3" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.19.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "oodle" @@ -2543,65 +1660,16 @@ dependencies = [ ] [[package]] -name = "open" -version = "5.3.2" +name = "opaque-debug" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2483562e62ea94312f3576a7aca397306df7990b8d89033e18766744377ef95" -dependencies = [ - "is-wsl", - "libc", - "pathdiff", -] +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "openssl" -version = "0.10.66" +name = "os_str_bytes" +version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags 2.9.1", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "overload" @@ -2621,7 +1689,7 @@ version = "0.16.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdff66b271861037b89d028656184059e03b0b6ccb36003820be19f7200b1e94" dependencies = [ - "bitflags 1.3.2", + "bitflags", "gio", "glib", "libc", @@ -2647,7 +1715,7 @@ version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16ad2ec87789371b551fd2367c10aa37060412ffd3e60abd99491b21b93a3f9b" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cairo-rs", "glib", "libc", @@ -2668,6 +1736,17 @@ dependencies = [ "system-deps", ] +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + [[package]] name = "path-clean" version = "1.0.1" @@ -2675,73 +1754,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" [[package]] -name = "path-slash" -version = "0.2.1" +name = "pbkdf2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" - -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pest" -version = "2.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ - "memchr", - "thiserror 1.0.63", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a548d2beca6773b1c244554d36fcf8548a8a58e74156968211567250e48e49a" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c93a82e8d145725dcbaf44e5ea887c8a869efdcc28706df2d08c69e17077183" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn 2.0.100", -] - -[[package]] -name = "pest_meta" -version = "2.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a941429fea7e08bedec25e4f6785b6ffaacc6b755da98df5ef3e7dcf4a124c4f" -dependencies = [ - "once_cell", - "pest", + "digest", + "hmac", + "password-hash", "sha2", ] [[package]] -name = "pico-args" -version = "0.5.0" +name = "peeking_take_while" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pest" +version = "2.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660" +dependencies = [ + "thiserror", + "ucd-trie", +] [[package]] name = "piet" @@ -2749,8 +1787,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e381186490a3e2017a506d62b759ea8eaf4be14666b13ed53973e8ae193451b1" dependencies = [ - "image", - "kurbo 0.9.5", + "kurbo", "unic-bidi", ] @@ -2832,9 +1869,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.16" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" @@ -2844,48 +1881,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - -[[package]] -name = "png" -version = "0.17.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" -dependencies = [ - "bitflags 1.3.2", - "crc32fast", - "fdeflate", - "flate2", - "miniz_oxide 0.7.4", -] - -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "pretty_assertions" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" -dependencies = [ - "diff", - "yansi", -] - -[[package]] -name = "prettyplease" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" -dependencies = [ - "proc-macro2", - "syn 2.0.100", -] +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "proc-macro-crate" @@ -2894,7 +1892,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit 0.19.15", + "toml_edit", ] [[package]] @@ -2906,7 +1904,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn 1.0.109", + "syn", "version_check", ] @@ -2923,9 +1921,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] @@ -2941,19 +1939,13 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.40" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] -[[package]] -name = "r-efi" -version = "5.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" - [[package]] name = "radix_trie" version = "0.2.1" @@ -2979,59 +1971,35 @@ dependencies = [ "rand_core", ] -[[package]] -name = "rctree" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b42e27ef78c35d3998403c1d26f3efd9e135d3e5121b0a4845cc5cc27547f4f" - -[[package]] -name = "recvmsg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3edd4d5d42c92f0a659926464d4cce56b562761267ecf0f469d85b7de384175" - [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags 2.9.1", + "bitflags", ] [[package]] name = "redox_users" -version = "0.4.6" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.15", - "libredox", - "thiserror 1.0.63", -] - -[[package]] -name = "redox_users" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" -dependencies = [ - "getrandom 0.2.15", - "libredox", - "thiserror 2.0.12", + "getrandom", + "redox_syscall", + "thiserror", ] [[package]] name = "regex" -version = "1.11.1" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.9", - "regex-syntax 0.8.5", + "regex-syntax", ] [[package]] @@ -3040,134 +2008,20 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "regex-syntax 0.6.29", -] - -[[package]] -name = "regex-automata" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax 0.8.5", + "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - -[[package]] -name = "regex-syntax" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" - -[[package]] -name = "reqwest" -version = "0.12.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531" -dependencies = [ - "base64 0.22.1", - "bytes", - "encoding_rs", - "futures-core", - "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-tls", - "hyper-util", - "js-sys", - "log", - "mime", - "native-tls", - "percent-encoding", - "pin-project-lite", - "rustls-pki-types", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tokio-native-tls", - "tower", - "tower-http", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - -[[package]] -name = "resvg" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea0337740f86c70141e7596d81c2e76c0cd3726dbcee053ac18d0ec45101f8e" -dependencies = [ - "gif", - "jpeg-decoder", - "log", - "pico-args", - "png", - "rgb", - "svgfilters", - "svgtypes", - "tiny-skia", - "usvg", -] - -[[package]] -name = "rgb" -version = "0.8.48" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f86ae463694029097b846d8f99fd5536740602ae00022c0c50c5600720b2f71" -dependencies = [ - "bytemuck", -] - -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom 0.2.15", - "libc", - "spin", - "untrusted", - "windows-sys 0.52.0", -] - -[[package]] -name = "roxmltree" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9de9831a129b122e7e61f242db509fa9d0838008bf0b29bb0624669edfe48a" -dependencies = [ - "xmlparser", -] - -[[package]] -name = "roxmltree" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "rustc-demangle" -version = "0.1.24" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "rustc-hash" @@ -3175,100 +2029,27 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-hash" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" - [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" dependencies = [ "semver", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.36.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" dependencies = [ - "bitflags 2.9.1", + "bitflags", "errno", + "io-lifetimes", "libc", - "linux-raw-sys 0.4.14", - "windows-sys 0.52.0", -] - -[[package]] -name = "rustix" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" -dependencies = [ - "bitflags 2.9.1", - "errno", - "libc", - "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", -] - -[[package]] -name = "rustls" -version = "0.23.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" -dependencies = [ - "once_cell", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" -dependencies = [ - "zeroize", -] - -[[package]] -name = "rustls-webpki" -version = "0.102.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "rustversion" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" - -[[package]] -name = "rustybuzz" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9e34ecf6900625412355a61bda0bd68099fe674de707c67e5e4aed2c05e489" -dependencies = [ - "bitflags 1.3.2", - "bytemuck", - "smallvec", - "ttf-parser", - "unicode-bidi-mirroring", - "unicode-ccc", - "unicode-general-category", - "unicode-script", + "linux-raw-sys", + "windows-sys 0.45.0", ] [[package]] @@ -3277,7 +2058,7 @@ version = "9.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db7826789c0e25614b03e5a54a0717a86f9ff6e6e5247f92b369472869320039" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cfg-if", "clipboard-win", "dirs-next", @@ -3290,53 +2071,29 @@ dependencies = [ "scopeguard", "smallvec", "unicode-segmentation", - "unicode-width 0.1.13", + "unicode-width", "utf8parse", "winapi", ] [[package]] name = "ryu" -version = "1.0.18" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "schannel" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "scopeguard" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sdk" version = "0.3.0" dependencies = [ "async-recursion", - "bitflags 2.9.1", + "bitflags", "byteorder", "color-eyre", "csv-async", @@ -3344,10 +2101,10 @@ dependencies = [ "futures", "futures-util", "glob", + "libloading", "luajit2-sys", "nanorand", "oodle", - "path-slash", "pin-project-lite", "serde", "serde_sjson", @@ -3357,119 +2114,75 @@ dependencies = [ "tracing-error", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags 2.9.1", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "self_cell" -version = "0.10.3" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14e4d63b804dc0c7ec4a1e52bcb63f02c7ac94476755aa579edac21e01f915d" -dependencies = [ - "self_cell 1.0.4", -] - -[[package]] -name = "self_cell" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" +checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af" [[package]] name = "semver" -version = "1.0.23" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] [[package]] name = "serde" -version = "1.0.219" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", -] - -[[package]] -name = "serde_json" -version = "1.0.140" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", + "syn", ] [[package]] name = "serde_sjson" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c5b0d7af37492e99b8559436ee76b9ec8935c75449b1c2ef08c205a9e92ae6f" +version = "0.2.4" dependencies = [ - "nom 8.0.0", + "nom", "nom_locate", "serde", ] [[package]] -name = "serde_spanned" -version = "0.6.7" +name = "sha1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", + "cfg-if", + "cpufeatures", + "digest", ] [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", @@ -3478,49 +2191,28 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.7" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" dependencies = [ "lazy_static", ] [[package]] name = "shlex" -version = "1.3.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "signal-hook-registry" -version = "1.4.2" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] -[[package]] -name = "simd-adler32" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" - -[[package]] -name = "simplecss" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a11be7c62927d9427e9f40f3444d5499d868648e2edbc4e2116de69e7ec0e89d" -dependencies = [ - "log", -] - -[[package]] -name = "siphasher" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" - [[package]] name = "sized-chunks" version = "0.6.5" @@ -3533,54 +2225,18 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.9" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.13.2" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - -[[package]] -name = "socket2" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] -name = "steamlocate" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13160bc6ea5cd80cde195ad4a4c629701db2bf397b62c139aa9e739016d2499" -dependencies = [ - "crc", - "home", - "keyvalues-parser", - "keyvalues-serde", - "serde", - "winreg", -] +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "str-buf" @@ -3589,53 +2245,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" [[package]] -name = "strict-num" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" -dependencies = [ - "float-cmp", -] - -[[package]] -name = "strip-ansi-escapes" +name = "string_template" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a8f8038e7e7969abb3f1b7c2a811225e9296da208539e0f79c5251d6cac0025" +checksum = "dc6f2c6b2c3fa950895c9aeb0c3cb9271d7eb580662af9af2b711b593f446320" dependencies = [ - "vte", + "regex", ] [[package]] name = "strsim" -version = "0.11.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" -version = "2.6.1" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "svgfilters" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "639abcebc15fdc2df179f37d6f5463d660c1c79cd552c12343a4600827a04bce" -dependencies = [ - "float-cmp", - "rgb", -] - -[[package]] -name = "svgtypes" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22975e8a2bac6a76bb54f898a6b18764633b00e780330f0b689f65afb3975564" -dependencies = [ - "siphasher", -] +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" @@ -3648,144 +2276,66 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn" -version = "2.0.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "sync_wrapper" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" -dependencies = [ - "futures-core", -] - -[[package]] -name = "synstructure" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", -] - -[[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags 2.9.1", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "system-deps" -version = "6.2.2" +version = "6.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" +checksum = "2955b1fe31e1fa2fbd1976b71cc69a606d7d4da16f6de3333d0c92d51419aeff" dependencies = [ "cfg-expr", - "heck 0.5.0", + "heck", "pkg-config", - "toml 0.8.19", + "toml", "version-compare", ] -[[package]] -name = "target-lexicon" -version = "0.12.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" - [[package]] name = "tempfile" -version = "3.20.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" dependencies = [ + "cfg-if", "fastrand", - "getrandom 0.3.2", - "once_cell", - "rustix 1.0.5", - "windows-sys 0.59.0", + "redox_syscall", + "rustix", + "windows-sys 0.42.0", ] [[package]] name = "termcolor" -version = "1.4.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ - "thiserror-impl 1.0.63", -] - -[[package]] -name = "thiserror" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" -dependencies = [ - "thiserror-impl 2.0.12", + "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", + "syn", ] [[package]] name = "thread_local" -version = "1.1.8" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ "cfg-if", "once_cell", @@ -3793,16 +2343,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.41" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" dependencies = [ - "deranged", "itoa", "libc", - "num-conv", "num_threads", - "powerfmt", "serde", "time-core", "time-macros", @@ -3810,131 +2357,69 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.4" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] name = "time-macros" -version = "0.2.22" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" dependencies = [ - "num-conv", "time-core", ] -[[package]] -name = "tiny-skia" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df8493a203431061e901613751931f047d1971337153f96d0e5e363d6dbf6a67" -dependencies = [ - "arrayref", - "arrayvec", - "bytemuck", - "cfg-if", - "png", - "tiny-skia-path", -] - -[[package]] -name = "tiny-skia-path" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adbfb5d3f3dd57a0e11d12f4f13d4ebbbc1b5c15b7ab0a156d030b21da5f677c" -dependencies = [ - "arrayref", - "bytemuck", - "strict-num", -] - [[package]] name = "tinystr" -version = "0.7.6" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +checksum = "7ac3f5b6856e931e15e07b478e98c8045239829a65f9156d4fa7e7788197a5ef" dependencies = [ "displaydoc", - "zerovec", ] [[package]] name = "tokio" -version = "1.46.0" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1140bb80481756a8cbe10541f37433b459c5aa1e727b4c020fbfebdc25bf3ec4" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ - "backtrace", + "autocfg", "bytes", - "io-uring", "libc", + "memchr", "mio", + "num_cpus", "pin-project-lite", "signal-hook-registry", - "slab", - "socket2", "tokio-macros", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.42.0", ] [[package]] name = "tokio-macros" -version = "2.5.0" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" -dependencies = [ - "rustls", - "rustls-pki-types", - "tokio", + "syn", ] [[package]] name = "tokio-stream" -version = "0.1.17" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" +checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" dependencies = [ "futures-core", "pin-project-lite", "tokio", ] -[[package]] -name = "tokio-util" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml" version = "0.5.11" @@ -3944,102 +2429,30 @@ dependencies = [ "serde", ] -[[package]] -name = "toml" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit 0.22.20", -] - [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" -dependencies = [ - "serde", -] +checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.19.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "9a1eb0622d28f4b9c90adc4ea4b2b46b47663fde9ac5fafcb14a1369d5508825" dependencies = [ "indexmap", "toml_datetime", - "winnow 0.5.40", + "winnow", ] -[[package]] -name = "toml_edit" -version = "0.22.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow 0.6.18", -] - -[[package]] -name = "tower" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" -dependencies = [ - "futures-core", - "futures-util", - "pin-project-lite", - "sync_wrapper", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-http" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc2d9e086a412a451384326f521c8123a99a466b329941a9403696bff9b0da2" -dependencies = [ - "bitflags 2.9.1", - "bytes", - "futures-util", - "http", - "http-body", - "iri-string", - "pin-project-lite", - "tower", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - -[[package]] -name = "tower-service" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" - [[package]] name = "tracing" -version = "0.1.41" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ + "cfg-if", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -4047,20 +2460,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.28" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", + "syn", ] [[package]] name = "tracing-core" -version = "0.1.33" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", "valuable", @@ -4068,9 +2481,9 @@ dependencies = [ [[package]] name = "tracing-error" -version = "0.2.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" dependencies = [ "tracing", "tracing-subscriber", @@ -4078,20 +2491,20 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.2.0" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" dependencies = [ + "lazy_static", "log", - "once_cell", "tracing-core", ] [[package]] name = "tracing-subscriber" -version = "0.3.19" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" dependencies = [ "matchers", "nu-ansi-term", @@ -4116,38 +2529,26 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "ttf-parser" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" - [[package]] name = "type-map" -version = "0.5.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb68604048ff8fa93347f02441e4487594adc20bb8a084f9e564d2b827a0a9f" +checksum = "b6d3364c5e96cb2ad1603037ab253ddd34d7fb72a58bdddf4b7350760fc69a46" dependencies = [ - "rustc-hash 1.1.0", + "rustc-hash", ] [[package]] name = "typenum" -version = "1.17.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "ucd-trie" -version = "0.1.6" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unic-bidi" @@ -4182,18 +2583,18 @@ checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" [[package]] name = "unic-langid" -version = "0.9.5" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dd9d1e72a73b25e07123a80776aae3e7b0ec461ef94f9151eed6ec88005a44" +checksum = "398f9ad7239db44fd0f80fe068d12ff22d78354080332a5077dc6f52f14dcf2f" dependencies = [ "unic-langid-impl", ] [[package]] name = "unic-langid-impl" -version = "0.9.5" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5422c1f65949306c99240b81de9f3f15929f5a8bfe05bb44b034cc8bf593e5" +checksum = "e35bfd2f2b8796545b55d7d3fd3e89a0613f68a0d1c8bc28cb7ff96b411a35ff" dependencies = [ "tinystr", ] @@ -4220,128 +2621,30 @@ dependencies = [ [[package]] name = "unicase" -version = "2.7.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" dependencies = [ "version_check", ] -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - -[[package]] -name = "unicode-bidi-mirroring" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56d12260fb92d52f9008be7e4bca09f584780eb2266dc8fecc6a192bec561694" - -[[package]] -name = "unicode-ccc" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc2520efa644f8268dce4dcd3050eaa7fc044fca03961e9998ac7e2e92b77cf1" - -[[package]] -name = "unicode-general-category" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2281c8c1d221438e373249e065ca4989c4c36952c211ff21a0ee91c44a3869e7" - [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-script" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8d71f5726e5f285a935e9fe8edfd53f0491eb6e9a5774097fdabee7cd8c9cd" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-segmentation" -version = "1.11.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - -[[package]] -name = "unicode-vo" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" - -[[package]] -name = "unicode-width" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "unty" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" - -[[package]] -name = "url" -version = "2.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - -[[package]] -name = "usvg" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585bb2d87c8fd6041a479dea01479dcf9094e61b5f9af221606927e61a2bd939" -dependencies = [ - "base64 0.13.1", - "data-url", - "flate2", - "fontdb", - "kurbo 0.8.3", - "log", - "pico-args", - "rctree", - "roxmltree 0.15.1", - "rustybuzz", - "simplecss", - "siphasher", - "strict-num", - "svgtypes", - "unicode-bidi", - "unicode-script", - "unicode-vo", - "xmlwriter", -] - -[[package]] -name = "utf16_iter" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "utf16_lit" @@ -4349,17 +2652,11 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14706d2a800ee8ff38c1d3edb873cd616971ea59eb7c0d046bb44ef59b06a1ae" -[[package]] -name = "utf8_iter" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" - [[package]] name = "utf8parse" -version = "0.2.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" [[package]] name = "valuable" @@ -4367,57 +2664,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version-compare" -version = "0.2.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" +checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" [[package]] name = "version_check" -version = "0.9.5" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "virtue" -version = "0.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" - -[[package]] -name = "vte" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077" -dependencies = [ - "memchr", -] - -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasi" @@ -4425,58 +2682,36 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasi" -version = "0.14.2+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" -dependencies = [ - "wit-bindgen-rt", -] - [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", - "once_cell", - "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.100" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", + "once_cell", "proc-macro2", "quote", - "syn 2.0.100", + "syn", "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4484,73 +2719,43 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.100", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "wasm-bindgen-test" -version = "0.3.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9" -dependencies = [ - "console_error_panic_hook", - "js-sys", - "minicov", - "scoped-tls", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test-macro", -] - -[[package]] -name = "wasm-bindgen-test-macro" -version = "0.3.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", -] +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] -name = "weezl" -version = "0.1.8" +name = "which" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" - -[[package]] -name = "widestring" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +dependencies = [ + "either", + "libc", + "once_cell", +] [[package]] name = "winapi" @@ -4570,11 +2775,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.9" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "windows-sys 0.48.0", + "winapi", ] [[package]] @@ -4584,289 +2789,95 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows-link" -version = "0.1.1" +name = "windows-sys" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" - -[[package]] -name = "windows-registry" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows-result", - "windows-strings", - "windows-targets 0.53.0", -] - -[[package]] -name = "windows-result" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" -dependencies = [ - "windows-link", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows-sys" -version = "0.48.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", + "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" -dependencies = [ - "windows_aarch64_gnullvm 0.53.0", - "windows_aarch64_msvc 0.53.0", - "windows_i686_gnu 0.53.0", - "windows_i686_gnullvm 0.53.0", - "windows_i686_msvc 0.53.0", - "windows_x86_64_gnu 0.53.0", - "windows_x86_64_gnullvm 0.53.0", - "windows_x86_64_msvc 0.53.0", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winnow" -version = "0.5.40" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +checksum = "faf09497b8f8b5ac5d3bb4d05c0a99be20f26fd3d5f2db7b0716e946d5103658" dependencies = [ "memchr", ] -[[package]] -name = "winnow" -version = "0.6.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" -dependencies = [ - "memchr", -] - -[[package]] -name = "winreg" -version = "0.55.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97" -dependencies = [ - "cfg-if", - "windows-sys 0.59.0", -] - -[[package]] -name = "winres" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c" -dependencies = [ - "toml 0.5.11", -] - [[package]] name = "wio" version = "0.2.2" @@ -4876,185 +2887,58 @@ dependencies = [ "winapi", ] -[[package]] -name = "wit-bindgen-rt" -version = "0.39.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" -dependencies = [ - "bitflags 2.9.1", -] - -[[package]] -name = "write16" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" - -[[package]] -name = "writeable" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" - [[package]] name = "xi-unicode" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" -[[package]] -name = "xmlparser" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" - -[[package]] -name = "xmlwriter" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" - -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" - -[[package]] -name = "yoke" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" -dependencies = [ - "serde", - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", - "synstructure", -] - -[[package]] -name = "zerofrom" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", - "synstructure", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" - -[[package]] -name = "zerovec" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", -] - [[package]] name = "zip" -version = "4.2.0" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ab361742de920c5535880f89bbd611ee62002bf11341d16a5f057bb8ba6899" +checksum = "0445d0fbc924bb93539b4316c11afb121ea39296f99a3c4c9edad09e3658cdef" dependencies = [ - "arbitrary", + "aes", + "byteorder", "bzip2", + "constant_time_eq", "crc32fast", + "crossbeam-utils", "flate2", - "indexmap", - "memchr", + "hmac", + "pbkdf2", + "sha1", "time", - "zopfli", "zstd", ] -[[package]] -name = "zlib-rs" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "868b928d7949e09af2f6086dfc1e01936064cc7a819253bce650d4e2a2d63ba8" - -[[package]] -name = "zopfli" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" -dependencies = [ - "bumpalo", - "crc32fast", - "lockfree-object-pool", - "log", - "once_cell", - "simd-adler32", -] - [[package]] name = "zstd" -version = "0.13.2" +version = "0.11.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "7.2.1" +version = "5.0.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" dependencies = [ + "libc", "zstd-sys", ] [[package]] name = "zstd-sys" -version = "2.0.13+zstd.1.5.6" +version = "2.0.7+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" dependencies = [ "cc", + "libc", "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index 35f8d72..aef4708 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,82 +1,7 @@ [workspace] resolver = "2" -members = [ - "crates/dtmt", - "crates/dtmm", - "lib/dtmt-shared", - "lib/oodle", - "lib/sdk", - "lib/luajit2-sys", - "lib/color-eyre", -] -exclude = ["lib/color-eyre"] - -[workspace.dependencies] -ansi-parser = "0.9.1" -ansi_term = "0.12.1" -async-recursion = "1.0.5" -bincode = "2.0.0" -bindgen = "0.72.0" -bitflags = "2.5.0" -byteorder = "1.4.3" -cc = { version = "1.2.27", features = ["parallel"] } -clap = { version = "4.0.15", features = ["color", "derive", "std", "cargo", "string", "unicode"] } -cli-table = { version = "0.5.0", default-features = false, features = ["derive"] } -color-eyre = { path = "lib/color-eyre" } -colors-transform = "0.2.11" -confy = "1.0.0" -csv-async = { version = "1.2.4", features = ["tokio", "serde"] } -druid = { version = "0.8", features = ["im", "serde", "image", "png", "jpeg", "bmp", "webp", "svg"] } -druid-widget-nursery = "0.1" -dtmt-shared = { path = "lib/dtmt-shared" } -fastrand = "2.1.0" -fs_extra = "1.1.0" -futures = "0.3.25" -futures-util = "0.3.24" -glob = "0.3.0" -interprocess = "2.1.0" -lazy_static = "1.4.0" -libc = "0.2.174" -luajit2-sys = { path = "lib/luajit2-sys" } -minijinja = { version = "2.0.1", default-features = false, features = ["serde"] } -nanorand = "0.8.0" -nexusmods = { path = "lib/nexusmods" } -notify = "8.0.0" -oodle = { path = "lib/oodle" } -open = "5.0.1" -path-clean = "1.0.1" -path-slash = "0.2.1" -pin-project-lite = "0.2.9" -promptly = "0.3.1" -sdk = { path = "lib/sdk" } -serde = { version = "1.0.152", features = ["derive", "rc"] } -serde_sjson = "1.2.1" -steamlocate = "2.0.0-beta.2" -strip-ansi-escapes = "0.2.0" -time = { version = "0.3.20", features = ["serde", "serde-well-known", "local-offset", "formatting", "macros"] } -tokio = { version = "1.23.0", features = ["rt-multi-thread", "fs", "process", "macros", "tracing", "io-util", "io-std"] } -tokio-stream = { version = "0.1.12", features = ["fs", "io-util"] } -tracing = { version = "0.1.37", features = ["async-await"] } -tracing-error = "0.2.0" -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -usvg = "0.25.0" -zip = { version = "4.0.0", default-features = false, features = ["deflate", "bzip2", "zstd", "time"] } - -[profile.dev.package.backtrace] -opt-level = 3 +members = ["crates/*", "lib/*"] [profile.release] strip = "debuginfo" - -# The MSVC toolchain cannot handle LTO properly. Some symbol related to -# panic unwind would always be missing. -# So we use a separate profile for when we can compile with LTO. -[profile.release-lto] -inherits = "release" lto = true - -[profile.perf] -inherits = "release" -strip = false -lto = true -debug = "line-tables-only" diff --git a/Justfile b/Justfile deleted file mode 100644 index 697bdcc..0000000 --- a/Justfile +++ /dev/null @@ -1,61 +0,0 @@ -set positional-arguments - -fly_target := "main" - -build-perf-dtmt: - cargo build --profile perf --bin dtmt - -perf-dtmt *args='': build-perf-dtmt - perf record --call-graph dwarf ./target/perf/dtmt "$@" - -ci-build: ci-build-msvc ci-build-linux - -ci-build-msvc: - docker run --rm -ti --user $(id -u) -v ./:/src/dtmt dtmt-ci-base-msvc cargo --color always build --release --target x86_64-pc-windows-msvc --locked -Zbuild-std - -ci-build-linux: - docker run --rm -ti --user $(id -u) -v ./:/src/dtmt dtmt-ci-base-linux cargo --color always build --profile release-lto --locked - -build-image: build-image-msvc build-image-linux - -build-image-msvc: - docker build -f .ci/Dockerfile.msvc . - -build-image-linux: - docker build -f .ci/Dockerfile.linux . - -ci-image: - # The MSVC image depends on the Linux image. So by building that first, - # we actually build both, and cache them, so that "building" the - # Linux image afterwards merely needs to pull the cache. - docker build --target msvc -t dtmt-ci-base-msvc -f .ci/image/Dockerfile . - docker build --target linux -t dtmt-ci-base-linux -f .ci/image/Dockerfile . - docker tag dtmt-ci-base-msvc registry.sclu1034.dev/dtmt-ci-base-msvc - docker tag dtmt-ci-base-linux registry.sclu1034.dev/dtmt-ci-base-linux - docker push registry.sclu1034.dev/dtmt-ci-base-msvc - docker push registry.sclu1034.dev/dtmt-ci-base-linux - -set-base-pipeline: - fly -t {{fly_target}} set-pipeline \ - --pipeline dtmt \ - --config .ci/pipelines/base.yml \ - -v gitea_api_key=${GITEA_API_KEY} \ - -v registry_user=${REGISTRY_USER} \ - -v registry_password=${REGISTRY_PASSWORD} \ - -v owner=bitsquid_dt \ - -v repo=dtmt - -set-pr-pipeline pr: - curl \ - -H "Authorization: ${GITEA_API_KEY}" \ - -H 'Accept: application/json' \ - 'https://git.sclu1034.dev/api/v1/repos/bitsquid_dt/dtmt/pulls/{{pr}}' \ - | yq -y '.' - > 'pr-{{pr}}.yaml' - fly -t main set-pipeline \ - --pipeline dtmt-pr \ - --config .ci/pipelines/pr.yml \ - -v gitea_api_key=${GITEA_API_KEY} \ - -i number={{pr}} \ - -y branch="$(yq -y '.head.ref' 'pr-{{pr}}.yaml')" \ - -y pr="$(cat 'pr-{{pr}}.yaml')" - diff --git a/crates/dtmm/Cargo.toml b/crates/dtmm/Cargo.toml index 52c0522..6d95e32 100644 --- a/crates/dtmm/Cargo.toml +++ b/crates/dtmm/Cargo.toml @@ -2,48 +2,24 @@ name = "dtmm" version = "0.1.0" edition = "2021" -authors = ["Lucas Schwiderski "] -description = "DTMM is a GUI application to install and manage mods for the game." -documentation = "https://git.sclu1034.dev/bitsquid_dt/dtmt/wiki" -repository = "https://git.sclu1034.dev/bitsquid_dt/dtmt" -homepage = "https://git.sclu1034.dev/bitsquid_dt/dtmt" -license-file = "LICENSE" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ansi-parser = { workspace = true } -async-recursion = { workspace = true } -bincode = { workspace = true } -bitflags = { workspace = true } -clap = { workspace = true } -color-eyre = { workspace = true } -colors-transform = { workspace = true } -confy = { workspace = true } -druid = { workspace = true } -druid-widget-nursery = { workspace = true } -dtmt-shared = { workspace = true } -futures = { workspace = true } -interprocess = { workspace = true } -lazy_static = { workspace = true } -luajit2-sys = { workspace = true } -minijinja = { workspace = true } -nexusmods = { workspace = true } -oodle = { workspace = true } -open = { workspace = true } -path-slash = { workspace = true } -sdk = { workspace = true } -serde = { workspace = true } -serde_sjson = { workspace = true } -strip-ansi-escapes = { workspace = true } -time = { workspace = true } -tokio = { workspace = true } -tokio-stream = { workspace = true } -tracing = { workspace = true } -tracing-error = { workspace = true } -tracing-subscriber = { workspace = true } -usvg = { workspace = true } -zip = { workspace = true } - -[build-dependencies] -winres = "0.1.12" +bitflags = "1.3.2" +clap = { version = "4.0.15", features = ["color", "derive", "std", "cargo", "string", "unicode"] } +color-eyre = "0.6.2" +confy = "0.5.1" +druid = { git = "https://github.com/linebender/druid.git", features = ["im", "serde"] } +dtmt-shared = { path = "../../lib/dtmt-shared", version = "*" } +futures = "0.3.25" +oodle = { path = "../../lib/oodle", version = "*" } +sdk = { path = "../../lib/sdk", version = "*" } +serde_sjson = { path = "../../lib/serde_sjson", version = "*" } +serde = { version = "1.0.152", features = ["derive", "rc"] } +tokio = { version = "1.23.0", features = ["rt", "fs", "tracing", "sync"] } +tracing = "0.1.37" +tracing-error = "0.2.0" +tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } +zip = "0.6.4" +tokio-stream = { version = "0.1.12", features = ["fs"] } diff --git a/crates/dtmm/assets/DTMM_logo.xcf b/crates/dtmm/assets/DTMM_logo.xcf deleted file mode 100644 index 00de67d..0000000 --- a/crates/dtmm/assets/DTMM_logo.xcf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:144903129d56235895e433435ecee90528ceb5c4db98f5b02e637a215dde1881 -size 17736337 diff --git a/crates/dtmm/assets/DTMM_logo_256.png b/crates/dtmm/assets/DTMM_logo_256.png deleted file mode 100644 index e53931f..0000000 --- a/crates/dtmm/assets/DTMM_logo_256.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:62096b0f6e3798820c9ad04ba61fdff45522b7c67c4b254dc8fd11bdde984c76 -size 39017 diff --git a/crates/dtmm/assets/DTMM_logo_48.png b/crates/dtmm/assets/DTMM_logo_48.png deleted file mode 100644 index 33c1d11..0000000 --- a/crates/dtmm/assets/DTMM_logo_48.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6b0524e05b8f2c6ca061aa7edc6f7e62efb8bcddf347e4e9344187efb437436c -size 3082 diff --git a/crates/dtmm/assets/DTMM_logo_64.png b/crates/dtmm/assets/DTMM_logo_64.png deleted file mode 100644 index e5d5407..0000000 --- a/crates/dtmm/assets/DTMM_logo_64.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e0bf9431d5f46f4437c21fe38ebbd86e8b3872acaf3a13f0bc8f4a9e8e78e118 -size 4287 diff --git a/crates/dtmm/assets/DTMM_logo_border.png b/crates/dtmm/assets/DTMM_logo_border.png deleted file mode 100644 index bf610e4..0000000 --- a/crates/dtmm/assets/DTMM_logo_border.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:cefec60ffe91eb4d827e1c7c9b4bfebdec528236809e02ccc9f15b15ee290442 -size 537707 diff --git a/crates/dtmm/assets/DTMM_logo_faint_glow.png b/crates/dtmm/assets/DTMM_logo_faint_glow.png deleted file mode 100644 index 1066370..0000000 --- a/crates/dtmm/assets/DTMM_logo_faint_glow.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d579be0297e78ef0c9cfb4ce357dd61ed13cc65084d5a38c322913cdcdbe5b99 -size 605023 diff --git a/crates/dtmm/assets/DTMM_logo_small.png b/crates/dtmm/assets/DTMM_logo_small.png deleted file mode 100644 index 0020520..0000000 --- a/crates/dtmm/assets/DTMM_logo_small.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:be2a3cb6a94828b3df9368bcf9ea335ad08590a69b128a15a92fb1cf751d06b6 -size 502425 diff --git a/crates/dtmm/assets/dtmm.desktop b/crates/dtmm/assets/dtmm.desktop deleted file mode 100644 index cb9185c..0000000 --- a/crates/dtmm/assets/dtmm.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Name=DTMM -GenericName=Mod Manager -Comment=A graphical mod manager for Warhammer 40,000: Darktide -Exec=dtmm %u -Type=Application -Keywords=Mod; -StartupNotify=true -Categories=Utility; -MimeType=x-scheme-handler/nxm; -Icon=dtmm diff --git a/crates/dtmm/assets/dtmm.ico b/crates/dtmm/assets/dtmm.ico deleted file mode 100644 index b862839..0000000 --- a/crates/dtmm/assets/dtmm.ico +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:02d4bea2d7af89a86c3f052240a2acd137a0df5e9b6e85ecfe3f163032010652 -size 37519 diff --git a/crates/dtmm/assets/init.lua b/crates/dtmm/assets/init.lua deleted file mode 100644 index e2acdbd..0000000 --- a/crates/dtmm/assets/init.lua +++ /dev/null @@ -1,70 +0,0 @@ -local StateGame = require("scripts/game_states/state_game") -local StateSplash = require("scripts/game_states/game/state_splash") -local GameStateMachine = require("scripts/foundation/utilities/game_state_machine") - -local function hook(obj, fn_name, cb) - local orig = obj[fn_name] - - obj[fn_name] = function(...) - return cb(orig, ...) - end -end - -function init(mod_data, boot_gui) - local ModLoader = require("scripts/mods/mod_loader") - local mod_loader = ModLoader:new(mod_data, boot_gui) - - -- The mod loader needs to remain active during game play, to - -- enable reloads - hook(StateGame, "update", function(func, dt, ...) - mod_loader:update(dt) - return func(dt, ...) - end) - - -- Skip splash view - hook(StateSplash, "on_enter", function(func, self, ...) - local result = func(self, ...) - - self._should_skip = true - self._continue = true - - return result - end) - - -- Trigger state change events - hook(GameStateMachine, "_change_state", function(func, self, ...) - local old_state = self._state - local old_state_name = old_state and self:current_state_name() - - if old_state_name then - mod_loader:on_game_state_changed("exit", old_state_name, old_state) - end - - local result = func(self, ...) - - local new_state = self._state - local new_state_name = new_state and self:current_state_name() - - if new_state_name then - mod_loader:on_game_state_changed("enter", new_state_name, new_state) - end - - return result - end) - - -- Trigger ending state change event - hook(GameStateMachine, "destroy", function(func, self, ...) - local old_state = self._state - local old_state_name = old_state and self:current_state_name() - - if old_state_name then - mod_loader:on_game_state_changed("exit", old_state_name) - end - - return func(self, ...) - end) - - return mod_loader -end - -return init diff --git a/crates/dtmm/assets/mod_data.lua.j2 b/crates/dtmm/assets/mod_data.lua.j2 deleted file mode 100644 index b5e7f17..0000000 --- a/crates/dtmm/assets/mod_data.lua.j2 +++ /dev/null @@ -1,28 +0,0 @@ -return { -{% for mod in mods %} -{ - id = "{{ mod.id }}", - name = "{{ mod.name }}", - bundled = {{ mod.bundled }}, - version = {{ mod.version }}, - packages = { - {% for pkg in mod.packages %} - "{{ pkg }}", - {% endfor %} - }, - run = function() - {% if mod.data is none %} - return dofile("{{ mod.init }}") - {% else %} - new_mod("{{ mod.id }}", { - mod_script = "{{ mod.init }}", - mod_data = "{{ mod.data }}", - {% if not mod.localization is none %} - mod_localization = "{{ mod.localization }}", - {% endif %} - }) - {% endif %} - end, -}, -{% endfor %} -} diff --git a/crates/dtmm/assets/mod_loader.lua b/crates/dtmm/assets/mod_loader.lua deleted file mode 100644 index 126c0eb..0000000 --- a/crates/dtmm/assets/mod_loader.lua +++ /dev/null @@ -1,412 +0,0 @@ --- Copyright on this file is owned by Fatshark. --- It is extracted, used and modified with permission only for --- the purpose of loading mods within Warhammer 40,000: Darktide. -local ModLoader = class("ModLoader") - -local table_unpack = table.unpack or unpack -local table_pack = table.pack or pack - -local ScriptGui = require("scripts/foundation/utilities/script_gui") - -local FONT_MATERIAL = "content/ui/fonts/arial" - -local LOG_LEVELS = { - spew = 4, - info = 3, - warning = 2, - error = 1 -} -local DEFAULT_SETTINGS = { - log_level = LOG_LEVELS.error, - developer_mode = false -} - -local Keyboard = Keyboard -local BUTTON_INDEX_R = Keyboard.button_index("r") -local BUTTON_INDEX_LEFT_SHIFT = Keyboard.button_index("left shift") -local BUTTON_INDEX_LEFT_CTRL = Keyboard.button_index("left ctrl") - -ModLoader.init = function(self, mod_data, boot_gui) - table.dump(mod_data, nil, 5, function(...) Log.info("ModLoader", ...) end) - - self._mod_data = mod_data - self._gui = boot_gui - - self._settings = Application.user_setting("mod_settings") or DEFAULT_SETTINGS - - self._mods = {} - self._num_mods = nil - self._chat_print_buffer = {} - self._reload_data = {} - self._ui_time = 0 - - self._state = "scanning" -end - -ModLoader.developer_mode_enabled = function(self) - return self._settings.developer_mode -end - -ModLoader.set_developer_mode = function(self, enabled) - self._settings.developer_mode = enabled -end - -ModLoader._draw_state_to_gui = function(self, gui, dt) - local state = self._state - local t = self._ui_time + dt - self._ui_time = t - local status_str = "Loading mods" - - if state == "scanning" then - status_str = "Scanning for mods" - elseif state == "loading" or state == "initializing" then - local mod = self._mods[self._mod_load_index] - status_str = string.format("Loading mod %q", mod.name) - end - - local msg = status_str .. string.rep(".", (2 * t) % 4) - ScriptGui.text(gui, msg, FONT_MATERIAL, 25, Vector3(20, 30, 1), Color.white()) -end - -ModLoader.remove_gui = function(self) - self._gui = nil -end - -ModLoader.mod_data = function(self, id) - -- Since this primarily exists for DMF, - -- we can optimize the search for its use case of looking for the - -- mod currently being loaded - local mod_data = self._mods[self._mod_load_index] - - if mod_data.id ~= id then - mod_data = nil - - for _, v in ipairs(self._mods) do - if v.id == id then - mod_data = v - end - end - end - - return mod_data -end - -ModLoader._check_reload = function() - return Keyboard.pressed(BUTTON_INDEX_R) and - Keyboard.button(BUTTON_INDEX_LEFT_SHIFT) + - Keyboard.button(BUTTON_INDEX_LEFT_CTRL) == 2 -end - -ModLoader.update = function(self, dt) - local chat_print_buffer = self._chat_print_buffer - local num_delayed_prints = #chat_print_buffer - - if num_delayed_prints > 0 and Managers.chat then - for i = 1, num_delayed_prints, 1 do - -- TODO: Use new chat system - -- Managers.chat:add_local_system_message(1, chat_print_buffer[i], true) - - chat_print_buffer[i] = nil - end - end - - local old_state = self._state - - if self._settings.developer_mode and self:_check_reload() then - self._reload_requested = true - end - - if self._reload_requested and old_state == "done" then - self:_reload_mods() - end - - if old_state == "done" then - self:_run_callbacks("update", dt) - elseif old_state == "scanning" then - Log.info("ModLoader", "Scanning for mods") - self:_build_mod_table() - - self._state = self:_load_mod(1) - self._ui_time = 0 - elseif old_state == "loading" then - local handle = self._loading_resource_handle - - if ResourcePackage.has_loaded(handle) then - ResourcePackage.flush(handle) - - local mod = self._mods[self._mod_load_index] - local next_index = mod.package_index + 1 - local mod_data = mod.data - - if next_index <= #mod_data.packages then - self:_load_package(mod, next_index) - else - self._state = "initializing" - end - end - elseif old_state == "initializing" then - local mod = self._mods[self._mod_load_index] - local mod_data = mod.data - - Log.info("ModLoader", "Initializing mod %q", mod.name) - - mod.state = "running" - local ok, object = xpcall(mod_data.run, function(err) - if type(err) == "string" then - return err .. "\n" .. Script.callstack() - else - return err - end - end) - - if not ok then - if object.error then - object = string.format( - "%s\n<>\n%s\n<>\n<>\n%s\n<>\n<>\n%s\n<>", - object.error, object.traceback, object.locals, object.self) - end - - Log.error("ModLoader", "Failed 'run' for %q: %s", mod.name, object) - end - - mod.object = object or {} - - self:_run_callback(mod, "init", self._reload_data[mod.id]) - - Log.info("ModLoader", "Finished loading %q", mod.name) - - self._state = self:_load_mod(self._mod_load_index + 1) - end - - local gui = self._gui - if gui then - self:_draw_state_to_gui(gui, dt) - end - - if old_state ~= self._state then - Log.info("ModLoader", "%s -> %s", old_state, self._state) - end -end - -ModLoader.all_mods_loaded = function(self) - return self._state == "done" -end - -ModLoader.destroy = function(self) - self:_run_callbacks("on_destroy") - self:unload_all_mods() -end - -ModLoader._run_callbacks = function(self, callback_name, ...) - for i = 1, self._num_mods, 1 do - local mod = self._mods[i] - - if mod and not mod.callbacks_disabled then - self:_run_callback(mod, callback_name, ...) - end - end -end - -ModLoader._run_callback = function(self, mod, callback_name, ...) - local object = mod.object - local cb = object[callback_name] - - if not cb then - return - end - - local args = table_pack(...) - - local success, val = xpcall( - function() return cb(object, table_unpack(args)) end, - function(err) - if type(err) == "string" then - return err .. "\n" .. Script.callstack() - else - return err - end - end - ) - - if success then - return val - else - Log.error("ModLoader", "Failed to run callback %q for mod %q with id %q. Disabling callbacks until reload.", - callback_name, mod.name, mod.id) - if val.error then - Log.error("ModLoader", - "Error: %s\n<>\n%s<>\n<>\n%s<>\n<>\n%s<>", - val.error, val.traceback, val.locals, val.self) - else - Log.error("ModLoader", "Error: %s", val or "[unknown error]") - end - - mod.callbacks_disabled = true - end -end - -ModLoader._start_scan = function(self) - Log.info("ModLoader", "Starting mod scan") - self._state = "scanning" -end - -ModLoader._build_mod_table = function(self) - fassert(table.is_empty(self._mods), "Trying to add mods to non-empty mod table") - - for i, mod_data in ipairs(self._mod_data) do - Log.info( - "ModLoader", - "mods[%d] = id=%q | name=%q | version=%q | bundled=%s", - i, - mod_data.id, - mod_data.name, - mod_data.version, - tostring(mod_data.bundled) - ) - - self._mods[i] = { - id = mod_data.id, - state = "not_loaded", - callbacks_disabled = false, - name = mod_data.name, - loaded_packages = {}, - packages = mod_data.packages, - data = mod_data, - bundled = mod_data.bundled or false, - } - end - - self._num_mods = #self._mods - - Log.info("ModLoader", "Found %i mods", self._num_mods) -end - -ModLoader._load_mod = function(self, index) - self._ui_time = 0 - local mods = self._mods - local mod = mods[index] - - if not mod then - table.clear(self._reload_data) - - return "done" - end - - Log.info("ModLoader", "Loading mod %q", mod.id) - - mod.state = "loading" - - Crashify.print_property(string.format("Mod:%s", mod.name), true) - - self._mod_load_index = index - - if mod.bundled and mod.packages[1] then - self:_load_package(mod, 1) - return "loading" - else - return "initializing" - end -end - -ModLoader._load_package = function(self, mod, index) - mod.package_index = index - local package_name = mod.packages[index] - - if not package_name then - return - end - - Log.info("ModLoader", "Loading package %q", package_name) - - local resource_handle = Application.resource_package(package_name) - self._loading_resource_handle = resource_handle - - ResourcePackage.load(resource_handle) - - table.insert(mod.loaded_packages, resource_handle) -end - -ModLoader.unload_all_mods = function(self) - if self._state ~= "done" then - Log.error("ModLoader", "Mods can't be unloaded, mod state is not \"done\". current: %q", self._state) - - return - end - - Log.info("ModLoader", "Unload all mod packages") - - for i = self._num_mods, 1, -1 do - local mod = self._mods[i] - - if mod then - self:unload_mod(i) - end - - self._mods[i] = nil - end - - self._num_mods = nil - self._state = "unloaded" -end - -ModLoader.unload_mod = function(self, index) - local mod = self._mods[index] - - if mod then - Log.info("ModLoader", "Unloading %q.", mod.name) - - for _, handle in ipairs(mod.loaded_packages) do - ResourcePackage.unload(handle) - Application.release_resource_package(handle) - end - - mod.state = "not_loaded" - else - Log.error("ModLoader", "Mod index %i can't be unloaded, has not been loaded", index) - end -end - -ModLoader._reload_mods = function(self) - Log.info("ModLoader", "reloading mods") - - for i = 1, self._num_mods, 1 do - local mod = self._mods[i] - - if mod and mod.state == "running" then - Log.info("ModLoader", "reloading %s", mod.name) - - self._reload_data[mod.id] = self:_run_callback(mod, "on_reload") - else - Log.info("ModLoader", "not reloading mod, state: %s", mod.state) - end - end - - self:unload_all_mods() - self:_start_scan() - - self._reload_requested = false -end - -ModLoader.on_game_state_changed = function(self, status, state_name, state_object) - if self._state == "done" then - self:_run_callbacks("on_game_state_changed", status, state_name, state_object) - else - Log.warning("ModLoader", "Ignored on_game_state_changed call due to being in state %q", self._state) - end -end - -ModLoader.print = function(self, level, str, ...) - local f = Log[level] - if f then - f("ModLoader", str, ...) - else - local message = string.format("[ModLoader][" .. level .. "] " .. str, ...) - local log_level = LOG_LEVELS[level] or 99 - - if log_level <= 2 then - print(message) - end - end -end - -return ModLoader diff --git a/crates/dtmm/assets/mod_main.lua b/crates/dtmm/assets/mod_main.lua new file mode 100644 index 0000000..715397f --- /dev/null +++ b/crates/dtmm/assets/mod_main.lua @@ -0,0 +1,192 @@ +local _G = _G +local rawget = rawget +local rawset = rawset + +local log = function(category, format, ...) + local Log = rawget(_G, "Log") + if Log then + Log.info(category, format, ...) + else + print(string.format("[%s] %s", category or "", string.format(format or "", ...))) + end +end + +-- Patch `GameStateMachine.init` to add our own state for loading mods. +-- In the future, Fatshark might provide us with a dedicated way to do this. +local function patch_mod_loading_state() + local StateBootSubStateBase = require("scripts/game_states/boot/state_boot_sub_state_base") + + -- A necessary override. + -- The original does not proxy `dt` to `_state_update`, but we need that. + StateBootSubStateBase.update = function (self, dt) + local done, error = self:_state_update(dt) + local params = self._params + + if error then + return StateError, { error } + elseif done then + local next_index = params.sub_state_index + 1 + params.sub_state_index = next_index + local next_state_data = params.states[next_index] + + if next_state_data then + return next_state_data[1], self._params + else + self._parent:sub_states_done() + end + end + end + + local StateBootLoadMods = class("StateBootLoadMods", "StateBootSubStateBase") + + StateBootLoadMods.on_enter = function (self, parent, params) + log("StateBootLoadMods", "Entered") + StateBootLoadMods.super.on_enter(self, parent, params) + + local state_params = self:_state_params() + local package_manager = state_params.package_manager + + self._state = "load_package" + self._package_manager = package_manager + self._package_handles = { + ["packages/mods"] = package_manager:load("packages/mods", "StateBootLoadMods", nil), + ["packages/dml"] = package_manager:load("packages/dml", "StateBootLoadMods", nil), + } + end + + StateBootLoadMods._state_update = function (self, dt) + local state = self._state + local package_manager = self._package_manager + + if state == "load_package" and package_manager:update() then + log("StateBootLoadMods", "Packages loaded, loading mods") + self._state = "load_mods" + local mod_loader = require("scripts/mods/dml/init") + self._mod_loader = mod_loader + + local mod_data = require("scripts/mods/mod_data") + mod_loader:init(mod_data, self._parent:gui()) + elseif state == "load_mods" and self._mod_loader:update(dt) then + log("StateBootLoadMods", "Mods loaded, exiting") + return true, false + end + + return false, false + end + + local GameStateMachine = require("scripts/foundation/utilities/game_state_machine") + + local patched = false + + local GameStateMachine_init = GameStateMachine.init + GameStateMachine.init = function(self, parent, start_state, params, ...) + if not patched then + log("mod_main", "Injecting mod loading state") + patched = true + + -- Hardcoded position after `StateRequireScripts`. + -- We do want to wait until then, so that most of the game's core + -- systems are at least loaded and can be hooked, even if they aren't + -- running, yet. + local pos = 4 + table.insert(params.states, pos, { + StateBootLoadMods, + { + package_manager = params.package_manager, + }, + }) + end + + GameStateMachine_init(self, parent, start_state, params, ...) + end + + log("mod_main", "Mod patching complete") +end + +log("mod_main", "Initializing mods...") + +local require_store = {} + +Mods = { + -- Keep a backup of certain system libraries before + -- Fatshark's code scrubs them. + -- The loader can then decide to pass them on to mods, or ignore them + lua = setmetatable({}, { + io = io, + debug = debug, + ffi = ffi, + os = os, + load = load, + loadfile = loadfile, + loadstring = loadstring, + }), + require_store = require_store +} + +local can_insert = function(filepath, new_result) + local store = require_store[filepath] + if not store or #store then + return true + end + + if store[#store] ~= new_result then + return true + end +end + +local original_require = require +require = function(filepath, ...) + local result = original_require(filepath, ...) + if result and type(result) == "table" then + if can_insert(filepath, result) then + require_store[filepath] = require_store[filepath] or {} + local store = require_store[filepath] + + table.insert(store, result) + + if Mods.hook then + Mods.hook.enable_by_file(filepath, #store) + end + end + end + + return result +end + +require("scripts/boot_init") +require("scripts/foundation/utilities/class") + +-- The `__index` metamethod maps a proper identifier `CLASS.MyClassName` to the +-- stringified version of the key: `"MyClassName"`. +-- This allows using LuaCheck for the stringified class names in hook parameters. +_G.CLASS = setmetatable({}, { + __index = function(_, key) + return key + end +}) + +local original_class = class +class = function(class_name, super_name, ...) + local result = original_class(class_name, super_name, ...) + if not rawget(_G, class_name) then + rawset(_G, class_name, result) + end + if not rawget(_G.CLASS, class_name) then + rawset(_G.CLASS, class_name, result) + end + return result +end + +require("scripts/main") +log("mod_main", "'scripts/main' loaded") + +-- Override `init` to run our injection +function init() + patch_mod_loading_state() + + -- As requested by Fatshark + local StateRequireScripts = require("scripts/game_states/boot/state_require_scripts") + StateRequireScripts._get_is_modded = function() return true end + + Main:init() +end diff --git a/crates/dtmm/assets/mod_main.lua.j2 b/crates/dtmm/assets/mod_main.lua.j2 deleted file mode 100644 index 29caa79..0000000 --- a/crates/dtmm/assets/mod_main.lua.j2 +++ /dev/null @@ -1,216 +0,0 @@ -local _G = _G -local rawget = rawget -local rawset = rawset - -local log = function(category, format, ...) - local Log = rawget(_G, "Log") - if Log then - Log.info(category, format, ...) - else - print(string.format("[%s] %s", category or "", string.format(format or "", ...))) - end -end - -log("mod_main", "Initializing mods...") -log("mod_main", "[DTMM] Deployment data:\n{{ deployment_info }}") - -local require_store = {} - --- This token is treated as a string template and filled by DTMM during deployment. --- This allows hiding unsafe I/O functions behind a setting. --- When not replaced, it's also a valid table definition, thereby degrading gracefully. -local is_io_enabled = {{ is_io_enabled }} -- luacheck: ignore 113 -local lua_libs = { - debug = debug, - os = { - date = os.date, - time = os.time, - clock = os.clock, - getenv = os.getenv, - difftime = os.difftime, - }, - load = load, - loadfile = loadfile, - loadstring = loadstring, -} - -if is_io_enabled then - lua_libs.io = io - lua_libs.os = os - lua_libs.ffi = require("ffi") -end - -Mods = { - -- Keep a backup of certain system libraries before - -- Fatshark's code scrubs them. - -- The loader can then decide to pass them on to mods, or ignore them - lua = setmetatable({}, { __index = lua_libs }), - require_store = require_store, - original_require = require, -} - -local can_insert = function(filepath, new_result) - local store = require_store[filepath] - if not store or #store then - return true - end - - if store[#store] ~= new_result then - return true - end -end - -local original_require = require -require = function(filepath, ...) - local result = original_require(filepath, ...) - if result and type(result) == "table" then - if can_insert(filepath, result) then - require_store[filepath] = require_store[filepath] or {} - local store = require_store[filepath] - - table.insert(store, result) - - if Mods.hook then - Mods.hook.enable_by_file(filepath, #store) - end - end - end - - return result -end - -require("scripts/boot_init") -require("scripts/foundation/utilities/class") - --- The `__index` metamethod maps a proper identifier `CLASS.MyClassName` to the --- stringified version of the key: `"MyClassName"`. --- This allows using LuaCheck for the stringified class names in hook parameters. -_G.CLASS = setmetatable({}, { - __index = function(_, key) - return key - end -}) - -local original_class = class -class = function(class_name, super_name, ...) - local result = original_class(class_name, super_name, ...) - if not rawget(_G, class_name) then - rawset(_G, class_name, result) - end - if not rawget(_G.CLASS, class_name) then - rawset(_G.CLASS, class_name, result) - end - return result -end - -require("scripts/main") -log("mod_main", "'scripts/main' loaded") - --- We need to inject two states into two different state machines: --- First, we inject one into the `"Main"` state machine at a specific location, so that we're --- still early in the process, but right after `StateRequireScripts` where most game files --- are already available to `require` and hook. --- This is where the `ModLoader` is created initially. --- Then, we inject into the very first position of the `"Game"` state machine. This runs right --- after `StateGame._init_managers`, at which point all the parts needed for DMF and other mods --- have been initialized. --- This is where `ModLoader` will finally start loading mods. -local function patch_mod_loading_state() - local StateBootLoadDML = class("StateBootLoadDML", "StateBootSubStateBase") - local StateGameLoadMods = class("StateGameLoadMods") - - StateBootLoadDML.on_enter = function(self, parent, params) - log("StateBootLoadDML", "Entered") - StateBootLoadDML.super.on_enter(self, parent, params) - - local state_params = self:_state_params() - local package_manager = state_params.package_manager - - self._package_manager = package_manager - self._package_handles = { - ["packages/mods"] = package_manager:load("packages/mods", "StateBootLoadDML", nil), - } - end - - StateBootLoadDML._state_update = function(self, _) - local package_manager = self._package_manager - - if package_manager:update() then - local mod_data = require("scripts/mods/mod_data") - - local create_mod_loader = require("scripts/mods/init") - local mod_loader = create_mod_loader(mod_data) - - Managers.mod = mod_loader - - log("StateBootLoadDML", "DML loaded, exiting") - return true, false - end - - return false, false - end - - - function StateGameLoadMods:on_enter(_, params) - log("StateGameLoadMods", "Entered") - self._next_state = require("scripts/game_states/game/state_splash") - self._next_state_params = params - end - - function StateGameLoadMods:update(_) - -- We're relying on the fact that DML internally makes sure - -- that `Managers.mod:update()` is being called appropriately. - -- The implementation as of this writing is to hook `StateGame.update`. - if Managers.mod:all_mods_loaded() then - Log.info("StateGameLoadMods", "Mods loaded, exiting") - return self._next_state, self._next_state_params - end - end - - local GameStateMachine = require("scripts/foundation/utilities/game_state_machine") - local GameStateMachine_init = GameStateMachine.init - GameStateMachine.init = function(self, parent, start_state, params, creation_context, state_change_callbacks, name) - if name == "Main" then - log("mod_main", "Injecting StateBootLoadDML") - - -- Hardcoded position after `StateRequireScripts`. - -- We need to wait until then to even begin most of our stuff, - -- so that most of the game's core systems are at least loaded and can be hooked, - -- even if they aren't running, yet. - local pos = 4 - table.insert(params.states, pos, { - StateBootLoadDML, - { - package_manager = params.package_manager, - }, - }) - - GameStateMachine_init(self, parent, start_state, params, creation_context, state_change_callbacks, name) - elseif name == "Game" then - log("mod_main", "Injection StateGameLoadMods") - -- The second time around, we want to be the first, so we pass our own - -- 'start_state'. - -- We can't just have the state machine be initialized and then change its `_next_state`, as by the end of - -- `init`, a bunch of stuff will already be initialized. - GameStateMachine_init(self, parent, StateGameLoadMods, params, creation_context, state_change_callbacks, name) - -- And since we're done now, we can revert the function to its original - GameStateMachine.init = GameStateMachine_init - else - -- In all other cases, simply call the original - GameStateMachine_init(self, parent, start_state, params, creation_context, state_change_callbacks, name) - end - end -end - --- Override `init` to run our injection -function init() - patch_mod_loading_state() - - -- As requested by Fatshark - local StateRequireScripts = require("scripts/game_states/boot/state_require_scripts") - StateRequireScripts._get_is_modded = function() return true end - - Main:init() -end - --- vim: ft=lua diff --git a/crates/dtmm/assets/tabler-icons/LICENSE b/crates/dtmm/assets/tabler-icons/LICENSE deleted file mode 100644 index fe62055..0000000 --- a/crates/dtmm/assets/tabler-icons/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2023 Paweł Kuna - -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/crates/dtmm/assets/tabler-icons/alert-circle.svg b/crates/dtmm/assets/tabler-icons/alert-circle.svg deleted file mode 100644 index 35e7aad..0000000 --- a/crates/dtmm/assets/tabler-icons/alert-circle.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/crates/dtmm/assets/tabler-icons/alert-triangle.svg b/crates/dtmm/assets/tabler-icons/alert-triangle.svg deleted file mode 100644 index 523111c..0000000 --- a/crates/dtmm/assets/tabler-icons/alert-triangle.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/crates/dtmm/assets/tabler-icons/cloud-download.svg b/crates/dtmm/assets/tabler-icons/cloud-download.svg deleted file mode 100644 index 5b62734..0000000 --- a/crates/dtmm/assets/tabler-icons/cloud-download.svg +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/crates/dtmm/build.rs b/crates/dtmm/build.rs deleted file mode 100644 index 9e551d4..0000000 --- a/crates/dtmm/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - if cfg!(target_os = "windows") { - let mut res = winres::WindowsResource::new(); - res.set_icon("assets/dtmm.ico"); - res.compile().unwrap(); - } -} diff --git a/crates/dtmm/src/controller/app.rs b/crates/dtmm/src/controller/app.rs index d5b397c..d8cb619 100644 --- a/crates/dtmm/src/controller/app.rs +++ b/crates/dtmm/src/controller/app.rs @@ -1,303 +1,213 @@ use std::collections::HashMap; -use std::io::ErrorKind; -use std::path::{Path, PathBuf}; -use std::sync::Arc; +use std::io::{Cursor, ErrorKind, Read}; +use std::path::Path; use color_eyre::eyre::{self, Context}; -use color_eyre::{Help, Report, Result}; +use color_eyre::{Help, Result}; use druid::im::Vector; -use druid::ImageBuf; +use druid::FileInfo; use dtmt_shared::ModConfig; -use nexusmods::Api as NexusApi; -use tokio::fs::{self, DirEntry, File}; +use serde::Deserialize; +use tokio::fs::{self, DirEntry}; +use tokio::runtime::Runtime; use tokio_stream::wrappers::ReadDirStream; use tokio_stream::StreamExt; +use zip::ZipArchive; -use crate::state::{ActionState, InitialLoadResult, ModInfo, ModOrder, NexusInfo, PackageInfo}; -use crate::util; +use crate::state::{ModInfo, PackageInfo, State}; use crate::util::config::{ConfigSerialize, LoadOrderEntry}; -use super::read_sjson_file; +#[tracing::instrument(skip(state))] +pub(crate) async fn import_mod(state: State, info: FileInfo) -> Result { + let data = fs::read(&info.path) + .await + .wrap_err_with(|| format!("failed to read file {}", info.path.display()))?; + let data = Cursor::new(data); + + let mut archive = ZipArchive::new(data).wrap_err("failed to open ZIP archive")?; + + if tracing::enabled!(tracing::Level::DEBUG) { + let names = archive.file_names().fold(String::new(), |mut s, name| { + s.push('\n'); + s.push_str(name); + s + }); + tracing::debug!("Archive contents:{}", names); + } + + let dir_name = { + let f = archive.by_index(0).wrap_err("archive is empty")?; + + if !f.is_dir() { + let err = eyre::eyre!("archive does not have a top-level directory"); + return Err(err).with_suggestion(|| "Use 'dtmt build' to create the mod archive."); + } + + let name = f.name(); + // The directory name is returned with a trailing slash, which we don't want + name[..(name.len().saturating_sub(1))].to_string() + }; + + tracing::info!("Importing mod {}", dir_name); + + let mod_cfg: ModConfig = { + let mut f = archive + .by_name(&format!("{}/{}", dir_name, "dtmt.cfg")) + .wrap_err("failed to read mod config from archive")?; + let mut buf = Vec::with_capacity(f.size() as usize); + f.read_to_end(&mut buf) + .wrap_err("failed to read mod config from archive")?; + + let data = String::from_utf8(buf).wrap_err("mod config is not valid UTF-8")?; + + serde_sjson::from_str(&data).wrap_err("failed to deserialize mod config")? + }; + + tracing::debug!(?mod_cfg); + + let files: HashMap> = { + let mut f = archive + .by_name(&format!("{}/{}", dir_name, "files.sjson")) + .wrap_err("failed to read file index from archive")?; + let mut buf = Vec::with_capacity(f.size() as usize); + f.read_to_end(&mut buf) + .wrap_err("failed to read file index from archive")?; + + let data = String::from_utf8(buf).wrap_err("file index is not valid UTF-8")?; + + serde_sjson::from_str(&data).wrap_err("failed to deserialize file index")? + }; + + tracing::trace!(?files); + + let mod_dir = state.get_mod_dir(); + + tracing::trace!("Creating mods directory {}", mod_dir.display()); + fs::create_dir_all(&mod_dir) + .await + .wrap_err_with(|| format!("failed to create data directory {}", mod_dir.display()))?; + + tracing::trace!("Extracting mod archive to {}", mod_dir.display()); + archive + .extract(&mod_dir) + .wrap_err_with(|| format!("failed to extract archive to {}", mod_dir.display()))?; + + let packages = files + .into_iter() + .map(|(name, files)| PackageInfo::new(name, files.into_iter().collect())) + .collect(); + let info = ModInfo::new(mod_cfg, packages); + + Ok(info) +} #[tracing::instrument(skip(state))] -pub(crate) async fn delete_mod(state: ActionState, info: &ModInfo) -> Result<()> { - let mod_dir = state.mod_dir.join(&info.id); +pub(crate) async fn delete_mod(state: State, info: &ModInfo) -> Result<()> { + let mod_dir = state.get_mod_dir().join(&info.id); fs::remove_dir_all(&mod_dir) .await - .wrap_err_with(|| format!("Failed to remove directory {}", mod_dir.display()))?; + .wrap_err_with(|| format!("failed to remove directory {}", mod_dir.display()))?; Ok(()) } #[tracing::instrument(skip(state))] -pub(crate) async fn save_settings(state: ActionState) -> Result<()> { +pub(crate) async fn save_settings(state: State) -> Result<()> { let cfg = ConfigSerialize::from(&state); tracing::info!("Saving settings to '{}'", state.config_path.display()); tracing::debug!(?cfg); - let data = serde_sjson::to_string(&cfg).wrap_err("Failed to serialize config")?; + let data = serde_sjson::to_string(&cfg).wrap_err("failed to serialize config")?; fs::write(state.config_path.as_ref(), &data) .await .wrap_err_with(|| { format!( - "Failed to write config to '{}'", + "failed to write config to '{}'", state.config_path.display() ) }) } +async fn read_sjson_file(path: P) -> Result +where + T: for<'a> Deserialize<'a>, + P: AsRef + std::fmt::Debug, +{ + let buf = fs::read(path).await.wrap_err("failed to read file")?; + let data = String::from_utf8(buf).wrap_err("invalid UTF8")?; + serde_sjson::from_str(&data).wrap_err("failed to deserialize") +} + #[tracing::instrument(skip_all,fields( name = ?res.as_ref().map(|entry| entry.file_name()) ))] async fn read_mod_dir_entry(res: Result) -> Result { let entry = res?; let config_path = entry.path().join("dtmt.cfg"); - let nexus_path = entry.path().join("nexus.sjson"); let index_path = entry.path().join("files.sjson"); let cfg: ModConfig = read_sjson_file(&config_path) .await - .wrap_err_with(|| format!("Failed to read mod config '{}'", config_path.display()))?; + .wrap_err_with(|| format!("failed to read mod config '{}'", config_path.display()))?; - let nexus: Option = match read_sjson_file(&nexus_path) + let files: HashMap> = read_sjson_file(&index_path) .await - .wrap_err_with(|| format!("Failed to read Nexus info '{}'", nexus_path.display())) - { - Ok(nexus) => Some(nexus), - Err(err) if err.is::() => match err.downcast_ref::() { - Some(err) if err.kind() == std::io::ErrorKind::NotFound => None, - _ => return Err(err), - }, - Err(err) => return Err(err), - }; - - let files: HashMap> = if cfg.bundled { - read_sjson_file(&index_path) - .await - .wrap_err_with(|| format!("Failed to read file index '{}'", index_path.display()))? - } else { - Default::default() - }; - - let image = if let Some(path) = &cfg.image { - let path = entry.path().join(path); - if let Ok(data) = fs::read(&path).await { - // Druid somehow doesn't return an error compatible with eyre, here. - // So we have to wrap through `Display` manually. - let img = match ImageBuf::from_data(&data) { - Ok(img) => img, - Err(err) => { - let err = Report::msg(err.to_string()); - return Err(err) - .wrap_err_with(|| { - format!("Failed to import image file '{}'", path.display()) - }) - .with_suggestion(|| { - "Supported formats are: PNG, JPEG, Bitmap and WebP".to_string() - }); - } - }; - - Some(img) - } else { - None - } - } else { - None - }; + .wrap_err_with(|| format!("failed to read file index '{}'", index_path.display()))?; let packages = files .into_iter() - .map(|(name, files)| Arc::new(PackageInfo::new(name, files.into_iter().collect()))) + .map(|(name, files)| PackageInfo::new(name, files.into_iter().collect())) .collect(); - let info = ModInfo::new(cfg, packages, image, nexus); + let info = ModInfo::new(cfg, packages); Ok(info) } #[tracing::instrument(skip(mod_order))] -pub(crate) async fn load_mods<'a, P, S>(mod_dir: P, mod_order: S) -> Result>> +pub(crate) fn load_mods<'a, P, S>(mod_dir: P, mod_order: S) -> Result> where S: Iterator, P: AsRef + std::fmt::Debug, { - let mod_dir = mod_dir.as_ref(); - let read_dir = match fs::read_dir(mod_dir).await { - Ok(read_dir) => read_dir, - Err(err) if err.kind() == ErrorKind::NotFound => { - return Ok(Vector::new()); - } - Err(err) => { - return Err(err) - .wrap_err_with(|| format!("Failed to open directory '{}'", mod_dir.display())); - } - }; + let rt = Runtime::new()?; - let stream = ReadDirStream::new(read_dir) - .map(|res| res.wrap_err("Failed to read dir entry")) - .then(read_mod_dir_entry); - tokio::pin!(stream); - - let mut mods: HashMap = HashMap::new(); - - while let Some(res) = stream.next().await { - let info = res?; - mods.insert(info.id.clone(), info); - } - - let mods = mod_order - .filter_map(|entry| { - if let Some(mut info) = mods.remove(&entry.id) { - info.enabled = entry.enabled; - Some(Arc::new(info)) - } else { - None + rt.block_on(async move { + let mod_dir = mod_dir.as_ref(); + let read_dir = match fs::read_dir(mod_dir).await { + Ok(read_dir) => read_dir, + Err(err) if err.kind() == ErrorKind::NotFound => { + return Ok(Vector::new()); } - }) - .collect(); - - Ok(mods) -} - -pub(crate) fn check_mod_order(state: &ActionState) -> Result<()> { - if tracing::enabled!(tracing::Level::DEBUG) { - let order = state - .mods - .iter() - .enumerate() - .filter(|(_, i)| i.enabled) - .fold(String::new(), |mut s, (i, info)| { - s.push_str(&format!("{}: {} - {}\n", i, info.id, info.name)); - s - }); - - tracing::debug!("Mod order:\n{}", order); - } - - for (i, mod_info) in state.mods.iter().enumerate().filter(|(_, i)| i.enabled) { - for dep in &mod_info.depends { - let dep_info = state.mods.iter().enumerate().find(|(_, m)| m.id == dep.id); - - match dep_info { - Some((_, dep_info)) if !dep_info.enabled => { - eyre::bail!( - "Dependency '{}' ({}) must be enabled.", - dep_info.name, - dep.id - ); - } - Some((j, dep_info)) if dep.order == ModOrder::Before && j >= i => { - eyre::bail!( - "Dependency '{}' ({}) must be loaded before '{}'", - dep_info.name, - dep.id, - mod_info.name - ); - } - Some((j, dep_info)) if dep.order == ModOrder::After && j <= i => { - eyre::bail!( - "Dependency '{}' ({}) must be loaded after '{}'", - dep_info.name, - dep.id, - mod_info.name - ); - } - None => { - eyre::bail!( - "Missing dependency '{}' for mod '{}'", - dep.id, - mod_info.name - ); - } - Some(_) => { - // All good - } - } - } - } - - Ok(()) -} - -#[tracing::instrument(skip(info, api), fields(id = info.id, name = info.name, version = info.version))] -async fn check_mod_update(info: Arc, api: Arc) -> Result> { - let Some(nexus) = &info.nexus else { - return Ok(None); - }; - - let updated_info = api - .mods_id(nexus.id) - .await - .wrap_err_with(|| format!("Failed to query mod {} from Nexus", nexus.id))?; - - let mut info = Arc::unwrap_or_clone(info); - info.nexus = Some(NexusInfo::from(updated_info)); - - Ok(Some(info)) -} - -#[tracing::instrument(skip(state))] -pub(crate) async fn check_updates(state: ActionState) -> Result> { - if state.nexus_api_key.is_empty() { - eyre::bail!("Nexus API key not set. Cannot check for updates."); - } - - let api = NexusApi::new(state.nexus_api_key.to_string()) - .wrap_err("Failed to initialize Nexus API")?; - let api = Arc::new(api); - - let tasks = state - .mods - .iter() - .map(|info| check_mod_update(info.clone(), api.clone())); - - let results = futures::future::join_all(tasks).await; - let updates = results - .into_iter() - .filter_map(|res| match res { - Ok(info) => info, Err(err) => { - tracing::error!("{:?}", err); - None + return Err(err) + .wrap_err_with(|| format!("failed to open directory '{}'", mod_dir.display())); } - }) - .collect(); - Ok(updates) -} + }; -pub(crate) async fn load_initial(path: PathBuf, is_default: bool) -> Result { - let config = util::config::read_config(path, is_default) - .await - .wrap_err("Failed to read config file")?; + let stream = ReadDirStream::new(read_dir) + .map(|res| res.wrap_err("failed to read dir entry")) + .then(read_mod_dir_entry); + tokio::pin!(stream); - // Create or truncate the log file - let log_path = config.data_dir.join("dtmm.log"); - tokio::spawn(async move { - let _ = File::create(&log_path).await; - tracing::debug!("Truncated log file"); - }); + let mut mods: HashMap = HashMap::new(); - let game_info = tokio::task::spawn_blocking(dtmt_shared::collect_game_info) - .await - .wrap_err("Failed to spawn task to collect Steam game info")?; - - let game_info = match game_info { - Ok(game_info) => game_info, - Err(err) => { - tracing::error!("Failed to collect game info: {:?}", err); - None + while let Some(res) = stream.next().await { + let info = res?; + mods.insert(info.id.clone(), info); } - }; - if config.game_dir.is_none() && game_info.is_none() { - tracing::error!("No Game Directory set. Head to the 'Settings' tab to set it manually",); - } + let mods = mod_order + .filter_map(|entry| { + if let Some(mut info) = mods.remove(&entry.id) { + info.enabled = entry.enabled; + Some(info) + } else { + None + } + }) + .collect(); - let mod_dir = config.data_dir.join("mods"); - let mods = load_mods(mod_dir, config.mod_order.iter()) - .await - .wrap_err("Failed to load mods")?; - - Ok((config, mods)) + Ok::<_, color_eyre::Report>(mods) + }) } diff --git a/crates/dtmm/src/controller/deploy.rs b/crates/dtmm/src/controller/deploy.rs deleted file mode 100644 index 8b36ae2..0000000 --- a/crates/dtmm/src/controller/deploy.rs +++ /dev/null @@ -1,809 +0,0 @@ -use std::io::{Cursor, ErrorKind}; -use std::path::{Path, PathBuf}; -use std::str::FromStr; -use std::sync::Arc; - -use color_eyre::eyre::Context; -use color_eyre::{eyre, Help, Report, Result}; -use futures::StreamExt; -use futures::{stream, TryStreamExt}; -use minijinja::Environment; -use sdk::filetype::lua; -use sdk::filetype::package::Package; -use sdk::murmur::Murmur64; -use sdk::{ - Bundle, BundleDatabase, BundleFile, BundleFileType, BundleFileVariant, FromBinary, ToBinary, -}; -use serde::{Deserialize, Serialize}; -use time::OffsetDateTime; -use tokio::fs::{self, DirEntry}; -use tokio::io::AsyncWriteExt; -use tracing::Instrument; - -use super::read_sjson_file; -use crate::controller::app::check_mod_order; -use crate::state::{ActionState, PackageInfo}; - -pub const MOD_BUNDLE_NAME: &str = "packages/mods"; -pub const BOOT_BUNDLE_NAME: &str = "packages/boot"; -pub const BUNDLE_DATABASE_NAME: &str = "bundle_database.data"; -pub const MOD_BOOT_SCRIPT: &str = "scripts/mod_main"; -pub const MOD_DATA_SCRIPT: &str = "scripts/mods/mod_data"; -pub const SETTINGS_FILE_PATH: &str = "application_settings/settings_common.ini"; -pub const DEPLOYMENT_DATA_PATH: &str = "dtmm-deployment.sjson"; - -#[derive(Debug, Serialize, Deserialize)] -pub struct DeploymentData { - pub bundles: Vec, - pub mod_folders: Vec, - #[serde(with = "time::serde::iso8601")] - pub timestamp: OffsetDateTime, -} - -#[tracing::instrument] -async fn read_file_with_backup

(path: P) -> Result> -where - P: AsRef + std::fmt::Debug, -{ - let path = path.as_ref(); - let backup_path = { - let mut p = PathBuf::from(path); - let ext = if let Some(ext) = p.extension() { - ext.to_string_lossy().to_string() + ".bak" - } else { - String::from("bak") - }; - p.set_extension(ext); - p - }; - - let file_name = path - .file_name() - .map(|s| s.to_string_lossy().to_string()) - .unwrap_or_else(|| String::from("file")); - - let bin = match fs::read(&backup_path).await { - Ok(bin) => bin, - Err(err) if err.kind() == ErrorKind::NotFound => { - // TODO: This doesn't need to be awaited here, yet. - // I only need to make sure it has finished before writing the changed bundle. - tracing::debug!( - "Backup does not exist. Backing up original {} to '{}'", - file_name, - backup_path.display() - ); - fs::copy(path, &backup_path).await.wrap_err_with(|| { - format!( - "Failed to back up {} '{}' to '{}'", - file_name, - path.display(), - backup_path.display() - ) - })?; - - tracing::debug!("Reading {} from original '{}'", file_name, path.display()); - fs::read(path).await.wrap_err_with(|| { - format!("Failed to read {} file: {}", file_name, path.display()) - })? - } - Err(err) => { - return Err(err).wrap_err_with(|| { - format!( - "Failed to read {} from backup '{}'", - file_name, - backup_path.display() - ) - }); - } - }; - Ok(bin) -} - -#[tracing::instrument(skip_all)] -async fn patch_game_settings(state: Arc) -> Result<()> { - let settings_path = state.game_dir.join("bundle").join(SETTINGS_FILE_PATH); - - let settings = read_file_with_backup(&settings_path) - .await - .wrap_err("Failed to read settings.ini")?; - let settings = String::from_utf8(settings).wrap_err("Settings.ini is not valid UTF-8")?; - - let mut f = fs::File::create(&settings_path) - .await - .wrap_err_with(|| format!("Failed to open {}", settings_path.display()))?; - - let Some(i) = settings.find("boot_script =") else { - eyre::bail!("couldn't find 'boot_script' field"); - }; - - f.write_all(&settings.as_bytes()[0..i]).await?; - f.write_all(b"boot_script = \"scripts/mod_main\"").await?; - - let Some(j) = settings[i..].find('\n') else { - eyre::bail!("couldn't find end of 'boot_script' field"); - }; - - f.write_all(&settings.as_bytes()[(i + j)..]).await?; - - Ok(()) -} - -#[tracing::instrument(skip_all, fields(package = info.name))] -fn make_package(info: &PackageInfo) -> Result { - let mut pkg = Package::new(info.name.clone(), PathBuf::new()); - - for f in &info.files { - let mut it = f.rsplit('.'); - let file_type = it - .next() - .ok_or_else(|| eyre::eyre!("missing file extension")) - .and_then(BundleFileType::from_str) - .wrap_err("Invalid file name in package info")?; - let name: String = it.collect(); - pkg.add_file(file_type, name); - } - - Ok(pkg) -} - -#[tracing::instrument] -async fn copy_recursive( - from: impl Into + std::fmt::Debug, - to: impl AsRef + std::fmt::Debug, -) -> Result<()> { - let to = to.as_ref(); - - #[tracing::instrument] - async fn handle_dir(from: PathBuf) -> Result> { - let mut dir = fs::read_dir(&from) - .await - .wrap_err("Failed to read directory")?; - let mut entries = Vec::new(); - - while let Some(entry) = dir.next_entry().await? { - let meta = entry.metadata().await.wrap_err_with(|| { - format!("Failed to get metadata for '{}'", entry.path().display()) - })?; - entries.push((meta.is_dir(), entry)); - } - - Ok(entries) - } - - let base = from.into(); - stream::unfold(vec![base.clone()], |mut state| async { - let from = state.pop()?; - let inner = match handle_dir(from).await { - Ok(entries) => { - for (is_dir, entry) in &entries { - if *is_dir { - state.push(entry.path()); - } - } - stream::iter(entries).map(Ok).left_stream() - } - Err(e) => stream::once(async { Err(e) }).right_stream(), - }; - - Some((inner, state)) - }) - .flatten() - .try_for_each(|(is_dir, entry)| { - let path = entry.path(); - let dest = path - .strip_prefix(&base) - .map(|suffix| to.join(suffix)) - .expect("all entries are relative to the directory we are walking"); - - async move { - if is_dir { - tracing::trace!("Creating directory '{}'", dest.display()); - // Instead of trying to filter "already exists" errors out explicitly, - // we just ignore all. It'll fail eventually with the next copy operation. - let _ = fs::create_dir(&dest).await; - Ok(()) - } else { - tracing::trace!("Copying file '{}' -> '{}'", path.display(), dest.display()); - fs::copy(&path, &dest).await.map(|_| ()).wrap_err_with(|| { - format!( - "Failed to copy file '{}' -> '{}'", - path.display(), - dest.display() - ) - }) - } - } - }) - .await - .map(|_| ()) -} - -#[tracing::instrument(skip(state))] -async fn copy_mod_folders(state: Arc) -> Result> { - let game_dir = Arc::clone(&state.game_dir); - - let mut tasks = Vec::new(); - - for mod_info in state.mods.iter().filter(|m| m.enabled && !m.bundled) { - let span = tracing::trace_span!("copying legacy mod", name = mod_info.name); - let _enter = span.enter(); - - let mod_id = mod_info.id.clone(); - let mod_dir = Arc::clone(&state.mod_dir); - let game_dir = Arc::clone(&game_dir); - - let task = async move { - let from = mod_dir.join(&mod_id); - let to = game_dir.join("mods").join(&mod_id); - - tracing::debug!(from = %from.display(), to = %to.display(), "Copying legacy mod '{}'", mod_id); - let _ = fs::create_dir_all(&to).await; - copy_recursive(&from, &to).await.wrap_err_with(|| { - format!( - "Failed to copy legacy mod from '{}' to '{}'", - from.display(), - to.display() - ) - })?; - - Ok::<_, Report>(mod_id) - }; - tasks.push(task); - } - - let ids = futures::future::try_join_all(tasks).await?; - Ok(ids) -} - -fn build_mod_data_lua(state: Arc) -> Result { - #[derive(Serialize)] - struct TemplateDataMod { - id: String, - name: String, - bundled: bool, - version: String, - init: String, - data: Option, - localization: Option, - packages: Vec, - } - - let mut env = Environment::new(); - env.set_trim_blocks(true); - env.set_lstrip_blocks(true); - env.add_template("mod_data.lua", include_str!("../../assets/mod_data.lua.j2")) - .wrap_err("Failed to compile template for `mod_data.lua`")?; - let tmpl = env - .get_template("mod_data.lua") - .wrap_err("Failed to get template `mod_data.lua`")?; - - let data: Vec = state - .mods - .iter() - .filter_map(|m| { - if !m.enabled { - return None; - } - - Some(TemplateDataMod { - id: m.id.clone(), - name: m.name.clone(), - bundled: m.bundled, - version: m.version.clone(), - init: m.resources.init.to_string_lossy().to_string(), - data: m - .resources - .data - .as_ref() - .map(|p| p.to_string_lossy().to_string()), - localization: m - .resources - .localization - .as_ref() - .map(|p| p.to_string_lossy().to_string()), - packages: m.packages.iter().map(|p| p.name.clone()).collect(), - }) - }) - .collect(); - - let lua = tmpl - .render(minijinja::context!(mods => data)) - .wrap_err("Failed to render template `mod_data.lua`")?; - - tracing::debug!("mod_data.lua:\n{}", lua); - - Ok(lua) -} - -#[tracing::instrument(skip_all)] -async fn build_bundles(state: Arc) -> Result> { - let mut mod_bundle = Bundle::new(MOD_BUNDLE_NAME.to_string()); - let mut tasks = Vec::new(); - - let bundle_dir = Arc::new(state.game_dir.join("bundle")); - - let mut bundles = Vec::new(); - - let mut add_lua_asset = |name: &str, data: &str| { - let span = tracing::info_span!("Compiling Lua", name, data_len = data.len()); - let _enter = span.enter(); - - let file = lua::compile(name.to_string(), data).wrap_err("Failed to compile Lua")?; - - mod_bundle.add_file(file); - - Ok::<_, Report>(()) - }; - - build_mod_data_lua(state.clone()) - .wrap_err("Failed to build 'mod_data.lua'") - .and_then(|data| add_lua_asset(MOD_DATA_SCRIPT, &data))?; - add_lua_asset("scripts/mods/init", include_str!("../../assets/init.lua"))?; - add_lua_asset( - "scripts/mods/mod_loader", - include_str!("../../assets/mod_loader.lua"), - )?; - - tracing::trace!("Preparing tasks to deploy bundle files"); - - for mod_info in state.mods.iter().filter(|m| m.enabled && m.bundled) { - let span = tracing::trace_span!("building mod packages", name = mod_info.name); - let _enter = span.enter(); - - let mod_dir = state.mod_dir.join(&mod_info.id); - for pkg_info in &mod_info.packages { - let span = tracing::trace_span!("building package", name = pkg_info.name); - let _enter = span.enter(); - - tracing::trace!( - "Building package {} for mod {}", - pkg_info.name, - mod_info.name - ); - - let pkg = make_package(pkg_info).wrap_err("Failed to make package")?; - let mut variant = BundleFileVariant::new(); - let bin = pkg - .to_binary() - .wrap_err("Failed to serialize package to binary")?; - variant.set_data(bin); - let mut file = BundleFile::new(pkg_info.name.clone(), BundleFileType::Package); - file.add_variant(variant); - - tracing::trace!( - "Compiled package {} for mod {}", - pkg_info.name, - mod_info.name - ); - - mod_bundle.add_file(file); - - let bundle_name = format!("{:016x}", Murmur64::hash(&pkg_info.name)); - let src = mod_dir.join(&bundle_name); - let dest = bundle_dir.join(&bundle_name); - let pkg_name = pkg_info.name.clone(); - let mod_name = mod_info.name.clone(); - - // Explicitely drop the guard, so that we can move the span - // into the async operation - drop(_enter); - - let ctx = state.ctx.clone(); - - let task = async move { - let bundle = { - let bin = fs::read(&src).await.wrap_err_with(|| { - format!("Failed to read bundle file '{}'", src.display()) - })?; - let name = Bundle::get_name_from_path(&ctx, &src); - Bundle::from_binary(&ctx, name, bin) - .wrap_err_with(|| format!("Failed to parse bundle '{}'", src.display()))? - }; - - tracing::debug!( - src = %src.display(), - dest = %dest.display(), - "Copying bundle '{}' for mod '{}'", - pkg_name, - mod_name, - ); - // We attempt to remove any previous file, so that the hard link can be created. - // We can reasonably ignore errors here, as a 'NotFound' is actually fine, the copy - // may be possible despite an error here, or the error will be reported by it anyways. - // TODO: There is a chance that we delete an actual game bundle, but with 64bit - // hashes, it's low enough for now, and the setup required to detect - // "game bundle vs mod bundle" is non-trivial. - let _ = fs::remove_file(&dest).await; - fs::copy(&src, &dest).await.wrap_err_with(|| { - format!( - "Failed to copy bundle {pkg_name} for mod {mod_name}. Src: {}, dest: {}", - src.display(), - dest.display() - ) - })?; - - Ok::(bundle) - } - .instrument(span); - - tasks.push(task); - } - } - - tracing::debug!("Copying {} mod bundles", tasks.len()); - - let mut tasks = stream::iter(tasks).buffer_unordered(10); - - while let Some(res) = tasks.next().await { - let bundle = res?; - bundles.push(bundle); - } - - { - let path = bundle_dir.join(format!("{:x}", mod_bundle.name().to_murmur64())); - tracing::trace!("Writing mod bundle to '{}'", path.display()); - fs::write(&path, mod_bundle.to_binary()?) - .await - .wrap_err_with(|| format!("Failed to write bundle to '{}'", path.display()))?; - } - - bundles.push(mod_bundle); - - Ok(bundles) -} - -#[tracing::instrument(skip_all)] -async fn patch_boot_bundle(state: Arc, deployment_info: &str) -> Result> { - let bundle_dir = Arc::new(state.game_dir.join("bundle")); - let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes()))); - - let mut bundles = Vec::with_capacity(2); - - let mut boot_bundle = async { - let bin = read_file_with_backup(&bundle_path) - .await - .wrap_err("Failed to read boot bundle")?; - - Bundle::from_binary(&state.ctx, BOOT_BUNDLE_NAME.to_string(), bin) - .wrap_err("Failed to parse boot bundle") - } - .instrument(tracing::trace_span!("read boot bundle")) - .await - .wrap_err_with(|| format!("Failed to read bundle '{BOOT_BUNDLE_NAME}'"))?; - - { - tracing::trace!("Adding mod package file to boot bundle"); - let span = tracing::trace_span!("create mod package file"); - let _enter = span.enter(); - - let mut pkg = Package::new(MOD_BUNDLE_NAME.to_string(), PathBuf::new()); - - for mod_info in &state.mods { - for pkg_info in &mod_info.packages { - pkg.add_file(BundleFileType::Package, &pkg_info.name); - } - } - - pkg.add_file(BundleFileType::Lua, MOD_DATA_SCRIPT); - - let mut variant = BundleFileVariant::new(); - variant.set_data(pkg.to_binary()?); - let mut f = BundleFile::new(MOD_BUNDLE_NAME.to_string(), BundleFileType::Package); - f.add_variant(variant); - - boot_bundle.add_file(f); - } - - { - let span = tracing::debug_span!("Importing mod main script"); - let _enter = span.enter(); - - let mut env = Environment::new(); - env.set_trim_blocks(true); - env.set_lstrip_blocks(true); - env.add_template("mod_main.lua", include_str!("../../assets/mod_main.lua.j2")) - .wrap_err("Failed to compile template for `mod_main.lua`")?; - let tmpl = env - .get_template("mod_main.lua") - .wrap_err("Failed to get template `mod_main.lua`")?; - - let is_io_enabled = if state.is_io_enabled { "true" } else { "false" }; - let deployment_info = deployment_info.replace("\"", "\\\"").replace("\n", "\\n"); - let lua = tmpl - .render(minijinja::context!(is_io_enabled => is_io_enabled, deployment_info => deployment_info)) - .wrap_err("Failed to render template `mod_main.lua`")?; - - tracing::trace!("Main script rendered:\n===========\n{}\n=============", lua); - let file = lua::compile(MOD_BOOT_SCRIPT.to_string(), lua) - .wrap_err("Failed to compile mod main Lua file")?; - - boot_bundle.add_file(file); - } - - async { - let bin = boot_bundle - .to_binary() - .wrap_err("Failed to serialize boot bundle")?; - fs::write(&bundle_path, bin) - .await - .wrap_err_with(|| format!("Failed to write main bundle: {}", bundle_path.display())) - } - .instrument(tracing::trace_span!("write boot bundle")) - .await?; - - bundles.push(boot_bundle); - - Ok(bundles) -} - -#[tracing::instrument(skip_all, fields(bundles = bundles.as_ref().len()))] -async fn patch_bundle_database(state: Arc, bundles: B) -> Result<()> -where - B: AsRef<[Bundle]>, -{ - let bundle_dir = Arc::new(state.game_dir.join("bundle")); - let database_path = bundle_dir.join(BUNDLE_DATABASE_NAME); - - let mut db = { - let bin = read_file_with_backup(&database_path) - .await - .wrap_err("Failed to read bundle database")?; - let mut r = Cursor::new(bin); - let db = BundleDatabase::from_binary(&mut r).wrap_err("Failed to parse bundle database")?; - tracing::trace!("Finished parsing bundle database"); - db - }; - - for bundle in bundles.as_ref() { - tracing::trace!("Adding '{}' to bundle database", bundle.name().display()); - db.add_bundle(bundle); - } - - { - let bin = db - .to_binary() - .wrap_err("Failed to serialize bundle database")?; - fs::write(&database_path, bin).await.wrap_err_with(|| { - format!( - "failed to write bundle database to '{}'", - database_path.display() - ) - })?; - } - - Ok(()) -} - -#[tracing::instrument(skip_all, fields(bundles = bundles.as_ref().len()))] -fn build_deployment_data( - bundles: impl AsRef<[Bundle]>, - mod_folders: impl AsRef<[String]>, -) -> Result { - let info = DeploymentData { - timestamp: OffsetDateTime::now_utc(), - bundles: bundles - .as_ref() - .iter() - .map(|bundle| format!("{:x}", bundle.name().to_murmur64())) - .collect(), - // TODO: - mod_folders: mod_folders.as_ref().to_vec(), - }; - serde_sjson::to_string(&info).wrap_err("Failed to serizalize deployment data") -} - -#[tracing::instrument(skip_all, fields( - game_dir = %state.game_dir.display(), - mods = state.mods.len() -))] -pub(crate) async fn deploy_mods(state: ActionState) -> Result<()> { - let state = Arc::new(state); - let bundle_dir = state.game_dir.join("bundle"); - let boot_bundle_path = format!("{:016x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes())); - - if fs::metadata(bundle_dir.join(format!("{boot_bundle_path}.patch_999"))) - .await - .is_ok() - { - let err = eyre::eyre!("Found dtkit-patch-based mod installation."); - return Err(err) - .with_suggestion(|| { - "If you're a mod author and saved projects directly in 'mods/', \ - use DTMT to migrate them to the new project structure." - .to_string() - }) - .with_suggestion(|| { - "Click 'Reset Game' to remove the previous mod installation.".to_string() - }); - } - - let (_, game_info, deployment_info) = tokio::try_join!( - async { - fs::metadata(&bundle_dir) - .await - .wrap_err("Failed to open game bundle directory") - .with_suggestion(|| "Double-check 'Game Directory' in the Settings tab.") - }, - async { - tokio::task::spawn_blocking(dtmt_shared::collect_game_info) - .await - .map_err(Report::new) - }, - async { - let path = state.game_dir.join(DEPLOYMENT_DATA_PATH); - match read_sjson_file::<_, DeploymentData>(&path).await { - Ok(data) => Ok(Some(data)), - Err(err) => { - if let Some(err) = err.downcast_ref::() - && err.kind() == ErrorKind::NotFound - { - Ok(None) - } else { - Err(err).wrap_err(format!( - "Failed to read deployment data from: {}", - path.display() - )) - } - } - } - } - ) - .wrap_err("Failed to gather deployment information")?; - - let game_info = match game_info { - Ok(game_info) => game_info, - Err(err) => { - tracing::error!("Failed to collect game info: {:#?}", err); - None - } - }; - - tracing::debug!(?game_info, ?deployment_info); - - if let Some(game_info) = game_info { - if deployment_info - .as_ref() - .map(|i| game_info.last_updated > i.timestamp) - .unwrap_or(false) - { - tracing::warn!( - "Game was updated since last mod deployment. \ - Attempting to reconcile game files." - ); - - tokio::try_join!( - async { - let path = bundle_dir.join(BUNDLE_DATABASE_NAME); - let backup_path = path.with_extension("data.bak"); - - fs::copy(&path, &backup_path) - .await - .wrap_err("Failed to re-create backup for bundle database.") - }, - async { - let path = bundle_dir.join(boot_bundle_path); - let backup_path = path.with_extension("bak"); - - fs::copy(&path, &backup_path) - .await - .wrap_err("Failed to re-create backup for boot bundle") - } - ) - .with_suggestion(|| { - "Reset the game using 'Reset Game', then verify game files.".to_string() - })?; - - tracing::info!( - "Successfully re-created game file backups. \ - Continuing mod deployment." - ); - } - } - - check_mod_order(&state)?; - - tracing::info!( - "Deploying {} mods to '{}'.", - state.mods.iter().filter(|i| i.enabled).count(), - bundle_dir.display() - ); - - tracing::info!("Copy legacy mod folders"); - let mod_folders = copy_mod_folders(state.clone()) - .await - .wrap_err("Failed to copy mod folders")?; - - tracing::info!("Build mod bundles"); - let mut bundles = build_bundles(state.clone()) - .await - .wrap_err("Failed to build mod bundles")?; - - let new_deployment_info = build_deployment_data(&bundles, &mod_folders) - .wrap_err("Failed to build new deployment data")?; - - tracing::info!("Patch boot bundle"); - let mut boot_bundles = patch_boot_bundle(state.clone(), &new_deployment_info) - .await - .wrap_err("Failed to patch boot bundle")?; - bundles.append(&mut boot_bundles); - - if let Some(info) = &deployment_info { - let bundle_dir = Arc::new(bundle_dir); - // Remove bundles from the previous deployment that don't match the current one. - // I.e. mods that used to be installed/enabled but aren't anymore. - { - let tasks = info.bundles.iter().cloned().filter_map(|file_name| { - let is_being_deployed = bundles.iter().any(|b2| { - let name = format!("{:016x}", b2.name()); - file_name == name - }); - - if !is_being_deployed { - let bundle_dir = bundle_dir.clone(); - let task = async move { - let path = bundle_dir.join(&file_name); - - tracing::debug!("Removing unused bundle '{}'", file_name); - - if let Err(err) = fs::remove_file(&path).await.wrap_err_with(|| { - format!("Failed to remove unused bundle '{}'", path.display()) - }) { - tracing::error!("{:?}", err); - } - }; - Some(task) - } else { - None - } - }); - - futures::future::join_all(tasks).await; - } - - // Do the same thing for mod folders - { - let tasks = info.mod_folders.iter().filter_map(|mod_id| { - let is_being_deployed = mod_folders.iter().any(|id| id == mod_id); - - if !is_being_deployed { - let path = bundle_dir.join("mods").join(mod_id); - tracing::debug!("Removing unused mod folder '{}'", path.display()); - - let task = async move { - if let Err(err) = fs::remove_dir_all(&path).await.wrap_err_with(|| { - format!("Failed to remove unused legacy mod '{}'", path.display()) - }) { - tracing::error!("{:?}", err); - } - }; - - Some(task) - } else { - None - } - }); - futures::future::join_all(tasks).await; - } - } - - tracing::info!("Patch game settings"); - patch_game_settings(state.clone()) - .await - .wrap_err("Failed to patch game settings")?; - - tracing::info!("Patching bundle database"); - patch_bundle_database(state.clone(), &bundles) - .await - .wrap_err("Failed to patch bundle database")?; - - tracing::info!("Writing deployment data"); - { - let path = state.game_dir.join(DEPLOYMENT_DATA_PATH); - fs::write(&path, &new_deployment_info) - .await - .wrap_err_with(|| format!("Failed to write deployment data to '{}'", path.display()))?; - } - - tracing::info!("Finished deploying mods"); - Ok(()) -} diff --git a/crates/dtmm/src/controller/game.rs b/crates/dtmm/src/controller/game.rs index a5853bb..508e84a 100644 --- a/crates/dtmm/src/controller/game.rs +++ b/crates/dtmm/src/controller/game.rs @@ -1,19 +1,32 @@ -use std::io::{self, ErrorKind}; +use std::ffi::CString; +use std::io::{Cursor, ErrorKind}; use std::path::{Path, PathBuf}; +use std::str::FromStr; use std::sync::Arc; use color_eyre::eyre::Context; -use color_eyre::{eyre, Result}; +use color_eyre::{eyre, Help, Result}; +use futures::stream; +use futures::StreamExt; +use sdk::filetype::lua; +use sdk::filetype::package::Package; use sdk::murmur::Murmur64; -use tokio::fs::{self}; -use tokio::io::AsyncWriteExt; - -use crate::controller::deploy::{ - DeploymentData, BOOT_BUNDLE_NAME, BUNDLE_DATABASE_NAME, DEPLOYMENT_DATA_PATH, +use sdk::{ + Bundle, BundleDatabase, BundleFile, BundleFileType, BundleFileVariant, FromBinary, ToBinary, }; -use crate::state::ActionState; +use tokio::fs; +use tokio::io::AsyncWriteExt; +use tracing::Instrument; -use super::deploy::SETTINGS_FILE_PATH; +use crate::state::{PackageInfo, State}; + +const MOD_BUNDLE_NAME: &str = "packages/mods"; +const BOOT_BUNDLE_NAME: &str = "packages/boot"; +const DML_BUNDLE_NAME: &str = "packages/dml"; +const BUNDLE_DATABASE_NAME: &str = "bundle_database.data"; +const MOD_BOOT_SCRIPT: &str = "scripts/mod_main"; +const MOD_DATA_SCRIPT: &str = "scripts/mods/mod_data"; +const SETTINGS_FILE_PATH: &str = "application_settings/settings_common.ini"; #[tracing::instrument] async fn read_file_with_backup

(path: P) -> Result> @@ -49,7 +62,7 @@ where ); fs::copy(path, &backup_path).await.wrap_err_with(|| { format!( - "Failed to back up {} '{}' to '{}'", + "failed to back up {} '{}' to '{}'", file_name, path.display(), backup_path.display() @@ -58,13 +71,13 @@ where tracing::debug!("Reading {} from original '{}'", file_name, path.display()); fs::read(path).await.wrap_err_with(|| { - format!("Failed to read {} file: {}", file_name, path.display()) + format!("failed to read {} file: {}", file_name, path.display()) })? } Err(err) => { return Err(err).wrap_err_with(|| { format!( - "Failed to read {} from backup '{}'", + "failed to read {} from backup '{}'", file_name, backup_path.display() ) @@ -75,140 +88,458 @@ where } #[tracing::instrument(skip_all)] -async fn patch_game_settings(state: Arc) -> Result<()> { +async fn patch_game_settings(state: Arc) -> Result<()> { let settings_path = state.game_dir.join("bundle").join(SETTINGS_FILE_PATH); let settings = read_file_with_backup(&settings_path) .await - .wrap_err("Failed to read settings.ini")?; - let settings = String::from_utf8(settings).wrap_err("Settings.ini is not valid UTF-8")?; + .wrap_err("failed to read settings.ini")?; + let settings = String::from_utf8(settings).wrap_err("settings.ini is not valid UTF-8")?; let mut f = fs::File::create(&settings_path) .await - .wrap_err_with(|| format!("Failed to open {}", settings_path.display()))?; + .wrap_err_with(|| format!("failed to open {}", settings_path.display()))?; let Some(i) = settings.find("boot_script =") else { eyre::bail!("couldn't find 'boot_script' field"); }; - f.write_all(&settings.as_bytes()[0..i]).await?; + f.write_all(settings[0..i].as_bytes()).await?; f.write_all(b"boot_script = \"scripts/mod_main\"").await?; let Some(j) = settings[i..].find('\n') else { eyre::bail!("couldn't find end of 'boot_script' field"); }; - f.write_all(&settings.as_bytes()[(i + j)..]).await?; + f.write_all(settings[(i + j)..].as_bytes()).await?; Ok(()) } +#[tracing::instrument(skip_all, fields(package = info.name))] +fn make_package(info: &PackageInfo) -> Result { + let mut pkg = Package::new(info.name.clone(), PathBuf::new()); + + for f in &info.files { + let mut it = f.rsplit('.'); + let file_type = it + .next() + .ok_or_else(|| eyre::eyre!("missing file extension")) + .and_then(BundleFileType::from_str) + .wrap_err("invalid file name in package info")?; + let name: String = it.collect(); + pkg.add_file(file_type, name); + } + + Ok(pkg) +} + +fn build_mod_data_lua(state: Arc) -> String { + let mut lua = String::from("return {\n"); + + // DMF is handled explicitely by the loading procedures, as it actually drives most of that + // and should therefore not show up in the load order. + for mod_info in state.mods.iter().filter(|m| m.id != "dml" && m.enabled) { + lua.push_str(" {\n name = \""); + lua.push_str(&mod_info.name); + + lua.push_str("\",\n id = \""); + lua.push_str(&mod_info.id); + + lua.push_str("\",\n run = function()\n"); + + let resources = &mod_info.resources; + if resources.data.is_some() || resources.localization.is_some() { + lua.push_str(" new_mod(\""); + lua.push_str(&mod_info.id); + lua.push_str("\", {\n mod_script = \""); + lua.push_str(&resources.init.to_string_lossy()); + + if let Some(data) = resources.data.as_ref() { + lua.push_str("\",\n mod_data = \""); + lua.push_str(&data.to_string_lossy()); + } + + if let Some(localization) = &resources.localization { + lua.push_str("\",\n mod_localization = \""); + lua.push_str(&localization.to_string_lossy()); + } + + lua.push_str("\",\n })\n"); + } else { + lua.push_str(" return dofile(\""); + lua.push_str(&resources.init.to_string_lossy()); + lua.push_str("\")\n"); + } + + lua.push_str(" end,\n packages = {\n"); + + for pkg_info in &mod_info.packages { + lua.push_str(" \""); + lua.push_str(&pkg_info.name); + lua.push_str("\",\n"); + } + + lua.push_str(" },\n },\n"); + } + + lua.push('}'); + + tracing::debug!("mod_data_lua:\n{}", lua); + + lua +} + #[tracing::instrument(skip_all)] -async fn reset_dtkit_patch(state: ActionState) -> Result<()> { - let bundle_dir = state.game_dir.join("bundle"); +async fn build_bundles(state: Arc) -> Result> { + let mut mod_bundle = Bundle::new(MOD_BUNDLE_NAME.to_string()); + let mut tasks = Vec::new(); + + let bundle_dir = Arc::new(state.game_dir.join("bundle")); + + let mut bundles = Vec::new(); { - let path = bundle_dir.join(BUNDLE_DATABASE_NAME); - let backup_path = path.with_extension("data.bak"); - fs::rename(&backup_path, &path).await.wrap_err_with(|| { + let span = tracing::debug_span!("Building mod data script"); + let _enter = span.enter(); + + let lua = build_mod_data_lua(state.clone()); + let lua = CString::new(lua).wrap_err("failed to build CString from mod data Lua string")?; + let file = + lua::compile(MOD_DATA_SCRIPT, &lua).wrap_err("failed to compile mod data Lua file")?; + + mod_bundle.add_file(file); + } + + for mod_info in state.mods.iter().filter(|m| m.id != "dml" && m.enabled) { + let span = tracing::trace_span!("building mod packages", name = mod_info.name); + let _enter = span.enter(); + + let mod_dir = state.get_mod_dir().join(&mod_info.id); + for pkg_info in &mod_info.packages { + let span = tracing::trace_span!("building package", name = pkg_info.name); + let _enter = span.enter(); + + let pkg = make_package(pkg_info).wrap_err("failed to make package")?; + let mut variant = BundleFileVariant::new(); + let bin = pkg + .to_binary() + .wrap_err("failed to serialize package to binary")?; + variant.set_data(bin); + let mut file = BundleFile::new(pkg_info.name.clone(), BundleFileType::Package); + file.add_variant(variant); + + mod_bundle.add_file(file); + + let bundle_name = Murmur64::hash(&pkg_info.name) + .to_string() + .to_ascii_lowercase(); + let src = mod_dir.join(&bundle_name); + let dest = bundle_dir.join(&bundle_name); + let pkg_name = pkg_info.name.clone(); + let mod_name = mod_info.name.clone(); + + // Explicitely drop the guard, so that we can move the span + // into the async operation + drop(_enter); + + let ctx = state.ctx.clone(); + + let task = async move { + let bundle = { + let bin = fs::read(&src).await.wrap_err_with(|| { + format!("failed to read bundle file '{}'", src.display()) + })?; + let name = Bundle::get_name_from_path(&ctx, &src); + Bundle::from_binary(&ctx, name, bin) + .wrap_err_with(|| format!("failed to parse bundle '{}'", src.display()))? + }; + + tracing::debug!( + src = %src.display(), + dest = %dest.display(), + "Copying bundle '{}' for mod '{}'", + pkg_name, + mod_name, + ); + // We attempt to remove any previous file, so that the hard link can be created. + // We can reasonably ignore errors here, as a 'NotFound' is actually fine, the copy + // may be possible despite an error here, or the error will be reported by it anyways. + // TODO: There is a chance that we delete an actual game bundle, but with 64bit + // hashes, it's low enough for now, and the setup required to detect + // "game bundle vs mod bundle" is non-trivial. + let _ = fs::remove_file(&dest).await; + fs::copy(&src, &dest).await.wrap_err_with(|| { + format!( + "failed to copy bundle {pkg_name} for mod {mod_name}. src: {}, dest: {}", + src.display(), + dest.display() + ) + })?; + + Ok::(bundle) + } + .instrument(span); + + tasks.push(task); + } + } + + tracing::debug!("Copying {} mod bundles", tasks.len()); + + let mut tasks = stream::iter(tasks).buffer_unordered(10); + + while let Some(res) = tasks.next().await { + let bundle = res?; + bundles.push(bundle); + } + + { + let path = bundle_dir.join(format!("{:x}", mod_bundle.name().to_murmur64())); + tracing::trace!("Writing mod bundle to '{}'", path.display()); + fs::write(&path, mod_bundle.to_binary()?) + .await + .wrap_err_with(|| format!("failed to write bundle to '{}'", path.display()))?; + } + + bundles.push(mod_bundle); + + Ok(bundles) +} + +#[tracing::instrument(skip_all)] +async fn patch_boot_bundle(state: Arc) -> Result> { + let bundle_dir = Arc::new(state.game_dir.join("bundle")); + let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes()))); + + let mut bundles = Vec::with_capacity(2); + + let mut boot_bundle = async { + let bin = read_file_with_backup(&bundle_path) + .await + .wrap_err("failed to read boot bundle")?; + + Bundle::from_binary(&state.ctx, BOOT_BUNDLE_NAME.to_string(), bin) + .wrap_err("failed to parse boot bundle") + } + .instrument(tracing::trace_span!("read boot bundle")) + .await + .wrap_err_with(|| format!("failed to read bundle '{}'", BOOT_BUNDLE_NAME))?; + + { + tracing::trace!("Adding mod package file to boot bundle"); + let span = tracing::trace_span!("create mod package file"); + let _enter = span.enter(); + + let mut pkg = Package::new(MOD_BUNDLE_NAME.to_string(), PathBuf::new()); + + for mod_info in &state.mods { + for pkg_info in &mod_info.packages { + pkg.add_file(BundleFileType::Package, &pkg_info.name); + } + } + + pkg.add_file(BundleFileType::Lua, MOD_DATA_SCRIPT); + + let mut variant = BundleFileVariant::new(); + variant.set_data(pkg.to_binary()?); + let mut f = BundleFile::new(MOD_BUNDLE_NAME.to_string(), BundleFileType::Package); + f.add_variant(variant); + + boot_bundle.add_file(f); + } + + { + tracing::trace!("Handling DML packages and bundle"); + let span = tracing::trace_span!("handle DML"); + let _enter = span.enter(); + + let mut variant = BundleFileVariant::new(); + + let mod_info = state + .mods + .iter() + .find(|m| m.id == "dml") + .ok_or_else(|| eyre::eyre!("DML not found in mod list"))?; + let pkg_info = mod_info + .packages + .get(0) + .ok_or_else(|| eyre::eyre!("invalid mod package for DML")) + .with_suggestion(|| "Re-download and import the newest version.".to_string())?; + let bundle_name = Murmur64::hash(&pkg_info.name) + .to_string() + .to_ascii_lowercase(); + let src = state.get_mod_dir().join(&mod_info.id).join(&bundle_name); + + { + let bin = fs::read(&src) + .await + .wrap_err_with(|| format!("failed to read bundle file '{}'", src.display()))?; + let name = Bundle::get_name_from_path(&state.ctx, &src); + + let dml_bundle = Bundle::from_binary(&state.ctx, name, bin) + .wrap_err_with(|| format!("failed to parse bundle '{}'", src.display()))?; + + bundles.push(dml_bundle); + }; + + { + let dest = bundle_dir.join(&bundle_name); + let pkg_name = pkg_info.name.clone(); + let mod_name = mod_info.name.clone(); + + tracing::debug!( + "Copying bundle {} for mod {}: {} -> {}", + pkg_name, + mod_name, + src.display(), + dest.display() + ); + // We attempt to remove any previous file, so that the hard link can be created. + // We can reasonably ignore errors here, as a 'NotFound' is actually fine, the copy + // may be possible despite an error here, or the error will be reported by it anyways. + // TODO: There is a chance that we delete an actual game bundle, but with 64bit + // hashes, it's low enough for now, and the setup required to detect + // "game bundle vs mod bundle" is non-trivial. + let _ = fs::remove_file(&dest).await; + fs::copy(&src, &dest).await.wrap_err_with(|| { + format!( + "failed to copy bundle {pkg_name} for mod {mod_name}. src: {}, dest: {}", + src.display(), + dest.display() + ) + })?; + } + + let pkg = make_package(pkg_info).wrap_err("failed to create package file for dml")?; + variant.set_data(pkg.to_binary()?); + + let mut f = BundleFile::new(DML_BUNDLE_NAME.to_string(), BundleFileType::Package); + f.add_variant(variant); + + boot_bundle.add_file(f); + } + + { + let span = tracing::debug_span!("Importing mod main script"); + let _enter = span.enter(); + + let lua = include_str!("../../assets/mod_main.lua"); + let lua = CString::new(lua).wrap_err("failed to build CString from mod main Lua string")?; + let file = + lua::compile(MOD_BOOT_SCRIPT, &lua).wrap_err("failed to compile mod main Lua file")?; + + boot_bundle.add_file(file); + } + + async { + let bin = boot_bundle + .to_binary() + .wrap_err("failed to serialize boot bundle")?; + fs::write(&bundle_path, bin) + .await + .wrap_err_with(|| format!("failed to write main bundle: {}", bundle_path.display())) + } + .instrument(tracing::trace_span!("write boot bundle")) + .await?; + + bundles.push(boot_bundle); + + Ok(bundles) +} + +#[tracing::instrument(skip_all, fields(bundles = bundles.len()))] +async fn patch_bundle_database(state: Arc, bundles: Vec) -> Result<()> { + let bundle_dir = Arc::new(state.game_dir.join("bundle")); + let database_path = bundle_dir.join(BUNDLE_DATABASE_NAME); + + let mut db = { + let bin = read_file_with_backup(&database_path) + .await + .wrap_err("failed to read bundle database")?; + let mut r = Cursor::new(bin); + let db = BundleDatabase::from_binary(&mut r).wrap_err("failed to parse bundle database")?; + tracing::trace!("Finished parsing bundle database"); + db + }; + + for bundle in bundles { + tracing::trace!("Adding '{}' to bundle database", bundle.name().display()); + db.add_bundle(&bundle); + } + + { + let bin = db + .to_binary() + .wrap_err("failed to serialize bundle database")?; + fs::write(&database_path, bin).await.wrap_err_with(|| { format!( - "Failed to move bundle database backup '{}' -> '{}'", - backup_path.display(), - path.display() + "failed to write bundle database to '{}'", + database_path.display() ) })?; - tracing::trace!("Reverted bundle database from backup"); } - for path in [ - bundle_dir.join(format!( - "{:016x}.patch_999", - Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes()) - )), - state.game_dir.join("binaries/mod_loader"), - state.game_dir.join("toggle_darktide_mods.bat"), - state.game_dir.join("README.md"), - ] { - match fs::remove_file(&path).await { - Ok(_) => tracing::trace!("Removed file '{}'", path.display()), - Err(err) if err.kind() != io::ErrorKind::NotFound => { - tracing::error!("Failed to remove file '{}': {}", path.display(), err) - } - Err(_) => {} + Ok(()) +} + +#[tracing::instrument(skip_all, fields( + game_dir = %state.game_dir.display(), + mods = state.mods.len() +))] +pub(crate) async fn deploy_mods(state: State) -> Result<()> { + let state = Arc::new(state); + + { + let first = state.mods.get(0); + if first.is_none() || !(first.unwrap().id == "dml" && first.unwrap().enabled) { + // TODO: Add a suggestion where to get it, once that's published + eyre::bail!("'Darktide Mod Loader' needs to be installed, enabled and at the top of the load order"); } } - // We deliberately skip the `mods/` directory here. - // Many modders did their development right in there, and as people are prone to not read - // error messages and guides in full, there is bound to be someone who would have - // deleted all their source code if this removed the `mods/` folder. - for path in [state.game_dir.join("tools")] { - match fs::remove_dir_all(&path).await { - Ok(_) => tracing::trace!("Removed directory '{}'", path.display()), - Err(err) if err.kind() != io::ErrorKind::NotFound => { - tracing::error!("Failed to remove directory '{}': {}", path.display(), err) - } - Err(_) => {} - } - } + tracing::info!( + "Deploying {} mods to {}", + state.mods.len(), + state.game_dir.join("bundle").display() + ); - tracing::info!("Removed dtkit-patch-based mod installation."); + tracing::info!("Build mod bundles"); + let mut bundles = build_bundles(state.clone()) + .await + .wrap_err("failed to build mod bundles")?; + + tracing::info!("Patch boot bundle"); + let mut more_bundles = patch_boot_bundle(state.clone()) + .await + .wrap_err("failed to patch boot bundle")?; + bundles.append(&mut more_bundles); + + tracing::info!("Patch game settings"); + patch_game_settings(state.clone()) + .await + .wrap_err("failed to patch game settings")?; + + tracing::info!("Patching bundle database"); + patch_bundle_database(state.clone(), bundles) + .await + .wrap_err("failed to patch bundle database")?; + + tracing::info!("Finished deploying mods"); Ok(()) } #[tracing::instrument(skip(state))] -pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> { +pub(crate) async fn reset_mod_deployment(state: State) -> Result<()> { let boot_bundle_path = format!("{:016x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes())); let paths = [BUNDLE_DATABASE_NAME, &boot_bundle_path, SETTINGS_FILE_PATH]; let bundle_dir = state.game_dir.join("bundle"); tracing::info!("Resetting mod deployment in {}", bundle_dir.display()); - if fs::metadata(bundle_dir.join(format!("{boot_bundle_path}.patch_999"))) - .await - .is_ok() - { - tracing::info!("Found dtkit-patch-based mod installation. Removing."); - return reset_dtkit_patch(state).await; - } - - tracing::debug!("Reading mod deployment"); - - let info: DeploymentData = { - let path = state.game_dir.join(DEPLOYMENT_DATA_PATH); - let data = match fs::read(&path).await { - Ok(data) => data, - Err(err) if err.kind() == ErrorKind::NotFound => { - tracing::info!("No deployment to reset"); - return Ok(()); - } - Err(err) => { - return Err(err).wrap_err_with(|| { - format!("Failed to read deployment info at '{}'", path.display()) - }); - } - }; - - let data = String::from_utf8(data).wrap_err("Invalid UTF8 in deployment data")?; - - serde_sjson::from_str(&data).wrap_err("Invalid SJSON in deployment data")? - }; - - for name in info.bundles { - let path = bundle_dir.join(name); - - match fs::remove_file(&path).await { - Ok(_) => {} - Err(err) if err.kind() == ErrorKind::NotFound => {} - Err(err) => { - tracing::error!("Failed to remove '{}': {:?}", path.display(), err); - } - }; - } - for p in paths { let path = bundle_dir.join(p); - let backup = bundle_dir.join(format!("{p}.bak")); + let backup = bundle_dir.join(&format!("{}.bak", p)); let res = async { tracing::debug!( @@ -219,17 +550,13 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> { fs::copy(&backup, &path) .await - .wrap_err_with(|| format!("Failed to copy from '{}'", backup.display()))?; + .wrap_err_with(|| format!("failed to copy from '{}'", backup.display()))?; tracing::debug!("Deleting backup: {}", backup.display()); - match fs::remove_file(&backup).await { - Ok(_) => Ok(()), - Err(err) if err.kind() == ErrorKind::NotFound => Ok(()), - Err(err) => { - Err(err).wrap_err_with(|| format!("Failed to remove '{}'", backup.display())) - } - } + fs::remove_file(&backup) + .await + .wrap_err_with(|| format!("failed to remove '{}'", backup.display())) } .await; @@ -242,17 +569,6 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> { } } - { - let path = state.game_dir.join(DEPLOYMENT_DATA_PATH); - if let Err(err) = fs::remove_file(&path).await { - tracing::error!( - "Failed to remove deployment data '{}': {:?}", - path.display(), - err - ); - } - } - tracing::info!("Reset finished"); Ok(()) diff --git a/crates/dtmm/src/controller/import.rs b/crates/dtmm/src/controller/import.rs deleted file mode 100644 index 36f3268..0000000 --- a/crates/dtmm/src/controller/import.rs +++ /dev/null @@ -1,584 +0,0 @@ -use std::collections::HashMap; -use std::ffi::CStr; -use std::io::{Cursor, Read, Seek, Write}; -use std::path::{Path, PathBuf}; -use std::sync::Arc; - -use color_eyre::eyre::{self, Context}; -use color_eyre::{Help, Report, Result}; -use druid::im::Vector; -use druid::{FileInfo, ImageBuf}; -use dtmt_shared::{ModConfig, ModConfigResources}; -use luajit2_sys as lua; -use nexusmods::Api as NexusApi; -use tokio::fs; -use zip::ZipArchive; - -use crate::state::{ActionState, ModInfo, NexusInfo, PackageInfo}; - -fn find_archive_file( - archive: &ZipArchive, - name: impl AsRef, -) -> Option { - let path = archive - .file_names() - .find(|path| path.ends_with(name.as_ref())) - .map(|s| s.to_string()); - path -} - -fn image_data_to_buffer(data: impl AsRef<[u8]>) -> Result { - // Druid somehow doesn't return an error compatible with eyre, here. - // So we have to wrap through `Display` manually. - ImageBuf::from_data(data.as_ref()).map_err(|err| { - Report::msg(err.to_string()) - .wrap_err("Invalid image data") - .suggestion("Supported formats are: PNG, JPEG, Bitmap and WebP") - }) -} - -// Runs the content of a `.mod` file to extract what data we can get -// from legacy mods. -// 1. Create a global function `new_mod` that stores -// the relevant bits in global variables. -// 2. Run the `.mod` file, which will return a table. -// 3. Run the `run` function from that table. -// 4. Access the global variables from #1. -#[tracing::instrument] -fn parse_mod_id_file(data: &str) -> Result<(String, ModConfigResources)> { - tracing::debug!("Parsing mod file:\n{}", data); - - let ret = unsafe { - let state = lua::luaL_newstate(); - lua::luaL_openlibs(state); - - let run = b" -function fassert() end -function new_mod(id, resources) - _G.id = id - _G.script = resources.mod_script - _G.data = resources.mod_data - _G.localization = resources.mod_localization -end -\0"; - match lua::luaL_loadstring(state, run.as_ptr() as _) as u32 { - lua::LUA_OK => {} - lua::LUA_ERRSYNTAX => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Invalid syntax: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory to create `new_mod`") - } - _ => unreachable!(), - } - - match lua::lua_pcall(state, 0, 0, 0) as u32 { - lua::LUA_OK => {} - lua::LUA_ERRRUN => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Failed to run buffer: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory to run buffer") - } - // We don't use an error handler function, so this should be unreachable - lua::LUA_ERRERR => unreachable!(), - _ => unreachable!(), - } - - let name = b".mod\0"; - match lua::luaL_loadbuffer( - state, - data.as_ptr() as _, - data.len() as _, - name.as_ptr() as _, - ) as u32 - { - lua::LUA_OK => {} - lua::LUA_ERRSYNTAX => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Invalid syntax: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory to load `.mod` file buffer") - } - _ => unreachable!(), - } - - match lua::lua_pcall(state, 0, 1, 0) as u32 { - lua::LUA_OK => {} - lua::LUA_ERRRUN => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Failed to run `.mod` file: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory to run `.mod` file") - } - // We don't use an error handler function, so this should be unreachable - lua::LUA_ERRERR => unreachable!(), - _ => unreachable!(), - } - - let key = b"run\0"; - lua::lua_pushstring(state, key.as_ptr() as _); - lua::lua_gettable(state, -2); - - match lua::lua_pcall(state, 0, 0, 0) as u32 { - lua::LUA_OK => {} - lua::LUA_ERRRUN => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Failed to run `.mod.run`: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory to run `.mod.run`") - } - // We don't use an error handler function, so this should be unreachable - lua::LUA_ERRERR => unreachable!(), - _ => unreachable!(), - } - - let get_global = |state, key: &[u8]| { - lua::lua_getglobal(state, key.as_ptr() as _); - - if lua::lua_isnil(state, -1) != 0 { - return Ok(None); - } - - let s = lua::lua_tostring(state, -1); - - if s.is_null() { - eyre::bail!("Expected string, got NULL"); - } - - let ret = CStr::from_ptr(s).to_string_lossy().to_string(); - lua::lua_pop(state, 1); - Ok(Some(ret)) - }; - - let mod_id = get_global(state, b"id\0") - .and_then(|s| s.ok_or_else(|| eyre::eyre!("Got `nil`"))) - .wrap_err("Failed to get `id`")?; - - let resources = ModConfigResources { - init: get_global(state, b"script\0") - .and_then(|s| s.map(PathBuf::from).ok_or_else(|| eyre::eyre!("Got `nil`"))) - .wrap_err("Failed to get `script`.")?, - data: get_global(state, b"data\0") - .wrap_err("Failed to get `data`.")? - .map(PathBuf::from), - localization: get_global(state, b"localization\0") - .wrap_err("Failed to get `localization`")? - .map(PathBuf::from), - }; - - lua::lua_close(state); - - (mod_id, resources) - }; - - Ok(ret) -} - -// Extracts the mod configuration from the mod archive. -// This may either be a proper `dtmt.cfg`, or the legacy `.mod` ID file. -// -// It also returns the directory where this file was found, used as root path. This -// allows flexibility in what the directory structure is exactly, since many people -// still end up creating tarbombs and Nexus does its own re-packaging. -#[tracing::instrument(skip(archive))] -fn extract_mod_config(archive: &mut ZipArchive) -> Result<(ModConfig, String)> { - let legacy_mod_data = if let Some(name) = find_archive_file(archive, ".mod") { - let (mod_id, resources) = { - let mut f = archive - .by_name(&name) - .wrap_err("Failed to read `.mod` file from archive")?; - - let mut buf = Vec::with_capacity(f.size() as usize); - f.read_to_end(&mut buf) - .wrap_err("Failed to read `.mod` file from archive")?; - - let data = String::from_utf8(buf).wrap_err("`.mod` file is not valid UTF-8")?; - parse_mod_id_file(&data) - .wrap_err("Invalid `.mod` file") - .note( - "The `.mod` file's `run` function may not contain any additional logic \ - besides the default.", - ) - .suggestion("Contact the mod author to fix this.")? - }; - - let root = if let Some(index) = name.rfind('/') { - name[..index].to_string() - } else { - String::new() - }; - - Some((mod_id, resources, root)) - } else { - None - }; - - tracing::debug!(?legacy_mod_data); - - if let Some(name) = find_archive_file(archive, "dtmt.cfg") { - let mut f = archive - .by_name(&name) - .wrap_err("Failed to read mod config from archive")?; - - let mut buf = Vec::with_capacity(f.size() as usize); - f.read_to_end(&mut buf) - .wrap_err("Failed to read mod config from archive")?; - - let data = String::from_utf8(buf).wrap_err("Mod config is not valid UTF-8")?; - - let mut cfg: ModConfig = serde_sjson::from_str(&data) - .wrap_err("Failed to deserialize mod config") - .suggestion("Contact the mod author to fix this.")?; - - if let Some((mod_id, resources, root)) = legacy_mod_data { - if cfg.id != mod_id { - let err = eyre::eyre!("Mod ID in `dtmt.cfg` does not match mod ID in `.mod` file"); - return Err(err).suggestion("Contact the mod author to fix this."); - } - - cfg.resources = resources; - - // Enforce that packages are skipped - cfg.bundled = false; - cfg.packages = vec![]; - - Ok((cfg, root)) - } else { - let root = name - .strip_suffix("dtmt.cfg") - .expect("String must end with that suffix") - .to_string(); - - Ok((cfg, root)) - } - } else if let Some((mod_id, resources, root)) = legacy_mod_data { - let cfg = ModConfig { - bundled: false, - dir: PathBuf::new(), - id: mod_id.clone(), - name: mod_id, - summary: "A mod for the game Warhammer 40,000: Darktide".into(), - version: "N/A".into(), - description: None, - author: None, - image: None, - categories: Vec::new(), - packages: Vec::new(), - resources, - depends: Vec::new(), - name_overrides: Default::default(), - }; - - Ok((cfg, root)) - } else { - eyre::bail!( - "Mod needs a config file or `.mod` file. \ - Please get in touch with the author to provide a properly packaged mod." - ); - } -} - -#[tracing::instrument(skip(archive))] -fn extract_bundled_mod( - archive: &mut ZipArchive, - root: String, - dest: impl AsRef + std::fmt::Debug, -) -> Result>> { - let files: HashMap> = { - let name = archive - .file_names() - .find(|name| name.ends_with("files.sjson")) - .map(|s| s.to_string()) - .ok_or_else(|| eyre::eyre!("archive does not contain file index"))?; - - let mut f = archive - .by_name(&name) - .wrap_err("Failed to read file index from archive")?; - let mut buf = Vec::with_capacity(f.size() as usize); - f.read_to_end(&mut buf) - .wrap_err("Failed to read file index from archive")?; - - let data = String::from_utf8(buf).wrap_err("File index is not valid UTF-8")?; - serde_sjson::from_str(&data).wrap_err("Failed to deserialize file index")? - }; - - tracing::trace!(?files); - - let dest = dest.as_ref(); - tracing::trace!("Extracting mod archive to {}", dest.display()); - archive - .extract(dest) - .wrap_err_with(|| format!("Failed to extract archive to {}", dest.display()))?; - - let packages = files - .into_iter() - .map(|(name, files)| Arc::new(PackageInfo::new(name, files.into_iter().collect()))) - .collect(); - - tracing::trace!(?packages); - - Ok(packages) -} - -#[tracing::instrument(skip(archive))] -fn extract_legacy_mod( - archive: &mut ZipArchive, - root: String, - dest: impl Into + std::fmt::Debug, -) -> Result<()> { - let dest = dest.into(); - let file_count = archive.len(); - - for i in 0..file_count { - let mut f = archive - .by_index(i) - .wrap_err_with(|| format!("Failed to get file at index {i}"))?; - - let Some(name) = f.enclosed_name().map(|p| p.to_path_buf()) else { - let err = eyre::eyre!("File name in archive is not a safe path value.").suggestion( - "Only use well-known applications to create the ZIP archive, \ - and don't create paths that point outside the archive directory.", - ); - return Err(err); - }; - - let Ok(suffix) = name.strip_prefix(&root) else { - tracing::warn!( - "Skipping file outside of the mod root directory: {}", - name.display() - ); - continue; - }; - let name = dest.join(suffix); - - if f.is_dir() { - // The majority of errors will actually be "X already exists". - // But rather than filter them invidually, we just ignore all of them. - // If there is a legitimate error of "couldn't create X", it will eventually fail when - // we try to put a file in there. - tracing::trace!("Creating directory '{}'", name.display()); - let _ = std::fs::create_dir_all(&name); - } else { - let mut buf = Vec::with_capacity(f.size() as usize); - f.read_to_end(&mut buf) - .wrap_err_with(|| format!("Failed to read file '{}'", name.display()))?; - - tracing::trace!("Writing file '{}'", name.display()); - let mut out = std::fs::OpenOptions::new() - .write(true) - .truncate(true) - .open(&name) - .wrap_err_with(|| format!("Failed to open file '{}'", name.display()))?; - - out.write_all(&buf) - .wrap_err_with(|| format!("Failed to write to '{}'", name.display()))?; - } - } - - Ok(()) -} - -#[tracing::instrument(skip(state))] -pub(crate) async fn import_from_file(state: ActionState, info: FileInfo) -> Result { - let data = fs::read(&info.path) - .await - .wrap_err_with(|| format!("Failed to read file {}", info.path.display()))?; - - let nexus = if let Some((_, id, version, timestamp)) = info - .path - .file_name() - .and_then(|s| s.to_str()) - .and_then(NexusApi::parse_file_name) - { - if !state.nexus_api_key.is_empty() { - let api = NexusApi::new(state.nexus_api_key.to_string())?; - let mod_info = api - .mods_id(id) - .await - .wrap_err_with(|| format!("Failed to query mod {id} from Nexus"))?; - - let version = match api.file_version(id, timestamp).await { - Ok(version) => version, - Err(err) => { - let err = Report::new(err); - tracing::warn!( - "Failed to fetch version for Nexus download. \ - Falling back to file name:\n{:?}", - err - ); - version - } - }; - - let info = NexusInfo::from(mod_info); - tracing::debug!(version, ?info); - - Some((info, version)) - } else { - None - } - } else { - None - }; - - tracing::trace!(?nexus); - - import_mod(state, nexus, data).await -} - -#[tracing::instrument(skip(state))] -pub(crate) async fn import_from_nxm(state: ActionState, uri: String) -> Result { - let url = uri - .parse() - .wrap_err_with(|| format!("Invalid Uri '{uri}'"))?; - - let api = NexusApi::new(state.nexus_api_key.to_string())?; - let (mod_info, file_info, data) = api - .handle_nxm(url) - .await - .wrap_err_with(|| format!("Failed to download mod from NXM uri '{uri}'"))?; - - let nexus = NexusInfo::from(mod_info); - import_mod(state, Some((nexus, file_info.version)), data).await -} - -#[tracing::instrument(skip(state, data), fields(data = data.len()))] -pub(crate) async fn import_mod( - state: ActionState, - nexus: Option<(NexusInfo, String)>, - data: Vec, -) -> Result { - let data = Cursor::new(data); - let mut archive = ZipArchive::new(data).wrap_err("Failed to open ZIP archive")?; - - if tracing::enabled!(tracing::Level::DEBUG) { - let names = archive.file_names().fold(String::new(), |mut s, name| { - s.push('\n'); - s.push_str(name); - s - }); - tracing::debug!("Archive contents:{}", names); - } - - let (mut mod_cfg, root) = - extract_mod_config(&mut archive).wrap_err("Failed to extract mod configuration")?; - tracing::info!("Importing mod {} ({})", mod_cfg.name, mod_cfg.id); - - let mod_dir = state.data_dir.join(state.mod_dir.as_ref()); - let dest = mod_dir.join(&mod_cfg.id); - tracing::trace!("Creating mods directory {}", dest.display()); - fs::create_dir_all(&dest) - .await - .wrap_err_with(|| format!("Failed to create data directory '{}'", dest.display()))?; - - let image = if let Some(path) = &mod_cfg.image { - let name = archive - .file_names() - .find(|name| name.ends_with(&path.display().to_string())) - .map(|s| s.to_string()) - .ok_or_else(|| eyre::eyre!("archive does not contain configured image file"))?; - - let mut f = archive - .by_name(&name) - .wrap_err("Failed to read image file from archive")?; - let mut buf = Vec::with_capacity(f.size() as usize); - f.read_to_end(&mut buf) - .wrap_err("Failed to read file index from archive")?; - - let img = image_data_to_buffer(buf)?; - Some(img) - } else if let Some((nexus, _)) = &nexus { - let api = NexusApi::new(state.nexus_api_key.to_string())?; - let url = nexus.picture_url.as_ref(); - let data = api - .picture(url) - .await - .wrap_err_with(|| format!("Failed to download Nexus image from '{url}'"))?; - - let img = image_data_to_buffer(&data)?; - - let name = "image.bin"; - let path = dest.join(name); - match fs::write(&path, &data).await { - Ok(_) => { - mod_cfg.image = Some(name.into()); - Some(img) - } - Err(err) => { - let err = Report::new(err).wrap_err(format!( - "Failed to write Nexus picture to file '{}'", - path.display() - )); - tracing::error!("{:?}", err); - None - } - } - } else { - None - }; - - tracing::trace!(?image); - tracing::debug!(root, ?mod_cfg); - - let packages = if mod_cfg.bundled { - extract_bundled_mod(&mut archive, root, &mod_dir).wrap_err("Failed to extract mod")? - } else { - extract_legacy_mod(&mut archive, root, &dest).wrap_err("Failed to extract legacy mod")?; - - if let Some((_, version)) = &nexus { - // We use the version number stored in the `ModInfo` to compare against the `NexusInfo` - // for version checks. So for this one, we can't actually rely on merely shadowing, - // like with the other fields. - mod_cfg.version = version.clone(); - } - - let data = serde_sjson::to_string(&mod_cfg).wrap_err("Failed to serialize mod config")?; - fs::write(dest.join("dtmt.cfg"), &data) - .await - .wrap_err("Failed to write mod config")?; - - Default::default() - }; - - if let Some((nexus, _)) = &nexus { - let data = serde_sjson::to_string(nexus).wrap_err("Failed to serialize Nexus info")?; - let path = dest.join("nexus.sjson"); - fs::write(&path, data.as_bytes()) - .await - .wrap_err_with(|| format!("Failed to write Nexus info to '{}'", path.display()))?; - } - - let info = ModInfo::new(mod_cfg, packages, image, nexus.map(|(info, _)| info)); - Ok(info) -} diff --git a/crates/dtmm/src/controller/mod.rs b/crates/dtmm/src/controller/mod.rs deleted file mode 100644 index 9c75e84..0000000 --- a/crates/dtmm/src/controller/mod.rs +++ /dev/null @@ -1,25 +0,0 @@ -use std::path::Path; - -use color_eyre::{eyre::Context, Result}; -use serde::Deserialize; -use tokio::fs; - -pub mod app; -pub mod deploy; -pub mod game; -pub mod import; -pub mod worker; - -#[tracing::instrument] -async fn read_sjson_file(path: P) -> Result -where - T: for<'a> Deserialize<'a>, - P: AsRef + std::fmt::Debug, -{ - let path = path.as_ref(); - let buf = fs::read(path) - .await - .wrap_err_with(|| format!("Failed to read file '{}'", path.display()))?; - let data = String::from_utf8(buf).wrap_err("Invalid UTF8")?; - serde_sjson::from_str(&data).wrap_err("Failed to deserialize SJSON") -} diff --git a/crates/dtmm/src/controller/worker.rs b/crates/dtmm/src/controller/worker.rs index 6ee498f..80abf53 100644 --- a/crates/dtmm/src/controller/worker.rs +++ b/crates/dtmm/src/controller/worker.rs @@ -1,53 +1,30 @@ use std::sync::Arc; -use color_eyre::eyre::Context; -use color_eyre::Help; -use color_eyre::Report; use color_eyre::Result; use druid::{ExtEventSink, SingleUse, Target}; -use tokio::fs::OpenOptions; -use tokio::io::AsyncWriteExt; use tokio::runtime::Runtime; - use tokio::sync::mpsc::UnboundedReceiver; use tokio::sync::RwLock; use crate::controller::app::*; -use crate::controller::deploy::deploy_mods; use crate::controller::game::*; -use crate::controller::import::*; use crate::state::AsyncAction; -use crate::state::ACTION_FINISH_CHECK_UPDATE; -use crate::state::ACTION_FINISH_LOAD_INITIAL; use crate::state::ACTION_FINISH_SAVE_SETTINGS; -use crate::state::ACTION_SHOW_ERROR_DIALOG; use crate::state::{ ACTION_FINISH_ADD_MOD, ACTION_FINISH_DELETE_SELECTED_MOD, ACTION_FINISH_DEPLOY, ACTION_FINISH_RESET_DEPLOYMENT, ACTION_LOG, }; -async fn send_error(sink: Arc>, err: Report) { - sink.write() - .await - .submit_command(ACTION_SHOW_ERROR_DIALOG, SingleUse::new(err), Target::Auto) - .expect("failed to send command"); -} - async fn handle_action( event_sink: Arc>, action_queue: Arc>>, ) { while let Some(action) = action_queue.write().await.recv().await { - if cfg!(debug_assertions) && !matches!(action, AsyncAction::Log(_)) { - tracing::debug!(?action); - } - let event_sink = event_sink.clone(); match action { AsyncAction::DeployMods(state) => tokio::spawn(async move { - if let Err(err) = deploy_mods(state).await.wrap_err("Failed to deploy mods") { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; + if let Err(err) = deploy_mods(state).await { + tracing::error!("Failed to deploy mods: {:?}", err); } event_sink @@ -56,39 +33,32 @@ async fn handle_action( .submit_command(ACTION_FINISH_DEPLOY, (), Target::Auto) .expect("failed to send command"); }), - AsyncAction::AddMod(state, info) => tokio::spawn(async move { - match import_from_file(state, info) - .await - .wrap_err("Failed to import mod") - { + AsyncAction::AddMod((state, info)) => tokio::spawn(async move { + match import_mod(state, info).await { Ok(mod_info) => { event_sink .write() .await .submit_command( ACTION_FINISH_ADD_MOD, - SingleUse::new(Arc::new(mod_info)), + SingleUse::new(mod_info), Target::Auto, ) .expect("failed to send command"); } Err(err) => { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; + tracing::error!("Failed to import mod: {:?}", err); } } }), - AsyncAction::DeleteMod(state, info) => tokio::spawn(async move { - let mod_dir = state.mod_dir.join(&info.id); - if let Err(err) = delete_mod(state, &info) - .await - .wrap_err("Failed to delete mod files") - .with_suggestion(|| { - format!("Clean the folder '{}' manually", mod_dir.display()) - }) - { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; + AsyncAction::DeleteMod((state, info)) => tokio::spawn(async move { + if let Err(err) = delete_mod(state, &info).await { + tracing::error!( + "Failed to delete mod files. \ + You might want to clean up the data directory manually. \ + Reason: {:?}", + err + ); } event_sink @@ -102,12 +72,8 @@ async fn handle_action( .expect("failed to send command"); }), AsyncAction::ResetDeployment(state) => tokio::spawn(async move { - if let Err(err) = reset_mod_deployment(state) - .await - .wrap_err("Failed to reset mod deployment") - { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; + if let Err(err) = reset_mod_deployment(state).await { + tracing::error!("Failed to reset mod deployment: {:?}", err); } event_sink @@ -117,12 +83,8 @@ async fn handle_action( .expect("failed to send command"); }), AsyncAction::SaveSettings(state) => tokio::spawn(async move { - if let Err(err) = save_settings(state) - .await - .wrap_err("Failed to save settings") - { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; + if let Err(err) = save_settings(state).await { + tracing::error!("Failed to save settings: {:?}", err); } event_sink @@ -131,90 +93,13 @@ async fn handle_action( .submit_command(ACTION_FINISH_SAVE_SETTINGS, (), Target::Auto) .expect("failed to send command"); }), - AsyncAction::CheckUpdates(state) => tokio::spawn(async move { - let updates = match check_updates(state) - .await - .wrap_err("Failed to check for updates") - { - Ok(updates) => updates, - Err(err) => { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; - vec![] - } - }; - - event_sink - .write() - .await - .submit_command( - ACTION_FINISH_CHECK_UPDATE, - SingleUse::new(updates), - Target::Auto, - ) - .expect("failed to send command"); - }), - AsyncAction::LoadInitial((path, is_default)) => tokio::spawn(async move { - let data = match load_initial(path, is_default) - .await - .wrap_err("Failed to load initial application data") - { - Ok(data) => Some(data), - Err(err) => { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; - None - } - }; - - event_sink - .write() - .await - .submit_command( - ACTION_FINISH_LOAD_INITIAL, - SingleUse::new(data), - Target::Auto, - ) - .expect("failed to send command"); - }), - AsyncAction::Log((state, line)) => tokio::spawn(async move { - if let Ok(mut f) = OpenOptions::new() - .append(true) - .open(state.data_dir.join("dtmm.log")) - .await - { - let _ = f.write_all(&line).await; - } - }), - AsyncAction::NxmDownload(state, uri) => tokio::spawn(async move { - match import_from_nxm(state, uri) - .await - .wrap_err("Failed to handle NXM URI") - { - Ok(mod_info) => { - event_sink - .write() - .await - .submit_command( - ACTION_FINISH_ADD_MOD, - SingleUse::new(Arc::new(mod_info)), - Target::Auto, - ) - .expect("failed to send command"); - } - Err(err) => { - tracing::error!("{:?}", err); - send_error(event_sink.clone(), err).await; - } - } - }), }; } } async fn handle_log( event_sink: Arc>, - log_queue: Arc>>>, + log_queue: Arc>>, ) { while let Some(line) = log_queue.write().await.recv().await { let event_sink = event_sink.clone(); @@ -229,7 +114,7 @@ async fn handle_log( pub(crate) fn work_thread( event_sink: Arc>, action_queue: Arc>>, - log_queue: Arc>>>, + log_queue: Arc>>, ) -> Result<()> { let rt = Runtime::new()?; diff --git a/crates/dtmm/src/main.rs b/crates/dtmm/src/main.rs index 41a9253..9ce6192 100644 --- a/crates/dtmm/src/main.rs +++ b/crates/dtmm/src/main.rs @@ -1,73 +1,33 @@ #![recursion_limit = "256"] #![feature(let_chains)] -#![feature(iterator_try_collect)] -#![windows_subsystem = "windows"] use std::path::PathBuf; use std::sync::Arc; -use clap::parser::ValueSource; -use clap::{command, value_parser, Arg}; -use color_eyre::eyre::{self, Context}; -use color_eyre::{Report, Result, Section}; +use clap::command; +use clap::value_parser; +use clap::Arg; +use color_eyre::eyre::Context; +use color_eyre::{Report, Result}; use druid::AppLauncher; -use interprocess::local_socket::{prelude::*, GenericNamespaced, ListenerOptions}; use tokio::sync::RwLock; +use crate::controller::app::load_mods; use crate::controller::worker::work_thread; -use crate::state::{AsyncAction, ACTION_HANDLE_NXM}; use crate::state::{Delegate, State}; -use crate::ui::theme; -use crate::util::log::LogLevel; -mod controller; +mod controller { + pub mod app; + pub mod game; + pub mod worker; +} mod state; mod util { - pub mod ansi; pub mod config; pub mod log; } mod ui; -// As explained in https://docs.rs/interprocess/2.1.0/interprocess/local_socket/struct.Name.html -// namespaces are supported on both platforms we care about: Windows and Linux. -const IPC_ADDRESS: &str = "dtmm.sock"; - -#[tracing::instrument] -fn notify_nxm_download( - uri: impl AsRef + std::fmt::Debug, - level: Option, -) -> Result<()> { - util::log::create_tracing_subscriber(level, None); - - tracing::debug!("Received Uri '{}', sending to main process.", uri.as_ref()); - - let mut stream = LocalSocketStream::connect( - IPC_ADDRESS - .to_ns_name::() - .expect("Invalid socket name"), - ) - .wrap_err_with(|| format!("Failed to connect to '{IPC_ADDRESS}'")) - .suggestion("Make sure the main window is open.")?; - - tracing::debug!("Connected to main process at '{}'", IPC_ADDRESS); - - let bincode_config = bincode::config::standard(); - - bincode::encode_into_std_write(uri.as_ref(), &mut stream, bincode_config) - .wrap_err("Failed to send URI")?; - - // We don't really care what the message is, we just need an acknowledgement. - let _: String = bincode::decode_from_std_read(&mut stream, bincode_config) - .wrap_err("Failed to receive reply")?; - - tracing::info!( - "Notified DTMM with uri '{}'. Check the main window.", - uri.as_ref() - ); - Ok(()) -} - #[tracing::instrument] fn main() -> Result<()> { color_eyre::install()?; @@ -77,6 +37,12 @@ fn main() -> Result<()> { tracing::trace!(default_config_path = %default_config_path.display()); let matches = command!() + .arg(Arg::new("oodle").long("oodle").help( + "The oodle library to load. This may either be:\n\ + - A library name that will be searched for in the system's default paths.\n\ + - A file path relative to the current working directory.\n\ + - An absolute file path.", + )) .arg( Arg::new("config") .long("config") @@ -85,138 +51,41 @@ fn main() -> Result<()> { .value_parser(value_parser!(PathBuf)) .default_value(default_config_path.to_string_lossy().to_string()), ) - .arg( - Arg::new("log-level") - .long("log-level") - .help("The maximum level of log events to print") - .value_parser(value_parser!(LogLevel)) - .default_value("info"), - ) - .arg( - Arg::new("nxm") - .help("An `nxm://` URI to download") - .required(false), - ) .get_matches(); - let level = if matches.value_source("log-level") == Some(ValueSource::DefaultValue) { - None - } else { - matches.get_one::("log-level").cloned() + let (log_tx, log_rx) = tokio::sync::mpsc::unbounded_channel(); + util::log::create_tracing_subscriber(log_tx); + + let config = util::config::read_config(&default_config_path, &matches) + .wrap_err("failed to read config file")?; + + let initial_state = { + let mut state = State::new( + config.path, + config.game_dir.unwrap_or_default(), + config.data_dir.unwrap_or_default(), + ); + state.mods = load_mods(state.get_mod_dir(), config.mod_order.iter()) + .wrap_err("failed to load mods")?; + state }; - if let Some(uri) = matches.get_one::("nxm") { - return notify_nxm_download(uri, level).wrap_err("Failed to send NXM Uri to main window."); - } - - let (log_tx, log_rx) = tokio::sync::mpsc::unbounded_channel(); - util::log::create_tracing_subscriber(level, Some(log_tx)); - let (action_tx, action_rx) = tokio::sync::mpsc::unbounded_channel(); + let delegate = Delegate::new(action_tx); - let config_path = matches - .get_one::("config") - .cloned() - .expect("argument has default value"); - let is_config_default = matches.value_source("config") == Some(ValueSource::DefaultValue); - if action_tx - .send(AsyncAction::LoadInitial((config_path, is_config_default))) - .is_err() - { - let err = eyre::eyre!("Failed to send action"); - return Err(err); - } - - let launcher = AppLauncher::with_window(ui::window::main::new()) - .delegate(Delegate::new(action_tx)) - .configure_env(theme::set_theme_env); + let launcher = AppLauncher::with_window(ui::window::main::new()).delegate(delegate); let event_sink = launcher.get_external_handle(); - - { - let span = tracing::info_span!(IPC_ADDRESS, "nxm-socket"); - let _guard = span.enter(); - - let event_sink = event_sink.clone(); - let server = ListenerOptions::new() - .name( - IPC_ADDRESS - .to_ns_name::() - .expect("Invalid socket name"), - ) - .create_sync() - .wrap_err("Failed to create IPC listener")?; - - tracing::debug!("IPC server listening on '{}'", IPC_ADDRESS); - - // Drop the guard here, so that we can re-enter the same span in the thread. - drop(_guard); - - std::thread::Builder::new() - .name("nxm-socket".into()) - .spawn(move || { - let _guard = span.enter(); - - loop { - let res = server.accept().wrap_err_with(|| { - format!("IPC server failed to listen on '{IPC_ADDRESS}'") - }); - - match res { - Ok(mut stream) => { - let res = bincode::decode_from_std_read( - &mut stream, - bincode::config::standard(), - ) - .wrap_err("Failed to read message") - .and_then(|uri: String| { - tracing::trace!(uri, "Received NXM uri"); - - event_sink - .submit_command(ACTION_HANDLE_NXM, uri, druid::Target::Auto) - .wrap_err("Failed to start NXM download") - }); - match res { - Ok(()) => { - let _ = bincode::encode_into_std_write( - "Ok", - &mut stream, - bincode::config::standard(), - ); - } - Err(err) => { - tracing::error!("{:?}", err); - let _ = bincode::encode_into_std_write( - "Error", - &mut stream, - bincode::config::standard(), - ); - } - } - } - Err(err) => { - tracing::error!("Failed to receive client connection: {:?}", err) - } - } - } - }) - .wrap_err("Failed to create thread")?; - } - - std::thread::Builder::new() - .name("work-thread".into()) - .spawn(move || { - let event_sink = Arc::new(RwLock::new(event_sink)); - let action_rx = Arc::new(RwLock::new(action_rx)); - let log_rx = Arc::new(RwLock::new(log_rx)); - loop { - if let Err(err) = work_thread(event_sink.clone(), action_rx.clone(), log_rx.clone()) - { - tracing::error!("Work thread failed, restarting: {:?}", err); - } + std::thread::spawn(move || { + let event_sink = Arc::new(RwLock::new(event_sink)); + let action_rx = Arc::new(RwLock::new(action_rx)); + let log_rx = Arc::new(RwLock::new(log_rx)); + loop { + if let Err(err) = work_thread(event_sink.clone(), action_rx.clone(), log_rx.clone()) { + tracing::error!("Work thread failed, restarting: {:?}", err); } - }) - .wrap_err("Failed to create thread")?; + } + }); - launcher.launch(State::new()).map_err(Report::new) + launcher.launch(initial_state).map_err(Report::new) } diff --git a/crates/dtmm/src/state/data.rs b/crates/dtmm/src/state/data.rs index 23a4ae0..c8dc3aa 100644 --- a/crates/dtmm/src/state/data.rs +++ b/crates/dtmm/src/state/data.rs @@ -1,11 +1,7 @@ -use std::path::PathBuf; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; -use druid::im::{HashMap, Vector}; -use druid::text::RichText; -use druid::{Data, ImageBuf, Lens, WindowHandle, WindowId}; +use druid::{im::Vector, Data, Lens}; use dtmt_shared::ModConfig; -use nexusmods::Mod as NexusMod; use super::SelectedModLens; @@ -21,7 +17,7 @@ impl Default for View { } } -#[derive(Clone, Data, Debug, PartialEq)] +#[derive(Clone, Data, Debug)] pub struct PackageInfo { pub name: String, pub files: Vector, @@ -33,191 +29,68 @@ impl PackageInfo { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub(crate) struct ModResourceInfo { pub init: PathBuf, pub data: Option, pub localization: Option, } -#[derive(Clone, Data, Debug, PartialEq)] -pub(crate) enum ModOrder { - Before, - After, -} - -#[derive(Clone, Data, Debug, PartialEq)] -pub(crate) struct ModDependency { - pub id: String, - pub order: ModOrder, -} - -impl From for ModDependency { - fn from(value: dtmt_shared::ModDependency) -> Self { - match value { - dtmt_shared::ModDependency::ID(id) => ModDependency { - id, - order: ModOrder::Before, - }, - dtmt_shared::ModDependency::Config { id, order } => ModDependency { - id, - order: match order { - dtmt_shared::ModOrder::Before => ModOrder::Before, - dtmt_shared::ModOrder::After => ModOrder::After, - }, - }, - } - } -} - -#[derive(Clone, Data, Debug, Lens, serde::Serialize, serde::Deserialize)] -pub(crate) struct NexusInfo { - pub author: String, - pub category_id: u64, - pub created_timestamp: i64, - pub description: Arc, - pub id: u64, - pub name: String, - pub picture_url: Arc, - pub summary: Arc, - pub uid: u64, - pub updated_timestamp: i64, - pub uploaded_by: String, - pub version: String, -} - -impl From for NexusInfo { - fn from(value: NexusMod) -> Self { - Self { - author: value.author, - category_id: value.category_id, - created_timestamp: value.created_timestamp.unix_timestamp(), - description: Arc::new(value.description), - id: value.mod_id, - name: value.name, - picture_url: Arc::new(value.picture_url.into()), - summary: Arc::new(value.summary), - uid: value.uid, - updated_timestamp: value.updated_timestamp.unix_timestamp(), - uploaded_by: value.uploaded_by, - version: value.version, - } - } -} - -#[derive(Clone, Data, Lens)] +#[derive(Clone, Data, Debug, Lens)] pub(crate) struct ModInfo { pub id: String, pub name: String, - pub summary: Arc, - pub description: Option>, - pub categories: Vector, - pub author: Option, - pub image: Option, - pub version: String, + pub description: Arc, pub enabled: bool, - pub depends: Vector, - pub bundled: bool, #[lens(ignore)] #[data(ignore)] - pub packages: Vector>, + pub packages: Vector, #[lens(ignore)] #[data(ignore)] pub resources: ModResourceInfo, - #[data(ignore)] - pub nexus: Option, -} - -impl std::fmt::Debug for ModInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("ModInfo") - .field("id", &self.id) - .field("name", &self.name) - .field("summary", &self.summary) - .field( - "description", - &(match &self.description { - Some(desc) => format!("Some(String[0..{}])", desc.len()), - None => "None".to_string(), - }), - ) - .field("categories", &self.categories) - .field("author", &self.author) - .field( - "image", - &(match &self.image { - Some(image) => format!("Some(ImageBuf[{}x{}])", image.width(), image.height()), - None => "None".to_string(), - }), - ) - .field("version", &self.version) - .field("enabled", &self.enabled) - .field("packages", &format!("Vec[0..{}]", self.packages.len())) - .field("resources", &self.resources) - .field("depends", &self.depends) - .field("bundled", &self.bundled) - .field("nexus", &self.nexus) - .finish() - } } impl ModInfo { - pub fn new( - cfg: ModConfig, - packages: Vector>, - image: Option, - nexus: Option, - ) -> Self { + pub fn new(cfg: ModConfig, packages: Vector) -> Self { Self { id: cfg.id, name: cfg.name, - summary: Arc::new(cfg.summary), - description: cfg.description.map(Arc::new), - author: cfg.author, - version: cfg.version, + description: Arc::new(cfg.description), enabled: false, packages, - bundled: cfg.bundled, - image, - categories: cfg.categories.into_iter().collect(), resources: ModResourceInfo { init: cfg.resources.init, data: cfg.resources.data, localization: cfg.resources.localization, }, - depends: cfg.depends.into_iter().map(ModDependency::from).collect(), - nexus, } } } +impl PartialEq for ModInfo { + fn eq(&self, other: &Self) -> bool { + self.name.eq(&other.name) + } +} + #[derive(Clone, Data, Lens)] pub(crate) struct State { pub current_view: View, - pub mods: Vector>, + pub mods: Vector, pub selected_mod_index: Option, - pub dirty: bool, pub is_deployment_in_progress: bool, pub is_reset_in_progress: bool, pub is_save_in_progress: bool, pub is_next_save_pending: bool, - pub is_update_in_progress: bool, - pub is_io_enabled: bool, pub game_dir: Arc, pub data_dir: Arc, - pub nexus_api_key: Arc, - pub log: Vector, - // True, when the initial loading of configuration and mods is still in progress - pub loading: bool, + pub log: Arc, #[lens(ignore)] #[data(ignore)] pub config_path: Arc, #[lens(ignore)] #[data(ignore)] - pub windows: HashMap, - #[lens(ignore)] - #[data(ignore)] pub ctx: Arc, } @@ -225,7 +98,7 @@ impl State { #[allow(non_upper_case_globals)] pub const selected_mod: SelectedModLens = SelectedModLens; - pub fn new() -> Self { + pub fn new(config_path: PathBuf, game_dir: PathBuf, data_dir: PathBuf) -> Self { let ctx = sdk::Context::new(); Self { @@ -233,20 +106,14 @@ impl State { current_view: View::default(), mods: Vector::new(), selected_mod_index: None, - dirty: false, is_deployment_in_progress: false, is_reset_in_progress: false, is_save_in_progress: false, is_next_save_pending: false, - is_update_in_progress: false, - is_io_enabled: false, - config_path: Arc::new(PathBuf::new()), - game_dir: Arc::new(PathBuf::new()), - data_dir: Arc::new(PathBuf::new()), - nexus_api_key: Arc::new(String::new()), - log: Vector::new(), - windows: HashMap::new(), - loading: true, + config_path: Arc::new(config_path), + game_dir: Arc::new(game_dir), + data_dir: Arc::new(data_dir), + log: Arc::new(String::new()), } } @@ -254,8 +121,8 @@ impl State { self.selected_mod_index = Some(index); } - pub fn add_mod(&mut self, info: Arc) { - if let Some(pos) = self.mods.iter().position(|i| i.id == info.id) { + pub fn add_mod(&mut self, info: ModInfo) { + if let Some(pos) = self.mods.index_of(&info) { self.mods.set(pos, info); self.selected_mod_index = Some(pos); } else { @@ -273,4 +140,13 @@ impl State { pub fn can_move_mod_up(&self) -> bool { self.selected_mod_index.map(|i| i > 0).unwrap_or(false) } + + pub(crate) fn get_mod_dir(&self) -> PathBuf { + self.data_dir.join("mods") + } + + pub(crate) fn add_log_line(&mut self, line: String) { + let log = Arc::make_mut(&mut self.log); + log.push_str(&line); + } } diff --git a/crates/dtmm/src/state/delegate.rs b/crates/dtmm/src/state/delegate.rs index 62fb319..08d17b0 100644 --- a/crates/dtmm/src/state/delegate.rs +++ b/crates/dtmm/src/state/delegate.rs @@ -1,27 +1,17 @@ -use std::path::PathBuf; -use std::sync::Arc; - -use color_eyre::Report; -use druid::im::Vector; use druid::{ AppDelegate, Command, DelegateCtx, Env, FileInfo, Handled, Selector, SingleUse, Target, - WindowHandle, WindowId, }; use tokio::sync::mpsc::UnboundedSender; -use crate::ui::window; -use crate::util::ansi::ansi_to_rich_text; -use crate::util::config::Config; - use super::{ModInfo, State}; pub(crate) const ACTION_SELECT_MOD: Selector = Selector::new("dtmm.action.select-mod"); pub(crate) const ACTION_SELECTED_MOD_UP: Selector = Selector::new("dtmm.action.selected-mod-up"); pub(crate) const ACTION_SELECTED_MOD_DOWN: Selector = Selector::new("dtmm.action.selected-mod-down"); -pub(crate) const ACTION_START_DELETE_SELECTED_MOD: Selector>> = +pub(crate) const ACTION_START_DELETE_SELECTED_MOD: Selector> = Selector::new("dtmm.action.srart-delete-selected-mod"); -pub(crate) const ACTION_FINISH_DELETE_SELECTED_MOD: Selector>> = +pub(crate) const ACTION_FINISH_DELETE_SELECTED_MOD: Selector> = Selector::new("dtmm.action.finish-delete-selected-mod"); pub(crate) const ACTION_START_DEPLOY: Selector = Selector::new("dtmm.action.start-deploy"); @@ -32,98 +22,23 @@ pub(crate) const ACTION_START_RESET_DEPLOYMENT: Selector = pub(crate) const ACTION_FINISH_RESET_DEPLOYMENT: Selector = Selector::new("dtmm.action.finish-reset-deployment"); -pub(crate) const ACTION_HANDLE_NXM: Selector = Selector::new("dtmm.action.handle-nxm"); pub(crate) const ACTION_ADD_MOD: Selector = Selector::new("dtmm.action.add-mod"); -pub(crate) const ACTION_FINISH_ADD_MOD: Selector>> = +pub(crate) const ACTION_FINISH_ADD_MOD: Selector> = Selector::new("dtmm.action.finish-add-mod"); -pub(crate) const ACTION_LOG: Selector>> = Selector::new("dtmm.action.log"); +pub(crate) const ACTION_LOG: Selector> = Selector::new("dtmm.action.log"); pub(crate) const ACTION_START_SAVE_SETTINGS: Selector = Selector::new("dtmm.action.start-save-settings"); pub(crate) const ACTION_FINISH_SAVE_SETTINGS: Selector = Selector::new("dtmm.action.finish-save-settings"); -pub(crate) const ACTION_START_CHECK_UPDATE: Selector = - Selector::new("dtmm.action.start-check-update"); -pub(crate) const ACTION_FINISH_CHECK_UPDATE: Selector>> = - Selector::new("dtmm.action.finish-check-update"); - -pub(crate) const ACTION_SET_DIRTY: Selector = Selector::new("dtmm.action.set-dirty"); - -pub(crate) const ACTION_SHOW_ERROR_DIALOG: Selector> = - Selector::new("dtmm.action.show-error-dialog"); - -pub(crate) const ACTION_SET_WINDOW_HANDLE: Selector> = - Selector::new("dtmm.action.set-window-handle"); - -pub(crate) type InitialLoadResult = (Config, Vector>); -pub(crate) const ACTION_FINISH_LOAD_INITIAL: Selector>> = - Selector::new("dtmm.action.finish-load-initial"); - -pub(crate) const ACTION_OPEN_LINK: Selector> = Selector::new("dtmm.action.open-link"); - -// A sub-selection of `State`'s fields that are required in `AsyncAction`s and that are -// `Send + Sync` -pub(crate) struct ActionState { - pub mods: Vector>, - pub game_dir: Arc, - pub data_dir: Arc, - pub mod_dir: Arc, - pub config_path: Arc, - pub ctx: Arc, - pub nexus_api_key: Arc, - pub is_io_enabled: bool, -} - -impl From for ActionState { - fn from(state: State) -> Self { - Self { - mods: state.mods, - game_dir: state.game_dir, - mod_dir: Arc::new(state.data_dir.join("mods")), - data_dir: state.data_dir, - config_path: state.config_path, - ctx: state.ctx, - nexus_api_key: state.nexus_api_key, - is_io_enabled: state.is_io_enabled, - } - } -} - pub(crate) enum AsyncAction { - DeployMods(ActionState), - ResetDeployment(ActionState), - AddMod(ActionState, FileInfo), - DeleteMod(ActionState, Arc), - SaveSettings(ActionState), - CheckUpdates(ActionState), - LoadInitial((PathBuf, bool)), - Log((ActionState, Vec)), - NxmDownload(ActionState, String), -} - -impl std::fmt::Debug for AsyncAction { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - AsyncAction::DeployMods(_) => write!(f, "AsyncAction::DeployMods(_state)"), - AsyncAction::ResetDeployment(_) => write!(f, "AsyncAction::ResetDeployment(_state)"), - AsyncAction::AddMod(_, info) => write!(f, "AsyncAction::AddMod(_state, {info:?})"), - AsyncAction::DeleteMod(_, info) => { - write!(f, "AsyncAction::DeleteMod(_state, {info:?})") - } - AsyncAction::SaveSettings(_) => write!(f, "AsyncAction::SaveSettings(_state)"), - AsyncAction::CheckUpdates(_) => write!(f, "AsyncAction::CheckUpdates(_state)"), - AsyncAction::LoadInitial((path, is_default)) => write!( - f, - "AsyncAction::LoadInitial(({path:?}, {is_default:?}))" - ), - AsyncAction::Log(_) => write!(f, "AsyncAction::Log(_)"), - AsyncAction::NxmDownload(_, uri) => { - write!(f, "AsyncAction::NxmDownload(_state, {uri})") - } - } - } + DeployMods(State), + ResetDeployment(State), + AddMod((State, FileInfo)), + DeleteMod((State, ModInfo)), + SaveSettings(State), } pub(crate) struct Delegate { @@ -154,7 +69,7 @@ impl AppDelegate for Delegate { cmd if cmd.is(ACTION_START_DEPLOY) => { if self .sender - .send(AsyncAction::DeployMods(state.clone().into())) + .send(AsyncAction::DeployMods(state.clone())) .is_ok() { state.is_deployment_in_progress = true; @@ -166,13 +81,12 @@ impl AppDelegate for Delegate { } cmd if cmd.is(ACTION_FINISH_DEPLOY) => { state.is_deployment_in_progress = false; - state.dirty = false; Handled::Yes } cmd if cmd.is(ACTION_START_RESET_DEPLOYMENT) => { if self .sender - .send(AsyncAction::ResetDeployment(state.clone().into())) + .send(AsyncAction::ResetDeployment(state.clone())) .is_ok() { state.is_reset_in_progress = true; @@ -228,12 +142,11 @@ impl AppDelegate for Delegate { cmd if cmd.is(ACTION_START_DELETE_SELECTED_MOD) => { let info = cmd .get(ACTION_START_DELETE_SELECTED_MOD) - .and_then(SingleUse::take) + .and_then(|info| info.take()) .expect("command type matched but didn't contain the expected value"); - if self .sender - .send(AsyncAction::DeleteMod(state.clone().into(), info)) + .send(AsyncAction::DeleteMod((state.clone(), info))) .is_err() { tracing::error!("Failed to queue action to deploy mods"); @@ -244,40 +157,25 @@ impl AppDelegate for Delegate { cmd if cmd.is(ACTION_FINISH_DELETE_SELECTED_MOD) => { let info = cmd .get(ACTION_FINISH_DELETE_SELECTED_MOD) - .and_then(SingleUse::take) + .and_then(|info| info.take()) .expect("command type matched but didn't contain the expected value"); - let found = state.mods.iter().enumerate().find(|(_, i)| i.id == info.id); let Some((index, _)) = found else { return Handled::No; }; state.mods.remove(index); + // ctx.submit_command(ACTION_START_SAVE_SETTINGS); Handled::Yes } - cmd if cmd.is(ACTION_HANDLE_NXM) => { - let uri = cmd - .get(ACTION_HANDLE_NXM) - .expect("command type match but didn't contain the expected value"); - - if self - .sender - .send(AsyncAction::NxmDownload(state.clone().into(), uri.clone())) - .is_err() - { - tracing::error!("Failed to queue action to download NXM mod"); - } - Handled::Yes - } cmd if cmd.is(ACTION_ADD_MOD) => { let info = cmd .get(ACTION_ADD_MOD) .expect("command type matched but didn't contain the expected value"); - if self .sender - .send(AsyncAction::AddMod(state.clone().into(), info.clone())) + .send(AsyncAction::AddMod((state.clone(), info.clone()))) .is_err() { tracing::error!("Failed to queue action to add mod"); @@ -288,33 +186,19 @@ impl AppDelegate for Delegate { let info = cmd .get(ACTION_FINISH_ADD_MOD) .expect("command type matched but didn't contain the expected value"); - if let Some(info) = info.take() { state.add_mod(info); + // ctx.submit_command(ACTION_START_SAVE_SETTINGS); } - Handled::Yes } cmd if cmd.is(ACTION_LOG) => { let line = cmd .get(ACTION_LOG) .expect("command type matched but didn't contain the expected value"); - if let Some(line) = line.take() { - { - let line = String::from_utf8_lossy(&line); - state.log.push_back(ansi_to_rich_text(line.trim())); - } - - if self - .sender - .send(AsyncAction::Log((state.clone().into(), line))) - .is_err() - { - tracing::error!("Failed to queue action to add mod"); - } + state.add_log_line(line); } - Handled::Yes } cmd if cmd.is(ACTION_START_SAVE_SETTINGS) => { @@ -322,7 +206,7 @@ impl AppDelegate for Delegate { state.is_next_save_pending = true; } else if self .sender - .send(AsyncAction::SaveSettings(state.clone().into())) + .send(AsyncAction::SaveSettings(state.clone())) .is_ok() { state.is_save_in_progress = true; @@ -333,11 +217,6 @@ impl AppDelegate for Delegate { Handled::Yes } cmd if cmd.is(ACTION_FINISH_SAVE_SETTINGS) => { - tracing::trace!( - in_progress = state.is_save_in_progress, - next_pending = state.is_next_save_pending, - "Finished saving settings", - ); state.is_save_in_progress = false; if state.is_next_save_pending { @@ -347,128 +226,12 @@ impl AppDelegate for Delegate { Handled::Yes } - cmd if cmd.is(ACTION_SET_DIRTY) => { - state.dirty = true; - Handled::Yes - } - cmd if cmd.is(ACTION_SHOW_ERROR_DIALOG) => { - let err = cmd - .get(ACTION_SHOW_ERROR_DIALOG) - .and_then(SingleUse::take) - .expect("command type matched but didn't contain the expected value"); - - let window = state - .windows - .get(&window::main::WINDOW_ID) - .expect("root window does not exist"); - - let dialog = window::dialog::error::(err, window.clone()); - ctx.new_window(dialog); - - Handled::Yes - } - cmd if cmd.is(ACTION_SET_WINDOW_HANDLE) => { - let (id, handle) = cmd - .get(ACTION_SET_WINDOW_HANDLE) - .and_then(SingleUse::take) - .expect("command type matched but didn't contain the expected value"); - - state.windows.insert(id, handle); - Handled::Yes - } - cmd if cmd.is(ACTION_START_CHECK_UPDATE) => { - if self - .sender - .send(AsyncAction::CheckUpdates(state.clone().into())) - .is_ok() - { - state.is_update_in_progress = true; - } else { - tracing::error!("Failed to queue action to check updates"); + cmd => { + if cfg!(debug_assertions) { + tracing::warn!("Unknown command: {:?}", cmd); } - Handled::Yes + Handled::No } - cmd if cmd.is(ACTION_FINISH_CHECK_UPDATE) => { - let mut updates = cmd - .get(ACTION_FINISH_CHECK_UPDATE) - .and_then(SingleUse::take) - .expect("command type matched but didn't contain the expected value"); - - if tracing::enabled!(tracing::Level::DEBUG) { - let mods: Vec<_> = updates - .iter() - .map(|info| { - format!( - "{}: {} -> {:?}", - info.name, - info.version, - info.nexus.as_ref().map(|n| &n.version) - ) - }) - .collect(); - - tracing::info!("Mod updates:\n{}", mods.join("\n")); - } - - for mod_info in state.mods.iter_mut() { - if let Some(index) = updates.iter().position(|i2| i2.id == mod_info.id) { - let update = updates.swap_remove(index); - *mod_info = Arc::new(update); - } - } - - state.is_update_in_progress = false; - Handled::Yes - } - cmd if cmd.is(ACTION_FINISH_LOAD_INITIAL) => { - let data = cmd - .get(ACTION_FINISH_LOAD_INITIAL) - .and_then(SingleUse::take) - .expect("command type matched but didn't contain the expected value"); - - if let Some((config, mods)) = data { - state.mods = mods; - state.config_path = Arc::new(config.path); - state.data_dir = Arc::new(config.data_dir); - state.game_dir = Arc::new(config.game_dir.unwrap_or_default()); - state.nexus_api_key = Arc::new(config.nexus_api_key.unwrap_or_default()); - state.is_io_enabled = config.unsafe_io; - } - - state.loading = false; - - Handled::Yes - } - cmd if cmd.is(ACTION_OPEN_LINK) => { - let url = cmd - .get(ACTION_OPEN_LINK) - .expect("command type matched but didn't contain the expected value"); - - if let Err(err) = open::that_detached(Arc::as_ref(url)) { - tracing::error!( - "{:?}", - Report::new(err).wrap_err(format!("Failed to open url '{url}'")) - ); - } - - Handled::Yes - } - _ => Handled::No, } } - - fn window_added( - &mut self, - id: WindowId, - handle: WindowHandle, - data: &mut State, - _: &Env, - _: &mut DelegateCtx, - ) { - data.windows.insert(id, handle); - } - - fn window_removed(&mut self, id: WindowId, data: &mut State, _: &Env, _: &mut DelegateCtx) { - data.windows.remove(&id); - } } diff --git a/crates/dtmm/src/state/lens.rs b/crates/dtmm/src/state/lens.rs index 983cb2e..6c457a4 100644 --- a/crates/dtmm/src/state/lens.rs +++ b/crates/dtmm/src/state/lens.rs @@ -1,15 +1,13 @@ -use std::sync::Arc; - use druid::im::Vector; use druid::{Data, Lens}; -use super::{ModInfo, NexusInfo, State}; +use super::{ModInfo, State}; pub(crate) struct SelectedModLens; -impl Lens>> for SelectedModLens { +impl Lens> for SelectedModLens { #[tracing::instrument(name = "SelectedModLens::with", skip_all)] - fn with>) -> V>(&self, data: &State, f: F) -> V { + fn with) -> V>(&self, data: &State, f: F) -> V { let info = data .selected_mod_index .and_then(|i| data.mods.get(i).cloned()); @@ -18,16 +16,16 @@ impl Lens>> for SelectedModLens { } #[tracing::instrument(name = "SelectedModLens::with_mut", skip_all)] - fn with_mut>) -> V>(&self, data: &mut State, f: F) -> V { + fn with_mut) -> V>(&self, data: &mut State, f: F) -> V { match data.selected_mod_index { Some(i) => { let mut info = data.mods.get_mut(i).cloned(); let ret = f(&mut info); - if let Some(new) = info { + if let Some(info) = info { // TODO: Figure out a way to check for equality and // only update when needed - data.mods.set(i, new); + data.mods.set(i, info); } else { data.selected_mod_index = None; } @@ -42,7 +40,6 @@ impl Lens>> for SelectedModLens { /// A Lens that maps an `im::Vector` to `im::Vector<(usize, T)>`, /// where each element in the destination vector includes its index in the /// source vector. -#[allow(dead_code)] pub(crate) struct IndexedVectorLens; impl Lens, Vector<(usize, T)>> for IndexedVectorLens { @@ -74,51 +71,3 @@ impl Lens, Vector<(usize, T)>> for IndexedVectorLens { ret } } - -/// A Lens that first checks a key in a mod's `NexusInfo`, then falls back to -/// the regular one. -pub(crate) struct NexusInfoLens -where - L: Lens, - R: Lens, -{ - value: L, - fallback: R, - _marker: std::marker::PhantomData, -} - -impl NexusInfoLens -where - L: Lens, - R: Lens, -{ - pub fn new(value: L, fallback: R) -> Self { - Self { - value, - fallback, - _marker: std::marker::PhantomData, - } - } -} - -impl Lens for NexusInfoLens -where - L: Lens, - R: Lens, -{ - fn with V>(&self, data: &ModInfo, f: F) -> V { - if let Some(nexus) = &data.nexus { - self.value.with(nexus, f) - } else { - self.fallback.with(data, f) - } - } - - fn with_mut V>(&self, data: &mut ModInfo, f: F) -> V { - if let Some(nexus) = &mut data.nexus { - self.value.with_mut(nexus, f) - } else { - self.fallback.with_mut(data, f) - } - } -} diff --git a/crates/dtmm/src/ui/mod.rs b/crates/dtmm/src/ui/mod.rs index 12f66c9..cf8554f 100644 --- a/crates/dtmm/src/ui/mod.rs +++ b/crates/dtmm/src/ui/mod.rs @@ -1,6 +1,5 @@ pub mod theme; pub mod widget; pub mod window { - pub mod dialog; pub mod main; } diff --git a/crates/dtmm/src/ui/theme.rs b/crates/dtmm/src/ui/theme.rs new file mode 100644 index 0000000..7658f3f --- /dev/null +++ b/crates/dtmm/src/ui/theme.rs @@ -0,0 +1,4 @@ +use druid::{Color, Insets}; + +pub const TOP_BAR_BACKGROUND_COLOR: Color = Color::rgba8(255, 255, 255, 50); +pub const TOP_BAR_INSETS: Insets = Insets::uniform(5.0); diff --git a/crates/dtmm/src/ui/theme/colors.rs b/crates/dtmm/src/ui/theme/colors.rs deleted file mode 100644 index c78644e..0000000 --- a/crates/dtmm/src/ui/theme/colors.rs +++ /dev/null @@ -1,87 +0,0 @@ -use colors_transform::Color as _; -use colors_transform::Rgb; -use druid::Color; - -pub use gruvbox_dark::*; - -macro_rules! make_color { - ($name:ident, $r:literal, $g:literal, $b:literal, $a:literal) => { - pub const $name: Color = Color::rgba8($r, $g, $b, $a); - }; - ($name:ident, $r:literal, $g:literal, $b:literal) => { - pub const $name: Color = Color::rgb8($r, $g, $b); - }; - ($name:ident, $col:expr) => { - pub const $name: Color = $col; - }; -} - -make_color!(TOP_BAR_BACKGROUND_COLOR, COLOR_BG1); -make_color!(LINK_COLOR, COLOR_ACCENT); - -#[allow(dead_code)] -pub mod gruvbox_dark { - use druid::Color; - - make_color!(COLOR_BG0_H, 0x1d, 0x20, 0x21); - make_color!(COLOR_BG0_S, 0x32, 0x20, 0x2f); - make_color!(COLOR_BG0, 0x28, 0x28, 0x28); - make_color!(COLOR_BG1, 0x3c, 0x38, 0x36); - make_color!(COLOR_BG2, 0x50, 0x49, 0x45); - make_color!(COLOR_BG3, 0x66, 0x5c, 0x54); - make_color!(COLOR_BG4, 0x7c, 0x6f, 0x64); - - make_color!(COLOR_FG0, 0xfb, 0xf1, 0xc7); - make_color!(COLOR_FG1, 0xeb, 0xdb, 0xb2); - make_color!(COLOR_FG2, 0xd5, 0xc4, 0xa1); - make_color!(COLOR_FG3, 0xbd, 0xae, 0x93); - make_color!(COLOR_FG4, 0xa8, 0x99, 0x84); - - make_color!(COLOR_BG, COLOR_BG0); - make_color!(COLOR_GRAY_LIGHT, 0x92, 0x83, 0x74); - - make_color!(COLOR_RED_DARK, 0xcc, 0x24, 0x1d); - make_color!(COLOR_RED_LIGHT, 0xfb, 0x49, 0x34); - - make_color!(COLOR_GREEN_DARK, 0x98, 0x97, 0x1a); - make_color!(COLOR_GREEN_LIGHT, 0xb8, 0xbb, 0x26); - - make_color!(COLOR_YELLOW_DARK, 0xd7, 0x99, 0x21); - make_color!(COLOR_YELLOW_LIGHT, 0xfa, 0xbd, 0x2f); - - make_color!(COLOR_BLUE_DARK, 0x45, 0x85, 0x88); - make_color!(COLOR_BLUE_LIGHT, 0x83, 0xa5, 0x98); - - make_color!(COLOR_PURPLE_DARK, 0xb1, 0x26, 0x86); - make_color!(COLOR_PURPLE_LIGHT, 0xd3, 0x86, 0x9b); - - make_color!(COLOR_AQUA_DARK, 0x68, 0x9d, 0x6a); - make_color!(COLOR_AQUA_LIGHT, 0x8e, 0xc0, 0x7c); - - make_color!(COLOR_GRAY_DARK, 0xa8, 0x99, 0x84); - make_color!(COLOR_FG, COLOR_FG1); - - make_color!(COLOR_ORANGE_DARK, 0xd6, 0x5d, 0x0e); - make_color!(COLOR_ORANGE_LIGHT, 0xfe, 0x80, 0x19); - - make_color!(COLOR_ACCENT, COLOR_BLUE_LIGHT); - make_color!(COLOR_ACCENT_FG, COLOR_BG0_H); -} - -pub trait ColorExt { - fn darken(&self, fac: f32) -> Self; -} - -impl ColorExt for Color { - fn darken(&self, fac: f32) -> Self { - let (r, g, b, a) = self.as_rgba(); - let rgb = Rgb::from(r as f32, g as f32, b as f32); - let rgb = rgb.lighten(-fac); - Self::rgba( - rgb.get_red() as f64, - rgb.get_green() as f64, - rgb.get_blue() as f64, - a, - ) - } -} diff --git a/crates/dtmm/src/ui/theme/icons.rs b/crates/dtmm/src/ui/theme/icons.rs deleted file mode 100644 index 50ecbe3..0000000 --- a/crates/dtmm/src/ui/theme/icons.rs +++ /dev/null @@ -1,41 +0,0 @@ -use druid::Color; -use usvg::{ - Error, Fill, LineCap, LineJoin, NodeKind, NonZeroPositiveF64, Options, Paint, Stroke, Tree, -}; - -pub static ALERT_CIRCLE: &str = include_str!("../../../assets/tabler-icons/alert-circle.svg"); -pub static CLOUD_DOWNLOAD: &str = include_str!("../../../assets/tabler-icons/cloud-download.svg"); - -pub fn parse_svg(svg: &str) -> Result { - let opt = Options::default(); - Tree::from_str(svg, &opt.to_ref()) -} - -pub fn recolor_icon(tree: Tree, stroke: bool, color: Color) -> Tree { - let (red, green, blue, _) = color.as_rgba8(); - - let mut children = tree.root.children(); - // The first element is always some kind of background placeholder - children.next(); - - for node in children { - if let NodeKind::Path(ref mut path) = *node.borrow_mut() { - if stroke { - path.stroke = Some(Stroke { - paint: Paint::Color(usvg::Color { red, green, blue }), - width: NonZeroPositiveF64::new(2.).expect("the value is not zero"), - linecap: LineCap::Round, - linejoin: LineJoin::Round, - ..Default::default() - }); - } else { - path.fill = Some(Fill { - paint: Paint::Color(usvg::Color { red, green, blue }), - ..Default::default() - }); - } - } - } - - tree -} diff --git a/crates/dtmm/src/ui/theme/keys.rs b/crates/dtmm/src/ui/theme/keys.rs deleted file mode 100644 index 9d4120b..0000000 --- a/crates/dtmm/src/ui/theme/keys.rs +++ /dev/null @@ -1,13 +0,0 @@ -use druid::{Color, Insets, Key}; - -pub const KEY_BUTTON_BG: Key = Key::new("dtmm.button.bg"); -pub const KEY_BUTTON_BG_HOT: Key = Key::new("dtmm.button.bg-hot"); -pub const KEY_BUTTON_BG_ACTIVE: Key = Key::new("dtmm.button.bg-active"); -pub const KEY_BUTTON_BG_DISABLED: Key = Key::new("dtmm.button.bg-disabled"); - -pub const KEY_BUTTON_FG: Key = Key::new("dtmm.button.fg"); -pub const KEY_BUTTON_FG_DISABLED: Key = Key::new("dtmm.button.fg-disabled"); - -pub const KEY_BUTTON_PADDING: Key = Key::new("dtmm.button.padding"); - -pub const KEY_MOD_LIST_ITEM_BG_COLOR: Key = Key::new("dtmm.mod-list.item.background-color"); diff --git a/crates/dtmm/src/ui/theme/mod.rs b/crates/dtmm/src/ui/theme/mod.rs deleted file mode 100644 index 7f93524..0000000 --- a/crates/dtmm/src/ui/theme/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -use druid::{Env, Insets}; - -use crate::state::State; - -mod colors; -pub mod icons; -pub mod keys; - -pub use colors::*; - -pub const TOP_BAR_INSETS: Insets = Insets::uniform(5.0); -pub const DISABLED_ALPHA: f64 = 0.65; - -pub(crate) fn set_theme_env(env: &mut Env, _: &State) { - env.set(druid::theme::TEXT_COLOR, COLOR_FG); - env.set(druid::theme::SCROLLBAR_COLOR, COLOR_FG); - env.set(druid::theme::BORDER_LIGHT, COLOR_FG); - env.set(druid::theme::BUTTON_BORDER_RADIUS, 2.); - - env.set(keys::KEY_BUTTON_BG, COLOR_ACCENT); - env.set(keys::KEY_BUTTON_BG_HOT, COLOR_ACCENT.darken(0.03)); - env.set(keys::KEY_BUTTON_BG_ACTIVE, COLOR_ACCENT.darken(0.1)); - env.set( - keys::KEY_BUTTON_BG_DISABLED, - COLOR_ACCENT.with_alpha(DISABLED_ALPHA), - ); - env.set(keys::KEY_BUTTON_FG, COLOR_ACCENT_FG); - env.set( - keys::KEY_BUTTON_FG_DISABLED, - COLOR_ACCENT_FG.with_alpha(DISABLED_ALPHA), - ); - env.set(keys::KEY_BUTTON_PADDING, Insets::uniform_xy(8., 2.)); -} diff --git a/crates/dtmm/src/ui/widget/border.rs b/crates/dtmm/src/ui/widget/border.rs deleted file mode 100644 index 2ca7cdb..0000000 --- a/crates/dtmm/src/ui/widget/border.rs +++ /dev/null @@ -1,197 +0,0 @@ -use druid::kurbo::Line; -use druid::widget::prelude::*; -use druid::{Color, KeyOrValue, Point, WidgetPod}; - -pub struct Border { - inner: WidgetPod>>, - color: BorderColor, - width: BorderWidths, - // corner_radius: KeyOrValue, -} - -impl Border { - pub fn new(inner: impl Widget + 'static) -> Self { - let inner = WidgetPod::new(inner).boxed(); - Self { - inner, - color: Color::TRANSPARENT.into(), - width: 0f64.into(), - } - } - - pub fn set_color(&mut self, color: impl Into>) { - self.color = BorderColor::Uniform(color.into()); - } - - pub fn with_color(mut self, color: impl Into>) -> Self { - self.set_color(color); - self - } - - pub fn set_bottom_border(&mut self, width: impl Into>) { - self.width.bottom = width.into(); - } - - pub fn with_bottom_border(mut self, width: impl Into>) -> Self { - self.set_bottom_border(width); - self - } - - pub fn set_top_border(&mut self, width: impl Into>) { - self.width.top = width.into(); - } - - pub fn with_top_border(mut self, width: impl Into>) -> Self { - self.set_top_border(width); - self - } -} - -impl Widget for Border { - fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut T, env: &Env) { - self.inner.event(ctx, event, data, env) - } - - fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &T, env: &Env) { - self.inner.lifecycle(ctx, event, data, env); - } - - fn update(&mut self, ctx: &mut UpdateCtx, _: &T, data: &T, env: &Env) { - self.inner.update(ctx, data, env); - } - - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, data: &T, env: &Env) -> Size { - bc.debug_check("Border"); - - let (left, top, right, bottom) = self.width.resolve(env); - - let inner_bc = bc.shrink((left + right, top + bottom)); - let inner_size = self.inner.layout(ctx, &inner_bc, data, env); - - let origin = Point::new(left, top); - self.inner.set_origin(ctx, origin); - - let size = Size::new( - inner_size.width + left + right, - inner_size.height + top + bottom, - ); - - let insets = self.inner.compute_parent_paint_insets(size); - ctx.set_paint_insets(insets); - - let baseline_offset = self.inner.baseline_offset(); - if baseline_offset > 0. { - ctx.set_baseline_offset(baseline_offset + bottom); - } - - size - } - - fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) { - let size = ctx.size(); - let (left, top, right, bottom) = self.width.resolve(env); - let (col_left, col_top, col_right, col_bottom) = self.color.resolve(env); - - self.inner.paint(ctx, data, env); - - // There's probably a more elegant way to create the various `Line`s, but this works for now. - // The important bit is to move each line inwards by half each side's border width. Otherwise - // it would draw hald of the border outside of the widget's boundary. - - if left > 0. { - ctx.stroke( - Line::new((left / 2., top / 2.), (left / 2., size.height)), - &col_left, - left, - ); - } - - if top > 0. { - ctx.stroke( - Line::new((left / 2., top / 2.), (size.width - (right / 2.), top / 2.)), - &col_top, - top, - ); - } - - if right > 0. { - ctx.stroke( - Line::new( - (size.width - (right / 2.), top / 2.), - (size.width - (right / 2.), size.height - (bottom / 2.)), - ), - &col_right, - right, - ); - } - - if bottom > 0. { - ctx.stroke( - Line::new( - (left / 2., size.height - (bottom / 2.)), - (size.width - (right / 2.), size.height - (bottom / 2.)), - ), - &col_bottom, - bottom, - ); - } - } -} - -#[derive(Clone, Debug)] -pub enum BorderColor { - Uniform(KeyOrValue), - // Individual { - // left: KeyOrValue, - // top: KeyOrValue, - // right: KeyOrValue, - // bottom: KeyOrValue, - // }, -} - -impl BorderColor { - pub fn resolve(&self, env: &Env) -> (Color, Color, Color, Color) { - match self { - Self::Uniform(val) => { - let color = val.resolve(env); - (color, color, color, color) - } - } - } -} - -impl From for BorderColor { - fn from(value: Color) -> Self { - Self::Uniform(value.into()) - } -} - -#[derive(Clone, Debug)] -pub struct BorderWidths { - pub left: KeyOrValue, - pub top: KeyOrValue, - pub right: KeyOrValue, - pub bottom: KeyOrValue, -} - -impl From for BorderWidths { - fn from(value: f64) -> Self { - Self { - left: value.into(), - top: value.into(), - right: value.into(), - bottom: value.into(), - } - } -} - -impl BorderWidths { - pub fn resolve(&self, env: &Env) -> (f64, f64, f64, f64) { - ( - self.left.resolve(env), - self.top.resolve(env), - self.right.resolve(env), - self.bottom.resolve(env), - ) - } -} diff --git a/crates/dtmm/src/ui/widget/button.rs b/crates/dtmm/src/ui/widget/button.rs deleted file mode 100644 index 08e1dec..0000000 --- a/crates/dtmm/src/ui/widget/button.rs +++ /dev/null @@ -1,113 +0,0 @@ -use druid::widget::prelude::*; -use druid::widget::{Click, ControllerHost, Label, LabelText}; -use druid::WidgetPod; -use druid::{Affine, WidgetExt}; - -use crate::ui::theme; - -pub struct Button { - inner: WidgetPod>>, - inner_size: Size, -} - -impl Button { - pub fn new(inner: impl Widget + 'static) -> Self { - let inner = inner.env_scope(|env, _| { - env.set( - druid::theme::TEXT_COLOR, - env.get(theme::keys::KEY_BUTTON_FG), - ); - env.set( - druid::theme::DISABLED_TEXT_COLOR, - env.get(theme::keys::KEY_BUTTON_FG_DISABLED), - ); - }); - let inner = WidgetPod::new(inner).boxed(); - Self { - inner, - inner_size: Size::ZERO, - } - } - - pub fn with_label(text: impl Into>) -> Self { - let inner = Label::new(text); - Self::new(inner) - } - - pub fn on_click( - self, - f: impl Fn(&mut EventCtx, &mut T, &Env) + 'static, - ) -> ControllerHost> { - ControllerHost::new(self, Click::new(f)) - } -} - -impl Widget for Button { - fn event(&mut self, ctx: &mut EventCtx, event: &Event, _: &mut T, _: &Env) { - match event { - Event::MouseDown(_) if !ctx.is_disabled() => { - ctx.set_active(true); - ctx.request_paint(); - } - Event::MouseUp(_) => { - if ctx.is_active() && !ctx.is_disabled() { - ctx.request_paint(); - } - ctx.set_active(false); - } - _ => {} - } - } - - fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &T, env: &Env) { - if let LifeCycle::HotChanged(_) | LifeCycle::DisabledChanged(_) = event { - ctx.request_paint(); - } - self.inner.lifecycle(ctx, event, data, env); - } - - fn update(&mut self, ctx: &mut UpdateCtx, _: &T, data: &T, env: &Env) { - self.inner.update(ctx, data, env); - } - - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, data: &T, env: &Env) -> Size { - bc.debug_check("Button"); - - let padding = env.get(theme::keys::KEY_BUTTON_PADDING).size(); - let inner_bc = bc.shrink(padding).loosen(); - - self.inner_size = self.inner.layout(ctx, &inner_bc, data, env); - - bc.constrain(Size::new( - self.inner_size.width + padding.width, - self.inner_size.height + padding.height, - )) - } - - fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) { - let size = ctx.size(); - - let bg_color = if ctx.is_disabled() { - env.get(theme::keys::KEY_BUTTON_BG_DISABLED) - } else if ctx.is_hot() { - env.get(theme::keys::KEY_BUTTON_BG_HOT) - } else if ctx.is_active() { - env.get(theme::keys::KEY_BUTTON_BG_ACTIVE) - } else { - env.get(theme::keys::KEY_BUTTON_BG) - }; - - ctx.fill( - size.to_rect() - .to_rounded_rect(env.get(druid::theme::BUTTON_BORDER_RADIUS)), - &bg_color, - ); - - let inner_pos = (size.to_vec2() - self.inner_size.to_vec2()) / 2.; - - ctx.with_save(|ctx| { - ctx.transform(Affine::translate(inner_pos)); - self.inner.paint(ctx, data, env); - }); - } -} diff --git a/crates/dtmm/src/ui/widget/controller.rs b/crates/dtmm/src/ui/widget/controller.rs index f3b8a2e..ce18d5b 100644 --- a/crates/dtmm/src/ui/widget/controller.rs +++ b/crates/dtmm/src/ui/widget/controller.rs @@ -1,11 +1,8 @@ -use druid::widget::{Button, Controller, Image, Scroll}; -use druid::{ - Data, Env, Event, EventCtx, ImageBuf, LifeCycle, LifeCycleCtx, Rect, UpdateCtx, Widget, -}; +use druid::widget::{Button, Controller, Scroll}; +use druid::{Data, Env, Event, EventCtx, Rect, UpdateCtx, Widget}; -use crate::state::{State, ACTION_SET_DIRTY, ACTION_START_SAVE_SETTINGS}; +use crate::state::{State, ACTION_START_SAVE_SETTINGS}; -#[allow(dead_code)] pub struct DisabledButtonController; impl Controller> for DisabledButtonController { @@ -51,26 +48,20 @@ impl> Controller> for AutoScrollController data: &T, env: &Env, ) { - child.update(ctx, old_data, data, env); - if !ctx.is_disabled() { let size = child.child_size(); let end_region = Rect::new(size.width - 1., size.height - 1., size.width, size.height); child.scroll_to(ctx, end_region); } + child.update(ctx, old_data, data, env) } } -macro_rules! compare_state_fields { - ($old:ident, $new:ident, $($field:ident),+) => { - $(!Data::same(&$old.$field, &$new.$field)) || + - } -} +/// A controller that submits the command to save settings every time its widget's +/// data changes. +pub struct SaveSettingsController; -/// A controller that tracks state changes for certain fields and submits commands to handle them. -pub struct DirtyStateController; - -impl> Controller for DirtyStateController { +impl> Controller for SaveSettingsController { fn update( &mut self, child: &mut W, @@ -79,59 +70,13 @@ impl> Controller for DirtyStateController { data: &State, env: &Env, ) { - // Only start tracking changes after the initial load has finished - if old_data.loading == data.loading { - if compare_state_fields!( - old_data, - data, - mods, - game_dir, - data_dir, - nexus_api_key, - is_io_enabled - ) { - ctx.submit_command(ACTION_START_SAVE_SETTINGS); - } - - if compare_state_fields!(old_data, data, mods, game_dir, is_io_enabled) { - ctx.submit_command(ACTION_SET_DIRTY); - } + // Only filter for the values that actually go into the settings file. + if old_data.mods != data.mods + || old_data.game_dir != data.game_dir + || old_data.data_dir != data.data_dir + { + ctx.submit_command(ACTION_START_SAVE_SETTINGS); } - child.update(ctx, old_data, data, env) } } - -pub struct ImageLensController; - -impl Controller for ImageLensController { - fn lifecycle( - &mut self, - widget: &mut Image, - ctx: &mut LifeCycleCtx, - event: &LifeCycle, - data: &ImageBuf, - env: &Env, - ) { - if let LifeCycle::WidgetAdded = event { - widget.set_image_data(data.clone()); - } - - widget.lifecycle(ctx, event, data, env); - } - - fn update( - &mut self, - widget: &mut Image, - ctx: &mut UpdateCtx, - old_data: &ImageBuf, - data: &ImageBuf, - env: &Env, - ) { - if !Data::same(old_data, data) { - widget.set_image_data(data.clone()); - } - - widget.update(ctx, old_data, data, env); - } -} diff --git a/crates/dtmm/src/ui/widget/mod.rs b/crates/dtmm/src/ui/widget/mod.rs index 06ccedd..ebb634e 100644 --- a/crates/dtmm/src/ui/widget/mod.rs +++ b/crates/dtmm/src/ui/widget/mod.rs @@ -2,11 +2,14 @@ use std::path::PathBuf; use std::sync::Arc; use druid::text::Formatter; +use druid::{Data, Widget}; -pub mod border; -pub mod button; pub mod controller; +pub trait ExtraWidgetExt: Widget + Sized + 'static {} + +impl + 'static> ExtraWidgetExt for W {} + pub(crate) struct PathBufFormatter; impl PathBufFormatter { diff --git a/crates/dtmm/src/ui/window/dialog.rs b/crates/dtmm/src/ui/window/dialog.rs deleted file mode 100644 index 511d1de..0000000 --- a/crates/dtmm/src/ui/window/dialog.rs +++ /dev/null @@ -1,91 +0,0 @@ -use color_eyre::{Handler, HelpInfo, Report}; -use druid::widget::{CrossAxisAlignment, Flex, Label, LineBreaking}; -use druid::{Data, WidgetExt, WindowDesc, WindowHandle}; - -use crate::ui::theme; -use crate::ui::widget::button::Button; - -const WINDOW_SIZE: (f64, f64) = (600., 250.); - -/// Show an error dialog. -/// The title and message are extracted from the error chain in the given `Report`. -pub fn error(err: Report, _parent: WindowHandle) -> WindowDesc { - let (title, msg) = { - let count = err.chain().count(); - - if count == 1 { - // If there is only one error, that's all we can show. - ( - String::from("An error occurred!"), - err.root_cause().to_string(), - ) - } else { - let first = err.chain().next().unwrap(); - let root = err.root_cause(); - - // If there is more than one error in the chain we want to show - // - The first one: This will describe the overall operation that failed - // - The root cause: The actual thing that failed (e.g. 'No such file or directory') - // - The one before the root cause: With diligent `wrap_err` usage, this will provide - // context to the root cause (e.g. the file name we failed to access) - // - // If there are only two errors, the first one is also the context to the root cause. - if count > 2 { - // The second to last one, the context to the root cause - let context = err.chain().nth(count - 2).unwrap(); - - (format!("{first}!"), format!("{context}: {root}")) - } else { - ("An error occurred!".to_string(), format!("{first}: {root}")) - } - } - }; - - let title = Label::new(title) - .with_text_size(24.) - .with_text_color(theme::COLOR_RED_LIGHT); - let text = Label::new(msg).with_line_break_mode(LineBreaking::WordWrap); - - let button = Button::with_label("Ok") - .on_click(|ctx, _, _| { - ctx.window().close(); - }) - .align_right(); - - let mut widget = Flex::column() - .cross_axis_alignment(CrossAxisAlignment::Start) - .with_child(title) - .with_default_spacer() - .with_child(text); - - if let Some(handler) = err.handler().downcast_ref::() { - let mut first = true; - for section in handler.sections() { - if let HelpInfo::Suggestion(data, _) = section { - if first { - widget.add_default_spacer(); - first = false; - } - - let w = Flex::row() - .cross_axis_alignment(CrossAxisAlignment::Start) - .with_child(Label::new("Suggestion:").with_text_color(theme::COLOR_GREEN_LIGHT)) - .with_spacer(2.) - .with_child( - Label::new(data.to_string()).with_line_break_mode(LineBreaking::WordWrap), - ); - - widget.add_child(w); - } - } - } - - let widget = widget.with_flex_spacer(1.).with_child(button).padding(10.); - - WindowDesc::new(widget) - .title("Critical Error") - .show_titlebar(true) - .with_min_size(WINDOW_SIZE) - .set_always_on_top(true) - .resizable(false) -} diff --git a/crates/dtmm/src/ui/window/main.rs b/crates/dtmm/src/ui/window/main.rs index 3955bb1..a0ccaa2 100644 --- a/crates/dtmm/src/ui/window/main.rs +++ b/crates/dtmm/src/ui/window/main.rs @@ -1,43 +1,29 @@ -use std::str::FromStr; -use std::sync::Arc; - use druid::im::Vector; -use druid::text::RichTextBuilder; +use druid::lens; use druid::widget::{ - Checkbox, CrossAxisAlignment, Either, Flex, Image, Label, LineBreaking, List, - MainAxisAlignment, Maybe, Scroll, SizedBox, Split, Svg, SvgData, TextBox, ViewSwitcher, + Button, Checkbox, CrossAxisAlignment, Flex, Label, LineBreaking, List, MainAxisAlignment, + Maybe, Scroll, SizedBox, Split, TextBox, ViewSwitcher, }; -use druid::{lens, Env}; use druid::{ - Color, FileDialogOptions, FileSpec, FontDescriptor, FontFamily, LensExt, SingleUse, Widget, - WidgetExt, WindowDesc, WindowId, + Color, FileDialogOptions, FileSpec, FontDescriptor, FontFamily, Key, LensExt, SingleUse, + TextAlignment, Widget, WidgetExt, WindowDesc, }; -use druid::{Data, ImageBuf, LifeCycleCtx}; -use druid_widget_nursery::WidgetExt as _; -use lazy_static::lazy_static; use crate::state::{ - ModInfo, NexusInfo, NexusInfoLens, State, View, ACTION_ADD_MOD, ACTION_OPEN_LINK, - ACTION_SELECTED_MOD_DOWN, ACTION_SELECTED_MOD_UP, ACTION_SELECT_MOD, ACTION_SET_WINDOW_HANDLE, - ACTION_START_CHECK_UPDATE, ACTION_START_DELETE_SELECTED_MOD, ACTION_START_DEPLOY, + ModInfo, State, View, ACTION_ADD_MOD, ACTION_SELECTED_MOD_DOWN, ACTION_SELECTED_MOD_UP, + ACTION_SELECT_MOD, ACTION_START_DELETE_SELECTED_MOD, ACTION_START_DEPLOY, ACTION_START_RESET_DEPLOYMENT, }; -use crate::ui::theme::{self, ColorExt, COLOR_GREEN_LIGHT}; -use crate::ui::widget::border::Border; -use crate::ui::widget::button::Button; -use crate::ui::widget::controller::{ - AutoScrollController, DirtyStateController, ImageLensController, -}; +use crate::ui::theme; +use crate::ui::widget::controller::{AutoScrollController, SaveSettingsController}; use crate::ui::widget::PathBufFormatter; -lazy_static! { - pub static ref WINDOW_ID: WindowId = WindowId::next(); -} - const TITLE: &str = "Darktide Mod Manager"; const WINDOW_SIZE: (f64, f64) = (1080., 720.); const MOD_DETAILS_MIN_WIDTH: f64 = 325.; +const KEY_MOD_LIST_ITEM_BG_COLOR: Key = Key::new("dtmm.mod-list.item.background-color"); + pub(crate) fn new() -> WindowDesc { WindowDesc::new(build_window()) .title(TITLE) @@ -45,160 +31,70 @@ pub(crate) fn new() -> WindowDesc { } fn build_top_bar() -> impl Widget { - let mods_button = Button::with_label("Mods") - .on_click(|_ctx, state: &mut State, _env| state.current_view = View::Mods); - - let settings_button = - Button::with_label("Settings").on_click(|_ctx, state: &mut State, _env| { - state.current_view = View::Settings; - }); - - let check_update_button = { - let make_button = || { - Button::with_label("Check for updates").on_click(|ctx, _: &mut State, _| { - ctx.submit_command(ACTION_START_CHECK_UPDATE); - }) - }; - - Either::new( - |data, _| data.nexus_api_key.is_empty(), - make_button() - .tooltip(|_: &State, _: &Env| "A Nexus API key is required") - .disabled_if(|_, _| true), - make_button().disabled_if(|data, _| data.is_update_in_progress), - ) - }; - - let deploy_button = { - let icon = Svg::new(SvgData::from_str(theme::icons::ALERT_CIRCLE).expect("invalid SVG")) - .fix_height(druid::theme::TEXT_SIZE_NORMAL); - - let inner = Either::new( - |state: &State, _| state.dirty, - Flex::row() - .with_child(icon) - .with_spacer(3.) - .with_child(Label::new("Deploy Mods")), - Label::new("Deploy Mods"), - ); - Button::new(inner) - .on_click(|ctx, _state: &mut State, _env| { - ctx.submit_command(ACTION_START_DEPLOY); - }) - .disabled_if(|data, _| data.is_deployment_in_progress || data.is_reset_in_progress) - }; - - let reset_button = Button::with_label("Reset Game") - .on_click(|ctx, _state: &mut State, _env| { - ctx.submit_command(ACTION_START_RESET_DEPLOYMENT); - }) - .disabled_if(|data, _| data.is_deployment_in_progress || data.is_reset_in_progress); - - let bar = Flex::row() + Flex::row() .must_fill_main_axis(true) .main_axis_alignment(MainAxisAlignment::SpaceBetween) .with_child( Flex::row() - .with_child(mods_button) + .with_child( + Button::new("Mods") + .on_click(|_ctx, state: &mut State, _env| state.current_view = View::Mods), + ) .with_default_spacer() - .with_child(settings_button), + .with_child( + Button::new("Settings").on_click(|_ctx, state: &mut State, _env| { + state.current_view = View::Settings; + }), + ), ) .with_child( Flex::row() - .with_child(check_update_button) + .with_child( + Button::new("Deploy Mods") + .on_click(|ctx, _state: &mut State, _env| { + ctx.submit_command(ACTION_START_DEPLOY); + }) + .disabled_if(|data, _| { + data.is_deployment_in_progress || data.is_reset_in_progress + }), + ) .with_default_spacer() - .with_child(deploy_button) - .with_default_spacer() - .with_child(reset_button), + .with_child( + Button::new("Reset Game") + .on_click(|ctx, _state: &mut State, _env| { + ctx.submit_command(ACTION_START_RESET_DEPLOYMENT); + }) + .disabled_if(|data, _| { + data.is_deployment_in_progress || data.is_reset_in_progress + }), + ), ) .padding(theme::TOP_BAR_INSETS) - .background(theme::TOP_BAR_BACKGROUND_COLOR); - - Border::new(bar) - .with_color(theme::COLOR_FG2) - .with_bottom_border(1.) + .background(theme::TOP_BAR_BACKGROUND_COLOR) + // TODO: Add bottom border. Need a custom widget for that, as the built-in only provides + // uniform borders on all sides } fn build_mod_list() -> impl Widget { let list = List::new(|| { - let checkbox = Checkbox::new("") - .env_scope(|env, selected| { - env.set(druid::theme::BORDER_DARK, theme::COLOR_BG3); - env.set(druid::theme::BORDER_LIGHT, theme::COLOR_BG3); - env.set(druid::theme::TEXT_COLOR, theme::COLOR_ACCENT_FG); - - if *selected { - env.set(druid::theme::BACKGROUND_DARK, theme::COLOR_ACCENT); - env.set(druid::theme::BACKGROUND_LIGHT, theme::COLOR_ACCENT); - } else { - env.set(druid::theme::BACKGROUND_DARK, Color::TRANSPARENT); - env.set(druid::theme::BACKGROUND_LIGHT, Color::TRANSPARENT); - } - }) - .lens(lens!((usize, Arc, bool), 1).then(ModInfo::enabled.in_arc())); - - let name = Label::dynamic(|info: &Arc, _| { - info.nexus - .as_ref() - .map(|n| n.name.clone()) - .unwrap_or_else(|| info.name.clone()) - }) - .lens(lens!((usize, Arc, bool), 1)); - - let version = { - let icon = { - let tree = - theme::icons::parse_svg(theme::icons::CLOUD_DOWNLOAD).expect("invalid SVG"); - - let tree = theme::icons::recolor_icon(tree, true, COLOR_GREEN_LIGHT); - - Svg::new(tree).fix_height(druid::theme::TEXT_SIZE_NORMAL) - }; - - Either::new( - |info, _| { - info.nexus - .as_ref() - .map(|n| info.version != n.version) - .unwrap_or(false) - }, - Flex::row() - .with_child(icon) - .with_spacer(3.) - .with_child(Label::raw().lens(ModInfo::version.in_arc())), - Label::raw().lens(ModInfo::version.in_arc()), - ) - .lens(lens!((usize, Arc, bool), 1)) - }; - - let fields = Flex::row() - .must_fill_main_axis(true) - .main_axis_alignment(MainAxisAlignment::SpaceBetween) - .with_child(name) - .with_child(version); + let checkbox = + Checkbox::new("").lens(lens!((usize, ModInfo, bool), 1).then(ModInfo::enabled)); + let name = Label::raw().lens(lens!((usize, ModInfo, bool), 1).then(ModInfo::name)); Flex::row() .must_fill_main_axis(true) .with_child(checkbox) - .with_flex_child(fields, 1.) + .with_child(name) .padding((5.0, 4.0)) - .background(theme::keys::KEY_MOD_LIST_ITEM_BG_COLOR) + .background(KEY_MOD_LIST_ITEM_BG_COLOR) .on_click(|ctx, (i, _, _), _env| ctx.submit_command(ACTION_SELECT_MOD.with(*i))) .env_scope(|env, (i, _, selected)| { if *selected { - env.set(theme::keys::KEY_MOD_LIST_ITEM_BG_COLOR, theme::COLOR_ACCENT); - env.set( - druid::theme::TEXT_COLOR, - theme::COLOR_ACCENT_FG.darken(0.05), - ); + env.set(KEY_MOD_LIST_ITEM_BG_COLOR, Color::NAVY); + } else if (i % 2) == 1 { + env.set(KEY_MOD_LIST_ITEM_BG_COLOR, Color::WHITE.with_alpha(0.05)); } else { - env.set(druid::theme::TEXT_COLOR, theme::COLOR_FG); - - if (i % 2) == 1 { - env.set(theme::keys::KEY_MOD_LIST_ITEM_BG_COLOR, theme::COLOR_BG1); - } else { - env.set(theme::keys::KEY_MOD_LIST_ITEM_BG_COLOR, theme::COLOR_BG); - } + env.set(KEY_MOD_LIST_ITEM_BG_COLOR, Color::TRANSPARENT); } }) }); @@ -213,10 +109,8 @@ fn build_mod_list() -> impl Widget { .collect::>() }, |state, infos| { - infos.into_iter().for_each(|(i, new, _)| { - if !Data::same(&state.mods.get(i).cloned(), &Some(new.clone())) { - state.mods.set(i, new); - } + infos.into_iter().for_each(|(i, info, _)| { + state.mods.set(i, info); }); }, )); @@ -228,36 +122,35 @@ fn build_mod_list() -> impl Widget { } fn build_mod_details_buttons() -> impl Widget { - let button_move_up = Button::with_label("Move Up") + let button_move_up = Button::new("Move Up") .on_click(|ctx, _state, _env| ctx.submit_command(ACTION_SELECTED_MOD_UP)) .disabled_if(|state: &State, _env: &druid::Env| !state.can_move_mod_up()); - let button_move_down = Button::with_label("Move Down") + let button_move_down = Button::new("Move Down") .on_click(|ctx, _state, _env| ctx.submit_command(ACTION_SELECTED_MOD_DOWN)) .disabled_if(|state: &State, _env: &druid::Env| !state.can_move_mod_down()); let button_toggle_mod = Maybe::new( || { - let inner = Label::dynamic(|enabled, _env| { + Button::dynamic(|enabled, _env| { if *enabled { "Disable Mod".into() } else { "Enable Mod".into() } - }); - Button::new(inner) - .on_click(|_ctx, enabled: &mut bool, _env| { - *enabled = !(*enabled); - }) - .lens(ModInfo::enabled.in_arc()) + }) + .on_click(|_ctx, enabled: &mut bool, _env| { + *enabled = !(*enabled); + }) + .lens(ModInfo::enabled) }, // TODO: Gray out - || Button::with_label("Enable Mod"), + || Button::new("Enable Mod"), ) - .disabled_if(|info: &Option>, _env: &druid::Env| info.is_none()) + .disabled_if(|info: &Option, _env: &druid::Env| info.is_none()) .lens(State::selected_mod); - let button_add_mod = Button::with_label("Add Mod").on_click(|ctx, _state: &mut State, _env| { + let button_add_mod = Button::new("Add Mod").on_click(|ctx, _state: &mut State, _env| { let zip = FileSpec::new("Zip file", &["zip"]); let opts = FileDialogOptions::new() .allowed_types(vec![zip]) @@ -268,15 +161,15 @@ fn build_mod_details_buttons() -> impl Widget { ctx.submit_command(druid::commands::SHOW_OPEN_PANEL.with(opts)) }); - let button_delete_mod = Button::with_label("Delete Mod") - .on_click(|ctx, data: &mut Option>, _env| { + let button_delete_mod = Button::new("Delete Mod") + .on_click(|ctx, data: &mut Option, _env| { if let Some(info) = data { ctx.submit_command( ACTION_START_DELETE_SELECTED_MOD.with(SingleUse::new(info.clone())), ); } }) - .disabled_if(|info: &Option>, _env: &druid::Env| info.is_none()) + .disabled_if(|info: &Option, _env: &druid::Env| info.is_none()) .lens(State::selected_mod); Flex::column() @@ -305,94 +198,26 @@ fn build_mod_details_info() -> impl Widget { Maybe::new( || { let name = Label::raw() + .with_text_alignment(TextAlignment::Center) .with_text_size(24.) // Force the label to take up the entire details' pane width, // so that we can center-align it. .expand_width() - .lens(NexusInfoLens::new(NexusInfo::name, ModInfo::name).in_arc()); - let summary = Label::raw() + .lens(ModInfo::name); + let description = Label::raw() .with_line_break_mode(LineBreaking::WordWrap) - .lens(NexusInfoLens::new(NexusInfo::summary, ModInfo::summary).in_arc()); + .lens(ModInfo::description); - let version_line = Label::dynamic(|info: &Arc, _| { - let author = info - .nexus - .as_ref() - .map(|n| &n.author) - .or(info.author.as_ref()); - - if let Some(author) = &author { - format!("Version: {}, by {author}", info.version) - } else { - format!("Version: {}", info.version) - } - }); - - let categories = Label::dynamic(|info: &Arc, _| { - if info.categories.is_empty() { - String::from("Uncategorized") - } else { - info.categories.iter().enumerate().fold( - String::from("Category: "), - |mut s, (i, category)| { - if i > 0 { - s.push_str(", "); - } - s.push_str(category); - s - }, - ) - } - }); - - let nexus_link = Maybe::or_empty(|| { - let link = Label::raw().lens(NexusInfo::id.map( - |id| { - let url = format!("https://nexusmods.com/warhammer40kdarktide/mods/{id}"); - let mut builder = RichTextBuilder::new(); - builder - .push("Open on Nexusmods") - .underline(true) - .text_color(theme::LINK_COLOR) - .link(ACTION_OPEN_LINK.with(Arc::new(url))); - builder.build() - }, - |_, _| {}, - )); - Flex::column() - .cross_axis_alignment(CrossAxisAlignment::Start) - .main_axis_alignment(MainAxisAlignment::Start) - .with_child(link) - .with_spacer(4.) - }) - .lens(ModInfo::nexus.in_arc()); - - let details = Flex::column() + Flex::column() .cross_axis_alignment(CrossAxisAlignment::Start) .main_axis_alignment(MainAxisAlignment::Start) .with_child(name) .with_spacer(4.) - .with_child(summary) - .with_spacer(4.) - .with_child(nexus_link) - .with_child(version_line) - .with_spacer(4.) - .with_child(categories) - .padding((4., 4.)); - - let image = - Maybe::or_empty(|| Image::new(ImageBuf::empty()).controller(ImageLensController)) - .lens(ModInfo::image.in_arc()); - - Flex::column() - .main_axis_alignment(MainAxisAlignment::Start) - .must_fill_main_axis(true) - .cross_axis_alignment(CrossAxisAlignment::Start) - .with_child(image) - .with_child(details) + .with_child(description) }, Flex::column, ) + .padding((4., 4.)) .lens(State::selected_mod) } @@ -402,7 +227,7 @@ fn build_mod_details() -> impl Widget { .cross_axis_alignment(CrossAxisAlignment::Start) .main_axis_alignment(MainAxisAlignment::SpaceBetween) .with_flex_child(build_mod_details_info(), 1.0) - .with_child(build_mod_details_buttons().padding((4., 4., 4., 8.))) + .with_child(build_mod_details_buttons().padding(4.)) } fn build_view_mods() -> impl Widget { @@ -443,47 +268,12 @@ fn build_view_settings() -> impl Widget { ) .expand_width(); - let nexus_apy_key_setting = Flex::row() - .must_fill_main_axis(true) - .main_axis_alignment(MainAxisAlignment::Start) - .with_child(Label::new("Nexus API Key:")) - .with_default_spacer() - .with_flex_child(TextBox::new().expand_width().lens(State::nexus_api_key), 1.) - .expand_width(); - - let io_setting = Flex::row() - .must_fill_main_axis(true) - .main_axis_alignment(MainAxisAlignment::Start) - .with_child(Label::new("Enable unsafe I/O:")) - .with_default_spacer() - .with_child(Checkbox::from_label(Label::dynamic( - |enabled: &bool, _: &Env| { - if *enabled { - "Enabled".into() - } else { - "Disabled".into() - } - }, - ))) - .lens(State::is_io_enabled) - .tooltip(|_: &State, _: &Env| { - "Enabling this gives ANY mod full access to your files \ - and the ability to load arbitrary software libraries.\n\ - Only enable this if it is crucial for a mod's functionality, \ - and you are sure none of the ones you have installed are malicious." - }) - .expand_width(); - let content = Flex::column() .must_fill_main_axis(true) .cross_axis_alignment(CrossAxisAlignment::Start) .with_child(data_dir_setting) .with_default_spacer() - .with_child(game_dir_setting) - .with_default_spacer() - .with_child(io_setting) - .with_default_spacer() - .with_child(nexus_apy_key_setting); + .with_child(game_dir_setting); SizedBox::new(content) .width(800.) @@ -502,22 +292,17 @@ fn build_main() -> impl Widget { } fn build_log_view() -> impl Widget { - let list = List::new(|| { - Label::raw() - .with_font(FontDescriptor::new(FontFamily::MONOSPACE)) - .with_line_break_mode(LineBreaking::WordWrap) - }) - .lens(State::log) - .padding(4.) - .scroll() - .vertical() - .controller(AutoScrollController); + let font = FontDescriptor::new(FontFamily::MONOSPACE); + let label = Label::raw() + .with_font(font) + .with_line_break_mode(LineBreaking::WordWrap) + .lens(State::log) + .padding(4.) + .scroll() + .vertical() + .controller(AutoScrollController); - let inner = Border::new(list) - .with_color(theme::COLOR_FG2) - .with_top_border(1.); - - SizedBox::new(inner).expand_width().height(128.0) + SizedBox::new(label).expand_width().height(128.0) } fn build_window() -> impl Widget { @@ -527,10 +312,5 @@ fn build_window() -> impl Widget { .with_child(build_top_bar()) .with_flex_child(build_main(), 1.0) .with_child(build_log_view()) - .controller(DirtyStateController) - .on_added(|_, ctx: &mut LifeCycleCtx, _, _| { - ctx.submit_command( - ACTION_SET_WINDOW_HANDLE.with(SingleUse::new((*WINDOW_ID, ctx.window().clone()))), - ); - }) + .controller(SaveSettingsController) } diff --git a/crates/dtmm/src/util/ansi.rs b/crates/dtmm/src/util/ansi.rs deleted file mode 100644 index 24855fc..0000000 --- a/crates/dtmm/src/util/ansi.rs +++ /dev/null @@ -1,92 +0,0 @@ -use ansi_parser::{AnsiParser, AnsiSequence, Output}; -use druid::text::{RichText, RichTextBuilder}; -use druid::{Color, FontStyle, FontWeight}; - -use crate::ui::theme; - -#[derive(Default, Debug)] -struct TextState { - color: Option, - dim: bool, - bold: bool, - underline: bool, - strikethrough: bool, - italic: bool, -} - -pub fn ansi_to_rich_text(input: &str) -> RichText { - let mut builder = RichTextBuilder::new(); - - let mut state = TextState::default(); - - for token in input.ansi_parse() { - match token { - Output::TextBlock(text) => { - let mut attr = builder.push(text); - attr.underline(state.underline); - attr.strikethrough(state.strikethrough); - - if state.bold { - attr.weight(FontWeight::BOLD); - } - - if state.italic { - attr.style(FontStyle::Italic); - } - - if let Some(color) = state.color { - attr.text_color(color); - } - } - Output::Escape(AnsiSequence::SetGraphicsMode(values)) => { - for v in values { - match v { - 0 => { - state = Default::default(); - break; - } - 1 => state.bold = true, - 2 => state.dim = true, - 3 => state.italic = true, - 4 => state.underline = true, - 9 => state.strikethrough = true, - 22 => { - state.bold = false; - state.dim = false; - } - 23 => state.italic = false, - 24 => state.underline = false, - 29 => state.underline = false, - 30..=40 | 90..=100 => { - let mut col = v - 30; - if col > 9 { - state.bold = true; - col -= 60; - } - - state.color = match col { - // This escape code is usually called 'black', but is actually used - // as "foreground color", in regards to light themes. - 0 => Some(theme::COLOR_FG), - 1 => Some(theme::COLOR_RED_LIGHT), - 2 => Some(theme::COLOR_GREEN_LIGHT), - 3 => Some(theme::COLOR_YELLOW_LIGHT), - 4 => Some(theme::COLOR_BLUE_LIGHT), - 5 => Some(theme::COLOR_PURPLE_LIGHT), - 6 => Some(theme::COLOR_AQUA_LIGHT), - // Similarly, 'white' is the background color - 7 => Some(theme::COLOR_BG), - 9 => None, - _ => unreachable!(), - }; - } - _ => {} - } - } - } - Output::Escape(_) => {} - } - } - - builder.build() -} diff --git a/crates/dtmm/src/util/config.rs b/crates/dtmm/src/util/config.rs index 9affbb6..d2ae44c 100644 --- a/crates/dtmm/src/util/config.rs +++ b/crates/dtmm/src/util/config.rs @@ -1,13 +1,12 @@ use std::io::ErrorKind; -use std::path::Path; use std::path::PathBuf; -use std::sync::Arc; +use std::{fs, path::Path}; +use clap::{parser::ValueSource, ArgMatches}; use color_eyre::{eyre::Context, Result}; use serde::{Deserialize, Serialize}; -use tokio::fs; -use crate::state::{ActionState, ModInfo}; +use crate::state::{ModInfo, State}; #[derive(Clone, Debug, Serialize)] pub(crate) struct LoadOrderEntrySerialize<'a> { @@ -28,22 +27,17 @@ impl<'a> From<&'a ModInfo> for LoadOrderEntrySerialize<'a> { pub(crate) struct ConfigSerialize<'a> { game_dir: &'a Path, data_dir: &'a Path, - nexus_api_key: &'a String, mod_order: Vec>, - unsafe_io: bool, } -impl<'a> From<&'a ActionState> for ConfigSerialize<'a> { - fn from(state: &'a ActionState) -> Self { +impl<'a> From<&'a State> for ConfigSerialize<'a> { + fn from(state: &'a State) -> Self { Self { game_dir: &state.game_dir, data_dir: &state.data_dir, - nexus_api_key: &state.nexus_api_key, - unsafe_io: state.is_io_enabled, mod_order: state .mods .iter() - .map(Arc::as_ref) .map(LoadOrderEntrySerialize::from) .collect(), } @@ -60,17 +54,13 @@ pub(crate) struct LoadOrderEntry { pub(crate) struct Config { #[serde(skip)] pub path: PathBuf, - #[serde(default = "get_default_data_dir")] - pub data_dir: PathBuf, + pub data_dir: Option, pub game_dir: Option, #[serde(default)] - pub unsafe_io: bool, - pub nexus_api_key: Option, - #[serde(default)] pub mod_order: Vec, } -#[cfg(not(target_os = "windows"))] +#[cfg(not(arget_os = "windows"))] pub fn get_default_config_path() -> PathBuf { let config_dir = std::env::var("XDG_CONFIG_DIR").unwrap_or_else(|_| { let home = std::env::var("HOME").unwrap_or_else(|_| { @@ -89,7 +79,7 @@ pub fn get_default_config_path() -> PathBuf { PathBuf::from(config_dir).join("dtmm").join("dtmm.cfg") } -#[cfg(not(target_os = "windows"))] +#[cfg(not(arget_os = "windows"))] pub fn get_default_data_dir() -> PathBuf { let data_dir = std::env::var("XDG_DATA_DIR").unwrap_or_else(|_| { let home = std::env::var("HOME").unwrap_or_else(|_| { @@ -104,67 +94,59 @@ pub fn get_default_data_dir() -> PathBuf { #[cfg(target_os = "windows")] pub fn get_default_data_dir() -> PathBuf { - let data_dir = std::env::var("LOCALAPPDATA").expect("appdata env var not set"); + let data_dir = std::env::var("APPDATA").expect("appdata env var not set"); PathBuf::from(data_dir).join("dtmm") } -#[tracing::instrument] -pub(crate) async fn read_config

(path: P, is_default: bool) -> Result +#[tracing::instrument(skip(matches),fields(path = ?matches.get_one::("config")))] +pub(crate) fn read_config

(default: P, matches: &ArgMatches) -> Result where P: Into + std::fmt::Debug, { - let path = path.into(); - let default_path = get_default_config_path(); + let path = matches + .get_one::("config") + .expect("argument missing despite default"); + let default_path = default.into(); - match fs::read(&path).await { + match fs::read(path) { Ok(data) => { let data = String::from_utf8(data).wrap_err_with(|| { - format!("Config file '{}' contains invalid UTF-8", path.display()) + format!("config file {} contains invalid UTF-8", path.display()) })?; let mut cfg: Config = serde_sjson::from_str(&data) - .wrap_err_with(|| format!("Invalid config file {}", path.display()))?; - - cfg.path = path; - - tracing::debug!("Read config file '{}': {:?}", cfg.path.display(), cfg); + .wrap_err_with(|| format!("invalid config file {}", path.display()))?; + cfg.path = path.clone(); Ok(cfg) } Err(err) if err.kind() == ErrorKind::NotFound => { - if !is_default { + if matches.value_source("config") != Some(ValueSource::DefaultValue) { return Err(err) - .wrap_err_with(|| format!("Failed to read config file {}", path.display()))?; + .wrap_err_with(|| format!("failed to read config file {}", path.display()))?; } - tracing::debug!( - "Config file not found at '{}', creating default.", - path.display() - ); - { let parent = default_path .parent() .expect("a file path always has a parent directory"); - fs::create_dir_all(parent).await.wrap_err_with(|| { - format!("Failed to create directories {}", parent.display()) + fs::create_dir_all(parent).wrap_err_with(|| { + format!("failed to create directories {}", parent.display()) })?; } let config = Config { path: default_path, - data_dir: get_default_data_dir(), + data_dir: Some(get_default_data_dir()), game_dir: None, - nexus_api_key: None, mod_order: Vec::new(), - unsafe_io: false, }; { let data = serde_sjson::to_string(&config) - .wrap_err("Failed to serialize default config value")?; - fs::write(&config.path, data).await.wrap_err_with(|| { + .wrap_err("failed to serialize default config value")?; + fs::write(&config.path, data).wrap_err_with(|| { format!( - "Failed to write default config to {}", + "failed to write default config to {}", config.path.display() ) })?; @@ -173,7 +155,7 @@ where Ok(config) } Err(err) => { - Err(err).wrap_err_with(|| format!("Failed to read config file {}", path.display())) + Err(err).wrap_err_with(|| format!("failed to read config file {}", path.display())) } } } diff --git a/crates/dtmm/src/util/log.rs b/crates/dtmm/src/util/log.rs index 4b7c15a..e6a019e 100644 --- a/crates/dtmm/src/util/log.rs +++ b/crates/dtmm/src/util/log.rs @@ -1,4 +1,3 @@ -use clap::ValueEnum; use tokio::sync::mpsc::UnboundedSender; use tracing_error::ErrorLayer; use tracing_subscriber::filter::FilterFn; @@ -8,34 +7,12 @@ use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::prelude::*; use tracing_subscriber::EnvFilter; -#[derive(Clone, Copy, Debug, ValueEnum)] -pub enum LogLevel { - Trace, - Debug, - Info, - Warn, - Error, -} - -impl From for EnvFilter { - fn from(level: LogLevel) -> Self { - let filter = match level { - LogLevel::Trace => "error,dtmm=trace,sdk=trace", - LogLevel::Debug => "error,dtmm=debug,sdk=debug", - LogLevel::Info => "error,dtmm=info", - LogLevel::Warn => "error,dtmm=warn", - LogLevel::Error => "error", - }; - EnvFilter::new(filter) - } -} - pub struct ChannelWriter { - tx: UnboundedSender>, + tx: UnboundedSender, } impl ChannelWriter { - pub fn new(tx: UnboundedSender>) -> Self { + pub fn new(tx: UnboundedSender) -> Self { Self { tx } } } @@ -43,9 +20,11 @@ impl ChannelWriter { impl std::io::Write for ChannelWriter { fn write(&mut self, buf: &[u8]) -> std::io::Result { let tx = self.tx.clone(); + let string = String::from_utf8_lossy(buf).to_string(); + // The `send` errors when the receiving end has closed. // But there's not much we can do at that point, so we just ignore it. - let _ = tx.send(buf.to_vec()); + let _ = tx.send(string); Ok(buf.len()) } @@ -55,36 +34,27 @@ impl std::io::Write for ChannelWriter { } } -pub fn create_tracing_subscriber(level: Option, tx: Option>>) { - let mut env_layer = if let Some(level) = level { - EnvFilter::from(level) - } else if cfg!(debug_assertions) { +pub fn create_tracing_subscriber(tx: UnboundedSender) { + let env_layer = if cfg!(debug_assertions) { EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")) } else { EnvFilter::new("error,dtmm=info") }; - // The internal implementation of Druid's GTK file dialog turns - // cancelling the dialog into an error. The, also internal, wrapper - // then logs and swallows the error. - // Therefore, as a consumer of the library, we don't have any way - // to customize this behavior, and instead have to filter out the - // tracing event. - env_layer = env_layer.add_directive( - "druid_shell::backend::gtk::window=off" - .parse() - .expect("Invalid env filter directive"), - ); + let stdout_layer = if cfg!(debug_assertions) { + let layer = fmt::layer().pretty(); + Some(layer) + } else { + None + }; - let stdout_layer = fmt::layer().pretty(); - - let channel_layer = tx.map(|tx| { - fmt::layer() - .event_format(dtmt_shared::Formatter) - .fmt_fields(debug_fn(dtmt_shared::format_fields)) - .with_writer(move || ChannelWriter::new(tx.clone())) - .with_filter(FilterFn::new(dtmt_shared::filter_fields)) - }); + let channel_layer = fmt::layer() + // TODO: Re-enable and implement a formatter for the Druid widget + .with_ansi(false) + .event_format(dtmt_shared::Formatter) + .fmt_fields(debug_fn(dtmt_shared::format_fields)) + .with_writer(move || ChannelWriter::new(tx.clone())) + .with_filter(FilterFn::new(dtmt_shared::filter_fields)); tracing_subscriber::registry() .with(env_layer) diff --git a/crates/dtmt/Cargo.toml b/crates/dtmt/Cargo.toml index 183d6a5..ee5d4c4 100644 --- a/crates/dtmt/Cargo.toml +++ b/crates/dtmt/Cargo.toml @@ -4,40 +4,31 @@ version = "0.3.0" edition = "2021" [dependencies] -async-recursion = { workspace = true } -clap = { workspace = true } -cli-table = { workspace = true } -color-eyre = { workspace = true } -confy = { workspace = true } -csv-async = { workspace = true } -dtmt-shared = { workspace = true } -futures = { workspace = true } -futures-util = { workspace = true } -glob = { workspace = true } -luajit2-sys = { workspace = true } -minijinja = { workspace = true } -nanorand = { workspace = true } -notify = { workspace = true } -oodle = { workspace = true } -path-clean = { workspace = true } -path-slash = { workspace = true } -pin-project-lite = { workspace = true } -promptly = { workspace = true } -sdk = { workspace = true } -serde = { workspace = true } -serde_sjson = { workspace = true } -tokio = { workspace = true } -tokio-stream = { workspace = true } -tracing = { workspace = true } -tracing-error = { workspace = true } -tracing-subscriber = { workspace = true } -zip = { workspace = true } - -# Cannot be a workspace dependencies when it's optional -shlex = { version = "1.2.0", optional = true } +clap = { version = "4.0.15", features = ["color", "derive", "std", "cargo", "unicode"] } +cli-table = { version = "0.4.7", default-features = false, features = ["derive"] } +color-eyre = "0.6.2" +confy = "0.5.1" +csv-async = { version = "1.2.4", features = ["tokio", "serde"] } +dtmt-shared = { path = "../../lib/dtmt-shared", version = "*" } +futures = "0.3.25" +futures-util = "0.3.24" +glob = "0.3.0" +libloading = "0.7.4" +nanorand = "0.7.0" +oodle = { path = "../../lib/oodle", version = "*" } +pin-project-lite = "0.2.9" +promptly = "0.3.1" +sdk = { path = "../../lib/sdk", version = "*" } +serde_sjson = { path = "../../lib/serde_sjson", version = "*" } +serde = { version = "1.0.147", features = ["derive"] } +string_template = "0.2.1" +tokio-stream = { version = "0.1.11", features = ["fs", "io-util"] } +tokio = { version = "1.21.2", features = ["rt-multi-thread", "fs", "process", "macros", "tracing", "io-util", "io-std"] } +tracing-error = "0.2.0" +tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } +tracing = { version = "0.1.37", features = ["async-await"] } +zip = "0.6.3" +path-clean = "1.0.1" [dev-dependencies] tempfile = "3.3.0" - -[features] -shlex-bench = ["dep:shlex"] diff --git a/crates/dtmt/src/cmd/build.rs b/crates/dtmt/src/cmd/build.rs index 74a627d..f077094 100644 --- a/crates/dtmt/src/cmd/build.rs +++ b/crates/dtmt/src/cmd/build.rs @@ -1,5 +1,3 @@ -use std::collections::{HashMap, HashSet}; -use std::ops::Deref; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -9,18 +7,15 @@ use color_eyre::{Help, Report}; use dtmt_shared::ModConfig; use futures::future::try_join_all; use futures::StreamExt; -use path_slash::PathExt; use sdk::filetype::package::Package; -use sdk::murmur::IdString64; use sdk::{Bundle, BundleFile}; use tokio::fs::{self, File}; use tokio::io::AsyncReadExt; -use tokio::sync::Mutex; + +use crate::mods::archive::Archive; const PROJECT_CONFIG_NAME: &str = "dtmt.cfg"; -type FileIndexMap = HashMap>; - pub(crate) fn command_definition() -> Command { Command::new("build") .about("Build a project") @@ -33,35 +28,20 @@ pub(crate) fn command_definition() -> Command { If omitted, dtmt will search from the current working directory upward.", ), ) - .arg( - Arg::new("out") - .long("out") - .short('o') - .default_value("out") - .value_parser(value_parser!(PathBuf)) - .help("The directory to write output files to."), - ) - .arg( - Arg::new("deploy") - .long("deploy") - .short('d') - .value_parser(value_parser!(PathBuf)) - .help( - "If the path to the game (without the trailing '/bundle') is specified, \ - deploy the newly built bundles. \ - This will not adjust the bundle database or package files, so if files are \ - added or removed, you will have to import into DTMM and re-deploy there.", - ), - ) + .arg(Arg::new("oodle").long("oodle").help( + "The oodle library to load. This may either be:\n\ + - A library name that will be searched for in the system's default paths.\n\ + - A file path relative to the current working directory.\n\ + - An absolute file path.", + )) } -/// Try to find a `dtmt.cfg` in the given directory or traverse up the parents. #[tracing::instrument] async fn find_project_config(dir: Option) -> Result { let (path, mut file) = if let Some(path) = dir { let file = File::open(&path.join(PROJECT_CONFIG_NAME)) .await - .wrap_err_with(|| format!("Failed to open file: {}", path.display())) + .wrap_err_with(|| format!("failed to open file: {}", path.display())) .with_suggestion(|| { format!( "Make sure the file at '{}' exists and is readable", @@ -85,7 +65,7 @@ async fn find_project_config(dir: Option) -> Result { } Err(err) => { let err = Report::new(err) - .wrap_err(format!("Failed to open file: {}", path.display())); + .wrap_err(format!("failed to open file: {}", path.display())); return Err(err); } } @@ -95,52 +75,47 @@ async fn find_project_config(dir: Option) -> Result { let mut buf = String::new(); file.read_to_string(&mut buf) .await - .wrap_err("Invalid UTF-8")?; + .wrap_err("invalid UTF-8")?; let mut cfg: ModConfig = - serde_sjson::from_str(&buf).wrap_err("Failed to deserialize mod config")?; + serde_sjson::from_str(&buf).wrap_err("failed to deserialize mod config")?; cfg.dir = path; Ok(cfg) } -/// Iterate over the paths in the given `Package` and -/// compile each file by its file type. #[tracing::instrument(skip_all)] -async fn compile_package_files(pkg: &Package, cfg: &ModConfig) -> Result> { - let root = Arc::new(&cfg.dir); - let name_overrides = &cfg.name_overrides; +async fn compile_package_files

(pkg: &Package, root: P) -> Result> +where + P: AsRef + std::fmt::Debug, +{ + let root = Arc::new(root.as_ref()); let tasks = pkg .iter() - .flat_map(|(file_type, names)| { - names.iter().map(|name| { + .flat_map(|(file_type, paths)| { + paths.iter().map(|path| { ( *file_type, - name, + path, // Cloning the `Arc` here solves the issue that in the next `.map`, I need to // `move` the closure parameters, but can't `move` `root` before it was cloned. root.clone(), ) }) }) - .map(|(file_type, name, root)| async move { - let path = PathBuf::from(name); - let sjson = fs::read_to_string(&path) - .await - .wrap_err_with(|| format!("Failed to read file '{}'", path.display()))?; + .map(|(file_type, path, root)| async move { + let sjson = fs::read_to_string(&path).await?; - let name = path.with_extension("").to_slash_lossy().to_string(); - let name = if let Some(new_name) = name_overrides.get(&name) { - let new_name = match u64::from_str_radix(new_name, 16) { - Ok(hash) => IdString64::from(hash), - Err(_) => IdString64::from(new_name.clone()), - }; - tracing::info!("Overriding '{}' -> '{}'", name, new_name.display()); - new_name - } else { - IdString64::from(name.clone()) - }; - BundleFile::from_sjson(name, file_type, sjson, root.as_ref()).await + let mut path = path.clone(); + path.set_extension(""); + + BundleFile::from_sjson( + path.to_string_lossy().to_string(), + file_type, + sjson, + root.as_ref(), + ) + .await }); let results = futures::stream::iter(tasks) @@ -151,29 +126,10 @@ async fn compile_package_files(pkg: &Package, cfg: &ModConfig) -> Result + std::fmt::Debug, -) -> Result { - let root = &cfg.dir; - let package = package.as_ref(); +#[tracing::instrument(skip_all, fields(files = files.len()))] +fn compile_bundle(name: String, files: Vec) -> Result { + let mut bundle = Bundle::new(name); - let mut path = root.join(package); - path.set_extension("package"); - let sjson = fs::read_to_string(&path) - .await - .wrap_err_with(|| format!("Failed to read file {}", path.display()))?; - - let pkg_name = package.to_slash_lossy().to_string(); - let pkg = Package::from_sjson(sjson, pkg_name.clone(), root) - .await - .wrap_err_with(|| format!("Invalid package file {}", &pkg_name))?; - - let files = compile_package_files(&pkg, cfg).await?; - let mut bundle = Bundle::new(pkg_name); for file in files { bundle.add_file(file); } @@ -181,13 +137,38 @@ async fn build_package( Ok(bundle) } -/// Cleans the path of internal parent (`../`) or self (`./`) components, -/// and ensures that it is relative. +#[tracing::instrument] +async fn build_package(package: P1, root: P2) -> Result +where + P1: AsRef + std::fmt::Debug, + P2: AsRef + std::fmt::Debug, +{ + let root = root.as_ref(); + let package = package.as_ref(); + + let mut path = root.join(package); + path.set_extension("package"); + let sjson = fs::read_to_string(&path) + .await + .wrap_err_with(|| format!("failed to read file {}", path.display()))?; + + let pkg_name = package.to_string_lossy().to_string(); + let pkg = Package::from_sjson(sjson, pkg_name.clone(), root) + .await + .wrap_err_with(|| format!("invalid package file {}", &pkg_name))?; + + compile_package_files(&pkg, root) + .await + .wrap_err("failed to compile package") + .and_then(|files| compile_bundle(pkg_name, files)) + .wrap_err("failed to build bundle") +} + fn normalize_file_path>(path: P) -> Result { let path = path.as_ref(); if path.is_absolute() || path.has_root() { - let err = eyre::eyre!("Path is absolute: {}", path.display()); + let err = eyre::eyre!("path is absolute: {}", path.display()); return Err(err).with_suggestion(|| "Specify a relative file path.".to_string()); } @@ -200,94 +181,74 @@ fn normalize_file_path>(path: P) -> Result { Ok(path) } -#[tracing::instrument] -pub(crate) async fn read_project_config(dir: Option) -> Result { - let mut cfg = find_project_config(dir).await?; +#[tracing::instrument(skip_all)] +pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { + let cfg = { + let dir = matches.get_one::("directory").cloned(); + let mut cfg = find_project_config(dir).await?; - if let Some(path) = cfg.image { - let path = normalize_file_path(path) - .wrap_err("Invalid config field 'image'") + cfg.resources.init = normalize_file_path(cfg.resources.init) + .wrap_err("invalid config field 'resources.init'") .with_suggestion(|| { "Specify a file path relative to and child path of the \ directory where 'dtmt.cfg' is." .to_string() - })?; - cfg.image = Some(path); - } - - cfg.resources.init = normalize_file_path(cfg.resources.init) - .wrap_err("Invalid config field 'resources.init'") - .with_suggestion(|| { - "Specify a file path relative to and child path of the \ - directory where 'dtmt.cfg' is." - .to_string() - }) - .with_suggestion(|| { - "Use 'dtmt new' in a separate directory to generate \ + }) + .with_suggestion(|| { + "Use 'dtmt new' in a separate directory to generate \ a valid mod template." - .to_string() - })?; + .to_string() + })?; - if let Some(path) = cfg.resources.data { - let path = normalize_file_path(path) - .wrap_err("Invalid config field 'resources.data'") - .with_suggestion(|| { - "Specify a file path relative to and child path of the \ + if let Some(path) = cfg.resources.data { + let path = normalize_file_path(path) + .wrap_err("invalid config field 'resources.data'") + .with_suggestion(|| { + "Specify a file path relative to and child path of the \ directory where 'dtmt.cfg' is." - .to_string() - }) - .with_suggestion(|| { - "Use 'dtmt new' in a separate directory to generate \ + .to_string() + }) + .with_suggestion(|| { + "Use 'dtmt new' in a separate directory to generate \ a valid mod template." - .to_string() - })?; - cfg.resources.data = Some(path); - } + .to_string() + })?; + cfg.resources.data = Some(path); + } - if let Some(path) = cfg.resources.localization { - let path = normalize_file_path(path) - .wrap_err("Invalid config field 'resources.localization'") - .with_suggestion(|| { - "Specify a file path relative to and child path of the \ + if let Some(path) = cfg.resources.localization { + let path = normalize_file_path(path) + .wrap_err("invalid config field 'resources.localization'") + .with_suggestion(|| { + "Specify a file path relative to and child path of the \ directory where 'dtmt.cfg' is." - .to_string() - }) - .with_suggestion(|| { - "Use 'dtmt new' in a separate directory to generate \ + .to_string() + }) + .with_suggestion(|| { + "Use 'dtmt new' in a separate directory to generate \ a valid mod template." - .to_string() - })?; - cfg.resources.localization = Some(path); - } + .to_string() + })?; + cfg.resources.localization = Some(path); + } - Ok(cfg) -} + cfg + }; -#[tracing::instrument] -pub(crate) async fn build

( - cfg: &ModConfig, - out_path: impl AsRef + std::fmt::Debug, - game_dir: Arc>, -) -> Result<()> -where - P: AsRef + std::fmt::Debug, -{ - let out_path = out_path.as_ref(); + let dest = { + let mut path = PathBuf::from(&cfg.id); + path.set_extension("zip"); + Arc::new(path) + }; + let cfg = Arc::new(cfg); - fs::create_dir_all(out_path) - .await - .wrap_err_with(|| format!("Failed to create output directory '{}'", out_path.display()))?; - - let file_map = Arc::new(Mutex::new(FileIndexMap::new())); + tracing::debug!(?cfg); let tasks = cfg .packages .iter() - // The closure below would capture the `Arc`s before they could be cloned, - // so instead we need to clone them in a non-move block and inject them - // via parameters. - .map(|path| (path, cfg.clone(), file_map.clone(), game_dir.clone())) - .map(|(path, cfg, file_map, game_dir)| async move { + .map(|path| (path, cfg.clone())) + .map(|(path, cfg)| async move { if path.extension().is_some() { eyre::bail!( "Package name must be specified without file extension: {}", @@ -295,120 +256,45 @@ where ); } - let bundle = build_package(&cfg, path).await.wrap_err_with(|| { + build_package(path, &cfg.dir).await.wrap_err_with(|| { format!( - "Failed to build package '{}' at '{}'", + "failed to build package {} in {}", path.display(), cfg.dir.display() ) - })?; - - let bundle_name = match bundle.name() { - IdString64::Hash(_) => { - eyre::bail!("bundle name must be known as string. got hash") - } - IdString64::String(s) => s.clone(), - }; - - { - let mut file_map = file_map.lock().await; - let map_entry = file_map.entry(bundle_name).or_default(); - - for file in bundle.files() { - map_entry.insert(file.name(false, None)); - } - } - - let name = bundle.name().to_murmur64().to_string().to_ascii_lowercase(); - let path = out_path.join(&name); - let data = bundle.to_binary()?; - - tracing::trace!( - "Writing bundle {} to '{}'", - bundle.name().display(), - path.display() - ); - fs::write(&path, &data) - .await - .wrap_err_with(|| format!("Failed to write bundle to '{}'", path.display()))?; - - if let Some(game_dir) = game_dir.as_ref() { - let path = game_dir.as_ref().join(&name); - - tracing::trace!( - "Deploying bundle {} to '{}'", - bundle.name().display(), - path.display() - ); - fs::write(&path, &data) - .await - .wrap_err_with(|| format!("Failed to write bundle to '{}'", path.display()))?; - } - - Ok(()) + }) }); - try_join_all(tasks) + let bundles = try_join_all(tasks) .await - .wrap_err("Failed to build mod bundles")?; + .wrap_err("failed to build mod bundles")?; + + let config_file = { + let path = cfg.dir.join("dtmt.cfg"); + fs::read(&path) + .await + .wrap_err_with(|| format!("failed to read mod config at {}", path.display()))? + }; { - let path = out_path.join("files.sjson"); - tracing::trace!(path = %path.display(), "Writing file index"); - let file_map = file_map.lock().await; - let data = serde_sjson::to_string(file_map.deref())?; - fs::write(&path, data) - .await - .wrap_err_with(|| format!("Failed to write file index to '{}'", path.display()))?; - } - - if let Some(img_path) = &cfg.image { - let path = cfg.dir.join(img_path); - let dest = out_path.join(img_path); - - tracing::trace!(src = %path.display(), dest = %dest.display(), "Copying image file"); - - if let Some(parent) = dest.parent() { - fs::create_dir_all(&parent) - .await - .wrap_err_with(|| format!("Failed to create directory '{}'", parent.display()))?; - } - - fs::copy(&path, &dest).await.wrap_err_with(|| { - format!( - "Failed to copy image from '{}' to '{}'", - path.display(), - dest.display() - ) - })?; - } - - tracing::info!("Compiled bundles written to '{}'", out_path.display()); - - if let Some(game_dir) = game_dir.as_ref() { - tracing::info!("Deployed bundles to '{}'", game_dir.as_ref().display()); + let dest = dest.clone(); + let id = cfg.id.clone(); + tokio::task::spawn_blocking(move || { + let mut archive = Archive::new(id); + + archive.add_config(config_file); + + for bundle in bundles { + archive.add_bundle(bundle); + } + + archive + .write(dest.as_ref()) + .wrap_err("failed to write mod archive") + }) + .await??; } - Ok(()) -} - -#[tracing::instrument(skip_all)] -pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { - let cfg = read_project_config(matches.get_one::("directory").cloned()).await?; - - let game_dir = matches - .get_one::("deploy") - .map(|p| p.join("bundle")); - - let out_path = matches - .get_one::("out") - .expect("parameter should have default value"); - - tracing::debug!(?cfg, ?game_dir, ?out_path); - - let game_dir = Arc::new(game_dir); - - build(&cfg, out_path, game_dir).await?; - + tracing::info!("Mod archive written to {}", dest.display()); Ok(()) } diff --git a/crates/dtmt/src/cmd/bundle/db.rs b/crates/dtmt/src/cmd/bundle/db.rs deleted file mode 100644 index 2398573..0000000 --- a/crates/dtmt/src/cmd/bundle/db.rs +++ /dev/null @@ -1,174 +0,0 @@ -use std::{io::Cursor, path::PathBuf}; - -use clap::{value_parser, Arg, ArgMatches, Command}; -use color_eyre::{eyre::Context as _, Result}; -use sdk::murmur::{HashGroup, IdString64, Murmur64}; -use sdk::{BundleDatabase, FromBinary as _}; -use tokio::fs; - -pub(crate) fn command_definition() -> Command { - Command::new("db") - .about("Various operations regarding `bundle_database.data`.") - .subcommand_required(true) - .subcommand( - Command::new("list-files") - .about("List bundle contents") - .arg( - Arg::new("database") - .required(true) - .help("Path to the bundle database") - .value_parser(value_parser!(PathBuf)), - ) - .arg( - Arg::new("bundle") - .help("The bundle name. If omitted, all bundles will be listed.") - .required(false), - ), - ) - .subcommand( - Command::new("list-bundles").about("List bundles").arg( - Arg::new("database") - .required(true) - .help("Path to the bundle database") - .value_parser(value_parser!(PathBuf)), - ), - ) - .subcommand( - Command::new("find-file") - .about("Find the bundle a file belongs to") - .arg( - Arg::new("database") - .required(true) - .help("Path to the bundle database") - .value_parser(value_parser!(PathBuf)), - ) - .arg( - Arg::new("file-name") - .required(true) - .help("Name of the file. May be a hash in hex representation or a string"), - ), - ) -} - -#[tracing::instrument(skip_all)] -pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { - let Some((op, sub_matches)) = matches.subcommand() else { - unreachable!("clap is configured to require a subcommand"); - }; - - let database = { - let path = sub_matches - .get_one::("database") - .expect("argument is required"); - - let binary = fs::read(&path) - .await - .wrap_err_with(|| format!("Failed to read file '{}'", path.display()))?; - - let mut r = Cursor::new(binary); - - BundleDatabase::from_binary(&mut r).wrap_err("Failed to parse bundle database")? - }; - - match op { - "list-files" => { - let index = database.files(); - - if let Some(bundle) = sub_matches.get_one::("bundle") { - let hash = u64::from_str_radix(bundle, 16) - .map(Murmur64::from) - .wrap_err("Invalid hex sequence")?; - - if let Some(files) = index.get(&hash) { - for file in files { - let name = ctx.lookup_hash(file.name, HashGroup::Filename); - let extension = file.extension.ext_name(); - println!("{}.{}", name.display(), extension); - } - } else { - tracing::info!("Bundle {} not found in the database", bundle); - } - } else { - for (bundle_hash, files) in index.iter() { - let bundle_name = ctx.lookup_hash(*bundle_hash, HashGroup::Filename); - - match bundle_name { - IdString64::String(name) => { - println!("{bundle_hash:016x} {name}"); - } - IdString64::Hash(hash) => { - println!("{hash:016x}"); - } - } - - for file in files { - let name = ctx.lookup_hash(file.name, HashGroup::Filename); - let extension = file.extension.ext_name(); - - match name { - IdString64::String(name) => { - println!("\t{:016x}.{:<12} {}", file.name, extension, name); - } - IdString64::Hash(hash) => { - println!("\t{hash:016x}.{extension}"); - } - } - } - - println!(); - } - } - - Ok(()) - } - "list-bundles" => { - for bundle_hash in database.bundles().keys() { - let bundle_name = ctx.lookup_hash(*bundle_hash, HashGroup::Filename); - - match bundle_name { - IdString64::String(name) => { - println!("{bundle_hash:016x} {name}"); - } - IdString64::Hash(hash) => { - println!("{hash:016x}"); - } - } - } - - Ok(()) - } - "find-file" => { - let name = sub_matches - .get_one::("file-name") - .expect("required argument"); - let name = match u64::from_str_radix(name, 16).map(Murmur64::from) { - Ok(hash) => hash, - Err(_) => Murmur64::hash(name), - }; - - let bundles = database.files().iter().filter_map(|(bundle_hash, files)| { - if files.iter().any(|file| file.name == name) { - Some(bundle_hash) - } else { - None - } - }); - - let mut found = false; - - for bundle in bundles { - found = true; - println!("{bundle:016x}"); - } - - if !found { - std::process::exit(1); - } - - Ok(()) - } - _ => unreachable!( - "clap is configured to require a subcommand, and they're all handled above" - ), - } -} diff --git a/crates/dtmt/src/cmd/bundle/extract.rs b/crates/dtmt/src/cmd/bundle/extract.rs index f20733d..3524f5b 100644 --- a/crates/dtmt/src/cmd/bundle/extract.rs +++ b/crates/dtmt/src/cmd/bundle/extract.rs @@ -1,20 +1,17 @@ -use std::ffi::OsStr; use std::path::{Path, PathBuf}; use std::sync::Arc; use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; -use color_eyre::eyre::{self, bail, Context, Result}; -use color_eyre::{Help, Report}; +use color_eyre::eyre::{self, Context, Result}; +use color_eyre::{Help, Report, SectionExt}; use futures::future::try_join_all; use futures::StreamExt; use glob::Pattern; -use sdk::{Bundle, BundleFile, CmdLine}; +use sdk::{Bundle, BundleFile}; use tokio::fs; use crate::cmd::util::resolve_bundle_paths; -use crate::shell_parse::ShellParser; -#[inline] fn parse_glob_pattern(s: &str) -> Result { match Pattern::new(s) { Ok(p) => Ok(p), @@ -22,7 +19,6 @@ fn parse_glob_pattern(s: &str) -> Result { } } -#[inline] fn flatten_name(s: &str) -> String { s.replace('/', "_") } @@ -37,7 +33,7 @@ pub(crate) fn command_definition() -> Command { .value_parser(value_parser!(PathBuf)) .help( "Path to the bundle(s) to read. If this points to a directory instead \ - of a file, all files in that directory will be checked.", + of a file, all files in that directory will be checked.", ), ) .arg( @@ -93,81 +89,30 @@ pub(crate) fn command_definition() -> Command { Arg::new("ljd") .long("ljd") .help( - "A custom command line to execute ljd with. It is treated as follows:\n\ - * if the argument is a valid path to an existing file:\n\ - ** if the file is called 'main.py', it is assumed that 'python.exe' \ - exists in PATH to execute this with.\n\ - ** otherwise it is treated as an executable\n\ - * if it's a single word, it's treated as an executable in PATH\n\ - * otherwise it is treated as a command line template.\n\ - In any case, the application being run must accept ljd's flags '-c' and '-f'.", + "Path to a custom ljd executable. If not set, \ + `ljd` will be called from PATH.", ) .default_value("ljd"), ) - // .arg( - // Arg::new("revorb") - // .long("revorb") - // .help( - // "Path to a custom revorb executable. If not set, \ - // `revorb` will be called from PATH.", - // ) - // .default_value("revorb"), - // ) - // .arg( - // Arg::new("ww2ogg") - // .long("ww2ogg") - // .help( - // "Path to a custom ww2ogg executable. If not set, \ - // `ww2ogg` will be called from PATH.\nSee the documentation for how \ - // to set up the script for this.", - // ) - // .default_value("ww2ogg"), - // ) -} - -#[tracing::instrument] -async fn parse_command_line_template(tmpl: &String) -> Result { - if tmpl.trim().is_empty() { - eyre::bail!("Command line template must not be empty"); - } - - let mut cmd = if matches!(fs::try_exists(tmpl).await, Ok(true)) { - let path = PathBuf::from(tmpl); - if path.file_name() == Some(OsStr::new("main.py")) { - let mut cmd = CmdLine::new("python"); - cmd.arg(path); - cmd - } else { - CmdLine::new(path) - } - } else { - let mut parsed = ShellParser::new(tmpl.as_bytes()); - // Safety: The initial `tmpl` was a `&String` (i.e. valid UTF-8), and `shlex` does not - // insert or remove characters, nor does it split UTF-8 characters. - // So the resulting byte stream is still valid UTF-8. - let mut cmd = CmdLine::new(unsafe { - let bytes = parsed.next().expect("Template is not empty"); - String::from_utf8_unchecked(bytes.to_vec()) - }); - - for arg in parsed.by_ref() { - // Safety: See above. - cmd.arg(unsafe { String::from_utf8_unchecked(arg.to_vec()) }); - } - - if parsed.errored { - bail!("Invalid command line template"); - } - - cmd - }; - - // Add ljd flags - cmd.arg("-c"); - - tracing::debug!("Parsed command line template: {:?}", cmd); - - Ok(cmd) + .arg( + Arg::new("revorb") + .long("revorb") + .help( + "Path to a custom revorb executable. If not set, \ + `revorb` will be called from PATH.", + ) + .default_value("revorb"), + ) + .arg( + Arg::new("ww2ogg") + .long("ww2ogg") + .help( + "Path to a custom ww2ogg executable. If not set, \ + `ww2ogg` will be called from PATH.\nSee the documentation for how \ + to set up the script for this.", + ) + .default_value("ww2ogg"), + ) } #[tracing::instrument(skip_all)] @@ -176,19 +121,16 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( let ljd_bin = matches .get_one::("ljd") .expect("no default value for 'ljd' parameter"); - // let revorb_bin = matches - // .get_one::("revorb") - // .expect("no default value for 'revorb' parameter"); - // let ww2ogg_bin = matches - // .get_one::("ww2ogg") - // .expect("no default value for 'ww2ogg' parameter"); + let revorb_bin = matches + .get_one::("revorb") + .expect("no default value for 'revorb' parameter"); + let ww2ogg_bin = matches + .get_one::("ww2ogg") + .expect("no default value for 'ww2ogg' parameter"); - ctx.ljd = parse_command_line_template(ljd_bin) - .await - .map(Option::Some) - .wrap_err("Failed to parse command line template for flag 'ljd'")?; - // ctx.revorb = Some(revorb_bin.clone()); - // ctx.ww2ogg = Some(ww2ogg_bin.clone()); + ctx.ljd = Some(ljd_bin.clone()); + ctx.revorb = Some(revorb_bin.clone()); + ctx.ww2ogg = Some(ww2ogg_bin.clone()); } let includes = match matches.get_many::("include") { @@ -287,34 +229,6 @@ where P1: AsRef + std::fmt::Debug, P2: AsRef + std::fmt::Debug, { - let ctx = if ctx.game_dir.is_some() { - tracing::debug!( - "Got game directory from config: {}", - ctx.game_dir.as_ref().unwrap().display() - ); - - ctx - } else { - let game_dir = path - .as_ref() - .parent() - .and_then(|parent| parent.parent()) - .map(|p| p.to_path_buf()); - - tracing::info!( - "No game directory configured, guessing from bundle path: {:?}", - game_dir - ); - - Arc::new(sdk::Context { - game_dir, - lookup: Arc::clone(&ctx.lookup), - ljd: ctx.ljd.clone(), - revorb: ctx.revorb.clone(), - ww2ogg: ctx.ww2ogg.clone(), - }) - }; - let bundle = { let data = fs::read(path.as_ref()).await?; let name = Bundle::get_name_from_path(&ctx, path.as_ref()); @@ -397,25 +311,14 @@ where path.push(name); if options.dry_run { - tracing::info!("Dry Run: Writing file '{}'", path.display()); + tracing::info!(path = %path.display(), "Writing file"); } else { - tracing::info!("Writing file '{}'", path.display()); + tracing::debug!(path = %path.display(), "Writing file"); tasks.push(tokio::spawn(async move { - if let Some(parent) = path.parent() { - fs::create_dir_all(&parent).await.wrap_err_with(|| { - format!( - "failed to create parent directories '{}'", - parent.display() - ) - })?; - } - - fs::write(&path, file.data()).await.wrap_err_with(|| { - format!( - "failed to write extracted file to disc: '{}'", - path.display() - ) - }) + fs::write(&path, file.data()) + .await + .wrap_err("failed to write extracted file to disc") + .with_section(|| path.display().to_string().header("Path")) })); } } @@ -439,9 +342,9 @@ where path.push(name); if options.dry_run { - tracing::info!("Dry Run: Writing file '{}'", path.display()); + tracing::info!(path = %path.display(), "Writing file"); } else { - tracing::info!("Writing file '{}'", path.display()); + tracing::debug!(path = %path.display(), "Writing file"); tasks.push(tokio::spawn(async move { let parent = match path.parent() { Some(parent) => parent, @@ -453,19 +356,17 @@ where } }; - fs::create_dir_all(parent).await.wrap_err_with(|| { - format!( - "failed to create parent directory: '{}'", - parent.display() - ) - })?; + fs::create_dir_all(parent) + .await + .wrap_err("failed to create parent directory") + .with_section(|| { + parent.display().to_string().header("Path") + })?; - fs::write(&path, file.data()).await.wrap_err_with(|| { - format!( - "failed to write extracted file to disc: '{}'", - path.display() - ) - }) + fs::write(&path, file.data()) + .await + .wrap_err("failed to write extracted file to disc") + .with_section(|| path.display().to_string().header("Path")) })); } } @@ -473,7 +374,10 @@ where } } Err(err) => { - let err = err.wrap_err(format!("Failed to decompile file {name}")); + let err = err + .wrap_err("Failed to decompile") + .with_section(|| name.header("File")); + tracing::error!("{:?}", err); } }; diff --git a/crates/dtmt/src/cmd/bundle/inject.rs b/crates/dtmt/src/cmd/bundle/inject.rs index 1fba83d..9c47686 100644 --- a/crates/dtmt/src/cmd/bundle/inject.rs +++ b/crates/dtmt/src/cmd/bundle/inject.rs @@ -1,298 +1,112 @@ -use std::path::{Path, PathBuf}; -use std::str::FromStr as _; +use std::path::PathBuf; -use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; -use color_eyre::eyre::{self, Context, OptionExt, Result}; +use clap::{value_parser, Arg, ArgMatches, Command}; +use color_eyre::eyre::{self, Context, Result}; use color_eyre::Help; -use path_slash::PathBufExt as _; -use sdk::murmur::IdString64; -use sdk::{Bundle, BundleFile, BundleFileType}; -use tokio::fs; +use sdk::Bundle; +use tokio::fs::{self, File}; +use tokio::io::AsyncReadExt; pub(crate) fn command_definition() -> Command { Command::new("inject") - .subcommand_required(true) - .about("Inject a file into a bundle.\n\ - Raw binary data can be used to directly replace the file's variant data blob without affecting the metadata.\n\ - Alternatively, a compiler format may be specified, and a complete bundle file is created.") + .about("Inject a file into a bundle.") + .arg( + Arg::new("replace") + .help("The name of a file in the bundle whos content should be replaced.") + .short('r') + .long("replace"), + ) .arg( Arg::new("output") .help( "The path to write the changed bundle to. \ - If omitted, the input bundle will be overwritten.\n\ - Remember to add a `.patch_` suffix if you also use '--patch'.", + If omitted, the input bundle will be overwritten.", ) .short('o') .long("output") .value_parser(value_parser!(PathBuf)), ) .arg( - Arg::new("patch") - .help("Create a patch bundle. Optionally, a patch NUMBER may be specified as \ - '--patch=123'.\nThe maximum number is 999, the default is 1.\n\ - If `--output` is not specified, the `.patch_` suffix is added to \ - the given bundle name.") - .short('p') - .long("patch") - .num_args(0..=1) - .require_equals(true) - .default_missing_value("1") - .value_name("NUMBER") - .value_parser(value_parser!(u16)) + Arg::new("bundle") + .help("Path to the bundle to inject the file into.") + .required(true) + .value_parser(value_parser!(PathBuf)), ) .arg( - Arg::new("type") - .help("Compile the new file as the given TYPE. If omitted, the file type is \ - is guessed from the file extension.") - .value_name("TYPE") + Arg::new("file") + .help("Path to the file to inject.") + .required(true) + .value_parser(value_parser!(PathBuf)), ) - .subcommand( - Command::new("replace") - .about("Replace an existing file in the bundle") - .arg( - Arg::new("variant") - .help("In combination with '--raw', specify the variant index to replace.") - .long("variant") - .default_value("0") - .value_parser(value_parser!(u8)) - ) - .arg( - Arg::new("raw") - .help("Insert the given file as raw binary data.\n\ - Cannot be used with '--patch'.") - .long("raw") - .action(ArgAction::SetTrue) - ) - .arg( - Arg::new("bundle") - .help("Path to the bundle to inject the file into.") - .required(true) - .value_parser(value_parser!(PathBuf)), - ) - .arg( - Arg::new("bundle-file") - .help("The name of a file in the bundle whose content should be replaced.") - .required(true), - ) - .arg( - Arg::new("new-file") - .help("Path to the file to inject.") - .required(true) - .value_parser(value_parser!(PathBuf)), - ), - ) - // .subcommand( - // Command::new("add") - // .about("Add a new file to the bundle") - // .arg( - // Arg::new("new-file") - // .help("Path to the file to inject.") - // .required(true) - // .value_parser(value_parser!(PathBuf)), - // ) - // .arg( - // Arg::new("bundle") - // .help("Path to the bundle to inject the file into.") - // .required(true) - // .value_parser(value_parser!(PathBuf)), - // ), - // ) } -#[tracing::instrument] -async fn compile_file( - path: impl AsRef + std::fmt::Debug, - name: impl Into + std::fmt::Debug, - file_type: BundleFileType, -) -> Result { - let path = path.as_ref(); - - let file_data = fs::read(&path) - .await - .wrap_err_with(|| format!("Failed to read file '{}'", path.display()))?; - let _sjson = String::from_utf8(file_data) - .wrap_err_with(|| format!("Invalid UTF8 data in '{}'", path.display()))?; - - let _root = path.parent().ok_or_eyre("File path has no parent")?; - - eyre::bail!( - "Compilation for type '{}' is not implemented, yet", - file_type - ) -} - -#[tracing::instrument( - skip_all, - fields( - bundle_path = tracing::field::Empty, - in_file_path = tracing::field::Empty, - output_path = tracing::field::Empty, - target_name = tracing::field::Empty, - file_type = tracing::field::Empty, - raw = tracing::field::Empty, - ) -)] +#[tracing::instrument(skip_all)] pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { - let Some((op, sub_matches)) = matches.subcommand() else { - unreachable!("clap is configured to require a subcommand, and they're all handled above"); - }; - - let bundle_path = sub_matches + let bundle_path = matches .get_one::("bundle") .expect("required parameter not found"); - let in_file_path = sub_matches - .get_one::("new-file") + let file_path = matches + .get_one::("file") .expect("required parameter not found"); - let patch_number = matches - .get_one::("patch") - .map(|num| format!("{num:03}")); + tracing::trace!(bundle_path = %bundle_path.display(), file_path = %file_path.display()); - let output_path = matches - .get_one::("output") - .cloned() - .unwrap_or_else(|| { - let mut output_path = bundle_path.clone(); - - if let Some(patch_number) = patch_number.as_ref() { - output_path.set_extension(format!("patch_{patch_number:03}")); - } - - output_path - }); - - let target_name = if op == "replace" { - sub_matches - .get_one::("bundle-file") - .map(|name| match u64::from_str_radix(name, 16) { - Ok(id) => IdString64::from(id), - Err(_) => IdString64::String(name.clone()), - }) - .expect("argument is required") - } else { - let mut path = PathBuf::from(in_file_path); - path.set_extension(""); - IdString64::from(path.to_slash_lossy().to_string()) - }; - - let file_type = if let Some(forced_type) = matches.get_one::("type") { - BundleFileType::from_str(forced_type.as_str()).wrap_err("Unknown file type")? - } else { - in_file_path - .extension() - .and_then(|s| s.to_str()) - .ok_or_eyre("File extension missing") - .and_then(BundleFileType::from_str) - .wrap_err("Unknown file type") - .with_suggestion(|| "Use '--type TYPE' to specify the file type")? - }; - - { - let span = tracing::Span::current(); - if !span.is_disabled() { - span.record("bundle_path", bundle_path.display().to_string()); - span.record("in_file_path", in_file_path.display().to_string()); - span.record("output_path", output_path.display().to_string()); - span.record("raw", sub_matches.get_flag("raw")); - span.record("target_name", target_name.display().to_string()); - span.record("file_type", format!("{file_type:?}")); - } - } - - let bundle_name = Bundle::get_name_from_path(&ctx, bundle_path); let mut bundle = { - fs::read(bundle_path) - .await - .map_err(From::from) - .and_then(|binary| Bundle::from_binary(&ctx, bundle_name.clone(), binary)) - .wrap_err_with(|| format!("Failed to open bundle '{}'", bundle_path.display()))? + let binary = fs::read(bundle_path).await?; + let name = Bundle::get_name_from_path(&ctx, bundle_path); + Bundle::from_binary(&ctx, name, binary).wrap_err("Failed to open bundle file")? }; - let output_bundle = match op { - "replace" => { - let Some(file) = bundle - .files_mut() - .find(|file| *file.base_name() == target_name) - else { - let err = eyre::eyre!( - "No file with name '{}' in bundle '{}'", - target_name.display(), - bundle_path.display() - ); + if let Some(name) = matches.get_one::("replace") { + let mut file = File::open(&file_path) + .await + .wrap_err_with(|| format!("failed to open '{}'", file_path.display()))?; - return Err(err).with_suggestion(|| { + if let Some(variant) = bundle + .files_mut() + .filter(|file| file.matches_name(name.clone())) + // TODO: Handle file variants + .find_map(|file| file.variants_mut().next()) + { + let mut data = Vec::new(); + file.read_to_end(&mut data) + .await + .wrap_err("failed to read input file")?; + variant.set_data(data); + } else { + let err = eyre::eyre!("No file '{}' in this bundle.", name) + .with_suggestion(|| { format!( - "Run '{} bundle list \"{}\"' to list the files in this bundle.", + "Run '{} bundle list {}' to list the files in this bundle.", clap::crate_name!(), bundle_path.display() ) + }) + .with_suggestion(|| { + format!( + "Use '{} bundle inject --add {} {} {}' to add it as a new file", + clap::crate_name!(), + name, + bundle_path.display(), + file_path.display() + ) }); - }; - if sub_matches.get_flag("raw") { - let variant_index = sub_matches - .get_one::("variant") - .expect("argument with default missing"); - - let Some(variant) = file.variants_mut().nth(*variant_index as usize) else { - let err = eyre::eyre!( - "Variant index '{}' does not exist in '{}'", - variant_index, - target_name.display() - ); - - return Err(err).with_suggestion(|| { - format!( - "See '{} bundle inject add --help' if you want to add it as a new file", - clap::crate_name!(), - ) - }); - }; - - let data = tokio::fs::read(&in_file_path).await.wrap_err_with(|| { - format!("Failed to read file '{}'", in_file_path.display()) - })?; - variant.set_data(data); - file.set_modded(true); - bundle - } else { - let mut bundle_file = compile_file(in_file_path, target_name.clone(), file_type) - .await - .wrap_err("Failed to compile")?; - - bundle_file.set_modded(true); - - if patch_number.is_some() { - let mut output_bundle = Bundle::new(bundle_name); - output_bundle.add_file(bundle_file); - output_bundle - } else { - *file = bundle_file; - - dbg!(&file); - bundle - } - } + return Err(err); } - "add" => { - unimplemented!("Implement adding a new file to the bundle."); - } - "copy" => { - unimplemented!("Implement copying a file from one bundle to the other."); - } - _ => unreachable!("no other operations exist"), - }; - let data = output_bundle - .to_binary() - .wrap_err("Failed to write changed bundle to output")?; + let out_path = matches.get_one::("output").unwrap_or(bundle_path); + let data = bundle + .to_binary() + .wrap_err("failed to write changed bundle to output")?; - fs::write(&output_path, &data) - .await - .wrap_err_with(|| format!("Failed to write data to '{}'", output_path.display()))?; + fs::write(out_path, &data) + .await + .wrap_err("failed to write data to output file")?; - tracing::info!("Modified bundle written to '{}'", output_path.display()); - - Ok(()) + Ok(()) + } else { + eyre::bail!("Currently, only the '--replace' operation is supported."); + } } diff --git a/crates/dtmt/src/cmd/bundle/list.rs b/crates/dtmt/src/cmd/bundle/list.rs index d511f35..b985ad2 100644 --- a/crates/dtmt/src/cmd/bundle/list.rs +++ b/crates/dtmt/src/cmd/bundle/list.rs @@ -36,18 +36,6 @@ enum OutputFormat { Text, } -fn format_byte_size(size: usize) -> String { - if size < 1024 { - format!("{size} Bytes") - } else if size < 1024 * 1024 { - format!("{} kB", size / 1024) - } else if size < 1024 * 1024 * 1024 { - format!("{} MB", size / (1024 * 1024)) - } else { - format!("{} GB", size / (1024 * 1024 * 1024)) - } -} - #[tracing::instrument(skip(ctx))] async fn print_bundle_contents

(ctx: &sdk::Context, path: P, fmt: OutputFormat) -> Result<()> where @@ -62,11 +50,7 @@ where match fmt { OutputFormat::Text => { - println!( - "Bundle: {} ({:016x})", - bundle.name().display(), - bundle.name() - ); + println!("Bundle: {}", bundle.name().display()); for f in bundle.files().iter() { if f.variants().len() != 1 { @@ -79,10 +63,9 @@ where let v = &f.variants()[0]; println!( - "\t{}.{}: {} ({})", + "\t{}.{}: {} bytes", f.base_name().display(), f.file_type().ext_name(), - format_byte_size(v.size()), v.size() ); } @@ -115,7 +98,7 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { async move { if let Err(err) = print_bundle_contents(&ctx, &p, fmt) .await - .wrap_err_with(|| format!("Failed to list contents of bundle {}", p.display())) + .wrap_err_with(|| format!("failed to list contents of bundle {}", p.display())) { tracing::error!("{err:?}"); } diff --git a/crates/dtmt/src/cmd/bundle/mod.rs b/crates/dtmt/src/cmd/bundle/mod.rs index c5145e4..6baf860 100644 --- a/crates/dtmt/src/cmd/bundle/mod.rs +++ b/crates/dtmt/src/cmd/bundle/mod.rs @@ -1,7 +1,6 @@ -use clap::{ArgMatches, Command}; +use clap::{Arg, ArgMatches, Command}; use color_eyre::eyre::Result; -mod db; mod decompress; mod extract; mod inject; @@ -11,11 +10,16 @@ pub(crate) fn command_definition() -> Command { Command::new("bundle") .subcommand_required(true) .about("Manipulate the game's bundle files") + .arg(Arg::new("oodle").long("oodle").help( + "The oodle library to load. This may either be:\n\ + - A library name that will be searched for in the system's default paths.\n\ + - A file path relative to the current working directory.\n\ + - An absolute file path.", + )) .subcommand(decompress::command_definition()) .subcommand(extract::command_definition()) .subcommand(inject::command_definition()) .subcommand(list::command_definition()) - .subcommand(db::command_definition()) } #[tracing::instrument(skip_all)] @@ -25,7 +29,6 @@ pub(crate) async fn run(ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { Some(("extract", sub_matches)) => extract::run(ctx, sub_matches).await, Some(("inject", sub_matches)) => inject::run(ctx, sub_matches).await, Some(("list", sub_matches)) => list::run(ctx, sub_matches).await, - Some(("db", sub_matches)) => db::run(ctx, sub_matches).await, _ => unreachable!( "clap is configured to require a subcommand, and they're all handled above" ), diff --git a/crates/dtmt/src/cmd/dictionary.rs b/crates/dtmt/src/cmd/dictionary.rs index 8f0d32c..20ec1fc 100644 --- a/crates/dtmt/src/cmd/dictionary.rs +++ b/crates/dtmt/src/cmd/dictionary.rs @@ -1,5 +1,4 @@ use std::path::PathBuf; -use std::sync::Arc; use clap::{value_parser, Arg, ArgAction, ArgMatches, Command, ValueEnum}; use cli_table::{print_stdout, WithTitle}; @@ -123,7 +122,7 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( .expect("required argument not found"); u64::from_str_radix(s, 16) - .wrap_err("Failed to parse argument as hexadecimal string")? + .wrap_err("failed to parse argument as hexadecimal string")? }; let groups = sub_matches @@ -146,10 +145,7 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( .get_one::("group") .expect("required argument not found"); - let r: BufReader> = if let Some(name) = - path.file_name() - && name == "-" - { + let r: BufReader> = if let Some(name) = path.file_name() && name == "-" { let f = tokio::io::stdin(); BufReader::new(Box::new(f)) } else { @@ -157,8 +153,6 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( BufReader::new(Box::new(f)) }; - let lookup = Arc::make_mut(&mut ctx.lookup); - let group = sdk::murmur::HashGroup::from(*group); let mut added = 0; @@ -168,15 +162,15 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( let total = { for line in lines.into_iter() { let value = line?; - if lookup.find(&value, group).is_some() { + if ctx.lookup.find(&value, group).is_some() { skipped += 1; } else { - lookup.add(value, group); + ctx.lookup.add(value, group); added += 1; } } - lookup.len() + ctx.lookup.len() }; let out_path = matches @@ -193,7 +187,7 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( }) .with_section(|| out_path.display().to_string().header("Path:"))?; - lookup + ctx.lookup .to_csv(f) .await .wrap_err("Failed to write dictionary to disk")?; @@ -230,12 +224,9 @@ pub(crate) async fn run(mut ctx: sdk::Context, matches: &ArgMatches) -> Result<( let lookup = &ctx.lookup; let rows: Vec<_> = lookup.entries().iter().map(TableRow::from).collect(); - match print_stdout(rows.with_title()) { - Ok(_) => Ok(()), - // Closing stdout prematurely is normal behavior with things like piping into `head` - Err(err) if err.kind() == std::io::ErrorKind::BrokenPipe => Ok(()), - Err(err) => Err(err.into()), - } + print_stdout(rows.with_title())?; + + Ok(()) } _ => unreachable!( "clap is configured to require a subcommand, and they're all handled above" diff --git a/crates/dtmt/src/cmd/migrate.rs b/crates/dtmt/src/cmd/migrate.rs deleted file mode 100644 index d7bfa19..0000000 --- a/crates/dtmt/src/cmd/migrate.rs +++ /dev/null @@ -1,407 +0,0 @@ -use std::collections::HashMap; -use std::ffi::{CStr, CString}; -use std::path::{Path, PathBuf}; - -use clap::{value_parser, Arg, ArgMatches, Command}; -use color_eyre::eyre::{self, Context}; -use color_eyre::{Help, Report, Result}; -use dtmt_shared::{ModConfig, ModConfigResources, ModDependency}; -use futures::FutureExt; -use luajit2_sys as lua; -use tokio::fs; -use tokio_stream::wrappers::ReadDirStream; -use tokio_stream::StreamExt; - -pub(crate) fn command_definition() -> Command { - Command::new("migrate") - .about("Migrate a mod project from the loose file structure to DTMT.") - .arg( - Arg::new("mod-file") - .required(true) - .value_parser(value_parser!(PathBuf)) - .help("The path to the mod's '.mod' file."), - ) - .arg( - Arg::new("directory") - .required(true) - .value_parser(value_parser!(PathBuf)) - .help( - "The directory to create the mod in. Within this directory, \ - DTMT will create a new folder named after the mod ID and migrate files \ - into that folder.", - ), - ) -} - -#[derive(Clone, Debug)] -struct ModFile { - id: String, - init: PathBuf, - data: Option, - localization: Option, -} - -// This piece of Lua code stubs DMF functions and runs a mod's `.mod` file to extract -// the contained information. -static MOD_FILE_RUNNER: &str = r#" -_DATA = {} - -function fassert() end - -function new_mod(id, options) - _DATA.id = id - _DATA.init = options.mod_script - _DATA.data = options.mod_data - _DATA.localization = options.mod_localization -end - -dmf = { - dofile = function(self, file) - _DATA.init = file - end -} - -_MOD().run() -"#; - -#[tracing::instrument] -async fn evaluate_mod_file(path: impl AsRef + std::fmt::Debug) -> Result { - let path = path.as_ref(); - let code = fs::read(path) - .await - .wrap_err_with(|| format!("Failed to read file '{}'", path.display()))?; - - tokio::task::spawn_blocking(move || unsafe { - let state = lua::luaL_newstate(); - lua::luaL_openlibs(state); - - let code = CString::new(code).expect("Cannot build CString"); - let name = CString::new("_MOD").expect("Cannot build CString"); - - match lua::luaL_loadstring(state, code.as_ptr()) as u32 { - lua::LUA_OK => {} - lua::LUA_ERRSYNTAX => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Invalid syntax: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory") - } - _ => unreachable!(), - } - - tracing::trace!("Loaded '.mod' code"); - - lua::lua_setglobal(state, name.as_ptr()); - - let code = CString::new(MOD_FILE_RUNNER).expect("Cannot build CString"); - match lua::luaL_loadstring(state, code.as_ptr()) as u32 { - lua::LUA_OK => {} - lua::LUA_ERRSYNTAX => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Invalid syntax: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory") - } - _ => unreachable!(), - } - - match lua::lua_pcall(state, 0, 1, 0) as u32 { - lua::LUA_OK => {} - lua::LUA_ERRRUN => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); - - lua::lua_close(state); - - eyre::bail!("Failed to evaluate '.mod' file: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory") - } - // We don't use an error handler function, so this should be unreachable - lua::LUA_ERRERR => unreachable!(), - _ => unreachable!(), - } - - tracing::trace!("Loaded file runner code"); - - let name = CString::new("_DATA").expect("Cannot build CString"); - lua::lua_getglobal(state, name.as_ptr()); - - let id = { - let name = CString::new("id").expect("Cannot build CString"); - lua::lua_getfield(state, -1, name.as_ptr()); - let val = { - let ptr = lua::lua_tostring(state, -1); - let str = CStr::from_ptr(ptr); - str.to_str() - .expect("ID value is not a valid string") - .to_string() - }; - lua::lua_pop(state, 1); - val - }; - - let path_prefix = format!("{id}/"); - - let init = { - let name = CString::new("init").expect("Cannot build CString"); - lua::lua_getfield(state, -1, name.as_ptr()); - let val = { - let ptr = lua::lua_tostring(state, -1); - let str = CStr::from_ptr(ptr); - str.to_str().expect("ID value is not a valid string") - }; - lua::lua_pop(state, 1); - PathBuf::from(val.strip_prefix(&path_prefix).unwrap_or(val)) - }; - - let data = { - let name = CString::new("data").expect("Cannot build CString"); - lua::lua_getfield(state, -1, name.as_ptr()); - - if lua::lua_isnil(state, -1) > 0 { - None - } else { - let val = { - let ptr = lua::lua_tostring(state, -1); - let str = CStr::from_ptr(ptr); - str.to_str().expect("ID value is not a valid string") - }; - lua::lua_pop(state, 1); - Some(PathBuf::from(val.strip_prefix(&path_prefix).unwrap_or(val))) - } - }; - - let localization = { - let name = CString::new("localization").expect("Cannot build CString"); - lua::lua_getfield(state, -1, name.as_ptr()); - - if lua::lua_isnil(state, -1) > 0 { - None - } else { - let val = { - let ptr = lua::lua_tostring(state, -1); - let str = CStr::from_ptr(ptr); - str.to_str().expect("ID value is not a valid string") - }; - lua::lua_pop(state, 1); - Some(PathBuf::from(val.strip_prefix(&path_prefix).unwrap_or(val))) - } - }; - - lua::lua_close(state); - - let mod_file = ModFile { - id, - init, - data, - localization, - }; - - tracing::trace!(?mod_file); - - Ok(mod_file) - }) - .await - .map_err(Report::new) - .flatten() - .wrap_err("Failed to run mod file handler") -} - -#[async_recursion::async_recursion] -#[tracing::instrument] -async fn process_directory(path: P1, prefix: P2) -> Result<()> -where - P1: AsRef + std::fmt::Debug + std::marker::Send, - P2: AsRef + std::fmt::Debug + std::marker::Send, -{ - let path = path.as_ref(); - let prefix = prefix.as_ref(); - - let read_dir = fs::read_dir(&path) - .await - .wrap_err_with(|| format!("Failed to read directory '{}'", path.display()))?; - - let stream = ReadDirStream::new(read_dir).map(|res| res.wrap_err("Failed to read dir entry")); - tokio::pin!(stream); - - while let Some(res) = stream.next().await { - let entry = res?; - let in_path = entry.path(); - let out_path = prefix.join(entry.file_name()); - - let t = entry.file_type().await?; - - if t.is_dir() { - process_directory(in_path, out_path).await?; - } else { - tracing::trace!( - "Copying file '{}' -> '{}'", - in_path.display(), - out_path.display() - ); - let res = fs::create_dir_all(prefix) - .then(|_| fs::copy(&in_path, &out_path)) - .await - .wrap_err_with(|| { - format!( - "Failed to copy '{}' -> '{}'", - in_path.display(), - out_path.display() - ) - }); - if let Err(err) = res { - tracing::error!("{:?}", err); - } - } - } - - Ok(()) -} - -#[tracing::instrument(skip_all)] -pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { - let (mod_file, in_dir) = { - let path = matches - .get_one::("mod-file") - .expect("Parameter is required"); - - let mod_file = evaluate_mod_file(&path) - .await - .wrap_err("Failed to evaluate '.mod' file")?; - - ( - mod_file, - path.parent().expect("A file path always has a parent"), - ) - }; - - let out_dir = matches - .get_one::("directory") - .expect("Parameter is required"); - - { - let is_dir = fs::metadata(out_dir) - .await - .map(|meta| meta.is_dir()) - .unwrap_or(false); - - if !is_dir { - let err = eyre::eyre!("Invalid output directory '{}'", out_dir.display()); - return Err(err) - .with_suggestion(|| "Make sure the directory exists and is writable.".to_string()); - } - } - - let out_dir = out_dir.join(&mod_file.id); - - fs::create_dir(&out_dir) - .await - .wrap_err_with(|| format!("Failed to create mod directory '{}'", out_dir.display()))?; - - tracing::info!("Created mod directory '{}'", out_dir.display()); - - println!( - "Enter additional information about your mod '{}'!", - &mod_file.id - ); - - let name = promptly::prompt_default("Display name", mod_file.id.clone()) - .map(|s: String| s.trim().to_string())?; - let summary = promptly::prompt("Short summary").map(|s: String| s.trim().to_string())?; - let author = - promptly::prompt_opt("Author").map(|opt| opt.map(|s: String| s.trim().to_string()))?; - let version = promptly::prompt_default("Version", String::from("0.1.0")) - .map(|s: String| s.trim().to_string())?; - let categories = promptly::prompt("Categories (comma separated list)") - .map(|s: String| s.trim().to_string()) - .map(|s: String| s.split(',').map(|s| s.trim().to_string()).collect())?; - - let packages = vec![PathBuf::from("packages/mods").join(&mod_file.id)]; - - let dtmt_cfg = ModConfig { - dir: out_dir, - id: mod_file.id, - name, - summary, - author, - version, - description: None, - image: None, - categories, - packages, - resources: ModConfigResources { - init: mod_file.init, - data: mod_file.data, - localization: mod_file.localization, - }, - depends: vec![ModDependency::ID(String::from("DMF"))], - bundled: true, - name_overrides: HashMap::new(), - }; - - tracing::debug!(?dtmt_cfg); - - { - let path = dtmt_cfg.dir.join("dtmt.cfg"); - let data = serde_sjson::to_string(&dtmt_cfg).wrap_err("Failed to serialize dtmt.cfg")?; - fs::write(&path, &data) - .await - .wrap_err_with(|| format!("Failed to write '{}'", path.display()))?; - - tracing::info!("Created mod configuration at '{}'", path.display()); - } - - { - let path = dtmt_cfg - .dir - .join(&dtmt_cfg.packages[0]) - .with_extension("package"); - - let data = { - let mut map = HashMap::new(); - map.insert("lua", vec![format!("scripts/mods/{}/*", dtmt_cfg.id)]); - map - }; - let data = serde_sjson::to_string(&data).wrap_err("Failed to serialize package file")?; - - fs::create_dir_all(path.parent().unwrap()) - .then(|_| fs::write(&path, &data)) - .await - .wrap_err_with(|| format!("Failed to write '{}'", path.display()))?; - - tracing::info!("Created package file at '{}'", path.display()); - } - - { - let path = in_dir.join("scripts"); - let scripts_dir = dtmt_cfg.dir.join("scripts"); - process_directory(&path, &scripts_dir) - .await - .wrap_err_with(|| { - format!( - "Failed to copy files from '{}' to '{}'", - path.display(), - scripts_dir.display() - ) - })?; - - tracing::info!("Copied script files to '{}'", scripts_dir.display()); - } - - Ok(()) -} diff --git a/crates/dtmt/src/cmd/new.rs b/crates/dtmt/src/cmd/new.rs index 9d69b74..187706c 100644 --- a/crates/dtmt/src/cmd/new.rs +++ b/crates/dtmt/src/cmd/new.rs @@ -1,75 +1,38 @@ +use std::collections::HashMap; use std::path::PathBuf; use clap::{Arg, ArgMatches, Command}; use color_eyre::eyre::{self, Context, Result}; use color_eyre::Help; use futures::{StreamExt, TryStreamExt}; -use minijinja::Environment; +use string_template::Template; use tokio::fs::{self, DirBuilder}; const TEMPLATES: [(&str, &str); 5] = [ ( "dtmt.cfg", - r#"// -// This is your mod's main configuration file. It tells DTMT how to build the mod, -// and DTMM what to display to your users. -// Certain files have been pre-filled by the template, the ones commented out (`//`) -// are optional. -// -// A unique identifier (preferably lower case, alphanumeric) -id = "{{id}}" -// The display name that your users will see. -// This doesn't have to be unique, but you still want to avoid being confused with other -// mods. + r#"id = "{{id}}" name = "{{name}}" -// It's good practice to increase this number whenever you publish changes. -// It's up to you if you use SemVer or something simpler like `1970-12-24`. It should sort and -// compare well, though. +description = "This is my new mod '{{name}}'!" version = "0.1.0" -// author = "" -// A one- or two-line short description. -summary = "This is my new mod '{{name}}'!" -// description = "" -// image = "assets/logo.png" - -// Can contain arbitrary strings. But to keep things consistent and useful, -// capitalize names and check existing mods for matching categories. -categories = [ - Misc - // UI - // QoL - // Tools -] - -// A list of mod IDs that this mod depends on. You can find -// those IDs by downloading the mod and extracting their `dtmt.cfg`. -// To make your fellow modders' lives easier, publish your own mods' IDs -// somewhere visible, such as the Nexusmods page. -depends = [ - DMF -] - -// The primary resources that serve as the entry point to your -// mod's code. Unless for very specific use cases, the generated -// values shouldn't be changed. resources = { init = "scripts/mods/{{id}}/init" data = "scripts/mods/{{id}}/data" localization = "scripts/mods/{{id}}/localization" } -// The list of packages, or bundles, to build. -// Each one corresponds to a package definition in the named folder. -// For mods that contain only code and/or a few small assets, a single -// package will suffice. packages = [ - "packages/mods/{{id}}" + "packages/{{id}}" +] + +depends = [ + "dmf" ] "#, ), ( - "packages/mods/{{id}}.package", + "packages/{{id}}.package", r#"lua = [ "scripts/mods/{{id}}/*" ] @@ -80,6 +43,7 @@ packages = [ r#"local mod = get_mod("{{id}}") -- Your mod code goes here. +-- https://vmf-docs.verminti.de "#, ), ( @@ -122,7 +86,7 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()> let root = if let Some(dir) = matches.get_one::("root") { if dir == "." { std::env::current_dir() - .wrap_err("The current working dir is invalid") + .wrap_err("the current working dir is invalid") .with_suggestion(|| "Change to a different directory.")? } else { PathBuf::from(dir) @@ -157,45 +121,34 @@ pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()> tracing::debug!(root = %root.display(), name, id); - let render_ctx = minijinja::context!(name => name.as_str(), id => id.as_str()); - let env = Environment::new(); + let mut data = HashMap::new(); + data.insert("name", name.as_str()); + data.insert("id", id.as_str()); let templates = TEMPLATES .iter() .map(|(path_tmpl, content_tmpl)| { - env.render_str(path_tmpl, &render_ctx) - .wrap_err_with(|| format!("Failed to render template: {path_tmpl}")) - .and_then(|path| { - env.render_named_str(&path, content_tmpl, &render_ctx) - .wrap_err_with(|| format!("Failed to render template '{}'", &path)) - .map(|content| (root.join(path), content)) - }) + let path = Template::new(path_tmpl).render(&data); + let content = Template::new(content_tmpl).render(&data); + + (root.join(path), content) }) - .map(|res| async move { - match res { - Ok((path, content)) => { - let dir = path - .parent() - .ok_or_else(|| eyre::eyre!("invalid root path"))?; + .map(|(path, content)| async move { + let dir = path + .parent() + .ok_or_else(|| eyre::eyre!("invalid root path"))?; - DirBuilder::new() - .recursive(true) - .create(&dir) - .await - .wrap_err_with(|| { - format!("Failed to create directory {}", dir.display()) - })?; + DirBuilder::new() + .recursive(true) + .create(&dir) + .await + .wrap_err_with(|| format!("failed to create directory {}", dir.display()))?; - tracing::trace!("Writing file {}", path.display()); + tracing::trace!("Writing file {}", path.display()); - fs::write(&path, content.as_bytes()) - .await - .wrap_err_with(|| { - format!("Failed to write content to path {}", path.display()) - }) - } - Err(e) => Err(e), - } + fs::write(&path, content.as_bytes()) + .await + .wrap_err_with(|| format!("failed to write content to path {}", path.display())) }); futures::stream::iter(templates) diff --git a/crates/dtmt/src/cmd/package.rs b/crates/dtmt/src/cmd/package.rs deleted file mode 100644 index 5ded885..0000000 --- a/crates/dtmt/src/cmd/package.rs +++ /dev/null @@ -1,147 +0,0 @@ -use std::io::{Cursor, Write}; -use std::path::{Path, PathBuf}; - -use clap::{value_parser, Arg, ArgMatches, Command}; -use color_eyre::eyre::{Context, Result}; -use color_eyre::Help; -use dtmt_shared::ModConfig; -use path_slash::{PathBufExt, PathExt}; -use tokio::fs; -use tokio_stream::wrappers::ReadDirStream; -use tokio_stream::StreamExt; -use zip::write::SimpleFileOptions; -use zip::ZipWriter; - -use crate::cmd::build::read_project_config; - -pub(crate) fn command_definition() -> Command { - Command::new("package") - .about("Package compiled bundles for distribution") - .arg( - Arg::new("project") - .required(false) - .value_parser(value_parser!(PathBuf)) - .help( - "The path to the project to build. \ - If omitted, dtmt will search from the current working directory upward.", - ), - ) - .arg( - Arg::new("directory") - .long("directory") - .short('d') - .default_value("out") - .value_parser(value_parser!(PathBuf)) - .help( - "The path to the directory were the compiled bundles were written to. \ - This is the same directory as `dtmt build -o`", - ), - ) - .arg( - Arg::new("out") - .long("out") - .short('o') - .value_parser(value_parser!(PathBuf)) - .help( - "The path to write the packaged file to. Will default to a file in the \ - current working directory", - ), - ) -} - -#[async_recursion::async_recursion] -async fn process_directory(zip: &mut ZipWriter, path: P1, prefix: P2) -> Result<()> -where - P1: AsRef + std::marker::Send, - P2: AsRef + std::marker::Send, - W: std::io::Write + std::io::Seek + std::marker::Send, -{ - let path = path.as_ref(); - let prefix = prefix.as_ref(); - - zip.add_directory(prefix.to_slash_lossy(), SimpleFileOptions::default())?; - - let read_dir = fs::read_dir(&path) - .await - .wrap_err_with(|| format!("Failed to read directory '{}'", path.display()))?; - - let stream = ReadDirStream::new(read_dir).map(|res| res.wrap_err("Failed to read dir entry")); - tokio::pin!(stream); - - while let Some(res) = stream.next().await { - let entry = res?; - let in_path = entry.path(); - let out_path = prefix.join(entry.file_name()); - - let t = entry.file_type().await?; - - if t.is_file() || t.is_symlink() { - let data = fs::read(&in_path) - .await - .wrap_err_with(|| format!("Failed to read '{}'", in_path.display()))?; - { - zip.start_file(out_path.to_slash_lossy(), SimpleFileOptions::default())?; - zip.write_all(&data)?; - } - } else if t.is_dir() { - process_directory(zip, in_path, out_path).await?; - } - } - - Ok(()) -} - -pub(crate) async fn package(cfg: &ModConfig, path: P1, dest: P2) -> Result<()> -where - P1: AsRef, - P2: AsRef, -{ - let path = path.as_ref(); - let dest = dest.as_ref(); - - let mut zip = ZipWriter::new(Cursor::new(Vec::with_capacity(1024))); - - process_directory(&mut zip, path, PathBuf::from(&cfg.id)) - .await - .wrap_err("Failed to add directory to archive")?; - - { - let name = PathBuf::from(&cfg.id).join("dtmt.cfg"); - let path = cfg.dir.join("dtmt.cfg"); - - let data = fs::read(&path) - .await - .wrap_err_with(|| format!("Failed to read mod config at {}", path.display()))?; - - zip.start_file(name.to_slash_lossy(), SimpleFileOptions::default())?; - zip.write_all(&data)?; - } - - let data = zip.finish()?; - - fs::write(dest, data.into_inner()) - .await - .wrap_err_with(|| format!("Failed to write mod archive to '{}'", dest.display())) - .with_suggestion(|| "Make sure that parent directories exist.".to_string())?; - - tracing::info!("Mod archive written to {}", dest.display()); - Ok(()) -} - -#[tracing::instrument(skip_all)] -pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { - let cfg = read_project_config(matches.get_one::("project").cloned()).await?; - - let dest = matches - .get_one::("out") - .map(path_clean::clean) - .unwrap_or_else(|| PathBuf::from(format!("{}.zip", cfg.id))); - - let path = cfg.dir.join( - matches - .get_one::("directory") - .expect("parameter has default value"), - ); - - package(&cfg, path, dest).await -} diff --git a/crates/dtmt/src/cmd/util.rs b/crates/dtmt/src/cmd/util.rs index c233425..c783ed1 100644 --- a/crates/dtmt/src/cmd/util.rs +++ b/crates/dtmt/src/cmd/util.rs @@ -8,7 +8,7 @@ use tokio::fs; use tokio_stream::wrappers::ReadDirStream; #[tracing::instrument] -pub async fn process_path

(path: P) -> Vec +pub async fn foo

(path: P) -> Vec where P: AsRef + std::fmt::Debug, { @@ -98,10 +98,7 @@ where I: Iterator + std::fmt::Debug, { let tasks = paths.map(|p| async move { - // Clippy doesn't understand that the block here is required to `move` in the reference. - // The task is spawned to make sure tokio can distribute these over threads. - #[allow(clippy::redundant_async_block)] - match tokio::spawn(async move { process_path(&p).await }).await { + match tokio::spawn(async move { foo(&p).await }).await { Ok(paths) => paths, Err(err) => { tracing::error!(%err, "failed to spawn task to resolve bundle paths"); @@ -114,9 +111,6 @@ where results.into_iter().flatten().collect() } -// `tracing::instrument` generates code that triggers this warning. -// Not much we can do to prevent that. -#[allow(clippy::let_with_type_underscore)] #[tracing::instrument(skip_all)] pub fn resolve_bundle_paths(paths: I) -> impl Stream where @@ -135,12 +129,12 @@ mod tests { use tempfile::tempdir; use tokio::process::Command; - use super::process_path; + use super::foo; #[tokio::test] async fn resolve_single_file() { let path = PathBuf::from("foo"); - let paths = process_path(&path).await; + let paths = foo(&path).await; assert_eq!(paths.len(), 1); assert_eq!(paths[0], path); } @@ -148,7 +142,7 @@ mod tests { #[tokio::test] async fn resolve_empty_directory() { let dir = tempdir().expect("failed to create temporary directory"); - let paths = process_path(dir).await; + let paths = foo(dir).await; assert!(paths.is_empty()); } @@ -176,7 +170,7 @@ mod tests { .await .expect("failed to create temporary files"); - let paths = process_path(dir).await; + let paths = foo(dir).await; assert_eq!(bundle_names.len(), paths.len()); diff --git a/crates/dtmt/src/cmd/watch.rs b/crates/dtmt/src/cmd/watch.rs index 2abd0f7..508cef9 100644 --- a/crates/dtmt/src/cmd/watch.rs +++ b/crates/dtmt/src/cmd/watch.rs @@ -1,231 +1,24 @@ -use std::path::{Path, PathBuf}; -use std::sync::Arc; -use std::time::Duration; +use std::path::PathBuf; -use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; -use color_eyre::eyre::{Context, Result}; -use dtmt_shared::ModConfig; -use notify::{Event, Watcher}; +use clap::{value_parser, Arg, ArgMatches, Command}; +use color_eyre::eyre::Result; -use crate::cmd::build::{build, read_project_config}; - -use super::package::package; - -pub(crate) fn command_definition() -> Command { +pub(crate) fn _command_definition() -> Command { Command::new("watch") - .about("Watch for file system changes and re-build the mod archive.") - .arg( - Arg::new("debounce") - .long("debounce") - .short('b') - .default_value("150") - .value_parser(value_parser!(u64)) - .help( - "The delay to debounce events by. This avoids continously \ - rebuilding on rapid file changes, such as version control checkouts.", - ), - ) + .about("Re-build the given directory on file changes.") .arg( Arg::new("directory") .required(false) + .default_value(".") .value_parser(value_parser!(PathBuf)) .help( "The path to the project to build. \ - If omitted, the current working directory is used.", + If omitted, the current working directory is used.", ), ) - .arg( - Arg::new("out") - .long("out") - .short('o') - .default_value("out") - .value_parser(value_parser!(PathBuf)) - .help("The directory to write output files to."), - ) - .arg( - Arg::new("deploy") - .long("deploy") - .short('d') - .value_parser(value_parser!(PathBuf)) - .help( - "If the path to the game (without the trailing '/bundle') is specified, \ - deploy the newly built bundles. \ - This will not adjust the bundle database or package files, so if files are \ - added or removed, you will have to import into DTMM and re-deploy there.", - ), - ) - .arg( - Arg::new("archive") - .long("archive") - .short('a') - .value_parser(value_parser!(PathBuf)) - .help( - "The path to write the packaged file to. Will default to a file in the \ - current working directory", - ), - ) - .arg( - Arg::new("ignore") - .long("ignore") - .short('i') - .value_parser(value_parser!(PathBuf)) - .action(ArgAction::Append) - .help( - "A directory or file path to ignore. May be specified multiple times. \ - The values of 'out' and 'archive' are ignored automatically.", - ), - ) -} - -#[tracing::instrument] -async fn compile( - cfg: &ModConfig, - out_path: impl AsRef + std::fmt::Debug, - archive_path: impl AsRef + std::fmt::Debug, - game_dir: Arc + std::fmt::Debug>>, -) -> Result<()> { - let out_path = out_path.as_ref(); - build(cfg, out_path, game_dir) - .await - .wrap_err("Failed to build bundles")?; - package(cfg, out_path, archive_path) - .await - .wrap_err("Failed to package bundles") } #[tracing::instrument(skip_all)] -pub(crate) async fn run(_ctx: sdk::Context, matches: &ArgMatches) -> Result<()> { - let cfg = read_project_config(matches.get_one::("directory").cloned()) - .await - .wrap_err("failed to load project config")?; - tracing::debug!(?cfg); - let cfg = Arc::new(cfg); - - let game_dir = matches - .get_one::("deploy") - .map(path_clean::clean) - .map(|p| if p.is_absolute() { p } else { cfg.dir.join(p) }) - .map(|p| p.join("bundle")); - - let out_path = matches - .get_one::("out") - .map(path_clean::clean) - .map(|p| if p.is_absolute() { p } else { cfg.dir.join(p) }) - .expect("parameter should have default value"); - - let archive_path = matches - .get_one::("archive") - .map(path_clean::clean) - .map(|p| if p.is_absolute() { p } else { cfg.dir.join(p) }) - .unwrap_or_else(|| cfg.dir.join(format!("{}.zip", cfg.id))); - - let ignored = { - let mut ignored: Vec<_> = matches - .get_many::("ignore") - .unwrap_or_default() - .map(path_clean::clean) - .map(|p| if p.is_absolute() { p } else { cfg.dir.join(p) }) - .collect(); - - ignored.push(out_path.clone()); - ignored.push(archive_path.clone()); - - ignored - }; - - if tracing::enabled!(tracing::Level::INFO) { - let list = ignored.iter().fold(String::new(), |mut s, p| { - s.push_str("\n - "); - s.push_str(&p.display().to_string()); - s - }); - - tracing::info!("Ignoring:{}", list); - } - - let game_dir = Arc::new(game_dir); - - let duration = - Duration::from_millis(matches.get_one::("debounce").copied().unwrap_or(150)); - let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); - - let mut watcher = notify::recommended_watcher(move |res: Result| { - let ignored = match &res { - Ok(evt) => evt.paths.iter().any(|p1| { - let p1 = path_clean::clean(p1); - ignored.iter().any(|p2| p1.starts_with(p2)) - }), - Err(_) => false, - }; - - tracing::trace!(?res, ignored, "Received file system event"); - - if !ignored { - if let Err(err) = tx.send(res) { - tracing::error!("Failed to send file system event: {:?}", err); - } - } - }) - .wrap_err("failed to create file system watcher")?; - - tracing::info!("Starting file watcher on '{}'", cfg.dir.display()); - - let path = cfg.dir.clone(); - watcher - .watch(&path, notify::RecursiveMode::Recursive) - .wrap_err_with(|| { - format!( - "failed to watch directory for file changes: {}", - path.display() - ) - })?; - - tracing::trace!("Starting debounce loop"); - - let mut dirty = false; - loop { - // While we could just always await on the timeout, splitting things like this - // optimizes the case when no events happen for a while. Rather than being woken every - // `duration` just to do nothing, this way we always wait for a new event first until - // we start the debounce timeouts. - if dirty { - match tokio::time::timeout(duration, rx.recv()).await { - // The error is the wanted case, as it signals that we haven't received an - // event within `duration`, which es what the debounce is supposed to wait for. - Err(_) => { - tracing::trace!("Received debounce timeout, running build"); - if let Err(err) = - compile(&cfg, &out_path, &archive_path, game_dir.clone()).await - { - tracing::error!("Failed to build mod archive: {:?}", err); - } - dirty = false; - } - Ok(None) => { - break; - } - // We received a value before the timeout, so we reset it - Ok(_) => { - tracing::trace!("Received value before timeout, resetting"); - } - } - } else { - match rx.recv().await { - Some(_) => { - tracing::trace!("Received event, starting debounce"); - dirty = true; - } - None => { - break; - } - } - } - } - - tracing::trace!("Event channel closed"); - if let Err(err) = compile(&cfg, &out_path, &archive_path, game_dir.clone()).await { - tracing::error!("Failed to build mod archive: {:?}", err); - } - - Ok(()) +pub(crate) async fn run(_ctx: sdk::Context, _matches: &ArgMatches) -> Result<()> { + unimplemented!() } diff --git a/crates/dtmt/src/main.rs b/crates/dtmt/src/main.rs index e2cb718..dc4853e 100644 --- a/crates/dtmt/src/main.rs +++ b/crates/dtmt/src/main.rs @@ -1,7 +1,5 @@ #![feature(io_error_more)] #![feature(let_chains)] -#![feature(test)] -#![windows_subsystem = "console"] use std::path::PathBuf; use std::sync::Arc; @@ -11,7 +9,6 @@ use clap::value_parser; use clap::{command, Arg}; use color_eyre::eyre; use color_eyre::eyre::{Context, Result}; -use sdk::murmur::Dictionary; use serde::{Deserialize, Serialize}; use tokio::fs::File; use tokio::io::BufReader; @@ -21,14 +18,15 @@ mod cmd { pub mod build; pub mod bundle; pub mod dictionary; - pub mod migrate; pub mod murmur; pub mod new; - pub mod package; mod util; pub mod watch; } -mod shell_parse; + +mod mods { + pub mod archive; +} #[derive(Default, Deserialize, Serialize)] struct GlobalConfig { @@ -36,21 +34,10 @@ struct GlobalConfig { } #[tokio::main] -#[tracing::instrument(level = "error", fields(cmd_line = tracing::field::Empty))] +#[tracing::instrument] async fn main() -> Result<()> { color_eyre::install()?; - { - let span = tracing::Span::current(); - if !span.is_disabled() { - let cmdline: String = std::env::args_os().fold(String::new(), |mut s, arg| { - s.push_str(&arg.to_string_lossy()); - s - }); - span.record("cmd_line", cmdline); - } - } - let matches = command!() .subcommand_required(true) .arg( @@ -67,11 +54,9 @@ async fn main() -> Result<()> { .subcommand(cmd::build::command_definition()) .subcommand(cmd::bundle::command_definition()) .subcommand(cmd::dictionary::command_definition()) - .subcommand(cmd::migrate::command_definition()) .subcommand(cmd::murmur::command_definition()) .subcommand(cmd::new::command_definition()) - .subcommand(cmd::package::command_definition()) - .subcommand(cmd::watch::command_definition()) + // .subcommand(cmd::watch::command_definition()) .get_matches(); dtmt_shared::create_tracing_subscriber(); @@ -91,7 +76,7 @@ async fn main() -> Result<()> { tokio::spawn(async move { let res = File::open(&path) .await - .wrap_err_with(|| format!("Failed to open dictionary file: {}", path.display())); + .wrap_err_with(|| format!("failed to open dictionary file: {}", path.display())); let f = match res { Ok(f) => f, @@ -107,9 +92,8 @@ async fn main() -> Result<()> { let r = BufReader::new(f); let mut ctx = ctx.write().await; - match Dictionary::from_csv(r).await { - Ok(lookup) => ctx.lookup = Arc::new(lookup), - Err(err) => tracing::error!("{:#}", err), + if let Err(err) = ctx.lookup.from_csv(r).await { + tracing::error!("{:#}", err); } }) }; @@ -119,7 +103,7 @@ async fn main() -> Result<()> { tokio::spawn(async move { let conf = tokio::task::spawn_blocking(|| { confy::load::(clap::crate_name!(), None) - .wrap_err("Failed to load global configuration") + .wrap_err("failed to load global configuration") }) .await; @@ -142,14 +126,12 @@ async fn main() -> Result<()> { }; match matches.subcommand() { - Some(("build", sub_matches)) => cmd::build::run(ctx, sub_matches).await?, Some(("bundle", sub_matches)) => cmd::bundle::run(ctx, sub_matches).await?, - Some(("dictionary", sub_matches)) => cmd::dictionary::run(ctx, sub_matches).await?, - Some(("migrate", sub_matches)) => cmd::migrate::run(ctx, sub_matches).await?, Some(("murmur", sub_matches)) => cmd::murmur::run(ctx, sub_matches).await?, Some(("new", sub_matches)) => cmd::new::run(ctx, sub_matches).await?, - Some(("package", sub_matches)) => cmd::package::run(ctx, sub_matches).await?, + Some(("build", sub_matches)) => cmd::build::run(ctx, sub_matches).await?, Some(("watch", sub_matches)) => cmd::watch::run(ctx, sub_matches).await?, + Some(("dictionary", sub_matches)) => cmd::dictionary::run(ctx, sub_matches).await?, _ => unreachable!( "clap is configured to require a subcommand, and they're all handled above" ), diff --git a/crates/dtmt/src/mods/archive.rs b/crates/dtmt/src/mods/archive.rs new file mode 100644 index 0000000..37fec19 --- /dev/null +++ b/crates/dtmt/src/mods/archive.rs @@ -0,0 +1,98 @@ +use std::collections::{HashMap, HashSet}; +use std::fs::File; +use std::io::Write; +use std::path::{Path, PathBuf}; + +use color_eyre::eyre::{self, Context}; +use color_eyre::Result; +use sdk::murmur::IdString64; +use sdk::Bundle; +use zip::ZipWriter; + +pub struct Archive { + name: String, + bundles: Vec, + config_file: Option>, +} + +impl Archive { + pub fn new(name: String) -> Self { + Self { + name, + bundles: Vec::new(), + config_file: None, + } + } + + pub fn add_bundle(&mut self, bundle: Bundle) { + self.bundles.push(bundle) + } + + pub fn add_config(&mut self, content: Vec) { + self.config_file = Some(content); + } + + pub fn write

(&self, path: P) -> Result<()> + where + P: AsRef, + { + let config_file = self + .config_file + .as_ref() + .ok_or_else(|| eyre::eyre!("Config file is missing in mod archive"))?; + + let f = File::create(path.as_ref()).wrap_err_with(|| { + format!( + "failed to open file for reading: {}", + path.as_ref().display() + ) + })?; + let mut zip = ZipWriter::new(f); + + zip.add_directory(&self.name, Default::default())?; + + let base_path = PathBuf::from(&self.name); + + { + let name = base_path.join("dtmt.cfg"); + zip.start_file(name.to_string_lossy(), Default::default())?; + zip.write_all(config_file)?; + } + + let mut file_map = HashMap::new(); + + for bundle in self.bundles.iter() { + let bundle_name = match bundle.name() { + IdString64::Hash(_) => eyre::bail!("bundle name must be known as string. got hash"), + IdString64::String(s) => s, + }; + + let map_entry: &mut HashSet<_> = file_map.entry(bundle_name).or_default(); + + for file in bundle.files() { + map_entry.insert(file.name(false, None)); + } + + let name = bundle.name().to_murmur64(); + let path = base_path.join(name.to_string().to_ascii_lowercase()); + + zip.start_file(path.to_string_lossy(), Default::default())?; + + let data = bundle.to_binary()?; + zip.write_all(&data)?; + } + + { + let data = serde_sjson::to_string(&file_map)?; + zip.start_file( + base_path.join("files.sjson").to_string_lossy(), + Default::default(), + )?; + zip.write_all(data.as_bytes())?; + } + + zip.finish()?; + + Ok(()) + } +} diff --git a/crates/dtmt/src/shell_parse.rs b/crates/dtmt/src/shell_parse.rs deleted file mode 100644 index 13b3c4d..0000000 --- a/crates/dtmt/src/shell_parse.rs +++ /dev/null @@ -1,183 +0,0 @@ -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -enum ParserState { - Start, - Word, - SingleQuote, - DoubleQuote, -} - -pub struct ShellParser<'a> { - bytes: &'a [u8], - offset: usize, - pub errored: bool, -} - -impl<'a> ShellParser<'a> { - pub fn new(bytes: &'a [u8]) -> Self { - Self { - bytes, - offset: 0, - errored: false, - } - } - - fn parse_word(&mut self) -> Option<&'a [u8]> { - // The start of the current word. Certain leading characters should be ignored, - // so this might change. - let mut start = self.offset; - let mut state = ParserState::Start; - - while self.offset < self.bytes.len() { - let c = self.bytes[self.offset]; - self.offset += 1; - - match state { - ParserState::Start => match c { - // Ignore leading whitespace - b' ' | b'\t' | b'\n' => start += 1, - b'\'' => { - state = ParserState::SingleQuote; - start += 1; - } - b'"' => { - state = ParserState::DoubleQuote; - start += 1; - } - _ => { - state = ParserState::Word; - } - }, - ParserState::Word => match c { - // Unquoted whitespace ends the current word - b' ' | b'\t' | b'\n' => { - return Some(&self.bytes[start..self.offset - 1]); - } - _ => {} - }, - ParserState::SingleQuote => if c == b'\'' { - return Some(&self.bytes[start..(self.offset - 1)]); - }, - ParserState::DoubleQuote => if c == b'"' { - return Some(&self.bytes[start..(self.offset - 1)]); - }, - } - } - - match state { - ParserState::Start => None, - ParserState::Word => Some(&self.bytes[start..self.offset]), - ParserState::SingleQuote | ParserState::DoubleQuote => { - self.errored = true; - None - } - } - } -} - -impl<'a> Iterator for ShellParser<'a> { - type Item = &'a [u8]; - - fn next(&mut self) -> Option { - self.parse_word() - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_one_word() { - let mut it = ShellParser::new(b"hello"); - assert_eq!(it.next(), Some("hello".as_bytes())); - assert_eq!(it.next(), None); - } - - #[test] - fn test_one_single() { - let mut it = ShellParser::new(b"'hello'"); - assert_eq!(it.next(), Some("hello".as_bytes())); - assert_eq!(it.next(), None); - } - - #[test] - fn test_open_quote() { - let mut it = ShellParser::new(b"'hello"); - assert_eq!(it.next(), None); - assert!(it.errored) - } - - #[test] - fn test_ww2ogg() { - let mut it = ShellParser::new( - b"ww2ogg.exe --pcb \"/usr/share/ww2ogg/packed_cookbook_aoTuV_603.bin\"", - ); - assert_eq!(it.next(), Some("ww2ogg.exe".as_bytes())); - assert_eq!(it.next(), Some("--pcb".as_bytes())); - assert_eq!( - it.next(), - Some("/usr/share/ww2ogg/packed_cookbook_aoTuV_603.bin".as_bytes()) - ); - assert_eq!(it.next(), None); - } -} - -#[cfg(test)] -mod bench { - extern crate test; - - use super::*; - #[cfg(feature = "shlex-bench")] - use shlex::bytes::Shlex; - use test::Bencher; - - mod ww2ogg { - use super::*; - - #[bench] - fn custom(b: &mut Bencher) { - let val = test::black_box( - b"ww2ogg.exe --pcb \"/usr/share/ww2ogg/packed_cookbook_aoTuV_603.bin\"", - ); - b.iter(|| { - let it = ShellParser::new(val); - let _: Vec<_> = test::black_box(it.collect()); - }) - } - - #[cfg(feature = "shlex-bench")] - #[bench] - fn shlex(b: &mut Bencher) { - let val = test::black_box( - b"ww2ogg.exe --pcb \"/usr/share/ww2ogg/packed_cookbook_aoTuV_603.bin\"", - ); - b.iter(|| { - let it = Shlex::new(val); - let _: Vec<_> = test::black_box(it.collect()); - }) - } - } - - mod one_single { - use super::*; - - #[bench] - fn custom(b: &mut Bencher) { - let val = test::black_box(b"'hello'"); - b.iter(|| { - let it = ShellParser::new(val); - let _: Vec<_> = test::black_box(it.collect()); - }) - } - - #[cfg(feature = "shlex-bench")] - #[bench] - fn shlex(b: &mut Bencher) { - let val = test::black_box(b"'hello'"); - b.iter(|| { - let it = Shlex::new(val); - let _: Vec<_> = test::black_box(it.collect()); - }) - } - } -} diff --git a/docs/screenshots/dtmm.png b/docs/screenshots/dtmm.png index d51c253..af2a980 100644 Binary files a/docs/screenshots/dtmm.png and b/docs/screenshots/dtmm.png differ diff --git a/lib/ansi-parser b/lib/ansi-parser deleted file mode 160000 index 27beb4b..0000000 --- a/lib/ansi-parser +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 27beb4bc1ffd2865a432e13f0588b5351ff419bf diff --git a/lib/color-eyre b/lib/color-eyre deleted file mode 160000 index bdefeef..0000000 --- a/lib/color-eyre +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bdefeef09803df45bdf6dae7f3ae289e58427e3a diff --git a/lib/dtmt-shared/Cargo.toml b/lib/dtmt-shared/Cargo.toml index 26e1b6a..0f8ed63 100644 --- a/lib/dtmt-shared/Cargo.toml +++ b/lib/dtmt-shared/Cargo.toml @@ -6,11 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ansi_term = { workspace = true } -color-eyre = { workspace = true } -serde = { workspace = true } -steamlocate = { workspace = true } -time = { workspace = true } -tracing = { workspace = true } -tracing-error = { workspace = true } -tracing-subscriber = { workspace = true } +serde = "1.0.152" +time = { version = "0.3.19", features = ["formatting", "local-offset", "macros"] } +tracing = "0.1.37" +tracing-error = "0.2.0" +tracing-subscriber = "0.3.16" diff --git a/lib/dtmt-shared/src/lib.rs b/lib/dtmt-shared/src/lib.rs index db11579..3c8690d 100644 --- a/lib/dtmt-shared/src/lib.rs +++ b/lib/dtmt-shared/src/lib.rs @@ -1,102 +1,28 @@ -use std::collections::HashMap; -use std::path::PathBuf; +mod log; -use color_eyre::eyre::{OptionExt as _, WrapErr as _}; -use color_eyre::Result; -use serde::{Deserialize, Serialize}; -use steamlocate::SteamDir; -use time::OffsetDateTime; +use std::path::PathBuf; pub use log::*; -mod log; - -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, serde::Deserialize)] pub struct ModConfigResources { pub init: PathBuf, - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(default)] pub data: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] + #[serde(default)] pub localization: Option, } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] -pub enum ModOrder { - Before, - After, -} - -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] -#[serde(untagged)] -pub enum ModDependency { - ID(String), - Config { id: String, order: ModOrder }, -} - -// A bit dumb, but serde doesn't support literal values with the -// `default` attribute, only paths. -fn default_true() -> bool { - true -} - -// Similarly dumb, as the `skip_serializing_if` attribute needs a function -fn is_true(val: &bool) -> bool { - *val -} - -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, serde::Deserialize)] pub struct ModConfig { #[serde(skip)] - pub dir: PathBuf, + pub dir: std::path::PathBuf, pub id: String, pub name: String, - pub summary: String, + pub description: String, pub version: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub description: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub author: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub image: Option, - #[serde(default)] - pub categories: Vec, - #[serde(default)] - pub packages: Vec, + pub packages: Vec, pub resources: ModConfigResources, #[serde(default)] - pub depends: Vec, - #[serde(default = "default_true", skip_serializing_if = "is_true")] - pub bundled: bool, - #[serde(default)] - pub name_overrides: HashMap, -} - -pub const STEAMAPP_ID: u32 = 1361210; - -#[derive(Debug)] -pub struct GameInfo { - pub path: PathBuf, - pub last_updated: OffsetDateTime, -} - -pub fn collect_game_info() -> Result> { - let dir = SteamDir::locate().wrap_err("Failed to locate Steam installation")?; - - let found = dir - .find_app(STEAMAPP_ID) - .wrap_err("Failed to look up game by Steam app ID")?; - - let Some((app, library)) = found else { - return Ok(None); - }; - - let last_updated = app - .last_updated - .ok_or_eyre("Missing field 'last_updated'")?; - - Ok(Some(GameInfo { - path: library.path().join(app.install_dir), - last_updated: last_updated.into(), - })) + pub depends: Vec, } diff --git a/lib/dtmt-shared/src/log.rs b/lib/dtmt-shared/src/log.rs index e5afc6c..3c46a4b 100644 --- a/lib/dtmt-shared/src/log.rs +++ b/lib/dtmt-shared/src/log.rs @@ -1,11 +1,10 @@ use std::fmt::Result; -use ansi_term::Color; use time::format_description::FormatItem; use time::macros::format_description; use time::OffsetDateTime; use tracing::field::Field; -use tracing::{Event, Level, Metadata, Subscriber}; +use tracing::{Event, Metadata, Subscriber}; use tracing_error::ErrorLayer; use tracing_subscriber::filter::FilterFn; use tracing_subscriber::fmt::format::{debug_fn, Writer}; @@ -19,7 +18,7 @@ pub const TIME_FORMAT: &[FormatItem] = format_description!("[hour]:[minute]:[sec pub fn format_fields(w: &mut Writer<'_>, field: &Field, val: &dyn std::fmt::Debug) -> Result { if field.name() == "message" { - write!(w, "{val:?}") + write!(w, "{:?}", val) } else { Ok(()) } @@ -50,28 +49,7 @@ where let time = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc()); let time = time.format(TIME_FORMAT).map_err(|_| std::fmt::Error)?; - let level = meta.level(); - // Sadly, tracing's `Level` is a struct, not an enum, so we can't properly `match` it. - let color = if *level == Level::TRACE { - Color::Purple - } else if *level == Level::DEBUG { - Color::Blue - } else if *level == Level::INFO { - Color::Green - } else if *level == Level::WARN { - Color::Yellow - } else if *level == Level::ERROR { - Color::Red - } else { - unreachable!() - }; - - write!( - writer, - "[{}] [{:>5}] ", - time, - color.bold().paint(format!("{level}")) - )?; + write!(writer, "[{}] [{:>5}] ", time, meta.level())?; ctx.field_format().format_fields(writer.by_ref(), event)?; @@ -84,7 +62,7 @@ pub fn create_tracing_subscriber() { EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::try_new("info").unwrap()); let (dev_stdout_layer, prod_stdout_layer, filter_layer) = if cfg!(debug_assertions) { - let fmt_layer = fmt::layer().pretty().with_writer(std::io::stderr); + let fmt_layer = fmt::layer().pretty(); (Some(fmt_layer), None, None) } else { // Creates a layer that @@ -93,7 +71,6 @@ pub fn create_tracing_subscriber() { // - does not print spans/targets // - only prints time, not date let fmt_layer = fmt::layer() - .with_writer(std::io::stderr) .event_format(Formatter) .fmt_fields(debug_fn(format_fields)); diff --git a/lib/luajit2-sys/Cargo.toml b/lib/luajit2-sys/Cargo.toml deleted file mode 100644 index 65dd61a..0000000 --- a/lib/luajit2-sys/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "luajit2-sys" -version = "0.0.2" -description = "LuaJIT-2.1 FFI Bindings" -authors = ["Aaron Loucks "] -edition = "2021" -keywords = ["lua", "luajit", "script"] -license = "MIT OR Apache-2.0" -readme = "README.md" -repository = "https://github.com/aloucks/luajit2-sys" -documentation = "https://docs.rs/luajit2-sys" -links = "luajit" - -[dependencies] -libc = { workspace = true } - -[build-dependencies] -bindgen = { workspace = true } -cc = { workspace = true } -fs_extra = { workspace = true } diff --git a/lib/luajit2-sys/LICENSE-APACHE b/lib/luajit2-sys/LICENSE-APACHE deleted file mode 100644 index f007b81..0000000 --- a/lib/luajit2-sys/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - https://www.apache.org/licenses/LICENSE-2.0 - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://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. \ No newline at end of file diff --git a/lib/luajit2-sys/LICENSE-MIT b/lib/luajit2-sys/LICENSE-MIT deleted file mode 100644 index 468cd79..0000000 --- a/lib/luajit2-sys/LICENSE-MIT +++ /dev/null @@ -1,23 +0,0 @@ -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. \ No newline at end of file diff --git a/lib/luajit2-sys/build.rs b/lib/luajit2-sys/build.rs deleted file mode 100644 index ea6026b..0000000 --- a/lib/luajit2-sys/build.rs +++ /dev/null @@ -1,217 +0,0 @@ -use cc::Build; -use fs_extra::dir; -use fs_extra::dir::CopyOptions; -use std::env; -use std::path::PathBuf; -use std::process::{Command, Stdio}; - -const LIB_NAME: &str = "luajit"; -const LUAJIT_HEADERS: [&str; 4] = ["lua.h", "lualib.h", "lauxlib.h", "luajit.h"]; -const LUAJIT_SRC: [&str; 65] = [ - // LJCORE_O - // The MSVC toolchain cannot compile this assembler file, - // as it contains GNU-specific directives - // "lj_vm.S", - "lj_gc.c", - "lj_err.c", - "lj_char.c", - "lj_bc.c", - "lj_obj.c", - "lj_buf.c", - "lj_str.c", - "lj_tab.c", - "lj_func.c", - "lj_udata.c", - "lj_meta.c", - "lj_debug.c", - "lj_state.c", - "lj_dispatch.c", - "lj_vmevent.c", - "lj_vmmath.c", - "lj_strscan.c", - "lj_strfmt.c", - "lj_strfmt_num.c", - "lj_api.c", - "lj_profile.c", - "lj_lex.c", - "lj_parse.c", - "lj_bcread.c", - "lj_bcwrite.c", - "lj_load.c", - "lj_ir.c", - "lj_opt_mem.c", - "lj_opt_fold.c", - "lj_opt_narrow.c", - "lj_opt_dce.c", - "lj_opt_loop.c", - "lj_opt_split.c", - "lj_opt_sink.c", - "lj_mcode.c", - "lj_snap.c", - "lj_record.c", - "lj_crecord.c", - "lj_ffrecord.c", - "lj_asm.c", - "lj_trace.c", - "lj_gdbjit.c", - "lj_ctype.c", - "lj_cdata.c", - "lj_cconv.c", - "lj_ccall.c", - "lj_ccallback.c", - "lj_carith.c", - "lj_clib.c", - "lj_cparse.c", - "lj_lib.c", - "lj_alloc.c", - // LJLIB_O - "lib_aux.c", - "lib_base.c", - "lib_math.c", - "lib_bit.c", - "lib_string.c", - "lib_table.c", - "lib_io.c", - "lib_os.c", - "lib_package.c", - "lib_debug.c", - "lib_jit.c", - "lib_ffi.c", - "lib_init.c", -]; - -fn build_gcc(src_dir: &str) { - let mut buildcmd = Command::new("make"); - if let Ok(flags) = env::var("CARGO_MAKEFLAGS") { - buildcmd.env("MAKEFLAGS", flags); - } else { - buildcmd.arg("-j8"); - } - buildcmd.current_dir(src_dir); - buildcmd.stderr(Stdio::inherit()); - buildcmd.arg("--no-silent"); - - // We do need to cross-compile even here, so that `lj_vm.o` is created - // for the correct architecture. - if env::var("CARGO_CFG_WINDOWS").is_ok() { - buildcmd.arg("TARGET_SYS=Windows"); - buildcmd.arg("CROSS=x86_64-w64-mingw32-"); - } - - if cfg!(target_pointer_width = "32") { - buildcmd.arg("HOST_CC='gcc -m32'"); - buildcmd.arg("-e"); - } else { - buildcmd.arg("HOST_CC='gcc'"); - } - - let mut child = buildcmd.spawn().expect("failed to run make"); - - child - .wait() - .map(|status| status.success()) - .expect("Failed to build LuaJIT"); -} - -fn build_msvc(src_dir: &str, out_dir: &str) { - let mut cc = Build::new(); - // cc can't handle many of the `clang-dl`-specific flags, so - // we need to port them manually from a `make -n` run. - cc.out_dir(out_dir) - // `llvm-as` (which the clang-based toolchain for MSVC would use to compile `lj_vm.S` - // assembler) doesn't support some of the GNU-specific directives. - // However, the previous host-targeted compilation already created the - // object, so we simply link that. - .object(format!("{src_dir}/lj_vm.o")) - .define("_FILE_OFFSET_BITS", "64") - .define("_LARGEFILE_SOURCE", None) - .define("LUA_MULTILIB", "\"lib\"") - .define("LUAJIT_UNWIND_EXTERNAL", None) - .flag("-fcolor-diagnostics") - // Disable warnings - .flag("/W0") - .flag("/U _FORTIFY_SOURCE") - // Link statically - .flag("/MT") - // Omit frame pointers - .flag("/Oy"); - - for f in LUAJIT_SRC { - cc.file(format!("{src_dir}/{f}")); - } - - cc.compile(LIB_NAME); -} - -fn main() { - let luajit_dir = format!("{}/luajit", env!("CARGO_MANIFEST_DIR")); - let out_dir = env::var("OUT_DIR").unwrap(); - let src_dir = format!("{out_dir}/luajit/src"); - - dbg!(&luajit_dir); - dbg!(&out_dir); - dbg!(&src_dir); - - let mut copy_options = CopyOptions::new(); - copy_options.overwrite = true; - - dir::copy(&luajit_dir, &out_dir, ©_options).expect("Failed to copy LuaJIT source"); - - // The first run builds with and for the host architecture. - // This also creates all the tools and generated sources that a compilation needs. - build_gcc(&src_dir); - - // Then, for cross-compilation, we can utilize those generated - // sources to re-compile just the library. - if env::var("CARGO_CFG_WINDOWS").is_ok() { - build_msvc(&src_dir, &out_dir); - println!("cargo:rustc-link-search={out_dir}"); - } else { - println!("cargo:rustc-link-search=native={src_dir}"); - } - - println!("cargo:lib-name={LIB_NAME}"); - println!("cargo:include={src_dir}"); - println!("cargo:rustc-link-lib=static={LIB_NAME}"); - - let mut bindings = bindgen::Builder::default(); - - for header in LUAJIT_HEADERS { - println!("cargo:rerun-if-changed={luajit_dir}/src/{header}"); - bindings = bindings.header(format!("{luajit_dir}/src/{header}")); - } - - let bindings = bindings - .allowlist_var("LUA.*") - .allowlist_var("LUAJIT.*") - .allowlist_type("lua_.*") - .allowlist_type("luaL_.*") - .allowlist_function("lua_.*") - .allowlist_function("luaL_.*") - .allowlist_function("luaJIT.*") - .ctypes_prefix("libc") - .impl_debug(true) - .use_core() - .detect_include_paths(true) - .formatter(bindgen::Formatter::Rustfmt) - .sort_semantically(true) - .merge_extern_blocks(true) - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())); - - let bindings = if env::var("CARGO_CFG_WINDOWS").is_ok() { - bindings - .clang_arg("-I/xwin/sdk/include/ucrt") - .clang_arg("-I/xwin/sdk/include/um") - .clang_arg("-I/xwin/sdk/include/shared") - .clang_arg("-I/xwin/crt/include") - .generate() - .expect("Failed to generate bindings") - } else { - bindings.generate().expect("Failed to generate bindings") - }; - - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); - bindings - .write_to_file(out_path.join("bindings.rs")) - .expect("Failed to write bindings"); -} diff --git a/lib/luajit2-sys/luajit b/lib/luajit2-sys/luajit deleted file mode 160000 index 70f4b15..0000000 --- a/lib/luajit2-sys/luajit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 70f4b15ee45a6137fe6b48b941faea79d72f7159 diff --git a/lib/luajit2-sys/src/lib.rs b/lib/luajit2-sys/src/lib.rs deleted file mode 100644 index c48ca06..0000000 --- a/lib/luajit2-sys/src/lib.rs +++ /dev/null @@ -1,167 +0,0 @@ -#![no_std] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] -#![allow(clippy::deprecated_semver)] -#![allow(clippy::missing_safety_doc)] - -//! # LuaJIT 2.1 -//! -//! -//! -//! -//! -//! ## Performance considerations -//! -//! The _Not Yet Implemented_ guide documents which language features will be JIT compiled -//! into native machine code. -//! -//! - -mod ffi { - include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -} -pub use ffi::*; - -use core::ptr; - -// These are defined as macros - -/// -#[inline] -pub unsafe fn lua_pop(L: *mut lua_State, idx: libc::c_int) { - lua_settop(L, -(idx) - 1) -} - -/// -#[inline] -pub unsafe fn lua_newtable(L: *mut lua_State) { - lua_createtable(L, 0, 0) -} - -/// -#[inline] -pub unsafe fn lua_register(L: *mut lua_State, name: *const libc::c_char, f: lua_CFunction) { - lua_pushcfunction(L, f); - lua_setglobal(L, name); -} - -/// -#[inline] -pub unsafe fn lua_pushcfunction(L: *mut lua_State, f: lua_CFunction) { - lua_pushcclosure(L, f, 0); -} - -/// -#[inline] -pub unsafe fn lua_strlen(L: *mut lua_State, idx: libc::c_int) -> usize { - lua_objlen(L, idx) -} - -/// -#[inline] -pub unsafe fn lua_isfunction(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) == LUA_TFUNCTION as i32) as i32 -} - -/// -#[inline] -pub unsafe fn lua_istable(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) == LUA_TTABLE as i32) as i32 -} - -/// -#[inline] -pub unsafe fn lua_islightuserdata(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) == LUA_TLIGHTUSERDATA as i32) as i32 -} - -/// -#[inline] -pub unsafe fn lua_isnil(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) == LUA_TNIL as i32) as i32 -} - -/// -#[inline] -pub unsafe fn lua_isboolean(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) == LUA_TBOOLEAN as i32) as i32 -} - -/// -#[inline] -pub unsafe fn lua_isthread(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) == LUA_TTHREAD as i32) as i32 -} - -/// -#[inline] -pub unsafe fn lua_isnone(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) == LUA_TNONE) as i32 -} - -/// -#[inline] -pub unsafe fn lua_isnoneornil(L: *mut lua_State, idx: libc::c_int) -> libc::c_int { - (lua_type(L, idx) <= 0) as i32 -} - -/// -#[inline] -pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &str) { - lua_pushlstring(L, s.as_ptr() as _, s.len() as _); -} - -/// -#[inline] -pub unsafe fn lua_setglobal(L: *mut lua_State, k: *const libc::c_char) { - lua_setfield(L, LUA_GLOBALSINDEX, k); -} - -/// -#[inline] -pub unsafe fn lua_getglobal(L: *mut lua_State, k: *const libc::c_char) { - lua_getfield(L, LUA_GLOBALSINDEX, k) -} - -/// -#[inline] -pub unsafe fn lua_tostring(L: *mut lua_State, idx: libc::c_int) -> *const libc::c_char { - lua_tolstring(L, idx, ptr::null_mut()) -} - -// Additional compatibility items that are defined as macros - -/// `luaL_newstate()` -#[inline] -#[deprecated(since = "Lua 5.1", note = "replace with `luaL_newstate()`")] -pub unsafe fn lua_open() -> *mut lua_State { - luaL_newstate() -} - -/// `lua_pushvalue(L, LUA_REGISTRYINDEX)` -#[inline] -#[deprecated( - since = "Lua 5.1", - note = "replace with `lua_pushvalue(L, LUA_REGISTRYINDEX)`" -)] -pub unsafe fn lua_getregistry(L: *mut lua_State) { - lua_pushvalue(L, LUA_REGISTRYINDEX) -} - -/// `lua_gc(L, LUA_GCCOUNT as _, 0)` -#[inline] -#[deprecated( - since = "Lua 5.1", - note = "replace with `lua_gc(L, LUA_GCCOUNT as _, 0)`" -)] -pub unsafe fn lua_getgccount(L: *mut lua_State) -> libc::c_int { - lua_gc(L, LUA_GCCOUNT as _, 0) -} - -/// `lua_Reader` -#[deprecated(since = "Lua 5.1", note = "replace with `lua_Reader`")] -pub type lua_Chunkreader = lua_Reader; - -/// `lua_Writer` -#[deprecated(since = "Lua 5.1", note = "replace with `lua_Writer`")] -pub type lua_Chunkwriter = lua_Writer; diff --git a/lib/nexusmods/Cargo.toml b/lib/nexusmods/Cargo.toml deleted file mode 100644 index b9cc879..0000000 --- a/lib/nexusmods/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "nexusmods" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -futures = "0.3.26" -lazy_static = "1.4.0" -regex = "1.7.1" -reqwest = { version = "0.12.4" } -serde = { version = "1.0.152", features = ["derive"] } -serde_json = "1.0.94" -thiserror = "2.0.0" -time = { version = "0.3.20", features = ["serde"] } -tracing = "0.1.37" -url = { version = "2.3.1", features = ["serde"] } - -[dev-dependencies] -tokio = { version = "1.26.0", features = ["rt", "macros"] } diff --git a/lib/nexusmods/src/lib.rs b/lib/nexusmods/src/lib.rs deleted file mode 100644 index 5c243e6..0000000 --- a/lib/nexusmods/src/lib.rs +++ /dev/null @@ -1,339 +0,0 @@ -use std::collections::HashMap; -use std::convert::Infallible; - -use lazy_static::lazy_static; -use regex::Regex; -use reqwest::header::{HeaderMap, HeaderValue, InvalidHeaderValue}; -use reqwest::{Client, IntoUrl, RequestBuilder, Url}; -use serde::Deserialize; -use thiserror::Error; - -mod types; -use time::OffsetDateTime; -pub use types::*; - -// TODO: Add OS information -const USER_AGENT: &str = concat!("DTMM/", env!("CARGO_PKG_VERSION")); -const GAME_ID: &str = "warhammer40kdarktide"; - -lazy_static! { - static ref BASE_URL: Url = Url::parse("https://api.nexusmods.com/v1/").unwrap(); - static ref BASE_URL_GAME: Url = - Url::parse("https://api.nexusmods.com/v1/games/warhammer40kdarktide/").unwrap(); -} - -#[derive(Error, Debug)] -pub enum Error { - #[error("HTTP error: {0:?}")] - HTTP(#[from] reqwest::Error), - #[error("invalid URL: {0:?}")] - URLParseError(#[from] url::ParseError), - #[error("failed to deserialize due to {error}: {json}")] - Deserialize { - json: String, - error: serde_json::Error, - }, - #[error(transparent)] - InvalidHeaderValue(#[from] InvalidHeaderValue), - #[error("this error cannot happen")] - Infallible(#[from] Infallible), - #[error("invalid NXM URL '{url}': {0}", url = .1.as_str())] - InvalidNXM(&'static str, Url), - #[error("{0}")] - Custom(String), -} - -pub type Result = std::result::Result; - -pub struct Nxm { - pub mod_id: u64, - pub file_id: u64, - pub user_id: u64, - pub key: String, - pub expires: OffsetDateTime, -} - -pub struct Api { - client: Client, -} - -impl Api { - pub fn new(key: String) -> Result { - let mut headers = HeaderMap::new(); - headers.insert("accept", HeaderValue::from_static("application/json")); - headers.insert("apikey", HeaderValue::from_str(&key)?); - - let client = Client::builder() - .user_agent(USER_AGENT) - .default_headers(headers) - .build()?; - - Ok(Self { client }) - } - - #[tracing::instrument(skip(self))] - async fn send(&self, req: RequestBuilder) -> Result - where - T: for<'a> Deserialize<'a>, - { - let res = req.send().await?.error_for_status()?; - tracing::trace!(?res); - - let json = res.text().await?; - serde_json::from_str(&json).map_err(|error| Error::Deserialize { json, error }) - } - - #[tracing::instrument(skip(self))] - pub async fn user_validate(&self) -> Result { - let url = BASE_URL.join("users/validate.json")?; - let req = self.client.get(url); - self.send(req).await - } - - #[tracing::instrument(skip(self))] - pub async fn mods_updated(&self, period: UpdatePeriod) -> Result> { - let url = BASE_URL_GAME.join("mods/updated.json")?; - let req = self.client.get(url).query(&[period]); - self.send(req).await - } - - #[tracing::instrument(skip(self))] - pub async fn mods_id(&self, id: u64) -> Result { - let url = BASE_URL_GAME.join(&format!("mods/{id}.json"))?; - let req = self.client.get(url); - self.send(req).await - } - - #[tracing::instrument(skip(self))] - pub async fn file_version(&self, id: u64, timestamp: T) -> Result - where - T: std::fmt::Debug, - OffsetDateTime: PartialEq, - { - let url = BASE_URL_GAME.join(&format!("mods/{id}/files.json"))?; - let req = self.client.get(url); - let files: FileList = self.send(req).await?; - - let Some(file) = files - .files - .into_iter() - .find(|file| file.uploaded_timestamp == timestamp) - else { - let err = Error::Custom("Timestamp does not match any file".into()); - return Err(err); - }; - - Ok(file.version) - } - - #[tracing::instrument(skip(self))] - pub async fn picture(&self, url: impl IntoUrl + std::fmt::Debug) -> Result> { - let res = self.client.get(url).send().await?.error_for_status()?; - - res.bytes() - .await - .map(|bytes| bytes.to_vec()) - .map_err(From::from) - } - - #[tracing::instrument(skip(self))] - pub async fn get_file_by_id(&self, mod_id: u64, file_id: u64) -> Result { - let url = BASE_URL_GAME.join(&format!("mods/{mod_id}/files/{file_id}.json"))?; - let req = self.client.get(url); - self.send(req).await - } - - pub fn parse_file_name>( - name: S, - ) -> Option<(String, u64, String, OffsetDateTime)> { - lazy_static! { - static ref RE: Regex = Regex::new(r#"^(?P.+?)-(?P[1-9]\d*)-(?P.+?)-(?P[1-9]\d*)(?:\.\w+)?$"#).unwrap(); - } - - RE.captures(name.as_ref()).and_then(|cap| { - let name = cap.name("name").map(|s| s.as_str().to_string())?; - let mod_id = cap.name("mod_id").and_then(|s| s.as_str().parse().ok())?; - let version = cap.name("version").map(|s| s.as_str().replace('-', "."))?; - let updated = cap - .name("updated") - .and_then(|s| s.as_str().parse().ok()) - .and_then(|s| OffsetDateTime::from_unix_timestamp(s).ok())?; - - Some((name, mod_id, version, updated)) - }) - } - - #[tracing::instrument(skip(self))] - pub async fn mods_download_link( - &self, - mod_id: u64, - file_id: u64, - key: String, - expires: OffsetDateTime, - ) -> Result> { - let url = - BASE_URL_GAME.join(&format!("mods/{mod_id}/files/{file_id}/download_link.json"))?; - let req = self - .client - .get(url) - .query(&[("key", key)]) - .query(&[("expires", expires.unix_timestamp())]); - self.send(req).await - } - - pub async fn handle_nxm(&self, url: Url) -> Result<(Mod, File, Vec)> { - let nxm = Self::parse_nxm(url.clone())?; - - let user = self.user_validate().await?; - - if nxm.user_id != user.user_id { - return Err(Error::InvalidNXM("user_id mismtach", url)); - } - - let (mod_data, file_info, download_info) = futures::try_join!( - self.mods_id(nxm.mod_id), - self.get_file_by_id(nxm.mod_id, nxm.file_id), - self.mods_download_link(nxm.mod_id, nxm.file_id, nxm.key, nxm.expires) - )?; - - let Some(download_url) = download_info.first().map(|i| i.uri.clone()) else { - return Err(Error::InvalidNXM("no download link", url)); - }; - - let req = self.client.get(download_url); - let data = req.send().await?.bytes().await?; - - Ok((mod_data, file_info, data.to_vec())) - } - - pub fn parse_nxm(nxm: Url) -> Result { - if nxm.scheme() != "nxm" { - return Err(Error::InvalidNXM("Invalid scheme", nxm)); - } - - // Now it makes sense, why Nexus calls this field `game_domain_name`, when it's just - // another path segment in the regular API calls. - if nxm.host_str() != Some(GAME_ID) { - return Err(Error::InvalidNXM("Invalid game domain name", nxm)); - } - - let Some(mut segments) = nxm.path_segments() else { - return Err(Error::InvalidNXM("Missing path segments", nxm)); - }; - - if segments.next() != Some("mods") { - return Err(Error::InvalidNXM( - "Unexpected path segment, expected 'mods'", - nxm, - )); - } - - let Some(mod_id) = segments.next().and_then(|id| id.parse().ok()) else { - return Err(Error::InvalidNXM("Invalid mod ID", nxm)); - }; - - if segments.next() != Some("files") { - return Err(Error::InvalidNXM( - "Unexpected path segment, expected 'files'", - nxm, - )); - } - - let Some(file_id) = segments.next().and_then(|id| id.parse().ok()) else { - return Err(Error::InvalidNXM("Invalid file ID", nxm)); - }; - - let mut query = HashMap::new(); - let pairs = nxm.query_pairs(); - - for (key, val) in pairs { - query.insert(key, val); - } - - let Some(key) = query.get("key") else { - return Err(Error::InvalidNXM("Missing query field 'key'", nxm)); - }; - - let expires = query - .get("expires") - .and_then(|expires| expires.parse().ok()) - .and_then(|expires| OffsetDateTime::from_unix_timestamp(expires).ok()); - let Some(expires) = expires else { - return Err(Error::InvalidNXM("Missing query field 'expires'", nxm)); - }; - - let user_id = query.get("user_id").and_then(|id| id.parse().ok()); - let Some(user_id) = user_id else { - return Err(Error::InvalidNXM("Missing query field 'user_id'", nxm)); - }; - - Ok(Nxm { - mod_id, - file_id, - key: key.to_string(), - expires, - user_id, - }) - } -} - -#[cfg(test)] -mod test { - use reqwest::Url; - use time::OffsetDateTime; - - use crate::Api; - - fn make_api() -> Api { - let key = std::env::var("NEXUSMODS_API_KEY").expect("'NEXUSMODS_API_KEY' env var missing"); - Api::new(key).expect("failed to build API client") - } - - #[tokio::test] - async fn mods_updated() { - let client = make_api(); - client - .mods_updated(Default::default()) - .await - .expect("failed to query 'mods_updated'"); - } - - #[tokio::test] - async fn user_validate() { - let client = make_api(); - client - .user_validate() - .await - .expect("failed to query 'user_validate'"); - } - - #[tokio::test] - async fn mods_id() { - let client = make_api(); - let dmf_id = 8; - client - .mods_id(dmf_id) - .await - .expect("failed to query 'mods_id'"); - } - - #[test] - fn parse_file_name() { - let file = "Darktide Mod Framework-8-23-3-04-1677966575.zip"; - let (name, mod_id, version, updated) = Api::parse_file_name(file).unwrap(); - - assert_eq!(name, String::from("Darktide Mod Framework")); - assert_eq!(mod_id, 8); - assert_eq!(version, String::from("23-3-04")); - assert_eq!( - updated, - OffsetDateTime::from_unix_timestamp(1677966575).unwrap() - ); - } - - #[test] - fn parse_nxm() { - let nxm = Url::parse("nxm://warhammer40kdarktide/mods/8/files/1000172397?key=VZ86Guj_LosPvtkD90-ZQg&expires=1678359882&user_id=1234567").expect("invalid NXM example"); - Api::parse_nxm(nxm).expect("failed to parse nxm link"); - } -} diff --git a/lib/nexusmods/src/types.rs b/lib/nexusmods/src/types.rs deleted file mode 100644 index db0f624..0000000 --- a/lib/nexusmods/src/types.rs +++ /dev/null @@ -1,140 +0,0 @@ -use reqwest::Url; -use serde::ser::SerializeTuple; -use serde::{Deserialize, Serialize}; -use time::OffsetDateTime; - -#[derive(Debug, Deserialize)] -pub struct User { - pub user_id: u64, - pub name: String, - pub profile_url: Url, - // pub is_premium: bool, - // pub is_supporter: bool, - // pub email: String, -} - -#[derive(Copy, Clone, Debug, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum ModStatus { - Published, -} - -#[derive(Copy, Clone, Debug, Deserialize)] -pub enum EndorseStatus { - Endorsed, - Undecided, -} - -#[derive(Debug, Deserialize)] -pub struct ModEndorsement { - pub endorse_status: EndorseStatus, - #[serde(with = "time::serde::timestamp::option")] - pub timestamp: Option, - pub version: Option, -} - -#[derive(Debug, Deserialize)] -pub struct Mod { - pub name: String, - pub description: String, - pub summary: String, - pub picture_url: Url, - pub uid: u64, - pub mod_id: u64, - pub category_id: u64, - pub version: String, - #[serde(with = "time::serde::timestamp")] - pub created_timestamp: OffsetDateTime, - // created_time: OffsetDateTime, - #[serde(with = "time::serde::timestamp")] - pub updated_timestamp: OffsetDateTime, - // updated_time: OffsetDateTime, - pub author: String, - pub uploaded_by: String, - pub uploaded_users_profile_url: Url, - pub status: ModStatus, - pub available: bool, - pub endorsement: ModEndorsement, - // pub mod_downloads: u64, - // pub mod_unique_downloads: u64, - // pub game_id: u64, - // pub allow_rating: bool, - // pub domain_name: String, - // pub endorsement_count: u64, - // pub contains_adult_content: bool, -} - -#[derive(Debug, Deserialize)] -pub struct File { - pub id: Vec, - pub uid: u64, - pub file_id: u64, - pub name: String, - pub version: String, - pub category_id: u64, - pub category_name: String, - pub is_primary: bool, - pub size: u64, - pub file_name: String, - #[serde(with = "time::serde::timestamp")] - pub uploaded_timestamp: OffsetDateTime, - pub mod_version: String, - pub external_virus_scan_url: String, - pub description: String, - pub size_kb: u64, - pub size_in_bytes: u64, - pub changelog_html: Option, - pub content_preview_link: String, -} - -#[derive(Debug, Deserialize)] -pub struct FileList { - pub files: Vec, - // pub file_updates: Vec, -} - -#[derive(Debug, Deserialize)] -pub struct DownloadLink { - pub name: String, - pub short_name: String, - #[serde(alias = "URI")] - pub uri: Url, -} - -#[derive(Debug, Deserialize)] -pub struct UpdateInfo { - pub mod_id: u64, - #[serde(with = "time::serde::timestamp")] - pub latest_file_update: OffsetDateTime, - #[serde(with = "time::serde::timestamp")] - pub latest_mod_activity: OffsetDateTime, -} - -#[derive(Copy, Clone, Debug)] -pub enum UpdatePeriod { - Day, - Week, - Month, -} - -impl Default for UpdatePeriod { - fn default() -> Self { - Self::Week - } -} - -impl Serialize for UpdatePeriod { - fn serialize(&self, serializer: S) -> std::result::Result - where - S: serde::Serializer, - { - let mut tup = serializer.serialize_tuple(2)?; - tup.serialize_element("period")?; - tup.serialize_element(match self { - Self::Day => "1d", - Self::Week => "1w", - Self::Month => "1m", - })?; - tup.end() - } -} diff --git a/lib/oodle/Cargo.toml b/lib/oodle/Cargo.toml index 4a6fe2f..3283592 100644 --- a/lib/oodle/Cargo.toml +++ b/lib/oodle/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -color-eyre = { workspace = true } -tracing = { workspace = true } +color-eyre = "0.6.2" +tracing = "0.1.37" [build-dependencies] -bindgen = "0.72.0" +bindgen = "0.64.0" diff --git a/lib/oodle/build.rs b/lib/oodle/build.rs index 03b6463..2a48078 100644 --- a/lib/oodle/build.rs +++ b/lib/oodle/build.rs @@ -1,22 +1,21 @@ +extern crate bindgen; + use std::env; use std::path::PathBuf; fn main() { - let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("No CARGO_MANIFEST_DIR"); - println!("cargo:rustc-link-search=native={}", &manifest_dir); + // Tell cargo to look for shared libraries in the specified directory + // println!("cargo:rustc-link-search=/path/to/lib"); - if std::env::var("CARGO_CFG_TARGET_FAMILY") == Ok(String::from("windows")) { - let lib_name = if cfg!(debug_assertions) { - "oo2core_win64_debug" - } else { - "oo2core_win64" - }; - println!("cargo:rustc-link-lib=static={lib_name}"); + // Tell cargo to tell rustc to link the system bzip2 + // shared library. + if cfg!(target_os = "windows") { + println!("cargo:rustc-link-lib=oo2core_8_win64"); } else { - println!("cargo:rustc-link-lib=static=oo2corelinux64"); - println!("cargo:rustc-link-lib=stdc++"); + println!("cargo:rustc-link-lib=oo2corelinux64"); } + // Tell cargo to invalidate the built crate whenever the wrapper changes println!("cargo:rerun-if-changed=oodle2.h"); // The bindgen::Builder is the main entry point @@ -31,7 +30,7 @@ fn main() { .blocklist_file("stdlib.h") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. diff --git a/lib/oodle/src/lib.rs b/lib/oodle/src/lib.rs index 7edadee..76b1d16 100644 --- a/lib/oodle/src/lib.rs +++ b/lib/oodle/src/lib.rs @@ -7,7 +7,6 @@ use std::ptr; use color_eyre::{eyre, Result}; #[allow(dead_code)] -#[allow(clippy::identity_op)] mod bindings { include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } @@ -52,7 +51,6 @@ impl From for bindings::OodleLZ_CheckCRC { #[tracing::instrument(skip(data))] pub fn decompress( data: I, - out_size: usize, fuzz_safe: OodleLZ_FuzzSafe, check_crc: OodleLZ_CheckCRC, ) -> Result> @@ -60,7 +58,7 @@ where I: AsRef<[u8]>, { let data = data.as_ref(); - let mut out = vec![0; out_size]; + let mut out = vec![0; CHUNK_SIZE]; let verbosity = if tracing::enabled!(tracing::Level::INFO) { bindings::OodleLZ_Verbosity_OodleLZ_Verbosity_Minimal diff --git a/lib/sdk/Cargo.toml b/lib/sdk/Cargo.toml index 4667a1c..d735f36 100644 --- a/lib/sdk/Cargo.toml +++ b/lib/sdk/Cargo.toml @@ -4,23 +4,23 @@ version = "0.3.0" edition = "2021" [dependencies] -async-recursion = { workspace = true } -bitflags = { workspace = true } -byteorder = { workspace = true } -color-eyre = { workspace = true } -csv-async = { workspace = true } -fastrand = { workspace = true } -futures = { workspace = true } -futures-util = { workspace = true } -glob = { workspace = true } -luajit2-sys = { workspace = true } -nanorand = { workspace = true } -oodle = { workspace = true } -path-slash = { workspace = true } -pin-project-lite = { workspace = true } -serde = { workspace = true } -serde_sjson = { workspace = true } -tokio = { workspace = true } -tokio-stream = { workspace = true } -tracing = { workspace = true } -tracing-error = { workspace = true } +bitflags = "1.3.2" +byteorder = "1.4.3" +color-eyre = "0.6.2" +csv-async = { version = "1.2.4", features = ["tokio", "serde"] } +fastrand = "1.8.0" +futures = "0.3.25" +futures-util = "0.3.24" +glob = "0.3.0" +libloading = "0.7.4" +nanorand = "0.7.0" +pin-project-lite = "0.2.9" +serde = { version = "1.0.147", features = ["derive"] } +serde_sjson = { path = "../../lib/serde_sjson", version = "*" } +oodle = { path = "../../lib/oodle", version = "*" } +tokio = { version = "1.21.2", features = ["rt-multi-thread", "fs", "process", "macros", "tracing", "io-util", "io-std"] } +tokio-stream = { version = "0.1.11", features = ["fs", "io-util"] } +tracing = { version = "0.1.37", features = ["async-await"] } +tracing-error = "0.2.0" +luajit2-sys = "0.0.2" +async-recursion = "1.0.2" diff --git a/lib/sdk/src/binary.rs b/lib/sdk/src/binary.rs index f96b3e0..9ce3f11 100644 --- a/lib/sdk/src/binary.rs +++ b/lib/sdk/src/binary.rs @@ -43,11 +43,10 @@ impl FromBinary for Vec { } pub mod sync { - use std::ffi::CStr; - use std::io::{self, Read, Seek, SeekFrom, Write}; + use std::io::{self, Read, Seek, SeekFrom}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; - use color_eyre::eyre::{self, WrapErr}; + use color_eyre::eyre::WrapErr; use color_eyre::{Help, Report, Result, SectionExt}; macro_rules! make_read { @@ -123,7 +122,7 @@ pub mod sync { }; } - pub trait ReadExt: Read + Seek { + pub trait ReadExt: ReadBytesExt + Seek { fn read_u8(&mut self) -> io::Result { ReadBytesExt::read_u8(self) } @@ -131,25 +130,9 @@ pub mod sync { make_read!(read_u32, read_u32_le, u32); make_read!(read_u64, read_u64_le, u64); + make_skip!(skip_u8, read_u8, u8); make_skip!(skip_u32, read_u32, u32); - // Implementation based on https://en.wikipedia.com/wiki/LEB128 - fn read_uleb128(&mut self) -> io::Result { - let mut result: u64 = 0; - let mut shift: u64 = 0; - - loop { - let byte = ReadExt::read_u8(self)? as u64; - result |= (byte & 0x7f) << shift; - - if byte < 0x80 { - return Ok(result); - } - - shift += 7; - } - } - fn skip_padding(&mut self) -> io::Result<()> { let pos = self.stream_position()?; let padding_size = 16 - (pos % 16); @@ -165,13 +148,25 @@ pub mod sync { } fn read_string_len(&mut self, len: usize) -> Result { - let pos = self.stream_position(); + let mut buf = vec![0; len]; + let res = self + .read_exact(&mut buf) + .map_err(Report::new) + .and_then(|_| { + String::from_utf8(buf).map_err(|err| { + let ascii = String::from_utf8_lossy(err.as_bytes()).to_string(); + let bytes = format!("{:?}", err.as_bytes()); + Report::new(err) + .with_section(move || bytes.header("Bytes:")) + .with_section(move || ascii.header("ASCII:")) + }) + }); - let res = read_string_len(self, len); if res.is_ok() { return res; } + let pos = self.stream_position(); if pos.is_ok() { res.with_section(|| { format!("{pos:#X} ({pos})", pos = pos.unwrap()).header("Position: ") @@ -180,17 +175,9 @@ pub mod sync { res } } - - fn read_bool(&mut self) -> Result { - match ReadExt::read_u8(self)? { - 0 => Ok(false), - 1 => Ok(true), - v => eyre::bail!("Invalid value for boolean '{}'", v), - } - } } - pub trait WriteExt: Write + Seek { + pub trait WriteExt: WriteBytesExt + Seek { fn write_u8(&mut self, val: u8) -> io::Result<()> { WriteBytesExt::write_u8(self, val) } @@ -198,10 +185,6 @@ pub mod sync { make_write!(write_u32, write_u32_le, u32); make_write!(write_u64, write_u64_le, u64); - fn write_bool(&mut self, val: bool) -> io::Result<()> { - WriteBytesExt::write_u8(self, if val { 1 } else { 0 }) - } - fn write_padding(&mut self) -> io::Result { let pos = self.stream_position()?; let size = 16 - (pos % 16) as usize; @@ -218,8 +201,8 @@ pub mod sync { } } - impl ReadExt for R {} - impl WriteExt for W {} + impl ReadExt for R {} + impl WriteExt for W {} pub(crate) fn _read_up_to(r: &mut R, buf: &mut Vec) -> Result where @@ -243,22 +226,4 @@ pub mod sync { Err(err).with_section(|| format!("{pos:#X} ({pos})").header("Position: ")) } - - fn read_string_len(mut r: impl Read, len: usize) -> Result { - let mut buf = vec![0; len]; - r.read_exact(&mut buf) - .wrap_err_with(|| format!("Failed to read {len} bytes"))?; - - let res = match CStr::from_bytes_until_nul(&buf) { - Ok(s) => { - let s = s.to_str()?; - Ok(s.to_string()) - } - Err(_) => String::from_utf8(buf.clone()).map_err(Report::new), - }; - - res.wrap_err("Invalid binary for UTF8 string") - .with_section(|| format!("{}", String::from_utf8_lossy(&buf)).header("ASCI:")) - .with_section(|| format!("{buf:x?}").header("Bytes:")) - } } diff --git a/lib/sdk/src/bundle/database.rs b/lib/sdk/src/bundle/database.rs index 185c62f..6152ede 100644 --- a/lib/sdk/src/bundle/database.rs +++ b/lib/sdk/src/bundle/database.rs @@ -13,21 +13,21 @@ use crate::binary::ToBinary; use crate::murmur::Murmur64; use crate::Bundle; -use super::filetype::BundleFileType; +use super::file::BundleFileType; const DATABASE_VERSION: u32 = 0x6; const FILE_VERSION: u32 = 0x4; pub struct BundleFile { - pub name: String, - pub stream: String, - pub platform_specific: bool, - pub file_time: u64, + name: String, + stream: String, + platform_specific: bool, + file_time: u64, } pub struct FileName { - pub extension: BundleFileType, - pub name: Murmur64, + extension: BundleFileType, + name: Murmur64, } pub struct BundleDatabase { @@ -36,34 +36,7 @@ pub struct BundleDatabase { bundle_contents: HashMap>, } -// Implements the partial Murmur that's used by the engine to compute bundle resource hashes, -// but in a way that the loop can be done outside the function. -#[inline(always)] -fn add_to_resource_hash(mut k: u64, name: impl Into) -> u64 { - const M: u64 = 0xc6a4a7935bd1e995; - const R: u64 = 47; - - let mut h: u64 = name.into(); - - k = k.wrapping_mul(M); - k ^= k >> R; - k = k.wrapping_mul(M); - - h ^= k; - k = M.wrapping_mul(h); - - k -} - impl BundleDatabase { - pub fn bundles(&self) -> &HashMap> { - &self.stored_files - } - - pub fn files(&self) -> &HashMap> { - &self.bundle_contents - } - pub fn add_bundle(&mut self, bundle: &Bundle) { let hash = bundle.name().to_murmur64(); let name = hash.to_string(); @@ -96,26 +69,20 @@ impl BundleDatabase { } } - let mut resource_hash = 0; - for f in bundle.files() { - let name = f.base_name().to_murmur64(); let file_name = FileName { extension: f.file_type(), - name, + name: f.base_name().to_murmur64(), }; - resource_hash = add_to_resource_hash(resource_hash, name); + // TODO: Compute actual resource hash + self.resource_hashes.insert(hash, 0); - // TODO: Make sure each file name only exists once. Probably best to turn - // the `Vec` into a sorted `HashSet`. self.bundle_contents .entry(hash) .or_default() .push(file_name); } - - self.resource_hashes.insert(hash, resource_hash); } } @@ -136,7 +103,7 @@ impl FromBinary for BundleDatabase { let mut stored_files = HashMap::with_capacity(num_entries); for _ in 0..num_entries { - let hash = r.read_u64().map(Murmur64::from)?; + let hash = Murmur64::from(r.read_u64()?); let num_files = r.read_u32()? as usize; let mut files = Vec::with_capacity(num_files); @@ -194,7 +161,7 @@ impl FromBinary for BundleDatabase { let mut resource_hashes = HashMap::with_capacity(num_hashes); for _ in 0..num_hashes { - let name = r.read_u64().map(Murmur64::from)?; + let name = Murmur64::from(r.read_u64()?); let hash = r.read_u64()?; resource_hashes.insert(name, hash); @@ -204,14 +171,14 @@ impl FromBinary for BundleDatabase { let mut bundle_contents = HashMap::with_capacity(num_contents); for _ in 0..num_contents { - let hash = r.read_u64().map(Murmur64::from)?; + let hash = Murmur64::from(r.read_u64()?); let num_files = r.read_u32()? as usize; let mut files = Vec::with_capacity(num_files); for _ in 0..num_files { - let extension = r.read_u64().map(BundleFileType::from)?; - let name = r.read_u64().map(Murmur64::from)?; + let extension = BundleFileType::from(r.read_u64()?); + let name = Murmur64::from(r.read_u64()?); files.push(FileName { extension, name }); } diff --git a/lib/sdk/src/bundle/file.rs b/lib/sdk/src/bundle/file.rs index 18d329f..872b48b 100644 --- a/lib/sdk/src/bundle/file.rs +++ b/lib/sdk/src/bundle/file.rs @@ -1,3 +1,4 @@ +use std::ffi::CString; use std::io::{Cursor, Read, Seek, Write}; use std::path::Path; @@ -5,28 +6,421 @@ use bitflags::bitflags; use color_eyre::eyre::Context; use color_eyre::{eyre, Result}; use futures::future::join_all; +use serde::Serialize; use crate::binary::sync::*; use crate::filetype::*; use crate::murmur::{HashGroup, IdString64, Murmur64}; -use super::filetype::BundleFileType; +#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)] +pub enum BundleFileType { + Animation, + AnimationCurves, + Apb, + BakedLighting, + Bik, + BlendSet, + Bones, + Chroma, + CommonPackage, + Config, + Crypto, + Data, + Entity, + Flow, + Font, + Ies, + Ini, + Input, + Ivf, + Keys, + Level, + Lua, + Material, + Mod, + MouseCursor, + NavData, + NetworkConfig, + OddleNet, + Package, + Particles, + PhysicsProperties, + RenderConfig, + RtPipeline, + Scene, + Shader, + ShaderLibrary, + ShaderLibraryGroup, + ShadingEnvionmentMapping, + ShadingEnvironment, + Slug, + SlugAlbum, + SoundEnvironment, + SpuJob, + StateMachine, + StaticPVS, + Strings, + SurfaceProperties, + Texture, + TimpaniBank, + TimpaniMaster, + Tome, + Ugg, + Unit, + Upb, + VectorField, + Wav, + WwiseBank, + WwiseDep, + WwiseEvent, + WwiseMetadata, + WwiseStream, + Xml, + + Unknown(Murmur64), +} + +impl BundleFileType { + pub fn ext_name(&self) -> String { + match self { + BundleFileType::AnimationCurves => String::from("animation_curves"), + BundleFileType::Animation => String::from("animation"), + BundleFileType::Apb => String::from("apb"), + BundleFileType::BakedLighting => String::from("baked_lighting"), + BundleFileType::Bik => String::from("bik"), + BundleFileType::BlendSet => String::from("blend_set"), + BundleFileType::Bones => String::from("bones"), + BundleFileType::Chroma => String::from("chroma"), + BundleFileType::CommonPackage => String::from("common_package"), + BundleFileType::Config => String::from("config"), + BundleFileType::Crypto => String::from("crypto"), + BundleFileType::Data => String::from("data"), + BundleFileType::Entity => String::from("entity"), + BundleFileType::Flow => String::from("flow"), + BundleFileType::Font => String::from("font"), + BundleFileType::Ies => String::from("ies"), + BundleFileType::Ini => String::from("ini"), + BundleFileType::Input => String::from("input"), + BundleFileType::Ivf => String::from("ivf"), + BundleFileType::Keys => String::from("keys"), + BundleFileType::Level => String::from("level"), + BundleFileType::Lua => String::from("lua"), + BundleFileType::Material => String::from("material"), + BundleFileType::Mod => String::from("mod"), + BundleFileType::MouseCursor => String::from("mouse_cursor"), + BundleFileType::NavData => String::from("nav_data"), + BundleFileType::NetworkConfig => String::from("network_config"), + BundleFileType::OddleNet => String::from("oodle_net"), + BundleFileType::Package => String::from("package"), + BundleFileType::Particles => String::from("particles"), + BundleFileType::PhysicsProperties => String::from("physics_properties"), + BundleFileType::RenderConfig => String::from("render_config"), + BundleFileType::RtPipeline => String::from("rt_pipeline"), + BundleFileType::Scene => String::from("scene"), + BundleFileType::ShaderLibraryGroup => String::from("shader_library_group"), + BundleFileType::ShaderLibrary => String::from("shader_library"), + BundleFileType::Shader => String::from("shader"), + BundleFileType::ShadingEnvionmentMapping => String::from("shading_environment_mapping"), + BundleFileType::ShadingEnvironment => String::from("shading_environment"), + BundleFileType::SlugAlbum => String::from("slug_album"), + BundleFileType::Slug => String::from("slug"), + BundleFileType::SoundEnvironment => String::from("sound_environment"), + BundleFileType::SpuJob => String::from("spu_job"), + BundleFileType::StateMachine => String::from("state_machine"), + BundleFileType::StaticPVS => String::from("static_pvs"), + BundleFileType::Strings => String::from("strings"), + BundleFileType::SurfaceProperties => String::from("surface_properties"), + BundleFileType::Texture => String::from("texture"), + BundleFileType::TimpaniBank => String::from("timpani_bank"), + BundleFileType::TimpaniMaster => String::from("timpani_master"), + BundleFileType::Tome => String::from("tome"), + BundleFileType::Ugg => String::from("ugg"), + BundleFileType::Unit => String::from("unit"), + BundleFileType::Upb => String::from("upb"), + BundleFileType::VectorField => String::from("vector_field"), + BundleFileType::Wav => String::from("wav"), + BundleFileType::WwiseBank => String::from("wwise_bank"), + BundleFileType::WwiseDep => String::from("wwise_dep"), + BundleFileType::WwiseEvent => String::from("wwise_event"), + BundleFileType::WwiseMetadata => String::from("wwise_metadata"), + BundleFileType::WwiseStream => String::from("wwise_stream"), + BundleFileType::Xml => String::from("xml"), + + BundleFileType::Unknown(s) => format!("{s:016X}"), + } + } + + pub fn decompiled_ext_name(&self) -> String { + match self { + BundleFileType::Texture => String::from("dds"), + BundleFileType::WwiseBank => String::from("bnk"), + BundleFileType::WwiseStream => String::from("ogg"), + _ => self.ext_name(), + } + } + + pub fn hash(&self) -> Murmur64 { + Murmur64::from(*self) + } +} + +impl std::str::FromStr for BundleFileType { + type Err = color_eyre::Report; + + fn from_str(s: &str) -> Result { + let val = match s { + "animation_curves" => BundleFileType::AnimationCurves, + "animation" => BundleFileType::Animation, + "apb" => BundleFileType::Apb, + "baked_lighting" => BundleFileType::BakedLighting, + "bik" => BundleFileType::Bik, + "blend_set" => BundleFileType::BlendSet, + "bones" => BundleFileType::Bones, + "chroma" => BundleFileType::Chroma, + "common_package" => BundleFileType::CommonPackage, + "config" => BundleFileType::Config, + "crypto" => BundleFileType::Crypto, + "data" => BundleFileType::Data, + "entity" => BundleFileType::Entity, + "flow" => BundleFileType::Flow, + "font" => BundleFileType::Font, + "ies" => BundleFileType::Ies, + "ini" => BundleFileType::Ini, + "input" => BundleFileType::Input, + "ivf" => BundleFileType::Ivf, + "keys" => BundleFileType::Keys, + "level" => BundleFileType::Level, + "lua" => BundleFileType::Lua, + "material" => BundleFileType::Material, + "mod" => BundleFileType::Mod, + "mouse_cursor" => BundleFileType::MouseCursor, + "nav_data" => BundleFileType::NavData, + "network_config" => BundleFileType::NetworkConfig, + "oodle_net" => BundleFileType::OddleNet, + "package" => BundleFileType::Package, + "particles" => BundleFileType::Particles, + "physics_properties" => BundleFileType::PhysicsProperties, + "render_config" => BundleFileType::RenderConfig, + "rt_pipeline" => BundleFileType::RtPipeline, + "scene" => BundleFileType::Scene, + "shader_library_group" => BundleFileType::ShaderLibraryGroup, + "shader_library" => BundleFileType::ShaderLibrary, + "shader" => BundleFileType::Shader, + "shading_environment_mapping" => BundleFileType::ShadingEnvionmentMapping, + "shading_environment" => BundleFileType::ShadingEnvironment, + "slug_album" => BundleFileType::SlugAlbum, + "slug" => BundleFileType::Slug, + "sound_environment" => BundleFileType::SoundEnvironment, + "spu_job" => BundleFileType::SpuJob, + "state_machine" => BundleFileType::StateMachine, + "static_pvs" => BundleFileType::StaticPVS, + "strings" => BundleFileType::Strings, + "surface_properties" => BundleFileType::SurfaceProperties, + "texture" => BundleFileType::Texture, + "timpani_bank" => BundleFileType::TimpaniBank, + "timpani_master" => BundleFileType::TimpaniMaster, + "tome" => BundleFileType::Tome, + "ugg" => BundleFileType::Ugg, + "unit" => BundleFileType::Unit, + "upb" => BundleFileType::Upb, + "vector_field" => BundleFileType::VectorField, + "wav" => BundleFileType::Wav, + "wwise_bank" => BundleFileType::WwiseBank, + "wwise_dep" => BundleFileType::WwiseDep, + "wwise_event" => BundleFileType::WwiseEvent, + "wwise_metadata" => BundleFileType::WwiseMetadata, + "wwise_stream" => BundleFileType::WwiseStream, + "xml" => BundleFileType::Xml, + s => eyre::bail!("Unknown type string '{}'", s), + }; + + Ok(val) + } +} + +impl Serialize for BundleFileType { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let value = self.ext_name(); + value.serialize(serializer) + } +} + +impl From for BundleFileType { + fn from(value: Murmur64) -> Self { + Self::from(Into::::into(value)) + } +} + +impl From for BundleFileType { + fn from(hash: u64) -> BundleFileType { + match hash { + 0x931e336d7646cc26 => BundleFileType::Animation, + 0xdcfb9e18fff13984 => BundleFileType::AnimationCurves, + 0x3eed05ba83af5090 => BundleFileType::Apb, + 0x7ffdb779b04e4ed1 => BundleFileType::BakedLighting, + 0xaa5965f03029fa18 => BundleFileType::Bik, + 0xe301e8af94e3b5a3 => BundleFileType::BlendSet, + 0x18dead01056b72e9 => BundleFileType::Bones, + 0xb7893adf7567506a => BundleFileType::Chroma, + 0xfe9754bd19814a47 => BundleFileType::CommonPackage, + 0x82645835e6b73232 => BundleFileType::Config, + 0x69108ded1e3e634b => BundleFileType::Crypto, + 0x8fd0d44d20650b68 => BundleFileType::Data, + 0x9831ca893b0d087d => BundleFileType::Entity, + 0x92d3ee038eeb610d => BundleFileType::Flow, + 0x9efe0a916aae7880 => BundleFileType::Font, + 0x8f7d5a2c0f967655 => BundleFileType::Ies, + 0xd526a27da14f1dc5 => BundleFileType::Ini, + 0x2bbcabe5074ade9e => BundleFileType::Input, + 0xfa4a8e091a91201e => BundleFileType::Ivf, + 0xa62f9297dc969e85 => BundleFileType::Keys, + 0x2a690fd348fe9ac5 => BundleFileType::Level, + 0xa14e8dfa2cd117e2 => BundleFileType::Lua, + 0xeac0b497876adedf => BundleFileType::Material, + 0x3fcdd69156a46417 => BundleFileType::Mod, + 0xb277b11fe4a61d37 => BundleFileType::MouseCursor, + 0x169de9566953d264 => BundleFileType::NavData, + 0x3b1fa9e8f6bac374 => BundleFileType::NetworkConfig, + 0xb0f2c12eb107f4d8 => BundleFileType::OddleNet, + 0xad9c6d9ed1e5e77a => BundleFileType::Package, + 0xa8193123526fad64 => BundleFileType::Particles, + 0xbf21403a3ab0bbb1 => BundleFileType::PhysicsProperties, + 0x27862fe24795319c => BundleFileType::RenderConfig, + 0x9ca183c2d0e76dee => BundleFileType::RtPipeline, + 0x9d0a795bfe818d19 => BundleFileType::Scene, + 0xcce8d5b5f5ae333f => BundleFileType::Shader, + 0xe5ee32a477239a93 => BundleFileType::ShaderLibrary, + 0x9e5c3cc74575aeb5 => BundleFileType::ShaderLibraryGroup, + 0x250e0a11ac8e26f8 => BundleFileType::ShadingEnvionmentMapping, + 0xfe73c7dcff8a7ca5 => BundleFileType::ShadingEnvironment, + 0xa27b4d04a9ba6f9e => BundleFileType::Slug, + 0xe9fc9ea7042e5ec0 => BundleFileType::SlugAlbum, + 0xd8b27864a97ffdd7 => BundleFileType::SoundEnvironment, + 0xf97af9983c05b950 => BundleFileType::SpuJob, + 0xa486d4045106165c => BundleFileType::StateMachine, + 0xe3f0baa17d620321 => BundleFileType::StaticPVS, + 0x0d972bab10b40fd3 => BundleFileType::Strings, + 0xad2d3fa30d9ab394 => BundleFileType::SurfaceProperties, + 0xcd4238c6a0c69e32 => BundleFileType::Texture, + 0x99736be1fff739a4 => BundleFileType::TimpaniBank, + 0x00a3e6c59a2b9c6c => BundleFileType::TimpaniMaster, + 0x19c792357c99f49b => BundleFileType::Tome, + 0x712d6e3dd1024c9c => BundleFileType::Ugg, + 0xe0a48d0be9a7453f => BundleFileType::Unit, + 0xa99510c6e86dd3c2 => BundleFileType::Upb, + 0xf7505933166d6755 => BundleFileType::VectorField, + 0x786f65c00a816b19 => BundleFileType::Wav, + 0x535a7bd3e650d799 => BundleFileType::WwiseBank, + 0xaf32095c82f2b070 => BundleFileType::WwiseDep, + 0xaabdd317b58dfc8a => BundleFileType::WwiseEvent, + 0xd50a8b7e1c82b110 => BundleFileType::WwiseMetadata, + 0x504b55235d21440e => BundleFileType::WwiseStream, + 0x76015845a6003765 => BundleFileType::Xml, + + _ => BundleFileType::Unknown(Murmur64::from(hash)), + } + } +} + +impl From for u64 { + fn from(t: BundleFileType) -> u64 { + match t { + BundleFileType::Animation => 0x931e336d7646cc26, + BundleFileType::AnimationCurves => 0xdcfb9e18fff13984, + BundleFileType::Apb => 0x3eed05ba83af5090, + BundleFileType::BakedLighting => 0x7ffdb779b04e4ed1, + BundleFileType::Bik => 0xaa5965f03029fa18, + BundleFileType::BlendSet => 0xe301e8af94e3b5a3, + BundleFileType::Bones => 0x18dead01056b72e9, + BundleFileType::Chroma => 0xb7893adf7567506a, + BundleFileType::CommonPackage => 0xfe9754bd19814a47, + BundleFileType::Config => 0x82645835e6b73232, + BundleFileType::Crypto => 0x69108ded1e3e634b, + BundleFileType::Data => 0x8fd0d44d20650b68, + BundleFileType::Entity => 0x9831ca893b0d087d, + BundleFileType::Flow => 0x92d3ee038eeb610d, + BundleFileType::Font => 0x9efe0a916aae7880, + BundleFileType::Ies => 0x8f7d5a2c0f967655, + BundleFileType::Ini => 0xd526a27da14f1dc5, + BundleFileType::Input => 0x2bbcabe5074ade9e, + BundleFileType::Ivf => 0xfa4a8e091a91201e, + BundleFileType::Keys => 0xa62f9297dc969e85, + BundleFileType::Level => 0x2a690fd348fe9ac5, + BundleFileType::Lua => 0xa14e8dfa2cd117e2, + BundleFileType::Material => 0xeac0b497876adedf, + BundleFileType::Mod => 0x3fcdd69156a46417, + BundleFileType::MouseCursor => 0xb277b11fe4a61d37, + BundleFileType::NavData => 0x169de9566953d264, + BundleFileType::NetworkConfig => 0x3b1fa9e8f6bac374, + BundleFileType::OddleNet => 0xb0f2c12eb107f4d8, + BundleFileType::Package => 0xad9c6d9ed1e5e77a, + BundleFileType::Particles => 0xa8193123526fad64, + BundleFileType::PhysicsProperties => 0xbf21403a3ab0bbb1, + BundleFileType::RenderConfig => 0x27862fe24795319c, + BundleFileType::RtPipeline => 0x9ca183c2d0e76dee, + BundleFileType::Scene => 0x9d0a795bfe818d19, + BundleFileType::Shader => 0xcce8d5b5f5ae333f, + BundleFileType::ShaderLibrary => 0xe5ee32a477239a93, + BundleFileType::ShaderLibraryGroup => 0x9e5c3cc74575aeb5, + BundleFileType::ShadingEnvionmentMapping => 0x250e0a11ac8e26f8, + BundleFileType::ShadingEnvironment => 0xfe73c7dcff8a7ca5, + BundleFileType::Slug => 0xa27b4d04a9ba6f9e, + BundleFileType::SlugAlbum => 0xe9fc9ea7042e5ec0, + BundleFileType::SoundEnvironment => 0xd8b27864a97ffdd7, + BundleFileType::SpuJob => 0xf97af9983c05b950, + BundleFileType::StateMachine => 0xa486d4045106165c, + BundleFileType::StaticPVS => 0xe3f0baa17d620321, + BundleFileType::Strings => 0x0d972bab10b40fd3, + BundleFileType::SurfaceProperties => 0xad2d3fa30d9ab394, + BundleFileType::Texture => 0xcd4238c6a0c69e32, + BundleFileType::TimpaniBank => 0x99736be1fff739a4, + BundleFileType::TimpaniMaster => 0x00a3e6c59a2b9c6c, + BundleFileType::Tome => 0x19c792357c99f49b, + BundleFileType::Ugg => 0x712d6e3dd1024c9c, + BundleFileType::Unit => 0xe0a48d0be9a7453f, + BundleFileType::Upb => 0xa99510c6e86dd3c2, + BundleFileType::VectorField => 0xf7505933166d6755, + BundleFileType::Wav => 0x786f65c00a816b19, + BundleFileType::WwiseBank => 0x535a7bd3e650d799, + BundleFileType::WwiseDep => 0xaf32095c82f2b070, + BundleFileType::WwiseEvent => 0xaabdd317b58dfc8a, + BundleFileType::WwiseMetadata => 0xd50a8b7e1c82b110, + BundleFileType::WwiseStream => 0x504b55235d21440e, + BundleFileType::Xml => 0x76015845a6003765, + + BundleFileType::Unknown(hash) => hash.into(), + } + } +} +impl From for Murmur64 { + fn from(t: BundleFileType) -> Murmur64 { + let hash: u64 = t.into(); + Murmur64::from(hash) + } +} + +impl std::fmt::Display for BundleFileType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.ext_name()) + } +} #[derive(Debug)] struct BundleFileHeader { variant: u32, - external: bool, - size: usize, unknown_1: u8, + size: usize, len_data_file_name: usize, } -#[derive(Clone)] pub struct BundleFileVariant { property: u32, data: Vec, data_file_name: Option, - external: bool, + // Seems to be related to whether there is a data path. unknown_1: u8, } @@ -40,7 +434,6 @@ impl BundleFileVariant { property: 0, data: Vec::new(), data_file_name: None, - external: false, unknown_1: 0, } } @@ -65,30 +458,21 @@ impl BundleFileVariant { self.data_file_name.as_ref() } - pub fn external(&self) -> bool { - self.external - } - - pub fn unknown_1(&self) -> u8 { - self.unknown_1 - } - #[tracing::instrument(skip_all)] fn read_header(r: &mut R) -> Result where R: Read + Seek, { let variant = r.read_u32()?; - let external = r.read_bool()?; - let size = r.read_u32()? as usize; let unknown_1 = r.read_u8()?; + let size = r.read_u32()? as usize; + r.skip_u8(1)?; let len_data_file_name = r.read_u32()? as usize; Ok(BundleFileHeader { size, - external, - variant, unknown_1, + variant, len_data_file_name, }) } @@ -99,7 +483,7 @@ impl BundleFileVariant { W: Write + Seek, { w.write_u32(self.property)?; - w.write_bool(self.external)?; + w.write_u8(self.unknown_1)?; let len_data_file_name = self.data_file_name.as_ref().map(|s| s.len()).unwrap_or(0); @@ -117,36 +501,13 @@ impl BundleFileVariant { } } -impl std::fmt::Debug for BundleFileVariant { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut out = f.debug_struct("BundleFileVariant"); - out.field("property", &self.property); - - if self.data.len() <= 5 { - out.field("data", &format!("{:x?}", &self.data)); - } else { - out.field( - "data", - &format!("{:x?}.. ({} bytes)", &self.data[..5], &self.data.len()), - ); - } - - out.field("data_file_name", &self.data_file_name) - .field("external", &self.external) - .finish() - } -} - bitflags! { - #[derive(Default, Clone, Copy, Debug)] + #[derive(Default)] pub struct Properties: u32 { const DATA = 0b100; - // A custom flag used by DTMT to signify a file altered by mods. - const MODDED = 1 << 31; } } -#[derive(Clone, Debug)] pub struct BundleFile { file_type: BundleFileType, name: IdString64, @@ -155,7 +516,7 @@ pub struct BundleFile { } impl BundleFile { - pub fn new(name: impl Into, file_type: BundleFileType) -> Self { + pub fn new(name: String, file_type: BundleFileType) -> Self { Self { file_type, name: name.into(), @@ -168,18 +529,6 @@ impl BundleFile { self.variants.push(variant) } - pub fn set_variants(&mut self, variants: Vec) { - self.variants = variants; - } - - pub fn set_props(&mut self, props: Properties) { - self.props = props; - } - - pub fn set_modded(&mut self, is_modded: bool) { - self.props.set(Properties::MODDED, is_modded); - } - #[tracing::instrument(name = "File::read", skip(ctx, r))] pub fn from_reader(ctx: &crate::Context, r: &mut R, props: Properties) -> Result where @@ -199,7 +548,7 @@ impl BundleFile { let _enter = span.enter(); let header = BundleFileVariant::read_header(r) - .wrap_err_with(|| format!("Failed to read header {i}"))?; + .wrap_err_with(|| format!("failed to read header {i}"))?; // TODO: Figure out how `header.unknown_1` correlates to `properties::DATA` // if props.contains(Properties::DATA) { @@ -223,19 +572,18 @@ impl BundleFile { let data = vec![]; let s = r .read_string_len(header.size) - .wrap_err("Failed to read data file name")?; + .wrap_err("failed to read data file name")?; (data, Some(s)) } else { let mut data = vec![0; header.size]; r.read_exact(&mut data) - .wrap_err_with(|| format!("Failed to read file {i}"))?; + .wrap_err_with(|| format!("failed to read file {i}"))?; let data_file_name = if header.len_data_file_name > 0 { let s = r .read_string_len(header.len_data_file_name) - .wrap_err("Failed to read data file name")?; - + .wrap_err("failed to read data file name")?; Some(s) } else { None @@ -248,7 +596,6 @@ impl BundleFile { property: header.variant, data, data_file_name, - external: header.external, unknown_1: header.unknown_1, }; @@ -276,7 +623,7 @@ impl BundleFile { for variant in self.variants.iter() { w.write_u32(variant.property())?; - w.write_bool(variant.external)?; + w.write_u8(variant.unknown_1)?; let len_data_file_name = variant.data_file_name().map(|s| s.len()).unwrap_or(0); @@ -301,15 +648,23 @@ impl BundleFile { Ok(w.into_inner()) } - #[tracing::instrument("File::from_sjson", skip(sjson, name), fields(name = %name.display()))] - pub async fn from_sjson( - name: IdString64, + #[tracing::instrument(name = "File::from_sjson", skip(sjson))] + pub async fn from_sjson( + name: String, file_type: BundleFileType, - sjson: impl AsRef, - root: impl AsRef + std::fmt::Debug, - ) -> Result { + sjson: S, + root: P, + ) -> Result + where + P: AsRef + std::fmt::Debug, + S: AsRef, + { match file_type { - BundleFileType::Lua => lua::compile(name, sjson).wrap_err("Failed to compile Lua file"), + BundleFileType::Lua => { + let sjson = + CString::new(sjson.as_ref()).wrap_err("failed to build CString from SJSON")?; + lua::compile(name, sjson) + } BundleFileType::Unknown(_) => { eyre::bail!("Unknown file type. Cannot compile from SJSON"); } @@ -348,13 +703,17 @@ impl BundleFile { s } - pub fn matches_name(&self, name: &IdString64) -> bool { - if self.name == *name { + pub fn matches_name(&self, name: S) -> bool + where + S: Into, + { + let name = name.into(); + if self.name == name { return true; } if let IdString64::String(name) = name { - self.name(false, None) == *name || self.name(true, None) == *name + self.name(false, None) == name || self.name(true, None) == name } else { false } @@ -392,16 +751,18 @@ impl BundleFile { Ok(files) } - #[tracing::instrument( - name = "File::decompiled", - skip_all, - fields(file = self.name(false, None), file_type = self.file_type().ext_name(), variants = self.variants.len()) - )] + #[tracing::instrument(name = "File::decompiled", skip_all)] pub async fn decompiled(&self, ctx: &crate::Context) -> Result> { let file_type = self.file_type(); - // The `Strings` type handles all variants combined. - // For the other ones, each variant will be its own file. + if tracing::enabled!(tracing::Level::DEBUG) { + tracing::debug!( + name = self.name(true, None), + variants = self.variants.len(), + "Attempting to decompile" + ); + } + if file_type == BundleFileType::Strings { return strings::decompile(ctx, &self.variants); } @@ -423,7 +784,7 @@ impl BundleFile { } }; - let res = res.wrap_err_with(|| format!("Failed to decompile file {name}")); + let res = res.wrap_err_with(|| format!("failed to decompile file {name}")); match res { Ok(files) => files, Err(err) => { diff --git a/lib/sdk/src/bundle/filetype.rs b/lib/sdk/src/bundle/filetype.rs deleted file mode 100644 index a7a25dc..0000000 --- a/lib/sdk/src/bundle/filetype.rs +++ /dev/null @@ -1,175 +0,0 @@ -use color_eyre::eyre; -use color_eyre::Result; -use serde::Serialize; - -use crate::murmur::Murmur64; - -macro_rules! make_enum { - ( - $( $variant:ident, $hash:expr, $ext:expr $(, $decompiled:expr)? ; )+ - ) => { - #[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)] - pub enum BundleFileType { - $( - $variant, - )+ - Unknown(Murmur64), - } - - impl BundleFileType { - pub fn ext_name(&self) -> String { - match self { - $( - Self::$variant => String::from($ext), - )+ - Self::Unknown(s) => format!("{s:016X}"), - } - } - - pub fn decompiled_ext_name(&self) -> String { - match self { - $( - $( Self::$variant => String::from($decompiled), )? - )+ - _ => self.ext_name(), - } - } - } - - impl std::str::FromStr for BundleFileType { - type Err = color_eyre::Report; - fn from_str(s: &str) -> Result { - match s { - $( - $ext => Ok(Self::$variant), - )+ - s => eyre::bail!("Unknown type string '{}'", s), - } - } - } - - impl From for BundleFileType { - fn from(h: u64) -> Self { - match h { - $( - $hash => Self::$variant, - )+ - hash => Self::Unknown(hash.into()), - } - } - } - - impl From for u64 { - fn from(t: BundleFileType) -> u64 { - match t { - $( - BundleFileType::$variant => $hash, - )+ - BundleFileType::Unknown(hash) => hash.into(), - } - } - } - } -} - -make_enum! { - AnimationCurves, 0xdcfb9e18fff13984, "animation_curves"; - Animation, 0x931e336d7646cc26, "animation"; - Apb, 0x3eed05ba83af5090, "apb"; - BakedLighting, 0x7ffdb779b04e4ed1, "baked_lighting"; - Bik, 0xaa5965f03029fa18, "bik"; - BlendSet, 0xe301e8af94e3b5a3, "blend_set"; - Bones, 0x18dead01056b72e9, "bones"; - Chroma, 0xb7893adf7567506a, "chroma"; - CommonPackage, 0xfe9754bd19814a47, "common_package"; - Config, 0x82645835e6b73232, "config"; - Crypto, 0x69108ded1e3e634b, "crypto"; - Data, 0x8fd0d44d20650b68, "data"; - Entity, 0x9831ca893b0d087d, "entity"; - Flow, 0x92d3ee038eeb610d, "flow"; - Font, 0x9efe0a916aae7880, "font"; - Ies, 0x8f7d5a2c0f967655, "ies"; - Ini, 0xd526a27da14f1dc5, "ini"; - Input, 0x2bbcabe5074ade9e, "input"; - Ivf, 0xfa4a8e091a91201e, "ivf"; - Keys, 0xa62f9297dc969e85, "keys"; - Level, 0x2a690fd348fe9ac5, "level"; - Lua, 0xa14e8dfa2cd117e2, "lua"; - Material, 0xeac0b497876adedf, "material"; - Mod, 0x3fcdd69156a46417, "mod"; - MouseCursor, 0xb277b11fe4a61d37, "mouse_cursor"; - NavData, 0x169de9566953d264, "nav_data"; - NetworkConfig, 0x3b1fa9e8f6bac374, "network_config"; - OddleNet, 0xb0f2c12eb107f4d8, "oodle_net"; - Package, 0xad9c6d9ed1e5e77a, "package"; - Particles, 0xa8193123526fad64, "particles"; - PhysicsProperties, 0xbf21403a3ab0bbb1, "physics_properties"; - RenderConfig, 0x27862fe24795319c, "render_config"; - RtPipeline, 0x9ca183c2d0e76dee, "rt_pipeline"; - Scene, 0x9d0a795bfe818d19, "scene"; - Shader, 0xcce8d5b5f5ae333f, "shader"; - ShaderLibrary, 0xe5ee32a477239a93, "shader_library"; - ShaderLibraryGroup, 0x9e5c3cc74575aeb5, "shader_library_group"; - ShadingEnvionmentMapping, 0x250e0a11ac8e26f8, "shading_envionment_mapping"; - ShadingEnvironment, 0xfe73c7dcff8a7ca5, "shading_environment"; - Slug, 0xa27b4d04a9ba6f9e, "slug"; - SlugAlbum, 0xe9fc9ea7042e5ec0, "slug_album"; - SoundEnvironment, 0xd8b27864a97ffdd7, "sound_environment"; - SpuJob, 0xf97af9983c05b950, "spu_job"; - StateMachine, 0xa486d4045106165c, "state_machine"; - StaticPVS, 0xe3f0baa17d620321, "static_pvs"; - Strings, 0x0d972bab10b40fd3, "strings"; - SurfaceProperties, 0xad2d3fa30d9ab394, "surface_properties"; - Texture, 0xcd4238c6a0c69e32, "texture", "dds"; - TimpaniBank, 0x99736be1fff739a4, "timpani_bank"; - TimpaniMaster, 0x00a3e6c59a2b9c6c, "timpani_master"; - Tome, 0x19c792357c99f49b, "tome"; - Ugg, 0x712d6e3dd1024c9c, "ugg"; - Unit, 0xe0a48d0be9a7453f, "unit"; - Upb, 0xa99510c6e86dd3c2, "upb"; - VectorField, 0xf7505933166d6755, "vector_field"; - Wav, 0x786f65c00a816b19, "wav"; - WwiseBank, 0x535a7bd3e650d799, "wwise_bank", "bnk"; - WwiseDep, 0xaf32095c82f2b070, "wwise_dep"; - WwiseEvent, 0xaabdd317b58dfc8a, "wwise_event"; - WwiseMetadata, 0xd50a8b7e1c82b110, "wwise_metadata"; - WwiseStream, 0x504b55235d21440e, "wwise_stream", "ogg"; - Xml, 0x76015845a6003765, "xml"; - Theme, 0x38BB9442048A7FBD, "theme"; - MissionThemes, 0x80F2DE893657F83A, "mission_themes"; -} - -impl BundleFileType { - pub fn hash(&self) -> Murmur64 { - Murmur64::from(*self) - } -} - -impl Serialize for BundleFileType { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - let value = self.ext_name(); - value.serialize(serializer) - } -} - -impl From for BundleFileType { - fn from(value: Murmur64) -> Self { - Self::from(Into::::into(value)) - } -} - -impl From for Murmur64 { - fn from(t: BundleFileType) -> Murmur64 { - let hash: u64 = t.into(); - Murmur64::from(hash) - } -} - -impl std::fmt::Display for BundleFileType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.ext_name()) - } -} diff --git a/lib/sdk/src/bundle/mod.rs b/lib/sdk/src/bundle/mod.rs index 03a04c7..1c08530 100644 --- a/lib/sdk/src/bundle/mod.rs +++ b/lib/sdk/src/bundle/mod.rs @@ -7,14 +7,13 @@ use color_eyre::{Help, Report, SectionExt}; use oodle::{OodleLZ_CheckCRC, OodleLZ_FuzzSafe, CHUNK_SIZE}; use crate::binary::sync::*; +use crate::bundle::file::Properties; use crate::murmur::{HashGroup, IdString64, Murmur64}; pub(crate) mod database; pub(crate) mod file; -pub(crate) mod filetype; -pub use file::{BundleFile, BundleFileVariant, Properties}; -pub use filetype::BundleFileType; +pub use file::{BundleFile, BundleFileType, BundleFileVariant}; #[derive(Clone, Copy, Debug, PartialEq, PartialOrd)] enum BundleFormat { @@ -162,11 +161,10 @@ impl Bundle { // TODO: Optimize to not reallocate? let mut raw_buffer = oodle::decompress( &compressed_buffer, - oodle::CHUNK_SIZE, OodleLZ_FuzzSafe::No, OodleLZ_CheckCRC::No, ) - .wrap_err_with(|| format!("Failed to decompress chunk {chunk_index}"))?; + .wrap_err_with(|| format!("failed to decompress chunk {chunk_index}"))?; if unpacked_size_tracked < CHUNK_SIZE { raw_buffer.resize(unpacked_size_tracked, 0); @@ -194,7 +192,7 @@ impl Bundle { let _enter = span.enter(); let file = BundleFile::from_reader(ctx, &mut r, *props) - .wrap_err_with(|| format!("Failed to read file {i}"))?; + .wrap_err_with(|| format!("failed to read file {i}"))?; files.push(file); } @@ -229,15 +227,18 @@ impl Bundle { let _enter = span.enter(); tracing::trace!(num_files = self.files.len()); - self.files.iter().try_fold(Vec::new(), |mut data, file| { - data.append(&mut file.to_binary()?); - Ok::<_, Report>(data) - })? + self.files + .iter() + .fold(Ok::, Report>(Vec::new()), |data, file| { + let mut data = data?; + data.append(&mut file.to_binary()?); + Ok(data) + })? }; // Ceiling division (or division toward infinity) to calculate // the number of chunks required to fit the unpacked data. - let num_chunks = unpacked_data.len().div_ceil(CHUNK_SIZE); + let num_chunks = (unpacked_data.len() + CHUNK_SIZE - 1) / CHUNK_SIZE; tracing::trace!(num_chunks); w.write_u32(num_chunks as u32)?; @@ -360,7 +361,6 @@ where // TODO: Optimize to not reallocate? let mut raw_buffer = oodle::decompress( &compressed_buffer, - oodle::CHUNK_SIZE, OodleLZ_FuzzSafe::No, OodleLZ_CheckCRC::No, )?; diff --git a/lib/sdk/src/context.rs b/lib/sdk/src/context.rs index 8c10b3c..b0de6dc 100644 --- a/lib/sdk/src/context.rs +++ b/lib/sdk/src/context.rs @@ -1,62 +1,10 @@ -use std::ffi::OsString; use std::path::PathBuf; -use std::process::Command; -use std::sync::Arc; use crate::murmur::{Dictionary, HashGroup, IdString64, Murmur32, Murmur64}; -#[derive(Clone)] -pub struct CmdLine { - cmd: OsString, - args: Vec, -} - -impl CmdLine { - pub fn new(cmd: impl Into) -> Self { - Self { - cmd: cmd.into(), - args: vec![], - } - } - - pub fn arg(&mut self, arg: impl Into) -> &mut Self { - self.args.push(arg.into()); - self - } -} - -impl std::fmt::Debug for CmdLine { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("CmdLine") - .field("cmd", &self.cmd) - .field("args", &self.args) - .finish() - } -} - -impl std::fmt::Display for CmdLine { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "\"{}\"", self.cmd.to_string_lossy())?; - - for arg in &self.args { - write!(f, " \"{}\"", arg.to_string_lossy())?; - } - - Ok(()) - } -} - -impl From<&CmdLine> for Command { - fn from(value: &CmdLine) -> Self { - let mut cmd = Command::new(&value.cmd); - cmd.args(&value.args); - cmd - } -} - pub struct Context { - pub lookup: Arc, - pub ljd: Option, + pub lookup: Dictionary, + pub ljd: Option, pub revorb: Option, pub ww2ogg: Option, pub game_dir: Option, @@ -65,7 +13,7 @@ pub struct Context { impl Context { pub fn new() -> Self { Self { - lookup: Arc::new(Dictionary::new()), + lookup: Dictionary::new(), ljd: None, revorb: None, ww2ogg: None, diff --git a/lib/sdk/src/filetype/lua.rs b/lib/sdk/src/filetype/lua.rs index dd0494e..68b95e3 100644 --- a/lib/sdk/src/filetype/lua.rs +++ b/lib/sdk/src/filetype/lua.rs @@ -1,165 +1,49 @@ -use std::env; use std::ffi::CStr; use std::ffi::CString; use std::io::Cursor; -use std::io::Read; use std::io::Write; -use std::process::Command; use color_eyre::eyre; use color_eyre::eyre::Context; use color_eyre::Result; use luajit2_sys as lua; -use tokio::fs; -use crate::binary::sync::ReadExt; use crate::binary::sync::WriteExt; use crate::bundle::file::{BundleFileVariant, UserFile}; -use crate::murmur::IdString64; use crate::{BundleFile, BundleFileType}; -const BITSQUID_LUAJIT_HEADER: u32 = 0x8253461B; - #[tracing::instrument(skip_all, fields(buf_len = data.as_ref().len()))] -pub(crate) async fn decompile(ctx: &crate::Context, data: T) -> Result> +pub(crate) async fn decompile(_ctx: &crate::Context, data: T) -> Result> where T: AsRef<[u8]>, { - let data = data.as_ref(); - let length = { - let mut r = Cursor::new(data); - r.read_u32()? as usize - }; - - // This skips the unknown bytes 5..12 - let content = &data[12..]; - eyre::ensure!( - content.len() == length, - "Content length doesn't match. Expected {}, got {}", - length, - content.len() - ); - - let name = { - let mut r = Cursor::new(content); - - eyre::ensure!( - r.read_u32()? == BITSQUID_LUAJIT_HEADER, - "Invalid magic bytes" - ); - - // Skip additional header bytes - let _ = r.read_uleb128()?; - let length = r.read_uleb128()? as usize; - - let mut buf = vec![0u8; length]; - r.read_exact(&mut buf)?; - let mut s = - String::from_utf8(buf).wrap_err("Invalid byte sequence for LuaJIT bytecode name")?; - // Remove the leading `@` - s.remove(0); - s - }; - - let mut temp = env::temp_dir(); - // Using the actual file name and keeping it in case of an error makes debugging easier. - // But to avoid creating a bunch of folders, we flatten the name. - temp.push(name.replace('/', "_")); - temp.set_extension("luao"); - - tracing::debug!( - "Writing temporary LuaJIT bytecode file to '{}'", - temp.display() - ); - - fs::write(&temp, content) - .await - .wrap_err_with(|| format!("Failed to write LuaJIT bytecode to '{}'", temp.display()))?; - - let mut cmd = ctx - .ljd - .as_ref() - .map(|c| c.into()) - .unwrap_or_else(|| Command::new("ljd")); - - cmd.arg("--catch_asserts") - .args(["--function_def_sugar", "false"]) - .args(["--function_def_self_arg", "true"]) - .args(["--unsafe", "false"]) - .arg("-f") - .arg(&temp); - - tracing::debug!("Executing command: '{:?}'", cmd); - - let output = cmd.output().wrap_err("Failed to run ljd")?; - - if !output.status.success() { - let err = eyre::eyre!( - "LJD exited with code {:?}:\n{}", - output.status.code(), - String::from_utf8_lossy(&output.stderr) - ); - tracing::error!("Failed to decompile '{}':\n{:?}", name, err); - } - - let content = output.stdout; - - // No need to wait for this, so we move it to a separate task. - tokio::spawn(async move { - if let Err(err) = fs::remove_file(&temp) - .await - .wrap_err_with(|| format!("Failed to remove temporary file '{}'", temp.display())) - { - tracing::warn!("{:?}", err); - } - }); - - Ok(vec![UserFile::with_name(content, name)]) + let mut _r = Cursor::new(data.as_ref()); + todo!(); } #[tracing::instrument(skip_all)] -pub fn compile(name: impl Into, code: impl AsRef) -> Result { +pub fn compile(name: S, code: C) -> Result +where + S: Into, + C: AsRef, +{ let name = name.into(); let code = code.as_ref(); - tracing::trace!( - "Compiling '{}', {} bytes of code", - name.display(), - code.len() - ); - let bytecode = unsafe { let state = lua::luaL_newstate(); lua::luaL_openlibs(state); - let name = CString::new(format!("@{}", name.display()).into_bytes()) - .wrap_err_with(|| format!("Cannot convert name into CString: {}", name.display()))?; - match lua::luaL_loadbuffer( - state, - code.as_ptr() as _, - code.len() as _, - name.as_ptr() as _, - ) as u32 - { - lua::LUA_OK => {} - lua::LUA_ERRSYNTAX => { - let err = lua::lua_tostring(state, -1); - let err = CStr::from_ptr(err).to_string_lossy().to_string(); + lua::lua_pushstring(state, code.as_ptr() as _); + lua::lua_setglobal(state, b"code\0".as_ptr() as _); - lua::lua_close(state); + let name = CString::new(name.as_bytes()) + .wrap_err_with(|| format!("cannot convert name into CString: {}", name))?; + lua::lua_pushstring(state, name.as_ptr() as _); + lua::lua_setglobal(state, b"name\0".as_ptr() as _); - eyre::bail!("Invalid syntax: {}", err); - } - lua::LUA_ERRMEM => { - lua::lua_close(state); - eyre::bail!("Failed to allocate sufficient memory to compile LuaJIT bytecode") - } - _ => unreachable!(), - } - lua::lua_setglobal(state, c"fn".as_ptr()); - - let run = c"return string.dump(fn, false)"; - match lua::luaL_loadstring(state, run.as_ptr()) as u32 { + let run = b"return string.dump(loadstring(code, \"@\" .. name), false)\0"; + match lua::luaL_loadstring(state, run.as_ptr() as _) as u32 { lua::LUA_OK => {} lua::LUA_ERRSYNTAX => { let err = lua::lua_tostring(state, -1); diff --git a/lib/sdk/src/filetype/package.rs b/lib/sdk/src/filetype/package.rs index 758f79f..338cc8e 100644 --- a/lib/sdk/src/filetype/package.rs +++ b/lib/sdk/src/filetype/package.rs @@ -10,19 +10,9 @@ use color_eyre::Result; use tokio::fs; use crate::binary::sync::{ReadExt, WriteExt}; -use crate::bundle::file::UserFile; -use crate::bundle::filetype::BundleFileType; -use crate::murmur::{HashGroup, IdString64, Murmur64}; +use crate::bundle::file::{BundleFileType, UserFile}; +use crate::murmur::{HashGroup, Murmur64}; -/// Resolves a relative path that might contain wildcards into a list of -/// paths that exist on disk and match that wildcard. -/// This is similar to globbing in Unix shells, but with much less features. -/// -/// The only wilcard character allowed is `*`, and only at the end of the string, -/// where it matches all files recursively in that directory. -/// -/// `t` is an optional extension name, that may be used to force a wildcard -/// path to only match that file type `t`. #[tracing::instrument] #[async_recursion] async fn resolve_wildcard( @@ -99,12 +89,12 @@ where Ok(paths) } -type PackageType = HashMap>; +type PackageType = HashMap>; type PackageDefinition = HashMap>; #[derive(Default)] pub struct Package { - _name: IdString64, + _name: String, _root: PathBuf, inner: PackageType, flags: u8, @@ -125,9 +115,9 @@ impl DerefMut for Package { } impl Package { - pub fn new(name: impl Into, root: PathBuf) -> Self { + pub fn new(name: String, root: PathBuf) -> Self { Self { - _name: name.into(), + _name: name, _root: root, inner: Default::default(), flags: 1, @@ -138,22 +128,17 @@ impl Package { self.values().fold(0, |total, files| total + files.len()) } - pub fn add_file(&mut self, file_type: BundleFileType, name: impl Into) { + pub fn add_file>(&mut self, file_type: BundleFileType, name: P) { self.inner.entry(file_type).or_default().insert(name.into()); } #[tracing::instrument("Package::from_sjson", skip(sjson), fields(sjson_len = sjson.as_ref().len()))] - pub async fn from_sjson( - sjson: S, - name: impl Into + std::fmt::Debug, - root: P, - ) -> Result + pub async fn from_sjson(sjson: S, name: String, root: P) -> Result where P: AsRef + std::fmt::Debug, S: AsRef, { let root = root.as_ref(); - let name = name.into(); let definition: PackageDefinition = serde_sjson::from_str(sjson.as_ref())?; let mut inner: PackageType = Default::default(); @@ -162,7 +147,7 @@ impl Package { None } else { let t = BundleFileType::from_str(ty) - .wrap_err("Invalid file type in package definition")?; + .wrap_err("invalid file type in package definition")?; Some(t) }; @@ -187,11 +172,7 @@ impl Package { continue; }; - tracing::debug!("Adding file {}", path.display()); - inner - .entry(t) - .or_default() - .insert(path.display().to_string()); + inner.entry(t).or_default().insert(path); } } } @@ -210,13 +191,15 @@ impl Package { pub fn to_sjson(&self) -> Result { let mut map: PackageDefinition = Default::default(); - for (t, names) in self.iter() { - for name in names.iter() { - map.entry(t.ext_name()).or_default().insert(name.clone()); + for (t, paths) in self.iter() { + for path in paths.iter() { + map.entry(t.ext_name()) + .or_default() + .insert(path.display().to_string()); } } - serde_sjson::to_string(&map).wrap_err("Failed to serialize Package to SJSON") + serde_sjson::to_string(&map).wrap_err("failed to serialize Package to SJSON") } #[tracing::instrument("Package::from_binary", skip(binary, ctx), fields(binary_len = binary.as_ref().len()))] @@ -238,11 +221,11 @@ impl Package { for _ in 0..file_count { let t = BundleFileType::from(r.read_u64()?); let hash = Murmur64::from(r.read_u64()?); - let name = ctx.lookup_hash(hash, HashGroup::Filename); + let path = ctx.lookup_hash(hash, HashGroup::Filename); inner .entry(t) .or_default() - .insert(name.display().to_string()); + .insert(PathBuf::from(path.display().to_string())); } let flags = r.read_u8()?; @@ -255,7 +238,7 @@ impl Package { let pkg = Self { inner, - _name: name.into(), + _name: name, _root: PathBuf::new(), flags, }; @@ -271,10 +254,12 @@ impl Package { w.write_u32(0x2b)?; w.write_u32(self.values().flatten().count() as u32)?; - for (t, names) in self.iter() { - for name in names.iter() { + for (t, paths) in self.iter() { + for path in paths.iter() { w.write_u64(t.hash().into())?; - w.write_u64(Murmur64::hash(name.as_bytes()).into())?; + + let hash = Murmur64::hash(path.to_string_lossy().as_bytes()); + w.write_u64(hash.into())?; } } @@ -294,11 +279,17 @@ where Ok(vec![UserFile::new(s.into_bytes())]) } +// #[tracing::instrument(skip_all)] +// pub fn compile(_ctx: &crate::Context, data: String) -> Result> { +// let pkg = Package::from_sjson(data)?; +// pkg.to_binary() +// } + #[cfg(test)] mod test { use std::path::PathBuf; - use crate::bundle::filetype::BundleFileType; + use crate::BundleFileType; use super::resolve_wildcard; use super::Package; diff --git a/lib/sdk/src/filetype/strings.rs b/lib/sdk/src/filetype/strings.rs index 8643266..ca2ed8c 100644 --- a/lib/sdk/src/filetype/strings.rs +++ b/lib/sdk/src/filetype/strings.rs @@ -28,14 +28,10 @@ impl Language { #[derive(serde::Serialize)] pub struct Strings(HashMap>); -#[inline(always)] fn read_string(r: R) -> Result where R: Read, { - // We can safely ignore the warning here, as all data is already in memory, and no additional - // `BufReader` should be needed. - #[allow(clippy::unbuffered_bytes)] r.bytes() .take_while(|b| b.as_ref().map(|b| *b != 0).unwrap_or(false)) .map(|b| b.map_err(Report::new)) @@ -45,7 +41,7 @@ where impl Strings { #[tracing::instrument(skip_all, fields(languages = variants.len()))] - pub fn from_variants(ctx: &crate::Context, variants: &[BundleFileVariant]) -> Result { + pub fn from_variants(ctx: &crate::Context, variants: &Vec) -> Result { let mut map: HashMap> = HashMap::new(); for (i, variant) in variants.iter().enumerate() { @@ -80,7 +76,7 @@ impl Strings { } #[tracing::instrument(skip_all)] -pub fn decompile(ctx: &crate::Context, variants: &[BundleFileVariant]) -> Result> { +pub fn decompile(ctx: &crate::Context, variants: &Vec) -> Result> { let strings = Strings::from_variants(ctx, variants)?; let content = strings.to_sjson()?; diff --git a/lib/sdk/src/lib.rs b/lib/sdk/src/lib.rs index 9b1806b..e229e28 100644 --- a/lib/sdk/src/lib.rs +++ b/lib/sdk/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(test)] - mod binary; mod bundle; mod context; @@ -9,5 +7,5 @@ pub mod murmur; pub use binary::{FromBinary, ToBinary}; pub use bundle::database::BundleDatabase; pub use bundle::decompress; -pub use bundle::{Bundle, BundleFile, BundleFileType, BundleFileVariant, Properties}; -pub use context::{CmdLine, Context}; +pub use bundle::{Bundle, BundleFile, BundleFileType, BundleFileVariant}; +pub use context::Context; diff --git a/lib/sdk/src/murmur/dictionary.rs b/lib/sdk/src/murmur/dictionary.rs index c1b5636..2d51af1 100644 --- a/lib/sdk/src/murmur/dictionary.rs +++ b/lib/sdk/src/murmur/dictionary.rs @@ -48,7 +48,6 @@ struct Row { group: HashGroup, } -#[derive(Clone)] pub struct Entry { value: String, long: Murmur64, @@ -74,7 +73,6 @@ impl Entry { } } -#[derive(Clone)] pub struct Dictionary { entries: Vec, } @@ -90,12 +88,10 @@ impl Dictionary { Self { entries: vec![] } } - pub async fn from_csv(r: R) -> Result + pub async fn from_csv(&mut self, r: R) -> Result<()> where R: AsyncRead + std::marker::Unpin + std::marker::Send, { - let mut entries = vec![]; - let r = AsyncDeserializer::from_reader(r); let mut records = r.into_deserialize::(); @@ -116,10 +112,10 @@ impl Dictionary { group: record.group, }; - entries.push(entry); + self.entries.push(entry); } - Ok(Self { entries }) + Ok(()) } pub async fn to_csv(&self, w: W) -> Result<()> @@ -151,21 +147,21 @@ impl Dictionary { Ok(()) } - pub fn add(&mut self, value: impl AsRef<[u8]>, group: HashGroup) { - let long = Murmur64::from(murmurhash64::hash(value.as_ref(), SEED as u64)); - let short = Murmur32::from(murmurhash64::hash32(value.as_ref(), SEED)); + pub fn add(&mut self, value: String, group: HashGroup) { + let long = Murmur64::from(murmurhash64::hash(value.as_bytes(), SEED as u64)); + let short = Murmur32::from(murmurhash64::hash32(value.as_bytes(), SEED)); let entry = Entry { long, short, - value: String::from_utf8_lossy(value.as_ref()).to_string(), + value, group, }; self.entries.push(entry); } - pub fn find(&self, value: &String, group: HashGroup) -> Option<&Entry> { + pub fn find(&mut self, value: &String, group: HashGroup) -> Option<&Entry> { self.entries .iter() .find(|e| e.value == *value && e.group == group) diff --git a/lib/sdk/src/murmur/idstring32.rs b/lib/sdk/src/murmur/idstring32.rs deleted file mode 100644 index 99ea7aa..0000000 --- a/lib/sdk/src/murmur/idstring32.rs +++ /dev/null @@ -1,162 +0,0 @@ -use std::fmt; - -use serde::{Deserializer, Serializer}; - -use super::Murmur32; - -// This type encodes the fact that when reading in a bundle, we don't always have a dictionary -// entry for every hash in there. So we do want to have the real string available when needed, -// but at the same time retain the original hash information for when we don't. -// This is especially important when wanting to write back the read bundle, as the hashes need to -// stay the same. -// The previous system of always turning hashes into strings worked well for the purpose of -// displaying hashes, but would have made it very hard to turn a stringyfied hash back into -// an actual hash. -#[derive(Clone, Debug, Eq)] -pub enum IdString32 { - Hash(Murmur32), - String(String), -} - -impl IdString32 { - pub fn to_murmur32(&self) -> Murmur32 { - match self { - Self::Hash(hash) => *hash, - Self::String(s) => Murmur32::hash(s.as_bytes()), - } - } - - pub fn display(&self) -> IdString32Display { - let s = match self { - IdString32::Hash(hash) => hash.to_string(), - IdString32::String(s) => s.clone(), - }; - - IdString32Display(s) - } - - pub fn is_string(&self) -> bool { - match self { - IdString32::Hash(_) => false, - IdString32::String(_) => true, - } - } - - pub fn is_hash(&self) -> bool { - match self { - IdString32::Hash(_) => true, - IdString32::String(_) => false, - } - } -} - -impl From for IdString32 { - fn from(value: String) -> Self { - Self::String(value) - } -} - -impl From for IdString32 { - fn from(value: u32) -> Self { - Self::Hash(value.into()) - } -} - -impl From for u32 { - fn from(value: IdString32) -> Self { - value.to_murmur32().into() - } -} - -impl From for IdString32 { - fn from(value: Murmur32) -> Self { - Self::Hash(value) - } -} - -impl From for Murmur32 { - fn from(value: IdString32) -> Self { - value.to_murmur32() - } -} - -impl PartialEq for IdString32 { - fn eq(&self, other: &Self) -> bool { - self.to_murmur32() == other.to_murmur32() - } -} - -impl std::hash::Hash for IdString32 { - fn hash(&self, state: &mut H) { - state.write_u32(self.to_murmur32().into()); - } -} - -impl serde::Serialize for IdString32 { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_u32(self.to_murmur32().into()) - } -} - -struct IdString32Visitor; - -impl<'de> serde::de::Visitor<'de> for IdString32Visitor { - type Value = IdString32; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("an u32 or a string") - } - - fn visit_u32(self, value: u32) -> Result - where - E: serde::de::Error, - { - Ok(IdString32::Hash(value.into())) - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, - { - Ok(IdString32::String(v.to_string())) - } - - fn visit_string(self, v: String) -> Result - where - E: serde::de::Error, - { - Ok(IdString32::String(v)) - } -} - -impl<'de> serde::Deserialize<'de> for IdString32 { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - deserializer.deserialize_u32(IdString32Visitor) - } -} - -pub struct IdString32Display(String); - -impl std::fmt::Display for IdString32Display { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -impl std::fmt::UpperHex for IdString32 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - std::fmt::UpperHex::fmt(&self.to_murmur32(), f) - } -} - -impl std::fmt::LowerHex for IdString32 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - std::fmt::LowerHex::fmt(&self.to_murmur32(), f) - } -} diff --git a/lib/sdk/src/murmur/idstring64.rs b/lib/sdk/src/murmur/idstring64.rs deleted file mode 100644 index 781a0cd..0000000 --- a/lib/sdk/src/murmur/idstring64.rs +++ /dev/null @@ -1,175 +0,0 @@ -use std::{fmt, path::Path}; - -use path_slash::PathExt as _; -use serde::{Deserializer, Serializer}; - -use super::Murmur64; - -// This type encodes the fact that when reading in a bundle, we don't always have a dictionary -// entry for every hash in there. So we do want to have the real string available when needed, -// but at the same time retain the original hash information for when we don't. -// This is especially important when wanting to write back the read bundle, as the hashes need to -// stay the same. -// The previous system of always turning hashes into strings worked well for the purpose of -// displaying hashes, but would have made it very hard to turn a stringyfied hash back into -// an actual hash. -#[derive(Clone, Debug, Eq)] -pub enum IdString64 { - Hash(Murmur64), - String(String), -} - -impl IdString64 { - pub fn to_murmur64(&self) -> Murmur64 { - match self { - Self::Hash(hash) => *hash, - Self::String(s) => Murmur64::hash(s.as_bytes()), - } - } - - pub fn display(&self) -> IdString64Display { - let s = match self { - IdString64::Hash(hash) => hash.to_string(), - IdString64::String(s) => s.clone(), - }; - - IdString64Display(s) - } - - pub fn is_string(&self) -> bool { - match self { - IdString64::Hash(_) => false, - IdString64::String(_) => true, - } - } - - pub fn is_hash(&self) -> bool { - match self { - IdString64::Hash(_) => true, - IdString64::String(_) => false, - } - } - - // Would love to have this as a proper `impl From`, but - // rustc will complain that it overlaps with the `impl From>`. - pub fn from_path(p: impl AsRef) -> Self { - Self::String(p.as_ref().to_slash_lossy().to_string()) - } -} - -impl From for IdString64 { - fn from(value: String) -> Self { - Self::String(value) - } -} - -impl From for IdString64 { - fn from(value: u64) -> Self { - Self::Hash(value.into()) - } -} - -impl From for IdString64 { - fn from(value: Murmur64) -> Self { - Self::Hash(value) - } -} - -impl From for Murmur64 { - fn from(value: IdString64) -> Self { - value.to_murmur64() - } -} - -impl From for u64 { - fn from(value: IdString64) -> Self { - value.to_murmur64().into() - } -} - -impl Default for IdString64 { - fn default() -> Self { - Self::Hash(0.into()) - } -} - -impl PartialEq for IdString64 { - fn eq(&self, other: &Self) -> bool { - self.to_murmur64() == other.to_murmur64() - } -} - -impl std::hash::Hash for IdString64 { - fn hash(&self, state: &mut H) { - state.write_u64(self.to_murmur64().into()); - } -} - -impl serde::Serialize for IdString64 { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_u64(self.to_murmur64().into()) - } -} - -struct IdString64Visitor; - -impl<'de> serde::de::Visitor<'de> for IdString64Visitor { - type Value = IdString64; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("an u64 or a string") - } - - fn visit_u64(self, value: u64) -> Result - where - E: serde::de::Error, - { - Ok(IdString64::Hash(value.into())) - } - - fn visit_str(self, v: &str) -> Result - where - E: serde::de::Error, - { - Ok(IdString64::String(v.to_string())) - } - - fn visit_string(self, v: String) -> Result - where - E: serde::de::Error, - { - Ok(IdString64::String(v)) - } -} - -impl<'de> serde::Deserialize<'de> for IdString64 { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - deserializer.deserialize_u64(IdString64Visitor) - } -} - -pub struct IdString64Display(String); - -impl std::fmt::Display for IdString64Display { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -impl std::fmt::UpperHex for IdString64 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - std::fmt::UpperHex::fmt(&self.to_murmur64(), f) - } -} - -impl std::fmt::LowerHex for IdString64 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - std::fmt::LowerHex::fmt(&self.to_murmur64(), f) - } -} diff --git a/lib/sdk/src/murmur/mod.rs b/lib/sdk/src/murmur/mod.rs index 6449d38..7ede170 100644 --- a/lib/sdk/src/murmur/mod.rs +++ b/lib/sdk/src/murmur/mod.rs @@ -1,26 +1,389 @@ use std::fmt; use color_eyre::eyre::Context; -use color_eyre::{Report, Result}; +use color_eyre::Report; use serde::de::Visitor; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Deserialize, Serialize}; +use serde::{Deserializer, Serializer}; mod dictionary; // Currently unused // mod murmurhash32; -mod idstring32; -mod idstring64; mod murmurhash64; -mod types; -mod util; pub const SEED: u32 = 0; pub use dictionary::{Dictionary, Entry, HashGroup}; -pub use idstring32::*; -pub use idstring64::*; pub use murmurhash64::hash; pub use murmurhash64::hash32; pub use murmurhash64::hash_inverse as inverse; -pub use types::*; +fn _swap_bytes_u32(value: u32) -> u32 { + u32::from_le_bytes(value.to_be_bytes()) +} + +fn _swap_bytes_u64(value: u64) -> u64 { + u64::from_le_bytes(value.to_be_bytes()) +} + +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] +pub struct Murmur64(u64); + +impl Murmur64 { + pub fn hash(s: B) -> Self + where + B: AsRef<[u8]>, + { + hash(s.as_ref(), SEED as u64).into() + } +} + +impl From for Murmur64 { + fn from(value: u64) -> Self { + Self(value) + } +} + +impl From for u64 { + fn from(value: Murmur64) -> Self { + value.0 + } +} + +impl TryFrom<&str> for Murmur64 { + type Error = Report; + + fn try_from(value: &str) -> Result { + u64::from_str_radix(value, 16) + .map(Self) + .wrap_err_with(|| format!("failed to convert value to Murmur64: {value}")) + } +} + +impl fmt::UpperHex for Murmur64 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::UpperHex::fmt(&self.0, f) + } +} + +impl fmt::LowerHex for Murmur64 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::LowerHex::fmt(&self.0, f) + } +} + +impl fmt::Display for Murmur64 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::UpperHex::fmt(&self.0, f) + } +} + +impl<'de> Visitor<'de> for Murmur64 { + type Value = Self; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str( + "an usigned 64 bit integer \ + or a string in hexadecimal format encoding such an integer", + ) + } + + fn visit_f64(self, value: f64) -> Result + where + E: serde::de::Error, + { + let bytes = value.to_le_bytes(); + Ok(Self::from(u64::from_le_bytes(bytes))) + } + + fn visit_u64(self, value: u64) -> Result + where + E: serde::de::Error, + { + Ok(Self::from(value)) + } + + fn visit_str(self, value: &str) -> Result + where + E: serde::de::Error, + { + match Murmur64::try_from(value) { + Ok(hash) => Ok(hash), + Err(err) => Err(E::custom(format!( + "failed to convert '{value}' to Murmur64: {err}" + ))), + } + } +} + +impl<'de> Deserialize<'de> for Murmur64 { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_any(Self(0)) + } +} + +impl Serialize for Murmur64 { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&format!("{self:016X}")) + } +} + +#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] +pub struct Murmur32(u32); + +impl Murmur32 { + pub fn hash(s: B) -> Self + where + B: AsRef<[u8]>, + { + hash32(s.as_ref(), SEED).into() + } +} + +impl From for Murmur32 { + fn from(value: u32) -> Self { + Self(value) + } +} + +impl From for u32 { + fn from(value: Murmur32) -> Self { + value.0 + } +} + +impl TryFrom<&str> for Murmur32 { + type Error = Report; + + fn try_from(value: &str) -> Result { + u32::from_str_radix(value, 16) + .map(Self) + .wrap_err_with(|| format!("failed to convert value to Murmur32: {value}")) + } +} + +impl fmt::UpperHex for Murmur32 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::UpperHex::fmt(&self.0, f) + } +} + +impl fmt::Display for Murmur32 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::UpperHex::fmt(&self.0, f) + } +} + +impl Serialize for Murmur32 { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&format!("{self:08X}")) + } +} + +impl<'de> Visitor<'de> for Murmur32 { + type Value = Self; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str( + "an usigned 32 bit integer \ + or a string in hexadecimal format encoding such an integer", + ) + } + + fn visit_f64(self, value: f64) -> Result + where + E: serde::de::Error, + { + let bytes = value.to_le_bytes(); + self.visit_u32(u64::from_le_bytes(bytes) as u32) + } + + fn visit_u64(self, value: u64) -> Result + where + E: serde::de::Error, + { + self.visit_u32(value as u32) + } + + fn visit_u32(self, value: u32) -> Result + where + E: serde::de::Error, + { + Ok(Self::from(value)) + } + + fn visit_str(self, value: &str) -> Result + where + E: serde::de::Error, + { + match Murmur32::try_from(value) { + Ok(hash) => Ok(hash), + Err(err) => Err(E::custom(format!( + "failed to convert '{value}' to Murmur32: {err}" + ))), + } + } +} + +impl<'de> Deserialize<'de> for Murmur32 { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_any(Self(0)) + } +} + +// This type encodes the fact that when reading in a bundle, we don't always have a dictionary +// entry for every hash in there. So we do want to have the real string available when needed, +// but at the same time retain the original hash information for when we don't. +// This is especially important when wanting to write back the read bundle, as the hashes need to +// stay the same. +// The previous system of always turning hashes into strings worked well for the purpose of +// displaying hashes, but would have made it very hard to turn a stringyfied hash back into +// an actual hash. +#[derive(Clone, Debug, Eq)] +pub enum IdString64 { + Hash(Murmur64), + String(String), +} + +impl IdString64 { + pub fn to_murmur64(&self) -> Murmur64 { + match self { + Self::Hash(hash) => *hash, + Self::String(s) => Murmur64::hash(s.as_bytes()), + } + } + + pub fn display(&self) -> IdString64Display { + let s = match self { + IdString64::Hash(hash) => hash.to_string(), + IdString64::String(s) => s.clone(), + }; + + IdString64Display(s) + } + + pub fn is_string(&self) -> bool { + match self { + IdString64::Hash(_) => false, + IdString64::String(_) => true, + } + } + + pub fn is_hash(&self) -> bool { + match self { + IdString64::Hash(_) => true, + IdString64::String(_) => false, + } + } +} + +impl> From for IdString64 { + fn from(value: S) -> Self { + Self::String(value.into()) + } +} + +impl From for IdString64 { + fn from(value: Murmur64) -> Self { + Self::Hash(value) + } +} + +impl From for Murmur64 { + fn from(value: IdString64) -> Self { + value.to_murmur64() + } +} + +impl PartialEq for IdString64 { + fn eq(&self, other: &Self) -> bool { + self.to_murmur64() == other.to_murmur64() + } +} + +impl std::hash::Hash for IdString64 { + fn hash(&self, state: &mut H) { + state.write_u64(self.to_murmur64().into()); + } +} + +impl serde::Serialize for IdString64 { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_u64(self.to_murmur64().into()) + } +} + +struct IdString64Visitor; + +impl<'de> serde::de::Visitor<'de> for IdString64Visitor { + type Value = IdString64; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("an u64 or a string") + } + + fn visit_u64(self, value: u64) -> Result + where + E: serde::de::Error, + { + Ok(IdString64::Hash(value.into())) + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + Ok(IdString64::String(v.to_string())) + } + + fn visit_string(self, v: String) -> Result + where + E: serde::de::Error, + { + Ok(IdString64::String(v)) + } +} + +impl<'de> serde::Deserialize<'de> for IdString64 { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_u64(IdString64Visitor) + } +} + +pub struct IdString64Display(String); + +impl std::fmt::Display for IdString64Display { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +impl std::fmt::UpperHex for IdString64 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + std::fmt::UpperHex::fmt(&self.to_murmur64(), f) + } +} + +impl std::fmt::LowerHex for IdString64 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + std::fmt::LowerHex::fmt(&self.to_murmur64(), f) + } +} diff --git a/lib/sdk/src/murmur/murmurhash64.rs b/lib/sdk/src/murmur/murmurhash64.rs index ca69852..f15248c 100644 --- a/lib/sdk/src/murmur/murmurhash64.rs +++ b/lib/sdk/src/murmur/murmurhash64.rs @@ -119,9 +119,4 @@ fn test_hash() { } #[test] -fn test_inverse() { - let h = hash("lua".as_bytes(), crate::murmur::SEED as u64); - let inv = hash_inverse(h, crate::murmur::SEED as u64); - assert_eq!(h, hash(&inv.to_le_bytes(), crate::murmur::SEED as u64)); - assert_ne!(h, hash(&inv.to_be_bytes(), crate::murmur::SEED as u64)); -} +fn test_inverse() {} diff --git a/lib/sdk/src/murmur/types.rs b/lib/sdk/src/murmur/types.rs deleted file mode 100644 index 4e6965b..0000000 --- a/lib/sdk/src/murmur/types.rs +++ /dev/null @@ -1,226 +0,0 @@ -use self::util::{parse_hex32, parse_hex64}; - -use super::*; - -#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] -pub struct Murmur64(u64); - -impl Murmur64 { - pub fn hash(s: B) -> Self - where - B: AsRef<[u8]>, - { - hash(s.as_ref(), SEED as u64).into() - } -} - -impl From for Murmur64 { - fn from(value: u64) -> Self { - Self(value) - } -} - -impl From for u64 { - fn from(value: Murmur64) -> Self { - value.0 - } -} - -impl TryFrom<&str> for Murmur64 { - type Error = Report; - - fn try_from(value: &str) -> Result { - parse_hex64(value) - .map(Self) - .wrap_err_with(|| format!("Failed to convert value to Murmur64: {value}")) - } -} - -impl fmt::UpperHex for Murmur64 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::UpperHex::fmt(&self.0, f) - } -} - -impl fmt::LowerHex for Murmur64 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::LowerHex::fmt(&self.0, f) - } -} - -impl fmt::Display for Murmur64 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{self:016X}") - } -} - -impl<'de> Visitor<'de> for Murmur64 { - type Value = Self; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str( - "an usigned 64 bit integer \ - or a string in hexadecimal format encoding such an integer", - ) - } - - fn visit_f64(self, value: f64) -> Result - where - E: serde::de::Error, - { - let bytes = value.to_le_bytes(); - Ok(Self::from(u64::from_le_bytes(bytes))) - } - - fn visit_u64(self, value: u64) -> Result - where - E: serde::de::Error, - { - Ok(Self::from(value)) - } - - fn visit_str(self, value: &str) -> Result - where - E: serde::de::Error, - { - match Murmur64::try_from(value) { - Ok(hash) => Ok(hash), - Err(err) => Err(E::custom(format!( - "failed to convert '{value}' to Murmur64: {err}" - ))), - } - } -} - -impl<'de> Deserialize<'de> for Murmur64 { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - deserializer.deserialize_any(Self(0)) - } -} - -impl Serialize for Murmur64 { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_str(&format!("{self:016X}")) - } -} - -#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] -pub struct Murmur32(u32); - -impl Murmur32 { - pub fn hash(s: B) -> Self - where - B: AsRef<[u8]>, - { - hash32(s.as_ref(), SEED).into() - } -} - -impl From for Murmur32 { - fn from(value: u32) -> Self { - Self(value) - } -} - -impl From for u32 { - fn from(value: Murmur32) -> Self { - value.0 - } -} - -impl TryFrom<&str> for Murmur32 { - type Error = Report; - - fn try_from(value: &str) -> Result { - parse_hex32(value) - .map(Self) - .wrap_err_with(|| format!("Failed to convert value to Murmur32: {value}")) - } -} - -impl fmt::UpperHex for Murmur32 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::UpperHex::fmt(&self.0, f) - } -} - -impl fmt::LowerHex for Murmur32 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::LowerHex::fmt(&self.0, f) - } -} - -impl fmt::Display for Murmur32 { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{self:08X}") - } -} - -impl Serialize for Murmur32 { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_str(&format!("{self:08X}")) - } -} - -impl<'de> Visitor<'de> for Murmur32 { - type Value = Self; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str( - "an usigned 32 bit integer \ - or a string in hexadecimal format encoding such an integer", - ) - } - - fn visit_f64(self, value: f64) -> Result - where - E: serde::de::Error, - { - let bytes = value.to_le_bytes(); - self.visit_u32(u64::from_le_bytes(bytes) as u32) - } - - fn visit_u64(self, value: u64) -> Result - where - E: serde::de::Error, - { - self.visit_u32(value as u32) - } - - fn visit_u32(self, value: u32) -> Result - where - E: serde::de::Error, - { - Ok(Self::from(value)) - } - - fn visit_str(self, value: &str) -> Result - where - E: serde::de::Error, - { - match Murmur32::try_from(value) { - Ok(hash) => Ok(hash), - Err(err) => Err(E::custom(format!( - "failed to convert '{value}' to Murmur32: {err}" - ))), - } - } -} - -impl<'de> Deserialize<'de> for Murmur32 { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - deserializer.deserialize_any(Self(0)) - } -} diff --git a/lib/sdk/src/murmur/util.rs b/lib/sdk/src/murmur/util.rs deleted file mode 100644 index 134c4e7..0000000 --- a/lib/sdk/src/murmur/util.rs +++ /dev/null @@ -1,132 +0,0 @@ -use color_eyre::eyre::bail; -use color_eyre::Result; - -// Generates tables similar to these: -// https://github.com/zbjornson/fast-hex/blob/a3487bca95127634a61bfeae8f8bfc8f0e5baa3f/src/hex.cc#L20-L89 -// `upper` determines upper vs. lower bits (first character is `upper`). -const fn generate_byte_map(upper: bool) -> [u8; 256] { - let mut out = [0u8; 256]; - let factor = if upper { 16 } else { 1 }; - - let mut i = 0; - - while i < 256 { - match i { - 0x30..=0x39 => out[i] = factor * (i as u8 - 0x30), - 0x41..=0x46 => out[i] = factor * (9 + i as u8 - 0x40), - 0x61..=0x66 => out[i] = factor * (9 + i as u8 - 0x60), - _ => out[i] = u8::MAX, - } - i += 1; - } - - out -} - -const BYTE_MAP_UPPER: [u8; 256] = generate_byte_map(true); -const BYTE_MAP_LOWER: [u8; 256] = generate_byte_map(false); - -macro_rules! make_parse_hex { - ($name:ident, $ty:ty, $len:expr) => { - #[inline] - pub fn $name(s: impl AsRef) -> Result<$ty> { - // For the string to be valid hex characters, it needs to be ASCII. - // So we can simply treat it as a byte stream. - let s = s.as_ref().as_bytes(); - - if s.len() != $len { - bail!( - "String length doesn't match. Expected {}, got {}", - $len, - s.len() - ); - } - - let n = $len / 2; - let mut out: $ty = 0; - let mut i = 0; - - while i < n { - let j = i * 2; - - let c1 = BYTE_MAP_UPPER[s[j] as usize]; - if c1 == u8::MAX { - bail!("Invalid character '{:?}' ({})", char::from(c1), c1); - } - - let c2 = BYTE_MAP_LOWER[s[j + 1] as usize]; - if c2 == u8::MAX { - bail!("Invalid character '{:?}' ({})", char::from(c2), c2); - } - - out |= ((c1 + c2) as $ty) << (n - i - 1) * 8; - - i += 1; - } - - Ok(out) - } - }; -} - -make_parse_hex!(parse_hex64, u64, 16); -make_parse_hex!(parse_hex32, u32, 8); - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn parse_32() { - let hash = "A14E8DFA"; - assert_eq!(parse_hex32(hash).unwrap(), 0xA14E8DFA); - } - - #[test] - fn parse_64() { - let hash = "A14E8DFA2CD117E2"; - assert_eq!(parse_hex64(hash).unwrap(), 0xA14E8DFA2CD117E2); - } - - #[test] - fn std_from_radix_32() { - let hash = "A14E8DFA"; - assert_eq!(u32::from_str_radix(hash, 16).unwrap(), 0xA14E8DFA); - } - - #[test] - fn std_from_radix_64() { - let hash = "A14E8DFA2CD117E2"; - assert_eq!(u64::from_str_radix(hash, 16).unwrap(), 0xA14E8DFA2CD117E2); - } -} - -#[cfg(test)] -mod bench { - use super::{parse_hex32, parse_hex64}; - - extern crate test; - - const HASH32: &str = "A14E8DFA"; - const HASH64: &str = "A14E8DFA2CD117E2"; - - #[bench] - fn custom_32(b: &mut test::Bencher) { - b.iter(|| test::black_box(parse_hex32(test::black_box(HASH32)))) - } - - #[bench] - fn std_32(b: &mut test::Bencher) { - b.iter(|| test::black_box(u32::from_str_radix(test::black_box(HASH32), 16))) - } - - #[bench] - fn custom_64(b: &mut test::Bencher) { - b.iter(|| test::black_box(parse_hex64(test::black_box(HASH64)))) - } - - #[bench] - fn std_64(b: &mut test::Bencher) { - b.iter(|| test::black_box(u64::from_str_radix(test::black_box(HASH64), 16))) - } -} diff --git a/lib/serde_sjson b/lib/serde_sjson new file mode 160000 index 0000000..e94218d --- /dev/null +++ b/lib/serde_sjson @@ -0,0 +1 @@ +Subproject commit e94218d8f52a51529c83af33a99cc17f66caae2e