From 01497d35cadb10280201d81509f5f16b9c2cf077 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Wed, 10 May 2023 02:53:03 +0300 Subject: [PATCH] add MegaLinter, .editorconfig and style fixes --- .editorconfig | 31 ++++ .github/workflows/docs-autoupdate.yml | 88 ++++++----- .github/workflows/mega-linter.yml | 73 +++++++++ .github/workflows/shellcheck-dev.yml | 20 --- .github/workflows/shellcheck-master.yml | 19 --- .github/workflows/shellcheck.yml | 22 +++ .gitignore | 4 +- .shellcheck/builder.cfg | 4 +- README.md | 31 ++-- TODO.md | 2 +- USAGE.md | 2 +- builder | 192 ++++++++++++------------ 12 files changed, 291 insertions(+), 197 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/mega-linter.yml delete mode 100644 .github/workflows/shellcheck-dev.yml delete mode 100644 .github/workflows/shellcheck-master.yml create mode 100644 .github/workflows/shellcheck.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6d0bef4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,31 @@ +root = true + +# Global +[*] +indent_style = unset +indent_size = 4 +tab_width = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = unset + +# Source +[*.{sh,bash,dash,ksh}] +indent_style = tab +insert_final_newline = true + +[builder] +insert_final_newline = true + +# Other +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_style = space +indent_size = 2 +insert_final_newline = true + +[*.{txt,cfg,conf}] +indent_style = tab diff --git a/.github/workflows/docs-autoupdate.yml b/.github/workflows/docs-autoupdate.yml index 21e1d6f..c87bf14 100644 --- a/.github/workflows/docs-autoupdate.yml +++ b/.github/workflows/docs-autoupdate.yml @@ -1,41 +1,47 @@ -name: docs-autoupdate - -on: - push: - branches: - - '*' - -jobs: - update-docs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Update docs - run: | - if ! [[ -e USAGE.md ]]; then touch USAGE.md; fi - mv USAGE.md USAGE.md.old - mkdir tools - cp ./builder ./tools/ - chmod +x ./tools/builder - echo '# KF2-BuildTools' >> USAGE.md - echo '[![title](https://img.shields.io/badge/Help-Page-w)](https://github.com/GenZmeY/KF2-BuildTools)' >> USAGE.md - echo '[![version](https://img.shields.io/github/v/tag/genzmey/KF2-BuildTools)](https://github.com/GenZmeY/KF2-BuildTools/tags)' >> USAGE.md - echo '[![docs-autoupdate](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml/badge.svg)](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml)' >> USAGE.md - echo '```' >> USAGE.md - ./tools/builder -nch >> USAGE.md - echo '```' >> USAGE.md - if ! cmp -s USAGE.md USAGE.md.old; then - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions" - git add USAGE.md - git commit -m "Update USAGE.md to version $(git describe 2> /dev/null)" - else - echo "No change, skip updating USAGE.md" - fi - - name: Push changes - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ github.ref }} \ No newline at end of file +--- +name: docs-autoupdate + +# checkov:skip=CKV2_GHA_1:Write permission is needed to push changes to the repository +permissions: write-all + +on: + push: + branches: + - '*' + +jobs: + update-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Update docs + run: | + if ! [[ -e USAGE.md ]]; then touch USAGE.md; fi + mv USAGE.md USAGE.md.old + mkdir tools + cp ./builder ./tools/ + chmod +x ./tools/builder + { + echo '# KF2-BuildTools' + echo '[![title](https://img.shields.io/badge/Help-Page-w)](https://github.com/GenZmeY/KF2-BuildTools)' + echo '[![version](https://img.shields.io/github/v/tag/genzmey/KF2-BuildTools)](https://github.com/GenZmeY/KF2-BuildTools/tags)' + echo '[![docs-autoupdate](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml/badge.svg)](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml)' + echo '```text' + ./tools/builder -nch + echo '```' + } >> USAGE.md + if ! cmp -s USAGE.md USAGE.md.old; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions" + git add USAGE.md + git commit -m "Update USAGE.md to version $(git describe 2> /dev/null)" + else + echo "No change, skip updating USAGE.md" + fi + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 0000000..df1a40b --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,73 @@ +--- +name: MegaLinter + +permissions: read-all + +on: + push: + pull_request: + branches: [master] + +env: + APPLY_FIXES: none + APPLY_FIXES_EVENT: pull_request + APPLY_FIXES_MODE: commit + DISABLE: SPELL + DISABLE_ERRORS_LINTERS: REPOSITORY_CHECKOV # Barks at write-permission on docs-autoupdate.yml which I need + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + build: + name: MegaLinter + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + + - name: MegaLinter + id: ml + uses: oxsecurity/megalinter@v6 + env: + VALIDATE_ALL_CODEBASE: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Archive production artifacts + if: ${{ success() }} || ${{ failure() }} + uses: actions/upload-artifact@v3 + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log + + - name: Create Pull Request with applied fixes + id: cpr + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + commit-message: "[MegaLinter] Apply linters automatic fixes" + title: "[MegaLinter] Apply linters automatic fixes" + labels: bot + - name: Create PR output + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" + + - name: Prepare commit + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + run: sudo chown -Rc $UID .git/ + - name: Commit and push applied linter fixes + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} + commit_message: "[MegaLinter] Apply linters fixes" + commit_user_name: megalinter-bot + commit_user_email: nicolas.vuillamy@ox.security diff --git a/.github/workflows/shellcheck-dev.yml b/.github/workflows/shellcheck-dev.yml deleted file mode 100644 index 45d88ee..0000000 --- a/.github/workflows/shellcheck-dev.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: shellcheck-dev - -on: - push: - branches: - - '*' - - '!master' - -jobs: - shellcheck: - name: shellcheck - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master - env: - SHELLCHECK_OPTS: -x - with: - additional_files: 'builder' \ No newline at end of file diff --git a/.github/workflows/shellcheck-master.yml b/.github/workflows/shellcheck-master.yml deleted file mode 100644 index 130bad2..0000000 --- a/.github/workflows/shellcheck-master.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: shellcheck - -on: - push: - branches: - - master - -jobs: - shellcheck: - name: shellcheck - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master - env: - SHELLCHECK_OPTS: -x - with: - additional_files: 'builder' \ No newline at end of file diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..ff50aa2 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,22 @@ +--- +name: shellcheck + +permissions: read-all + +on: + push: + branches: + - master + +jobs: + shellcheck: + name: shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + env: + SHELLCHECK_OPTS: -x + with: + additional_files: 'builder' diff --git a/.gitignore b/.gitignore index dc23619..94b936f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -3rd-party-bin -shellcheck.exe +3rd-party-bin +shellcheck.exe diff --git a/.shellcheck/builder.cfg b/.shellcheck/builder.cfg index ec62fd3..713c967 100644 --- a/.shellcheck/builder.cfg +++ b/.shellcheck/builder.cfg @@ -7,7 +7,7 @@ StripSource="True" # Mutators to be compiled # Specify them with a space as a separator, -# Mutators will be compiled in the specified order +# Mutators will be compiled in the specified order PackageBuildOrder="SomePackageName SomePackageNameMut" @@ -15,7 +15,7 @@ PackageBuildOrder="SomePackageName SomePackageNameMut" # Mutators that will be uploaded to the workshop # Specify them with a space as a separator, -# The order doesn't matter +# The order doesn't matter PackageUpload="SomePackageName SomePackageNameMut" diff --git a/README.md b/README.md index 9fc01e8..4ddcb46 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,27 @@ # KF2-BuildTools [![version](https://img.shields.io/github/v/tag/genzmey/KF2-BuildTools)](https://github.com/GenZmeY/KF2-BuildTools/tags) [![shellcheck](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/shellcheck-master.yml/badge.svg)](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/shellcheck-master.yml) +[![MegaLinter](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/mega-linter.yml/badge.svg?branch=master)](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/mega-linter.yml) [![docs-autoupdate](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml/badge.svg)](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml) [![license](https://img.shields.io/github/license/GenZmeY/KF2-Server-Extension)](LICENSE) -# Features: +## Features - Build, brew, test and upload to Steam Workshop; - No need to edit KFEditor.ini at all; - Sources can be stored in any path; - Easily switch between different projects. -# Requirements +## Requirements - [Killing Floor 2](https://store.steampowered.com/app/232090/Killing_Floor_2/); - Killing Floor 2 - SDK; - [git-bash](https://git-scm.com/download/win). -# Add to your project +## Add to your project Make sure that the location of folders and files in your project as follows (Correct it if it's not): `//Classes/*.uc` **There are two ways to add KF2-BuildTools to your project:** -## 1. As [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) +### 1. As [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) Open git-bash and go to your project: `cd ` Add submodule: `git submodule add https://github.com/GenZmeY/KF2-BuildTools tools` @@ -28,18 +29,18 @@ Add submodule: `git submodule add https://github.com/GenZmeY/KF2-BuildTools tool Get updates: `pushd tools && git pull && popd` Commit the changes: `git add tools && git commit -m 'update tools'` -## 2. As standalone script +### 2. As standalone script Just create a `tools` folder and put [builder](builder) there. Now you can use the script in the same way as in the first case, but you will have to update it yourself. -# Usage +## Usage Available commands can be found here: [USAGE.md](USAGE.md) If you have a simple mutator or game mode, then the usage is also simple: just use [the commands](USAGE.md) to compile, test and upload to the steam workshop. ![demo](example.gif) -## The result can be found here: +### The result can be found here **Compiled packages:** `C:\Users\\Documents\My Games\KillingFloor2\KFGame\Unpublished\` @@ -49,20 +50,20 @@ If you have a simple mutator or game mode, then the usage is also simple: just u **Uploaded packages:** your steam workshop 🙃 -# Usage (Advanced) -If your project contains several mutators, *.upk files, external dependencies, or you want to customize the whole process in more details, then this section is for you. +## Usage (Advanced) +If your project contains several mutators, *.upk files, external dependencies, or you want to customize the whole process in more details, then this section is for you. -## Setup +### Setup When you run compilation for the first time or do `./tools/builder --init` `builder.cfg` appears in your project folder. Edit it to set build/test/upload options. The config contains the necessary comments inside. Edit the files in the `PublicationContent` folder - they are responsible for the description in the Steam Workshop. -## Project filesystem +### Project filesystem If you have *.upk or localization files, they must be in a specific location. Change the filesystem of the project to such a form that everything works correctly: -``` +```text /SomePackageName1 *.upk /Classes @@ -84,7 +85,7 @@ Change the filesystem of the project to such a form that everything works correc /Config *.ini /BrewedPC - *.* + *.* /tools builder builder.cfg @@ -93,7 +94,7 @@ builder.cfg **Note:** Use the `BrewedPC` folder for additional content such as sound files for your weapons or other stuff. This will be copied to the final BrewedPC before being uploaded to the workshop. By the way, this allows you to use a script to upload maps (although this was not its original purpose). Just put the map(s) in `BrewedPC` (don't forget to edit the `PublicationContent`) and run `./tools/builder -u`. -## Examples (Projects that use KF2-BuildTools) +### Examples (Projects that use KF2-BuildTools) **Simplest case (one mutator):** - [AdminAutoLogin](https://github.com/GenZmeY/KF2-AdminAutoLogin) - [StartWave](https://github.com/GenZmeY/KF2-StartWave) @@ -112,5 +113,5 @@ By the way, this allows you to use a script to upload maps (although this was no **two mutators are uploaded to the steam workshop:** - [UnofficialMod](https://github.com/GenZmeY/UnofficialMod) -# License +## License [GNU GPLv3](LICENSE) diff --git a/TODO.md b/TODO.md index 62e4250..b25e7a3 100644 --- a/TODO.md +++ b/TODO.md @@ -1,2 +1,2 @@ -# TODO: +# TODO - [ ] improve error parser (class vs name mismatch, etc...) diff --git a/USAGE.md b/USAGE.md index d15b691..607161f 100644 --- a/USAGE.md +++ b/USAGE.md @@ -2,7 +2,7 @@ [![title](https://img.shields.io/badge/Help-Page-w)](https://github.com/GenZmeY/KF2-BuildTools) [![version](https://img.shields.io/github/v/tag/genzmey/KF2-BuildTools)](https://github.com/GenZmeY/KF2-BuildTools/tags) [![docs-autoupdate](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml/badge.svg)](https://github.com/GenZmeY/KF2-BuildTools/actions/workflows/docs-autoupdate.yml) -``` +```text Usage: ./tools/builder OPTIONS Compile, brew, test and upload your kf2 packages to the Steam Workshop. diff --git a/builder b/builder index 478f889..6348fea 100644 --- a/builder +++ b/builder @@ -37,11 +37,11 @@ function reg_readkey () # $1: path, $2: key function steamlib_by_steamid () # $1: SteamID { local Path - + if ! [[ -f "$SteamLibFoldersVdf" ]]; then return fi - + while read -r Line do if echo "$Line" | grep -Foq '"path"'; then @@ -154,7 +154,7 @@ function get_latest () # $1: Reponame, $2: filename, $3: output filename local LatestTag="" LatestTag="$(curl --silent "$ApiUrl" | grep -Po '"tag_name": "\K.*?(?=")')" local DownloadUrl="https://github.com/$1/releases/download/$LatestTag/$2" - + msg "download $2 ($LatestTag)" mkdir -p "$(dirname "$3")/" curl -LJs "$DownloadUrl" -o "$3" @@ -176,7 +176,7 @@ function repo_url () # $1: remote.origin.url if echo "$1" | grep -qoP '^https?://'; then echo "$1" | sed -r 's|\.git||' else - echo "$1" | sed -r 's|^.+:(.+)\.git$|https://github.com/\1|' + echo "$1" | sed -r 's|^.+:(.+)\.git$|https://github.com/\1|' fi } @@ -224,7 +224,7 @@ function warn () # $1: String function usage () { local HelpMessage="" - + HelpMessage="$(cat < "$MutBuilderConfig" < "$MutPubContentTitle" msg "$(basename "$MutPubContentTitle") created" "${GRN}" fi - + if is_true "$ArgForce" || ! [[ -e "$MutPubContentDescription" ]]; then :> "$MutPubContentDescription" if [[ -n "$AviableGamemodes" ]] || [[ -n "$AviableMutators" ]] || [[ -n "$AviableMaps" ]]; then @@ -517,7 +517,7 @@ EOF fi echo "" >> "$MutPubContentDescription" fi - + GitRemoteUrl="$(repo_url "$(git config --get remote.origin.url)")" if [[ -n "$GitRemoteUrl" ]]; then { @@ -526,7 +526,7 @@ EOF echo "" } >> "$MutPubContentDescription" fi - + GitUsername="$(git config --get user.name)" if [[ -n "$GitUsername" ]]; then { @@ -535,10 +535,10 @@ EOF echo "" } >> "$MutPubContentDescription" fi - + msg "$(basename "$MutPubContentDescription") created" "${GRN}" fi - + if is_true "$ArgForce" || [[ "$(preview_extension)" == "None" ]]; then if [[ -e "$DummyPreview" ]]; then cp -f "$DummyPreview" "${MutPubContentPreview}.png" @@ -547,7 +547,7 @@ EOF fi msg "$(basename "${MutPubContentPreview}.png") created" "${GRN}" fi - + if is_true "$ArgForce" || ! [[ -e "$MutPubContentTags" ]]; then :> "$MutPubContentTags" if [[ -n "$AviableGamemodes" ]]; then @@ -574,14 +574,14 @@ function preview_extension () return 0 fi done - + echo "None" } function read_settings () { if ! [[ -f "$MutBuilderConfig" ]]; then init; fi - + if bash -n "$MutBuilderConfig"; then # shellcheck source=./.shellcheck/builder.cfg source "$MutBuilderConfig" @@ -595,9 +595,9 @@ function merge_package () # $1: What, $2: Where local ModificationTime="" local ModificationTimeNew="" local PID="" - + msg "merge $1 into $2" - + if is_true "$ArgHoldEditor"; then pushd "$KFWin64" &> /dev/null CMD //C "$(basename "$KFEditorMergePackages")" make "$1" "$2" @@ -627,16 +627,16 @@ function merge_package () # $1: What, $2: Where sleep 1 done fi - + rm -f "$KFWin64/$1" # cleanup (manual) } function merge_packages () # $1: Mutator name { msg "merge packages for $1.u" - + cp -f "$KFUnpublishScript/$1.u" "$KFWin64" - + while read -r Upk do cp -f "$Upk" "$KFWin64" @@ -653,7 +653,7 @@ function parse_log () # $1: Logfile local Message='' local I=1 - if grep -qP ' Error:(.+:)? Error, ' "$1"; then # check to prevent a very strange crash + if grep -qP ' Error:(.+:)? Error, ' "$1"; then # check to prevent a very strange crash while read -r Error do if [[ -z "$Error" ]]; then break; fi @@ -670,7 +670,7 @@ function parse_log () # $1: Logfile ((I+=1)) done < <(grep -P ' Error:(.+:)? Error, ' "$1") fi - + if grep -qP ' Warning:(.+:)? Warning, ' "$1"; then # and here too while read -r Warning do @@ -711,49 +711,49 @@ function compile () local StripSourceArg="" local PID="" local Logfile="" - + read_settings if ! command -v multini &> /dev/null; then get_latest_multini "$ThirdPartyBin/multini.exe" fi - + if [[ -z "$PackageBuildOrder" ]]; then die "No packages found! Check project filesystem, fix config and try again" fi - + multini --del "$KFEditorConf" 'ModPackages' 'ModPackages' for Package in $PackageBuildOrder do multini --add "$KFEditorConf" 'ModPackages' 'ModPackages' "$Package" done multini --set "$KFEditorConf" 'ModPackages' 'ModPackagesInPath' "$(cygpath -w "$MutSource")" - + rm -rf "$KFUnpublish" "$KFPublish" - + mkdir -p "$KFUnpublishPackages" "$KFUnpublishScript" - + for Package in $PackageBuildOrder do find "$MutSource/$Package" -type f -iname '*.upk' -not -ipath "*/Weapons/*" -exec cp -f {} "$KFUnpublishPackages" \; find "$MutSource/$Package" -type d -iname 'WwiseAudio' -exec cp -rf {} "$KFUnpublishBrewedPC" \; find "$MutSource/$Package" -type d -iname 'Weapons' -exec cp -rf {} "$KFUnpublishPackages" \; done - + if [[ -d "$MutLocalization" ]]; then mkdir -p "$KFUnpublishLocalization" cp -rf "$MutLocalization"/* "$KFUnpublishLocalization" fi - + if [[ -d "$MutConfig" ]]; then mkdir -p "$KFUnpublishConfig" cp -rf "$MutConfig"/* "$KFUnpublishConfig" fi - + if is_true "$StripSource"; then StripSourceArg="-stripsource"; fi - + msg "compilation" - + if is_true "$ArgHoldEditor"; then CMD //C "$(cygpath -w "$KFEditor")" make $StripSourceArg -useunpublished parse_log "$(find_log)" @@ -770,7 +770,7 @@ function compile () Logfile="$(find_log)" if compiled; then msg "successfully compiled" "${GRN}" - + msg "wait for the log" while ! grep -qF 'Log file closed' "$Logfile" do @@ -786,7 +786,7 @@ function compile () fi done fi - + find "$KFUnpublish" -type d -empty -delete } @@ -796,12 +796,12 @@ function publish_common () mkdir -p "$KFPublishLocalization" cp -rf "$MutLocalization"/* "$KFPublishLocalization" fi - + if [[ -d "$MutConfig" ]]; then mkdir -p "$KFPublishConfig" cp -rf "$MutConfig"/* "$KFPublishConfig" fi - + if [[ -d "$MutBrewedPCAddon" ]]; then mkdir -p "$KFPublishBrewedPC" cp -rf "$MutBrewedPCAddon"/* "$KFPublishBrewedPC" @@ -833,15 +833,15 @@ function brew () { local PackageBrew="" local PID="" - + msg "brewing" - + read_settings - + if ! compiled; then die "You must compile packages before brewing. Use --compile option for this." 2 fi - + if [[ -z "$PackagePeelzBrew" ]]; then PackageBrew="$PackageBuildOrder" else @@ -852,17 +852,17 @@ function brew () fi done fi - + rm -rf "$KFPublish" - + mkdir -p "$KFPublishBrewedPC" "$KFPublishPackages" - + for Package in $PackageBuildOrder do find "$MutSource/$Package" -type d -iname 'WwiseAudio' -exec cp -rf {} "$KFPublishBrewedPC" \; find "$MutSource/$Package" -type d -iname 'Weapons' -exec cp -rf {} "$KFPublishPackages" \; done - + if [[ -n "$PackageBrew" ]]; then if is_true "$ArgHoldEditor"; then pushd "$KFWin64" &> /dev/null @@ -887,20 +887,20 @@ function brew () die "brewing failed" fi fi - + if [[ -n "$PackagePeelzBrew" ]]; then msg "peelz brewing" - + if ! [[ -x "$KFEditorPatcher" ]]; then get_latest_kfeditor_patcher "$KFEditorPatcher" fi - + msg "patching $(basename "$KFEditor")" pushd "$KFWin64" &> /dev/null CMD //C "$(basename "$KFEditorPatcher")" popd &> /dev/null msg "successfully patched" "${GRN}" - + for Package in $PackagePeelzBrew do merge_packages "$Package" @@ -908,20 +908,20 @@ function brew () find "$MutSource/$Package" -type f -iname '*.upk' -not -ipath '*/Weapons/*' -printf "%f\n" | xargs -I{} find "$KFPublishBrewedPC" -type f -iname {} -delete done fi - + msg "successfully brewed" "${GRN}" - + rm -f "$KFPublishBrewedPC"/*.tmp - + find "$KFPublish" -type d -empty -delete } function publish_unpublished () { warn "uploading without brewing${DEF}" - + mkdir -p "$KFPublishBrewedPC" "$KFPublishScript" "$KFPublishPackages" - + for Package in $PackageUpload do cp -f "$KFUnpublishScript/$Package.u" "$KFPublishScript" @@ -929,7 +929,7 @@ function publish_unpublished () find "$MutSource/$Package" -type d -iname 'WwiseAudio' -exec cp -rf {} "$KFPublishBrewedPC" \; find "$MutSource/$Package" -type d -iname 'Weapons' -exec cp -rf {} "$KFPublishPackages" \; done - + find "$KFPublish" -type d -empty -delete } @@ -938,36 +938,36 @@ function upload () local PreparedWsDir="" local Preview="" local Success="False" - + read_settings - + if ! compiled && ! test -d "$MutBrewedPCAddon"; then die "You must compile packages before uploading. Use --compile option for this." 2 fi - + if [[ -d "$KFPublish" ]]; then brew_cleanup elif [[ -d "$KFUnpublish" ]]; then publish_unpublished fi - + publish_common - + Preview="${MutPubContentPreview}.$(preview_extension)" - + if ! [[ -e "$Preview" ]]; then die "No preview image in PublicationContent" 2 elif [[ $(stat --printf="%s" "$Preview") -ge 1048576 ]]; then warn "The size of $(basename "$Preview") is greater than 1mb. Steam may prevent you from loading content with this image. if you get an error while loading - try using a smaller preview." fi - + if grep -Fq '"' "$MutPubContentDescription"; then warn "Double quotes (\") found in $(basename "$MutPubContentDescription"), this may prevent the item from being uploaded to the workshop" warn "Remove double quotes if there are problems uploading to the workshop" fi - + find "$KFPublish" -type d -empty -delete - + # it's a bad idea to use the $KFPublish folder for upload # because in that case some files won't get uploaded to the workshop for some reason # so create a temporary folder to get around this @@ -981,9 +981,9 @@ function upload () \$MicroTxItem "false" \$PackageDirectory "$(cygpath -w "$PreparedWsDir")" EOF - + cp -rf "$KFPublish" "$PreparedWsDir" - + msg "upload to steam workshop" while read -r Output do @@ -994,10 +994,10 @@ EOF err "UploadTool: $Output" fi done < <("$KFWorkshop" "$(basename "$MutWsInfo")" 2>&1) - + rm -rf "$PreparedWsDir" rm -f "$MutWsInfo" - + if is_true "$Success"; then msg "successfully uploaded to steam workshop" "${GRN}" else @@ -1008,16 +1008,16 @@ EOF function run_test () { local UseUnpublished="" - + read_settings - + if brewed "$PackageBuildOrder"; then msg "run test (brewed)" else UseUnpublished="-useunpublished" msg "run test (unpublished)" fi - + CMD //C "$(cygpath -w "$KFGame")" "$Map?Difficulty=$Difficulty?GameLength=$GameLength?Game=$Game?Mutator=$Mutators?$Args" $UseUnpublished -log } @@ -1026,7 +1026,7 @@ function parse_combined_params () # $1: Combined short parameters local Param="${1}" local Length="${#Param}" local Position=1 - + while true do if [[ "$Position" -ge "$Length" ]]; then break; fi @@ -1034,7 +1034,7 @@ function parse_combined_params () # $1: Combined short parameters he ) ((Position+=2)); ArgHoldEditor="true" ;; nc ) ((Position+=2)); ArgNoColors="true" ;; esac - + if [[ "$Position" -ge "$Length" ]]; then break; fi case "${Param:$Position:1}" in h ) ((Position+=1)); ArgHelp="true" ;; @@ -1083,41 +1083,41 @@ function main () parse_params "$@" setup_colors export PATH="$PATH:$ThirdPartyBin" - + # Modifiers if is_true "$ArgDebug"; then set -o xtrace; fi - + # Help if is_true "$ArgVersion" && is_true "$ArgHelp"; then version; usage; die "" 0; fi if is_true "$ArgVersion"; then version; die "" 0; fi if is_true "$ArgHelp"; then usage; die "" 0; fi - + # Checks if [[ -z "$KFSteamLibraryFolder" ]]; then err "\"Killing Floor 2\" not found" fi - + if [[ -z "$KFSDKSteamLibraryFolder" ]]; then err "\"Killing Floor 2 - SDK\" not found" fi - + if [[ -z "$KFSteamLibraryFolder" ]] || [[ -z "$KFSDKSteamLibraryFolder" ]]; then die "" 1 elif [[ "$KFPath" != "$KFSDKPath" ]]; then warn "\"Killing Floor 2\" and \"Killing Floor 2 - SDK\" installed in different steam library folders." warn "If you get errors, install them in the same steam library folder." fi - + # Backup if is_true "$ArgCompile" || is_true "$ArgBrew"; then backup_kfeditorconf; fi - + # Actions if is_true "$ArgInit"; then init; fi if is_true "$ArgCompile"; then compile; fi if is_true "$ArgBrew"; then brew; fi if is_true "$ArgUpload"; then upload; fi if is_true "$ArgTest"; then run_test; fi - + # Restore if is_true "$ArgCompile" || is_true "$ArgBrew"; then restore_kfeditorconf; fi }