[
  {
    "path": ".editorconfig",
    "content": "# EditorConfig (is awesome): http://EditorConfig.org\r\n\r\n# * top-most EditorConfig file\r\nroot = true\r\n\r\n# default style settings\r\n[*]\r\ncharset = utf-8\r\nend_of_line = crlf\r\nindent_size = 4\r\nindent_style = space\r\ninsert_final_newline = true\r\ntrim_trailing_whitespace = true\r\n\r\n[*.{[Bb][Aa][Tt],[Cc][Mm][Dd]}]\r\n# DOS/Win *requires* BAT/CMD files to have CRLF newlines\r\nend_of_line = crlf\r\n\r\n[*.{yml, yaml}]\r\nindent_size = 2\r\n\r\n# Makefiles require tab indentation\r\n[{{M,m,GNU}akefile{,.*},*.mak,*.mk}]\r\nindent_style = tab\r\nend_of_line = lf\r\n"
  },
  {
    "path": ".gitattributes",
    "content": "# retain windows line-endings in case checked out on mac or linux\r\n* text eol=crlf\r\n*.exe -text\r\n*.zip -text\r\n*.dll -text\r\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/Bug_report.md",
    "content": "---\r\nname: \"Bug Report\"\r\nabout: \"I am facing some problems.\"\r\ntitle: '[Bug] '\r\nlabels: \"bug\"\r\n\r\n---\r\n\r\n<!--\r\n  IMPORTANT:\r\n  If your problem is related to a specific package, open the issue in the relevant bucket,\r\n  not here.\r\n  By opening this issue you confirm that you have searched for similar issues/PRs here already.\r\n  Failing to do so will most likely result in closing of this issue without any explanation.\r\n  Incomplete form details below might also result in closing of the issue.\r\n-->\r\n\r\n## Bug Report\r\n\r\n#### Current Behavior\r\n<!-- A clear and concise description of the behavior. -->\r\n\r\n#### Expected Behavior\r\n<!-- A clear and concise description of what you expected to happen. -->\r\n\r\n#### Additional context/output\r\n<!-- Add any other context about the problem here. If applicable, paste terminal output here to help explain. -->\r\n\r\n#### Possible Solution\r\n<!--- Only if you have suggestions on a fix for the bug -->\r\n\r\n### System details\r\n\r\n**Windows version:** [e.g. 7, 8, 10, 11]\r\n\r\n**OS architecture:** [e.g. 32bit, 64bit, arm64]\r\n\r\n**PowerShell version:** [output of `\"$($PSVersionTable.PSVersion)\"`]\r\n\r\n**Additional software:** [(optional) e.g. ConEmu, Git]\r\n\r\n#### Scoop Configuration\r\n<!-- Can be found in  ~/.config/scoop/config.json -->\r\n\r\n```json\r\n//# Your configuration here\r\n```\r\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/Feature_request.md",
    "content": "---\r\nname: \"Feature Request\"\r\nabout: \"I have a suggestion (and may want to implement it)!\"\r\ntitle: '[Feature] '\r\nlabels: \"enhancement\"\r\n\r\n---\r\n\r\n<!--\r\n  IMPORTANT:\r\n  If your request is related to a specific package, open the issue in the relevant bucket,\r\n  not here.\r\n  By opening this issue you confirm that you have searched for similar issues/PRs here already.\r\n  Failing to do so will most likely result in closing of this issue without any explanation.\r\n  Incomplete form details below might also result in closing of the issue.\r\n-->\r\n\r\n## Feature Request\r\n\r\n#### Is your feature request related to a problem? Please describe.\r\n<!-- A clear and concise description of what the problem is. Ex. I have an issue when [...] -->\r\n\r\n#### Describe the solution you'd like\r\n<!-- A clear and concise description of what you want to happen. Add any considered drawbacks. -->\r\n\r\n#### Describe alternatives you've considered\r\n<!-- A clear and concise description of any alternative solutions or features you've considered. -->\r\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: false\r\n\r\n"
  },
  {
    "path": ".github/PULL_REQUEST_TEMPLATE.md",
    "content": "<!-- Provide a general summary of your changes in the Title above -->\r\n<!-- To help with semantic versioning the PR title should start with one of the conventional commit types. -->\r\n<!-- The conventional commit types for Semantic PR are: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert -->\r\n\r\n<!--\r\n  By opening this PR you confirm that you have searched for similar issues/PRs here already.\r\n  Failing to do so will most likely result in closing of this PR without any explanation.\r\n  It is also mandatory to open a relevant issue for discussion with the maintainers,\r\n  before creating any new PR.\r\n  Read the contributing guide first to save both your and our time.\r\n-->\r\n\r\n#### Description\r\n<!-- Describe your changes in detail -->\r\n\r\n#### Motivation and Context\r\n<!-- Why is this change required? What problem does it solve? -->\r\n<!-- If it fixes an open issue, please link to the issue here. -->\r\nCloses #XXXX\r\n<!-- or -->\r\nRelates to #XXXX\r\n\r\n#### How Has This Been Tested?\r\n<!-- Please describe in detail how you tested your changes. -->\r\n<!-- Include details of your testing environment, tests ran to see how -->\r\n<!-- your change affects other areas of the code, etc. -->\r\n\r\n#### Checklist:\r\n<!-- Go over all the following points, and put an `x` in all the boxes that apply. -->\r\n<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->\r\n- [ ] I have read the [Contributing Guide](https://github.com/ScoopInstaller/.github/blob/main/.github/CONTRIBUTING.md).\r\n- [ ] I have ensured that I am targeting the `develop` branch.\r\n- [ ] I have updated the documentation accordingly.\r\n- [ ] I have updated the tests accordingly.\r\n- [ ] I have added an entry in the CHANGELOG.\r\n"
  },
  {
    "path": ".github/dependabot.yml",
    "content": "---\r\n# ~/.github/dependabot.yml\r\nversion: 2\r\nupdates:\r\n  - package-ecosystem: \"github-actions\"\r\n    directory: \"/\" # == /.github/workflows/\r\n    schedule:\r\n      interval: \"daily\"\r\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: Scoop Core CI Tests\r\n\r\non:\r\n  pull_request:\r\n  workflow_dispatch:\r\n\r\njobs:\r\n  test_powershell:\r\n    name: WindowsPowerShell\r\n    runs-on: windows-latest\r\n    steps:\r\n      - name: Checkout\r\n        uses: actions/checkout@main\r\n        with:\r\n          fetch-depth: 2\r\n      - name: Init Test Suite\r\n        uses: potatoqualitee/psmodulecache@main\r\n        with:\r\n          modules-to-cache: BuildHelpers\r\n          shell: powershell\r\n      - name: Test Scoop Core\r\n        shell: powershell\r\n        run: ./test/bin/test.ps1\r\n  test_pwsh:\r\n    name: PowerShell\r\n    runs-on: windows-latest\r\n    steps:\r\n      - name: Checkout\r\n        uses: actions/checkout@main\r\n        with:\r\n          fetch-depth: 2\r\n      - name: Init Test Suite\r\n        uses: potatoqualitee/psmodulecache@main\r\n        with:\r\n          modules-to-cache: BuildHelpers\r\n          shell: pwsh\r\n      - name: Test Scoop Core\r\n        shell: pwsh\r\n        run: ./test/bin/test.ps1\r\n"
  },
  {
    "path": ".gitignore",
    "content": "*.log\r\n.DS_Store\r\n._.DS_Store\r\nscoop.sublime-workspace\r\ntest/installer/tmp/*\r\ntest/tmp/*\r\n*~\r\nTestResults.xml\r\nsupporting/sqlite/*\r\n"
  },
  {
    "path": ".vscode/extensions.json",
    "content": "{\r\n    \"recommendations\": [\r\n        \"EditorConfig.EditorConfig\",\r\n        \"ms-vscode.PowerShell\"\r\n    ]\r\n}\r\n"
  },
  {
    "path": ".vscode/settings.json",
    "content": "// Configure PSScriptAnalyzer settings\r\n{\r\n    \"powershell.scriptAnalysis.settingsPath\": \"PSScriptAnalyzerSettings.psd1\",\r\n    \"powershell.codeFormatting.preset\": \"OTBS\",\r\n    \"powershell.codeFormatting.alignPropertyValuePairs\": true,\r\n    \"powershell.codeFormatting.ignoreOneLineBlock\": true,\r\n    \"powershell.codeFormatting.useConstantStrings\": true,\r\n    \"powershell.codeFormatting.useCorrectCasing\": true,\r\n    \"powershell.codeFormatting.whitespaceBetweenParameters\": true,\r\n    \"files.exclude\": {\r\n        \"**/.git\": true,\r\n        \"**/.svn\": true,\r\n        \"**/.hg\": true,\r\n        \"**/CVS\": true,\r\n        \"**/.DS_Store\": true,\r\n        \"**/tmp\": true\r\n    }\r\n}\r\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "## [v0.5.3](https://github.com/ScoopInstaller/Scoop/compare/v0.5.2...v0.5.3) - 2025-08-11\r\n\r\n### Features\r\n\r\n**autoupdate:** GitHub predefined hashes support ([#6416](https://github.com/ScoopInstaller/Scoop/issues/6416), [#6435](https://github.com/ScoopInstaller/Scoop/issues/6435))\r\n\r\n### Bug Fixes\r\n\r\n- **scoop-download|install|update:** Fallback to default downloader when aria2 fails ([#4292](https://github.com/ScoopInstaller/Scoop/issues/4292))\r\n- **decompress**: `Expand-7zipArchive` only delete temp dir / `$extractDir` if it is empty ([#6092](https://github.com/ScoopInstaller/Scoop/issues/6092))\r\n- **decompress**: Replace deprecated 7ZIPEXTRACT_USE_EXTERNAL config with USE_EXTERNAL_7ZIP ([#6327](https://github.com/ScoopInstaller/Scoop/issues/6327))\r\n- **commands**: Handling broken aliases ([#6141](https://github.com/ScoopInstaller/Scoop/issues/6141))\r\n- **shim:** Do not suppress `stderr`, properly check `wslpath`/`cygpath` command first ([#6114](https://github.com/ScoopInstaller/Scoop/issues/6114))\r\n- **scoop-bucket:** Add missing import for `no_junction` envs ([#6181](https://github.com/ScoopInstaller/Scoop/issues/6181))\r\n- **scoop-uninstall:** Fix uninstaller does not gain Global state ([#6430](https://github.com/ScoopInstaller/Scoop/issues/6430))\r\n- **scoop-depends-tests:** Mocking `USE_EXTERNAL_7ZIP` as $false to avoding error when it is $true ([#6431](https://github.com/ScoopInstaller/Scoop/issues/6431))\r\n\r\n### Code Refactoring\r\n\r\n- **download:** Move download-related functions to 'download.ps1' ([#6095](https://github.com/ScoopInstaller/Scoop/issues/6095))\r\n- **Get-Manifest:** Select actual source for manifest ([#6142](https://github.com/ScoopInstaller/Scoop/issues/6142))\r\n\r\n### Performance Improvements\r\n\r\n- **shim:** Update kiennq-shim to v3.1.2 ([#6261](https://github.com/ScoopInstaller/Scoop/issues/6261))\r\n\r\n## [v0.5.2](https://github.com/ScoopInstaller/Scoop/compare/v0.5.1...v0.5.2) - 2024-07-26\r\n\r\n### Bug Fixes\r\n\r\n- **scoop-alias:** Fix 'Option --verbose not recognized.' ([#6062](https://github.com/ScoopInstaller/Scoop/issues/6062))\r\n- **scoop-hold:** Use 'foreach' loop to allow 'continue' statement ([#6078](https://github.com/ScoopInstaller/Scoop/issues/6078))\r\n- **core:** Use 'Join-Path' to construct cache file path ([#6079](https://github.com/ScoopInstaller/Scoop/issues/6079))\r\n- **json:** Don't serialize jsonpath return if only one result ([#6066](https://github.com/ScoopInstaller/Scoop/issues/6066), [#6073](https://github.com/ScoopInstaller/Scoop/issues/6073))\r\n\r\n### Builds\r\n\r\n- **supporting:** Update Json.Schema to 4.0.1 ([#6072](https://github.com/ScoopInstaller/Scoop/issues/6072))\r\n\r\n## [v0.5.1](https://github.com/ScoopInstaller/Scoop/compare/v0.5.0...v0.5.1) - 2024-07-16\r\n\r\n### Bug Fixes\r\n\r\n- **scoop-alias:** Pass options correctly ([#6003](https://github.com/ScoopInstaller/Scoop/issues/6003))\r\n- **scoop-virustotal:** Adjust `json_path` parameters to retrieve correct analysis stats ([#6044](https://github.com/ScoopInstaller/Scoop/issues/6044))\r\n- **bucket:** Implement error handling for failed bucket addition ([#6051](https://github.com/ScoopInstaller/Scoop/issues/6051))\r\n- **database:** Fix compatibility with Windows PowerShell ([#6045](https://github.com/ScoopInstaller/Scoop/issues/6045))\r\n- **install:** Expand `env_set` items before setting Environment Variables ([#6050](https://github.com/ScoopInstaller/Scoop/issues/6050))\r\n- **install:** Fix parsing error when installing multiple apps w/ specific version ([#6039](https://github.com/ScoopInstaller/Scoop/issues/6039))\r\n\r\n## [v0.5.0](https://github.com/ScoopInstaller/Scoop/compare/v0.4.2...v0.5.0) - 2024-07-01\r\n\r\n### Features\r\n\r\n- **scoop-search:** Use SQLite for caching apps to speed up local search ([#5851](https://github.com/ScoopInstaller/Scoop/issues/5851), [#5918](https://github.com/ScoopInstaller/Scoop/issues/5918), [#5946](https://github.com/ScoopInstaller/Scoop/issues/5946), [#5949](https://github.com/ScoopInstaller/Scoop/issues/5949), [#5955](https://github.com/ScoopInstaller/Scoop/issues/5955), [#5966](https://github.com/ScoopInstaller/Scoop/issues/5966), [#5967](https://github.com/ScoopInstaller/Scoop/issues/5967), [#5981](https://github.com/ScoopInstaller/Scoop/issues/5981))\r\n- **core:** New cache filename format ([#5929](https://github.com/ScoopInstaller/Scoop/issues/5929), [#5944](https://github.com/ScoopInstaller/Scoop/issues/5944))\r\n- **decompress:** Use innounp-unicode as default Inno Setup Unpacker ([#6028](https://github.com/ScoopInstaller/Scoop/issues/6028))\r\n- **install:** Added the ability to install specific version of app from URL/file link ([#5988](https://github.com/ScoopInstaller/Scoop/issues/5988))\r\n\r\n### Bug Fixes\r\n\r\n- **scoop-download|install|update:** Use consistent options ([#5956](https://github.com/ScoopInstaller/Scoop/issues/5956))\r\n- **scoop-info:** Fix download size estimating ([#5958](https://github.com/ScoopInstaller/Scoop/issues/5958))\r\n- **scoop-search:** Catch error of parsing invalid manifest ([#5930](https://github.com/ScoopInstaller/Scoop/issues/5930))\r\n- **checkver:** Correct variable 'regex' to 'regexp' ([#5993](https://github.com/ScoopInstaller/Scoop/issues/5993))\r\n- **checkver:** Correct error messages ([#6024](https://github.com/ScoopInstaller/Scoop/issues/6024))\r\n- **core:** Search for Git executable instead of any cmdlet ([#5998](https://github.com/ScoopInstaller/Scoop/issues/5998))\r\n- **core:** Use correct path in 'bash' ([#6006](https://github.com/ScoopInstaller/Scoop/issues/6006))\r\n- **core:** Limit the number of commands to get when search for git executable ([#6013](https://github.com/ScoopInstaller/Scoop/issues/6013))\r\n- **decompress:** Match `extract_dir`/`extract_to` and archives ([#5983](https://github.com/ScoopInstaller/Scoop/issues/5983))\r\n- **json:** Serialize jsonpath return ([#5921](https://github.com/ScoopInstaller/Scoop/issues/5921))\r\n- **shim:** Restore original path for JAR cmd ([#6030](https://github.com/ScoopInstaller/Scoop/issues/6030))\r\n\r\n### Code Refactoring\r\n\r\n- **decompress:** Use 7zip to extract Zstd archive ([#5973](https://github.com/ScoopInstaller/Scoop/issues/5973))\r\n- **install:** Separate archive extraction from downloader ([#5951](https://github.com/ScoopInstaller/Scoop/issues/5951))\r\n- **install:** Replace 'run_(un)installer()' with 'Invoke-Installer()' ([#5968](https://github.com/ScoopInstaller/Scoop/issues/5968), [#5971](https://github.com/ScoopInstaller/Scoop/issues/5971))\r\n\r\n## [v0.4.2](https://github.com/ScoopInstaller/Scoop/compare/v0.4.1...v0.4.2) - 2024-05-14\r\n\r\n### Bug Fixes\r\n\r\n- **autoupdate:** Copy `PSCustomObject`-type properties within `substitute()` to prevent reference changes ([#5934](https://github.com/ScoopInstaller/Scoop/issues/5934), [#5962](https://github.com/ScoopInstaller/Scoop/issues/5962))\r\n- **core:** Fix `Invoke-ExternalCommand` quoting rules ([#5945](https://github.com/ScoopInstaller/Scoop/issues/5945))\r\n- **system:** Fix argument passing to `Split-PathLikeEnvVar()` in deprecated `strip_path()` ([#5937](https://github.com/ScoopInstaller/Scoop/issues/5937))\r\n\r\n## [v0.4.1](https://github.com/ScoopInstaller/Scoop/compare/v0.4.0...v0.4.1) - 2024-04-25\r\n\r\n### Bug Fixes\r\n\r\n- **core:** Fix `Invoke-ExternalCommand` regression ([#5923](https://github.com/ScoopInstaller/Scoop/issues/5923))\r\n\r\n## [v0.4.0](https://github.com/ScoopInstaller/Scoop/compare/v0.3.1...v0.4.0) - 2024-04-18\r\n\r\n### Features\r\n\r\n- **scoop-update:** Add support for parallel syncing buckets in PowerShell 7 and improve output ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122))\r\n- **bucket:** Switch nirsoft bucket to ScoopInstaller/Nirsoft ([#5328](https://github.com/ScoopInstaller/Scoop/issues/5328))\r\n- **bucket:** Make official buckets higher priority ([#5398](https://github.com/ScoopInstaller/Scoop/issues/5398))\r\n- **config:** Support portable config file ([#5369](https://github.com/ScoopInstaller/Scoop/issues/5369))\r\n- **core:** Add `-Quiet` switch for `Invoke-ExternalCommand` ([#5346](https://github.com/ScoopInstaller/Scoop/issues/5346))\r\n- **core:** Allow global install of PowerShell modules ([#5611](https://github.com/ScoopInstaller/Scoop/issues/5611))\r\n- **path:** Isolate Scoop apps' PATH ([#5840](https://github.com/ScoopInstaller/Scoop/issues/5840))\r\n\r\n### Bug Fixes\r\n\r\n- **scoop-alias:** Prevent overwrite existing file when adding alias ([#5577](https://github.com/ScoopInstaller/Scoop/issues/5577))\r\n- **scoop-checkup:** Skip defender check in Windows Sandbox ([#5519](https://github.com/ScoopInstaller/Scoop/issues/5519))\r\n- **scoop-checkup:** Change the message level of helpers from ERROR to WARN ([#5614](https://github.com/ScoopInstaller/Scoop/issues/5614))\r\n- **scoop-checkup:** Don't throw 7zip error when external 7zip is used ([#5703](https://github.com/ScoopInstaller/Scoop/issues/5703))\r\n- **scoop-(un)hold:** Correct output the messages when manifest not found, (already|not) held ([#5519](https://github.com/ScoopInstaller/Scoop/issues/5519))\r\n- **scoop-info:** Fix errors in file size collection when `--verbose` ([#5352](https://github.com/ScoopInstaller/Scoop/issues/5352))\r\n- **scoop-reset:** Don't abort when multiple apps are passed and an app is running ([#5687](https://github.com/ScoopInstaller/Scoop/issues/5687))\r\n- **scoop-update:** Change error message to a better instruction ([#5677](https://github.com/ScoopInstaller/Scoop/issues/5677))\r\n- **scoop-virustotal:** Fix `scoop-virustotal` when `--all` has been passed without app ([#5593](https://github.com/ScoopInstaller/Scoop/issues/5593))\r\n- **scoop-virustotal:** Fix the issue that escape character not available in PowerShell 5.1 ([#5870](https://github.com/ScoopInstaller/Scoop/issues/5870))\r\n- **autoupdate:** Fix file hash extraction ([#5295](https://github.com/ScoopInstaller/Scoop/issues/5295))\r\n- **autoupdate:** Fix bug that 'WebClient' doesn't auto-extract 'gzip' ([#5901](https://github.com/ScoopInstaller/Scoop/issues/5901))\r\n- **buckets:** Avoid error messages for unexpected dir ([#5549](https://github.com/ScoopInstaller/Scoop/issues/5549))\r\n- **config:** Warn users about misconfigured GitHub token ([#5777](https://github.com/ScoopInstaller/Scoop/issues/5777))\r\n- **core:** Fix scripts' calling parameters ([#5365](https://github.com/ScoopInstaller/Scoop/issues/5365))\r\n- **core:** Fix `is_in_dir` under Unix ([#5391](https://github.com/ScoopInstaller/Scoop/issues/5391))\r\n- **core:** Rewrite config file when needed ([#5439](https://github.com/ScoopInstaller/Scoop/issues/5439))\r\n- **core:** Prevents leaking HTTP(S)_PROXY env vars to current sessions after Invoke-Git in parallel execution ([#5436](https://github.com/ScoopInstaller/Scoop/issues/5436))\r\n- **core:** Handle scoop aliases and broken(edited,copied) shim ([#5551](https://github.com/ScoopInstaller/Scoop/issues/5551))\r\n- **core:** Avoid error messages when deleting non-existent environment variable ([#5547](https://github.com/ScoopInstaller/Scoop/issues/5547))\r\n- **core:** Use relative path as fallback of `$scoopdir` ([#5544](https://github.com/ScoopInstaller/Scoop/issues/5544))\r\n- **core:** Fix detection of Git ([#5545](https://github.com/ScoopInstaller/Scoop/issues/5545))\r\n- **core:** Do not call `scoop` externally from inside the code ([#5695](https://github.com/ScoopInstaller/Scoop/issues/5695))\r\n- **core:** Fix arguments parsing method of `Invoke-ExternalCommand()` ([#5839](https://github.com/ScoopInstaller/Scoop/issues/5839))\r\n- **decompress:** Exclude '*.nsis' that may cause error ([#5294](https://github.com/ScoopInstaller/Scoop/issues/5294))\r\n- **decompress:** Remove unused parent dir w/ 'extract_dir' ([#5682](https://github.com/ScoopInstaller/Scoop/issues/5682))\r\n- **decompress:** Use `wix.exe` in WiX Toolset v4+ as primary extractor of `Expand-DarkArchive()` ([#5871](https://github.com/ScoopInstaller/Scoop/issues/5871))\r\n- **env:** Avoid automatic expansion of `%%` in env ([#5395](https://github.com/ScoopInstaller/Scoop/issues/5395), [#5452](https://github.com/ScoopInstaller/Scoop/issues/5452), [#5631](https://github.com/ScoopInstaller/Scoop/issues/5631))\r\n- **getopt:** Stop split arguments in `getopt()` and ensure array by explicit arguments type ([#5326](https://github.com/ScoopInstaller/Scoop/issues/5326))\r\n- **install:** Fix download from private GitHub repositories ([#5361](https://github.com/ScoopInstaller/Scoop/issues/5361))\r\n- **install:** Avoid error when unlinking non-existent junction/hardlink ([#5552](https://github.com/ScoopInstaller/Scoop/issues/5552))\r\n- **manifest:** Correct source of manifest ([#5575](https://github.com/ScoopInstaller/Scoop/issues/5575))\r\n- **shim:** Remove console window for GUI applications ([#5559](https://github.com/ScoopInstaller/Scoop/issues/5559))\r\n- **shim:** Use bash executable directly ([#5433](https://github.com/ScoopInstaller/Scoop/issues/5433))\r\n- **shim:** Check literal path in `Get-ShimPath` ([#5680](https://github.com/ScoopInstaller/Scoop/issues/5680))\r\n- **shim:** Avoid unexpected output of `list` subcommand ([#5681](https://github.com/ScoopInstaller/Scoop/issues/5681))\r\n- **shim:** Allow GUI applications to attach to the shell's console when launched using the GUI shim ([#5721](https://github.com/ScoopInstaller/Scoop/issues/5721))\r\n- **shim:** Run JAR file from app's root directory ([#5872](https://github.com/ScoopInstaller/Scoop/issues/5872))\r\n- **shortcuts:** Output correctly formatted path ([#5333](https://github.com/ScoopInstaller/Scoop/issues/5333))\r\n- **update/uninstall:** Remove items from PATH correctly ([#5833](https://github.com/ScoopInstaller/Scoop/issues/5833))\r\n\r\n### Performance Improvements\r\n\r\n- **scoop-search:** Improve performance for local search ([#5644](https://github.com/ScoopInstaller/Scoop/issues/5644))\r\n- **scoop-update:** Check for running process before wasting time on download ([#5799](https://github.com/ScoopInstaller/Scoop/issues/5799))\r\n- **decompress:** Disable progress bar to improve `Expand-Archive` performance ([#5410](https://github.com/ScoopInstaller/Scoop/issues/5410))\r\n- **shim:** Update kiennq-shim to v3.1.1 ([#5841](https://github.com/ScoopInstaller/Scoop/issues/5841), [#5847](https://github.com/ScoopInstaller/Scoop/issues/5847))\r\n\r\n### Code Refactoring\r\n\r\n- **scoop-download:** Output more detailed manifest information ([#5277](https://github.com/ScoopInstaller/Scoop/issues/5277))\r\n- **core:** Cleanup some old codes, e.g., msi section and config migration ([#5715](https://github.com/ScoopInstaller/Scoop/issues/5715), [#5824](https://github.com/ScoopInstaller/Scoop/issues/5824))\r\n- **core:** Rewrite and separate path-related functions to `system.ps1` ([#5836](https://github.com/ScoopInstaller/Scoop/issues/5836), [#5858](https://github.com/ScoopInstaller/Scoop/issues/5858), [#5864](https://github.com/ScoopInstaller/Scoop/issues/5864))\r\n- **core:** Get rid of 'fullpath' ([#3533](https://github.com/ScoopInstaller/Scoop/issues/3533))\r\n- **git:** Use Invoke-Git() with direct path to git.exe to prevent spawning shim subprocesses ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122), [#5375](https://github.com/ScoopInstaller/Scoop/issues/5375))\r\n- **helper:** Remove 7zip's fallback '7zip-zstd' ([#5548](https://github.com/ScoopInstaller/Scoop/issues/5548))\r\n- **shim:** Remove CS shim codebase ([#5903](https://github.com/ScoopInstaller/Scoop/issues/5903))\r\n\r\n### Builds\r\n\r\n- **checkver:** Read the private_host config variable ([#5381](https://github.com/ScoopInstaller/Scoop/issues/5381))\r\n- **supporting:** Update Json to 13.0.3, Json.Schema to 3.0.15 ([#5835](https://github.com/ScoopInstaller/Scoop/issues/5835))\r\n\r\n### Continuous Integration\r\n\r\n- **dependabot:** Add dependabot.yml for GitHub Actions ([#5377](https://github.com/ScoopInstaller/Scoop/issues/5377))\r\n- **module:** Update 'psmodulecache' version to 'main' ([#5828](https://github.com/ScoopInstaller/Scoop/issues/5828))\r\n\r\n### Tests\r\n\r\n- **bucket:** Skip manifest validation if no manifest changes ([#5270](https://github.com/ScoopInstaller/Scoop/issues/5270))\r\n\r\n### Documentation\r\n\r\n- **scoop-info:** Fix help message([#5445](https://github.com/ScoopInstaller/Scoop/issues/5445))\r\n- **readme:** Improve documentation language ([#5638](https://github.com/ScoopInstaller/Scoop/issues/5638))\r\n\r\n## [v0.3.1](https://github.com/ScoopInstaller/Scoop/compare/v0.3.0...v0.3.1) - 2022-11-15\r\n\r\n### Features\r\n\r\n- **config:** Allow Scoop to check if apps versioned as 'nightly' are outdated ([#5166](https://github.com/ScoopInstaller/Scoop/issues/5166))\r\n- **checkup:** Add Windows Developer Mode check ([#5233](https://github.com/ScoopInstaller/Scoop/issues/5233))\r\n- **bucket:** Add 'sysinternals' bucket to known ([#5237](https://github.com/ScoopInstaller/Scoop/issues/5237))\r\n\r\n### Bug Fixes\r\n\r\n- **decompress:** Use PS's default 'Expand-Archive()' ([#5185](https://github.com/ScoopInstaller/Scoop/issues/5185))\r\n- **hash:** Fix SourceForge's hash extraction ([#5189](https://github.com/ScoopInstaller/Scoop/issues/5189))\r\n- **decompress:** Trim ending '/' ([#5195](https://github.com/ScoopInstaller/Scoop/issues/5195))\r\n- **shim:** Exit if shim creating failed 'cause no git ([#5225](https://github.com/ScoopInstaller/Scoop/issues/5225))\r\n- **scoop-import:** Add correct architecture argument ([#5210](https://github.com/ScoopInstaller/Scoop/issues/5210))\r\n- **scoop-config:** Output `[DateTime]` as `[String]` ([#5232](https://github.com/ScoopInstaller/Scoop/issues/5232))\r\n- **shim:** fixed shim add bug related to Resolve-Path ([#5492](https://github.com/ScoopInstaller/Scoop/issues/5492))\r\n\r\n### Code Refactoring\r\n\r\n- **hash:** Use `Get-FileHash()` directly ([#5177](https://github.com/ScoopInstaller/Scoop/issues/5177))\r\n- **installer:** Drop the old installer ([#5186](https://github.com/ScoopInstaller/Scoop/issues/5186))\r\n- **unix:** Remove `unix.ps1` ([#5235](https://github.com/ScoopInstaller/Scoop/issues/5235))\r\n\r\n### Builds\r\n\r\n- **auto-pr:** Add `CommitMessageFormat` option ([#5171](https://github.com/ScoopInstaller/Scoop/issues/5171))\r\n- **checkver:** Support XML default namespace ([#5191](https://github.com/ScoopInstaller/Scoop/issues/5191))\r\n- **pssa:** Remove unused 'ExcludeRules' ([#5201](https://github.com/ScoopInstaller/Scoop/issues/5201))\r\n- **schema:** Add 'installer' and 'shortcuts' to 'autoupdate' ([#5220](https://github.com/ScoopInstaller/Scoop/issues/5220))\r\n- **checkhashes:** Use correct version number if `UseCache` ([#5240](https://github.com/ScoopInstaller/Scoop/issues/5240))\r\n\r\n### Continuous Integration\r\n\r\n- **module:** Update modules version ([#5209](https://github.com/ScoopInstaller/Scoop/issues/5209))\r\n\r\n### Tests\r\n\r\n- **unix:** Fix tests in Linux and macOS ([#5179](https://github.com/ScoopInstaller/Scoop/issues/5179))\r\n- **pester:** Update to Pester 5 ([#5222](https://github.com/ScoopInstaller/Scoop/issues/5222))\r\n- **bucket:** Use BuildHelpers' EnvVars ([#5226](https://github.com/ScoopInstaller/Scoop/issues/5226))\r\n\r\n### Documentation\r\n\r\n- **scoop-cat:** Fix help message([#5224](https://github.com/ScoopInstaller/Scoop/issues/5224))\r\n\r\n## [v0.3.0](https://github.com/ScoopInstaller/Scoop/compare/v0.2.4...v0.3.0) - 2022-10-10\r\n\r\n### Features\r\n\r\n- **install:** Add support for ARM64 architecture ([#5154](https://github.com/ScoopInstaller/Scoop/issues/5154))\r\n- **install:** Show the running process ([#5102](https://github.com/ScoopInstaller/Scoop/issues/5102))\r\n- **getopt:** Support option terminator (`--`) ([#5121](https://github.com/ScoopInstaller/Scoop/issues/5121))\r\n- **subdir:** Allow subdir in 'bucket' ([#5119](https://github.com/ScoopInstaller/Scoop/issues/5119))\r\n- **scoop-config:** Allow 'hold_update_until' be set manually ([#5100](https://github.com/ScoopInstaller/Scoop/issues/5100))\r\n- **scoop-(un)hold:** Support `scoop (un)hold scoop` ([#5089](https://github.com/ScoopInstaller/Scoop/issues/5089))\r\n- **scoop-update:** Stash uncommitted changes before update ([#5091](https://github.com/ScoopInstaller/Scoop/issues/5091))\r\n\r\n### Bug Fixes\r\n\r\n- **config:** Change config option to snake_case in file and SCREAMING_CASE in code ([#5116](https://github.com/ScoopInstaller/Scoop/issues/5116))\r\n- **jsonpath:** Prevent converting date string to DateTime in JSONPath ([#5130](https://github.com/ScoopInstaller/Scoop/issues/5130))\r\n- **psmodule:** Remove folder recursively when unlinking previous module path ([#5127](https://github.com/ScoopInstaller/Scoop/issues/5127))\r\n- **scoop-update:** Add `uninstall_psmodule` to update process ([#5136](https://github.com/ScoopInstaller/Scoop/issues/5136))\r\n\r\n### Code Refactoring\r\n\r\n- **download:** Rename `dl()` to `Invoke-Download()` ([#5143](https://github.com/ScoopInstaller/Scoop/issues/5143))\r\n- **path:** Use 'Convert-Path()' instead of 'Resolve-Path()' ([#5109](https://github.com/ScoopInstaller/Scoop/issues/5109))\r\n- **scoop-shim:** Use `getopt` to parse arguments ([#5125](https://github.com/ScoopInstaller/Scoop/issues/5125))\r\n\r\n### Builds\r\n\r\n- **checkver:** Implement SourceForge checkver functionality ([#5113](https://github.com/ScoopInstaller/Scoop/issues/5113), [#5163](https://github.com/ScoopInstaller/Scoop/issues/5163))\r\n- **checkurls:** Allow checking URLs from private_hosts ([#5152](https://github.com/ScoopInstaller/Scoop/issues/5152))\r\n- **schema:** Set manifest schema to be stricter ([#5093](https://github.com/ScoopInstaller/Scoop/issues/5093))\r\n- **vscode:** Tweak VSCode setting ([#5149](https://github.com/ScoopInstaller/Scoop/issues/5149))\r\n\r\n## [v0.2.4](https://github.com/ScoopInstaller/Scoop/compare/v0.2.3...v0.2.4) - 2022-08-08\r\n\r\n### Features\r\n\r\n- **core:** Create no window by default in `Invoke-ExternalCommand` ([#5066](https://github.com/ScoopInstaller/Scoop/issues/5066))\r\n- **core:** Improve argument concatenation in `Invoke-ExternalCommand` ([#5065](https://github.com/ScoopInstaller/Scoop/issues/5065))\r\n- **install:** Show bucket name while installing an app ([#5075](https://github.com/ScoopInstaller/Scoop/issues/5075))\r\n- **scoop-status:** Add flag to disable remote checking ([#5073](https://github.com/ScoopInstaller/Scoop/issues/5073))\r\n- **scoop-update:** Add support for `pre_uninstall` and `post_uninstall` ([#5085](https://github.com/ScoopInstaller/Scoop/issues/5085))\r\n\r\n### Bug Fixes\r\n\r\n- **core:** Avoid deadlock in `Invoke-ExternalCommand` ([#5064](https://github.com/ScoopInstaller/Scoop/issues/5064))\r\n- **core:** Use 'System.Nullable<bool>' for param 'global' ([#5088](https://github.com/ScoopInstaller/Scoop/issues/5088))\r\n- **install:** Move from cache when `--no-cache` is specified ([#5039](https://github.com/ScoopInstaller/Scoop/issues/5039))\r\n- **scoop-status:** Correct formatting of `Info` output ([#5047](https://github.com/ScoopInstaller/Scoop/issues/5047))\r\n\r\n### Builds\r\n\r\n- **checkver:** Load page content before running 'script' ([#5080](https://github.com/ScoopInstaller/Scoop/issues/5080))\r\n- **json:** Update Newtonsoft.Json.Schema to 3.0.15-beta2 ([#5053](https://github.com/ScoopInstaller/Scoop/issues/5053))\r\n\r\n## [v0.2.3](https://github.com/ScoopInstaller/Scoop/compare/v0.2.2...v0.2.3) - 2022-07-07\r\n\r\n### Features\r\n\r\n- **chore:** Add missing -a/--all param to all commands ([#5004](https://github.com/ScoopInstaller/Scoop/issues/5004))\r\n- **scoop-status:** Check bucket status, improve output ([#5011](https://github.com/ScoopInstaller/Scoop/issues/5011))\r\n- **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886))\r\n- **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014), [#5034](https://github.com/ScoopInstaller/Scoop/issues/5034))\r\n\r\n### Bug Fixes\r\n\r\n- **chore:** Update help documentation ([#5002](https://github.com/ScoopInstaller/Scoop/issues/5002), [#5029](https://github.com/ScoopInstaller/Scoop/issues/5029))\r\n- **decompress:** Handle split RAR archives ([#4994](https://github.com/ScoopInstaller/Scoop/issues/4994))\r\n- **shortcuts:** Fix network drive shortcut creation ([#4410](https://github.com/ScoopInstaller/Scoop/issues/4410), [#5006](https://github.com/ScoopInstaller/Scoop/issues/5006))\r\n\r\n### Code Refactoring\r\n\r\n- **scoop-search:** Output PSObject, use API token ([#4997](https://github.com/ScoopInstaller/Scoop/issues/4997))\r\n\r\n### Builds\r\n\r\n- **checkver,auto-pr:** Allow passing file path ([#5019](https://github.com/ScoopInstaller/Scoop/issues/5019))\r\n- **checkver:** Exit routine earlier if error ([#5025](https://github.com/ScoopInstaller/Scoop/issues/5025))\r\n- **json:** Update Newton.Json to 13.0.1 ([#5026](https://github.com/ScoopInstaller/Scoop/issues/5026))\r\n\r\n### Tests\r\n\r\n- **typo:** Fix typo ('formated' -> 'formatted') ([#4217](https://github.com/ScoopInstaller/Scoop/issues/4217))\r\n\r\n## [v0.2.2](https://github.com/ScoopInstaller/Scoop/compare/v0.2.1...v0.2.2) - 2022-06-21\r\n\r\n### Features\r\n\r\n- **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956))\r\n- **scoop-(un)hold:** Add `-g`/`--global` flag ([#4991](https://github.com/ScoopInstaller/Scoop/issues/4991))\r\n- **scoop-update:** Support `scoop update scoop` ([#4992](https://github.com/ScoopInstaller/Scoop/issues/4992))\r\n- **scoop-virustotal:** Migrate to VirusTotal API v3 ([#4983](https://github.com/ScoopInstaller/Scoop/issues/4983))\r\n\r\n### Bug Fixes\r\n\r\n- **manifest:** Fix bugs in 'Get-Manifest()' ([#4986](https://github.com/ScoopInstaller/Scoop/issues/4986))\r\n\r\n## [v0.2.1](https://github.com/ScoopInstaller/Scoop/compare/v0.2.0...v0.2.1) - 2022-06-10\r\n\r\n### Features\r\n\r\n- **core:** Add pre_uninstall and post_uninstall hooks ([#4957](https://github.com/ScoopInstaller/Scoop/issues/4957), [#4962](https://github.com/ScoopInstaller/Scoop/issues/4962))\r\n\r\n### Bug Fixes\r\n\r\n- **bucket:** Make sure `list_buckets` return array ([#4979](https://github.com/ScoopInstaller/Scoop/issues/4979))\r\n- **chore:** Deprecate tls1 and tls1.1 ([#4950](https://github.com/ScoopInstaller/Scoop/issues/4950))\r\n- **chore:** Update Nonportable bucket URL ([#4955](https://github.com/ScoopInstaller/Scoop/issues/4955))\r\n- **core:** Using `Invoke-Command` instead of `Invoke-Expression` ([#4941](https://github.com/ScoopInstaller/Scoop/issues/4941))\r\n- **core:** Load config file before initialization ([#4932](https://github.com/ScoopInstaller/Scoop/issues/4932))\r\n- **core:** Allow to use '_' and '.' in bucket name ([#4952](https://github.com/ScoopInstaller/Scoop/issues/4952))\r\n- **depends:** Avoid digits in archive file extension (except for .7z and .001) ([#4915](https://github.com/ScoopInstaller/Scoop/issues/4915))\r\n- **bucket:** Don't check remote URL of non-git buckets ([#4923](https://github.com/ScoopInstaller/Scoop/issues/4923))\r\n- **bucket:** Don't write message OK before bucket is cloned ([#4925](https://github.com/ScoopInstaller/Scoop/issues/4925))\r\n- **shim:** Add 'Get-CommandPath()' to find git ([#4913](https://github.com/ScoopInstaller/Scoop/issues/4913))\r\n- **shim:** Remove character replacement in .cmd -> .ps1 shims ([#4914](https://github.com/ScoopInstaller/Scoop/issues/4914))\r\n- **scoop:** Pass CLI arguments as string objects ([#4931](https://github.com/ScoopInstaller/Scoop/issues/4931))\r\n- **scoop-info:** Fix error message when manifest is not found ([#4935](https://github.com/ScoopInstaller/Scoop/issues/4935))\r\n- **scoop-search:** Require files in 'bucket' dir for remote known buckets ([#4944](https://github.com/ScoopInstaller/Scoop/issues/4944))\r\n- **update:** Prevent uninstall when update ([#4949](https://github.com/ScoopInstaller/Scoop/issues/4949))\r\n- **scoop-download:** Use correct Args when calling `Get-Manifest` ([#4970](https://github.com/ScoopInstaller/Scoop/issues/4970))\r\n\r\n### Code Refactoring\r\n\r\n- **manifest:** Rename 'Find-Manifest()' to 'Get-Manifest() ([#4966](https://github.com/ScoopInstaller/Scoop/issues/4966), [#4981](https://github.com/ScoopInstaller/Scoop/issues/4981))\r\n\r\n### Documentation\r\n\r\n- **readme:** Update license badge ([#4929](https://github.com/ScoopInstaller/Scoop/issues/4929))\r\n\r\n## [v0.2.0](https://github.com/ScoopInstaller/Scoop/compare/v0.1.0...v0.2.0) - 2022-05-10\r\n\r\n### Features\r\n\r\n- **relicense:** Relicense to dual-license (Unlicense or MIT) ([#4903](https://github.com/ScoopInstaller/Scoop/issues/4903), [#4870](https://github.com/ScoopInstaller/Scoop/issues/4870))\r\n- **install:** Allow downloading from private repositories ([#4254](https://github.com/ScoopInstaller/Scoop/issues/4254))\r\n- **scoop-cleanup:** Add `-a/--all` switch to cleanup all apps ([#4906](https://github.com/ScoopInstaller/Scoop/issues/4906))\r\n\r\n### Bug Fixes\r\n\r\n- **bucket:** Return empty list correctly in `Get-LocalBucket` ([#4885](https://github.com/ScoopInstaller/Scoop/issues/4885))\r\n- **install:** Fix issue with installation inside containers ([#4837](https://github.com/ScoopInstaller/Scoop/issues/4837))\r\n- **installed:** If no `$global`, check both local and global installed ([#4798](https://github.com/ScoopInstaller/Scoop/issues/4798))\r\n- **shim:** Manipulating shims with UTF8 encoding ([#4791](https://github.com/ScoopInstaller/Scoop/issues/4791), [#4813](https://github.com/ScoopInstaller/Scoop/issues/4813))\r\n- **shim:** Correctly quote $@ in sh->ps1 shims ([#4809](https://github.com/ScoopInstaller/Scoop/issues/4809))\r\n- **update:** Skip logs starting with `(chore)` ([#4800](https://github.com/ScoopInstaller/Scoop/issues/4800))\r\n- **scoop-download:** Add failure check ([#4822](https://github.com/ScoopInstaller/Scoop/issues/4822))\r\n- **scoop-list:** Fix date in 'Updated' column showing the months in the place of minutes ([#4880](https://github.com/ScoopInstaller/Scoop/issues/4880))\r\n- **scoop-prefix:** Fix typo that breaks global installed apps ([#4795](https://github.com/ScoopInstaller/Scoop/issues/4795))\r\n\r\n### Performance Improvements\r\n\r\n- **scoop:** Load libs only once ([#4839](https://github.com/ScoopInstaller/Scoop/issues/4839), [#4884](https://github.com/ScoopInstaller/Scoop/issues/4884))\r\n\r\n### Code Refactoring\r\n\r\n- **bucket:** Move 'Find-Manifest' and 'list_buckets' to 'buckets' ([#4814](https://github.com/ScoopInstaller/Scoop/issues/4814))\r\n- **relpath:** Use `$PSScriptRoot` instead of `relpath` ([#4793](https://github.com/ScoopInstaller/Scoop/issues/4793))\r\n- **reset_aliases:** Move core function of `reset_aliases` to `scoop` ([#4794](https://github.com/ScoopInstaller/Scoop/issues/4794))\r\n- **config:** Rename checkver_token to gh_token and SCOOP_CHECKVER_TOKEN to SCOOP_GH_TOKEN ([#4832](https://github.com/ScoopInstaller/Scoop/issues/4832), [#4842](https://github.com/ScoopInstaller/Scoop/issues/4842))\r\n\r\n### Builds\r\n\r\n- **checkver:** Add option to throw error as exception ([#4867](https://github.com/ScoopInstaller/Scoop/issues/4867))\r\n- **schema:** Remove 'description' from required fields ([#4853](https://github.com/ScoopInstaller/Scoop/issues/4853), [#4874](https://github.com/ScoopInstaller/Scoop/issues/4874))\r\n\r\n### Documentation\r\n\r\n- **changelog:** Rearrange CHANGELOG ([#4897](https://github.com/ScoopInstaller/Scoop/issues/4897))\r\n- **readme:** Update installation instruction ([#4825](https://github.com/ScoopInstaller/Scoop/issues/4825))\r\n- **readme:** Fix badges for Gitter and CI Tests ([#4830](https://github.com/ScoopInstaller/Scoop/issues/4830))\r\n- **scoop-shim:** Fix typo ([#4836](https://github.com/ScoopInstaller/Scoop/issues/4836))\r\n\r\n## [v0.1.0](https://github.com/ScoopInstaller/Scoop/compare/2021-12-26...v0.1.0) - 2022-03-01\r\n\r\n### Features\r\n\r\n- **scoop-bucket:** List more detailed information for buckets ([#4704](https://github.com/ScoopInstaller/Scoop/issues/4704), [#4756](https://github.com/ScoopInstaller/Scoop/issues/4756), [#4759](https://github.com/ScoopInstaller/Scoop/issues/4759))\r\n- **scoop-cache:** Handle multiple apps and show detailed information ([#4738](https://github.com/ScoopInstaller/Scoop/issues/4738))\r\n- **scoop-cat:** Use `bat` to pretty-print JSON ([#4742](https://github.com/ScoopInstaller/Scoop/issues/4742))\r\n- **scoop-config:** Allow Scoop to ignore running processes during reset/uninstall/update ([#4713](https://github.com/ScoopInstaller/Scoop/issues/4713), [#4731](https://github.com/ScoopInstaller/Scoop/issues/4731))\r\n- **scoop-config:** Show all settings ([#4765](https://github.com/ScoopInstaller/Scoop/issues/4765))\r\n- **scoop-download:** Add `scoop download` command ([#4621](https://github.com/ScoopInstaller/Scoop/issues/4621))\r\n- **scoop-(install|virustotal):** Allow skipping update check ([#4634](https://github.com/ScoopInstaller/Scoop/issues/4634))\r\n- **scoop-list:** Allow list manipulation ([#4718](https://github.com/ScoopInstaller/Scoop/issues/4718))\r\n- **scoop-list:** Show last-updated time ([#4723](https://github.com/ScoopInstaller/Scoop/issues/4723))\r\n- **scoop-info:** Revamp details and show more information ([#4747](https://github.com/ScoopInstaller/Scoop/issues/4747))\r\n- **scoop-shim:** Add `scoop shim` to manipulate shims ([#4727](https://github.com/ScoopInstaller/Scoop/issues/4727), [#4736](https://github.com/ScoopInstaller/Scoop/issues/4736))\r\n\r\n### Bug Fixes\r\n\r\n- **autoupdate:** Allow checksum file that contains whitespaces ([#4619](https://github.com/ScoopInstaller/Scoop/issues/4619))\r\n- **autoupdate:** Rename $response to $res ([#4706](https://github.com/ScoopInstaller/Scoop/issues/4706))\r\n- **config:** Ensure manipulating config with UTF8 encoding ([#4644](https://github.com/ScoopInstaller/Scoop/issues/4644))\r\n- **config:** Allow scoop config use Unicode characters ([#4631](https://github.com/ScoopInstaller/Scoop/issues/4631))\r\n- **config:** Fix `set_config` bugs ([#3681](https://github.com/ScoopInstaller/Scoop/issues/3681))\r\n- **current:** Remove 'current' while it's not a junction ([#4687](https://github.com/ScoopInstaller/Scoop/issues/4687))\r\n- **depends:** Prevent error on no URL ([#4595](https://github.com/ScoopInstaller/Scoop/issues/4595))\r\n- **depends:** Check if extractor is available ([#4042](https://github.com/ScoopInstaller/Scoop/issues/4042))\r\n- **decompress:** Fix nested Zstd archive extraction ([#4608](https://github.com/ScoopInstaller/Scoop/issues/4608), [#4639](https://github.com/ScoopInstaller/Scoop/issues/4639))\r\n- **installed:** Fix 'core/installed' that mark failed app as 'installed' ([#4650](https://github.com/ScoopInstaller/Scoop/issues/4650), [#4676](https://github.com/ScoopInstaller/Scoop/issues/4676), [#4689](https://github.com/ScoopInstaller/Scoop/issues/4689), [#4785](https://github.com/ScoopInstaller/Scoop/issues/4785))\r\n- **no-junctions:** Fix error when `NO_JUNCTIONS` is been set ([#4722](https://github.com/ScoopInstaller/Scoop/issues/4722), [#4726](https://github.com/ScoopInstaller/Scoop/issues/4726))\r\n- **shim:** Fix PS1 shim error when in different drive in PS7 ([#4614](https://github.com/ScoopInstaller/Scoop/issues/4614))\r\n- **shim:** Fix `sh` shim error in WSL ([#4637](https://github.com/ScoopInstaller/Scoop/issues/4637))\r\n- **shim:** Use `-file` instead of `-command` in ps1 script shims ([#4721](https://github.com/ScoopInstaller/Scoop/issues/4721))\r\n- **shim:** Fix exe shim when app path has white spaces ([#4734](https://github.com/ScoopInstaller/Scoop/issues/4734), [#4780](https://github.com/ScoopInstaller/Scoop/issues/4780))\r\n- **versions:** Fix wrong version number when only one version dir ([#4679](https://github.com/ScoopInstaller/Scoop/issues/4679))\r\n- **versions:** Get current version from failed installation if possible ([#4720](https://github.com/ScoopInstaller/Scoop/issues/4720), [#4725](https://github.com/ScoopInstaller/Scoop/issues/4725))\r\n- **scoop-alias:** Fix alias initialization ([#4737](https://github.com/ScoopInstaller/Scoop/issues/4737))\r\n- **scoop-checkup:** Skip 'check_windows_defender' when have not admin privileges ([#4699](https://github.com/ScoopInstaller/Scoop/issues/4699))\r\n- **scoop-cleanup:** Remove apps other than current version ([#4665](https://github.com/ScoopInstaller/Scoop/issues/4665))\r\n- **scoop-search:** Remove redundant 'bucket/' in search result ([#4773](https://github.com/ScoopInstaller/Scoop/issues/4773))\r\n- **scoop-update:** Skip updating non git buckets ([#4670](https://github.com/ScoopInstaller/Scoop/issues/4670), [#4672](https://github.com/ScoopInstaller/Scoop/issues/4672))\r\n\r\n### Performance Improvements\r\n\r\n- **uninstall:** Avoid checking all files for unlinking persisted data ([#4681](https://github.com/ScoopInstaller/Scoop/issues/4681), [#4763](https://github.com/ScoopInstaller/Scoop/issues/4763))\r\n\r\n### Code Refactoring\r\n\r\n- **depends:** Rewrite 'depends.ps1' ([#4638](https://github.com/ScoopInstaller/Scoop/issues/4638), [#4673](https://github.com/ScoopInstaller/Scoop/issues/4673))\r\n- **mklink:** Use 'New-Item' instead of 'mklink' ([#4690](https://github.com/ScoopInstaller/Scoop/issues/4690))\r\n- **rmdir:** Use 'Remove-Item' instead of 'rmdir' ([#4691](https://github.com/ScoopInstaller/Scoop/issues/4691))\r\n- **COMSPEC:** Deprecate use of subshell cmd.exe ([#4692](https://github.com/ScoopInstaller/Scoop/issues/4692))\r\n- **git:** Use 'git -C' to specify the work directory instead of 'Push-Location'/'Pop-Location' ([#4697](https://github.com/ScoopInstaller/Scoop/issues/4697))\r\n- **scoop-info:** Use List View for output ([#4741](https://github.com/ScoopInstaller/Scoop/issues/4741))\r\n- **scoop-config:** Use underscores everywhere ([#4745](https://github.com/ScoopInstaller/Scoop/issues/4745))\r\n\r\n### Builds\r\n\r\n- **checkver:** Fix output with '-Version' ([#3774](https://github.com/ScoopInstaller/Scoop/issues/3774))\r\n- **schema:** Add '$schema' property ([#4623](https://github.com/ScoopInstaller/Scoop/issues/4623))\r\n- **schema:** Add explicit escape to opening bracket matcher in jp/jsonpath regex ([#3719](https://github.com/ScoopInstaller/Scoop/issues/3719))\r\n- **schema:** Fix typo ('note' -> 'notes') ([#4678](https://github.com/ScoopInstaller/Scoop/issues/4678))\r\n- **tests:** Support both AppVeyor and GitHub Actions ([#4655](https://github.com/ScoopInstaller/Scoop/issues/4655))\r\n- **tests:** Run GitHub Actions CI on each commit ([#4664](https://github.com/ScoopInstaller/Scoop/issues/4664))\r\n- **tests:** Use cache in GitHub Actions ([#4671](https://github.com/ScoopInstaller/Scoop/issues/4671))\r\n- **tests:** Disable CI test on 'push' ([#4677](https://github.com/ScoopInstaller/Scoop/issues/4677))\r\n- **vscode-settings:** Remove 'formatOnSave' trigger ([#4635](https://github.com/ScoopInstaller/Scoop/issues/4635))\r\n\r\n### Styles\r\n\r\n- **test:** Format scripts by VSCode's PowerShell extension ([#4609](https://github.com/ScoopInstaller/Scoop/issues/4609))\r\n- **style:** Use correct casing for `$PSScriptRoot` ([#4775](https://github.com/ScoopInstaller/Scoop/issues/4775))\r\n\r\n### Tests\r\n\r\n- **test-bin:** Only write output file in CI and fix trailing whitespaces ([#4613](https://github.com/ScoopInstaller/Scoop/issues/4613))\r\n- **manifest:** Fix manifests validation ([#4620](https://github.com/ScoopInstaller/Scoop/issues/4620))\r\n- **zstd:** Fix 'zstd' extraction error in test ([#4651](https://github.com/ScoopInstaller/Scoop/issues/4651))\r\n\r\n### Documentation\r\n\r\n- **changelog:** Add 'CHANGLOG.md' ([#4600](https://github.com/ScoopInstaller/Scoop/issues/4600))\r\n- **changelog:** Rearrange CHANGELOG ([#4729](https://github.com/ScoopInstaller/Scoop/issues/4729))\r\n- **changelog:** Link CHANGELOG headers to 'releases/tag' ([#4730](https://github.com/ScoopInstaller/Scoop/issues/4730))\r\n\r\n## [2021-12-26](https://github.com/ScoopInstaller/Scoop/compare/2021-11-22...2021-12-26)\r\n\r\n### Features\r\n\r\n- **core:** Redirect 'StandardError' in `Invoke-ExternalCommand()` ([#4570](https://github.com/ScoopInstaller/Scoop/issues/4570), [#4582](https://github.com/ScoopInstaller/Scoop/issues/4582))\r\n- **install:** Add portableapps.com to strip_filename skips ([#3244](https://github.com/ScoopInstaller/Scoop/issues/3244))\r\n- **install:** Show manifest on installation ([#4155](https://github.com/ScoopInstaller/Scoop/issues/4155), [fb496c48](https://github.com/ScoopInstaller/Scoop/commit/fb496c482bec4063e01b328f943224ab703dbbd8), [#4581](https://github.com/ScoopInstaller/Scoop/issues/4581))\r\n- **template:** Add issue/PR templates ([#4572](https://github.com/ScoopInstaller/Scoop/issues/4572))\r\n- **scoop-cat:** Add `scoop cat` command ([#4532](https://github.com/ScoopInstaller/Scoop/issues/4532))\r\n- **scoop-config:** Document all configuration options ([#4579](https://github.com/ScoopInstaller/Scoop/issues/4579))\r\n\r\n### Bug Fixes\r\n\r\n- **bucket:** Remove JetBrains bucket ([dec25980](https://github.com/ScoopInstaller/Scoop/commit/dec25980525a81c176b3fd5f238e964db00f3be3))\r\n- **bucket:** Remove nightlies bucket ([48b035d7](https://github.com/ScoopInstaller/Scoop/commit/48b035d7f99baa2e81d87ead4ff03a9594e49c3d))\r\n- **core:** Escape '.' in 'parse_app()'. ([#4578](https://github.com/ScoopInstaller/Scoop/issues/4578))\r\n- **core:** Use '-Encoding ASCII' in 'Out-File' ([#4571](https://github.com/ScoopInstaller/Scoop/issues/4571))\r\n- **depends:** Specify function scope ([4d5fee36](https://github.com/ScoopInstaller/Scoop/commit/4d5fee36e1ed13fc850fd22a5414186aec030c6e))\r\n- **install:** Use `Select-CurrentVersion` ([#4535](https://github.com/ScoopInstaller/Scoop/issues/4535))\r\n- **install:** 'env_add_path' doesn't append '.' ([#4550](https://github.com/ScoopInstaller/Scoop/issues/4550))\r\n- **repo:** Update repo links ([cbe29edd](https://github.com/ScoopInstaller/Scoop/commit/cbe29eddb3475e34740300eb1c2c52715446e3be))\r\n- **scoop-update:** Update apps with '--all' ([ac71fccb](https://github.com/ScoopInstaller/Scoop/commit/ac71fccbecb3d4158f249db9c1b9bb043cb8e966))\r\n- **scoop-update:** Fix scoop update -a requiring arguments ([#4531](https://github.com/ScoopInstaller/Scoop/issues/4531))\r\n\r\n### Code Refactoring\r\n\r\n- **shim:** Rework shimming logic ([#4543](https://github.com/ScoopInstaller/Scoop/issues/4543), [#4555](https://github.com/ScoopInstaller/Scoop/issues/4555), [3c90d1a0](https://github.com/ScoopInstaller/Scoop/commit/3c90d1a0701b0b64730dbf9ebc8d31f9b9c238f1), [2ec00d57](https://github.com/ScoopInstaller/Scoop/commit/2ec00d576c7e594dc5c0f1eac4536c5310ce6f17))\r\n\r\n### Builds\r\n\r\n- **auto-pr:** Remove hardcoded 'master' branch ([#4567](https://github.com/ScoopInstaller/Scoop/issues/4567))\r\n- **checkver:** Improve JSONPath extraction support ([#4522](https://github.com/ScoopInstaller/Scoop/issues/4522))\r\n- **checkver:** Use GitHub token from environment ([#4557](https://github.com/ScoopInstaller/Scoop/issues/4557))\r\n- **schema:** Enable autoupdate for 'license' ([#4528](https://github.com/ScoopInstaller/Scoop/issues/4528), [#4596](https://github.com/ScoopInstaller/Scoop/issues/4596))\r\n\r\n### Documentation\r\n\r\n- **readme:** Add link to Contributing Guide ([5e11c94a](https://github.com/ScoopInstaller/Scoop/commit/5e11c94a544ff2adbdbec5072c32a94d3e5acb9c))\r\n- **readme:** Fix links ([3bb7036e](https://github.com/ScoopInstaller/Scoop/commit/3bb7036ee111bfe58e82ba3d0fd39189b058776a))\r\n\r\n### Reverts\r\n\r\n- **shim:** Revert [#4229](https://github.com/ScoopInstaller/Scoop/issues/4229) ([#4553](https://github.com/ScoopInstaller/Scoop/issues/4553))\r\n\r\n## [2021-11-22](https://github.com/ScoopInstaller/Scoop/compare/2020-11-26...2021-11-22)\r\n\r\n### Features\r\n\r\n- **bucket:** Move extras bucket to [@ScoopInstaller](https://github.com/ScoopInstaller) ([3e9a4d4e](https://github.com/ScoopInstaller/Scoop/commit/3e9a4d4ea0e7e4d6489099c46a763f58db07e633))\r\n- **decompress:** Support Zstandard archive ([#4372](https://github.com/ScoopInstaller/Scoop/issues/4372), [e35ff313](https://github.com/ScoopInstaller/Scoop/commit/e35ff313a5d35cab1049024938c3423a5f6bf060), [47ebc6f1](https://github.com/ScoopInstaller/Scoop/commit/47ebc6f176b0db0afeb51b4ee237a20b2d8649e9))\r\n- **install:** Handle arch-specific env_add_path ([#4013](https://github.com/ScoopInstaller/Scoop/issues/4013))\r\n- **install:** s/lukesamson/ScoopInstaller in install.ps1 ([5226f26f](https://github.com/ScoopInstaller/Scoop/commit/5226f26f18157ed78f1529144404ec682374452e))\r\n- **message:** Add config to disable aria2 warning message ([#4422](https://github.com/ScoopInstaller/Scoop/issues/4422))\r\n- **shim:** Add another alternative shim written in rust ([#4229](https://github.com/ScoopInstaller/Scoop/issues/4229))\r\n- **scoop-prefix:** Remove unused imports and functions ([#4494](https://github.com/ScoopInstaller/Scoop/issues/4494))\r\n- **scoop-install:** Auto uninstall previous failed installation ([#3281](https://github.com/ScoopInstaller/Scoop/issues/3281))\r\n- **scoop-update:** Add flags `--all` as an alternative to '*' to update all ([#3871](https://github.com/ScoopInstaller/Scoop/issues/3871))\r\n\r\n### Bug Fixes\r\n\r\n- **core:** Change url() scope to avoid conflict with global aliases ([#4342](https://github.com/ScoopInstaller/Scoop/issues/4342), [#4492](https://github.com/ScoopInstaller/Scoop/issues/4492))\r\n- **install:** Fix `aria2`'s resume download feature ([#3292](https://github.com/ScoopInstaller/Scoop/issues/3292))\r\n- **shim:** Fixed trailing whitespace issue ([#4307](https://github.com/ScoopInstaller/Scoop/issues/4307))\r\n- **scoop-reset:** Skip when app instance is running ([#4359](https://github.com/ScoopInstaller/Scoop/issues/4359))\r\n\r\n### Code Refactoring\r\n\r\n- **versions:** Refactor 'versions.ps1' ([#3721](https://github.com/ScoopInstaller/Scoop/issues/3721), [e6630272](https://github.com/ScoopInstaller/Scoop/commit/e663027299d03ca768a252fa4bcbc51d124d4cae), [ae892138](https://github.com/ScoopInstaller/Scoop/commit/ae892138423bb9bbf54c8f0bed8331b93199f6b8))\r\n\r\n### Builds\r\n\r\n- **autoupdate:** Add multiple URL/hash/extract_dir... support ([#3518](https://github.com/ScoopInstaller/Scoop/issues/3518), [#4502](https://github.com/ScoopInstaller/Scoop/issues/4502))\r\n- **schema:** Fix Schema to support `+` in version ([#4504](https://github.com/ScoopInstaller/Scoop/issues/4504))\r\n- **supporting:** Update Json to 12.0.3, Json.Schema to 3.0.14 ([#3352](https://github.com/ScoopInstaller/Scoop/issues/3352))\r\n\r\n### Documentation\r\n\r\n- **readme:** Capitalize to prevent redirect ([#4483](https://github.com/ScoopInstaller/Scoop/issues/4483))\r\n- **readme:** s/lukesampson/ScoopInstaller in readme ([4f5acd72](https://github.com/ScoopInstaller/Scoop/commit/4f5acd72109a98a148d1bfa269c23a2d43644d23))\r\n- **readme:** Update extras bucket url in readme ([f1a46e10](https://github.com/ScoopInstaller/Scoop/commit/f1a46e109596c55c7e83c77fc1fc9daedbe71636))\r\n- **readme:** Update Java bucket text ([#4514](https://github.com/ScoopInstaller/Scoop/issues/4514))\r\n- **readme:** Update notes about the NirSoft bucket ([#4524](https://github.com/ScoopInstaller/Scoop/issues/4524))\r\n\r\n## [2020-11-26](https://github.com/ScoopInstaller/Scoop/compare/2020-10-22...2020-11-26)\r\n\r\n### Bug Fixes\r\n\r\n- **shim:** Fix Makefile typo ([0948824e](https://github.com/ScoopInstaller/Scoop/commit/0948824ec7269c979882d09342d9a269193cd674)) ([227de6cf](https://github.com/ScoopInstaller/Scoop/commit/227de6cfb8433a86ac0f0a279e691327ae04554c))\r\n\r\n## [2020-10-22](https://github.com/ScoopInstaller/Scoop/compare/2019-10-23...2020-10-22)\r\n\r\n### Features\r\n\r\n- **aria2:** Inline progress ([#3987](https://github.com/ScoopInstaller/Scoop/issues/3987))\r\n- **autoupdate:** Add $urlNoExt and $basenameNoExt substitutions ([#3742](https://github.com/ScoopInstaller/Scoop/issues/3742))\r\n- **config:** Add configuration option for default architecture ([#3778](https://github.com/ScoopInstaller/Scoop/issues/3778))\r\n- **install:** Follow HTTP redirections when downloading a file ([#3902](https://github.com/ScoopInstaller/Scoop/issues/3902))\r\n- **install:** Let pathes in 'env_add_path' be added ascendantly ([#3788](https://github.com/ScoopInstaller/Scoop/issues/3788), [#3976](https://github.com/ScoopInstaller/Scoop/issues/3976))\r\n- **list:** Display main bucket name ([#3759](https://github.com/ScoopInstaller/Scoop/issues/3759))\r\n- **shim:** Add alt-shim support ([#3998](https://github.com/ScoopInstaller/Scoop/issues/3998))\r\n- **scoop-checkup:** Add check_envs_requirements ([#3860](https://github.com/ScoopInstaller/Scoop/issues/3860))\r\n\r\n### Bug Fixes\r\n\r\n- **bucket:** Update scoop-nonportable URL ([#3776](https://github.com/ScoopInstaller/Scoop/issues/3776))\r\n- **download:** Fosshub download ([#4051](https://github.com/ScoopInstaller/Scoop/issues/4051))\r\n- **download:** Progress bar on small files ([96de9c14](https://github.com/ScoopInstaller/Scoop/commit/96de9c14bb483f9278e4b0a9e22b1923ee752901))\r\n- **hold:** Replace \"locked\" terminology with \"held\" for consistency ([#3917](https://github.com/ScoopInstaller/Scoop/issues/3917))\r\n- **git:** Don't execute autostart programs when executing git commands ([#3993](https://github.com/ScoopInstaller/Scoop/issues/3993))\r\n- **git:** Enforce pull without rebase ([#3765](https://github.com/ScoopInstaller/Scoop/issues/3765))\r\n- **install:** Aria2 inline progress negative values ([#4053](https://github.com/ScoopInstaller/Scoop/issues/4053))\r\n- **install:** Fix wrong output of 'install/failed' ([#3784](https://github.com/ScoopInstaller/Scoop/issues/3784), [#3867](https://github.com/ScoopInstaller/Scoop/issues/3867))\r\n- **install:** Re-add \"Don't send referer to portableapps.com\" ([#3961](https://github.com/ScoopInstaller/Scoop/issues/3961))\r\n- **scoop:** Remove temporary code from the scoop executable ([#3898](https://github.com/ScoopInstaller/Scoop/issues/3898))\r\n- **update:** Update outdated PowerShell 5 warning ([#3986](https://github.com/ScoopInstaller/Scoop/issues/3986))\r\n- **scoop-info:** Check bucket of installed app ([#3740](https://github.com/ScoopInstaller/Scoop/issues/3740))\r\n\r\n### Builds\r\n\r\n- **checkver:** Present script property ([#3900](https://github.com/ScoopInstaller/Scoop/issues/3900))\r\n\r\n### Tests\r\n\r\n- **init:** Force pester v4 ([#4040](https://github.com/ScoopInstaller/Scoop/issues/4040))\r\n\r\n## [2019-10-23](https://github.com/ScoopInstaller/Scoop/compare/2019-10-18...2019-10-23)\r\n\r\n### Features\r\n\r\n- **update:** Support $persist_dir in uninstaller.script ([#3692](https://github.com/ScoopInstaller/Scoop/issues/3692))\r\n\r\n### Bug Fixes\r\n\r\n- **core:** Use [Environment]::Is64BitOperatingSystem instead of [intptr]::size ([#3690](https://github.com/ScoopInstaller/Scoop/issues/3690))\r\n- **git:** Remove unnecessary git_proxy_cmd() calls for local commands ([8ee45a57](https://github.com/ScoopInstaller/Scoop/commit/8ee45a57dc01a525dcf8776bf9bb45263992c81f))\r\n- **install:** Check execution policy ([#3619](https://github.com/ScoopInstaller/Scoop/issues/3619))\r\n- **update:** Fix scoop update changelog output ([e997017f](https://github.com/ScoopInstaller/Scoop/commit/e997017f1a03e2eefef2157acdfefe2e4fced896))\r\n\r\n## [2019-10-18](https://github.com/ScoopInstaller/Scoop/compare/2019-06-24...2019-10-18)\r\n\r\n### Features\r\n\r\n- **core:** Tweak Invoke-ExternalCommand parameters ([#3547](https://github.com/ScoopInstaller/Scoop/issues/3547))\r\n- **install:** Use 7zip when available for faster zip file extraction ([#3460](https://github.com/ScoopInstaller/Scoop/issues/3460))\r\n- **install:** Add arch support to `env_add_path` and `env_set` ([#3503](https://github.com/ScoopInstaller/Scoop/issues/3503))\r\n- **install:** Allow $version to be used in uninstaller scripts ([#3592](https://github.com/ScoopInstaller/Scoop/issues/3592))\r\n- **install:** Allow installing specific version if latest is installed ([11c42d78](https://github.com/ScoopInstaller/Scoop/commit/11c42d782f8adb29fbe0d94daa5f121cdda935ab))\r\n- **update:** Allow updating apps from local manifest or URL ([#3685](https://github.com/ScoopInstaller/Scoop/issues/3685))\r\n\r\n### Bug Fixes\r\n\r\n- **autoupdate:** Decode basename when extract hash ([#3615](https://github.com/ScoopInstaller/Scoop/issues/3615))\r\n- **autoupdate:** Remove any whitespace from hash ([#3579](https://github.com/ScoopInstaller/Scoop/issues/3579))\r\n- **bucket:** Only lookup directories in buckets folder ([#3631](https://github.com/ScoopInstaller/Scoop/issues/3631))\r\n- **comspec:** Escape variables when calling COMSPEC commands ([#3538](https://github.com/ScoopInstaller/Scoop/issues/3538))\r\n- **decompress:** Fix bugs on extract_dir ([#3540](https://github.com/ScoopInstaller/Scoop/issues/3540))\r\n- **editorconfig:** Add missing } to bat/cmd regex ([#3529](https://github.com/ScoopInstaller/Scoop/issues/3529))\r\n- **help:** Rename help() to scoop_help() ([#3564](https://github.com/ScoopInstaller/Scoop/issues/3564))\r\n- **install:** Use Join-Path instead of string gluing. ([#3566](https://github.com/ScoopInstaller/Scoop/issues/3566))\r\n- **scoop-info:** Fix output for single binaries with alias ([#3651](https://github.com/ScoopInstaller/Scoop/issues/3651))\r\n- **scoop-info:** Remove a whitespace ([#3652](https://github.com/ScoopInstaller/Scoop/issues/3652))\r\n\r\n### Builds\r\n\r\n- **auto-pr:** Fix git status detection ([7decfd4c](https://github.com/ScoopInstaller/Scoop/commit/7decfd4c107b8d8a59d7eedfe8a56e1801120c2f))\r\n- **auto-pr:** Hard reset bucket after running ([79f8538b](https://github.com/ScoopInstaller/Scoop/commit/79f8538b57b9021db71a279879b9032fefd1ae52))\r\n- **checkurls:** Trim renaming suffix in url ([#3677](https://github.com/ScoopInstaller/Scoop/issues/3677))\r\n\r\n### Continuous Integration\r\n\r\n- **appveyor:** use VS2019 image to fix PS6 issues ([#3646](https://github.com/ScoopInstaller/Scoop/issues/3646))\r\n- **tests:** Do not force maintainers to have SCOOP_HELPERS ([#3604](https://github.com/ScoopInstaller/Scoop/issues/3604))\r\n\r\n### Documentation\r\n\r\n- **readme:** Improve installation instructions ([#3600](https://github.com/ScoopInstaller/Scoop/issues/3600))\r\n\r\n## [2019-06-24](https://github.com/ScoopInstaller/Scoop/compare/2019-05-15...2019-06-24)\r\n\r\n### Features\r\n\r\n- **decompress:** Add 'ExtractDir' to 'Expand-...' functions ([#3466](https://github.com/ScoopInstaller/Scoop/issues/3466), [#3470](https://github.com/ScoopInstaller/Scoop/issues/3470), [#3472](https://github.com/ScoopInstaller/Scoop/issues/3472))\r\n- **decompress:** Allow 'Expand-InnoArchive -ExtractDir' to accept '{xxx}' ([#3487](https://github.com/ScoopInstaller/Scoop/issues/3487))\r\n\r\n### Bug Fixes\r\n\r\n- **config:** Show correct output when removing a config value ([#3462](https://github.com/ScoopInstaller/Scoop/issues/3462))\r\n- **decompress:** Change dark.exe parameter order ([6141e46d](https://github.com/ScoopInstaller/Scoop/commit/6141e46d6ae74b3ccf65e02a1c3fc92e1b4d3e7a))\r\n- **proxy:** Rename parameters for Net.NetworkCredential ([#3483](https://github.com/ScoopInstaller/Scoop/issues/3483))\r\n\r\n### Code Refactoring\r\n\r\n- **core:**  `run()` -> 'Invoke-ExternalCommand()' ([#3432](https://github.com/ScoopInstaller/Scoop/issues/3432))\r\n\r\n### Builds\r\n\r\n- **checkhashes:** Checkhashes downloading twice when architecture properties does hot have url property ([#3479](https://github.com/ScoopInstaller/Scoop/issues/3479))\r\n- **checkhashes:** Do not call scoop directly ([#3527](https://github.com/ScoopInstaller/Scoop/issues/3527))\r\n\r\n### Documentation\r\n\r\n- **readme:** Add known buckets to end of readme ([2849e0f9](https://github.com/ScoopInstaller/Scoop/commit/2849e0f96099004f761d7d8c715377e0d2c105f2))\r\n- **readme:** Adjust URL of `runat.json` ([#3484](https://github.com/ScoopInstaller/Scoop/issues/3484))\r\n- **readme:** Fix a small typo ([#3512](https://github.com/ScoopInstaller/Scoop/issues/3512))\r\n- **readme:** Fix typo in readme ([03bb07c8](https://github.com/ScoopInstaller/Scoop/commit/03bb07c8231563fa3a2092b9b52d4dde372f2a8e))\r\n- **readme:** Update readme with correct count of nirsoft apps ([e8d0be66](https://github.com/ScoopInstaller/Scoop/commit/e8d0be663b3bab25d9ee55c597b90bf922f4ec5d))\r\n\r\n## [2019-05-15](https://github.com/ScoopInstaller/Scoop/compare/2019-05-12...2019-05-15)\r\n\r\n### Features\r\n\r\n- **manifest:** XPath support in checkver and autoupdate ([#3458](https://github.com/ScoopInstaller/Scoop/issues/3458))\r\n- **update:** Support changing scoop tracking repository ([#3459](https://github.com/ScoopInstaller/Scoop/issues/3459))\r\n\r\n### Bug Fixes\r\n\r\n- **autoupdate:** Handle xml namespace in xpath mode ([#3465](https://github.com/ScoopInstaller/Scoop/issues/3465))\r\n\r\n## [2019-05-12](https://github.com/ScoopInstaller/Scoop/releases/tag/2019-05-12)\r\n\r\n### BREAKING CHANGE\r\n\r\n- **core:** Finalize bucket extraction ([#3399](https://github.com/ScoopInstaller/Scoop/issues/3399))\r\n- **core:** Bucket extraction and refactoring ([#3449](https://github.com/ScoopInstaller/Scoop/issues/3449))\r\n\r\n### Features\r\n\r\n- **autoupdate:** Add 'regex' alias for 'find' ([3453487e](https://github.com/ScoopInstaller/Scoop/commit/3453487ed65378cc9ba2efc658ed6bc1431ef463))\r\n- **autoupdate:** Allow simple metalink and meta4 hash extraction ([ecf627c3](https://github.com/ScoopInstaller/Scoop/commit/ecf627c3b8493b3ccf7ddb882b0c946533774d76))\r\n- **autoupdate:** Add version variables to autoupdate.hash.regex ([#2966](https://github.com/ScoopInstaller/Scoop/issues/2996))\r\n- **autoupdate:** Autoupdate improvements ([#1371](https://github.com/ScoopInstaller/Scoop/issues/1371))\r\n- **autoupdate:** Convert base64 encoded hash values ([04c9ddeb](https://github.com/ScoopInstaller/Scoop/commit/04c9ddeb6d3b99496c39543ad468d34f4f1adeff))\r\n- **autoupdate:** Improve base64 hash detection ([310096e2](https://github.com/ScoopInstaller/Scoop/commit/310096e2386ff3bf9082d547b140a98b92b87a83))\r\n- **core:** Add basic WSL support by appending .exe to powershell ([#2323](https://github.com/ScoopInstaller/Scoop/issues/2323))\r\n- **core:** Add Expand-DarkArchive and some other dependency features ([#3450](https://github.com/ScoopInstaller/Scoop/issues/3450))\r\n- **core:** Enable TLS 1.2 in core.ps1 ([#2074](https://github.com/ScoopInstaller/Scoop/issues/2074))\r\n- **core:** Prepare extraction of main bucket ([#3060](https://github.com/ScoopInstaller/Scoop/issues/3060))\r\n- **core:** Support loading basedirs from config ([#3121](https://github.com/ScoopInstaller/Scoop/issues/3121))\r\n- **core:** Update requirement to version 5 or greater ([#3330](https://github.com/ScoopInstaller/Scoop/issues/3330))\r\n- **core:** Use consistent User-Agent Header on all webrequests ([12962acf](https://github.com/ScoopInstaller/Scoop/commit/12962acfa853593e371d09186e51660aece331e5))\r\n- **core:** Warn on shim overwrite ([#2033](https://github.com/ScoopInstaller/Scoop/issues/2033))\r\n- **debug:** Add option to indent debug output ([bf54a978](https://github.com/ScoopInstaller/Scoop/commit/bf54a978a1bc2efcde52513a60ec5bcb7bb1a44e))\r\n- **decompress:** Allow other args to be passthrough ([#3411](https://github.com/ScoopInstaller/Scoop/issues/3411))\r\n- **download:** Add support for multi-connection downloads via aria2c ([#2312](https://github.com/ScoopInstaller/Scoop/issues/2312))\r\n- **download:** Convert sourceforge urls to use downloads mirror ([#3340](https://github.com/ScoopInstaller/Scoop/issues/3340))\r\n- **install:** Add .NET 4.5 check to scoop install script ([e52c24c9](https://github.com/ScoopInstaller/Scoop/commit/e52c24c94ec805a327440cc07aec699afc7cc308))\r\n- **install:** Set file write permission to global persist dir ([#2524](https://github.com/ScoopInstaller/Scoop/issues/2524))\r\n- **json:** Normalize multi-line strings to string arrays on format ([#2444](https://github.com/ScoopInstaller/Scoop/issues/2444))\r\n- **persist:** Support persisting files without a file extension ([#2408](https://github.com/ScoopInstaller/Scoop/issues/2408))\r\n- **shim:** Add '.com'-type shim ([#3366](https://github.com/ScoopInstaller/Scoop/issues/3366))\r\n- **shim:** Enabled applications which require elevated privileges ([#2053](https://github.com/ScoopInstaller/Scoop/issues/2053))\r\n- **shim:** Enabled shimming of external applications ([#2072](https://github.com/ScoopInstaller/Scoop/issues/2072))\r\n- **shim:** Enabled wide characters forwarding in shims ([#2106](https://github.com/ScoopInstaller/Scoop/issues/2106))\r\n- **shim:** Make shim support PowerShell 2.0 ([#2562](https://github.com/ScoopInstaller/Scoop/issues/2562))\r\n- **shim:** Create sh shim ([#1951](https://github.com/ScoopInstaller/Scoop/issues/1951))\r\n- **shortcuts:** Add subdirectories/arguments for shortcuts ([#1945](https://github.com/ScoopInstaller/Scoop/issues/1945))\r\n- **shortcuts:** Allow $dir, $original_dir and $persist_dir substitutions for shortcuts ([f3ddf0c0](https://github.com/ScoopInstaller/Scoop/commit/f3ddf0c0f81ee2a11466edf5d9f6e38a0fc2b9d4))\r\n- **shortcuts:** Get start menu folder location from environment rather than predefined user profile path ([c245a7fe](https://github.com/ScoopInstaller/Scoop/commit/c245a7fe96ffa0b0fba23bd47f31480ea93cc183))\r\n- **uninstall:** Print purge step to console ([#3123](https://github.com/ScoopInstaller/Scoop/issues/3123))\r\n- **uninstall:** Add support for soft/purge uninstalling of scoop itself ([#2781](https://github.com/ScoopInstaller/Scoop/issues/2781))\r\n- **update:** Add hold/unhold command ([#3444](https://github.com/ScoopInstaller/Scoop/issues/3444))\r\n- **scoop-checkup:** Add NTFS check to checkup command ([#1944](https://github.com/ScoopInstaller/Scoop/issues/1944))\r\n- **scoop-checkup:** Check for LongPaths setting ([#3387](https://github.com/ScoopInstaller/Scoop/issues/3387))\r\n- **scoop-info:** Add scoop-info command ([#2165](https://github.com/ScoopInstaller/Scoop/issues/2165))\r\n- **scoop-info:** Support url manifest ([#2538](https://github.com/ScoopInstaller/Scoop/issues/2538))\r\n- **scoop-prefix:** Add scoop prefix command ([#2117](https://github.com/ScoopInstaller/Scoop/issues/2117))\r\n- **scoop-update:** Add notification for new main bucket ([#3392](https://github.com/ScoopInstaller/Scoop/issues/3392))\r\n- **scoop-update:** Show changelog after updating scoop and buckets ([56c35f8f](https://github.com/ScoopInstaller/Scoop/commit/56c35f8f05ed387997ef1a80ec0362adec6e51a5))\r\n- **scoop-which:** Also show other applications in PATH with 'scoop which' ([79bf99c3](https://github.com/ScoopInstaller/Scoop/commit/79bf99c3c110494d799e147263db7b6f2f921d4e))\r\n\r\n### Bug Fixes\r\n\r\n- **autoupdate:** Fix base64 hash extraction ([98afb999](https://github.com/ScoopInstaller/Scoop/commit/98afb99990561c4f98f1e1334f348e52b4bee4e7))\r\n- **autoupdate:** Fix base64 hash extraction length ([#2852](https://github.com/ScoopInstaller/Scoop/issues/2852))\r\n- **autoupdate:** Fix metalink hash extraction ([2ad54747](https://github.com/ScoopInstaller/Scoop/commit/2ad547477b1432e7a269c90b393d62d88dce9803))\r\n- **autoupdate:** Fix single line hash extraction ([#3015](https://github.com/ScoopInstaller/Scoop/issues/3015))\r\n- **autoupdate:** Improve auto-update hash extraction regex ([21bf0dea](https://github.com/ScoopInstaller/Scoop/commit/21bf0dea561db021aa59bcd9363792436ac7c162))\r\n- **autoupdate:** Linter fix ([c9539b65](https://github.com/ScoopInstaller/Scoop/commit/c9539b6575e8842a8f895d82b4119c3aef01d7c2))\r\n- **autoupdate:** Use normal variable instead of magic $matches variable name ([d74e0a85](https://github.com/ScoopInstaller/Scoop/commit/d74e0a85b4081745bd1ab107a45794f02299737d))\r\n- **bucket:** Change wording of new_issue_msg() ([e82587df](https://github.com/ScoopInstaller/Scoop/commit/e82587dfc41618474e03347df333e847dfaffc70))\r\n- **bucket:** Fix new_issue_msg ([#3375](https://github.com/ScoopInstaller/Scoop/issues/3375))\r\n- **bucket:** Use $_.Name on gci result ([1eb2609d](https://github.com/ScoopInstaller/Scoop/commit/1eb2609db51587772a4b5d1b6f58114f52639568))\r\n- **config:** Enable writing to hidden .scoop file ([#1982](https://github.com/ScoopInstaller/Scoop/issues/1982))\r\n- **config:** Save and load true/false values as booleans in scoops config ([16aec1a4](https://github.com/ScoopInstaller/Scoop/commit/16aec1a40b45ba241ef2ac45ccf89de7206891be))\r\n- **core:** Allowed underscores in package names ([#2930](https://github.com/ScoopInstaller/Scoop/issues/2930))\r\n- **core:** Clean up some error messages ([#2032](https://github.com/ScoopInstaller/Scoop/issues/2032))\r\n- **core:** Change sf regex not to break some manifests ([#2476](https://github.com/ScoopInstaller/Scoop/issues/2476))\r\n- **core:** Check if 7zip installed via Scoop instead of using 7z.exe from PATH ([55ce0c0b](https://github.com/ScoopInstaller/Scoop/commit/55ce0c0b0c481ec3807655cb7aeac6dfcf9ef271))\r\n- **core:** Filter null or empty string from Scoops directory settings ([5d5c7fa9](https://github.com/ScoopInstaller/Scoop/commit/5d5c7fa91c03f05b705d3420618ec96d8e870174))\r\n- **core:** Fix \"enable-encryptionscheme\" for OSes before Windows 10 ([#2084](https://github.com/ScoopInstaller/Scoop/issues/2084))\r\n- **core:** Fix bug with Start-Process -Wait, exclusive to PowerShell Core on Windows 7 ([#3415](https://github.com/ScoopInstaller/Scoop/issues/3415))\r\n- **core:** Fix for relative paths ([ff9c0c3d](https://github.com/ScoopInstaller/Scoop/commit/ff9c0c3dafb3567ee958379b83205da84a925ecf))\r\n- **core:** Fix robocopy not releasing a directory after moving it ([e2792f2e](https://github.com/ScoopInstaller/Scoop/commit/e2792f2e02adee5947ebb95022a62282fb61024f))\r\n- **core:** Fix substitute() for arrays ([#2048](https://github.com/ScoopInstaller/Scoop/issues/2048))\r\n- **core:** Format hashes to lowercase ([5d56f8ff](https://github.com/ScoopInstaller/Scoop/commit/5d56f8ff5760ddedaf44eaf9652000e833b0944e))\r\n- **core:** Invoke powershell with -noprofile flag from bash shims ([#3165](https://github.com/ScoopInstaller/Scoop/issues/3165))\r\n- **core:** Removed the bucket from the app name when checking directories ([#2435](https://github.com/ScoopInstaller/Scoop/issues/2435))\r\n- **core:** Return true for checking if a directory is 'in' itself ([ac8a1567](https://github.com/ScoopInstaller/Scoop/commit/ac8a156796cb6d3d9cba24a2839271d924ab8fea))\r\n- **core:** Store last update time as String ([e8af15cc](https://github.com/ScoopInstaller/Scoop/commit/e8af15cc0615b707aee79be95f9c00e3ae0bfd9b))\r\n- **decompress:** Add .bz2 files to decompression ([#2085](https://github.com/ScoopInstaller/Scoop/issues/2085))\r\n- **decompress:** Added retry when unzip fail because of AV ([#1822](https://github.com/ScoopInstaller/Scoop/issues/1822))\r\n- **decompress:** Catch unzip failures from bad file names ([#2472](https://github.com/ScoopInstaller/Scoop/issues/2472))\r\n- **decompress:** Compatible Expand-ZipArchive() with Pscx ([#3425](https://github.com/ScoopInstaller/Scoop/issues/3425))\r\n- **decompress:** Correct deprecation function name ([#3406](https://github.com/ScoopInstaller/Scoop/issues/3406))\r\n- **decompress:** Fix dark parameter order ([87a1e784](https://github.com/ScoopInstaller/Scoop/commit/87a1e784d7463fea36fa41fcb7cb5537cbcfdc52))\r\n- **depends:** Don't force adding dark dependency ([#3453](https://github.com/ScoopInstaller/Scoop/issues/3453))\r\n- **depends:** Don't include the requested app in the list of dependencies ([1bc6a479](https://github.com/ScoopInstaller/Scoop/commit/1bc6a479ee969e44e2b0d83ed6ff19efd86c6ae9))\r\n- **depends:** Fix empty bucket name ([#2827](https://github.com/ScoopInstaller/Scoop/issues/2827))\r\n- **depends:** Fix null reference error when no buckets are configured ([88040972](https://github.com/ScoopInstaller/Scoop/commit/88040972a30b459a3859c7c2f883e47e19da9f84))\r\n- **depends:** Show message about missing bucket when installing dependencies ([7a6218c5](https://github.com/ScoopInstaller/Scoop/commit/7a6218c58677170fe32cf1c2bfcfe7488e4c3655))\r\n- **download:** Don't send referer to portableapps.com ([0c2b3da3](https://github.com/ScoopInstaller/Scoop/commit/0c2b3da3ff639722ad3ddf587219bb3155e97c7f))\r\n- **download:** Fix fosshub downloads with aria2c ([803525a8](https://github.com/ScoopInstaller/Scoop/commit/803525a8661ffaa39fc4ad6f0dc776cccad4c45e))\r\n- **download:** Interrupt download causes partial cache file to be used for next install ([5be02865](https://github.com/ScoopInstaller/Scoop/commit/5be0286561398debfee2c0610e51f006ef2dc2fb))\r\n- **download:** Overwrite any existing files when extracting ([58cca68f](https://github.com/ScoopInstaller/Scoop/commit/58cca68f7565bd5e8f63e08ad052c0029b98a23d))\r\n- **download:** Show warning about SourceForge.net hash validation fails ([8504338b](https://github.com/ScoopInstaller/Scoop/commit/8504338bc5faab3235cef2e1c2f41abd7ae496eb))\r\n- **getopt:** Don't try to parse int arguments ([23fe5a53](https://github.com/ScoopInstaller/Scoop/commit/23fe5a5319d4ede84c532df04f576c3854fd5826))\r\n- **getopt:** Don't try to parse array arguments ([9b6e7b5e](https://github.com/ScoopInstaller/Scoop/commit/9b6e7b5e0f7f6ddecdb139f932ad7d582fe639a4))\r\n- **getopt:** Return remaining args, use getopt for scoop install ([b7cfd6fd](https://github.com/ScoopInstaller/Scoop/commit/b7cfd6fdb0e18a623ceacfa6fc824241dabc6d01))\r\n- **getopt:** Skip if arg is $null ([f2d9f0d7](https://github.com/ScoopInstaller/Scoop/commit/f2d9f0d79fdf4a63879c1b87a6c0f5317a40a1d9))\r\n- **getopt:** Skip arg if it's decimal ([5f0c8cfb](https://github.com/ScoopInstaller/Scoop/commit/5f0c8cfb0a34078bb8118a21191cf046ddad18ac))\r\n- **git:** Disable git pager when running git log ([cac99759](https://github.com/ScoopInstaller/Scoop/commit/cac9975924691fe6e608789218b06be56bb8c658))\r\n- **git:** Fix update log output ([0daa25c6](https://github.com/ScoopInstaller/Scoop/commit/0daa25c6300cd2ab605d63b71037d741c9c904c6))\r\n- **json:** Catch JsonReaderException ([fb58e92c](https://github.com/ScoopInstaller/Scoop/commit/fb58e92c13552199f19f5df112801fc41321eee2))\r\n- **install:** Add filename to warning for files without hash in the manifest ([4c9beee8](https://github.com/ScoopInstaller/Scoop/commit/4c9beee8f2df891b2ec314e1efffb2ee9d5cca20))\r\n- **install:** Add multi-line support to pre/post_install ([#1980](https://github.com/ScoopInstaller/Scoop/issues/1980))\r\n- **install:** Added exclusion for sourceforge. [#METR-21516] ([#2109](https://github.com/ScoopInstaller/Scoop/issues/2109))\r\n- **install:** Ignore url fragment for PowerShell Core 6.1.0 ([#2602](https://github.com/ScoopInstaller/Scoop/issues/2602))\r\n- **install:** Fix fail when installing from non-default bucket ([#2247](https://github.com/ScoopInstaller/Scoop/issues/2247))\r\n- **install:** Fix PowerShell core crash ([#2554](https://github.com/ScoopInstaller/Scoop/issues/2554))\r\n- **install:** Option to skip hash validation and error message improvements ([#2260](https://github.com/ScoopInstaller/Scoop/issues/2260))\r\n- **install:** Remove env_ensure_home ([#1967](https://github.com/ScoopInstaller/Scoop/issues/1967))\r\n- **install:** Show first 8 bytes of file in the hash check error message ([e4cbb42e](https://github.com/ScoopInstaller/Scoop/commit/e4cbb42e64843e53b5b24de92f43062bca98c474))\r\n- **persist:** Fix condition for persist_permission() ([eb7b7cbf](https://github.com/ScoopInstaller/Scoop/commit/eb7b7cbf4f30e4122762856723155f3c1e980d1b)) ([1a2598bc](https://github.com/ScoopInstaller/Scoop/commit/1a2598bc3082a2e3fffac1a6bea0b42032e388f0))\r\n- **persist:** Fixed persisting bug when force update app with same version ([#2774](https://github.com/ScoopInstaller/Scoop/issues/2774))\r\n- **persist:** Fix the target didn't be created ([#3008](https://github.com/ScoopInstaller/Scoop/issues/3008))\r\n- **persist:** Prevent directory creation from being output ([#1999](https://github.com/ScoopInstaller/Scoop/issues/1999))\r\n- **scoop:** Force to add new main bucket ([#3419](https://github.com/ScoopInstaller/Scoop/issues/3419))\r\n- **shim:** Fix .ps1 shim parsing logic ([#2564](https://github.com/ScoopInstaller/Scoop/issues/2564))\r\n- **shim:** Fixed ps1/jar->ps1 shims args handling ([#2120](https://github.com/ScoopInstaller/Scoop/issues/2120))\r\n- **shortcuts:** Improve Shortcut creation ([83b82386](https://github.com/ScoopInstaller/Scoop/commit/83b823868f5ef5256d3dcfbecff278bb355fefc8))\r\n- **uninstall:** Better error handling during uninstallation ([#2079](https://github.com/ScoopInstaller/Scoop/issues/2079))\r\n- **uninstall:** Uninstall fails to remove architecture-specific shims ([8b1871b2](https://github.com/ScoopInstaller/Scoop/commit/8b1871b20df4dbf1b603d4066937ba213c03bb32))\r\n- **update:** Rewording PowerShell update notice ([d006fb93](https://github.com/ScoopInstaller/Scoop/commit/d006fb9315b55a9d8e6a36218cf5dbdde51433ec))\r\n- **versions:** Improvements for the reset command to deal with empty current alias dir correctly ([#2896](https://github.com/ScoopInstaller/Scoop/issues/2896))\r\n- **scoop-alias:** Improve \"scoop alias list\" output ([#2163](https://github.com/ScoopInstaller/Scoop/issues/2163))\r\n- **scoop-cache:** Display help on incorrect cache command ([#3431](https://github.com/ScoopInstaller/Scoop/issues/3431))\r\n- **scoop-cache:** scoop cache command not using $SCOOP_CACHE ([#1990](https://github.com/ScoopInstaller/Scoop/issues/1990))\r\n- **scoop-info:** Improve scoop-info license attributes output ([#2397](https://github.com/ScoopInstaller/Scoop/issues/2397))\r\n- **scoop-install:** Prevent installing programs from JSON multiple times ([936cf9cb](https://github.com/ScoopInstaller/Scoop/commit/936cf9cbb0c4dd3a594fbaf5c696ce519e586d8c))\r\n- **scoop-reset:** Persist data on reset ([#2773](https://github.com/ScoopInstaller/Scoop/issues/2773))\r\n- **scoop-reset:** Re-create shortcuts ([6e5b7e57](https://github.com/ScoopInstaller/Scoop/commit/6e5b7e57bb0628f072872d9a5b8c8a0fa58389e1))\r\n- **scoop-search:** Better handling for invalid query ([bf024705](https://github.com/ScoopInstaller/Scoop/commit/bf024705a8cc38592571aa3026dca2471f19ac5a))\r\n- **scoop-uninstall:** Checked if uninstaller removed its directory ([#2078](https://github.com/ScoopInstaller/Scoop/issues/2078))\r\n- **scoop-update:** Add config option \"show_update_log\" ([d68cb3ce](https://github.com/ScoopInstaller/Scoop/commit/d68cb3ce52acaa9983f278822febd506f54ebe02))\r\n- **scoop-update:** First scoop update fails because scoop deletes itself too early ([376630fd](https://github.com/ScoopInstaller/Scoop/commit/376630fd80a3f9012fd6e673460b9e28e375e951))\r\n- **scoop-update:** Fix branch switching ([#3372](https://github.com/ScoopInstaller/Scoop/issues/3372))\r\n- **scoop-update:** Fix update with cookies ([#3261](https://github.com/ScoopInstaller/Scoop/issues/3261))\r\n- **scoop-update:** Improve is_scoop_outdated() and add last_scoop_update() ([f3f559c4](https://github.com/ScoopInstaller/Scoop/commit/f3f559c460406689dab2375310fb1026e2be58bd))\r\n- **scoop-update:** Resolve linting, fix appveyor tests error ([#2148](https://github.com/ScoopInstaller/Scoop/issues/2148))\r\n\r\n### Code Refactoring\r\n\r\n- **bucket:** Move function into lib from lib-exec ([#3062](https://github.com/ScoopInstaller/Scoop/issues/3062))\r\n- **bucket:** Optimize buckets function ([#3341](https://github.com/ScoopInstaller/Scoop/issues/3341))\r\n- **config:** Move configuration handling to core.ps1 ([#3242](https://github.com/ScoopInstaller/Scoop/issues/3242))\r\n- **core:** aria2_path() -> file_path() ([0f464016](https://github.com/ScoopInstaller/Scoop/commit/0f4640168da8d68a52eb2b80af2f3ffa01c9b658))\r\n- **core:** cmd_available() -> Test-CommandAvailable() ([#3314](https://github.com/ScoopInstaller/Scoop/issues/3314))\r\n- **core:** ensure_all_installed() -> Confirm-InstallationStatus() ([#3293](https://github.com/ScoopInstaller/Scoop/issues/3293))\r\n- **core:** Move default_aliases into the scoped function ([#3233](https://github.com/ScoopInstaller/Scoop/issues/3233))\r\n- **core:** Refactor function names and fix installing 7zip locally if already globally available ([#3416](https://github.com/ScoopInstaller/Scoop/issues/3416))\r\n- **core:** Simplified last_scoop_update() ([#2931](https://github.com/ScoopInstaller/Scoop/issues/2931))\r\n- **core:** Tweak SecurityProtocol usage ([#3065](https://github.com/ScoopInstaller/Scoop/issues/3065))\r\n- **decompress:** Refactored (w/ install.ps1, core.ps1) ([#3169](https://github.com/ScoopInstaller/Scoop/issues/3169))\r\n- **decompress:** Refactor extraction handling functions ([#3204](https://github.com/ScoopInstaller/Scoop/issues/3204))\r\n- **download:** Download functionality refactor ([#1329](https://github.com/ScoopInstaller/Scoop/issues/1329))\r\n- **install:** Rename locate() to Find-Manifest() ([9eed3d89](https://github.com/ScoopInstaller/Scoop/commit/9eed3d8914c7a0fa294110eb0761776a01adf034))\r\n\r\n### Builds\r\n\r\n- **auto-pr:** Add -App parameter ([#3157](https://github.com/ScoopInstaller/Scoop/issues/3157))\r\n- **auto-pr:** Add SkipUpdated parameter ([#3168](https://github.com/ScoopInstaller/Scoop/issues/3168))\r\n- **checkhashes:** Add bin\\checkhashes.ps1 ([#2766](https://github.com/ScoopInstaller/Scoop/issues/2766))\r\n- **checkurls:** Add SkipValid Parameter ([#2845](https://github.com/ScoopInstaller/Scoop/issues/2845))\r\n- **checkurls:** Import config.ps1 in checkurls.ps1 ([126e9c97](https://github.com/ScoopInstaller/Scoop/commit/126e9c97d2ef7db537a5137167089a97f343e98e))\r\n- **checkver:** Add 'useragent' property ([8feb3867](https://github.com/ScoopInstaller/Scoop/commit/8feb3867a74ea0340585e3e695934d96cf483a05))\r\n- **checkver:** Add 'jsonpath' alias for 'jp' ([76fdb6b7](https://github.com/ScoopInstaller/Scoop/commit/76fdb6b74c1772bf607d2dad5f6c50269369ff88))\r\n- **checkver:** Add 're' alias 'regex' ([468649c8](https://github.com/ScoopInstaller/Scoop/commit/468649c88dea9c1ff9614f2cdf29a521d572664e))\r\n- **checkver:** Allow using the current version in checkver URL ([607ac9ca](https://github.com/ScoopInstaller/Scoop/commit/607ac9ca7c185da61e2c746ea87d28c2abe62adc))\r\n- **checkver:** Fix example parameters ([#3413](https://github.com/ScoopInstaller/Scoop/issues/3413))\r\n- **checkver:** GitHub checkver case-insensitive version check ([2e2633e9](https://github.com/ScoopInstaller/Scoop/commit/2e2633e9640f6cab5c2f895b680345cd6ca))\r\n- **checkver:** Remove old commented code ([72754036](https://github.com/ScoopInstaller/Scoop/commit/72754036a251fffd2f2eb0e242edfd9895543e3c))\r\n- **checkver:** Resolve issue on Powershell >6.1.0 ([#2592](https://github.com/ScoopInstaller/Scoop/issues/2592))\r\n- **checkver:** Support skipping up to date manifests ([#2624](https://github.com/ScoopInstaller/Scoop/issues/2624))\r\n- **schema:** Add shortcutsArray definition to schema.json ([0c7e6002](https://github.com/ScoopInstaller/Scoop/commit/0c7e60024a06e122331b17a204a158e4c5800a3d))\r\n- **schema:** extract_to property is on active duty (not deprecated) ([59e994c5](https://github.com/ScoopInstaller/Scoop/commit/59e994c5fdeb8dffe6037ca6767d56ad13bf04da))\r\n- **schema:** Improve comments in schema.json ([b5ed0761](https://github.com/ScoopInstaller/Scoop/commit/b5ed0761aef4f3e864533dc0460d110115850ba7))\r\n- **supporting:** Update validator.exe and shim.exe ([#2024](https://github.com/ScoopInstaller/Scoop/issues/2024), [#2034](https://github.com/ScoopInstaller/Scoop/issues/2034))\r\n- **supporting:** Update Newtonsoft.Json to 11.0.2, Newtonsoft.Json.Schema to 3.0.10 ([#3043](https://github.com/ScoopInstaller/Scoop/issues/3043))\r\n- **validator:** Improve error reporting, add support for multiple files ([#3134](https://github.com/ScoopInstaller/Scoop/issues/3134))\r\n\r\n### Continuous Integration\r\n\r\n- **appveyor:** Rebuild cache ([7311b41b](https://github.com/ScoopInstaller/Scoop/commit/7311b41b8d1e2e010175fb7d079662bbcba5bac8))\r\n- **appveyor:** Run tests for PowerShell 5 and 6 ([#2603](https://github.com/ScoopInstaller/Scoop/issues/2603))\r\n- **test:** Improve installation of lessmsi and innounp ([#3409](https://github.com/ScoopInstaller/Scoop/issues/3409))\r\n\r\n### Styles\r\n\r\n- **lint:** PSAvoidUsingCmdletAliases ([#2075](https://github.com/ScoopInstaller/Scoop/issues/2075))\r\n\r\n### Tests\r\n\r\n- **bucket:** Add importable tests for Buckets ([478f52c4](https://github.com/ScoopInstaller/Scoop/commit/478f52c421ca35ea35b5fd0b2df2631cf7d82487))\r\n- **bucket:** Fix manifest tests for buckets ([589303fa](https://github.com/ScoopInstaller/Scoop/commit/589303facc5284f6f95c1305191e0558c0169691))\r\n- **bucket:** Handle JSON.NET schema validation limit exceeded. ([139813a8](https://github.com/ScoopInstaller/Scoop/commit/139813a8f50ace85e2752d9b6c9f82fc64ff3e48))\r\n- **file:** Move style constraints tests to separate test file ([7b7113fc](https://github.com/ScoopInstaller/Scoop/commit/7b7113fc3bf962aaeba625f58341c30a80f0fe6a))\r\n- **linux:** Fix some tests on linux ([#2153](https://github.com/ScoopInstaller/Scoop/issues/2153))\r\n- **manifest:** Expose bucketdir variable in manifest test script ([#2182](https://github.com/ScoopInstaller/Scoop/issues/2182))\r\n- **test:** Add -TestPath param to test.ps1 ([f857dce9](https://github.com/ScoopInstaller/Scoop/commit/f857dce9f59a490f6dd07085c3abaa51e9577fda))\r\n- **test:** Force install PSScriptAnalyzer and BuildHelpers ([7a1b5a18](https://github.com/ScoopInstaller/Scoop/commit/7a1b5a1840e30321951fa0f5333c34d10f57fa94))\r\n- **test:** Require BuildHelpers version 2.0.0 ([ac3ee766](https://github.com/ScoopInstaller/Scoop/commit/ac3ee766722e99c1f15dc60a1f1dfb0a48428c55))\r\n- **test:** Update BuildHelpers to version 2.0.1 ([dde4d0f9](https://github.com/ScoopInstaller/Scoop/commit/dde4d0f93f260191af5524c0ecab927f3e252361))\r\n- **core:** Use Pester 4.0 syntax in core tests ([#2712](https://github.com/ScoopInstaller/Scoop/issues/2712))\r\n- **install:** Use Pester 4.0 syntax to the install tests ([#2713](https://github.com/ScoopInstaller/Scoop/issues/2713))\r\n- **test:** Use Pester 4.0 syntax to multiple files ([#2714](https://github.com/ScoopInstaller/Scoop/issues/2714))\r\n\r\n### Documentation\r\n\r\n- **readme:** Add discord chat badge ([#3241](https://github.com/ScoopInstaller/Scoop/issues/3241))\r\n- **readme:** Add more details about scoops installation ([#2273](https://github.com/ScoopInstaller/Scoop/issues/2273))\r\n- **readme:** Corrected enable powershell executionpolicy ([#2020](https://github.com/ScoopInstaller/Scoop/issues/2020))\r\n- **readme:** Update Discord invite link ([5f269249](https://github.com/ScoopInstaller/Scoop/commit/5f269249609b43f5c4fa9aba4def999e7ee05fe1))\r\n- **readme:** Update requirements note ([#2509](https://github.com/ScoopInstaller/Scoop/issues/2509))\r\n- **readme:** Fix typo (you -> your), (it's -> its) ([#2698](https://github.com/ScoopInstaller/Scoop/issues/2698))\r\n- **readme:** Remove trailing whitespaces ([d25186bf](https://github.com/ScoopInstaller/Scoop/commit/d25186bf1f833e30d8c5b530b7c260fe399b75ed))\r\n- **readme:** Remove \"tail\" from example (is coreutils) ([#2158](https://github.com/ScoopInstaller/Scoop/issues/2158))\r\n\r\n## *Commits before 2018 are trimmed*\r\n"
  },
  {
    "path": "LICENSE",
    "content": "SPDX-License-Identifier: UNLICENSE or MIT\r\n\r\nINFORMATION ABOUT THIS PROJECT'S LICENSE (SHORT)\r\n============================================================================================\r\nThis project is licensed under the Unlicense or the MIT license,\r\nat your option.\r\n\r\nINFORMATION ABOUT THIS PROJECT'S LICENSE (LONG)\r\n============================================================================================\r\nThis project (\"Scoop\") is free software, licensed under the Unlicense or the\r\nMIT license, at your option. Scoop was previously licensed under only the Unlicense,\r\nbut was dual-licensed from version 0.2.0.\r\n\r\nScoop comes with ABSOLUTELY NO WARRANTY. Use it at your own risk. Scoop is provided\r\non an AS-IS BASIS and its contributors disclaim all warranties.\r\n\r\nYou may use, modify, distribute, sell, copy, compile, or merge Scoop by any means.\r\n\r\nCopies of both licenses can be found below.\r\n\r\nTHE LICENSE OF SCOOP\r\n============================================================================================\r\nUnlicense\r\n---------\r\nThis is free and unencumbered software released into the public domain.\r\n\r\nAnyone is free to copy, modify, publish, use, compile, sell, or\r\ndistribute this software, either in source code form or as a compiled\r\nbinary, for any purpose, commercial or non-commercial, and by any\r\nmeans.\r\n\r\nIn jurisdictions that recognize copyright laws, the author or authors\r\nof this software dedicate any and all copyright interest in the\r\nsoftware to the public domain. We make this dedication for the benefit\r\nof the public at large and to the detriment of our heirs and\r\nsuccessors. We intend this dedication to be an overt act of\r\nrelinquishment in perpetuity of all present and future rights to this\r\nsoftware under copyright law.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r\nIN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR\r\nOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\r\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r\nOTHER DEALINGS IN THE SOFTWARE.\r\n\r\nFor more information, please refer to <http://unlicense.org/>\r\n\r\nMIT license\r\n-----------\r\nThe MIT License (MIT)\r\n\r\nCopyright (c) 2013-2017 Luke Sampson (https://github.com/lukesampson)\r\nCopyright (c) 2013-present Scoop contributors (https://github.com/ScoopInstaller/Scoop/graphs/contributors)\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n"
  },
  {
    "path": "PSScriptAnalyzerSettings.psd1",
    "content": "@{\r\n    # Only diagnostic records of the specified severity will be generated.\r\n    # Uncomment the following line if you only want Errors and Warnings but\r\n    # not Information diagnostic records.\r\n    Severity = @('Error')\r\n\r\n    # Analyze **only** the following rules. Use IncludeRules when you want\r\n    # to invoke only a small subset of the defualt rules.\r\n    # IncludeRules = @('PSAvoidDefaultValueSwitchParameter',\r\n    #                  'PSMisleadingBacktick',\r\n    #                  'PSMissingModuleManifestField',\r\n    #                  'PSReservedCmdletChar',\r\n    #                  'PSReservedParams',\r\n    #                  'PSShouldProcess',\r\n    #                  'PSUseApprovedVerbs',\r\n    #                  'PSAvoidUsingCmdletAliases',\r\n    #                  'PSUseDeclaredVarsMoreThanAssignments')\r\n\r\n    # Do not analyze the following rules. Use ExcludeRules when you have\r\n    # commented out the IncludeRules settings above and want to include all\r\n    # the default rules except for those you exclude below.\r\n    # Note: if a rule is in both IncludeRules and ExcludeRules, the rule\r\n    # will be excluded.\r\n    ExcludeRules = @(\r\n        # Currently Scoop widely uses Write-Host to output colored text.\r\n        'PSAvoidUsingWriteHost'\r\n    )\r\n}\r\n"
  },
  {
    "path": "README.md",
    "content": "<h1 align=\"center\">Scoop</h1>\r\n\r\n<!--<img src=\"scoop.png\" alt=\"Long live Scoop!\"/>-->\r\n<p align=\"center\">\r\n        <a href=\"https://github.com/ScoopInstaller/Scoop#what-does-scoop-do\">Features</a>\r\n        |\r\n        <a href=\"https://github.com/ScoopInstaller/Scoop#installation\">Installation</a>\r\n        |\r\n        <a href=\"https://github.com/ScoopInstaller/Scoop/wiki\">Documentation</a>\r\n</p>\r\n\r\n---\r\n\r\n<p align=\"center\">\r\n    <a href=\"https://github.com/ScoopInstaller/Scoop\">\r\n        <img src=\"https://img.shields.io/github/languages/code-size/ScoopInstaller/Scoop.svg\" alt=\"Code Size\" />\r\n    </a>\r\n    <a href=\"https://github.com/ScoopInstaller/Scoop\">\r\n        <img src=\"https://img.shields.io/github/repo-size/ScoopInstaller/Scoop.svg\" alt=\"Repository size\" />\r\n    </a>\r\n    <a href=\"https://github.com/ScoopInstaller/Scoop/actions/workflows/ci.yml\">\r\n        <img src=\"https://github.com/ScoopInstaller/Scoop/actions/workflows/ci.yml/badge.svg\" alt=\"Scoop Core CI Tests\" />\r\n    </a>\r\n    <a href=\"https://discord.gg/s9yRQHt\">\r\n        <img src=\"https://img.shields.io/badge/chat-on%20discord-7289DA.svg\" alt=\"Discord Chat\" />\r\n    </a>\r\n    <a href=\"https://gitter.im/lukesampson/scoop\">\r\n        <img src=\"https://badges.gitter.im/lukesampson/scoop.png\" alt=\"Gitter Chat\" />\r\n    </a>\r\n    <a href=\"./LICENSE\">\r\n        <img src=\"https://img.shields.io/badge/license-UNLICENSE%20or%20MIT-blue\" alt=\"License\" />\r\n    </a>\r\n</p>\r\n\r\nScoop is a command-line installer for Windows.\r\n\r\n## What does Scoop do?\r\n\r\nScoop installs apps from the command line with a minimal amount of friction. It:\r\n\r\n- Eliminates [User Account Control](https://learn.microsoft.com/windows/security/application-security/application-control/user-account-control/) (UAC) prompt notifications.\r\n- Hides the graphical user interface (GUI) of wizard-style installers.\r\n- Prevents polluting the `PATH` environment variable. Normally, this variable gets cluttered as different apps are installed on the device.\r\n- Avoids unexpected side effects from installing and uninstalling apps.\r\n- Resolves and installs dependencies automatically.\r\n- Performs all the necessary steps to get an app to a working state.\r\n\r\nScoop is quite script-friendly. Your environment can become the way you like by using repeatable setups. For example:\r\n\r\n```console\r\nscoop install sudo\r\nsudo scoop install 7zip git openssh --global\r\nscoop install aria2 curl grep sed less touch\r\nscoop install python ruby go perl\r\n```\r\n\r\nIf you have built software that you would like others to use, Scoop is an alternative to building an installer (like MSI or InnoSetup). You just need to compress your app to a `.zip` file and provide a JSON manifest that describes how to install it.\r\n\r\n## Installation\r\n\r\nRun the following commands from a regular (non-admin) PowerShell terminal to install Scoop:\r\n\r\n```powershell\r\nSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser\r\nInvoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression\r\n```\r\n\r\n**Note**: The first command makes your device allow running the installation and management scripts. This is necessary because Windows 10 client devices restrict execution of any PowerShell scripts by default.\r\n\r\nIt will install Scoop to its default location:\r\n\r\n`C:\\Users\\<YOUR USERNAME>\\scoop`\r\n\r\nYou can find the complete documentation about the installer, including advanced installation configurations, in [ScoopInstaller/Install](https://github.com/ScoopInstaller/Install). Please create new issues there if you have questions about the installation.\r\n\r\n## Multi-connection downloads with `aria2`\r\n\r\nScoop can utilize [`aria2`](https://github.com/aria2/aria2) to use multi-connection downloads. Simply install `aria2` through Scoop and it will be used for all downloads afterward.\r\n\r\n```console\r\nscoop install aria2\r\n```\r\n\r\nBy default, `scoop` displays a warning when running `scoop install` or `scoop update` while `aria2` is enabled. This warning can be suppressed by running `scoop config aria2-warning-enabled false`.\r\n\r\nYou can tweak the following `aria2` settings with the `scoop config` command:\r\n\r\n- aria2-enabled (default: true)\r\n- aria2-warning-enabled (default: true)\r\n- [aria2-retry-wait](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-retry-wait) (default: 2)\r\n- [aria2-split](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-s) (default: 5)\r\n- [aria2-max-connection-per-server](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-x) (default: 5)\r\n- [aria2-min-split-size](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-k) (default: 5M)\r\n- [aria2-options](https://aria2.github.io/manual/en/html/aria2c.html#options) (default: )\r\n\r\n## Inspiration\r\n\r\n- [Homebrew](https://brew.sh/)\r\n- [Sub](https://signalvnoise.com/posts/3264-automating-with-convention-introducing-sub)\r\n\r\n## What sort of apps can Scoop install?\r\n\r\nThe apps that are most likely to get installed fine with Scoop are those referred to as \"portable\" apps. These apps are compressed files which can run standalone after being extracted. This type of apps does not produce side effects like changing the Windows Registry or placing files outside the app directory.\r\n\r\nScoop also supports installer files and their uninstallation methods. Likewise, it can handle single-file apps and PowerShell scripts. These do not even need to be compressed. See the [runat](https://github.com/ScoopInstaller/Main/blob/master/bucket/runat.json) package for an example: it is simply a GitHub gist.\r\n\r\n### Contribute to this project\r\n\r\nIf you would like to improve Scoop by adding features or fixing bugs, please read our [Contributing Guide](https://github.com/ScoopInstaller/.github/blob/main/.github/CONTRIBUTING.md).\r\n\r\n### Support this project\r\n\r\nIf you find Scoop useful and would like to support the ongoing development and maintenance of this project, you can donate here:\r\n\r\n- [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DM2SUH9EUXSKJ) (one-time donations)\r\n\r\n## Known application buckets\r\n\r\nThe following buckets are known to Scoop:\r\n\r\n- [main](https://github.com/ScoopInstaller/Main) - Default bucket which contains popular non-GUI apps.\r\n- [extras](https://github.com/ScoopInstaller/Extras) - Apps that do not fit the main bucket's [criteria](https://github.com/ScoopInstaller/Scoop/wiki/Criteria-for-including-apps-in-the-main-bucket).\r\n- [games](https://github.com/Calinou/scoop-games) - Open-source and freeware video games and game-related tools.\r\n- [nerd-fonts](https://github.com/matthewjberger/scoop-nerd-fonts) -  Nerd Fonts.\r\n- [nirsoft](https://github.com/ScoopInstaller/Nirsoft) - A collection of over 250+ apps from [Nirsoft](https://nirsoft.net).\r\n- [sysinternals](https://github.com/niheaven/scoop-sysinternals) - The Sysinternals suite from [Microsoft](https://learn.microsoft.com/sysinternals/).\r\n- [java](https://github.com/ScoopInstaller/Java) - A collection of Java development kits (JDKs) and Java runtime engines (JREs), Java's virtual machine debugging tools and Java based runtime engines.\r\n- [nonportable](https://github.com/ScoopInstaller/Nonportable) - Non-portable apps (may trigger UAC prompts).\r\n- [php](https://github.com/ScoopInstaller/PHP) - Installers for most versions of PHP.\r\n- [versions](https://github.com/ScoopInstaller/Versions) - Alternative versions of apps found in other buckets.\r\n\r\nThe `main` bucket is installed by default. You can make use of more buckets by typing:\r\n\r\n```console\r\nscoop bucket add <name>\r\n```\r\n\r\nFor example, to add the `extras` bucket, type:\r\n\r\n```console\r\nscoop bucket add extras\r\n```\r\n\r\nYou would be able to install apps from the `extras` bucket now.\r\n\r\n## Other application buckets\r\n\r\nMany other application buckets hosted on GitHub can be found on [ScoopSearch](https://scoop.sh/) or via [other search engines](https://rasa.github.io/scoop-directory/#other-search-engines).\r\n"
  },
  {
    "path": "appveyor.yml",
    "content": "version: \"{build}-{branch}\"\r\nbranches:\r\n  except:\r\n    - gh-pages\r\nbuild: false\r\ndeploy: false\r\nclone_depth: 2\r\nimage: Visual Studio 2022\r\nenvironment:\r\n  matrix:\r\n    - PowerShell: 5\r\n    - PowerShell: 7\r\nmatrix:\r\n  fast_finish: true\r\nfor:\r\n  - matrix:\r\n      only:\r\n        - PowerShell: 5\r\n    cache:\r\n      - '%USERPROFILE%\\Documents\\WindowsPowerShell\\Modules -> appveyor.yml, test\\bin\\*.ps1'\r\n      - C:\\projects\\helpers  -> appveyor.yml, test\\bin\\*.ps1\r\n    install:\r\n      - ps: .\\test\\bin\\init.ps1\r\n    test_script:\r\n      - ps: .\\test\\bin\\test.ps1\r\n  - matrix:\r\n      only:\r\n        - PowerShell: 7\r\n    cache:\r\n      - '%USERPROFILE%\\Documents\\PowerShell\\Modules -> appveyor.yml, test\\bin\\*.ps1'\r\n      - C:\\projects\\helpers  -> appveyor.yml, test\\bin\\*.ps1\r\n    install:\r\n      - pwsh: .\\test\\bin\\init.ps1\r\n    test_script:\r\n      - pwsh: .\\test\\bin\\test.ps1\r\n"
  },
  {
    "path": "bin/auto-pr.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    Updates manifests and pushes them or creates pull-requests.\r\n.DESCRIPTION\r\n    Updates manifests and pushes them directly to the origin branch or creates pull-requests for upstream.\r\n.PARAMETER Upstream\r\n    Upstream repository with the target branch.\r\n    Must be in format '<user>/<repo>:<branch>'\r\n.PARAMETER OriginBranch\r\n    Origin (local) branch name.\r\n.PARAMETER App\r\n    Manifest name to search.\r\n    Placeholders are supported.\r\n.PARAMETER CommitMessageFormat\r\n    The format of the commit message.\r\n    <app> will be replaced with the file name of manifest.\r\n    <version> will be replaced with the version of the latest manifest.\r\n.PARAMETER Dir\r\n    The directory where to search for manifests.\r\n.PARAMETER Push\r\n    Push updates directly to 'origin branch'.\r\n.PARAMETER Request\r\n    Create pull-requests on 'upstream branch' for each update.\r\n.PARAMETER Help\r\n    Print help to console.\r\n.PARAMETER SpecialSnowflakes\r\n    An array of manifests, which should be updated all the time. (-ForceUpdate parameter to checkver)\r\n.PARAMETER SkipUpdated\r\n    Updated manifests will not be shown.\r\n.PARAMETER ThrowError\r\n    Throw error as exception instead of just printing it.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\auto-pr.ps1 'someUsername/repository:branch' -Request\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\auto-pr.ps1 -Push\r\n    Update all manifests inside 'bucket/' directory.\r\n#>\r\n\r\nparam(\r\n    [Parameter(Mandatory = $true)]\r\n    [ValidateScript( {\r\n        if (!($_ -match '^(.*)\\/(.*):(.*)$')) {\r\n            throw 'Upstream must be in this format: <user>/<repo>:<branch>'\r\n        }\r\n        $true\r\n    })]\r\n    [String] $Upstream,\r\n    [String] $OriginBranch = 'master',\r\n    [String] $App = '*',\r\n    [String] $CommitMessageFormat = '<app>: Update to version <version>',\r\n    [ValidateScript( {\r\n        if (!(Test-Path $_ -Type Container)) {\r\n            throw \"$_ is not a directory!\"\r\n        } else {\r\n            $true\r\n        }\r\n    })]\r\n    [String] $Dir,\r\n    [Switch] $Push,\r\n    [Switch] $Request,\r\n    [Switch] $Help,\r\n    [string[]] $SpecialSnowflakes,\r\n    [Switch] $SkipUpdated,\r\n    [Switch] $ThrowError\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\"\r\n\r\nif ($App -ne '*' -and (Test-Path $App -PathType Leaf)) {\r\n    $Dir = Split-Path $App\r\n} elseif ($Dir) {\r\n    $Dir = Convert-Path $Dir\r\n} else {\r\n    throw \"'-Dir' parameter required if '-App' is not a filepath!\"\r\n}\r\n\r\nif ((!$Push -and !$Request) -or $Help) {\r\n    Write-Host @'\r\nUsage: auto-pr.ps1 [OPTION]\r\n\r\nMandatory options:\r\n  -p,  -push                       push updates directly to 'origin branch'\r\n  -r,  -request                    create pull-requests on 'upstream branch' for each update\r\n\r\nOptional options:\r\n  -u,  -upstream                   upstream repository with target branch\r\n  -o,  -originbranch               origin (local) branch name\r\n  -h,  -help\r\n'@\r\n    exit 0\r\n}\r\n\r\nif ($IsLinux -or $IsMacOS) {\r\n    if (!(which hub)) {\r\n        Write-Host \"Please install hub ('brew install hub' or visit: https://hub.github.com/)\" -ForegroundColor Yellow\r\n        exit 1\r\n    }\r\n} else {\r\n    if (!(scoop which hub)) {\r\n        Write-Host \"Please install hub 'scoop install hub'\" -ForegroundColor Yellow\r\n        exit 1\r\n    }\r\n}\r\n\r\nfunction execute($cmd) {\r\n    Write-Host $cmd -ForegroundColor Green\r\n    $output = Invoke-Command ([scriptblock]::Create($cmd))\r\n\r\n    if ($LASTEXITCODE -gt 0) {\r\n        abort \"^^^ Error! See above ^^^ (last command: $cmd)\"\r\n    }\r\n\r\n    return $output\r\n}\r\n\r\nfunction pull_requests($json, [String] $app, [String] $upstream, [String] $manifest, [String] $commitMessage) {\r\n    $version = $json.version\r\n    $homepage = $json.homepage\r\n    $branch = \"manifest/$app-$version\"\r\n\r\n    execute \"hub checkout $OriginBranch\"\r\n    Write-Host \"hub rev-parse --verify $branch\" -ForegroundColor Green\r\n    hub rev-parse --verify $branch\r\n\r\n    if ($LASTEXITCODE -eq 0) {\r\n        Write-Host \"Skipping update $app ($version) ...\" -ForegroundColor Yellow\r\n        return\r\n    }\r\n\r\n    Write-Host \"Creating update $app ($version) ...\" -ForegroundColor DarkCyan\r\n    execute \"hub checkout -b $branch\"\r\n    execute \"hub add $manifest\"\r\n    execute \"hub commit -m '$commitMessage\"\r\n    Write-Host \"Pushing update $app ($version) ...\" -ForegroundColor DarkCyan\r\n    execute \"hub push origin $branch\"\r\n\r\n    if ($LASTEXITCODE -gt 0) {\r\n        error \"Push failed! (hub push origin $branch)\"\r\n        execute 'hub reset'\r\n        return\r\n    }\r\n\r\n    Start-Sleep 1\r\n    Write-Host \"Pull-Request update $app ($version) ...\" -ForegroundColor DarkCyan\r\n    Write-Host \"hub pull-request -m '<msg>' -b '$upstream' -h '$branch'\" -ForegroundColor Green\r\n\r\n    $msg = @\"\r\n$commitMessage\r\n\r\nHello lovely humans,\r\na new version of [$app]($homepage) is available.\r\n\r\n| State       | Update :rocket: |\r\n| :---------- | :-------------- |\r\n| New version | $version        |\r\n\"@\r\n\r\n    hub pull-request -m \"$msg\" -b \"$upstream\" -h \"$branch\"\r\n    if ($LASTEXITCODE -gt 0) {\r\n        execute 'hub reset'\r\n        abort \"Pull Request failed! (hub pull-request -m '$commitMessage' -b '$upstream' -h '$branch')\"\r\n    }\r\n}\r\n\r\nWrite-Host 'Updating ...' -ForegroundColor DarkCyan\r\nif ($Push) {\r\n    execute \"hub pull origin $OriginBranch\"\r\n    execute \"hub checkout $OriginBranch\"\r\n} else {\r\n    execute \"hub pull upstream $OriginBranch\"\r\n    execute \"hub push origin $OriginBranch\"\r\n}\r\n\r\n. \"$PSScriptRoot\\checkver.ps1\" -App $App -Dir $Dir -Update -SkipUpdated:$SkipUpdated -ThrowError:$ThrowError\r\nif ($SpecialSnowflakes) {\r\n    Write-Host \"Forcing update on our special snowflakes: $($SpecialSnowflakes -join ',')\" -ForegroundColor DarkCyan\r\n    $SpecialSnowflakes -split ',' | ForEach-Object {\r\n        . \"$PSScriptRoot\\checkver.ps1\" $_ -Dir $Dir -ForceUpdate -ThrowError:$ThrowError\r\n    }\r\n}\r\n\r\nhub diff --name-only | ForEach-Object {\r\n    $manifest = $_\r\n    if (!$manifest.EndsWith('.json')) {\r\n        return\r\n    }\r\n\r\n    $app = ([System.IO.Path]::GetFileNameWithoutExtension($manifest))\r\n    $json = parse_json $manifest\r\n    if (!$json.version) {\r\n        error \"Invalid manifest: $manifest ...\"\r\n        return\r\n    }\r\n    $version = $json.version\r\n    $CommitMessage = $CommitMessageFormat -replace '<app>',$app -replace '<version>',$version\r\n    if ($Push) {\r\n        Write-Host \"Creating update $app ($version) ...\" -ForegroundColor DarkCyan\r\n        execute \"hub add $manifest\"\r\n\r\n        # detect if file was staged, because it's not when only LF or CRLF have changed\r\n        $status = execute 'hub status --porcelain -uno'\r\n        $status = $status | Where-Object { $_ -match \"M\\s{2}.*$app.json\" }\r\n        if ($status -and $status.StartsWith('M  ') -and $status.EndsWith(\"$app.json\")) {\r\n            execute \"hub commit -m '$commitMessage'\"\r\n        } else {\r\n            Write-Host \"Skipping $app because only LF/CRLF changes were detected ...\" -ForegroundColor Yellow\r\n        }\r\n    } else {\r\n        pull_requests $json $app $Upstream $manifest $CommitMessage\r\n    }\r\n}\r\n\r\nif ($Push) {\r\n    Write-Host 'Pushing updates ...' -ForegroundColor DarkCyan\r\n    execute \"hub push origin $OriginBranch\"\r\n} else {\r\n    Write-Host \"Returning to $OriginBranch branch and removing unstaged files ...\" -ForegroundColor DarkCyan\r\n    execute \"hub checkout -f $OriginBranch\"\r\n}\r\n\r\nexecute 'hub reset --hard'\r\n"
  },
  {
    "path": "bin/checkhashes.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    Check if ALL urls inside manifest have correct hashes.\r\n.PARAMETER App\r\n    Manifest to be checked.\r\n    Wildcard is supported.\r\n.PARAMETER Dir\r\n    Where to search for manifest(s).\r\n.PARAMETER Update\r\n    When there are mismatched hashes, manifest will be updated.\r\n.PARAMETER ForceUpdate\r\n    Manifest will be updated all the time. Not only when there are mismatched hashes.\r\n.PARAMETER SkipCorrect\r\n    Manifests without mismatch will not be shown.\r\n.PARAMETER UseCache\r\n    Downloaded files will not be deleted after script finish.\r\n    Should not be used, because check should be used for downloading actual version of file (as normal user, not finding in some document from vendors, which could be damaged / wrong (Example: Slack@3.3.1 ScoopInstaller/Extras#1192)), not some previously downloaded.\r\n.EXAMPLE\r\n    PS BUCKETROOT> .\\bin\\checkhashes.ps1\r\n    Check all manifests for hash mismatch.\r\n.EXAMPLE\r\n    PS BUCKETROOT> .\\bin\\checkhashes.ps1 MANIFEST -Update\r\n    Check MANIFEST and Update if there are some wrong hashes.\r\n#>\r\nparam(\r\n    [String] $App = '*',\r\n    [Parameter(Mandatory = $true)]\r\n    [ValidateScript( {\r\n        if (!(Test-Path $_ -Type Container)) {\r\n            throw \"$_ is not a directory!\"\r\n        } else {\r\n            $true\r\n        }\r\n    })]\r\n    [String] $Dir,\r\n    [Switch] $Update,\r\n    [Switch] $ForceUpdate,\r\n    [Switch] $SkipCorrect,\r\n    [Alias('k')]\r\n    [Switch] $UseCache\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\buckets.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\autoupdate.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\n\r\n$Dir = Convert-Path $Dir\r\nif ($ForceUpdate) { $Update = $true }\r\n# Cleanup\r\nif (!$UseCache) { Remove-Item \"$cachedir\\*HASH_CHECK*\" -Force }\r\n\r\nfunction err ([String] $name, [String[]] $message) {\r\n    Write-Host \"$name`: \" -ForegroundColor Red -NoNewline\r\n    Write-Host ($message -join \"`r`n\") -ForegroundColor Red\r\n}\r\n\r\n$MANIFESTS = @()\r\nforeach ($single in Get-ChildItem $Dir -Filter \"$App.json\" -Recurse) {\r\n    $name = $single.BaseName\r\n    $file = $single.FullName\r\n    $manifest = parse_json $file\r\n\r\n    # Skip nighly manifests, since their hash validation is skipped\r\n    if ($manifest.version -eq 'nightly') { continue }\r\n\r\n    $urls = @()\r\n    $hashes = @()\r\n\r\n    if ($manifest.url) {\r\n        $manifest.url | ForEach-Object { $urls += $_ }\r\n        $manifest.hash | ForEach-Object { $hashes += $_ }\r\n    } elseif ($manifest.architecture) {\r\n        # First handle 64bit\r\n        script:url $manifest '64bit' | ForEach-Object { $urls += $_ }\r\n        hash $manifest '64bit' | ForEach-Object { $hashes += $_ }\r\n        script:url $manifest '32bit' | ForEach-Object { $urls += $_ }\r\n        hash $manifest '32bit' | ForEach-Object { $hashes += $_ }\r\n        script:url $manifest 'arm64' | ForEach-Object { $urls += $_ }\r\n        hash $manifest 'arm64' | ForEach-Object { $hashes += $_ }\r\n    } else {\r\n        err $name 'Manifest does not contain URL property.'\r\n        continue\r\n    }\r\n\r\n    # Number of URLS and Hashes is different\r\n    if ($urls.Length -ne $hashes.Length) {\r\n        err $name 'URLS and hashes count mismatch.'\r\n        continue\r\n    }\r\n\r\n    $MANIFESTS += @{\r\n        app      = $name\r\n        file     = $file\r\n        manifest = $manifest\r\n        urls     = $urls\r\n        hashes   = $hashes\r\n    }\r\n}\r\n\r\n# clear any existing events\r\nGet-Event | ForEach-Object { Remove-Event $_.SourceIdentifier }\r\n\r\nforeach ($current in $MANIFESTS) {\r\n    $count = 0\r\n    # Array of indexes mismatched hashes.\r\n    $mismatched = @()\r\n    # Array of computed hashes\r\n    $actuals = @()\r\n\r\n    $current.urls | ForEach-Object {\r\n        $algorithm, $expected = get_hash $current.hashes[$count]\r\n        if ($UseCache) {\r\n            $version = $current.manifest.version\r\n        } else {\r\n            $version = 'HASH_CHECK'\r\n        }\r\n\r\n        Invoke-CachedDownload $current.app $version $_ $null $null -use_cache:$UseCache\r\n\r\n        $to_check = cache_path $current.app $version $_\r\n        $actual_hash = (Get-FileHash -Path $to_check -Algorithm $algorithm).Hash.ToLower()\r\n\r\n        # Append type of algorithm to both expected and actual if it's not sha256\r\n        if ($algorithm -ne 'sha256') {\r\n            $actual_hash = \"$algorithm`:$actual_hash\"\r\n            $expected = \"$algorithm`:$expected\"\r\n        }\r\n\r\n        $actuals += $actual_hash\r\n        if ($actual_hash -ne $expected) {\r\n            $mismatched += $count\r\n        }\r\n        $count++\r\n    }\r\n\r\n    if ($mismatched.Length -eq 0 ) {\r\n        if (!$SkipCorrect) {\r\n            Write-Host \"$($current.app): \" -NoNewline\r\n            Write-Host 'OK' -ForegroundColor Green\r\n        }\r\n    } else {\r\n        Write-Host \"$($current.app): \" -NoNewline\r\n        Write-Host 'Mismatch found ' -ForegroundColor Red\r\n        $mismatched | ForEach-Object {\r\n            $file = cache_path $current.app $version $current.urls[$_]\r\n            Write-Host \"`tURL:`t`t$($current.urls[$_])\"\r\n            if (Test-Path $file) {\r\n                Write-Host \"`tFirst bytes:`t$((get_magic_bytes_pretty $file ' ').ToUpper())\"\r\n            }\r\n            Write-Host \"`tExpected:`t$($current.hashes[$_])\" -ForegroundColor Green\r\n            Write-Host \"`tActual:`t`t$($actuals[$_])\" -ForegroundColor Red\r\n        }\r\n    }\r\n\r\n    if ($Update) {\r\n        if ($current.manifest.url -and $current.manifest.hash) {\r\n            $current.manifest.hash = $actuals\r\n        } else {\r\n            $platforms = ($current.manifest.architecture | Get-Member -MemberType NoteProperty).Name\r\n            # Defaults to zero, don't know, which architecture is available\r\n            $64bit_count = 0\r\n            $32bit_count = 0\r\n            $arm64_count = 0\r\n\r\n            # 64bit is get, donwloaded and added first\r\n            if ($platforms.Contains('64bit')) {\r\n                $64bit_count = $current.manifest.architecture.'64bit'.hash.Count\r\n                $current.manifest.architecture.'64bit'.hash = $actuals[0..($64bit_count - 1)]\r\n            }\r\n            if ($platforms.Contains('32bit')) {\r\n                $32bit_count = $current.manifest.architecture.'32bit'.hash.Count\r\n                $current.manifest.architecture.'32bit'.hash = $actuals[($64bit_count)..($64bit_count + $32bit_count - 1)]\r\n            }\r\n            if ($platforms.Contains('arm64')) {\r\n                $arm64_count = $current.manifest.architecture.'arm64'.hash.Count\r\n                $current.manifest.architecture.'arm64'.hash = $actuals[($64bit_count + $32bit_count)..($64bit_count + $32bit_count + $arm64_count - 1)]\r\n            }\r\n        }\r\n\r\n        Write-Host \"Writing updated $($current.app) manifest\" -ForegroundColor DarkGreen\r\n\r\n        $current.manifest = $current.manifest | ConvertToPrettyJson\r\n        $path = Convert-Path $current.file\r\n        [System.IO.File]::WriteAllLines($path, $current.manifest)\r\n    }\r\n}\r\n"
  },
  {
    "path": "bin/checkurls.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    List manifests which do not have valid URLs.\r\n.PARAMETER App\r\n    Manifest name to search.\r\n    Placeholder is supported.\r\n.PARAMETER Dir\r\n    Where to search for manifest(s).\r\n.PARAMETER Timeout\r\n    How long (seconds) the request can be pending before it times out.\r\n.PARAMETER SkipValid\r\n    Manifests will all valid URLs will not be shown.\r\n#>\r\nparam(\r\n    [String] $App = '*',\r\n    [Parameter(Mandatory = $true)]\r\n    [ValidateScript( {\r\n        if (!(Test-Path $_ -Type Container)) {\r\n            throw \"$_ is not a directory!\"\r\n        } else {\r\n            $true\r\n        }\r\n    })]\r\n    [String] $Dir,\r\n    [Int] $Timeout = 5,\r\n    [Switch] $SkipValid\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\n\r\n$Dir = Convert-Path $Dir\r\n$Queue = @()\r\n\r\nGet-ChildItem $Dir -Filter \"$App.json\" -Recurse | ForEach-Object {\r\n    $manifest = parse_json $_.FullName\r\n    $Queue += , @($_.BaseName, $manifest)\r\n}\r\n\r\nWrite-Host '[' -NoNewLine\r\nWrite-Host 'U' -NoNewLine -ForegroundColor Cyan\r\nWrite-Host ']RLs'\r\nWrite-Host ' | [' -NoNewLine\r\nWrite-Host 'O' -NoNewLine -ForegroundColor Green\r\nWrite-Host ']kay'\r\nWrite-Host ' |  | [' -NoNewLine\r\nWrite-Host 'F' -NoNewLine -ForegroundColor Red\r\nWrite-Host ']ailed'\r\nWrite-Host ' |  |  |'\r\n\r\nfunction test_dl([String] $url, $cookies) {\r\n    # Trim renaming suffix, prevent getting 40x response\r\n    $url = ($url -split '#/')[0]\r\n\r\n    $wreq = [Net.WebRequest]::Create($url)\r\n    $wreq.Timeout = $Timeout * 1000\r\n    if ($wreq -is [Net.HttpWebRequest]) {\r\n        $wreq.UserAgent = Get-UserAgent\r\n        $wreq.Referer = strip_filename $url\r\n        if ($cookies) {\r\n            $wreq.Headers.Add('Cookie', (cookie_header $cookies))\r\n        }\r\n    }\r\n\r\n    get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object {\r\n        (ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object {\r\n            $wreq.Headers[$_.Key] = $_.Value\r\n        }\r\n    }\r\n\r\n    $wres = $null\r\n    try {\r\n        $wres = $wreq.GetResponse()\r\n\r\n        return $url, $wres.StatusCode, $null\r\n    } catch {\r\n        $e = $_.Exception\r\n        if ($e.InnerException) { $e = $e.InnerException }\r\n\r\n        return $url, 'Error', $e.Message\r\n    } finally {\r\n        if ($null -ne $wres -and $wres -isnot [Net.FtpWebResponse]) {\r\n            $wres.Close()\r\n        }\r\n    }\r\n}\r\n\r\nforeach ($man in $Queue) {\r\n    $name, $manifest = $man\r\n    $urls = @()\r\n    $ok = 0\r\n    $failed = 0\r\n    $errors = @()\r\n\r\n    if ($manifest.url) {\r\n        $manifest.url | ForEach-Object { $urls += $_ }\r\n    } else {\r\n        script:url $manifest '64bit' | ForEach-Object { $urls += $_ }\r\n        script:url $manifest '32bit' | ForEach-Object { $urls += $_ }\r\n        script:url $manifest 'arm64' | ForEach-Object { $urls += $_ }\r\n    }\r\n\r\n    $urls | ForEach-Object {\r\n        $url, $status, $msg = test_dl $_ $manifest.cookie\r\n        if ($msg) { $errors += \"$msg ($url)\" }\r\n        if ($status -eq 'OK' -or $status -eq 'OpeningData') { $ok += 1 } else { $failed += 1 }\r\n    }\r\n\r\n    if (($ok -eq $urls.Length) -and $SkipValid) { continue }\r\n\r\n    # URLS\r\n    Write-Host '[' -NoNewLine\r\n    Write-Host $urls.Length -NoNewLine -ForegroundColor Cyan\r\n    Write-Host ']' -NoNewLine\r\n\r\n    # Okay\r\n    Write-Host '[' -NoNewLine\r\n    if ($ok -eq $urls.Length) {\r\n        Write-Host $ok -NoNewLine -ForegroundColor Green\r\n    } elseif ($ok -eq 0) {\r\n        Write-Host $ok -NoNewLine -ForegroundColor Red\r\n    } else {\r\n        Write-Host $ok -NoNewLine -ForegroundColor Yellow\r\n    }\r\n    Write-Host ']' -NoNewLine\r\n\r\n    # Failed\r\n    Write-Host '[' -NoNewLine\r\n    if ($failed -eq 0) {\r\n        Write-Host $failed -NoNewLine -ForegroundColor Green\r\n    } else {\r\n        Write-Host $failed -NoNewLine -ForegroundColor Red\r\n    }\r\n    Write-Host '] ' -NoNewLine\r\n    Write-Host $name\r\n\r\n    $errors | ForEach-Object {\r\n        Write-Host \"       > $_\" -ForegroundColor DarkRed\r\n    }\r\n}\r\n"
  },
  {
    "path": "bin/checkver.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    Check manifest for a newer version.\r\n.DESCRIPTION\r\n    Checks websites for newer versions using an (optional) regular expression defined in the manifest.\r\n.PARAMETER App\r\n    Manifest name to search.\r\n    Placeholders are supported.\r\n.PARAMETER Dir\r\n    Where to search for manifest(s).\r\n.PARAMETER Update\r\n    Update given manifest\r\n.PARAMETER ForceUpdate\r\n    Update given manifest(s) even when there is no new version.\r\n    Useful for hash updates.\r\n.PARAMETER SkipUpdated\r\n    Updated manifests will not be shown.\r\n.PARAMETER Version\r\n    Update manifest to specific version.\r\n.PARAMETER ThrowError\r\n    Throw error as exception instead of just printing it.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1\r\n    Check all manifest inside default directory.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 -SkipUpdated\r\n    Check all manifest inside default directory (list only outdated manifests).\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 -Update\r\n    Check all manifests and update All outdated manifests.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 APP\r\n    Check manifest APP.json inside default directory.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 APP -Update\r\n    Check manifest APP.json and update, if there is newer version.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 APP -ForceUpdate\r\n    Check manifest APP.json and update, even if there is no new version.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 APP -Update -Version VER\r\n    Check manifest APP.json and update, using version VER\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 APP DIR\r\n    Check manifest APP.json inside ./DIR directory.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 -Dir DIR\r\n    Check all manifests inside ./DIR directory.\r\n.EXAMPLE\r\n    PS BUCKETROOT > .\\bin\\checkver.ps1 APP DIR -Update\r\n    Check manifest APP.json inside ./DIR directory and update if there is newer version.\r\n#>\r\nparam(\r\n    [String] $App = '*',\r\n    [ValidateScript( {\r\n        if (!(Test-Path $_ -Type Container)) {\r\n            throw \"$_ is not a directory!\"\r\n        } else {\r\n            $true\r\n        }\r\n    })]\r\n    [String] $Dir,\r\n    [Switch] $Update,\r\n    [Switch] $ForceUpdate,\r\n    [Switch] $SkipUpdated,\r\n    [String] $Version = '',\r\n    [Switch] $ThrowError\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\autoupdate.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\buckets.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\n\r\nif ($App -ne '*' -and (Test-Path $App -PathType Leaf)) {\r\n    $Dir = Split-Path $App\r\n    $files = Get-ChildItem $Dir -Filter (Split-Path $App -Leaf)\r\n} elseif ($Dir) {\r\n    $Dir = Convert-Path $Dir\r\n    $files = Get-ChildItem $Dir -Filter \"$App.json\" -Recurse\r\n} else {\r\n    throw \"'-Dir' parameter required if '-App' is not a filepath!\"\r\n}\r\n\r\n$GitHubToken = Get-GitHubToken\r\n\r\n# don't use $Version with $App = '*'\r\nif ($App -eq '*' -and $Version -ne '') {\r\n    throw \"Don't use '-Version' with '-App *'!\"\r\n}\r\n\r\n# get apps to check\r\n$Queue = @()\r\n$json = ''\r\n$files | ForEach-Object {\r\n    $file = $_.FullName\r\n    $json = parse_json $file\r\n    if ($json.checkver) {\r\n        $Queue += , @($_.BaseName, $json, $file)\r\n    }\r\n}\r\n\r\n# clear any existing events\r\nGet-Event | Remove-Event\r\nGet-EventSubscriber | Unregister-Event\r\n\r\n# start all downloads\r\n$Queue | ForEach-Object {\r\n    $name, $json, $file = $_\r\n\r\n    $substitutions = Get-VersionSubstitution $json.version # 'autoupdate.ps1'\r\n\r\n    $wc = New-Object Net.Webclient\r\n    if ($json.checkver.useragent) {\r\n        $wc.Headers.Add('User-Agent', (substitute $json.checkver.useragent $substitutions))\r\n    } else {\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n    }\r\n    Register-ObjectEvent $wc downloadDataCompleted -ErrorAction Stop | Out-Null\r\n\r\n    # Not Specified\r\n    if ($json.checkver.url) {\r\n        $url = $json.checkver.url\r\n    } else {\r\n        $url = $json.homepage\r\n    }\r\n\r\n    if ($json.checkver.re) {\r\n        $regex = $json.checkver.re\r\n    } elseif ($json.checkver.regex) {\r\n        $regex = $json.checkver.regex\r\n    } else {\r\n        $regex = ''\r\n    }\r\n\r\n    $jsonpath = ''\r\n    $xpath = ''\r\n    $replace = ''\r\n    $useGithubAPI = $false\r\n\r\n    # GitHub\r\n    if ($regex) {\r\n        $githubRegex = $regex\r\n    } else {\r\n        $githubRegex = '/releases/tag/(?:v|V)?([\\d.]+)'\r\n    }\r\n    if ($json.checkver -eq 'github') {\r\n        if (!$json.homepage.StartsWith('https://github.com/')) {\r\n            error \"$name checkver expects the homepage to be a github repository\"\r\n        }\r\n        $url = $json.homepage.TrimEnd('/') + '/releases/latest'\r\n        $regex = $githubRegex\r\n        $useGithubAPI = $true\r\n    }\r\n\r\n    if ($json.checkver.github) {\r\n        $url = $json.checkver.github.TrimEnd('/') + '/releases/latest'\r\n        $regex = $githubRegex\r\n        if ($json.checkver.PSObject.Properties.Count -eq 1) { $useGithubAPI = $true }\r\n    }\r\n\r\n    # SourceForge\r\n    if ($regex) {\r\n        $sourceforgeRegex = $regex\r\n    } else {\r\n        $sourceforgeRegex = '(?!\\.)([\\d.]+)(?<=\\d)'\r\n    }\r\n    if ($json.checkver -eq 'sourceforge') {\r\n        if ($json.homepage -match '//(sourceforge|sf)\\.net/projects/(?<project>[^/]+)(/files/(?<path>[^/]+))?|//(?<project>[^.]+)\\.(sourceforge\\.(net|io)|sf\\.net)') {\r\n            $project = $Matches['project']\r\n            $path = $Matches['path']\r\n        } else {\r\n            $project = strip_ext $name\r\n        }\r\n        $url = \"https://sourceforge.net/projects/$project/rss\"\r\n        if ($path) {\r\n            $url = $url + '?path=/' + $path.TrimStart('/')\r\n        }\r\n        $regex = \"CDATA\\[/$path/.*?$sourceforgeRegex.*?\\]\".Replace('//', '/')\r\n    }\r\n    if ($json.checkver.sourceforge) {\r\n        if ($json.checkver.sourceforge -is [System.String] -and $json.checkver.sourceforge -match '(?<project>[\\w-]*)(/(?<path>.*))?') {\r\n            $project = $Matches['project']\r\n            $path = $Matches['path']\r\n        } else {\r\n            $project = $json.checkver.sourceforge.project\r\n            $path = $json.checkver.sourceforge.path\r\n        }\r\n        $url = \"https://sourceforge.net/projects/$project/rss\"\r\n        if ($path) {\r\n            $url = $url + '?path=/' + $path.TrimStart('/')\r\n        }\r\n        $regex = \"CDATA\\[/$path/.*?$sourceforgeRegex.*?\\]\".Replace('//', '/')\r\n    }\r\n\r\n    if ($json.checkver.jp) {\r\n        $jsonpath = $json.checkver.jp\r\n    }\r\n    if ($json.checkver.jsonpath) {\r\n        $jsonpath = $json.checkver.jsonpath\r\n    }\r\n    if ($json.checkver.xpath) {\r\n        $xpath = $json.checkver.xpath\r\n    }\r\n\r\n    if ($json.checkver.replace -is [System.String]) { # If `checkver` is [System.String], it has a method called `Replace`\r\n        $replace = $json.checkver.replace\r\n    }\r\n\r\n    if (!$jsonpath -and !$regex -and !$xpath) {\r\n        $regex = $json.checkver\r\n    }\r\n\r\n    $reverse = $json.checkver.reverse -and $json.checkver.reverse -eq 'true'\r\n\r\n    if ($url -like '*api.github.com/*') { $useGithubAPI = $true }\r\n\r\n    if ($useGithubAPI -and ($null -ne $GitHubToken)) {\r\n        $url = $url -replace '//(www\\.)?github.com/', '//api.github.com/repos/'\r\n        $wc.Headers.Add('Authorization', \"token $GitHubToken\")\r\n    }\r\n\r\n    $url = substitute $url $substitutions\r\n\r\n    $state = New-Object psobject @{\r\n        app      = $name\r\n        file     = $file\r\n        url      = $url\r\n        regex    = $regex\r\n        json     = $json\r\n        jsonpath = $jsonpath\r\n        xpath    = $xpath\r\n        reverse  = $reverse\r\n        replace  = $replace\r\n    }\r\n\r\n    get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object {\r\n        (ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object {\r\n            $wc.Headers[$_.Key] = $_.Value\r\n        }\r\n    }\r\n\r\n    $wc.Headers.Add('Referer', (strip_filename $url))\r\n    $wc.DownloadDataAsync($url, $state)\r\n}\r\n\r\nfunction next($er) {\r\n    Write-Host \"$App`: \" -NoNewline\r\n    Write-Host $er -ForegroundColor DarkRed\r\n}\r\n\r\n# wait for all to complete\r\n$in_progress = $Queue.length\r\nwhile ($in_progress -gt 0) {\r\n    $ev = Wait-Event\r\n    Remove-Event $ev.SourceIdentifier\r\n    $in_progress--\r\n\r\n    $state = $ev.SourceEventArgs.UserState\r\n    $result = $ev.SourceEventArgs.Result\r\n    $app = $state.app\r\n    $file = $state.file\r\n    $json = $state.json\r\n    $url = $state.url\r\n    $regexp = $state.regex\r\n    $jsonpath = $state.jsonpath\r\n    $xpath = $state.xpath\r\n    $script = $json.checkver.script\r\n    $reverse = $state.reverse\r\n    $replace = $state.replace\r\n    $expected_ver = $json.version\r\n    $ver = $Version\r\n\r\n    if (!$ver) {\r\n        if (!$regexp -and $replace) {\r\n            next \"'replace' requires 're' or 'regex'\"\r\n            continue\r\n        }\r\n        $err = $ev.SourceEventArgs.Error\r\n        if ($err) {\r\n            next \"$($err.message)`r`nURL $url is not valid\"\r\n            continue\r\n        }\r\n\r\n        if ($url) {\r\n            $ms = New-Object System.IO.MemoryStream\r\n            $ms.Write($result, 0, $result.Length)\r\n            $ms.Seek(0, 0) | Out-Null\r\n            if ($result[0] -eq 0x1F -and $result[1] -eq 0x8B) {\r\n                $ms = New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Decompress)\r\n            }\r\n            $page = (New-Object System.IO.StreamReader($ms, (Get-Encoding $wc))).ReadToEnd()\r\n        }\r\n        $source = $url\r\n        if ($script) {\r\n            $page = Invoke-Command ([scriptblock]::Create($script -join \"`r`n\"))\r\n            $source = 'the output of script'\r\n        }\r\n\r\n        if ($jsonpath) {\r\n            # Return only a single value if regex is absent\r\n            $noregex = [String]::IsNullOrEmpty($regexp)\r\n            # If reverse is ON and regex is ON,\r\n            # Then reverse would have no effect because regex handles reverse\r\n            # on its own\r\n            # So in this case we have to disable reverse\r\n            $ver = json_path $page $jsonpath $null ($reverse -and $noregex) $noregex\r\n            if (!$ver) {\r\n                $ver = json_path_legacy $page $jsonpath\r\n            }\r\n            if (!$ver) {\r\n                next \"couldn't find '$jsonpath' in $source\"\r\n                continue\r\n            }\r\n        }\r\n\r\n        if ($xpath) {\r\n            $xml = [xml]$page\r\n            # Find all `significant namespace declarations` from the XML file\r\n            $nsList = $xml.SelectNodes(\"//namespace::*[not(. = ../../namespace::*)]\")\r\n            # Then add them into the NamespaceManager\r\n            $nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)\r\n            $nsList | ForEach-Object {\r\n                if ($_.LocalName -eq 'xmlns') {\r\n                    $nsmgr.AddNamespace('ns', $_.Value)\r\n                    $xpath = $xpath -replace '/([^:/]+)((?=/)|(?=$))', '/ns:$1'\r\n                } else {\r\n                    $nsmgr.AddNamespace($_.LocalName, $_.Value)\r\n                }\r\n            }\r\n            # Getting version from XML, using XPath\r\n            $ver = $xml.SelectSingleNode($xpath, $nsmgr).'#text'\r\n            if (!$ver) {\r\n                next \"couldn't find '$($xpath -replace 'ns:', '')' in $source\"\r\n                continue\r\n            }\r\n        }\r\n\r\n        if ($jsonpath -and $regexp) {\r\n            $page = $ver\r\n            $ver = ''\r\n        }\r\n\r\n        if ($xpath -and $regexp) {\r\n            $page = $ver\r\n            $ver = ''\r\n        }\r\n\r\n        if ($regexp) {\r\n            $re = New-Object System.Text.RegularExpressions.Regex($regexp)\r\n            if ($reverse) {\r\n                $match = $re.Matches($page) | Select-Object -Last 1\r\n            } else {\r\n                $match = $re.Matches($page) | Select-Object -First 1\r\n            }\r\n\r\n            if ($match -and $match.Success) {\r\n                $matchesHashtable = @{}\r\n                $re.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) }\r\n                $ver = $matchesHashtable['1']\r\n                if ($replace) {\r\n                    $ver = $re.Replace($match.Value, $replace)\r\n                }\r\n                if (!$ver) {\r\n                    $ver = $matchesHashtable['version']\r\n                }\r\n            } else {\r\n                next \"couldn't match '$regexp' in $source\"\r\n                continue\r\n            }\r\n        }\r\n\r\n        if (!$ver) {\r\n            next \"couldn't find new version in $source\"\r\n            continue\r\n        }\r\n    }\r\n\r\n    # Skip actual only if versions are same and there is no -f\r\n    if (($ver -eq $expected_ver) -and !$ForceUpdate -and $SkipUpdated) { continue }\r\n\r\n    Write-Host \"$app`: \" -NoNewline\r\n\r\n    # version hasn't changed (step over if forced update)\r\n    if ($ver -eq $expected_ver -and !$ForceUpdate) {\r\n        Write-Host $ver -ForegroundColor DarkGreen\r\n        continue\r\n    }\r\n\r\n    Write-Host $ver -ForegroundColor DarkRed -NoNewline\r\n    Write-Host \" (scoop version is $expected_ver)\" -NoNewline\r\n    $update_available = (Compare-Version -ReferenceVersion $ver -DifferenceVersion $expected_ver) -ne 0\r\n\r\n    if ($json.autoupdate -and $update_available) {\r\n        Write-Host ' autoupdate available' -ForegroundColor Cyan\r\n    } else {\r\n        Write-Host ''\r\n    }\r\n\r\n    # forcing an update implies updating, right?\r\n    if ($ForceUpdate) { $Update = $true }\r\n\r\n    if ($Update -and $json.autoupdate) {\r\n        if ($ForceUpdate) {\r\n            Write-Host 'Forcing autoupdate!' -ForegroundColor DarkMagenta\r\n        }\r\n        try {\r\n            Invoke-AutoUpdate $app $file $json $ver $matchesHashtable # 'autoupdate.ps1'\r\n        } catch {\r\n            if ($ThrowError) {\r\n                throw $_\r\n            } else {\r\n                error $_.Exception.Message\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "bin/describe.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    Search for application description on homepage.\r\n.PARAMETER App\r\n    Manifest name to search.\r\n    Placeholders are supported.\r\n.PARAMETER Dir\r\n    Where to search for manifest(s).\r\n#>\r\nparam(\r\n    [String] $App = '*',\r\n    [Parameter(Mandatory = $true)]\r\n    [ValidateScript( {\r\n        if (!(Test-Path $_ -Type Container)) {\r\n            throw \"$_ is not a directory!\"\r\n        } else {\r\n            $true\r\n        }\r\n    })]\r\n    [String] $Dir\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\description.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\n\r\n$Dir = Convert-Path $Dir\r\n$Queue = @()\r\n\r\nGet-ChildItem $Dir -Filter \"$App.json\" -Recurse | ForEach-Object {\r\n    $manifest = parse_json $_.FullName\r\n    $Queue += , @($_.BaseName, $manifest)\r\n}\r\n\r\n$Queue | ForEach-Object {\r\n    $name, $manifest = $_\r\n    Write-Host \"$name`: \" -NoNewline\r\n\r\n    if (!$manifest.homepage) {\r\n        Write-Host \"`nNo homepage set.\" -ForegroundColor Red\r\n        return\r\n    }\r\n    # get description from homepage\r\n    try {\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $homepage = $wc.DownloadData($manifest.homepage)\r\n        $home_html = (Get-Encoding($wc)).GetString($homepage)\r\n    } catch {\r\n        Write-Host \"`n$($_.Exception.Message)\" -ForegroundColor Red\r\n        return\r\n    }\r\n\r\n    $description, $descr_method = find_description $manifest.homepage $home_html\r\n    if (!$description) {\r\n        Write-Host \"`nDescription not found ($($manifest.homepage))\" -ForegroundColor Red\r\n        return\r\n    }\r\n\r\n    $description = clean_description $description\r\n\r\n    Write-Host \"(found by $descr_method)\"\r\n    Write-Host \"  \"\"$description\"\"\" -ForegroundColor Green\r\n}\r\n"
  },
  {
    "path": "bin/formatjson.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    Format manifest.\r\n.PARAMETER App\r\n    Manifest to format.\r\n\r\n    Wildcards are supported.\r\n.PARAMETER Dir\r\n    Where to search for manifest(s).\r\n.EXAMPLE\r\n    PS BUCKETROOT> .\\bin\\formatjson.ps1\r\n    Format all manifests inside bucket directory.\r\n.EXAMPLE\r\n    PS BUCKETROOT> .\\bin\\formatjson.ps1 7zip\r\n    Format manifest '7zip' inside bucket directory.\r\n#>\r\nparam(\r\n    [String] $App = '*',\r\n    [Parameter(Mandatory = $true)]\r\n    [ValidateScript( {\r\n        if (!(Test-Path $_ -Type Container)) {\r\n            throw \"$_ is not a directory!\"\r\n        } else {\r\n            $true\r\n        }\r\n    })]\r\n    [String] $Dir\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\"\r\n\r\n$Dir = Convert-Path $Dir\r\n\r\nGet-ChildItem $Dir -Filter \"$App.json\" -Recurse | ForEach-Object {\r\n    $file = $_.FullName\r\n    # beautify\r\n    $json = parse_json $file | ConvertToPrettyJson\r\n\r\n    # convert to 4 spaces\r\n    $json = $json -replace \"`t\", '    '\r\n    [System.IO.File]::WriteAllLines($file, $json)\r\n}\r\n"
  },
  {
    "path": "bin/install.ps1",
    "content": "#Requires -Version 5\r\nInvoke-RestMethod https://get.scoop.sh | Invoke-Expression\r\n"
  },
  {
    "path": "bin/missing-checkver.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    Check if manifest contains checkver and autoupdate property.\r\n.PARAMETER App\r\n    Manifest name.\r\n    Wirldcard is supported.\r\n.PARAMETER Dir\r\n    Location of manifests.\r\n.PARAMETER SkipSupported\r\n    Manifests with checkver and autoupdate will not be presented.\r\n#>\r\nparam(\r\n    [String] $App = '*',\r\n    [Parameter(Mandatory = $true)]\r\n    [ValidateScript( {\r\n        if (!(Test-Path $_ -Type Container)) {\r\n            throw \"$_ is not a directory!\"\r\n        } else {\r\n            $true\r\n        }\r\n    })]\r\n    [String] $Dir,\r\n    [Switch] $SkipSupported\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n\r\n$Dir = Convert-Path $Dir\r\n\r\nWrite-Host '[' -NoNewLine\r\nWrite-Host 'C' -NoNewLine -ForegroundColor Green\r\nWrite-Host ']heckver'\r\nWrite-Host ' | [' -NoNewLine\r\nWrite-Host 'A' -NoNewLine -ForegroundColor Cyan\r\nWrite-Host ']utoupdate'\r\nWrite-Host ' |  |'\r\n\r\nGet-ChildItem $Dir -Filter \"$App.json\" -Recurse | ForEach-Object {\r\n    $json = parse_json $_.FullName\r\n\r\n    if ($SkipSupported -and $json.checkver -and $json.autoupdate) { return }\r\n\r\n    Write-Host '[' -NoNewLine\r\n    Write-Host $(if ($json.checkver) { 'C' } else { ' ' }) -NoNewLine -ForegroundColor Green\r\n    Write-Host ']' -NoNewLine\r\n\r\n    Write-Host '[' -NoNewLine\r\n    Write-Host $(if ($json.autoupdate) { 'A' } else { ' ' }) -NoNewLine -ForegroundColor Cyan\r\n    Write-Host '] ' -NoNewLine\r\n    Write-Host $_.BaseName\r\n}\r\n"
  },
  {
    "path": "bin/refresh.ps1",
    "content": "# for development, update the installed scripts to match local source\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n\r\n$src = \"$PSScriptRoot\\..\"\r\n$dest = ensure (versiondir 'scoop' 'current')\r\n\r\n# make sure not running from the installed directory\r\nif(\"$src\" -eq \"$dest\") { abort \"$(strip_ext $myinvocation.mycommand.name) is for development only\" }\r\n\r\n'copying files...'\r\n$output = robocopy $src $dest /mir /njh /njs /nfl /ndl /xd .git tmp /xf .DS_Store last_updated\r\n\r\n$output | Where-Object { $_ -ne \"\" }\r\n\r\nWrite-Output 'creating shim...'\r\nshim \"$dest\\bin\\scoop.ps1\" $false\r\n\r\nsuccess 'scoop was refreshed!'\r\n"
  },
  {
    "path": "bin/scoop.ps1",
    "content": "#Requires -Version 5\r\nSet-StrictMode -Off\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\buckets.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\commands.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\help.ps1\"\r\n\r\n$subCommand = $Args[0]\r\n\r\n# for aliases where there's a local function, re-alias so the function takes precedence\r\n$aliases = Get-Alias | Where-Object { $_.Options -notmatch 'ReadOnly|AllScope' } | ForEach-Object { $_.Name }\r\nGet-ChildItem Function: | Where-Object -Property Name -In -Value $aliases | ForEach-Object {\r\n    Set-Alias -Name $_.Name -Value Local:$($_.Name) -Scope Script\r\n}\r\n\r\nswitch ($subCommand) {\r\n    ({ $subCommand -in @($null, '-h', '--help', '/?') }) {\r\n        exec 'help'\r\n    }\r\n    ({ $subCommand -in @('-v', '--version') }) {\r\n        Write-Host 'Current Scoop version:'\r\n        if (Test-GitAvailable -and (Test-Path \"$PSScriptRoot\\..\\.git\") -and (get_config SCOOP_BRANCH 'master') -ne 'master') {\r\n            Invoke-Git -Path \"$PSScriptRoot\\..\" -ArgumentList @('log', 'HEAD', '-1', '--oneline')\r\n        } else {\r\n            $version = Select-String -Pattern '^## \\[(v[\\d.]+)\\].*?([\\d-]+)$' -Path \"$PSScriptRoot\\..\\CHANGELOG.md\"\r\n            Write-Host $version.Matches.Groups[1].Value -ForegroundColor Cyan -NoNewline\r\n            Write-Host \" - Released at $($version.Matches.Groups[2].Value)\"\r\n        }\r\n        Write-Host ''\r\n\r\n        Get-LocalBucket | ForEach-Object {\r\n            $bucketLoc = Find-BucketDirectory $_ -Root\r\n            if (Test-GitAvailable -and (Test-Path \"$bucketLoc\\.git\")) {\r\n                Write-Host \"'$_' bucket:\"\r\n                Invoke-Git -Path $bucketLoc -ArgumentList @('log', 'HEAD', '-1', '--oneline')\r\n                Write-Host ''\r\n            }\r\n        }\r\n    }\r\n    ({ $subCommand -in (commands) }) {\r\n        [string[]]$arguments = $Args | Select-Object -Skip 1\r\n        if ($null -ne $arguments -and $arguments[0] -in @('-h', '--help', '/?')) {\r\n            exec 'help' @($subCommand)\r\n        } else {\r\n            exec $subCommand $arguments\r\n        }\r\n    }\r\n    default {\r\n        warn \"scoop: '$subCommand' isn't a scoop command. See 'scoop help'.\"\r\n        exit 1\r\n    }\r\n}\r\n"
  },
  {
    "path": "bin/test.ps1",
    "content": ". \"$PSScriptRoot\\..\\test\\bin\\test.ps1\"\r\n"
  },
  {
    "path": "bin/uninstall.ps1",
    "content": "<#\r\n.SYNOPSIS\r\n    Uninstall ALL scoop applications and scoop itself.\r\n.PARAMETER global\r\n    Global applications will be uninstalled.\r\n.PARAMETER purge\r\n    Persisted data will be deleted.\r\n#>\r\nparam(\r\n    [bool] $global,\r\n    [bool] $purge\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\system.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\shortcuts.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n\r\nif ($global -and !(is_admin)) {\r\n    error 'You need admin rights to uninstall globally.'\r\n    exit 1\r\n}\r\n\r\nif ($purge) {\r\n    warn 'This will uninstall Scoop, all the programs that have been installed with Scoop and all persisted data!'\r\n} else {\r\n    warn 'This will uninstall Scoop and all the programs that have been installed with Scoop!'\r\n}\r\n$yn = Read-Host 'Are you sure? (yN)'\r\nif ($yn -notlike 'y*') { exit }\r\n\r\n$errors = $false\r\n\r\n# Uninstall given app\r\nfunction do_uninstall($app, $global) {\r\n    $version = Select-CurrentVersion -AppName $app -Global:$global\r\n    $dir = versiondir $app $version $global\r\n    $manifest = installed_manifest $app $version $global\r\n    $install = install_info $app $version $global\r\n    $architecture = $install.architecture\r\n\r\n    Write-Output \"Uninstalling '$app'\"\r\n    Invoke-Installer -Path $dir -Manifest $manifest -ProcessorArchitecture $architecture -Uninstall\r\n    rm_shims $app $manifest $global $architecture\r\n\r\n    # If a junction was used during install, that will have been used\r\n    # as the reference directory. Othewise it will just be the version\r\n    # directory.\r\n    $refdir = unlink_current (appdir $app $global)\r\n\r\n    env_rm_path $manifest $refdir $global $architecture\r\n    env_rm $manifest $global $architecture\r\n\r\n    $appdir = appdir $app $global\r\n    try {\r\n        Remove-Item $appdir -Recurse -Force -ErrorAction Stop\r\n    } catch {\r\n        $errors = $true\r\n        warn \"Couldn't remove $(friendly_path $appdir): $_.Exception\"\r\n    }\r\n}\r\n\r\nfunction rm_dir($dir) {\r\n    try {\r\n        Remove-Item $dir -Recurse -Force -ErrorAction Stop\r\n    } catch {\r\n        abort \"Couldn't remove $(friendly_path $dir): $_\"\r\n    }\r\n}\r\n\r\n# Remove all folders (except persist) inside given scoop directory.\r\nfunction keep_onlypersist($directory) {\r\n    Get-ChildItem $directory -Exclude 'persist' | ForEach-Object { rm_dir $_ }\r\n}\r\n\r\n# Run uninstallation for each app if necessary, continuing if there's\r\n# a problem deleting a directory (which is quite likely)\r\nif ($global) {\r\n    installed_apps $true | ForEach-Object { # global apps\r\n        do_uninstall $_ $true\r\n    }\r\n}\r\n\r\ninstalled_apps $false | ForEach-Object { # local apps\r\n    do_uninstall $_ $false\r\n}\r\n\r\nif ($errors) {\r\n    abort 'Not all apps could be deleted. Try again or restart.'\r\n}\r\n\r\nif ($purge) {\r\n    rm_dir $scoopdir\r\n    if ($global) { rm_dir $globaldir }\r\n} else {\r\n    keep_onlypersist $scoopdir\r\n    if ($global) { keep_onlypersist $globaldir }\r\n}\r\n\r\nRemove-Path -Path (shimdir $global) -Global:$global\r\nif (get_config USE_ISOLATED_PATH) {\r\n    Remove-Path -Path ('%' + $scoopPathEnvVar + '%') -Global:$global\r\n}\r\n\r\nsuccess 'Scoop has been uninstalled.'\r\n"
  },
  {
    "path": "buckets.json",
    "content": "{\r\n    \"main\": \"https://github.com/ScoopInstaller/Main\",\r\n    \"extras\": \"https://github.com/ScoopInstaller/Extras\",\r\n    \"versions\": \"https://github.com/ScoopInstaller/Versions\",\r\n    \"nirsoft\": \"https://github.com/ScoopInstaller/Nirsoft\",\r\n    \"sysinternals\": \"https://github.com/niheaven/scoop-sysinternals\",\r\n    \"php\": \"https://github.com/ScoopInstaller/PHP\",\r\n    \"nerd-fonts\": \"https://github.com/matthewjberger/scoop-nerd-fonts\",\r\n    \"nonportable\": \"https://github.com/ScoopInstaller/Nonportable\",\r\n    \"java\": \"https://github.com/ScoopInstaller/Java\",\r\n    \"games\": \"https://github.com/Calinou/scoop-games\"\r\n}\r\n"
  },
  {
    "path": "lib/autoupdate.ps1",
    "content": "# Must included with 'json.ps1'\r\n\r\nfunction format_hash([String] $hash) {\r\n    $hash = $hash.toLower()\r\n\r\n    if ($hash -like 'sha256:*') {\r\n        $hash = $hash.Substring(7)  # Remove prefix 'sha256:'\r\n    }\r\n\r\n    switch ($hash.Length) {\r\n        32 { $hash = \"md5:$hash\" } # md5\r\n        40 { $hash = \"sha1:$hash\" } # sha1\r\n        64 { $hash = $hash } # sha256\r\n        128 { $hash = \"sha512:$hash\" } # sha512\r\n        default { $hash = $null }\r\n    }\r\n    return $hash\r\n}\r\n\r\nfunction find_hash_in_rdf([String] $url, [String] $basename) {\r\n    $xml = $null\r\n    try {\r\n        # Download and parse RDF XML file\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('Referer', (strip_filename $url))\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $data = $wc.DownloadData($url)\r\n        [xml]$xml = (Get-Encoding($wc)).GetString($data)\r\n    } catch [System.Net.WebException] {\r\n        Write-Host $_ -ForegroundColor DarkRed\r\n        Write-Host \"URL $url is not valid\" -ForegroundColor DarkRed\r\n        return $null\r\n    }\r\n\r\n    # Find file content\r\n    $digest = $xml.RDF.Content | Where-Object { [String]$_.about -eq $basename }\r\n\r\n    return format_hash $digest.sha256\r\n}\r\n\r\nfunction find_hash_in_textfile([String] $url, [Hashtable] $substitutions, [String] $regex) {\r\n    $hashfile = $null\r\n\r\n    $templates = @{\r\n        '$md5'      = '([a-fA-F0-9]{32})'\r\n        '$sha1'     = '([a-fA-F0-9]{40})'\r\n        '$sha256'   = '([a-fA-F0-9]{64})'\r\n        '$sha512'   = '([a-fA-F0-9]{128})'\r\n        '$checksum' = '([a-fA-F0-9]{32,128})'\r\n        '$base64'   = '([a-zA-Z0-9+\\/=]{24,88})'\r\n    }\r\n\r\n    try {\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('Referer', (strip_filename $url))\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $data = $wc.DownloadData($url)\r\n        $ms = New-Object System.IO.MemoryStream\r\n        $ms.Write($data, 0, $data.Length)\r\n        $ms.Seek(0, 0) | Out-Null\r\n        if ($data[0] -eq 0x1F -and $data[1] -eq 0x8B) {\r\n            $ms = New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Decompress)\r\n        }\r\n        $hashfile = (New-Object System.IO.StreamReader($ms, (Get-Encoding $wc))).ReadToEnd()\r\n    } catch [system.net.webexception] {\r\n        Write-Host $_ -ForegroundColor DarkRed\r\n        Write-Host \"URL $url is not valid\" -ForegroundColor DarkRed\r\n        return\r\n    }\r\n\r\n    if ($regex.Length -eq 0) {\r\n        $regex = '^\\s*([a-fA-F0-9]+)\\s*$'\r\n    }\r\n\r\n    $regex = substitute $regex $templates $false\r\n    $regex = substitute $regex $substitutions $true\r\n    if ($hashfile -match $regex) {\r\n        debug $regex\r\n        $hash = $matches[1] -replace '\\s', ''\r\n    }\r\n\r\n    # convert base64 encoded hash values\r\n    if ($hash -match '^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$') {\r\n        $base64 = $matches[0]\r\n        if (!($hash -match '^[a-fA-F0-9]+$') -and $hash.Length -notin @(32, 40, 64, 128)) {\r\n            try {\r\n                $hash = ([System.Convert]::FromBase64String($base64) | ForEach-Object { $_.ToString('x2') }) -join ''\r\n            } catch {\r\n                $hash = $hash\r\n            }\r\n        }\r\n    }\r\n\r\n    # find hash with filename in $hashfile\r\n    if ($hash.Length -eq 0) {\r\n        $filenameRegex = \"([a-fA-F0-9]{32,128})[\\x20\\t]+.*`$basename(?:\\s|$)|`$basename[\\x20\\t]+.*?([a-fA-F0-9]{32,128})\"\r\n        $filenameRegex = substitute $filenameRegex $substitutions $true\r\n        if ($hashfile -match $filenameRegex) {\r\n            debug $filenameRegex\r\n            $hash = $matches[1]\r\n        }\r\n        $metalinkRegex = '<hash[^>]+>([a-fA-F0-9]{64})'\r\n        if ($hashfile -match $metalinkRegex) {\r\n            debug $metalinkRegex\r\n            $hash = $matches[1]\r\n        }\r\n    }\r\n\r\n    return format_hash $hash\r\n}\r\n\r\nfunction find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $jsonpath) {\r\n    $json = $null\r\n\r\n    try {\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('Referer', (strip_filename $url))\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $data = $wc.DownloadData($url)\r\n        $ms = New-Object System.IO.MemoryStream\r\n        $ms.Write($data, 0, $data.Length)\r\n        $ms.Seek(0, 0) | Out-Null\r\n        if ($data[0] -eq 0x1F -and $data[1] -eq 0x8B) {\r\n            $ms = New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Decompress)\r\n        }\r\n        $json = (New-Object System.IO.StreamReader($ms, (Get-Encoding $wc))).ReadToEnd()\r\n    } catch [System.Net.WebException] {\r\n        Write-Host $_ -ForegroundColor DarkRed\r\n        Write-Host \"URL $url is not valid\" -ForegroundColor DarkRed\r\n        return\r\n    }\r\n    debug $jsonpath\r\n    $hash = json_path $json $jsonpath $substitutions\r\n    if (!$hash) {\r\n        $hash = json_path_legacy $json $jsonpath $substitutions\r\n    }\r\n    return format_hash $hash\r\n}\r\n\r\nfunction find_hash_in_xml([String] $url, [Hashtable] $substitutions, [String] $xpath) {\r\n    $xml = $null\r\n\r\n    try {\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('Referer', (strip_filename $url))\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $data = $wc.DownloadData($url)\r\n        $ms = New-Object System.IO.MemoryStream\r\n        $ms.Write($data, 0, $data.Length)\r\n        $ms.Seek(0, 0) | Out-Null\r\n        if ($data[0] -eq 0x1F -and $data[1] -eq 0x8B) {\r\n            $ms = New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Decompress)\r\n        }\r\n        $xml = [xml]((New-Object System.IO.StreamReader($ms, (Get-Encoding $wc))).ReadToEnd())\r\n    } catch [system.net.webexception] {\r\n        Write-Host $_ -ForegroundColor DarkRed\r\n        Write-Host \"URL $url is not valid\" -ForegroundColor DarkRed\r\n        return\r\n    }\r\n\r\n    # Replace placeholders\r\n    if ($substitutions) {\r\n        $xpath = substitute $xpath $substitutions\r\n    }\r\n\r\n    # Find all `significant namespace declarations` from the XML file\r\n    $nsList = $xml.SelectNodes('//namespace::*[not(. = ../../namespace::*)]')\r\n    # Then add them into the NamespaceManager\r\n    $nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)\r\n    $nsList | ForEach-Object {\r\n        $nsmgr.AddNamespace($_.LocalName, $_.Value)\r\n    }\r\n\r\n    debug $xpath\r\n    debug $nsmgr\r\n    # Getting hash from XML, using XPath\r\n    $hash = $xml.SelectSingleNode($xpath, $nsmgr).'#text'\r\n    return format_hash $hash\r\n}\r\n\r\nfunction find_hash_in_headers([String] $url) {\r\n    $hash = $null\r\n\r\n    try {\r\n        $req = [System.Net.WebRequest]::Create($url)\r\n        $req.Referer = (strip_filename $url)\r\n        $req.AllowAutoRedirect = $false\r\n        $req.UserAgent = (Get-UserAgent)\r\n        $req.Timeout = 2000\r\n        $req.Method = 'HEAD'\r\n        $res = $req.GetResponse()\r\n        if (([int]$res.StatusCode -ge 300) -and ([int]$res.StatusCode -lt 400)) {\r\n            if ($res.Headers['Digest'] -match 'SHA-256=([^,]+)' -or $res.Headers['Digest'] -match 'SHA=([^,]+)' -or $res.Headers['Digest'] -match 'MD5=([^,]+)') {\r\n                $hash = ([System.Convert]::FromBase64String($matches[1]) | ForEach-Object { $_.ToString('x2') }) -join ''\r\n                debug $hash\r\n            }\r\n        }\r\n        $res.Close()\r\n    } catch [System.Net.WebException] {\r\n        Write-Host $_ -ForegroundColor DarkRed\r\n        Write-Host \"URL $url is not valid\" -ForegroundColor DarkRed\r\n        return\r\n    }\r\n\r\n    return format_hash $hash\r\n}\r\n\r\nfunction get_hash_for_app([String] $app, $config, [String] $version, [String] $url, [Hashtable] $substitutions) {\r\n    $hash = $null\r\n\r\n    $hashmode = $config.mode\r\n    $basename = [System.Web.HttpUtility]::UrlDecode((url_remote_filename($url)))\r\n\r\n    $substitutions = $substitutions.Clone()\r\n    $substitutions.Add('$url', (strip_fragment $url))\r\n    $substitutions.Add('$baseurl', (strip_filename (strip_fragment $url)).TrimEnd('/'))\r\n    $substitutions.Add('$basename', $basename)\r\n    $substitutions.Add('$urlNoExt', (strip_ext (strip_fragment $url)))\r\n    $substitutions.Add('$basenameNoExt', (strip_ext $basename))\r\n\r\n    debug $substitutions\r\n\r\n    $hashfile_url = substitute $config.url $substitutions\r\n    debug $hashfile_url\r\n    if ($hashfile_url) {\r\n        Write-Host 'Searching hash for ' -ForegroundColor DarkYellow -NoNewline\r\n        Write-Host $basename -ForegroundColor Green -NoNewline\r\n        Write-Host ' in ' -ForegroundColor DarkYellow -NoNewline\r\n        Write-Host $hashfile_url -ForegroundColor Green\r\n    }\r\n\r\n    if ($hashmode.Length -eq 0 -and $config.url.Length -ne 0) {\r\n        $hashmode = 'extract'\r\n    }\r\n\r\n    $jsonpath = ''\r\n    if ($config.jp) {\r\n        $jsonpath = $config.jp\r\n        $hashmode = 'json'\r\n    }\r\n    if ($config.jsonpath) {\r\n        $jsonpath = $config.jsonpath\r\n        $hashmode = 'json'\r\n    }\r\n    $regex = ''\r\n    if ($config.find) {\r\n        $regex = $config.find\r\n    }\r\n    if ($config.regex) {\r\n        $regex = $config.regex\r\n    }\r\n\r\n    $xpath = ''\r\n    if ($config.xpath) {\r\n        $xpath = $config.xpath\r\n        $hashmode = 'xpath'\r\n    }\r\n\r\n    if (!$hashfile_url -and $url -match '^(?:.*fosshub.com\\/).*(?:\\/|\\?dwl=)(?<filename>.*)$') {\r\n        $hashmode = 'fosshub'\r\n    }\r\n\r\n    if (!$hashfile_url -and $url -match '(?:downloads\\.)?sourceforge.net\\/projects?\\/(?<project>[^\\/]+)\\/(?:files\\/)?(?<file>.*)') {\r\n        $hashmode = 'sourceforge'\r\n    }\r\n\r\n    if (!$hashfile_url -and $url -match 'https:\\/\\/github\\.com\\/(?<owner>[^\\/]+)\\/(?<repo>[^\\/]+)\\/releases\\/download\\/[^\\/]+\\/[^\\/]+') {\r\n        $hashmode = 'github'\r\n    }\r\n\r\n    switch ($hashmode) {\r\n        'extract' {\r\n            $hash = find_hash_in_textfile $hashfile_url $substitutions $regex\r\n        }\r\n        'json' {\r\n            $hash = find_hash_in_json $hashfile_url $substitutions $jsonpath\r\n        }\r\n        'xpath' {\r\n            $hash = find_hash_in_xml $hashfile_url $substitutions $xpath\r\n        }\r\n        'rdf' {\r\n            $hash = find_hash_in_rdf $hashfile_url $basename\r\n        }\r\n        'metalink' {\r\n            $hash = find_hash_in_headers $url\r\n            if (!$hash) {\r\n                $hash = find_hash_in_textfile \"$url.meta4\" $substitutions\r\n            }\r\n        }\r\n        'fosshub' {\r\n            $hash = find_hash_in_textfile $url $substitutions ($matches.filename + '.*?\"sha256\":\"([a-fA-F0-9]{64})\"')\r\n        }\r\n        'sourceforge' {\r\n            # change the URL because downloads.sourceforge.net doesn't have checksums\r\n            $hashfile_url = (strip_filename (strip_fragment \"https://sourceforge.net/projects/$($matches['project'])/files/$($matches['file'])\")).TrimEnd('/')\r\n            $hash = find_hash_in_textfile $hashfile_url $substitutions '\"$basename\":.*?\"sha1\":\\s*\"([a-fA-F0-9]{40})\"'\r\n        }\r\n        'github' {\r\n            $hashfile_url = \"https://api.github.com/repos/$($matches['owner'])/$($matches['repo'])/releases\"\r\n            $hash = find_hash_in_json $hashfile_url $substitutions (\"$..assets[?(@.browser_download_url == '\" + $url + \"')].digest\")\r\n        }\r\n    }\r\n\r\n    if ($hash) {\r\n        # got one!\r\n        Write-Host 'Found: ' -ForegroundColor DarkYellow -NoNewline\r\n        Write-Host $hash -ForegroundColor Green -NoNewline\r\n        Write-Host ' using ' -ForegroundColor DarkYellow -NoNewline\r\n        Write-Host \"$((Get-Culture).TextInfo.ToTitleCase($hashmode)) Mode\" -ForegroundColor Green\r\n        return $hash\r\n    } elseif ($hashfile_url) {\r\n        Write-Host -f DarkYellow \"Could not find hash in $hashfile_url\"\r\n    }\r\n\r\n    Write-Host 'Downloading ' -ForegroundColor DarkYellow -NoNewline\r\n    Write-Host $basename -ForegroundColor Green -NoNewline\r\n    Write-Host ' to compute hashes!' -ForegroundColor DarkYellow\r\n    try {\r\n        Invoke-CachedDownload $app $version $url $null $null $true\r\n    } catch [system.net.webexception] {\r\n        Write-Host $_ -ForegroundColor DarkRed\r\n        Write-Host \"URL $url is not valid\" -ForegroundColor DarkRed\r\n        return $null\r\n    }\r\n    $file = cache_path $app $version $url\r\n    $hash = (Get-FileHash -Path $file -Algorithm SHA256).Hash.ToLower()\r\n    Write-Host 'Computed hash: ' -ForegroundColor DarkYellow -NoNewline\r\n    Write-Host $hash -ForegroundColor Green\r\n    return $hash\r\n}\r\n\r\nfunction Update-ManifestProperty {\r\n    <#\r\n    .SYNOPSIS\r\n        Update propert(y|ies) in manifest\r\n    .DESCRIPTION\r\n        Update selected propert(y|ies) to given version in manifest.\r\n    .PARAMETER Manifest\r\n        Manifest to be updated\r\n    .PARAMETER Property\r\n        Selected propert(y|ies) to be updated\r\n    .PARAMETER AppName\r\n        Software name\r\n    .PARAMETER Version\r\n        Given software version\r\n    .PARAMETER Substitutions\r\n        Hashtable of internal substitutable variables\r\n    .OUTPUTS\r\n        System.Boolean\r\n            Flag that indicate if there are any changed properties\r\n    #>\r\n    [CmdletBinding(SupportsShouldProcess = $true)]\r\n    [OutputType([Boolean])]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 1)]\r\n        [PSCustomObject]\r\n        $Manifest,\r\n        [Parameter(ValueFromPipeline = $true, Position = 2)]\r\n        [String[]]\r\n        $Property,\r\n        [String]\r\n        $AppName,\r\n        [String]\r\n        $Version,\r\n        [Alias('Matches')]\r\n        [HashTable]\r\n        $Substitutions\r\n    )\r\n    begin {\r\n        $hasManifestChanged = $false\r\n    }\r\n    process {\r\n        foreach ($currentProperty in $Property) {\r\n            if ($currentProperty -eq 'hash') {\r\n                # Update hash\r\n                if ($Manifest.hash) {\r\n                    # Global\r\n                    $newURL = substitute $Manifest.autoupdate.url $Substitutions\r\n                    $newHash = HashHelper -AppName $AppName -Version $Version -HashExtraction $Manifest.autoupdate.hash -URL $newURL -Substitutions $Substitutions\r\n                    $Manifest.hash, $hasPropertyChanged = PropertyHelper -Property $Manifest.hash -Value $newHash\r\n                    $hasManifestChanged = $hasManifestChanged -or $hasPropertyChanged\r\n                } else {\r\n                    # Arch-spec\r\n                    $Manifest.architecture | Get-Member -MemberType NoteProperty | ForEach-Object {\r\n                        $arch = $_.Name\r\n                        $newURL = substitute (arch_specific 'url' $Manifest.autoupdate $arch) $Substitutions\r\n                        $newHash = HashHelper -AppName $AppName -Version $Version -HashExtraction (arch_specific 'hash' $Manifest.autoupdate $arch) -URL $newURL -Substitutions $Substitutions\r\n                        $Manifest.architecture.$arch.hash, $hasPropertyChanged = PropertyHelper -Property $Manifest.architecture.$arch.hash -Value $newHash\r\n                        $hasManifestChanged = $hasManifestChanged -or $hasPropertyChanged\r\n                    }\r\n                }\r\n            } elseif ($Manifest.$currentProperty -and $Manifest.autoupdate.$currentProperty) {\r\n                # Update other property (global)\r\n                $autoupdateProperty = $Manifest.autoupdate.$currentProperty\r\n                $newValue = substitute $autoupdateProperty $Substitutions\r\n                if (($autoupdateProperty.GetType().Name -eq 'Object[]') -and ($autoupdateProperty.Length -eq 1)) {\r\n                    # Make sure it's an array\r\n                    $newValue = , $newValue\r\n                }\r\n                $Manifest.$currentProperty, $hasPropertyChanged = PropertyHelper -Property $Manifest.$currentProperty -Value $newValue\r\n                $hasManifestChanged = $hasManifestChanged -or $hasPropertyChanged\r\n            } elseif ($Manifest.architecture) {\r\n                # Update other property (arch-spec)\r\n                $Manifest.architecture | Get-Member -MemberType NoteProperty | ForEach-Object {\r\n                    $arch = $_.Name\r\n                    if ($Manifest.architecture.$arch.$currentProperty -and ($Manifest.autoupdate.architecture.$arch.$currentProperty -or $Manifest.autoupdate.$currentProperty)) {\r\n                        $autoupdateProperty = @(arch_specific $currentProperty $Manifest.autoupdate $arch)\r\n                        $newValue = substitute $autoupdateProperty $Substitutions\r\n                        if (($autoupdateProperty.GetType().Name -eq 'Object[]') -and ($autoupdateProperty.Length -eq 1)) {\r\n                            # Make sure it's an array\r\n                            $newValue = , $newValue\r\n                        }\r\n                        $Manifest.architecture.$arch.$currentProperty, $hasPropertyChanged = PropertyHelper -Property $Manifest.architecture.$arch.$currentProperty -Value $newValue\r\n                        $hasManifestChanged = $hasManifestChanged -or $hasPropertyChanged\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    end {\r\n        if ($Version -ne '' -and $Manifest.version -ne $Version) {\r\n            $Manifest.version = $Version\r\n            $hasManifestChanged = $true\r\n        }\r\n        return $hasManifestChanged\r\n    }\r\n}\r\n\r\nfunction Get-VersionSubstitution {\r\n    param (\r\n        [String]\r\n        $Version,\r\n        [Hashtable]\r\n        $CustomMatches\r\n    )\r\n\r\n    $firstPart = $Version.Split('-') | Select-Object -First 1\r\n    $lastPart = $Version.Split('-') | Select-Object -Last 1\r\n    $versionVariables = @{\r\n        '$version'           = $Version\r\n        '$dotVersion'        = ($Version -replace '[._-]', '.')\r\n        '$underscoreVersion' = ($Version -replace '[._-]', '_')\r\n        '$dashVersion'       = ($Version -replace '[._-]', '-')\r\n        '$cleanVersion'      = ($Version -replace '[._-]', '')\r\n        '$majorVersion'      = $firstPart.Split('.') | Select-Object -First 1\r\n        '$minorVersion'      = $firstPart.Split('.') | Select-Object -Skip 1 -First 1\r\n        '$patchVersion'      = $firstPart.Split('.') | Select-Object -Skip 2 -First 1\r\n        '$buildVersion'      = $firstPart.Split('.') | Select-Object -Skip 3 -First 1\r\n        '$preReleaseVersion' = $lastPart\r\n    }\r\n    if ($Version -match '(?<head>\\d+\\.\\d+(?:\\.\\d+)?)(?<tail>.*)') {\r\n        $versionVariables.Add('$matchHead', $Matches['head'])\r\n        $versionVariables.Add('$matchTail', $Matches['tail'])\r\n    }\r\n    if ($CustomMatches) {\r\n        $CustomMatches.GetEnumerator() | ForEach-Object {\r\n            if ($_.Name -ne '0') {\r\n                $versionVariables.Add('$match' + (Get-Culture).TextInfo.ToTitleCase($_.Name), $_.Value)\r\n            }\r\n        }\r\n    }\r\n    return $versionVariables\r\n}\r\n\r\nfunction Invoke-AutoUpdate {\r\n    param (\r\n        [String]\r\n        $AppName,\r\n        [String]\r\n        $Path,\r\n        [PSObject]\r\n        $Manifest,\r\n        [String]\r\n        $Version,\r\n        [Hashtable]\r\n        $CustomMatches\r\n    )\r\n\r\n    Write-Host \"Autoupdating $AppName\" -ForegroundColor DarkCyan\r\n    $substitutions = Get-VersionSubstitution $Version $CustomMatches\r\n\r\n    # update properties\r\n    $updatedProperties = @(@($Manifest.autoupdate.PSObject.Properties.Name) -ne 'architecture')\r\n    if ($Manifest.autoupdate.architecture) {\r\n        $updatedProperties += $Manifest.autoupdate.architecture.PSObject.Properties | ForEach-Object { $_.Value.PSObject.Properties.Name }\r\n    }\r\n    if ($updatedProperties -contains 'url') {\r\n        $updatedProperties += 'hash'\r\n    }\r\n    $updatedProperties = $updatedProperties | Select-Object -Unique\r\n    debug [$updatedProperties]\r\n    $hasChanged = Update-ManifestProperty -Manifest $Manifest -Property $updatedProperties -AppName $AppName -Version $Version -Substitutions $substitutions\r\n\r\n    if ($hasChanged) {\r\n        # write file\r\n        Write-Host \"Writing updated $AppName manifest\" -ForegroundColor DarkGreen\r\n        # Accept unusual Unicode characters\r\n        # 'Set-Content -Encoding ASCII' don't works in PowerShell 5\r\n        # Wait for 'UTF8NoBOM' Encoding in PowerShell 7\r\n        # $Manifest | ConvertToPrettyJson | Set-Content -Path (Join-Path $Path \"$AppName.json\") -Encoding UTF8NoBOM\r\n        [System.IO.File]::WriteAllLines($Path, (ConvertToPrettyJson $Manifest))\r\n        # notes\r\n        $note = \"`nUpdating note:\"\r\n        if ($Manifest.autoupdate.note) {\r\n            $note += \"`nno-arch: $($Manifest.autoupdate.note)\"\r\n            $hasNote = $true\r\n        }\r\n        if ($Manifest.autoupdate.architecture) {\r\n            '64bit', '32bit', 'arm64' | ForEach-Object {\r\n                if ($Manifest.autoupdate.architecture.$_.note) {\r\n                    $note += \"`n$_-arch: $($Manifest.autoupdate.architecture.$_.note)\"\r\n                    $hasNote = $true\r\n                }\r\n            }\r\n        }\r\n        if ($hasNote) {\r\n            Write-Host $note -ForegroundColor DarkYellow\r\n        }\r\n    } else {\r\n        # This if-else branch may not be in use.\r\n        Write-Host \"No updates for $AppName\" -ForegroundColor DarkGray\r\n    }\r\n}\r\n\r\n## Helper Functions\r\n\r\nfunction PropertyHelper {\r\n    <#\r\n    .SYNOPSIS\r\n        Helper of updating property\r\n    .DESCRIPTION\r\n        Update manifest property (String, Array or PSCustomObject).\r\n    .PARAMETER Property\r\n        Property to be updated\r\n    .PARAMETER Value\r\n        New property values\r\n        Update line by line\r\n    .OUTPUTS\r\n        System.Object[]\r\n            The first element is new property, the second element is change flag\r\n    #>\r\n    param (\r\n        [Object]$Property,\r\n        [Object]$Value\r\n    )\r\n    $hasChanged = $false\r\n    if (@($Property).Length -lt @($Value).Length) {\r\n        $Property = $Value\r\n        $hasChanged = $true\r\n    } else {\r\n        switch ($Property.GetType().Name) {\r\n            'String' {\r\n                $Value = $Value -as [String]\r\n                if ($null -ne $Value) {\r\n                    $Property = $Value\r\n                    $hasChanged = $true\r\n                }\r\n            }\r\n            'Object[]' {\r\n                $Value = @($Value)\r\n                for ($i = 0; $i -lt $Value.Length; $i++) {\r\n                    $Property[$i], $hasItemChanged = PropertyHelper -Property $Property[$i] -Value $Value[$i]\r\n                    $hasChanged = $hasChanged -or $hasItemChanged\r\n                }\r\n            }\r\n            'PSCustomObject' {\r\n                if ($Value -is [PSObject]) {\r\n                    foreach ($name in $Property.PSObject.Properties.Name) {\r\n                        if ($Value.$name) {\r\n                            $Property.$name, $hasItemChanged = PropertyHelper -Property $Property.$name -Value $Value.$name\r\n                            $hasChanged = $hasChanged -or $hasItemChanged\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    return $Property, $hasChanged\r\n}\r\n\r\nfunction HashHelper {\r\n    <#\r\n    .SYNOPSIS\r\n        Helper of getting file hash(es)\r\n    .DESCRIPTION\r\n        Extract or calculate file hash(es).\r\n        If hash extraction templates are less then URLs, the last template will be reused for the rest URLs.\r\n    .PARAMETER AppName\r\n        Software name\r\n    .PARAMETER Version\r\n        Given software version\r\n    .PARAMETER HashExtraction\r\n        Hash extraction template(s)\r\n    .PARAMETER URL\r\n        New download URL(s), used to calculate hash locally (fallback)\r\n    .PARAMETER Substitutions\r\n        Hashtable of internal substitutable variables\r\n    .OUTPUTS\r\n        System.String\r\n            Hash value (single URL)\r\n        System.String[]\r\n            Hash values (multi URLs)\r\n    #>\r\n    param (\r\n        [String]\r\n        $AppName,\r\n        [String]\r\n        $Version,\r\n        [PSObject[]]\r\n        $HashExtraction,\r\n        [String[]]\r\n        $URL,\r\n        [HashTable]\r\n        $Substitutions\r\n    )\r\n    $hash = @()\r\n    for ($i = 0; $i -lt $URL.Length; $i++) {\r\n        if ($null -eq $HashExtraction) {\r\n            $currentHashExtraction = $null\r\n        } else {\r\n            $currentHashExtraction = $HashExtraction[$i], $HashExtraction[-1] | Select-Object -First 1\r\n        }\r\n        $hash += get_hash_for_app $AppName $currentHashExtraction $Version $URL[$i] $Substitutions\r\n        if ($null -eq $hash[$i]) {\r\n            throw \"Could not update $AppName, hash for $(url_remote_filename $URL[$i]) failed!\"\r\n        }\r\n    }\r\n    return $hash\r\n}\r\n"
  },
  {
    "path": "lib/buckets.ps1",
    "content": "$bucketsdir = \"$scoopdir\\buckets\"\r\n\r\nfunction Find-BucketDirectory {\r\n    <#\r\n    .DESCRIPTION\r\n        Return full path for bucket with given name.\r\n        Main bucket will be returned as default.\r\n    .PARAMETER Name\r\n        Name of bucket.\r\n    .PARAMETER Root\r\n        Root folder of bucket repository will be returned instead of 'bucket' subdirectory (if exists).\r\n    #>\r\n    param(\r\n        [string] $Name = 'main',\r\n        [switch] $Root\r\n    )\r\n\r\n    # Handle info passing empty string as bucket ($install.bucket)\r\n    if (($null -eq $Name) -or ($Name -eq '')) {\r\n        $Name = 'main'\r\n    }\r\n    $bucket = \"$bucketsdir\\$Name\"\r\n\r\n    if ((Test-Path \"$bucket\\bucket\") -and !$Root) {\r\n        $bucket = \"$bucket\\bucket\"\r\n    }\r\n\r\n    return $bucket\r\n}\r\n\r\nfunction bucketdir($name) {\r\n    Show-DeprecatedWarning $MyInvocation 'Find-BucketDirectory'\r\n\r\n    return Find-BucketDirectory $name\r\n}\r\n\r\nfunction known_bucket_repos {\r\n    $json = \"$PSScriptRoot\\..\\buckets.json\"\r\n\r\n    return Get-Content $json -Raw | ConvertFrom-Json -ErrorAction stop\r\n}\r\n\r\nfunction known_bucket_repo($name) {\r\n    $buckets = known_bucket_repos\r\n    $buckets.$name\r\n}\r\n\r\nfunction known_buckets {\r\n    known_bucket_repos | ForEach-Object { $_.PSObject.Properties | Select-Object -Expand 'name' }\r\n}\r\n\r\nfunction apps_in_bucket($dir) {\r\n    return (Get-ChildItem $dir -Filter '*.json' -Recurse).BaseName\r\n}\r\n\r\nfunction Get-LocalBucket {\r\n    <#\r\n    .SYNOPSIS\r\n        List all local buckets.\r\n    #>\r\n    $bucketNames = [System.Collections.Generic.List[String]](Get-ChildItem -Path $bucketsdir -Directory).Name\r\n    if ($null -eq $bucketNames) {\r\n        return @() # Return a zero-length list instead of $null.\r\n    } else {\r\n        $knownBuckets = known_buckets\r\n        for ($i = $knownBuckets.Count - 1; $i -ge 0 ; $i--) {\r\n            $name = $knownBuckets[$i]\r\n            if ($bucketNames.Contains($name)) {\r\n                [void]$bucketNames.Remove($name)\r\n                $bucketNames.Insert(0, $name)\r\n            }\r\n        }\r\n        return $bucketNames\r\n    }\r\n}\r\n\r\nfunction buckets {\r\n    Show-DeprecatedWarning $MyInvocation 'Get-LocalBucket'\r\n\r\n    return Get-LocalBucket\r\n}\r\n\r\nfunction Convert-RepositoryUri {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory, Position = 0, ValueFromPipeline = $true)]\r\n        [AllowEmptyString()]\r\n        [String] $Uri\r\n    )\r\n\r\n    process {\r\n        # https://git-scm.com/docs/git-clone#_git_urls\r\n        # https://regex101.com/r/xGmwRr/1\r\n        if ($Uri -match '(?:@|/{1,3})(?:www\\.|.*@)?(?<provider>[^/]+?)(?::\\d+)?[:/](?<user>.+)/(?<repo>.+?)(?:\\.git)?/?$') {\r\n            $Matches.provider, $Matches.user, $Matches.repo -join '/'\r\n        } else {\r\n            error \"$Uri is not a valid Git URL!\"\r\n            error \"Please see https://git-scm.com/docs/git-clone#_git_urls for valid ones.\"\r\n            return $null\r\n        }\r\n    }\r\n}\r\n\r\nfunction list_buckets {\r\n    $buckets = @()\r\n    Get-LocalBucket | ForEach-Object {\r\n        $bucket = [Ordered]@{ Name = $_ }\r\n        $path = Find-BucketDirectory $_ -Root\r\n        if ((Test-Path (Join-Path $path '.git')) -and (Get-Command git -ErrorAction SilentlyContinue)) {\r\n            $bucket.Source = Invoke-Git -Path $path -ArgumentList @('config', 'remote.origin.url')\r\n            $bucket.Updated = Invoke-Git -Path $path -ArgumentList @('log', '--format=%aD', '-n', '1') | Get-Date\r\n        } else {\r\n            $bucket.Source = friendly_path $path\r\n            $bucket.Updated = (Get-Item \"$path\\bucket\" -ErrorAction SilentlyContinue).LastWriteTime\r\n        }\r\n        $bucket.Manifests = Get-ChildItem \"$path\\bucket\" -Force -Recurse -ErrorAction SilentlyContinue |\r\n                Measure-Object | Select-Object -ExpandProperty Count\r\n        $buckets += [PSCustomObject]$bucket\r\n    }\r\n    ,$buckets\r\n}\r\n\r\nfunction add_bucket($name, $repo) {\r\n    if (!(Test-GitAvailable)) {\r\n        error \"Git is required for buckets. Run 'scoop install git' and try again.\"\r\n        return 1\r\n    }\r\n\r\n    $dir = Find-BucketDirectory $name -Root\r\n    if (Test-Path $dir) {\r\n        warn \"The '$name' bucket already exists. To add this bucket again, first remove it by running 'scoop bucket rm $name'.\"\r\n        return 2\r\n    }\r\n\r\n    $uni_repo = Convert-RepositoryUri -Uri $repo\r\n    if ($null -eq $uni_repo) {\r\n        return 1\r\n    }\r\n    foreach ($bucket in Get-LocalBucket) {\r\n        if (Test-Path -Path \"$bucketsdir\\$bucket\\.git\") {\r\n            $remote = Invoke-Git -Path \"$bucketsdir\\$bucket\" -ArgumentList @('config', '--get', 'remote.origin.url')\r\n            if ((Convert-RepositoryUri -Uri $remote) -eq $uni_repo) {\r\n                warn \"Bucket $bucket already exists for $repo\"\r\n                return 2\r\n            }\r\n        }\r\n    }\r\n\r\n    Write-Host 'Checking repo... ' -NoNewline\r\n    $out = Invoke-Git -ArgumentList @('ls-remote', $repo) 2>&1\r\n    if ($LASTEXITCODE -ne 0) {\r\n        error \"'$repo' doesn't look like a valid git repository`n`nError given:`n$out\"\r\n        return 1\r\n    }\r\n    ensure $bucketsdir | Out-Null\r\n    $dir = ensure $dir\r\n    $out = Invoke-Git -ArgumentList @('clone', $repo, $dir, '-q')\r\n    if ($LASTEXITCODE -ne 0) {\r\n        error \"Failed to clone '$repo' to '$dir'.`n`nError given:`n$out`n`nPlease check the repository URL or network connection and try again.\"\r\n        Remove-Item $dir -Recurse -Force -ErrorAction SilentlyContinue\r\n        return 1\r\n    }\r\n    Write-Host 'OK'\r\n    if (get_config USE_SQLITE_CACHE) {\r\n        info 'Updating cache...'\r\n        Set-ScoopDB -Path (Get-ChildItem (Find-BucketDirectory $name) -Filter '*.json' -Recurse).FullName\r\n    }\r\n    success \"The $name bucket was added successfully.\"\r\n    return 0\r\n}\r\n\r\nfunction rm_bucket($name) {\r\n    $dir = Find-BucketDirectory $name -Root\r\n    if (!(Test-Path $dir)) {\r\n        error \"'$name' bucket not found.\"\r\n        return 1\r\n    }\r\n\r\n    Remove-Item $dir -Recurse -Force -ErrorAction Stop\r\n    if (get_config USE_SQLITE_CACHE) {\r\n        info 'Updating cache...'\r\n        Remove-ScoopDBItem -Bucket $name\r\n    }\r\n    success \"The $name bucket was removed successfully.\"\r\n    return 0\r\n}\r\n\r\nfunction new_issue_msg($app, $bucket, $title, $body) {\r\n    $app, $manifest, $bucket, $url = Get-Manifest \"$bucket/$app\"\r\n    $url = known_bucket_repo $bucket\r\n    $bucket_path = \"$bucketsdir\\$bucket\"\r\n\r\n    if (Test-Path $bucket_path) {\r\n        $remote = Invoke-Git -Path $bucket_path -ArgumentList @('config', '--get', 'remote.origin.url')\r\n        # Support ssh and http syntax\r\n        # git@PROVIDER:USER/REPO.git\r\n        # https://PROVIDER/USER/REPO.git\r\n        $remote -match '(@|:\\/\\/)(?<provider>.+)[:/](?<user>.*)\\/(?<repo>.*)(\\.git)?$' | Out-Null\r\n        $url = \"https://$($Matches.Provider)/$($Matches.User)/$($Matches.Repo)\"\r\n    }\r\n\r\n    if (!$url) { return 'Please contact the bucket maintainer!' }\r\n\r\n    # Print only github repositories\r\n    if ($url -like '*github*') {\r\n        $title = [System.Web.HttpUtility]::UrlEncode(\"$app@$($manifest.version): $title\")\r\n        $body = [System.Web.HttpUtility]::UrlEncode($body)\r\n        $url = $url -replace '\\.git$', ''\r\n        $url = \"$url/issues/new?title=$title\"\r\n        if ($body) {\r\n            $url += \"&body=$body\"\r\n        }\r\n    }\r\n\r\n    $msg = \"`nPlease try again or create a new issue by using the following link and paste your console output:\"\r\n    return \"$msg`n$url\"\r\n}\r\n"
  },
  {
    "path": "lib/commands.ps1",
    "content": "# Description: Functions for managing commands and aliases.\r\n\r\n## Functions for commands\r\n\r\nfunction command_files {\r\n    (Get-ChildItem \"$PSScriptRoot\\..\\libexec\") + (Get-ChildItem \"$scoopdir\\shims\") |\r\n    Where-Object 'scoop-.*?\\.ps1$' -Property Name -Match\r\n}\r\n\r\nfunction commands {\r\n    command_files | ForEach-Object { command_name $_ }\r\n}\r\n\r\nfunction command_name($filename) {\r\n    $filename.name | Select-String 'scoop-(.*?)\\.ps1$' | ForEach-Object { $_.matches[0].groups[1].value }\r\n}\r\n\r\nfunction command_path($cmd) {\r\n    $cmd_path = \"$PSScriptRoot\\..\\libexec\\scoop-$cmd.ps1\"\r\n\r\n    # built in commands\r\n    if (!(Test-Path $cmd_path)) {\r\n        # get path from shim\r\n        $shim_path = \"$scoopdir\\shims\\scoop-$cmd.ps1\"\r\n        $line = ((Get-Content $shim_path) | Where-Object { $_.startswith('$path') })\r\n        if ($line) {\r\n            Invoke-Command ([scriptblock]::Create($line)) -NoNewScope\r\n            $cmd_path = $path\r\n        } else { $cmd_path = $shim_path }\r\n    }\r\n\r\n    $cmd_path\r\n}\r\n\r\nfunction exec($cmd, $arguments) {\r\n    $cmd_path = command_path $cmd\r\n\r\n    & $cmd_path @arguments\r\n}\r\n\r\n## Functions for aliases\r\n\r\nfunction add_alias {\r\n    param(\r\n        [ValidateNotNullOrEmpty()]\r\n        [string]$name,\r\n        [ValidateNotNullOrEmpty()]\r\n        [string]$command,\r\n        [string]$description\r\n    )\r\n\r\n    $aliases = get_config ALIAS ([PSCustomObject]@{})\r\n    if ($aliases.$name) {\r\n        abort \"Alias '$name' already exists.\"\r\n    }\r\n\r\n    $alias_script_name = \"scoop-$name\"\r\n    $shimdir = shimdir $false\r\n    if (Test-Path \"$shimdir\\$alias_script_name.ps1\") {\r\n        abort \"File '$alias_script_name.ps1' already exists in shims directory.\"\r\n    }\r\n    $script = @(\r\n        \"# Summary: $description\",\r\n        \"$command\"\r\n    ) -join \"`n\"\r\n    try {\r\n        $script | Out-UTF8File \"$shimdir\\$alias_script_name.ps1\"\r\n    } catch {\r\n        abort $_.Exception\r\n    }\r\n\r\n    # Add the new alias to the config.\r\n    $aliases | Add-Member -MemberType NoteProperty -Name $name -Value $alias_script_name\r\n    set_config ALIAS $aliases | Out-Null\r\n}\r\n\r\nfunction rm_alias {\r\n    param(\r\n        [ValidateNotNullOrEmpty()]\r\n        [string]$name\r\n    )\r\n\r\n    $aliases = get_config ALIAS ([PSCustomObject]@{})\r\n    if (!$aliases.$name) {\r\n        abort \"Alias '$name' doesn't exist.\"\r\n    }\r\n\r\n    info \"Removing alias '$name'...\"\r\n    if (Test-Path \"$(shimdir $false)\\scoop-$name.ps1\") {\r\n        Remove-Item \"$(shimdir $false)\\scoop-$name.ps1\"\r\n    }\r\n    $aliases.PSObject.Properties.Remove($name)\r\n    set_config ALIAS $aliases | Out-Null\r\n}\r\n\r\nfunction list_aliases {\r\n    param(\r\n        [bool]$verbose\r\n    )\r\n\r\n    $aliases = get_config ALIAS ([PSCustomObject]@{})\r\n    $alias_info = $aliases.PSObject.Properties.Name | Where-Object { $_ } | ForEach-Object {\r\n        # Mark the alias as <BROKEN>, if the alias script file does NOT exist.\r\n        if (!(Test-Path \"$(shimdir $false)\\scoop-$_.ps1\")) {\r\n            [PSCustomObject]@{\r\n                Name    = $_\r\n                Command = '<BROKEN>'\r\n            }\r\n            return\r\n        }\r\n        $content = Get-Content (command_path $_)\r\n        [PSCustomObject]@{\r\n            Name    = $_\r\n            Command = ($content | Select-Object -Skip 1).Trim()\r\n            Summary = (summary $content).Trim()\r\n        }\r\n    }\r\n    if (!$alias_info) {\r\n        info 'No alias found.'\r\n        return\r\n    }\r\n    $alias_info = $alias_info | Sort-Object Name\r\n    $properties = @('Name', 'Command')\r\n    if ($verbose) {\r\n        $properties += 'Summary'\r\n    }\r\n    $alias_info | Select-Object $properties\r\n}\r\n"
  },
  {
    "path": "lib/core.ps1",
    "content": "function Get-PESubsystem($filePath) {\r\n    try {\r\n        $fileStream = [System.IO.FileStream]::new($filePath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)\r\n        $binaryReader = [System.IO.BinaryReader]::new($fileStream)\r\n\r\n        $fileStream.Seek(0x3C, [System.IO.SeekOrigin]::Begin) | Out-Null\r\n        $peOffset = $binaryReader.ReadInt32()\r\n\r\n        $fileStream.Seek($peOffset, [System.IO.SeekOrigin]::Begin) | Out-Null\r\n        $fileHeaderOffset = $fileStream.Position\r\n\r\n        $fileStream.Seek(18, [System.IO.SeekOrigin]::Current) | Out-Null\r\n        $fileStream.Seek($fileHeaderOffset + 0x5C, [System.IO.SeekOrigin]::Begin) | Out-Null\r\n\r\n        return $binaryReader.ReadInt16()\r\n    } catch {\r\n        return -1\r\n    } finally {\r\n        $binaryReader.Close()\r\n        $fileStream.Close()\r\n    }\r\n}\r\n\r\nfunction Set-PESubsystem($filePath, $targetSubsystem) {\r\n    try {\r\n        $fileStream = [System.IO.FileStream]::new($filePath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite)\r\n        $binaryReader = [System.IO.BinaryReader]::new($fileStream)\r\n        $binaryWriter = [System.IO.BinaryWriter]::new($fileStream)\r\n\r\n        $fileStream.Seek(0x3C, [System.IO.SeekOrigin]::Begin) | Out-Null\r\n        $peOffset = $binaryReader.ReadInt32()\r\n\r\n        $fileStream.Seek($peOffset, [System.IO.SeekOrigin]::Begin) | Out-Null\r\n        $fileHeaderOffset = $fileStream.Position\r\n\r\n        $fileStream.Seek(18, [System.IO.SeekOrigin]::Current) | Out-Null\r\n        $fileStream.Seek($fileHeaderOffset + 0x5C, [System.IO.SeekOrigin]::Begin) | Out-Null\r\n\r\n        $binaryWriter.Write([System.Int16] $targetSubsystem)\r\n    } catch {\r\n        return $false\r\n    } finally {\r\n        $binaryReader.Close()\r\n        $fileStream.Close()\r\n    }\r\n    return $true\r\n}\r\n\r\nfunction Optimize-SecurityProtocol {\r\n    # .NET Framework 4.7+ has a default security protocol called 'SystemDefault',\r\n    # which allows the operating system to choose the best protocol to use.\r\n    # If SecurityProtocolType contains 'SystemDefault' (means .NET4.7+ detected)\r\n    # and the value of SecurityProtocol is 'SystemDefault', just do nothing on SecurityProtocol,\r\n    # 'SystemDefault' will use TLS 1.2 if the webrequest requires.\r\n    $isNewerNetFramework = ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -contains 'SystemDefault')\r\n    $isSystemDefault = ([System.Net.ServicePointManager]::SecurityProtocol.Equals([System.Net.SecurityProtocolType]::SystemDefault))\r\n\r\n    # If not, change it to support TLS 1.2\r\n    if (!($isNewerNetFramework -and $isSystemDefault)) {\r\n        # Set to TLS 1.2 (3072). Ssl3, TLS 1.0, and 1.1 have been deprecated,\r\n        # https://datatracker.ietf.org/doc/html/rfc8996\r\n        [System.Net.ServicePointManager]::SecurityProtocol = 3072\r\n    }\r\n}\r\n\r\nfunction Show-DeprecatedWarning {\r\n    <#\r\n    .SYNOPSIS\r\n        Print deprecated warning for functions, which will be deleted in near future.\r\n    .PARAMETER Invocation\r\n        Invocation to identify location of line.\r\n        Just pass $MyInvocation.\r\n    .PARAMETER New\r\n        New command name.\r\n    #>\r\n    param($Invocation, [String] $New)\r\n\r\n    warn ('\"{0}\" will be deprecated. Please change your code/manifest to use \"{1}\"' -f $Invocation.MyCommand.Name, $New)\r\n    Write-Host \"      -> $($Invocation.PSCommandPath):$($Invocation.ScriptLineNumber):$($Invocation.OffsetInLine)\" -ForegroundColor DarkGray\r\n}\r\n\r\nfunction load_cfg($file) {\r\n    if(!(Test-Path $file)) {\r\n        return $null\r\n    }\r\n\r\n    try {\r\n        # ReadAllLines will detect the encoding of the file automatically\r\n        # Ref: https://docs.microsoft.com/en-us/dotnet/api/system.io.file.readalllines?view=netframework-4.5\r\n        $content = [System.IO.File]::ReadAllLines($file)\r\n        return ($content | ConvertFrom-Json -ErrorAction Stop)\r\n    } catch {\r\n        Write-Host \"ERROR loading $file`: $($_.exception.message)\"\r\n    }\r\n}\r\n\r\nfunction get_config($name, $default) {\r\n    $name = $name.ToLowerInvariant()\r\n    if($null -eq $scoopConfig.$name -and $null -ne $default) {\r\n        return $default\r\n    }\r\n    return $scoopConfig.$name\r\n}\r\n\r\nfunction set_config {\r\n    Param (\r\n        [ValidateNotNullOrEmpty()]\r\n        $name,\r\n        $value\r\n    )\r\n\r\n    $name = $name.ToLowerInvariant()\r\n\r\n    if ($null -eq $scoopConfig -or $scoopConfig.Count -eq 0) {\r\n        ensure (Split-Path -Path $configFile) | Out-Null\r\n        $scoopConfig = New-Object -TypeName PSObject\r\n    }\r\n\r\n    if ($value -eq [bool]::TrueString -or $value -eq [bool]::FalseString) {\r\n        $value = [System.Convert]::ToBoolean($value)\r\n    }\r\n\r\n    # Initialize config's change\r\n    Complete-ConfigChange -Name $name -Value $value\r\n\r\n    if ($null -eq $scoopConfig.$name) {\r\n        $scoopConfig | Add-Member -MemberType NoteProperty -Name $name -Value $value\r\n    } else {\r\n        $scoopConfig.$name = $value\r\n    }\r\n\r\n    if ($null -eq $value) {\r\n        $scoopConfig.PSObject.Properties.Remove($name)\r\n    }\r\n\r\n    # Save config with UTF8NoBOM encoding\r\n    ConvertTo-Json $scoopConfig | Out-UTF8File -FilePath $configFile\r\n    return $scoopConfig\r\n}\r\n\r\nfunction Complete-ConfigChange {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory, Position = 0)]\r\n        [string]\r\n        $Name,\r\n        [Parameter(Mandatory, Position = 1)]\r\n        [AllowEmptyString()]\r\n        [string]\r\n        $Value\r\n    )\r\n\r\n    if ($Name -eq 'use_isolated_path') {\r\n        $oldValue = get_config USE_ISOLATED_PATH\r\n        if ($Value -eq $oldValue) {\r\n            return\r\n        } else {\r\n            $currPathEnvVar = $scoopPathEnvVar\r\n        }\r\n        . \"$PSScriptRoot\\..\\lib\\system.ps1\"\r\n\r\n        if ($Value -eq $false -or $Value -eq '') {\r\n            info 'Turn off Scoop isolated path... This may take a while, please wait.'\r\n            $movedPath = Get-EnvVar -Name $currPathEnvVar\r\n            if ($movedPath) {\r\n                Add-Path -Path $movedPath -Quiet\r\n                Remove-Path -Path ('%' + $currPathEnvVar + '%') -Quiet\r\n                Set-EnvVar -Name $currPathEnvVar -Quiet\r\n            }\r\n            if (is_admin) {\r\n                $movedPath = Get-EnvVar -Name $currPathEnvVar -Global\r\n                if ($movedPath) {\r\n                    Add-Path -Path $movedPath -Global -Quiet\r\n                    Remove-Path -Path ('%' + $currPathEnvVar + '%') -Global -Quiet\r\n                    Set-EnvVar -Name $currPathEnvVar -Global -Quiet\r\n                }\r\n            }\r\n        } else {\r\n            $newPathEnvVar = if ($Value -eq $true) {\r\n                'SCOOP_PATH'\r\n            } else {\r\n                $Value.ToUpperInvariant()\r\n            }\r\n            info \"Turn on Scoop isolated path ('$newPathEnvVar')... This may take a while, please wait.\"\r\n            $movedPath = Remove-Path -Path \"$scoopdir\\apps\\*\" -TargetEnvVar $currPathEnvVar -Quiet -PassThru\r\n            if ($movedPath) {\r\n                Add-Path -Path $movedPath -TargetEnvVar $newPathEnvVar -Quiet\r\n                Add-Path -Path ('%' + $newPathEnvVar + '%') -Quiet\r\n                if ($currPathEnvVar -ne 'PATH') {\r\n                    Remove-Path -Path ('%' + $currPathEnvVar + '%') -Quiet\r\n                    Set-EnvVar -Name $currPathEnvVar -Quiet\r\n                }\r\n            }\r\n            if (is_admin) {\r\n                $movedPath = Remove-Path -Path \"$globaldir\\apps\\*\" -TargetEnvVar $currPathEnvVar -Global -Quiet -PassThru\r\n                if ($movedPath) {\r\n                    Add-Path -Path $movedPath -TargetEnvVar $newPathEnvVar -Global -Quiet\r\n                    Add-Path -Path ('%' + $newPathEnvVar + '%') -Global -Quiet\r\n                    if ($currPathEnvVar -ne 'PATH') {\r\n                        Remove-Path -Path ('%' + $currPathEnvVar + '%') -Global -Quiet\r\n                        Set-EnvVar -Name $currPathEnvVar -Global -Quiet\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    if ($Name -eq 'use_sqlite_cache' -and $Value -eq $true) {\r\n        if ((Get-DefaultArchitecture) -eq 'arm64') {\r\n            abort 'SQLite cache is not supported on ARM64 platform.'\r\n        }\r\n        . \"$PSScriptRoot\\..\\lib\\database.ps1\"\r\n        . \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n        info 'Initializing SQLite cache in progress... This may take a while, please wait.'\r\n        Set-ScoopDB\r\n    }\r\n}\r\n\r\nfunction Invoke-Git {\r\n    [CmdletBinding()]\r\n    [OutputType([String])]\r\n    param(\r\n        [Parameter(Mandatory = $false, Position = 0)]\r\n        [Alias('PSPath', 'Path')]\r\n        [ValidateNotNullOrEmpty()]\r\n        [String]\r\n        $WorkingDirectory,\r\n        [Parameter(Mandatory = $true, Position = 1)]\r\n        [Alias('Args')]\r\n        [String[]]\r\n        $ArgumentList\r\n    )\r\n\r\n    $proxy = get_config PROXY\r\n    $git = Get-HelperPath -Helper Git\r\n\r\n    if ($WorkingDirectory) {\r\n        $ArgumentList = @('-C', $WorkingDirectory) + $ArgumentList\r\n    }\r\n\r\n    if([String]::IsNullOrEmpty($proxy) -or $proxy -eq 'none')  {\r\n        return & $git @ArgumentList\r\n    }\r\n\r\n    if($ArgumentList -Match '\\b(clone|checkout|pull|fetch|ls-remote)\\b') {\r\n        $j = Start-Job -ScriptBlock {\r\n            # convert proxy setting for git\r\n            $proxy = $using:proxy\r\n            if ($proxy -and $proxy.StartsWith('currentuser@')) {\r\n                $proxy = $proxy.Replace('currentuser@', ':@')\r\n            }\r\n            $env:HTTPS_PROXY = $proxy\r\n            $env:HTTP_PROXY = $proxy\r\n            & $using:git @using:ArgumentList\r\n        }\r\n        $o = $j | Receive-Job -Wait -AutoRemoveJob\r\n        return $o\r\n    }\r\n\r\n    return & $git @ArgumentList\r\n}\r\n\r\nfunction Invoke-GitLog {\r\n    [CmdletBinding()]\r\n    Param (\r\n        [Parameter(Mandatory, ValueFromPipeline)]\r\n        [String]$Path,\r\n        [Parameter(Mandatory, ValueFromPipeline)]\r\n        [String]$CommitHash,\r\n        [String]$Name = ''\r\n    )\r\n    Process {\r\n        if ($Name) {\r\n            if ($Name.Length -gt 12) {\r\n                $Name = \"$($Name.Substring(0, 10))..\"\r\n            }\r\n            $Name = \"%Cgreen$($Name.PadRight(12, ' ').Substring(0, 12))%Creset \"\r\n        }\r\n        Invoke-Git -Path $Path -ArgumentList @('--no-pager', 'log', '--color', '--no-decorate', \"--grep='^(chore)'\", '--invert-grep', '--abbrev=12', \"--format=tformat: * %C(yellow)%h%Creset %<|(72,trunc)%s $Name%C(cyan)%cr%Creset\", \"$CommitHash..HEAD\")\r\n    }\r\n}\r\n\r\n# helper functions\r\nfunction coalesce($a, $b) { if($a) { return $a } $b }\r\n\r\nfunction is_admin {\r\n    $admin = [security.principal.windowsbuiltinrole]::administrator\r\n    $id = [security.principal.windowsidentity]::getcurrent()\r\n    ([security.principal.windowsprincipal]($id)).isinrole($admin)\r\n}\r\n\r\n# messages\r\nfunction abort($msg, [int] $exit_code=1) { write-host $msg -f red; exit $exit_code }\r\nfunction error($msg) { write-host \"ERROR $msg\" -f darkred }\r\nfunction warn($msg) {  write-host \"WARN  $msg\" -f darkyellow }\r\nfunction info($msg) {  write-host \"INFO  $msg\" -f darkgray }\r\nfunction debug($obj) {\r\n    if ((get_config DEBUG $false) -ine 'true' -and $env:SCOOP_DEBUG -ine 'true') {\r\n        return\r\n    }\r\n\r\n    $prefix = \"DEBUG[$(Get-Date -UFormat %s)]\"\r\n    $param = $MyInvocation.Line.Replace($MyInvocation.InvocationName, '').Trim()\r\n    $msg = $obj | Out-String -Stream\r\n\r\n    if($null -eq $obj -or $null -eq $msg) {\r\n        Write-Host \"$prefix $param = \" -f DarkCyan -NoNewline\r\n        Write-Host '$null' -f DarkYellow -NoNewline\r\n        Write-Host \" -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)\" -f DarkGray\r\n        return\r\n    }\r\n\r\n    if($msg.GetType() -eq [System.Object[]]) {\r\n        Write-Host \"$prefix $param ($($obj.GetType()))\" -f DarkCyan -NoNewline\r\n        Write-Host \" -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)\" -f DarkGray\r\n        $msg | Where-Object { ![String]::IsNullOrWhiteSpace($_) } |\r\n            Select-Object -Skip 2 | # Skip headers\r\n            ForEach-Object {\r\n                Write-Host \"$prefix $param.$($_)\" -f DarkCyan\r\n            }\r\n    } else {\r\n        Write-Host \"$prefix $param = $($msg.Trim())\" -f DarkCyan -NoNewline\r\n        Write-Host \" -> $($MyInvocation.PSCommandPath):$($MyInvocation.ScriptLineNumber):$($MyInvocation.OffsetInLine)\" -f DarkGray\r\n    }\r\n}\r\nfunction success($msg) { write-host $msg -f darkgreen }\r\n\r\nfunction filesize($length) {\r\n    $gb = [math]::pow(2, 30)\r\n    $mb = [math]::pow(2, 20)\r\n    $kb = [math]::pow(2, 10)\r\n\r\n    if($length -gt $gb) {\r\n        \"{0:n1} GB\" -f ($length / $gb)\r\n    } elseif($length -gt $mb) {\r\n        \"{0:n1} MB\" -f ($length / $mb)\r\n    } elseif($length -gt $kb) {\r\n        \"{0:n1} KB\" -f ($length / $kb)\r\n    } else {\r\n        if ($null -eq $length) {\r\n            $length = 0\r\n        }\r\n        \"$($length) B\"\r\n    }\r\n}\r\n\r\n# dirs\r\nfunction basedir($global) { if($global) { return $globaldir } $scoopdir }\r\nfunction appsdir($global) { \"$(basedir $global)\\apps\" }\r\nfunction shimdir($global) { \"$(basedir $global)\\shims\" }\r\nfunction modulesdir($global) { \"$(basedir $global)\\modules\" }\r\nfunction appdir($app, $global) { \"$(appsdir $global)\\$app\" }\r\nfunction versiondir($app, $version, $global) { \"$(appdir $app $global)\\$version\" }\r\n\r\nfunction currentdir($app, $global) {\r\n    if (get_config NO_JUNCTION) {\r\n        $version = Select-CurrentVersion -App $app -Global:$global\r\n    } else {\r\n        $version = 'current'\r\n    }\r\n    \"$(appdir $app $global)\\$version\"\r\n}\r\n\r\nfunction persistdir($app, $global) { \"$(basedir $global)\\persist\\$app\" }\r\nfunction usermanifestsdir { \"$(basedir)\\workspace\" }\r\nfunction usermanifest($app) { \"$(usermanifestsdir)\\$app.json\" }\r\nfunction cache_path($app, $version, $url) {\r\n    $underscoredUrl = $url -replace '[^\\w\\.\\-]+', '_'\r\n    $filePath = Join-Path $cachedir \"$app#$version#$underscoredUrl\"\r\n\r\n    # NOTE: Scoop cache files migration. Remove this 6 months after the feature ships.\r\n    if (Test-Path $filePath) {\r\n        return $filePath\r\n    }\r\n\r\n    $urlStream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($url))\r\n    $sha = (Get-FileHash -Algorithm SHA256 -InputStream $urlStream).Hash.ToLower().Substring(0, 7)\r\n    $extension = [System.IO.Path]::GetExtension($url)\r\n    $filePath = $filePath -replace \"$underscoredUrl\", \"$sha$extension\"\r\n\r\n    return $filePath\r\n}\r\n\r\n# apps\r\nfunction sanitary_path($path) { return [regex]::replace($path, \"[/\\\\?:*<>|]\", \"\") }\r\nfunction installed($app, [Nullable[bool]]$global) {\r\n    if ($null -eq $global) {\r\n        return (installed $app $false) -or (installed $app $true)\r\n    }\r\n    # Dependencies of the format \"bucket/dependency\" install in a directory of form\r\n    # \"dependency\". So we need to extract the bucket from the name and only give the app\r\n    # name to is_directory\r\n    $app = ($app -split '/|\\\\')[-1]\r\n    return $null -ne (Select-CurrentVersion -AppName $app -Global:$global)\r\n}\r\nfunction installed_apps($global) {\r\n    $dir = appsdir $global\r\n    if (Test-Path $dir) {\r\n        Get-ChildItem $dir | Where-Object { $_.psiscontainer -and $_.name -ne 'scoop' } | ForEach-Object { $_.name }\r\n    }\r\n}\r\n\r\n# check whether the app failed to install\r\nfunction failed($app, $global) {\r\n    $app = ($app -split '/|\\\\')[-1]\r\n    $appPath = appdir $app $global\r\n    $hasCurrent = (get_config NO_JUNCTION) -or (Test-Path \"$appPath\\current\")\r\n    return (Test-Path $appPath) -and !($hasCurrent -and (installed $app $global))\r\n}\r\n\r\nfunction file_path($app, $file) {\r\n    Show-DeprecatedWarning $MyInvocation 'Get-AppFilePath'\r\n    Get-AppFilePath -App $app -File $file\r\n}\r\n\r\nfunction Get-AppFilePath {\r\n    [CmdletBinding()]\r\n    [OutputType([String])]\r\n    param(\r\n        [Parameter(Mandatory = $true, Position = 0)]\r\n        [String]\r\n        $App,\r\n        [Parameter(Mandatory = $true, Position = 1)]\r\n        [String]\r\n        $File\r\n    )\r\n\r\n    # normal path to file\r\n    $Path = \"$(currentdir $App $false)\\$File\"\r\n    if (Test-Path $Path) {\r\n        return $Path\r\n    }\r\n\r\n    # global path to file\r\n    $Path = \"$(currentdir $App $true)\\$File\"\r\n    if (Test-Path $Path) {\r\n        return $Path\r\n    }\r\n\r\n    # not found\r\n    return $null\r\n}\r\n\r\nFunction Test-CommandAvailable {\r\n    param (\r\n        [String]$Name\r\n    )\r\n    Return [Boolean](Get-Command $Name -ErrorAction Ignore)\r\n}\r\n\r\nFunction Test-GitAvailable {\r\n    return [Boolean](Get-HelperPath -Helper Git)\r\n}\r\n\r\nfunction Get-HelperPath {\r\n    [CmdletBinding()]\r\n    [OutputType([String])]\r\n    param(\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [ValidateSet('Git', '7zip', 'Lessmsi', 'Innounp', 'Dark', 'Aria2')]\r\n        [String]\r\n        $Helper\r\n    )\r\n    begin {\r\n        $HelperPath = $null\r\n    }\r\n    process {\r\n        switch ($Helper) {\r\n            'Git' {\r\n                $internalgit = (Get-AppFilePath 'git' 'mingw64\\bin\\git.exe'), (Get-AppFilePath 'git' 'mingw32\\bin\\git.exe') | Where-Object { $_ -ne $null }\r\n                if ($internalgit) {\r\n                    $HelperPath = $internalgit\r\n                } else {\r\n                    $HelperPath = (Get-Command git -CommandType Application -TotalCount 1 -ErrorAction Ignore).Source\r\n                }\r\n            }\r\n            '7zip' { $HelperPath = Get-AppFilePath '7zip' '7z.exe' }\r\n            'Lessmsi' { $HelperPath = Get-AppFilePath 'lessmsi' 'lessmsi.exe' }\r\n            'Innounp' {\r\n                $HelperPath = Get-AppFilePath 'innounp-unicode' 'innounp.exe'\r\n                if ([String]::IsNullOrEmpty($HelperPath)) {\r\n                    $HelperPath = Get-AppFilePath 'innounp' 'innounp.exe'\r\n                }\r\n            }\r\n            'Dark' {\r\n                $HelperPath = Get-AppFilePath 'wixtoolset' 'wix.exe'\r\n                if ([String]::IsNullOrEmpty($HelperPath)) {\r\n                    $HelperPath = Get-AppFilePath 'dark' 'dark.exe'\r\n                }\r\n            }\r\n            'Aria2' { $HelperPath = Get-AppFilePath 'aria2' 'aria2c.exe' }\r\n        }\r\n\r\n        return $HelperPath\r\n    }\r\n}\r\n\r\nfunction Get-CommandPath {\r\n    [CmdletBinding()]\r\n    [OutputType([String])]\r\n    param(\r\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]\r\n        [String]\r\n        $Command\r\n    )\r\n\r\n    begin {\r\n        $userShims = shimdir $false\r\n        $globalShims = shimdir $true\r\n    }\r\n\r\n    process {\r\n        try {\r\n            $comm = Get-Command $Command -ErrorAction Stop\r\n        } catch {\r\n            return $null\r\n        }\r\n        $commandPath = if ($comm.Path -like \"$userShims\\scoop-*.ps1\") {\r\n            # Scoop aliases\r\n            $comm.Source\r\n        } elseif ($comm.Path -like \"$userShims*\" -or $comm.Path -like \"$globalShims*\") {\r\n            Get-ShimTarget ($comm.Path -replace '\\.exe$', '.shim')\r\n        } elseif ($comm.CommandType -eq 'Application') {\r\n            $comm.Source\r\n        } elseif ($comm.CommandType -eq 'Alias') {\r\n            Get-CommandPath $comm.ResolvedCommandName\r\n        } else {\r\n            $null\r\n        }\r\n        return $commandPath\r\n    }\r\n}\r\n\r\nfunction Test-HelperInstalled {\r\n    [CmdletBinding()]\r\n    param(\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [ValidateSet('7zip', 'Lessmsi', 'Innounp', 'Dark', 'Aria2')]\r\n        [String]\r\n        $Helper\r\n    )\r\n\r\n    return ![String]::IsNullOrWhiteSpace((Get-HelperPath -Helper $Helper))\r\n}\r\n\r\nfunction app_status($app, $global) {\r\n    $status = @{}\r\n    $status.installed = installed $app $global\r\n    $status.version = Select-CurrentVersion -AppName $app -Global:$global\r\n    $status.latest_version = $status.version\r\n\r\n    $install_info = install_info $app $status.version $global\r\n\r\n    $status.failed = failed $app $global\r\n    $status.hold = ($install_info.hold -eq $true)\r\n\r\n    $deprecated_dir = (Find-BucketDirectory -Name $install_info.bucket -Root) + \"\\deprecated\"\r\n    $status.deprecated = (Get-ChildItem $deprecated_dir -Filter \"$(sanitary_path $app).json\" -Recurse).FullName\r\n\r\n    $manifest = manifest $app $install_info.bucket $install_info.url\r\n    $status.removed = (!$manifest)\r\n    if ($manifest.version) {\r\n        $status.latest_version = $manifest.version\r\n    }\r\n\r\n    $status.outdated = $false\r\n    if ($status.version -and $status.latest_version) {\r\n        if (get_config FORCE_UPDATE $false) {\r\n            $status.outdated = ((Compare-Version -ReferenceVersion $status.version -DifferenceVersion $status.latest_version) -ne 0)\r\n        } else {\r\n            $status.outdated = ((Compare-Version -ReferenceVersion $status.version -DifferenceVersion $status.latest_version) -gt 0)\r\n        }\r\n    }\r\n\r\n    $status.missing_deps = @()\r\n    $deps = @($manifest.depends) | Where-Object {\r\n        if ($null -eq $_) {\r\n            return $null\r\n        } else {\r\n            $app, $bucket, $null = parse_app $_\r\n            return !(installed $app)\r\n        }\r\n    }\r\n    if ($deps) {\r\n        $status.missing_deps += , $deps\r\n    }\r\n    return $status\r\n}\r\n\r\nfunction appname_from_url($url) {\r\n    (split-path $url -leaf) -replace '.json$', ''\r\n}\r\n\r\n# paths\r\nfunction fname($path) { split-path $path -leaf }\r\nfunction strip_ext($fname) { $fname -replace '\\.[^\\.]*$', '' }\r\nfunction strip_filename($path) { $path -replace [regex]::escape((fname $path)) }\r\nfunction strip_fragment($url) { $url -replace (new-object uri $url).fragment }\r\nfunction ensure($dir) {\r\n    if (!(Test-Path -Path $dir)) {\r\n        New-Item -Path $dir -ItemType Directory | Out-Null\r\n    }\r\n    Convert-Path -Path $dir\r\n}\r\nfunction Get-AbsolutePath {\r\n    <#\r\n    .SYNOPSIS\r\n        Get absolute path\r\n    .DESCRIPTION\r\n        Get absolute path, even if not existed\r\n    .PARAMETER Path\r\n        Path to manipulate\r\n    .OUTPUTS\r\n        System.String\r\n            Absolute path, may or maynot existed\r\n    #>\r\n    [CmdletBinding()]\r\n    [OutputType([string])]\r\n    param (\r\n        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]\r\n        [string]\r\n        $Path\r\n    )\r\n    process {\r\n        return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)\r\n    }\r\n}\r\n\r\nfunction fullpath($path) {\r\n    Show-DeprecatedWarning $MyInvocation 'Get-AbsolutePath'\r\n    return Get-AbsolutePath -Path $path\r\n}\r\nfunction friendly_path($path) {\r\n    $h = (Get-PSProvider 'FileSystem').Home\r\n    if (!$h.EndsWith('\\')) {\r\n        $h += '\\'\r\n    }\r\n    if ($h -eq '\\') {\r\n        return $path\r\n    } else {\r\n        return $path -replace ([Regex]::Escape($h)), '~\\'\r\n    }\r\n}\r\nfunction is_local($path) {\r\n    ($path -notmatch '^https?://') -and (Test-Path $path)\r\n}\r\n\r\n# operations\r\n\r\nfunction run($exe, $arg, $msg, $continue_exit_codes) {\r\n    Show-DeprecatedWarning $MyInvocation 'Invoke-ExternalCommand'\r\n    Invoke-ExternalCommand -FilePath $exe -ArgumentList $arg -Activity $msg -ContinueExitCodes $continue_exit_codes\r\n}\r\n\r\nfunction Invoke-ExternalCommand {\r\n    [CmdletBinding(DefaultParameterSetName = \"Default\")]\r\n    [OutputType([Boolean])]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0)]\r\n        [Alias(\"Path\")]\r\n        [ValidateNotNullOrEmpty()]\r\n        [String]\r\n        $FilePath,\r\n        [Parameter(Position = 1)]\r\n        [Alias(\"Args\")]\r\n        [String[]]\r\n        $ArgumentList,\r\n        [Parameter(ParameterSetName = \"UseShellExecute\")]\r\n        [Switch]\r\n        $RunAs,\r\n        [Parameter(ParameterSetName = \"UseShellExecute\")]\r\n        [Switch]\r\n        $Quiet,\r\n        [Alias(\"Msg\")]\r\n        [String]\r\n        $Activity,\r\n        [Alias(\"cec\")]\r\n        [Hashtable]\r\n        $ContinueExitCodes,\r\n        [Parameter(ParameterSetName = \"Default\")]\r\n        [Alias(\"Log\")]\r\n        [String]\r\n        $LogPath\r\n    )\r\n    if ($Activity) {\r\n        Write-Host \"$Activity \" -NoNewline\r\n    }\r\n    $Process = New-Object System.Diagnostics.Process\r\n    $Process.StartInfo.FileName = $FilePath\r\n    $Process.StartInfo.UseShellExecute = $false\r\n    if ($LogPath) {\r\n        if ($FilePath -match '^msiexec(.exe)?$') {\r\n            $ArgumentList += \"/lwe `\"$LogPath`\"\"\r\n        } else {\r\n            $redirectToLogFile = $true\r\n            $Process.StartInfo.RedirectStandardOutput = $true\r\n            $Process.StartInfo.RedirectStandardError = $true\r\n        }\r\n    }\r\n    if ($RunAs) {\r\n        $Process.StartInfo.UseShellExecute = $true\r\n        $Process.StartInfo.Verb = 'RunAs'\r\n    }\r\n    if ($Quiet) {\r\n        $Process.StartInfo.UseShellExecute = $true\r\n        $Process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden\r\n    }\r\n    if ($ArgumentList.Length -gt 0) {\r\n        # Remove existing double quotes and split arguments\r\n        # '(?<=(?<![:\\w])[/-]\\w+) ' matches a space after a command line switch starting with a slash ('/') or a hyphen ('-')\r\n        # The inner item '(?<![:\\w])[/-]' matches a slash ('/') or a hyphen ('-') not preceded by a colon (':') or a word character ('\\w')\r\n        # so that it must be a command line switch, otherwise, it would be a path (e.g. 'C:/Program Files') or other word (e.g. 'some-arg')\r\n        # ' (?=[/-])' matches a space followed by a slash ('/') or a hyphen ('-'), i.e. the space before a command line switch\r\n        $ArgumentList = $ArgumentList.ForEach({ $_ -replace '\"' -split '(?<=(?<![:\\w])[/-]\\w+) | (?=[/-])' })\r\n        # Use legacy argument escaping for commands having non-standard behavior with regard to argument passing.\r\n        # `msiexec` requires some args like `TARGETDIR=\"C:\\Program Files\"`, which is non-standard, therefore we treat it as a legacy command.\r\n        # NSIS installer's '/D' param may not work with the ArgumentList property, so we need to escape arguments manually.\r\n        # ref-1: https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.4#psnativecommandargumentpassing\r\n        # ref-2: https://nsis.sourceforge.io/Docs/Chapter3.html\r\n        $LegacyCommand = $FilePath -match '^((cmd|cscript|find|sqlcmd|wscript|msiexec)(\\.exe)?|.*\\.(bat|cmd|js|vbs|wsf))$' -or\r\n            ($ArgumentList -match '^/S$|^/D=[A-Z]:[\\\\/].*$').Length -eq 2\r\n        $SupportArgumentList = $Process.StartInfo.PSObject.Properties.Name -contains 'ArgumentList'\r\n        if ((-not $LegacyCommand) -and $SupportArgumentList) {\r\n            # ArgumentList is supported in PowerShell 6.1 and later (built on .NET Core 2.1+)\r\n            # ref-1: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0\r\n            # ref-2: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.2#net-framework-vs-net-core\r\n            $ArgumentList.ForEach({ $Process.StartInfo.ArgumentList.Add($_) })\r\n        } else {\r\n            # Escape arguments manually in lower versions\r\n            $escapedArgs = switch -regex ($ArgumentList) {\r\n                # Quote paths starting with a drive letter\r\n                '(?<!/D=)[A-Z]:[\\\\/].*' { $_ -replace '([A-Z]:[\\\\/].*)', '\"$1\"'; continue }\r\n                # Do not quote paths if it is NSIS's '/D' argument\r\n                '/D=[A-Z]:[\\\\/].*' { $_; continue }\r\n                # Quote args with spaces\r\n                ' ' { \"`\"$_`\"\"; continue }\r\n                default { $_; continue }\r\n            }\r\n            $Process.StartInfo.Arguments = $escapedArgs -join ' '\r\n        }\r\n    }\r\n    try {\r\n        [void]$Process.Start()\r\n    } catch {\r\n        if ($Activity) {\r\n            Write-Host \"error.\" -ForegroundColor DarkRed\r\n        }\r\n        error $_.Exception.Message\r\n        return $false\r\n    }\r\n    if ($redirectToLogFile) {\r\n        # we do this to remove a deadlock potential\r\n        # ref: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?view=netframework-4.5#remarks\r\n        $stdoutTask = $Process.StandardOutput.ReadToEndAsync()\r\n        $stderrTask = $Process.StandardError.ReadToEndAsync()\r\n    }\r\n    $Process.WaitForExit()\r\n    if ($redirectToLogFile) {\r\n        Out-UTF8File -FilePath $LogPath -Append -InputObject $stdoutTask.Result\r\n        Out-UTF8File -FilePath $LogPath -Append -InputObject $stderrTask.Result\r\n    }\r\n    if ($Process.ExitCode -ne 0) {\r\n        if ($ContinueExitCodes -and ($ContinueExitCodes.ContainsKey($Process.ExitCode))) {\r\n            if ($Activity) {\r\n                Write-Host \"done.\" -ForegroundColor DarkYellow\r\n            }\r\n            warn $ContinueExitCodes[$Process.ExitCode]\r\n            return $true\r\n        } else {\r\n            if ($Activity) {\r\n                Write-Host \"error.\" -ForegroundColor DarkRed\r\n            }\r\n            error \"Exit code was $($Process.ExitCode)!\"\r\n            return $false\r\n        }\r\n    }\r\n    if ($Activity) {\r\n        Write-Host \"done.\" -ForegroundColor Green\r\n    }\r\n    return $true\r\n}\r\n\r\nfunction isFileLocked([string]$path) {\r\n    $file = New-Object System.IO.FileInfo $path\r\n\r\n    if ((Test-Path -Path $path) -eq $false) {\r\n        return $false\r\n    }\r\n\r\n    try {\r\n        $stream = $file.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)\r\n        if ($stream) {\r\n            $stream.Close()\r\n        }\r\n        return $false\r\n    }\r\n    catch {\r\n        # file is locked by a process.\r\n        return $true\r\n    }\r\n}\r\n\r\nfunction is_directory([String] $path) {\r\n    return (Test-Path $path) -and (Get-Item $path) -is [System.IO.DirectoryInfo]\r\n}\r\n\r\nfunction movedir($from, $to) {\r\n    $from = $from.trimend('\\')\r\n    $to = $to.trimend('\\')\r\n\r\n    $proc = New-Object System.Diagnostics.Process\r\n    $proc.StartInfo.FileName = 'robocopy.exe'\r\n    $proc.StartInfo.Arguments = \"`\"$from`\" `\"$to`\" /e /move\"\r\n    $proc.StartInfo.RedirectStandardOutput = $true\r\n    $proc.StartInfo.RedirectStandardError = $true\r\n    $proc.StartInfo.UseShellExecute = $false\r\n    $proc.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden\r\n    [void]$proc.Start()\r\n    $stdoutTask = $proc.StandardOutput.ReadToEndAsync()\r\n    $proc.WaitForExit()\r\n\r\n    if($proc.ExitCode -ge 8) {\r\n        debug $stdoutTask.Result\r\n        throw \"Could not find '$(fname $from)'! (error $($proc.ExitCode))\"\r\n    }\r\n\r\n    # wait for robocopy to terminate its threads\r\n    1..10 | ForEach-Object {\r\n        if (Test-Path $from) {\r\n            Start-Sleep -Milliseconds 100\r\n        }\r\n    }\r\n}\r\n\r\nfunction get_app_name($path) {\r\n    if ((Test-Path (appsdir $false)) -and ($path -match \"$([Regex]::Escape($(Convert-Path (appsdir $false))))[/\\\\]([^/\\\\]+)\")) {\r\n        $appName = $Matches[1].ToLower()\r\n    } elseif ((Test-Path (appsdir $true)) -and ($path -match \"$([Regex]::Escape($(Convert-Path (appsdir $true))))[/\\\\]([^/\\\\]+)\")) {\r\n        $appName = $Matches[1].ToLower()\r\n    } else {\r\n        $appName = ''\r\n    }\r\n    return $appName\r\n}\r\n\r\nfunction get_app_name_from_shim($shim) {\r\n    if (!(Test-Path($shim))) {\r\n        return ''\r\n    }\r\n    $content = (Get-Content $shim -Encoding UTF8) -join ' '\r\n    return get_app_name $content\r\n}\r\n\r\nfunction Get-ShimTarget($ShimPath) {\r\n    if ($ShimPath) {\r\n        $shimTarget = if ($ShimPath.EndsWith('.shim')) {\r\n            (Get-Content -Path $ShimPath | Select-Object -First 1).Replace('path = ', '').Replace('\"', '')\r\n        } else {\r\n            ((Select-String -Path $ShimPath -Pattern '^(?:@rem|#)\\s*(.*)$').Matches.Groups | Select-Object -Index 1).Value\r\n        }\r\n        if (!$shimTarget) {\r\n            $shimTarget = ((Select-String -Path $ShimPath -Pattern '[''\"]([^@&]*?)[''\"]' -AllMatches).Matches.Groups | Select-Object -Last 1).Value\r\n        }\r\n        $shimTarget | Convert-Path -ErrorAction SilentlyContinue\r\n    }\r\n}\r\n\r\nfunction warn_on_overwrite($shim, $path) {\r\n    if (!(Test-Path $shim)) {\r\n        return\r\n    }\r\n    $shim_app = get_app_name_from_shim $shim\r\n    $path_app = get_app_name $path\r\n    if ($shim_app -eq $path_app) {\r\n        return\r\n    } else {\r\n        if (Test-Path -Path \"$shim.$path_app\" -PathType Leaf) {\r\n            Remove-Item -Path \"$shim.$path_app\" -Force -ErrorAction SilentlyContinue\r\n        }\r\n        Rename-Item -Path $shim -NewName \"$shim.$shim_app\" -ErrorAction SilentlyContinue\r\n    }\r\n    $shimname = (fname $shim) -replace '\\.shim$', '.exe'\r\n    $filename = (fname $path) -replace '\\.shim$', '.exe'\r\n    warn \"Overwriting shim ('$shimname' -> '$filename')$(if ($shim_app) { ' installed from ' + $shim_app })\"\r\n}\r\n\r\nfunction shim($path, $global, $name, $arg) {\r\n    if (!(Test-Path $path)) { abort \"Can't shim '$(fname $path)': couldn't find '$path'.\" }\r\n    $abs_shimdir = ensure (shimdir $global)\r\n    Add-Path -Path $abs_shimdir -Global:$global\r\n    if (!$name) { $name = strip_ext (fname $path) }\r\n\r\n    $shim = \"$abs_shimdir\\$($name.tolower())\"\r\n\r\n    # convert to relative path\r\n    $resolved_path = Convert-Path $path\r\n    Push-Location $abs_shimdir\r\n    $relative_path = Resolve-Path -Relative $resolved_path\r\n    Pop-Location\r\n\r\n    if ($path -match '\\.(exe|com)$') {\r\n        # for programs with no awareness of any shell\r\n        warn_on_overwrite \"$shim.shim\" $path\r\n        Copy-Item (get_shim_path) \"$shim.exe\" -Force\r\n        Write-Output \"path = `\"$resolved_path`\"\" | Out-UTF8File \"$shim.shim\"\r\n        if ($arg) {\r\n            Write-Output \"args = $arg\" | Out-UTF8File \"$shim.shim\" -Append\r\n        }\r\n\r\n        $target_subsystem = Get-PESubsystem $resolved_path\r\n        if ($target_subsystem -eq 2) { # we only want to make shims GUI\r\n            Write-Output \"Making $shim.exe a GUI binary.\"\r\n            Set-PESubsystem \"$shim.exe\" $target_subsystem | Out-Null\r\n        }\r\n    } elseif ($path -match '\\.(bat|cmd)$') {\r\n        # shim .bat, .cmd so they can be used by programs with no awareness of PSH\r\n        warn_on_overwrite \"$shim.cmd\" $path\r\n        @(\r\n            \"@rem $resolved_path\",\r\n            \"@`\"$resolved_path`\" $arg %*\"\r\n        ) -join \"`r`n\" | Out-UTF8File \"$shim.cmd\"\r\n\r\n        warn_on_overwrite $shim $path\r\n        @(\r\n            \"#!/bin/sh\",\r\n            \"# $resolved_path\",\r\n            \"MSYS2_ARG_CONV_EXCL=/C cmd.exe /C `\"$resolved_path`\" $arg `\"$@`\"\"\r\n        ) -join \"`n\" | Out-UTF8File $shim -NoNewLine\r\n    } elseif ($path -match '\\.ps1$') {\r\n        # if $path points to another drive resolve-path prepends .\\ which could break shims\r\n        warn_on_overwrite \"$shim.ps1\" $path\r\n        $ps1text = if ($relative_path -match '^(\\.\\\\)?\\w:.*$') {\r\n            @(\r\n                \"# $resolved_path\",\r\n                \"`$path = `\"$path`\"\",\r\n                \"if (`$MyInvocation.ExpectingInput) { `$input | & `$path $arg @args } else { & `$path $arg @args }\",\r\n                \"exit `$LASTEXITCODE\"\r\n            )\r\n        } else {\r\n            @(\r\n                \"# $resolved_path\",\r\n                \"`$path = Join-Path `$PSScriptRoot `\"$relative_path`\"\",\r\n                \"if (`$MyInvocation.ExpectingInput) { `$input | & `$path $arg @args } else { & `$path $arg @args }\",\r\n                \"exit `$LASTEXITCODE\"\r\n            )\r\n        }\r\n        $ps1text -join \"`r`n\" | Out-UTF8File \"$shim.ps1\"\r\n\r\n        # make ps1 accessible from cmd.exe\r\n        warn_on_overwrite \"$shim.cmd\" $path\r\n        @(\r\n            \"@rem $resolved_path\",\r\n            \"@echo off\",\r\n            \"where /q pwsh.exe\",\r\n            \"if %errorlevel% equ 0 (\",\r\n            \"    pwsh -noprofile -ex unrestricted -file `\"$resolved_path`\" $arg %*\",\r\n            \") else (\",\r\n            \"    powershell -noprofile -ex unrestricted -file `\"$resolved_path`\" $arg %*\",\r\n            \")\"\r\n        ) -join \"`r`n\" | Out-UTF8File \"$shim.cmd\"\r\n\r\n        warn_on_overwrite $shim $path\r\n        @(\r\n            \"#!/bin/sh\",\r\n            \"# $resolved_path\",\r\n            \"if command -v pwsh.exe > /dev/null 2>&1; then\",\r\n            \"    pwsh.exe -noprofile -ex unrestricted -file `\"$resolved_path`\" $arg `\"$@`\"\",\r\n            \"else\",\r\n            \"    powershell.exe -noprofile -ex unrestricted -file `\"$resolved_path`\" $arg `\"$@`\"\",\r\n            \"fi\"\r\n        ) -join \"`n\" | Out-UTF8File $shim -NoNewLine\r\n    } elseif ($path -match '\\.jar$') {\r\n        warn_on_overwrite \"$shim.cmd\" $path\r\n        @(\r\n            \"@rem $resolved_path\",\r\n            \"@pushd $(Split-Path $resolved_path -Parent)\",\r\n            \"@java -jar `\"$resolved_path`\" $arg %*\",\r\n            \"@popd\"\r\n        ) -join \"`r`n\" | Out-UTF8File \"$shim.cmd\"\r\n\r\n        warn_on_overwrite $shim $path\r\n        @(\r\n            \"#!/bin/sh\",\r\n            \"# $resolved_path\",\r\n            \"if [ `$WSL_INTEROP ]\",\r\n            'then',\r\n            \"  cd `$(wslpath -u '$(Split-Path $resolved_path -Parent)')\",\r\n            'else',\r\n            \"  cd `$(cygpath -u '$(Split-Path $resolved_path -Parent)')\",\r\n            'fi',\r\n            \"java.exe -jar `\"$resolved_path`\" $arg `\"$@`\"\"\r\n        ) -join \"`n\" | Out-UTF8File $shim -NoNewLine\r\n    } elseif ($path -match '\\.py$') {\r\n        warn_on_overwrite \"$shim.cmd\" $path\r\n        @(\r\n            \"@rem $resolved_path\",\r\n            \"@python `\"$resolved_path`\" $arg %*\"\r\n        ) -join \"`r`n\" | Out-UTF8File \"$shim.cmd\"\r\n\r\n        warn_on_overwrite $shim $path\r\n        @(\r\n            '#!/bin/sh',\r\n            \"# $resolved_path\",\r\n            \"python.exe `\"$resolved_path`\" $arg `\"$@`\"\"\r\n        ) -join \"`n\" | Out-UTF8File $shim -NoNewLine\r\n    } else {\r\n        warn_on_overwrite \"$shim.cmd\" $path\r\n        $quoted_arg = if ($arg.Count -gt 0) { $arg | ForEach-Object { \"`\"$_`\"\" } }\r\n        @(\r\n            \"@rem $resolved_path\",\r\n            '@echo off',\r\n            'bash -c \"command -v wslpath >/dev/null\"',\r\n            'if %errorlevel% equ 0 (',\r\n            \"  bash `\"`$(wslpath -u '$resolved_path')`\" $quoted_arg %*\",\r\n            ') else (',\r\n            \"  set args=$quoted_arg %*\",\r\n            '  setlocal enabledelayedexpansion',\r\n            '  if not \"!args!\"==\"\" set args=!args:\"=\"\"!',\r\n            \"  bash -c `\"`$(cygpath -u '$resolved_path') !args!`\"\",\r\n            ')'\r\n        ) -join \"`r`n\" | Out-UTF8File \"$shim.cmd\"\r\n\r\n        warn_on_overwrite $shim $path\r\n        @(\r\n            '#!/bin/sh',\r\n            \"# $resolved_path\",\r\n            \"if [ `$WSL_INTEROP ]\",\r\n            'then',\r\n            \"  `\"`$(wslpath -u '$resolved_path')`\" $arg `\"$@`\"\",\r\n            'else',\r\n            \"  `\"`$(cygpath -u '$resolved_path')`\" $arg `\"$@`\"\",\r\n            'fi'\r\n        ) -join \"`n\" | Out-UTF8File $shim -NoNewLine\r\n    }\r\n}\r\n\r\nfunction get_shim_path() {\r\n    $shim_version = get_config SHIM 'kiennq'\r\n    $shim_path = switch ($shim_version) {\r\n        'scoopcs' { \"$(versiondir 'scoop' 'current')\\supporting\\shims\\scoopcs\\shim.exe\" }\r\n        '71' { \"$(versiondir 'scoop' 'current')\\supporting\\shims\\71\\shim.exe\" }\r\n        'kiennq' { \"$(versiondir 'scoop' 'current')\\supporting\\shims\\kiennq\\shim.exe\" }\r\n        'default' { \"$(versiondir 'scoop' 'current')\\supporting\\shims\\scoopcs\\shim.exe\" }\r\n        default { warn \"Unknown shim version: '$shim_version'\" }\r\n    }\r\n    return $shim_path\r\n}\r\n\r\nfunction Get-DefaultArchitecture {\r\n    $arch = get_config DEFAULT_ARCHITECTURE\r\n    $system = if (${env:ProgramFiles(Arm)}) {\r\n        'arm64'\r\n    } elseif ([System.Environment]::Is64BitOperatingSystem) {\r\n        '64bit'\r\n    } else {\r\n        '32bit'\r\n    }\r\n    if ($null -eq $arch) {\r\n        $arch = $system\r\n    } else {\r\n        try {\r\n            $arch = Format-ArchitectureString $arch\r\n        } catch {\r\n            warn 'Invalid default architecture configured. Determining default system architecture'\r\n            $arch = $system\r\n        }\r\n    }\r\n    return $arch\r\n}\r\n\r\nfunction Format-ArchitectureString($Architecture) {\r\n    if (!$Architecture) {\r\n        return Get-DefaultArchitecture\r\n    }\r\n    $Architecture = $Architecture.ToString().ToLower()\r\n    switch ($Architecture) {\r\n        { @('64bit', '64', 'x64', 'amd64', 'x86_64', 'x86-64') -contains $_ } { return '64bit' }\r\n        { @('32bit', '32', 'x86', 'i386', '386', 'i686') -contains $_ } { return '32bit' }\r\n        { @('arm64', 'arm', 'aarch64') -contains $_ } { return 'arm64' }\r\n        default { throw [System.ArgumentException] \"Invalid architecture: '$Architecture'\" }\r\n    }\r\n}\r\n\r\nfunction Confirm-InstallationStatus {\r\n    [CmdletBinding()]\r\n    [OutputType([Object[]])]\r\n    param(\r\n        [Parameter(Mandatory = $true)]\r\n        [String[]]\r\n        $Apps,\r\n        [Switch]\r\n        $Global\r\n    )\r\n    $Installed = @()\r\n    $Apps | Select-Object -Unique | Where-Object { $_ -ne 'scoop' } | ForEach-Object {\r\n        $App, $null, $null = parse_app $_\r\n        if ($Global) {\r\n            if (Test-Path (appdir $App $true)) {\r\n                $Installed += , @($App, $true)\r\n            } elseif (Test-Path (appdir $App $false)) {\r\n                error \"'$App' isn't installed globally, but it may be installed locally.\"\r\n                warn \"Try again without the --global (or -g) flag instead.\"\r\n            } else {\r\n                error \"'$App' isn't installed.\"\r\n            }\r\n        } else {\r\n            if (Test-Path (appdir $App $false)) {\r\n                $Installed += , @($App, $false)\r\n            } elseif (Test-Path (appdir $App $true)) {\r\n                error \"'$App' isn't installed locally, but it may be installed globally.\"\r\n                warn \"Try again with the --global (or -g) flag instead.\"\r\n            } else {\r\n                error \"'$App' isn't installed.\"\r\n            }\r\n        }\r\n        if (failed $App $Global) {\r\n            error \"'$App' isn't installed correctly.\"\r\n        }\r\n    }\r\n    return , $Installed\r\n}\r\n\r\nfunction wraptext($text, $width) {\r\n    if(!$width) { $width = $host.ui.rawui.buffersize.width };\r\n    $width -= 1 # be conservative: doesn't seem to print the last char\r\n\r\n    $text -split '\\r?\\n' | ForEach-Object {\r\n        $line = ''\r\n        $_ -split ' ' | ForEach-Object {\r\n            if($line.length -eq 0) { $line = $_ }\r\n            elseif($line.length + $_.length + 1 -le $width) { $line += \" $_\" }\r\n            else { $lines += ,$line; $line = $_ }\r\n        }\r\n        $lines += ,$line\r\n    }\r\n\r\n    $lines -join \"`n\"\r\n}\r\n\r\nfunction pluralize($count, $singular, $plural) {\r\n    if($count -eq 1) { $singular } else { $plural }\r\n}\r\n\r\n# convert list of apps to list of ($app, $global) tuples\r\nfunction applist($apps, $global) {\r\n    if(!$apps) { return @() }\r\n    return ,@($apps | ForEach-Object { ,@($_, $global) })\r\n}\r\n\r\nfunction parse_app([string]$app) {\r\n    if ($app -match '^(?:(?<bucket>[a-zA-Z0-9-_.]+)/)?(?<app>.*\\.json|[a-zA-Z0-9-_.]+)(?:@(?<version>.*))?$') {\r\n        return $Matches['app'], $Matches['bucket'], $Matches['version']\r\n    } else {\r\n        return $app, $null, $null\r\n    }\r\n}\r\n\r\nfunction show_app($app, $bucket, $version) {\r\n    if($bucket) {\r\n        $app = \"$bucket/$app\"\r\n    }\r\n    if($version) {\r\n        $app = \"$app@$version\"\r\n    }\r\n    return $app\r\n}\r\n\r\nfunction is_scoop_outdated() {\r\n    $now = [System.DateTime]::Now\r\n    try {\r\n        $expireHour = (New-TimeSpan (get_config LAST_UPDATE) $now).TotalHours\r\n        return ($expireHour -ge 3)\r\n    } catch {\r\n        # If not System.DateTime\r\n        set_config LAST_UPDATE ($now.ToString('o')) | Out-Null\r\n        return $true\r\n    }\r\n}\r\n\r\nfunction Test-ScoopCoreOnHold() {\r\n    $hold_update_until = get_config HOLD_UPDATE_UNTIL\r\n    if ($null -eq $hold_update_until) {\r\n        return $false\r\n    }\r\n    $parsed_date = New-Object -TypeName DateTime\r\n    if ([System.DateTime]::TryParse($hold_update_until, $null, [System.Globalization.DateTimeStyles]::AssumeLocal, [ref]$parsed_date)) {\r\n        if ((New-TimeSpan $parsed_date).TotalSeconds -lt 0) {\r\n            warn \"Skipping self-update of Scoop Core until $($parsed_date.ToLocalTime())...\"\r\n            warn \"If you want to update Scoop Core immediately, use 'scoop unhold scoop; scoop update'.\"\r\n            return $true\r\n        } else {\r\n            warn 'Self-update of Scoop Core is enabled again!'\r\n        }\r\n    } else {\r\n        error \"'hold_update_until' has been set in the wrong format and was removed.\"\r\n        error 'If you want to disable self-update of Scoop Core for a moment,'\r\n        error \"use 'scoop hold scoop' or 'scoop config hold_update_until <YYYY-MM-DD>/<YYYY/MM/DD>'.\"\r\n    }\r\n    set_config HOLD_UPDATE_UNTIL $null | Out-Null\r\n    return $false\r\n}\r\n\r\nfunction substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) {\r\n    if ($null -ne $entity) {\r\n        $newentity = $entity.PSObject.Copy()\r\n        switch ($entity.GetType().Name) {\r\n            'String' {\r\n                $params.GetEnumerator() | ForEach-Object {\r\n                    if ($regexEscape -eq $false -or $null -eq $_.Value) {\r\n                        $newentity = $newentity.Replace($_.Name, $_.Value)\r\n                    } else {\r\n                        $newentity = $newentity.Replace($_.Name, [Regex]::Escape($_.Value))\r\n                    }\r\n                }\r\n            }\r\n            'Object[]' {\r\n                $newentity = $entity | ForEach-Object { , (substitute $_ $params $regexEscape) }\r\n            }\r\n            'PSCustomObject' {\r\n                $newentity.PSObject.Properties | ForEach-Object { $_.Value = substitute $_.Value $params $regexEscape }\r\n            }\r\n        }\r\n    }\r\n    return $newentity\r\n}\r\n\r\nfunction Out-UTF8File {\r\n    param(\r\n        [Parameter(Mandatory = $True, Position = 0)]\r\n        [Alias(\"Path\")]\r\n        [String] $FilePath,\r\n        [Switch] $Append,\r\n        [Switch] $NoNewLine,\r\n        [Parameter(ValueFromPipeline = $True)]\r\n        [PSObject] $InputObject\r\n    )\r\n    process {\r\n        if ($Append) {\r\n            [System.IO.File]::AppendAllText($FilePath, $InputObject)\r\n        } else {\r\n            if (!$NoNewLine) {\r\n                # Ref: https://stackoverflow.com/questions/5596982\r\n                # Performance Note: `WriteAllLines` throttles memory usage while\r\n                # `WriteAllText` needs to keep the complete string in memory.\r\n                [System.IO.File]::WriteAllLines($FilePath, $InputObject)\r\n            } else {\r\n                # However `WriteAllText` does not add ending newline.\r\n                [System.IO.File]::WriteAllText($FilePath, $InputObject)\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n##################\r\n# Core Bootstrap #\r\n##################\r\n\r\n# Note: Github disabled TLS 1.0 support on 2018-02-23. Need to enable TLS 1.2\r\n#       for all communication with api.github.com\r\nOptimize-SecurityProtocol\r\n\r\n# Load Scoop config\r\n$configHome = $env:XDG_CONFIG_HOME, \"$env:USERPROFILE\\.config\" | Select-Object -First 1\r\n$configFile = \"$configHome\\scoop\\config.json\"\r\n# Check if it's the expected install path for scoop: <root>/apps/scoop/current\r\n$coreRoot = Split-Path $PSScriptRoot\r\n$pathExpected = ($coreRoot -replace '\\\\','/') -like '*apps/scoop/current*'\r\nif ($pathExpected) {\r\n    # Portable config is located in root directory:\r\n    #    .\\current\\scoop\\apps\\<root>\\config.json  <- a reversed path\r\n    # Imagine `<root>/apps/scoop/current/` in a reversed format,\r\n    # and the directory tree:\r\n    #\r\n    # ```\r\n    # <root>:\r\n    # ├─apps\r\n    # ├─buckets\r\n    # ├─cache\r\n    # ├─persist\r\n    # ├─shims\r\n    # ├─config.json\r\n    # ```\r\n    $configPortablePath = Get-AbsolutePath \"$coreRoot\\..\\..\\..\\config.json\"\r\n    if (Test-Path $configPortablePath) {\r\n        $configFile = $configPortablePath\r\n    }\r\n}\r\n$scoopConfig = load_cfg $configFile\r\n\r\n# Scoop root directory\r\n$scoopdir = $env:SCOOP, (get_config ROOT_PATH), \"$PSScriptRoot\\..\\..\\..\\..\", \"$([System.Environment]::GetFolderPath('UserProfile'))\\scoop\" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath\r\n\r\n# Scoop global apps directory\r\n$globaldir = $env:SCOOP_GLOBAL, (get_config GLOBAL_PATH), \"$([System.Environment]::GetFolderPath('CommonApplicationData'))\\scoop\" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath\r\n\r\n# Scoop cache directory\r\n# Note: Setting the SCOOP_CACHE environment variable to use a shared directory\r\n#       is experimental and untested. There may be concurrency issues when\r\n#       multiple users write and access cached files at the same time.\r\n#       Use at your own risk.\r\n$cachedir = $env:SCOOP_CACHE, (get_config CACHE_PATH), \"$scoopdir\\cache\" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath\r\n\r\n# Scoop apps' PATH Environment Variable\r\n$scoopPathEnvVar = switch (get_config USE_ISOLATED_PATH) {\r\n    { $_ -is [string] } { $_.ToUpperInvariant() }\r\n    $true { 'SCOOP_PATH' }\r\n    default { 'PATH' }\r\n}\r\n\r\n# OS information\r\n$WindowsBuild = [System.Environment]::OSVersion.Version.Build\r\n"
  },
  {
    "path": "lib/database.ps1",
    "content": "# Description: Functions for interacting with the Scoop database cache\r\n\r\n<#\r\n.SYNOPSIS\r\n    Get SQLite .NET driver\r\n.DESCRIPTION\r\n    Download and extract the SQLite .NET driver from NuGet.\r\n.PARAMETER Version\r\n    System.String\r\n    The version of the SQLite .NET driver to download.\r\n.INPUTS\r\n    None\r\n.OUTPUTS\r\n    System.Boolean\r\n    True if the SQLite .NET driver was successfully downloaded and extracted, otherwise false.\r\n#>\r\nfunction Get-SQLite {\r\n    param (\r\n        [string]$Version = '1.0.118'\r\n    )\r\n    # Install SQLite\r\n    try {\r\n        Write-Host \"Downloading SQLite $Version...\" -ForegroundColor DarkYellow\r\n        $sqlitePkgPath = \"$env:TEMP\\sqlite.zip\"\r\n        $sqliteTempPath = \"$env:TEMP\\sqlite\"\r\n        $sqlitePath = \"$PSScriptRoot\\..\\supporting\\sqlite\"\r\n        Invoke-WebRequest -Uri \"https://api.nuget.org/v3-flatcontainer/stub.system.data.sqlite.core.netframework/$version/stub.system.data.sqlite.core.netframework.$version.nupkg\" -OutFile $sqlitePkgPath\r\n        Write-Host \"Extracting SQLite $Version...\" -ForegroundColor DarkYellow -NoNewline\r\n        Expand-Archive -Path $sqlitePkgPath -DestinationPath $sqliteTempPath -Force\r\n        New-Item -Path $sqlitePath -ItemType Directory -Force | Out-Null\r\n        Move-Item -Path \"$sqliteTempPath\\build\\net451\\*\", \"$sqliteTempPath\\lib\\net451\\System.Data.SQLite.dll\" -Destination $sqlitePath -Force\r\n        Remove-Item -Path $sqlitePkgPath, $sqliteTempPath -Recurse -Force\r\n        Write-Host ' Done' -ForegroundColor DarkYellow\r\n        return $true\r\n    } catch {\r\n        return $false\r\n    }\r\n}\r\n\r\n<#\r\n.SYNOPSIS\r\n    Open Scoop SQLite database.\r\n.DESCRIPTION\r\n    Open Scoop SQLite database connection and create the necessary tables if not exists.\r\n.INPUTS\r\n    None\r\n.OUTPUTS\r\n    System.Data.SQLite.SQLiteConnection\r\n    The SQLite database connection if **PassThru** is used.\r\n#>\r\nfunction Open-ScoopDB {\r\n    # Load System.Data.SQLite\r\n    if (!('System.Data.SQLite.SQLiteConnection' -as [Type])) {\r\n        try {\r\n            if (!(Test-Path -Path \"$PSScriptRoot\\..\\supporting\\sqlite\\System.Data.SQLite.dll\")) {\r\n                Get-SQLite | Out-Null\r\n            }\r\n            Add-Type -Path \"$PSScriptRoot\\..\\supporting\\sqlite\\System.Data.SQLite.dll\"\r\n        } catch {\r\n            throw \"Scoop's Database cache requires the ADO.NET driver:`n`thttp://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki\"\r\n        }\r\n    }\r\n    $dbPath = Join-Path $scoopdir 'scoop.db'\r\n    $db = New-Object -TypeName System.Data.SQLite.SQLiteConnection\r\n    $db.ConnectionString = \"Data Source=$dbPath\"\r\n    $db.ParseViaFramework = $true # Allow UNC path\r\n    $db.Open()\r\n    $tableCommand = $db.CreateCommand()\r\n    $tableCommand.CommandText = \"CREATE TABLE IF NOT EXISTS 'app' (\r\n        name TEXT NOT NULL COLLATE NOCASE,\r\n        description TEXT NOT NULL,\r\n        version TEXT NOT NULL,\r\n        bucket VARCHAR NOT NULL,\r\n        manifest JSON NOT NULL,\r\n        binary TEXT,\r\n        shortcut TEXT,\r\n        dependency TEXT,\r\n        suggest TEXT,\r\n        PRIMARY KEY (name, version, bucket)\r\n    )\"\r\n    $tableCommand.CommandType = [System.Data.CommandType]::Text\r\n    $tableCommand.ExecuteNonQuery() | Out-Null\r\n    $tableCommand.Dispose()\r\n    return $db\r\n}\r\n\r\n<#\r\n.SYNOPSIS\r\n    Set Scoop database item(s).\r\n.DESCRIPTION\r\n    Insert or replace item(s) into the Scoop SQLite database.\r\n.PARAMETER InputObject\r\n    System.Object[]\r\n    The database item(s) to insert or replace.\r\n.INPUTS\r\n    System.Object[]\r\n.OUTPUTS\r\n    None\r\n#>\r\nfunction Set-ScoopDBItem {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]\r\n        [psobject[]]\r\n        $InputObject\r\n    )\r\n\r\n    begin {\r\n        $db = Open-ScoopDB\r\n        $dbTrans = $db.BeginTransaction()\r\n        # TODO Support [hashtable]$InputObject\r\n        $colName = @($InputObject | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name)\r\n        $dbQuery = \"INSERT OR REPLACE INTO app ($($colName -join ', ')) VALUES ($('@' + ($colName -join ', @')))\"\r\n        $dbCommand = $db.CreateCommand()\r\n        $dbCommand.CommandText = $dbQuery\r\n        $dbCommand.CommandType = [System.Data.CommandType]::Text\r\n    }\r\n    process {\r\n        foreach ($item in $InputObject) {\r\n            $item.PSObject.Properties | ForEach-Object {\r\n                $dbCommand.Parameters.AddWithValue(\"@$($_.Name)\", $_.Value) | Out-Null\r\n            }\r\n            $dbCommand.ExecuteNonQuery() | Out-Null\r\n        }\r\n    }\r\n    end {\r\n        try {\r\n            $dbTrans.Commit()\r\n        } catch {\r\n            $dbTrans.Rollback()\r\n            throw $_\r\n        } finally {\r\n            $dbCommand.Dispose()\r\n            $dbTrans.Dispose()\r\n            $db.Dispose()\r\n        }\r\n    }\r\n}\r\n\r\n<#\r\n.SYNOPSIS\r\n    Set Scoop app database item(s).\r\n.DESCRIPTION\r\n    Insert or replace Scoop app(s) into the database.\r\n.PARAMETER Path\r\n    System.String\r\n    The path to the bucket.\r\n.PARAMETER CommitHash\r\n    System.String\r\n    The commit hash to compare with the HEAD.\r\n.INPUTS\r\n    None\r\n.OUTPUTS\r\n    None\r\n#>\r\nfunction Set-ScoopDB {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Position = 0, ValueFromPipeline)]\r\n        [string[]]\r\n        $Path\r\n    )\r\n\r\n    begin {\r\n        $list = [System.Collections.Generic.List[psobject]]::new()\r\n        $arch = Get-DefaultArchitecture\r\n    }\r\n    process {\r\n        if ($Path.Count -eq 0) {\r\n            $bucketPath = Get-LocalBucket | ForEach-Object { Find-BucketDirectory $_ }\r\n            $Path = (Get-ChildItem $bucketPath -Filter '*.json' -Recurse).FullName\r\n        }\r\n        $Path | ForEach-Object {\r\n            $manifestRaw = [System.IO.File]::ReadAllText($_)\r\n            $manifest = ConvertFrom-Json $manifestRaw -ErrorAction SilentlyContinue\r\n            if ($null -ne $manifest.version) {\r\n                $list.Add([pscustomobject]@{\r\n                        name        = $($_ -replace '.*[\\\\/]([^\\\\/]+)\\.json$', '$1')\r\n                        description = if ($manifest.description) { $manifest.description } else { '' }\r\n                        version     = $manifest.version\r\n                        bucket      = $($_ -replace '.*buckets[\\\\/]([^\\\\/]+)(?:[\\\\/].*)', '$1')\r\n                        manifest    = $manifestRaw\r\n                        binary      = $(\r\n                            $result = @()\r\n                            @(arch_specific 'bin' $manifest $arch) | ForEach-Object {\r\n                                if ($_ -is [System.Array]) {\r\n                                    $result += \"$($_[1]).$($_[0].Split('.')[-1])\"\r\n                                } else {\r\n                                    $result += $_\r\n                                }\r\n                            }\r\n                            $result -replace '.*?([^\\\\/]+)?(\\.(exe|bat|cmd|ps1|jar|py))$', '$1' -join ' | '\r\n                        )\r\n                        shortcut    = $(\r\n                            $result = @()\r\n                            @(arch_specific 'shortcuts' $manifest $arch) | ForEach-Object {\r\n                                $result += $_[1]\r\n                            }\r\n                            $result -replace '.*?([^\\\\/]+$)', '$1' -join ' | '\r\n                        )\r\n                        dependency  = $manifest.depends -join ' | '\r\n                        suggest     = $(\r\n                            $suggest_output = @()\r\n                            $manifest.suggest.PSObject.Properties | ForEach-Object {\r\n                                $suggest_output += $_.Value -join ' | '\r\n                            }\r\n                            $suggest_output -join ' | '\r\n                        )\r\n                    })\r\n            }\r\n        }\r\n    }\r\n    end {\r\n        if ($list.Count -ne 0) {\r\n            Set-ScoopDBItem $list\r\n        }\r\n    }\r\n}\r\n\r\n<#\r\n.SYNOPSIS\r\n    Select Scoop database item(s).\r\n.DESCRIPTION\r\n    Select item(s) from the Scoop SQLite database.\r\n    The pattern is matched against the name, binaries, and shortcuts columns for apps.\r\n.PARAMETER Pattern\r\n    System.String\r\n    The pattern to search for. If is an empty string, all items will be returned.\r\n.PARAMETER From\r\n    System.String[]\r\n    The fields to search from.\r\n.INPUTS\r\n    System.String\r\n.OUTPUTS\r\n    System.Data.DataTable\r\n    The selected database item(s).\r\n#>\r\nfunction Select-ScoopDBItem {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]\r\n        [AllowEmptyString()]\r\n        [string]\r\n        $Pattern,\r\n        [Parameter(Mandatory, Position = 1)]\r\n        [ValidateNotNullOrEmpty()]\r\n        [string[]]\r\n        $From\r\n    )\r\n\r\n    begin {\r\n        $db = Open-ScoopDB\r\n        $dbAdapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter\r\n        $result = New-Object System.Data.DataTable\r\n        $dbQuery = \"SELECT * FROM app WHERE $(($From -join ' LIKE @Pattern OR ') + ' LIKE @Pattern')\"\r\n        $dbQuery = \"SELECT * FROM ($($dbQuery + ' ORDER BY version DESC')) GROUP BY name, bucket\"\r\n        $dbCommand = $db.CreateCommand()\r\n        $dbCommand.CommandText = $dbQuery\r\n        $dbCommand.CommandType = [System.Data.CommandType]::Text\r\n        $dbAdapter.SelectCommand = $dbCommand\r\n    }\r\n    process {\r\n        $dbCommand.Parameters.AddWithValue('@Pattern', $(if ($Pattern -eq '') { '%' } else { '%' + $Pattern + '%' })) | Out-Null\r\n        [void]$dbAdapter.Fill($result)\r\n    }\r\n    end {\r\n        $dbAdapter.Dispose()\r\n        $db.Dispose()\r\n        return $result\r\n    }\r\n}\r\n\r\n<#\r\n.SYNOPSIS\r\n    Get Scoop database item.\r\n.DESCRIPTION\r\n    Get item from the Scoop SQLite database.\r\n.PARAMETER Name\r\n    System.String\r\n    The name of the item to get.\r\n.PARAMETER Bucket\r\n    System.String\r\n    The bucket of the item to get.\r\n.PARAMETER Version\r\n    System.String\r\n    The version of the item to get. If not provided, the latest version will be returned.\r\n.INPUTS\r\n    System.String\r\n.OUTPUTS\r\n    System.Data.DataTable\r\n    The selected database item.\r\n#>\r\nfunction Get-ScoopDBItem {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]\r\n        [string]\r\n        $Name,\r\n        [Parameter(Mandatory, Position = 1)]\r\n        [string]\r\n        $Bucket,\r\n        [Parameter(Position = 2)]\r\n        [string]\r\n        $Version\r\n    )\r\n\r\n    begin {\r\n        $db = Open-ScoopDB\r\n        $dbAdapter = New-Object -TypeName System.Data.SQLite.SQLiteDataAdapter\r\n        $result = New-Object System.Data.DataTable\r\n        $dbQuery = 'SELECT * FROM app WHERE name = @Name AND bucket = @Bucket'\r\n        if ($Version) {\r\n            $dbQuery += ' AND version = @Version'\r\n        } else {\r\n            $dbQuery += ' ORDER BY version DESC LIMIT 1'\r\n        }\r\n        $dbCommand = $db.CreateCommand()\r\n        $dbCommand.CommandText = $dbQuery\r\n        $dbCommand.CommandType = [System.Data.CommandType]::Text\r\n        $dbAdapter.SelectCommand = $dbCommand\r\n    }\r\n    process {\r\n        $dbCommand.Parameters.AddWithValue('@Name', $Name) | Out-Null\r\n        $dbCommand.Parameters.AddWithValue('@Bucket', $Bucket) | Out-Null\r\n        $dbCommand.Parameters.AddWithValue('@Version', $Version) | Out-Null\r\n        [void]$dbAdapter.Fill($result)\r\n    }\r\n    end {\r\n        $dbAdapter.Dispose()\r\n        $db.Dispose()\r\n        return $result\r\n    }\r\n}\r\n\r\n<#\r\n.SYNOPSIS\r\n    Remove Scoop database item(s).\r\n.DESCRIPTION\r\n    Remove item(s) from the Scoop SQLite database.\r\n.PARAMETER Name\r\n    System.String\r\n    The name of the item to remove.\r\n.PARAMETER Bucket\r\n    System.String\r\n    The bucket of the item to remove.\r\n.INPUTS\r\n    System.String\r\n.OUTPUTS\r\n    None\r\n#>\r\nfunction Remove-ScoopDBItem {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]\r\n        [string]\r\n        $Name,\r\n        [Parameter(Mandatory, Position = 1, ValueFromPipelineByPropertyName)]\r\n        [string]\r\n        $Bucket\r\n    )\r\n\r\n    begin {\r\n        $db = Open-ScoopDB\r\n        $dbTrans = $db.BeginTransaction()\r\n        $dbQuery = 'DELETE FROM app WHERE bucket = @Bucket'\r\n        $dbCommand = $db.CreateCommand()\r\n        $dbCommand.CommandText = $dbQuery\r\n        $dbCommand.CommandType = [System.Data.CommandType]::Text\r\n    }\r\n    process {\r\n        $dbCommand.Parameters.AddWithValue('@Bucket', $Bucket) | Out-Null\r\n        if ($Name) {\r\n            $dbCommand.CommandText = $dbQuery + ' AND name = @Name'\r\n            $dbCommand.Parameters.AddWithValue('@Name', $Name) | Out-Null\r\n        }\r\n        $dbCommand.ExecuteNonQuery() | Out-Null\r\n    }\r\n    end {\r\n        try {\r\n            $dbTrans.Commit()\r\n        } catch {\r\n            $dbTrans.Rollback()\r\n            throw $_\r\n        } finally {\r\n            $dbCommand.Dispose()\r\n            $dbTrans.Dispose()\r\n            $db.Dispose()\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/decompress.ps1",
    "content": "# Description: Functions for decompressing archives or installers\r\n\r\nfunction Invoke-Extraction {\r\n    param (\r\n        [string]\r\n        $Path,\r\n        [string[]]\r\n        $Name,\r\n        [psobject]\r\n        $Manifest,\r\n        [Alias('Arch', 'Architecture')]\r\n        [string]\r\n        $ProcessorArchitecture\r\n    )\r\n\r\n    $uri = @(url $Manifest $ProcessorArchitecture)\r\n    # 'extract_dir' and 'extract_to' are paired\r\n    $extractDir = @(extract_dir $Manifest $ProcessorArchitecture)\r\n    $extractTo = @(extract_to $Manifest $ProcessorArchitecture)\r\n    $extracted = 0\r\n\r\n    for ($i = 0; $i -lt $Name.Length; $i++) {\r\n        # work out extraction method, if applicable\r\n        $extractFn = $null\r\n        switch -regex ($Name[$i]) {\r\n            '\\.zip$' {\r\n                if ((Test-HelperInstalled -Helper 7zip) -or ((get_config USE_EXTERNAL_7ZIP) -and (Test-CommandAvailable 7z))) {\r\n                    $extractFn = 'Expand-7zipArchive'\r\n                } else {\r\n                    $extractFn = 'Expand-ZipArchive'\r\n                }\r\n                continue\r\n            }\r\n            '\\.msi$' {\r\n                $extractFn = 'Expand-MsiArchive'\r\n                continue\r\n            }\r\n            '\\.exe$' {\r\n                if ($Manifest.innosetup) {\r\n                    $extractFn = 'Expand-InnoArchive'\r\n                }\r\n                continue\r\n            }\r\n            { Test-7zipRequirement -Uri $_ } {\r\n                $extractFn = 'Expand-7zipArchive'\r\n                continue\r\n            }\r\n        }\r\n        if ($extractFn) {\r\n            $fnArgs = @{\r\n                Path            = Join-Path $Path $Name[$i]\r\n                DestinationPath = Join-Path $Path $extractTo[$extracted]\r\n                ExtractDir      = $extractDir[$extracted]\r\n            }\r\n            Write-Host 'Extracting ' -NoNewline\r\n            Write-Host $(url_remote_filename $uri[$i]) -ForegroundColor Cyan -NoNewline\r\n            Write-Host ' ... ' -NoNewline\r\n            & $extractFn @fnArgs -Removal\r\n            Write-Host 'done.' -ForegroundColor Green\r\n            $extracted++\r\n        }\r\n    }\r\n}\r\n\r\nfunction Expand-7zipArchive {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [String]\r\n        $Path,\r\n        [Parameter(Position = 1)]\r\n        [String]\r\n        $DestinationPath = (Split-Path $Path),\r\n        [String]\r\n        $ExtractDir,\r\n        [Parameter(ValueFromRemainingArguments = $true)]\r\n        [String]\r\n        $Switches,\r\n        [ValidateSet('All', 'Skip', 'Rename')]\r\n        [String]\r\n        $Overwrite,\r\n        [Switch]\r\n        $Removal\r\n    )\r\n    if ((get_config USE_EXTERNAL_7ZIP)) {\r\n        try {\r\n            $7zPath = (Get-Command '7z' -CommandType Application -ErrorAction Stop | Select-Object -First 1).Source\r\n        } catch [System.Management.Automation.CommandNotFoundException] {\r\n            abort \"`nCannot find external 7-Zip (7z.exe) while 'use_external_7zip' is 'true'!`nRun 'scoop config use_external_7zip false' or install 7-Zip manually and try again.\"\r\n        }\r\n    } else {\r\n        $7zPath = Get-HelperPath -Helper 7zip\r\n    }\r\n    $LogPath = \"$(Split-Path $Path)\\7zip.log\"\r\n    $DestinationPath = $DestinationPath.TrimEnd('\\')\r\n    $ArgList = @('x', $Path, \"-o$DestinationPath\", '-xr!*.nsis', '-y')\r\n    $IsTar = ((strip_ext $Path) -match '\\.tar$') -or ($Path -match '\\.t[abgpx]z2?$')\r\n    if (!$IsTar -and $ExtractDir) {\r\n        $ArgList += \"-ir!$ExtractDir\\*\"\r\n    }\r\n    if ($Switches) {\r\n        $ArgList += (-split $Switches)\r\n    }\r\n    switch ($Overwrite) {\r\n        'All' { $ArgList += '-aoa' }\r\n        'Skip' { $ArgList += '-aos' }\r\n        'Rename' { $ArgList += '-aou' }\r\n    }\r\n    $Status = Invoke-ExternalCommand $7zPath $ArgList -LogPath $LogPath\r\n    if (!$Status) {\r\n        abort \"Failed to extract files from $Path.`nLog file:`n  $(friendly_path $LogPath)`n$(new_issue_msg $app $bucket 'decompress error')\"\r\n    }\r\n    if ($IsTar) {\r\n        # Check for tar\r\n        $Status = Invoke-ExternalCommand $7zPath @('l', $Path) -LogPath $LogPath\r\n        if ($Status) {\r\n            # get inner tar file name\r\n            $TarFile = (Select-String -Path $LogPath -Pattern '[^ ]*tar$').Matches.Value\r\n            Expand-7zipArchive -Path \"$DestinationPath\\$TarFile\" -DestinationPath $DestinationPath -ExtractDir $ExtractDir -Removal\r\n        } else {\r\n            abort \"Failed to list files in $Path.`nNot a 7-Zip supported archive file.\"\r\n        }\r\n    }\r\n    if (!$IsTar -and $ExtractDir) {\r\n        movedir \"$DestinationPath\\$ExtractDir\" $DestinationPath | Out-Null\r\n        # Remove temporary directory if it is empty\r\n        $ExtractDirTopPath = [string] \"$DestinationPath\\$($ExtractDir -replace '[\\\\/].*')\"\r\n        if ((Get-ChildItem -Path $ExtractDirTopPath -Force -ErrorAction Ignore).Count -eq 0) {\r\n            Remove-Item -Path $ExtractDirTopPath -Recurse -Force -ErrorAction Ignore\r\n        }\r\n    }\r\n    if (Test-Path $LogPath) {\r\n        Remove-Item $LogPath -Force\r\n    }\r\n    if ($Removal) {\r\n        if (($Path -replace '.*\\.([^\\.]*)$', '$1') -eq '001') {\r\n            # Remove splitted 7-zip archive parts\r\n            Get-ChildItem \"$($Path -replace '\\.[^\\.]*$', '').???\" | Remove-Item -Force\r\n        } elseif (($Path -replace '.*\\.part(\\d+)\\.rar$', '$1')[-1] -eq '1') {\r\n            # Remove splitted RAR archive parts\r\n            Get-ChildItem \"$($Path -replace '\\.part(\\d+)\\.rar$', '').part*.rar\" | Remove-Item -Force\r\n        } else {\r\n            # Remove original archive file\r\n            Remove-Item $Path -Force\r\n        }\r\n    }\r\n}\r\n\r\nfunction Expand-ZstdArchive {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [String]\r\n        $Path,\r\n        [Parameter(Position = 1)]\r\n        [String]\r\n        $DestinationPath = (Split-Path $Path),\r\n        [String]\r\n        $ExtractDir,\r\n        [Parameter(ValueFromRemainingArguments = $true)]\r\n        [String]\r\n        $Switches,\r\n        [Switch]\r\n        $Removal\r\n    )\r\n    # TODO: Remove this function after 2024/12/31\r\n    Show-DeprecatedWarning $MyInvocation 'Expand-7zipArchive'\r\n    Expand-7zipArchive -Path $Path -DestinationPath $DestinationPath -ExtractDir $ExtractDir -Switches $Switches -Removal:$Removal\r\n}\r\n\r\nfunction Expand-MsiArchive {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [String]\r\n        $Path,\r\n        [Parameter(Position = 1)]\r\n        [String]\r\n        $DestinationPath = (Split-Path $Path),\r\n        [String]\r\n        $ExtractDir,\r\n        [Parameter(ValueFromRemainingArguments = $true)]\r\n        [String]\r\n        $Switches,\r\n        [Switch]\r\n        $Removal\r\n    )\r\n    $DestinationPath = $DestinationPath.TrimEnd('\\')\r\n    if ($ExtractDir) {\r\n        $OriDestinationPath = $DestinationPath\r\n        $DestinationPath = \"$DestinationPath\\_tmp\"\r\n    }\r\n    if ((get_config USE_LESSMSI)) {\r\n        $MsiPath = Get-HelperPath -Helper Lessmsi\r\n        $ArgList = @('x', $Path, \"$DestinationPath\\\")\r\n    } else {\r\n        $MsiPath = 'msiexec.exe'\r\n        $ArgList = @('/a', $Path, '/qn', \"TARGETDIR=$DestinationPath\\SourceDir\")\r\n    }\r\n    $LogPath = \"$(Split-Path $Path)\\msi.log\"\r\n    if ($Switches) {\r\n        $ArgList += (-split $Switches)\r\n    }\r\n    $Status = Invoke-ExternalCommand $MsiPath $ArgList -LogPath $LogPath\r\n    if (!$Status) {\r\n        abort \"Failed to extract files from $Path.`nLog file:`n  $(friendly_path $LogPath)`n$(new_issue_msg $app $bucket 'decompress error')\"\r\n    }\r\n    if ($ExtractDir -and (Test-Path \"$DestinationPath\\SourceDir\")) {\r\n        movedir \"$DestinationPath\\SourceDir\\$ExtractDir\" $OriDestinationPath | Out-Null\r\n        Remove-Item $DestinationPath -Recurse -Force\r\n    } elseif ($ExtractDir) {\r\n        movedir \"$DestinationPath\\$ExtractDir\" $OriDestinationPath | Out-Null\r\n        Remove-Item $DestinationPath -Recurse -Force\r\n    } elseif (Test-Path \"$DestinationPath\\SourceDir\") {\r\n        movedir \"$DestinationPath\\SourceDir\" $DestinationPath | Out-Null\r\n    }\r\n    if (($DestinationPath -ne (Split-Path $Path)) -and (Test-Path \"$DestinationPath\\$(fname $Path)\")) {\r\n        Remove-Item \"$DestinationPath\\$(fname $Path)\" -Force\r\n    }\r\n    if (Test-Path $LogPath) {\r\n        Remove-Item $LogPath -Force\r\n    }\r\n    if ($Removal) {\r\n        # Remove original archive file\r\n        Remove-Item $Path -Force\r\n    }\r\n}\r\n\r\nfunction Expand-InnoArchive {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [String]\r\n        $Path,\r\n        [Parameter(Position = 1)]\r\n        [String]\r\n        $DestinationPath = (Split-Path $Path),\r\n        [String]\r\n        $ExtractDir,\r\n        [Parameter(ValueFromRemainingArguments = $true)]\r\n        [String]\r\n        $Switches,\r\n        [Switch]\r\n        $Removal\r\n    )\r\n    $LogPath = \"$(Split-Path $Path)\\innounp.log\"\r\n    $ArgList = @('-x', \"-d$DestinationPath\", $Path, '-y')\r\n    switch -Regex ($ExtractDir) {\r\n        '^[^{].*' { $ArgList += \"-c{app}\\$ExtractDir\" }\r\n        '^{.*' { $ArgList += \"-c$ExtractDir\" }\r\n        Default { $ArgList += '-c{app}' }\r\n    }\r\n    if ($Switches) {\r\n        $ArgList += (-split $Switches)\r\n    }\r\n    $Status = Invoke-ExternalCommand (Get-HelperPath -Helper Innounp) $ArgList -LogPath $LogPath\r\n    if (!$Status) {\r\n        abort \"Failed to extract files from $Path.`nLog file:`n  $(friendly_path $LogPath)`n$(new_issue_msg $app $bucket 'decompress error')\"\r\n    }\r\n    if (Test-Path $LogPath) {\r\n        Remove-Item $LogPath -Force\r\n    }\r\n    if ($Removal) {\r\n        # Remove original archive file\r\n        Remove-Item $Path -Force\r\n    }\r\n}\r\n\r\nfunction Expand-ZipArchive {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [String]\r\n        $Path,\r\n        [Parameter(Position = 1)]\r\n        [String]\r\n        $DestinationPath = (Split-Path $Path),\r\n        [String]\r\n        $ExtractDir,\r\n        [Switch]\r\n        $Removal\r\n    )\r\n    if ($ExtractDir) {\r\n        $OriDestinationPath = $DestinationPath\r\n        $DestinationPath = \"$DestinationPath\\_tmp\"\r\n    }\r\n    # Disable progress bar to gain performance\r\n    $oldProgressPreference = $ProgressPreference\r\n    $global:ProgressPreference = 'SilentlyContinue'\r\n\r\n    # Compatible with Pscx v3 (https://github.com/Pscx/Pscx) ('Microsoft.PowerShell.Archive' is not needed for Pscx v4)\r\n    Microsoft.PowerShell.Archive\\Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force\r\n\r\n    $global:ProgressPreference = $oldProgressPreference\r\n    if ($ExtractDir) {\r\n        movedir \"$DestinationPath\\$ExtractDir\" $OriDestinationPath | Out-Null\r\n        Remove-Item $DestinationPath -Recurse -Force\r\n    }\r\n    if ($Removal) {\r\n        # Remove original archive file\r\n        Remove-Item $Path -Force\r\n    }\r\n}\r\n\r\nfunction Expand-DarkArchive {\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [String]\r\n        $Path,\r\n        [Parameter(Position = 1)]\r\n        [String]\r\n        $DestinationPath = (Split-Path $Path),\r\n        [Parameter(ValueFromRemainingArguments = $true)]\r\n        [String]\r\n        $Switches,\r\n        [Switch]\r\n        $Removal\r\n    )\r\n    $LogPath = \"$(Split-Path $Path)\\dark.log\"\r\n    $DarkPath = Get-HelperPath -Helper Dark\r\n    if ((Split-Path $DarkPath -Leaf) -eq 'wix.exe') {\r\n        $ArgList = @('burn', 'extract', $Path, '-out', $DestinationPath, '-outba', \"$DestinationPath\\UX\")\r\n    } else {\r\n        $ArgList = @('-nologo', '-x', $DestinationPath, $Path)\r\n    }\r\n    if ($Switches) {\r\n        $ArgList += (-split $Switches)\r\n    }\r\n    $Status = Invoke-ExternalCommand $DarkPath $ArgList -LogPath $LogPath\r\n    if (!$Status) {\r\n        abort \"Failed to extract files from $Path.`nLog file:`n  $(friendly_path $LogPath)`n$(new_issue_msg $app $bucket 'decompress error')\"\r\n    }\r\n    if (Test-Path \"$DestinationPath\\WixAttachedContainer\") {\r\n        Rename-Item \"$DestinationPath\\WixAttachedContainer\" 'AttachedContainer' -ErrorAction Ignore\r\n    } else {\r\n        if (Test-Path \"$DestinationPath\\AttachedContainer\\a0\") {\r\n            $Xml = [xml](Get-Content -Raw \"$DestinationPath\\UX\\manifest.xml\" -Encoding utf8)\r\n            $Xml.BurnManifest.UX.Payload | ForEach-Object {\r\n                Rename-Item \"$DestinationPath\\UX\\$($_.SourcePath)\" $_.FilePath -ErrorAction Ignore\r\n            }\r\n            $Xml.BurnManifest.Payload | ForEach-Object {\r\n                Rename-Item \"$DestinationPath\\AttachedContainer\\$($_.SourcePath)\" $_.FilePath -ErrorAction Ignore\r\n            }\r\n        }\r\n    }\r\n    if (Test-Path $LogPath) {\r\n        Remove-Item $LogPath -Force\r\n    }\r\n    if ($Removal) {\r\n        # Remove original archive file\r\n        Remove-Item $Path -Force\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/depends.ps1",
    "content": "function Get-Dependency {\r\n    <#\r\n    .SYNOPSIS\r\n        Get app's dependencies (with apps attached at the end).\r\n    .PARAMETER AppName\r\n        App's name\r\n    .PARAMETER Architecture\r\n        App's architecture\r\n    .PARAMETER Resolved\r\n        List of resolved dependencies (internal use)\r\n    .PARAMETER Unresolved\r\n        List of unresolved dependencies (internal use)\r\n    .OUTPUTS\r\n        [Object[]]\r\n        List of app's dependencies\r\n    .NOTES\r\n        When pipeline input is used, the output will have duplicate items, and should be filtered by 'Select-Object -Unique'.\r\n        ALgorithm: http://www.electricmonk.nl/docs/dependency_resolving_algorithm/dependency_resolving_algorithm.html\r\n    #>\r\n    [CmdletBinding()]\r\n    [OutputType([Object[]])]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [PSObject]\r\n        $AppName,\r\n        [Parameter(Mandatory = $true, Position = 1)]\r\n        [String]\r\n        $Architecture,\r\n        [String[]]\r\n        $Resolved = @(),\r\n        [String[]]\r\n        $Unresolved = @()\r\n    )\r\n    process {\r\n        $AppName, $manifest, $bucket, $url = Get-Manifest $AppName\r\n        $Unresolved += $AppName\r\n\r\n        if (!$manifest) {\r\n            if (((Get-LocalBucket) -notcontains $bucket) -and $bucket) {\r\n                warn \"Bucket '$bucket' not added. Add it with $(if($bucket -in (known_buckets)) { \"'scoop bucket add $bucket' or \" })'scoop bucket add $bucket <repo>'.\"\r\n            }\r\n            abort \"Couldn't find manifest for '$AppName'$(if($bucket) { \" from '$bucket' bucket\" } elseif($url) { \" at '$url'\" }).\"\r\n        }\r\n\r\n        $deps = @(Get-InstallationHelper $manifest $Architecture) + @($manifest.depends) | Select-Object -Unique\r\n\r\n        foreach ($dep in $deps) {\r\n            if ($Resolved -notcontains $dep) {\r\n                if ($Unresolved -contains $dep) {\r\n                    abort \"Circular dependency detected: '$AppName' -> '$dep'.\"\r\n                }\r\n                $Resolved, $Unresolved = Get-Dependency $dep $Architecture -Resolved $Resolved -Unresolved $Unresolved\r\n            }\r\n        }\r\n\r\n        $Unresolved = $Unresolved -ne $AppName\r\n        if ($bucket) {\r\n            $Resolved += \"$bucket/$AppName\"\r\n        } else {\r\n            if ($url) {\r\n                $Resolved += $url\r\n            } else {\r\n                $Resolved += $AppName\r\n            }\r\n        }\r\n        if ($Unresolved.Length -eq 0) {\r\n            return $Resolved\r\n        } else {\r\n            return $Resolved, $Unresolved\r\n        }\r\n    }\r\n}\r\n\r\nfunction Get-InstallationHelper {\r\n    <#\r\n    .SYNOPSIS\r\n        Get helpers that used in installation\r\n    .PARAMETER Manifest\r\n        App's manifest\r\n    .PARAMETER Architecture\r\n        Architecture of the app\r\n    .PARAMETER All\r\n        If true, return all helpers, otherwise return only helpers that are not already installed\r\n    .OUTPUTS\r\n        [Object[]]\r\n        List of helpers\r\n    #>\r\n    [CmdletBinding()]\r\n    [OutputType([Object[]])]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [PSObject]\r\n        $Manifest,\r\n        [Parameter(Mandatory = $true, Position = 1)]\r\n        [String]\r\n        $Architecture,\r\n        [Switch]\r\n        $All\r\n    )\r\n    begin {\r\n        $helper = @()\r\n    }\r\n    process {\r\n        $url = arch_specific 'url' $Manifest $Architecture\r\n        $pre_install = arch_specific 'pre_install' $Manifest $Architecture\r\n        $installer = arch_specific 'installer' $Manifest $Architecture\r\n        $post_install = arch_specific 'post_install' $Manifest $Architecture\r\n        $script = $pre_install + $installer.script + $post_install\r\n        if (((Test-7zipRequirement -Uri $url) -or ($script -like '*Expand-7zipArchive *')) -and !(get_config USE_EXTERNAL_7ZIP)) {\r\n            $helper += '7zip'\r\n        }\r\n        if (((Test-LessmsiRequirement -Uri $url) -or ($script -like '*Expand-MsiArchive *')) -and (get_config USE_LESSMSI)) {\r\n            $helper += 'lessmsi'\r\n        }\r\n        if ($Manifest.innosetup -or ($script -like '*Expand-InnoArchive *')) {\r\n            $helper += 'innounp'\r\n        }\r\n        if ($script -like '*Expand-DarkArchive *') {\r\n            $helper += 'dark'\r\n        }\r\n        if (!$All) {\r\n            '7zip', 'lessmsi', 'innounp', 'dark' | ForEach-Object {\r\n                if (Test-HelperInstalled -Helper $_) {\r\n                    $helper = $helper -ne $_\r\n                }\r\n            }\r\n        }\r\n    }\r\n    end {\r\n        return $helper\r\n    }\r\n}\r\n\r\nfunction Test-7zipRequirement {\r\n    [CmdletBinding()]\r\n    [OutputType([Boolean])]\r\n    param (\r\n        [Parameter(Mandatory = $true)]\r\n        [AllowNull()]\r\n        [String[]]\r\n        $Uri\r\n    )\r\n    return ($Uri | Where-Object {\r\n            $_ -match '\\.(001|7z|bz(ip)?2?|gz|img|iso|lzma|lzh|nupkg|rar|tar|t[abgpx]z2?|t?zst|xz)(\\.[^\\d.]+)?$'\r\n        }).Count -gt 0\r\n}\r\n\r\nfunction Test-LessmsiRequirement {\r\n    [CmdletBinding()]\r\n    [OutputType([Boolean])]\r\n    param (\r\n        [Parameter(Mandatory = $true)]\r\n        [AllowNull()]\r\n        [String[]]\r\n        $Uri\r\n    )\r\n    return ($Uri | Where-Object { $_ -match '\\.msi$' }).Count -gt 0\r\n}\r\n"
  },
  {
    "path": "lib/description.ps1",
    "content": "function find_description($url, $html, $redir = $false) {\r\n    $meta = meta_tags $html\r\n\r\n    # check <meta property=\"og:description\">\r\n    $og_description = meta_content $meta 'property' 'og:description'\r\n    if($og_description) {\r\n        return $og_description, '<meta property=\"og:description\">'\r\n    }\r\n\r\n    # check <meta name=\"description\">\r\n    $description = meta_content $meta 'name' 'description'\r\n    if($description) {\r\n        return $description, '<meta name=\"description\">'\r\n    }\r\n\r\n    # check <meta http-equiv=\"refresh\"> redirect\r\n    $refresh = meta_refresh $meta $url\r\n    if($refresh -and !$redir) {\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $data = $wc.DownloadData($refresh)\r\n        $html = (Get-Encoding($wc)).GetString($data)\r\n        return find_description $refresh $html $true\r\n    }\r\n\r\n    # check text for 'x is ...'\r\n    $text = html_text $html $meta\r\n    $text_desc = find_is $text\r\n    if($text_desc) {\r\n        return $text_desc, 'text'\r\n    }\r\n\r\n    # first paragraph\r\n    $first_para = first_para $html\r\n    if($first_para) {\r\n        return $first_para, 'first <p>'\r\n    }\r\n\r\n    return $null, $null\r\n}\r\n\r\nfunction clean_description($description) {\r\n    if(!$description) { return $description }\r\n    $description = $description -replace '\\n', ' '\r\n    $description = $description -replace '\\s{2,}', ' '\r\n    return $description.trim()\r\n}\r\n\r\n# Collects meta tags from $html into hashtables.\r\nfunction meta_tags($html) {\r\n    $tags = @()\r\n    $meta = ([regex]'<meta [^>]+>').matches($html)\r\n    $meta | ForEach-Object {\r\n        $attrs = ([regex]'([\\w-]+)=\"([^\"]+)\"').matches($_.value)\r\n        $hash = @{}\r\n        $attrs | ForEach-Object {\r\n            $hash[$_.groups[1].value] = $_.groups[2].value\r\n        }\r\n        $tags += $hash\r\n    }\r\n    $tags\r\n}\r\n\r\nfunction meta_content($tags, $attribute, $search) {\r\n    if(!$tags) { return }\r\n    return $tags | Where-Object { $_[$attribute] -eq $search } | ForEach-Object { $_['content'] }\r\n}\r\n\r\n# Looks for a redirect URL in a <meta> refresh tag.\r\nfunction meta_refresh($tags, $url) {\r\n    $refresh = meta_content $tags 'http-equiv' 'refresh'\r\n    if($refresh) {\r\n        if($refresh -match '\\d+;\\s*url\\s*=\\s*(.*)') {\r\n            $refresh_url = $matches[1].trim(\"'\", '\"')\r\n            if($refresh_url -notmatch '^https?://') {\r\n                $refresh_url = \"$url$refresh_url\"\r\n            }\r\n            return $refresh_url\r\n        }\r\n    }\r\n}\r\n\r\nfunction html_body($html) {\r\n    if($html -match '(?s)<body[^>]*>(.*?)</body>') {\r\n        $body = $matches[1]\r\n        $body = $body -replace '(?s)<script[^>]*>.*?</script>', ' '\r\n        $body = $body -replace '(?s)<!--.*?-->', ' '\r\n        return $body\r\n    }\r\n}\r\n\r\nfunction html_text($body, $meta_tags) {\r\n    $body = html_body $html\r\n    if($body) {\r\n        return strip_html $body\r\n    }\r\n}\r\n\r\nfunction strip_html($html) {\r\n    $html = $html -replace '(?s)<[^>]*>', ' '\r\n    $html = $html -replace '\\t', ' '\r\n    $html = $html -replace '&nbsp;?', ' '\r\n    $html = $html -replace '&gt;?', '>'\r\n    $html = $html -replace '&lt;?', '<'\r\n    $html = $html -replace '&quot;?', '\"'\r\n\r\n    $encoding_meta = meta_content $meta_tags 'http-equiv' 'Content-Type'\r\n    if($encoding_meta) {\r\n        if($encoding_meta -match 'charset\\s*=\\s*(.*)') {\r\n            $charset = $matches[1]\r\n            try {\r\n                $encoding = [text.encoding]::getencoding($charset)\r\n            } catch {\r\n                Write-Warning \"Unknown charset\"\r\n            }\r\n            if($encoding) {\r\n                $html = ([regex]'&#(\\d+);?').replace($html, {\r\n                    param($m)\r\n                    try {\r\n                        return $encoding.getstring($m.Groups[1].Value)\r\n                    } catch {\r\n                        return $m.value\r\n                    }\r\n                })\r\n            }\r\n        }\r\n    }\r\n\r\n    $html = $html -replace '\\n +', \"`r`n\"\r\n    $html = $html -replace '\\n{2,}', \"`r`n\"\r\n    $html = $html -replace ' {2,}', ' '\r\n    $html = $html -replace ' (\\.|,)', '$1'\r\n    return $html.trim()\r\n}\r\n\r\nfunction find_is($text) {\r\n    if($text -match '(?s)[\\n\\.]((?:[^\\n\\.])+? is .+?[\\.!])') {\r\n        return $matches[1].trim()\r\n    }\r\n}\r\n\r\nfunction first_para($html) {\r\n    $body = html_body $html\r\n    if($body -match '(?s)<p[^>]*>(.*?)</p>') {\r\n        return strip_html $matches[1]\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/diagnostic.ps1",
    "content": "<#\r\nDiagnostic tests.\r\nReturn $true if the test passed, otherwise $false.\r\nUse 'warn' to highlight the issue, and follow up with the recommended actions to rectify.\r\n#>\r\nfunction check_windows_defender($global) {\r\n    $defender = Get-Service -Name WinDefend -ErrorAction SilentlyContinue\r\n    if (Test-CommandAvailable Get-MpPreference) {\r\n        if ((Get-MpPreference).DisableRealtimeMonitoring) { return $true }\r\n        if ($defender -and $defender.Status) {\r\n            if ($defender.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Running) {\r\n                $installPath = $scoopdir;\r\n                if ($global) { $installPath = $globaldir; }\r\n\r\n                $exclusionPath = (Get-MpPreference).ExclusionPath\r\n                if (!($exclusionPath -contains $installPath)) {\r\n                    info \"Windows Defender may slow down or disrupt installs with realtime scanning.\"\r\n                    Write-Host \"  Consider running:\"\r\n                    Write-Host \"    sudo Add-MpPreference -ExclusionPath '$installPath'\"\r\n                    Write-Host \"  (Requires 'sudo' command. Run 'scoop install sudo' if you don't have it.)\"\r\n                    return $false\r\n                }\r\n            }\r\n        }\r\n    }\r\n    return $true\r\n}\r\n\r\nfunction check_main_bucket {\r\n    if ((Get-LocalBucket) -notcontains 'main') {\r\n        warn 'Main bucket is not added.'\r\n        Write-Host \"  run 'scoop bucket add main'\"\r\n\r\n        return $false\r\n    }\r\n\r\n    return $true\r\n}\r\n\r\nfunction check_long_paths {\r\n    if ([System.Environment]::OSVersion.Version.Major -lt 10 -or [System.Environment]::OSVersion.Version.Build -lt 1607) {\r\n        warn 'This version of Windows does not support configuration of LongPaths.'\r\n        return $false\r\n    }\r\n    $key = Get-ItemProperty 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\FileSystem' -ErrorAction SilentlyContinue -Name 'LongPathsEnabled'\r\n    if (!$key -or ($key.LongPathsEnabled -eq 0)) {\r\n        warn 'LongPaths support is not enabled.'\r\n        Write-Host \"  You can enable it by running:\"\r\n        Write-Host \"    sudo Set-ItemProperty 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\FileSystem' -Name 'LongPathsEnabled' -Value 1\"\r\n        Write-Host \"  (Requires 'sudo' command. Run 'scoop install sudo' if you don't have it.)\"\r\n        return $false\r\n    }\r\n\r\n    return $true\r\n}\r\n\r\nfunction Get-WindowsDeveloperModeStatus {\r\n    $DevModRegistryPath = \"HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock\"\r\n    if (!(Test-Path -Path $DevModRegistryPath) -or (Get-ItemProperty -Path `\r\n        $DevModRegistryPath -Name AllowDevelopmentWithoutDevLicense -ErrorAction `\r\n        SilentlyContinue).AllowDevelopmentWithoutDevLicense -ne 1) {\r\n        warn \"Windows Developer Mode is not enabled. Operations relevant to symlinks may fail without proper rights.\"\r\n        Write-Host \"  You may read more about the symlinks support here:\"\r\n        Write-Host \"  https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/\"\r\n        return $false\r\n    }\r\n\r\n    return $true\r\n}\r\n"
  },
  {
    "path": "lib/download.ps1",
    "content": "# Description: Functions for downloading files\r\n\r\n## Meta downloader\r\n\r\nfunction Invoke-ScoopDownload ($app, $version, $manifest, $bucket, $architecture, $dir, $use_cache = $true, $check_hash = $true) {\r\n    # we only want to show this warning once\r\n    if (!$use_cache) { warn 'Cache is being ignored.' }\r\n\r\n    # can be multiple urls: if there are, then installer should go first to make 'installer.args' section work\r\n    $urls = @(script:url $manifest $architecture)\r\n\r\n    # can be multiple cookies: they will be used for all HTTP requests.\r\n    $cookies = $manifest.cookie\r\n\r\n    # download first\r\n    if (Test-Aria2Enabled) {\r\n        Invoke-CachedAria2Download $app $version $manifest $architecture $dir $cookies $use_cache $check_hash\r\n    } else {\r\n        foreach ($url in $urls) {\r\n            $fname = url_filename $url\r\n\r\n            try {\r\n                Invoke-CachedDownload $app $version $url \"$dir\\$fname\" $cookies $use_cache\r\n            } catch {\r\n                Write-Host -ForegroundColor DarkRed $_\r\n                abort \"URL $url is not valid\"\r\n            }\r\n\r\n            if ($check_hash) {\r\n                $manifest_hash = hash_for_url $manifest $url $architecture\r\n                $ok, $err = check_hash \"$dir\\$fname\" $manifest_hash $(show_app $app $bucket)\r\n                if (!$ok) {\r\n                    error $err\r\n                    $cached = cache_path $app $version $url\r\n                    if (Test-Path $cached) {\r\n                        # rm cached file\r\n                        Remove-Item -Force $cached\r\n                    }\r\n                    if ($url.Contains('sourceforge.net')) {\r\n                        Write-Host -ForegroundColor Yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'\r\n                    }\r\n                    abort $(new_issue_msg $app $bucket 'hash check failed')\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    return $urls.ForEach({ url_filename $_ })\r\n}\r\n\r\n## [System.Net] downloader\r\n\r\nfunction Invoke-CachedDownload ($app, $version, $url, $to, $cookies = $null, $use_cache = $true) {\r\n    $cached = cache_path $app $version $url\r\n\r\n    if (!(Test-Path $cached) -or !$use_cache) {\r\n        ensure $cachedir | Out-Null\r\n        Start-Download $url \"$cached.download\" $cookies\r\n        Move-Item \"$cached.download\" $cached -Force\r\n    } else { Write-Host \"Loading $(url_remote_filename $url) from cache\" }\r\n\r\n    if (!($null -eq $to)) {\r\n        if ($use_cache) {\r\n            Copy-Item $cached $to\r\n        } else {\r\n            Move-Item $cached $to -Force\r\n        }\r\n    }\r\n}\r\n\r\nfunction Start-Download ($url, $to, $cookies) {\r\n    $progress = [console]::isoutputredirected -eq $false -and\r\n    $host.name -ne 'Windows PowerShell ISE Host'\r\n\r\n    try {\r\n        $url = handle_special_urls $url\r\n        Invoke-Download $url $to $cookies $progress\r\n    } catch {\r\n        $e = $_.exception\r\n        if ($e.Response.StatusCode -eq 'Unauthorized') {\r\n            warn 'Token might be misconfigured.'\r\n        }\r\n        if ($e.innerexception) { $e = $e.innerexception }\r\n        throw $e\r\n    }\r\n}\r\n\r\nfunction Invoke-Download ($url, $to, $cookies, $progress) {\r\n    # download with filesize and progress indicator\r\n    $reqUrl = ($url -split '#')[0]\r\n    $wreq = [Net.WebRequest]::Create($reqUrl)\r\n    if ($wreq -is [Net.HttpWebRequest]) {\r\n        $wreq.UserAgent = Get-UserAgent\r\n        if (-not ($url -match 'sourceforge\\.net' -or $url -match 'portableapps\\.com')) {\r\n            $wreq.Referer = strip_filename $url\r\n        }\r\n        if ($url -match 'api\\.github\\.com/repos') {\r\n            $wreq.Accept = 'application/octet-stream'\r\n            $wreq.Headers['Authorization'] = \"Bearer $(Get-GitHubToken)\"\r\n            $wreq.Headers['X-GitHub-Api-Version'] = '2022-11-28'\r\n        }\r\n        if ($cookies) {\r\n            $wreq.Headers.Add('Cookie', (cookie_header $cookies))\r\n        }\r\n\r\n        get_config PRIVATE_HOSTS | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object {\r\n            (ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object {\r\n                $wreq.Headers[$_.Key] = $_.Value\r\n            }\r\n        }\r\n    }\r\n\r\n    try {\r\n        $wres = $wreq.GetResponse()\r\n    } catch [System.Net.WebException] {\r\n        $exc = $_.Exception\r\n        $handledCodes = @(\r\n            [System.Net.HttpStatusCode]::MovedPermanently, # HTTP 301\r\n            [System.Net.HttpStatusCode]::Found, # HTTP 302\r\n            [System.Net.HttpStatusCode]::SeeOther, # HTTP 303\r\n            [System.Net.HttpStatusCode]::TemporaryRedirect  # HTTP 307\r\n        )\r\n\r\n        # Only handle redirection codes\r\n        $redirectRes = $exc.Response\r\n        if ($handledCodes -notcontains $redirectRes.StatusCode) {\r\n            throw $exc\r\n        }\r\n\r\n        # Get the new location of the file\r\n        if ((-not $redirectRes.Headers) -or ($redirectRes.Headers -notcontains 'Location')) {\r\n            throw $exc\r\n        }\r\n\r\n        $newUrl = $redirectRes.Headers['Location']\r\n        info \"Following redirect to $newUrl...\"\r\n\r\n        # Handle manual file rename\r\n        if ($url -like '*#/*') {\r\n            $null, $postfix = $url -split '#/'\r\n            $newUrl = \"$newUrl`#/$postfix\"\r\n        }\r\n\r\n        Invoke-Download $newUrl $to $cookies $progress\r\n        return\r\n    }\r\n\r\n    $total = $wres.ContentLength\r\n    if ($total -eq -1 -and $wreq -is [net.ftpwebrequest]) {\r\n        $total = ftp_file_size($url)\r\n    }\r\n\r\n    if ($progress -and ($total -gt 0)) {\r\n        [console]::CursorVisible = $false\r\n        function Trace-DownloadProgress ($read) {\r\n            Write-DownloadProgress $read $total $url\r\n        }\r\n    } else {\r\n        Write-Host \"Downloading $url ($(filesize $total))...\"\r\n        function Trace-DownloadProgress {\r\n            #no op\r\n        }\r\n    }\r\n\r\n    try {\r\n        $s = $wres.getresponsestream()\r\n        $fs = [io.file]::openwrite($to)\r\n        $buffer = New-Object byte[] 2048\r\n        $totalRead = 0\r\n        $sw = [diagnostics.stopwatch]::StartNew()\r\n\r\n        Trace-DownloadProgress $totalRead\r\n        while (($read = $s.read($buffer, 0, $buffer.length)) -gt 0) {\r\n            $fs.write($buffer, 0, $read)\r\n            $totalRead += $read\r\n            if ($sw.elapsedmilliseconds -gt 100) {\r\n                $sw.restart()\r\n                Trace-DownloadProgress $totalRead\r\n            }\r\n        }\r\n        $sw.stop()\r\n        Trace-DownloadProgress $totalRead\r\n    } finally {\r\n        if ($progress) {\r\n            [console]::CursorVisible = $true\r\n            Write-Host\r\n        }\r\n        if ($fs) {\r\n            $fs.close()\r\n        }\r\n        if ($s) {\r\n            $s.close()\r\n        }\r\n        $wres.close()\r\n    }\r\n}\r\n\r\nfunction Format-DownloadProgress ($url, $read, $total, $console) {\r\n    $filename = url_remote_filename $url\r\n\r\n    # calculate current percentage done\r\n    $p = [math]::Round($read / $total * 100, 0)\r\n\r\n    # pre-generate LHS and RHS of progress string\r\n    # so we know how much space we have\r\n    $left = \"$filename ($(filesize $total))\"\r\n    $right = [string]::Format('{0,3}%', $p)\r\n\r\n    # calculate remaining width for progress bar\r\n    $midwidth = $console.BufferSize.Width - ($left.Length + $right.Length + 8)\r\n\r\n    # calculate how many characters are completed\r\n    $completed = [math]::Abs([math]::Round(($p / 100) * $midwidth, 0) - 1)\r\n\r\n    # generate dashes to symbolise completed\r\n    if ($completed -gt 1) {\r\n        $dashes = [string]::Join('', ((1..$completed) | ForEach-Object { '=' }))\r\n    }\r\n\r\n    # this is why we calculate $completed - 1 above\r\n    $dashes += switch ($p) {\r\n        100 { '=' }\r\n        default { '>' }\r\n    }\r\n\r\n    # the remaining characters are filled with spaces\r\n    $spaces = switch ($dashes.Length) {\r\n        $midwidth { [string]::Empty }\r\n        default {\r\n            [string]::Join('', ((1..($midwidth - $dashes.Length)) | ForEach-Object { ' ' }))\r\n        }\r\n    }\r\n\r\n    \"$left [$dashes$spaces] $right\"\r\n}\r\n\r\nfunction Write-DownloadProgress ($read, $total, $url) {\r\n    $console = $Host.UI.RawUI\r\n    $left = $console.CursorPosition.X\r\n    $top = $console.CursorPosition.Y\r\n    $width = $console.BufferSize.Width\r\n\r\n    if ($read -eq 0) {\r\n        $maxOutputLength = $(Format-DownloadProgress $url 100 $total $console).Length\r\n        if (($left + $maxOutputLength) -gt $width) {\r\n            # not enough room to print progress on this line\r\n            # print on new line\r\n            Write-Host\r\n            $left = 0\r\n            $top = $top + 1\r\n            if ($top -gt $console.CursorPosition.Y) { $top = $console.CursorPosition.Y }\r\n        }\r\n    }\r\n\r\n    Write-Host $(Format-DownloadProgress $url $read $total $console) -NoNewline\r\n    [console]::SetCursorPosition($left, $top)\r\n}\r\n\r\n## Aria2 downloader\r\n\r\nfunction Test-Aria2Enabled {\r\n    return (Test-HelperInstalled -Helper Aria2) -and (get_config 'aria2-enabled' $true)\r\n}\r\n\r\nfunction aria_exit_code($exitcode) {\r\n    $codes = @{\r\n        0  = 'All downloads were successful'\r\n        1  = 'An unknown error occurred'\r\n        2  = 'Timeout'\r\n        3  = 'Resource was not found'\r\n        4  = 'Aria2 saw the specified number of \"resource not found\" error. See --max-file-not-found option'\r\n        5  = 'Download aborted because download speed was too slow. See --lowest-speed-limit option'\r\n        6  = 'Network problem occurred.'\r\n        7  = 'There were unfinished downloads. This error is only reported if all finished downloads were successful and there were unfinished downloads in a queue when aria2 exited by pressing Ctrl-C by an user or sending TERM or INT signal'\r\n        8  = 'Remote server did not support resume when resume was required to complete download'\r\n        9  = 'There was not enough disk space available'\r\n        10 = 'Piece length was different from one in .aria2 control file. See --allow-piece-length-change option'\r\n        11 = 'Aria2 was downloading same file at that moment'\r\n        12 = 'Aria2 was downloading same info hash torrent at that moment'\r\n        13 = 'File already existed. See --allow-overwrite option'\r\n        14 = 'Renaming file failed. See --auto-file-renaming option'\r\n        15 = 'Aria2 could not open existing file'\r\n        16 = 'Aria2 could not create new file or truncate existing file'\r\n        17 = 'File I/O error occurred'\r\n        18 = 'Aria2 could not create directory'\r\n        19 = 'Name resolution failed'\r\n        20 = 'Aria2 could not parse Metalink document'\r\n        21 = 'FTP command failed'\r\n        22 = 'HTTP response header was bad or unexpected'\r\n        23 = 'Too many redirects occurred'\r\n        24 = 'HTTP authorization failed'\r\n        25 = 'Aria2 could not parse bencoded file (usually \".torrent\" file)'\r\n        26 = '\".torrent\" file was corrupted or missing information that aria2 needed'\r\n        27 = 'Magnet URI was bad'\r\n        28 = 'Bad/unrecognized option was given or unexpected option argument was given'\r\n        29 = 'The remote server was unable to handle the request due to a temporary overloading or maintenance'\r\n        30 = 'Aria2 could not parse JSON-RPC request'\r\n        31 = 'Reserved. Not used'\r\n        32 = 'Checksum validation failed'\r\n    }\r\n    if ($null -eq $codes[$exitcode]) {\r\n        return 'An unknown error occurred'\r\n    }\r\n    return $codes[$exitcode]\r\n}\r\n\r\nfunction get_filename_from_metalink($file) {\r\n    $bytes = get_magic_bytes_pretty $file ''\r\n    # check if file starts with '<?xml'\r\n    if (!($bytes.StartsWith('3c3f786d6c'))) {\r\n        return $null\r\n    }\r\n\r\n    # Add System.Xml for reading metalink files\r\n    Add-Type -AssemblyName 'System.Xml'\r\n    $xr = [System.Xml.XmlReader]::Create($file)\r\n    $filename = $null\r\n    try {\r\n        $xr.ReadStartElement('metalink')\r\n        if ($xr.ReadToFollowing('file') -and $xr.MoveToFirstAttribute()) {\r\n            $filename = $xr.Value\r\n        }\r\n    } catch [System.Xml.XmlException] {\r\n        return $null\r\n    } finally {\r\n        $xr.Close()\r\n    }\r\n\r\n    return $filename\r\n}\r\n\r\nfunction Invoke-CachedAria2Download ($app, $version, $manifest, $architecture, $dir, $cookies = $null, $use_cache = $true, $check_hash = $true) {\r\n    $data = @{}\r\n    $urls = @(script:url $manifest $architecture)\r\n\r\n    # aria2 input file\r\n    $urlstxt = Join-Path $cachedir \"$app.txt\"\r\n    $urlstxt_content = ''\r\n    $download_finished = $true\r\n\r\n    # aria2 options\r\n    $options = @(\r\n        \"--input-file='$urlstxt'\"\r\n        \"--user-agent='$(Get-UserAgent)'\"\r\n        '--allow-overwrite=true'\r\n        '--auto-file-renaming=false'\r\n        \"--retry-wait=$(get_config 'aria2-retry-wait' 2)\"\r\n        \"--split=$(get_config 'aria2-split' 5)\"\r\n        \"--max-connection-per-server=$(get_config 'aria2-max-connection-per-server' 5)\"\r\n        \"--min-split-size=$(get_config 'aria2-min-split-size' '5M')\"\r\n        '--console-log-level=warn'\r\n        '--enable-color=false'\r\n        '--no-conf=true'\r\n        '--follow-metalink=true'\r\n        '--metalink-preferred-protocol=https'\r\n        '--min-tls-version=TLSv1.2'\r\n        \"--stop-with-process=$PID\"\r\n        '--continue'\r\n        '--summary-interval=0'\r\n        '--auto-save-interval=1'\r\n    )\r\n\r\n    if ($cookies) {\r\n        $options += \"--header='Cookie: $(cookie_header $cookies)'\"\r\n    }\r\n\r\n    $proxy = get_config PROXY\r\n    if ($proxy -ne 'none') {\r\n        if ([Net.Webrequest]::DefaultWebProxy.Address) {\r\n            $options += \"--all-proxy='$([Net.Webrequest]::DefaultWebProxy.Address.Authority)'\"\r\n        }\r\n        if ([Net.Webrequest]::DefaultWebProxy.Credentials.UserName) {\r\n            $options += \"--all-proxy-user='$([Net.Webrequest]::DefaultWebProxy.Credentials.UserName)'\"\r\n        }\r\n        if ([Net.Webrequest]::DefaultWebProxy.Credentials.Password) {\r\n            $options += \"--all-proxy-passwd='$([Net.Webrequest]::DefaultWebProxy.Credentials.Password)'\"\r\n        }\r\n    }\r\n\r\n    $more_options = get_config 'aria2-options'\r\n    if ($more_options) {\r\n        $options += $more_options\r\n    }\r\n\r\n    foreach ($url in $urls) {\r\n        $data.$url = @{\r\n            'target'    = Join-Path $dir (url_filename $url)\r\n            'cachename' = fname (cache_path $app $version $url)\r\n            'source'    = cache_path $app $version $url\r\n        }\r\n\r\n        if ((Test-Path $data.$url.source) -and -not((Test-Path \"$($data.$url.source).aria2\") -or (Test-Path $urlstxt)) -and $use_cache) {\r\n            Write-Host 'Loading ' -NoNewline\r\n            Write-Host $(url_remote_filename $url) -ForegroundColor Cyan -NoNewline\r\n            Write-Host ' from cache.'\r\n        } else {\r\n            $download_finished = $false\r\n            # create aria2 input file content\r\n            try {\r\n                $try_url = handle_special_urls $url\r\n            } catch {\r\n                if ($_.Exception.Response.StatusCode -eq 'Unauthorized') {\r\n                    warn 'Token might be misconfigured.'\r\n                }\r\n            }\r\n            $urlstxt_content += \"$try_url`n\"\r\n            if (!$url.Contains('sourceforge.net')) {\r\n                $urlstxt_content += \"    referer=$(strip_filename $url)`n\"\r\n            }\r\n            $urlstxt_content += \"    dir=$cachedir`n\"\r\n            $urlstxt_content += \"    out=$($data.$url.cachename)`n\"\r\n        }\r\n    }\r\n\r\n    if (-not($download_finished)) {\r\n        # write aria2 input file\r\n        if ($urlstxt_content -ne '') {\r\n            ensure $cachedir | Out-Null\r\n            # Write aria2 input-file with UTF8NoBOM encoding\r\n            $urlstxt_content | Out-UTF8File -FilePath $urlstxt\r\n        }\r\n\r\n        # build aria2 command\r\n        $aria2 = \"& '$(Get-HelperPath -Helper Aria2)' $($options -join ' ')\"\r\n\r\n        # handle aria2 console output\r\n        Write-Host 'Starting download with aria2 ...'\r\n\r\n        # Set console output encoding to UTF8 for non-ASCII characters printing\r\n        $oriConsoleEncoding = [Console]::OutputEncoding\r\n        [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding\r\n\r\n        Invoke-Command ([scriptblock]::Create($aria2)) | ForEach-Object {\r\n            # Skip blank lines\r\n            if ([String]::IsNullOrWhiteSpace($_)) { return }\r\n\r\n            # Prevent potential overlaping of text when one line is shorter\r\n            $len = $Host.UI.RawUI.WindowSize.Width - $_.Length - 20\r\n            $blank = if ($len -gt 0) { ' ' * $len } else { '' }\r\n            $color = 'Gray'\r\n\r\n            if ($_.StartsWith('(OK):')) {\r\n                $noNewLine = $true\r\n                $color = 'Green'\r\n            } elseif ($_.StartsWith('[') -and $_.EndsWith(']')) {\r\n                $noNewLine = $true\r\n                $color = 'Cyan'\r\n            } elseif ($_.StartsWith('Download Results:')) {\r\n                $noNewLine = $false\r\n            }\r\n\r\n            Write-Host \"`rDownload: $_$blank\" -ForegroundColor $color -NoNewline:$noNewLine\r\n        }\r\n        Write-Host ''\r\n\r\n        if ($lastexitcode -gt 0) {\r\n            warn \"Download failed! (Error $lastexitcode) $(aria_exit_code $lastexitcode)\"\r\n            warn $urlstxt_content\r\n            warn $aria2\r\n            warn $(new_issue_msg $app $bucket \"download via aria2 failed\")\r\n\r\n            Write-Host \"Fallback to default downloader ...\"\r\n\r\n            try {\r\n                foreach ($url in $urls) {\r\n                    Invoke-CachedDownload $app $version $url \"$($data.$url.target)\" $cookies $use_cache\r\n                }\r\n            } catch {\r\n                Write-Host $_ -ForegroundColor DarkRed\r\n                abort \"URL $url is not valid\"\r\n            }\r\n        }\r\n\r\n        # remove aria2 input file when done\r\n        if (Test-Path $urlstxt, \"$($data.$url.source).aria2*\") {\r\n            Remove-Item $urlstxt -Force -ErrorAction SilentlyContinue\r\n            Remove-Item \"$($data.$url.source).aria2*\" -Force -ErrorAction SilentlyContinue\r\n        }\r\n\r\n        # Revert console encoding\r\n        [Console]::OutputEncoding = $oriConsoleEncoding\r\n    }\r\n\r\n    foreach ($url in $urls) {\r\n\r\n        $metalink_filename = get_filename_from_metalink $data.$url.source\r\n        if ($metalink_filename) {\r\n            Remove-Item $data.$url.source -Force\r\n            Rename-Item -Force (Join-Path -Path $cachedir -ChildPath $metalink_filename) $data.$url.source\r\n        }\r\n\r\n        # run hash checks\r\n        if ($check_hash) {\r\n            $manifest_hash = hash_for_url $manifest $url $architecture\r\n            $ok, $err = check_hash $data.$url.source $manifest_hash $(show_app $app $bucket)\r\n            if (!$ok) {\r\n                error $err\r\n                if (Test-Path $data.$url.source) {\r\n                    # rm cached file\r\n                    Remove-Item $data.$url.source -Force -ErrorAction SilentlyContinue\r\n                    Remove-Item \"$($data.$url.source).aria2*\" -Force -ErrorAction SilentlyContinue\r\n                }\r\n                if ($url.Contains('sourceforge.net')) {\r\n                    Write-Host -f yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'\r\n                }\r\n                abort $(new_issue_msg $app $bucket 'hash check failed')\r\n            }\r\n        }\r\n\r\n        # copy or move file to target location\r\n        if (!(Test-Path $data.$url.source) ) {\r\n            abort $(new_issue_msg $app $bucket 'cached file not found')\r\n        }\r\n\r\n        if (!($dir -eq $cachedir)) {\r\n            if ($use_cache) {\r\n                Copy-Item $data.$url.source $data.$url.target\r\n            } else {\r\n                Move-Item $data.$url.source $data.$url.target -Force\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n## Helper functions\r\n\r\n### Downloader parameters\r\n\r\nfunction cookie_header($cookies) {\r\n    if (!$cookies) { return }\r\n\r\n    $vals = $cookies.psobject.properties | ForEach-Object {\r\n        \"$($_.name)=$($_.value)\"\r\n    }\r\n\r\n    [string]::join(';', $vals)\r\n}\r\n\r\nfunction Get-Encoding($wc) {\r\n    if ($null -ne $wc.ResponseHeaders -and $wc.ResponseHeaders['Content-Type'] -match 'charset=([^;]*)') {\r\n        return [System.Text.Encoding]::GetEncoding($Matches[1])\r\n    } else {\r\n        return [System.Text.Encoding]::GetEncoding('utf-8')\r\n    }\r\n}\r\n\r\nfunction Get-UserAgent() {\r\n    return \"Scoop/1.0 (+http://scoop.sh/) PowerShell/$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) (Windows NT $([System.Environment]::OSVersion.Version.Major).$([System.Environment]::OSVersion.Version.Minor); $(if(${env:ProgramFiles(Arm)}){'ARM64; '}elseif($env:PROCESSOR_ARCHITECTURE -eq 'AMD64'){'Win64; x64; '})$(if($env:PROCESSOR_ARCHITEW6432 -in 'AMD64','ARM64'){'WOW64; '})$PSEdition)\"\r\n}\r\n\r\nfunction setup_proxy() {\r\n    # note: '@' and ':' in password must be escaped, e.g. 'p@ssword' -> p\\@ssword'\r\n    $proxy = get_config PROXY\r\n    if (!$proxy) {\r\n        return\r\n    }\r\n    try {\r\n        $credentials, $address = $proxy -split '(?<!\\\\)@'\r\n        if (!$address) {\r\n            $address, $credentials = $credentials, $null # no credentials supplied\r\n        }\r\n\r\n        if ($address -eq 'none') {\r\n            [net.webrequest]::defaultwebproxy = $null\r\n        } elseif ($address -ne 'default') {\r\n            [net.webrequest]::defaultwebproxy = New-Object net.webproxy \"http://$address\"\r\n        }\r\n\r\n        if ($credentials -eq 'currentuser') {\r\n            [net.webrequest]::defaultwebproxy.credentials = [net.credentialcache]::defaultcredentials\r\n        } elseif ($credentials) {\r\n            $username, $password = $credentials -split '(?<!\\\\):' | ForEach-Object { $_ -replace '\\\\([@:])', '$1' }\r\n            [net.webrequest]::defaultwebproxy.credentials = New-Object net.networkcredential($username, $password)\r\n        }\r\n    } catch {\r\n        warn \"Failed to use proxy '$proxy': $($_.exception.message)\"\r\n    }\r\n}\r\n\r\nfunction Get-GitHubToken {\r\n    return $env:SCOOP_GH_TOKEN, (get_config GH_TOKEN) | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1\r\n}\r\n\r\nfunction github_ratelimit_reached {\r\n    $api_link = 'https://api.github.com/rate_limit'\r\n    $ret = (download_json $api_link).rate.remaining -eq 0\r\n    if ($ret) {\r\n        Write-Host \"GitHub API rate limit reached.`r`nPlease try again later or configure your API token using 'scoop config gh_token <your token>'.\"\r\n    }\r\n    $ret\r\n}\r\n\r\n### URL handling\r\n\r\nfunction handle_special_urls($url) {\r\n    # FossHub.com\r\n    if ($url -match '^(?:.*fosshub.com\\/)(?<name>.*)(?:\\/|\\?dwl=)(?<filename>.*)$') {\r\n        $Body = @{\r\n            projectUri      = $Matches.name\r\n            fileName        = $Matches.filename\r\n            source          = 'CF'\r\n            isLatestVersion = $true\r\n        }\r\n        if ((Invoke-RestMethod -Uri $url) -match '\"p\":\"(?<pid>[a-f0-9]{24}).*?\"r\":\"(?<rid>[a-f0-9]{24})') {\r\n            $Body.Add('projectId', $Matches.pid)\r\n            $Body.Add('releaseId', $Matches.rid)\r\n        }\r\n        $url = Invoke-RestMethod -Method Post -Uri 'https://api.fosshub.com/download/' -ContentType 'application/json' -Body (ConvertTo-Json $Body -Compress)\r\n        if ($null -eq $url.error) {\r\n            $url = $url.data.url\r\n        }\r\n    }\r\n\r\n    # Sourceforge.net\r\n    if ($url -match '(?:downloads\\.)?sourceforge.net\\/projects?\\/(?<project>[^\\/]+)\\/(?:files\\/)?(?<file>.*?)(?:$|\\/download|\\?)') {\r\n        # Reshapes the URL to avoid redirections\r\n        $url = \"https://downloads.sourceforge.net/project/$($matches['project'])/$($matches['file'])\"\r\n    }\r\n\r\n    # Github.com\r\n    if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = Get-GitHubToken)) {\r\n        $headers = @{ 'Authorization' = \"token $token\" }\r\n        $privateUrl = \"https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)\"\r\n        $assetUrl = \"https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)/releases/tags/$($Matches.tag)\"\r\n\r\n        if ((Invoke-RestMethod -Uri $privateUrl -Headers $headers).Private) {\r\n            $url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).Assets | Where-Object -Property Name -EQ -Value $Matches.file).Url, $Matches.filename -join ''\r\n        }\r\n    }\r\n\r\n    return $url\r\n}\r\n\r\n### Remote file information\r\n\r\nfunction download_json($url) {\r\n    $githubtoken = Get-GitHubToken\r\n    $authheader = @{}\r\n    if ($githubtoken) {\r\n        $authheader = @{'Authorization' = \"token $githubtoken\" }\r\n    }\r\n    $ProgressPreference = 'SilentlyContinue'\r\n    $result = Invoke-WebRequest $url -UseBasicParsing -Headers $authheader | Select-Object -ExpandProperty content | ConvertFrom-Json\r\n    $ProgressPreference = 'Continue'\r\n    $result\r\n}\r\n\r\nfunction get_magic_bytes($file) {\r\n    if (!(Test-Path $file)) {\r\n        return ''\r\n    }\r\n\r\n    if ((Get-Command Get-Content).parameters.ContainsKey('AsByteStream')) {\r\n        # PowerShell Core (6.0+) '-Encoding byte' is replaced by '-AsByteStream'\r\n        return Get-Content $file -AsByteStream -TotalCount 8\r\n    } else {\r\n        return Get-Content $file -Encoding byte -TotalCount 8\r\n    }\r\n}\r\n\r\nfunction get_magic_bytes_pretty($file, $glue = ' ') {\r\n    if (!(Test-Path $file)) {\r\n        return ''\r\n    }\r\n\r\n    return (get_magic_bytes $file | ForEach-Object { $_.ToString('x2') }) -join $glue\r\n}\r\n\r\nFunction Get-RemoteFileSize ($Uri) {\r\n    $response = Invoke-WebRequest -Uri $Uri -Method HEAD -UseBasicParsing\r\n    if (!$response.Headers.StatusCode) {\r\n        $response.Headers.'Content-Length' | ForEach-Object { [int]$_ }\r\n    }\r\n}\r\n\r\nfunction ftp_file_size($url) {\r\n    $request = [net.ftpwebrequest]::create($url)\r\n    $request.method = [net.webrequestmethods+ftp]::getfilesize\r\n    $request.getresponse().contentlength\r\n}\r\n\r\nfunction url_filename($url) {\r\n    (Split-Path $url -Leaf).split('?') | Select-Object -First 1\r\n}\r\n\r\nfunction url_remote_filename($url) {\r\n    # Unlike url_filename which can be tricked by appending a\r\n    # URL fragment (e.g. #/dl.7z, useful for coercing a local filename),\r\n    # this function extracts the original filename from the URL.\r\n    $uri = (New-Object URI $url)\r\n    $basename = Split-Path $uri.PathAndQuery -Leaf\r\n    If ($basename -match '.*[?=]+([\\w._-]+)') {\r\n        $basename = $matches[1]\r\n    }\r\n    If (($basename -notlike '*.*') -or ($basename -match '^[v.\\d]+$')) {\r\n        $basename = Split-Path $uri.AbsolutePath -Leaf\r\n    }\r\n    If (($basename -notlike '*.*') -and ($uri.Fragment -ne '')) {\r\n        $basename = $uri.Fragment.Trim('/', '#')\r\n    }\r\n    return $basename\r\n}\r\n\r\n### Hash-related functions\r\n\r\nfunction hash_for_url($manifest, $url, $arch) {\r\n    $hashes = @(hash $manifest $arch) | Where-Object { $_ -ne $null }\r\n\r\n    if ($hashes.length -eq 0) { return $null }\r\n\r\n    $urls = @(script:url $manifest $arch)\r\n\r\n    $index = [array]::IndexOf($urls, $url)\r\n    if ($index -eq -1) { abort \"Couldn't find hash in manifest for '$url'.\" }\r\n\r\n    @($hashes)[$index]\r\n}\r\n\r\nfunction check_hash($file, $hash, $app_name) {\r\n    # returns (ok, err)\r\n    if (!$hash) {\r\n        warn \"Warning: No hash in manifest. SHA256 for '$(fname $file)' is:`n    $((Get-FileHash -Path $file -Algorithm SHA256).Hash.ToLower())\"\r\n        return $true, $null\r\n    }\r\n\r\n    Write-Host 'Checking hash of ' -NoNewline\r\n    Write-Host $(url_remote_filename $url) -ForegroundColor Cyan -NoNewline\r\n    Write-Host ' ... ' -NoNewline\r\n    $algorithm, $expected = get_hash $hash\r\n    if ($null -eq $algorithm) {\r\n        return $false, \"Hash type '$algorithm' isn't supported.\"\r\n    }\r\n\r\n    $actual = (Get-FileHash -Path $file -Algorithm $algorithm).Hash.ToLower()\r\n    $expected = $expected.ToLower()\r\n\r\n    if ($actual -ne $expected) {\r\n        $msg = \"Hash check failed!`n\"\r\n        $msg += \"App:         $app_name`n\"\r\n        $msg += \"URL:         $url`n\"\r\n        if (Test-Path $file) {\r\n            $msg += \"First bytes: $((get_magic_bytes_pretty $file ' ').ToUpper())`n\"\r\n        }\r\n        if ($expected -or $actual) {\r\n            $msg += \"Expected:    $expected`n\"\r\n            $msg += \"Actual:      $actual\"\r\n        }\r\n        return $false, $msg\r\n    }\r\n    Write-Host 'ok.' -f Green\r\n    return $true, $null\r\n}\r\n\r\nfunction get_hash([String] $multihash) {\r\n    $type, $hash = $multihash -split ':'\r\n    if (!$hash) {\r\n        # no type specified, assume sha256\r\n        $type, $hash = 'sha256', $multihash\r\n    }\r\n\r\n    if (@('md5', 'sha1', 'sha256', 'sha512') -notcontains $type) {\r\n        return $null, \"Hash type '$type' isn't supported.\"\r\n    }\r\n\r\n    return $type, $hash.ToLower()\r\n}\r\n\r\n# Setup proxy globally\r\nsetup_proxy\r\n"
  },
  {
    "path": "lib/getopt.ps1",
    "content": "# adapted from http://hg.python.org/cpython/file/2.7/Lib/getopt.py\r\n# argv:\r\n#    array of arguments\r\n# shortopts:\r\n#    string of single-letter options. options that take a parameter\r\n#    should be follow by ':'\r\n# longopts:\r\n#    array of strings that are long-form options. options that take\r\n#    a parameter should end with '='\r\n# returns @(opts hash, remaining_args array, error string)\r\n# NOTES:\r\n#    The first \"--\" in $argv, if any, will terminate all options; any\r\n# following arguments are treated as non-option arguments, even if\r\n# they begin with a hyphen. The \"--\" itself will not be included in\r\n# the returned $opts. (POSIX-compatible)\r\nfunction getopt([String[]]$argv, [String]$shortopts, [String[]]$longopts) {\r\n    $opts = @{}; $rem = @()\r\n\r\n    function err($msg) {\r\n        $opts, $rem, $msg\r\n    }\r\n\r\n    function regex_escape($str) {\r\n        return [Regex]::Escape($str)\r\n    }\r\n\r\n    for ($i = 0; $i -lt $argv.Length; $i++) {\r\n        $arg = $argv[$i]\r\n        if ($null -eq $arg) { continue }\r\n        # don't try to parse array arguments\r\n        if ($arg -is [Array]) { $rem += , $arg; continue }\r\n        if ($arg -is [Int]) { $rem += $arg; continue }\r\n        if ($arg -is [Decimal]) { $rem += $arg; continue }\r\n\r\n        if ($arg -eq '--') {\r\n            if ($i -lt $argv.Length - 1) {\r\n                $rem += $argv[($i + 1)..($argv.Length - 1)]\r\n            }\r\n            break\r\n        } elseif ($arg.StartsWith('--')) {\r\n            $name = $arg.Substring(2)\r\n\r\n            $longopt = $longopts | Where-Object { $_ -match \"^$name=?$\" }\r\n\r\n            if ($longopt) {\r\n                if ($longopt.EndsWith('=')) {\r\n                    # requires arg\r\n                    if ($i -eq $argv.Length - 1) {\r\n                        return err \"Option --$name requires an argument.\"\r\n                    }\r\n                    $opts.$name = $argv[++$i]\r\n                } else {\r\n                    $opts.$name = $true\r\n                }\r\n            } else {\r\n                return err \"Option --$name not recognized.\"\r\n            }\r\n        } elseif ($arg.StartsWith('-') -and $arg -ne '-') {\r\n            for ($j = 1; $j -lt $arg.Length; $j++) {\r\n                $letter = $arg[$j].ToString()\r\n\r\n                if ($shortopts -match \"$(regex_escape $letter)`:?\") {\r\n                    $shortopt = $Matches[0]\r\n                    if ($shortopt[1] -eq ':') {\r\n                        if ($j -ne $arg.Length - 1 -or $i -eq $argv.Length - 1) {\r\n                            return err \"Option -$letter requires an argument.\"\r\n                        }\r\n                        $opts.$letter = $argv[++$i]\r\n                    } else {\r\n                        $opts.$letter = $true\r\n                    }\r\n                } else {\r\n                    return err \"Option -$letter not recognized.\"\r\n                }\r\n            }\r\n        } else {\r\n            $rem += $arg\r\n        }\r\n    }\r\n    $opts, $rem\r\n}\r\n"
  },
  {
    "path": "lib/help.ps1",
    "content": "function usage($text) {\r\n    $text | Select-String '(?m)^# Usage: ([^\\n]*)$' | ForEach-Object { \"Usage: \" + $_.matches[0].groups[1].value }\r\n}\r\n\r\nfunction summary($text) {\r\n    $text | Select-String '(?m)^# Summary: ([^\\n]*)$' | ForEach-Object { $_.matches[0].groups[1].value }\r\n}\r\n\r\nfunction scoop_help($text) {\r\n    $help_lines = $text | Select-String '(?ms)^# Help:(.(?!^[^#]))*' | ForEach-Object { $_.matches[0].value; }\r\n    $help_lines -replace '(?ms)^#\\s?(Help: )?', ''\r\n}\r\n\r\nfunction my_usage { # gets usage for the calling script\r\n    usage (Get-Content $myInvocation.PSCommandPath -raw)\r\n}\r\n"
  },
  {
    "path": "lib/install.ps1",
    "content": "function nightly_version($quiet = $false) {\r\n    if (!$quiet) {\r\n        warn \"This is a nightly version. Downloaded files won't be verified.\"\r\n    }\r\n    return \"nightly-$(Get-Date -Format 'yyyyMMdd')\"\r\n}\r\n\r\nfunction install_app($app, $architecture, $global, $suggested, $use_cache = $true, $check_hash = $true) {\r\n    $app, $manifest, $bucket, $url = Get-Manifest $app\r\n\r\n    if (!$manifest) {\r\n        abort \"Couldn't find manifest for '$app'$(if ($bucket) { \" from '$bucket' bucket\" } elseif ($url) { \" at '$url'\" }).\"\r\n    }\r\n\r\n    $version = $manifest.version\r\n    if (!$version) { abort \"Manifest doesn't specify a version.\" }\r\n    if ($version -match '[^\\w\\.\\-\\+_]') {\r\n        abort \"Manifest version has unsupported character '$($matches[0])'.\"\r\n    }\r\n\r\n    $is_nightly = $version -eq 'nightly'\r\n    if ($is_nightly) {\r\n        $version = nightly_version\r\n        $check_hash = $false\r\n    }\r\n\r\n    $architecture = Get-SupportedArchitecture $manifest $architecture\r\n    if ($null -eq $architecture) {\r\n        error \"'$app' doesn't support current architecture!\"\r\n        return\r\n    }\r\n\r\n    if ((get_config SHOW_MANIFEST $false) -and ($MyInvocation.ScriptName -notlike '*scoop-update*')) {\r\n        Write-Host \"Manifest: $app.json\"\r\n        $style = get_config CAT_STYLE\r\n        if ($style) {\r\n            $manifest | ConvertToPrettyJson | bat --no-paging --style $style --language json\r\n        } else {\r\n            $manifest | ConvertToPrettyJson\r\n        }\r\n        $answer = Read-Host -Prompt 'Continue installation? [Y/n]'\r\n        if (($answer -eq 'n') -or ($answer -eq 'N')) {\r\n            return\r\n        }\r\n    }\r\n    Write-Output \"Installing '$app' ($version) [$architecture]$(if ($bucket) { \" from '$bucket' bucket\" } else { \" from '$url'\" })\"\r\n\r\n    $dir = ensure (versiondir $app $version $global)\r\n    $original_dir = $dir # keep reference to real (not linked) directory\r\n    $persist_dir = persistdir $app $global\r\n\r\n    $fname = Invoke-ScoopDownload $app $version $manifest $bucket $architecture $dir $use_cache $check_hash\r\n    Invoke-Extraction -Path $dir -Name $fname -Manifest $manifest -ProcessorArchitecture $architecture\r\n    Invoke-HookScript -HookType 'pre_install' -Manifest $manifest -ProcessorArchitecture $architecture\r\n\r\n    Invoke-Installer -Path $dir -Name $fname -Manifest $manifest -ProcessorArchitecture $architecture -AppName $app -Global:$global\r\n    ensure_install_dir_not_in_path $dir $global\r\n    $dir = link_current $dir\r\n    create_shims $manifest $dir $global $architecture\r\n    create_startmenu_shortcuts $manifest $dir $global $architecture\r\n    install_psmodule $manifest $dir $global\r\n    env_add_path $manifest $dir $global $architecture\r\n    env_set $manifest $global $architecture\r\n\r\n    # persist data\r\n    persist_data $manifest $original_dir $persist_dir\r\n    persist_permission $manifest $global\r\n\r\n    Invoke-HookScript -HookType 'post_install' -Manifest $manifest -ProcessorArchitecture $architecture\r\n\r\n    # save info for uninstall\r\n    save_installed_manifest $app $bucket $dir $url\r\n    save_install_info @{ 'architecture' = $architecture; 'url' = $url; 'bucket' = $bucket } $dir\r\n\r\n    if ($manifest.suggest) {\r\n        $suggested[$app] = $manifest.suggest\r\n    }\r\n\r\n    success \"'$app' ($version) was installed successfully!\"\r\n\r\n    show_notes $manifest $dir $original_dir $persist_dir\r\n}\r\n\r\nfunction is_in_dir($dir, $check) {\r\n    $check -match \"^$([regex]::Escape(\"$dir\"))([/\\\\]|$)\"\r\n}\r\n\r\nfunction Invoke-Installer {\r\n    [CmdletBinding()]\r\n    param (\r\n        [string]\r\n        $Path,\r\n        [string[]]\r\n        $Name,\r\n        [psobject]\r\n        $Manifest,\r\n        [Alias('Arch', 'Architecture')]\r\n        [ValidateSet('32bit', '64bit', 'arm64')]\r\n        [string]\r\n        $ProcessorArchitecture,\r\n        [string]\r\n        $AppName,\r\n        [switch]\r\n        $Global,\r\n        [switch]\r\n        $Uninstall\r\n    )\r\n    $type = if ($Uninstall) { 'uninstaller' } else { 'installer' }\r\n    $installer = arch_specific $type $Manifest $ProcessorArchitecture\r\n    if ($installer.file -or $installer.args) {\r\n        # Installer filename is either explicit defined ('installer.file') or file name in the first URL\r\n        if (!$Name) {\r\n            $Name = url_filename @(url $manifest $architecture)\r\n        }\r\n        $progName = \"$Path\\$(coalesce $installer.file $Name[0])\"\r\n        if (!(is_in_dir $Path $progName)) {\r\n            abort \"Error in manifest: $((Get-Culture).TextInfo.ToTitleCase($type)) $progName is outside the app directory.\"\r\n        } elseif (!(Test-Path $progName)) {\r\n            abort \"$((Get-Culture).TextInfo.ToTitleCase($type)) $progName is missing.\"\r\n        }\r\n        $substitutions = @{\r\n            '$dir'     = $Path\r\n            '$global'  = $Global\r\n            '$version' = $Manifest.version\r\n        }\r\n        $fnArgs = substitute $installer.args $substitutions\r\n        if ($progName.EndsWith('.ps1')) {\r\n            & $progName @fnArgs\r\n        } else {\r\n            $status = Invoke-ExternalCommand $progName -ArgumentList $fnArgs -Activity \"Running $type ...\"\r\n            if (!$status) {\r\n                if ($Uninstall) {\r\n                    abort 'Uninstallation aborted.'\r\n                } else {\r\n                    abort \"Installation aborted. You might need to run 'scoop uninstall $AppName' before trying again.\"\r\n                }\r\n            }\r\n            # Don't remove installer if \"keep\" flag is set to true\r\n            if (!$installer.keep) {\r\n                Remove-Item $progName\r\n            }\r\n        }\r\n    }\r\n    Invoke-HookScript -HookType $type -Manifest $Manifest -ProcessorArchitecture $ProcessorArchitecture\r\n}\r\n\r\nfunction Invoke-HookScript {\r\n    [CmdletBinding()]\r\n    param(\r\n        [Parameter(Mandatory = $true)]\r\n        [ValidateSet('installer', 'pre_install', 'post_install', 'uninstaller', 'pre_uninstall', 'post_uninstall')]\r\n        [String] $HookType,\r\n        [Parameter(Mandatory = $true)]\r\n        [ValidateNotNullOrEmpty()]\r\n        [PSCustomObject] $Manifest,\r\n        [Parameter(Mandatory = $true)]\r\n        [Alias('Arch', 'Architecture')]\r\n        [ValidateSet('32bit', '64bit', 'arm64')]\r\n        [string]\r\n        $ProcessorArchitecture\r\n    )\r\n\r\n    $script = arch_specific $HookType $Manifest $ProcessorArchitecture\r\n    if ($HookType -in @('installer', 'uninstaller')) {\r\n        $script = $script.script\r\n    }\r\n    if ($script) {\r\n        Write-Host \"Running $HookType script...\" -NoNewline\r\n        Invoke-Command ([scriptblock]::Create($script -join \"`r`n\"))\r\n        Write-Host 'done.' -ForegroundColor Green\r\n    }\r\n}\r\n\r\n# get target, name, arguments for shim\r\nfunction shim_def($item) {\r\n    if ($item -is [array]) { return $item }\r\n    return $item, (strip_ext (fname $item)), $null\r\n}\r\n\r\nfunction create_shims($manifest, $dir, $global, $arch) {\r\n    $shims = @(arch_specific 'bin' $manifest $arch)\r\n    $shims | Where-Object { $_ -ne $null } | ForEach-Object {\r\n        $target, $name, $arg = shim_def $_\r\n        Write-Output \"Creating shim for '$name'.\"\r\n\r\n        if (Test-Path \"$dir\\$target\" -PathType leaf) {\r\n            $bin = \"$dir\\$target\"\r\n        } elseif (Test-Path $target -PathType leaf) {\r\n            $bin = $target\r\n        } else {\r\n            $bin = (Get-Command $target).Source\r\n        }\r\n        if (!$bin) { abort \"Can't shim '$target': File doesn't exist.\" }\r\n\r\n        shim $bin $global $name (substitute $arg @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir })\r\n    }\r\n}\r\n\r\nfunction rm_shim($name, $shimdir, $app) {\r\n    '', '.shim', '.cmd', '.ps1' | ForEach-Object {\r\n        $shimPath = \"$shimdir\\$name$_\"\r\n        $altShimPath = \"$shimPath.$app\"\r\n        if ($app -and (Test-Path -Path $altShimPath -PathType Leaf)) {\r\n            Write-Output \"Removing shim '$name$_.$app'.\"\r\n            Remove-Item $altShimPath\r\n        } elseif (Test-Path -Path $shimPath -PathType Leaf) {\r\n            Write-Output \"Removing shim '$name$_'.\"\r\n            Remove-Item $shimPath\r\n            $oldShims = Get-Item -Path \"$shimPath.*\" -Exclude '*.shim', '*.cmd', '*.ps1'\r\n            if ($null -eq $oldShims) {\r\n                if ($_ -eq '.shim') {\r\n                    Write-Output \"Removing shim '$name.exe'.\"\r\n                    Remove-Item -Path \"$shimdir\\$name.exe\"\r\n                }\r\n            } else {\r\n                (@($oldShims) | Sort-Object -Property LastWriteTimeUtc)[-1] | Rename-Item -NewName { $_.Name -replace '\\.[^.]*$', '' }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nfunction rm_shims($app, $manifest, $global, $arch) {\r\n    $shims = @(arch_specific 'bin' $manifest $arch)\r\n\r\n    $shims | Where-Object { $_ -ne $null } | ForEach-Object {\r\n        $target, $name, $null = shim_def $_\r\n        $shimdir = shimdir $global\r\n\r\n        rm_shim $name $shimdir $app\r\n    }\r\n}\r\n\r\n# Creates or updates the directory junction for [app]/current,\r\n# pointing to the specified version directory for the app.\r\n#\r\n# Returns the 'current' junction directory if in use, otherwise\r\n# the version directory.\r\nfunction link_current($versiondir) {\r\n    if (get_config NO_JUNCTION) { return $versiondir.ToString() }\r\n\r\n    $currentdir = \"$(Split-Path $versiondir)\\current\"\r\n\r\n    Write-Host \"Linking $(friendly_path $currentdir) => $(friendly_path $versiondir)\"\r\n\r\n    if ($currentdir -eq $versiondir) {\r\n        abort \"Error: Version 'current' is not allowed!\"\r\n    }\r\n\r\n    if (Test-Path $currentdir) {\r\n        # remove the junction\r\n        attrib -R /L $currentdir\r\n        Remove-Item $currentdir -Recurse -Force -ErrorAction Stop\r\n    }\r\n\r\n    New-DirectoryJunction $currentdir $versiondir | Out-Null\r\n    attrib $currentdir +R /L\r\n    return $currentdir\r\n}\r\n\r\n# Removes the directory junction for [app]/current which\r\n# points to the current version directory for the app.\r\n#\r\n# Returns the 'current' junction directory (if it exists),\r\n# otherwise the normal version directory.\r\nfunction unlink_current($versiondir) {\r\n    if (get_config NO_JUNCTION) { return $versiondir.ToString() }\r\n    $currentdir = \"$(Split-Path $versiondir)\\current\"\r\n\r\n    if (Test-Path $currentdir) {\r\n        Write-Host \"Unlinking $(friendly_path $currentdir)\"\r\n\r\n        # remove read-only attribute on link\r\n        attrib $currentdir -R /L\r\n\r\n        # remove the junction\r\n        Remove-Item $currentdir -Recurse -Force -ErrorAction Stop\r\n        return $currentdir\r\n    }\r\n    return $versiondir\r\n}\r\n\r\n# to undo after installers add to path so that scoop manifest can keep track of this instead\r\nfunction ensure_install_dir_not_in_path($dir, $global) {\r\n    $path = (Get-EnvVar -Name 'PATH' -Global:$global)\r\n\r\n    $fixed, $removed = find_dir_or_subdir $path \"$dir\"\r\n    if ($removed) {\r\n        $removed | ForEach-Object { \"Installer added '$(friendly_path $_)' to path. Removing.\" }\r\n        Set-EnvVar -Name 'PATH' -Value $fixed -Global:$global\r\n    }\r\n\r\n    if (!$global) {\r\n        $fixed, $removed = find_dir_or_subdir (Get-EnvVar -Name 'PATH' -Global) \"$dir\"\r\n        if ($removed) {\r\n            $removed | ForEach-Object { warn \"Installer added '$_' to system path. You might want to remove this manually (requires admin permission).\" }\r\n        }\r\n    }\r\n}\r\n\r\nfunction find_dir_or_subdir($path, $dir) {\r\n    $dir = $dir.trimend('\\')\r\n    $fixed = @()\r\n    $removed = @()\r\n    $path.split(';') | ForEach-Object {\r\n        if ($_) {\r\n            if (($_ -eq $dir) -or ($_ -like \"$dir\\*\")) { $removed += $_ }\r\n            else { $fixed += $_ }\r\n        }\r\n    }\r\n    return [string]::join(';', $fixed), $removed\r\n}\r\n\r\nfunction env_add_path($manifest, $dir, $global, $arch) {\r\n    $env_add_path = arch_specific 'env_add_path' $manifest $arch\r\n    $dir = $dir.TrimEnd('\\')\r\n    if ($env_add_path) {\r\n        if (get_config USE_ISOLATED_PATH) {\r\n            Add-Path -Path ('%' + $scoopPathEnvVar + '%') -Global:$global\r\n        }\r\n        $path = $env_add_path.Where({ $_ }).ForEach({ Join-Path $dir $_ | Get-AbsolutePath }).Where({ is_in_dir $dir $_ })\r\n        Add-Path -Path $path -TargetEnvVar $scoopPathEnvVar -Global:$global -Force\r\n    }\r\n}\r\n\r\nfunction env_rm_path($manifest, $dir, $global, $arch) {\r\n    $env_add_path = arch_specific 'env_add_path' $manifest $arch\r\n    $dir = $dir.TrimEnd('\\')\r\n    if ($env_add_path) {\r\n        $path = $env_add_path.Where({ $_ }).ForEach({ Join-Path $dir $_ | Get-AbsolutePath }).Where({ is_in_dir $dir $_ })\r\n        Remove-Path -Path $path -Global:$global # TODO: Remove after forced isolating Scoop path\r\n        Remove-Path -Path $path -TargetEnvVar $scoopPathEnvVar -Global:$global\r\n    }\r\n}\r\n\r\nfunction env_set($manifest, $global, $arch) {\r\n    $env_set = arch_specific 'env_set' $manifest $arch\r\n    if ($env_set) {\r\n        $env_set | Get-Member -MemberType NoteProperty | ForEach-Object {\r\n            $name = $_.Name\r\n            $val = $ExecutionContext.InvokeCommand.ExpandString($env_set.$($name))\r\n            Set-EnvVar -Name $name -Value $val -Global:$global\r\n            Set-Content env:\\$name $val\r\n        }\r\n    }\r\n}\r\nfunction env_rm($manifest, $global, $arch) {\r\n    $env_set = arch_specific 'env_set' $manifest $arch\r\n    if ($env_set) {\r\n        $env_set | Get-Member -MemberType NoteProperty | ForEach-Object {\r\n            $name = $_.Name\r\n            Set-EnvVar -Name $name -Value $null -Global:$global\r\n            if (Test-Path env:\\$name) { Remove-Item env:\\$name }\r\n        }\r\n    }\r\n}\r\n\r\nfunction show_notes($manifest, $dir, $original_dir, $persist_dir) {\r\n    if ($manifest.notes) {\r\n        Write-Output 'Notes'\r\n        Write-Output '-----'\r\n        Write-Output (wraptext (substitute $manifest.notes @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir }))\r\n    }\r\n}\r\n\r\nfunction all_installed($apps, $global) {\r\n    $apps | Where-Object {\r\n        $app, $null, $null = parse_app $_\r\n        installed $app $global\r\n    }\r\n}\r\n\r\n# returns (uninstalled, installed)\r\nfunction prune_installed($apps, $global) {\r\n    $installed = @(all_installed $apps $global)\r\n\r\n    $uninstalled = $apps | Where-Object { $installed -notcontains $_ }\r\n\r\n    return @($uninstalled), @($installed)\r\n}\r\n\r\nfunction ensure_none_failed($apps) {\r\n    foreach ($app in $apps) {\r\n        $app = ($app -split '/|\\\\')[-1] -replace '\\.json$', ''\r\n        foreach ($global in $true, $false) {\r\n            if ($global) {\r\n                $instArgs = @('--global')\r\n            } else {\r\n                $instArgs = @()\r\n            }\r\n            if (failed $app $global) {\r\n                if (installed $app $global) {\r\n                    info \"Repair previous failed installation of $app.\"\r\n                    & \"$PSScriptRoot\\..\\libexec\\scoop-reset.ps1\" $app @instArgs\r\n                } else {\r\n                    warn \"Purging previous failed installation of $app.\"\r\n                    & \"$PSScriptRoot\\..\\libexec\\scoop-uninstall.ps1\" $app @instArgs\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nfunction show_suggestions($suggested) {\r\n    $installed_apps = (installed_apps $true) + (installed_apps $false)\r\n\r\n    foreach ($app in $suggested.keys) {\r\n        $features = $suggested[$app] | Get-Member -type noteproperty | ForEach-Object { $_.name }\r\n        foreach ($feature in $features) {\r\n            $feature_suggestions = $suggested[$app].$feature\r\n\r\n            $fulfilled = $false\r\n            foreach ($suggestion in $feature_suggestions) {\r\n                $suggested_app, $bucket, $null = parse_app $suggestion\r\n\r\n                if ($installed_apps -contains $suggested_app) {\r\n                    $fulfilled = $true\r\n                    break\r\n                }\r\n            }\r\n\r\n            if (!$fulfilled) {\r\n                Write-Host \"'$app' suggests installing '$([string]::join(\"' or '\", $feature_suggestions))'.\"\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n# Persistent data\r\nfunction persist_def($persist) {\r\n    if ($persist -is [Array]) {\r\n        $source = $persist[0]\r\n        $target = $persist[1]\r\n    } else {\r\n        $source = $persist\r\n        $target = $null\r\n    }\r\n\r\n    if (!$target) {\r\n        $target = $source\r\n    }\r\n\r\n    return $source, $target\r\n}\r\n\r\nfunction persist_data($manifest, $original_dir, $persist_dir) {\r\n    $persist = $manifest.persist\r\n    if ($persist) {\r\n        $persist_dir = ensure $persist_dir\r\n\r\n        if ($persist -is [String]) {\r\n            $persist = @($persist)\r\n        }\r\n\r\n        $persist | ForEach-Object {\r\n            $source, $target = persist_def $_\r\n\r\n            Write-Host \"Persisting $source\"\r\n\r\n            $source = $source.TrimEnd('/').TrimEnd('\\\\')\r\n\r\n            $source = \"$dir\\$source\"\r\n            $target = \"$persist_dir\\$target\"\r\n\r\n            # if we have had persist data in the store, just create link and go\r\n            if (Test-Path $target) {\r\n                # if there is also a source data, rename it (to keep a original backup)\r\n                if (Test-Path $source) {\r\n                    Move-Item -Force $source \"$source.original\"\r\n                }\r\n                # we don't have persist data in the store, move the source to target, then create link\r\n            } elseif (Test-Path $source) {\r\n                # ensure target parent folder exist\r\n                ensure (Split-Path -Path $target) | Out-Null\r\n                Move-Item $source $target\r\n                # we don't have neither source nor target data! we need to create an empty target,\r\n                # but we can't make a judgement that the data should be a file or directory...\r\n                # so we create a directory by default. to avoid this, use pre_install\r\n                # to create the source file before persisting (DON'T use post_install)\r\n            } else {\r\n                $target = New-Object System.IO.DirectoryInfo($target)\r\n                ensure $target | Out-Null\r\n            }\r\n\r\n            # create link\r\n            if (is_directory $target) {\r\n                # target is a directory, create junction\r\n                New-DirectoryJunction $source $target | Out-Null\r\n                attrib $source +R /L\r\n            } else {\r\n                # target is a file, create hard link\r\n                New-Item -Path $source -ItemType HardLink -Value $target | Out-Null\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nfunction unlink_persist_data($manifest, $dir) {\r\n    $persist = $manifest.persist\r\n    # unlink all junction / hard link in the directory\r\n    if ($persist) {\r\n        @($persist) | ForEach-Object {\r\n            $source, $null = persist_def $_\r\n            $source = Get-Item \"$dir\\$source\" -ErrorAction SilentlyContinue\r\n            if ($source.LinkType) {\r\n                $source_path = $source.FullName\r\n                # directory (junction)\r\n                if ($source -is [System.IO.DirectoryInfo]) {\r\n                    # remove read-only attribute on the link\r\n                    attrib -R /L $source_path\r\n                    # remove the junction\r\n                    Remove-Item -Path $source_path -Recurse -Force -ErrorAction SilentlyContinue\r\n                } else {\r\n                    # remove the hard link\r\n                    Remove-Item -Path $source_path -Force -ErrorAction SilentlyContinue\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n# check whether write permission for Users usergroup is set to global persist dir, if not then set\r\nfunction persist_permission($manifest, $global) {\r\n    if ($global -and $manifest.persist -and (is_admin)) {\r\n        $path = persistdir $null $global\r\n        $user = New-Object System.Security.Principal.SecurityIdentifier 'S-1-5-32-545'\r\n        $target_rule = New-Object System.Security.AccessControl.FileSystemAccessRule($user, 'Write', 'ObjectInherit', 'none', 'Allow')\r\n        $acl = Get-Acl -Path $path\r\n        $acl.SetAccessRule($target_rule)\r\n        $acl | Set-Acl -Path $path\r\n    }\r\n}\r\n\r\n# test if there are running processes\r\nfunction test_running_process($app, $global) {\r\n    $processdir = appdir $app $global | Convert-Path\r\n    $running_processes = Get-Process | Where-Object { $_.Path -like \"$processdir\\*\" } | Out-String\r\n\r\n    if ($running_processes) {\r\n        if (get_config IGNORE_RUNNING_PROCESSES) {\r\n            warn \"The following instances of `\"$app`\" are still running. Scoop is configured to ignore this condition.\"\r\n            Write-Host $running_processes\r\n            return $false\r\n        } else {\r\n            error \"The following instances of `\"$app`\" are still running. Close them and try again.\"\r\n            Write-Host $running_processes\r\n            return $true\r\n        }\r\n    } else {\r\n        return $false\r\n    }\r\n}\r\n\r\n# wrapper function to create junction links\r\n# Required to handle docker/for-win#12240\r\nfunction New-DirectoryJunction($source, $target) {\r\n    # test if this script is being executed inside a docker container\r\n    if (Get-Service -Name cexecsvc -ErrorAction SilentlyContinue) {\r\n        cmd.exe /d /c \"mklink /j `\"$source`\" `\"$target`\"\"\r\n    } else {\r\n        New-Item -Path $source -ItemType Junction -Value $target\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/json.ps1",
    "content": "# Convert objects to pretty json\r\n# Only needed until PowerShell ConvertTo-Json will be improved https://github.com/PowerShell/PowerShell/issues/2736\r\n# https://github.com/PowerShell/PowerShell/issues/2736 was fixed in pwsh\r\n# Still needed in normal powershell\r\n\r\nfunction ConvertToPrettyJson {\r\n    [CmdletBinding()]\r\n\r\n    Param (\r\n        [Parameter(Mandatory, ValueFromPipeline)]\r\n        $data\r\n    )\r\n\r\n    Process {\r\n        $data = normalize_values $data\r\n\r\n        # convert to string\r\n        [String]$json = $data | ConvertTo-Json -Depth 8 -Compress\r\n        [String]$output = ''\r\n\r\n        # state\r\n        [String]$buffer = ''\r\n        [Int]$depth = 0\r\n        [Bool]$inString = $false\r\n\r\n        # configuration\r\n        [String]$indent = ' ' * 4\r\n        [Bool]$unescapeString = $true\r\n        [String]$eol = \"`r`n\"\r\n\r\n        for ($i = 0; $i -lt $json.Length; $i++) {\r\n            # read current char\r\n            $buffer = $json.Substring($i, 1)\r\n\r\n            $objectStart = !$inString -and $buffer.Equals('{')\r\n            $objectEnd = !$inString -and $buffer.Equals('}')\r\n            $arrayStart = !$inString -and $buffer.Equals('[')\r\n            $arrayEnd = !$inString -and $buffer.Equals(']')\r\n            $colon = !$inString -and $buffer.Equals(':')\r\n            $comma = !$inString -and $buffer.Equals(',')\r\n            $quote = $buffer.Equals('\"')\r\n            $escape = $buffer.Equals('\\')\r\n\r\n            if ($quote) {\r\n                $inString = !$inString\r\n            }\r\n\r\n            # skip escape sequences\r\n            if ($escape) {\r\n                $buffer = $json.Substring($i, 2)\r\n                ++$i\r\n\r\n                # Unescape unicode\r\n                if ($inString -and $unescapeString) {\r\n                    if ($buffer.Equals('\\n')) {\r\n                        $buffer = \"`n\"\r\n                    } elseif ($buffer.Equals('\\r')) {\r\n                        $buffer = \"`r\"\r\n                    } elseif ($buffer.Equals('\\t')) {\r\n                        $buffer = \"`t\"\r\n                    } elseif ($buffer.Equals('\\u')) {\r\n                        $buffer = [regex]::Unescape($json.Substring($i - 1, 6))\r\n                        $i += 4\r\n                    }\r\n                }\r\n\r\n                $output += $buffer\r\n                continue\r\n            }\r\n\r\n            # indent / outdent\r\n            if ($objectStart -or $arrayStart) {\r\n                ++$depth\r\n            } elseif ($objectEnd -or $arrayEnd) {\r\n                --$depth\r\n                $output += $eol + ($indent * $depth)\r\n            }\r\n\r\n            # add content\r\n            $output += $buffer\r\n\r\n            # add whitespace and newlines after the content\r\n            if ($colon) {\r\n                $output += ' '\r\n            } elseif ($comma -or $arrayStart -or $objectStart) {\r\n                $output += $eol\r\n                $output += $indent * $depth\r\n            }\r\n        }\r\n\r\n        return $output\r\n    }\r\n}\r\n\r\nfunction json_path([String] $json, [String] $jsonpath, [Hashtable] $substitutions, [Boolean] $reverse, [Boolean] $single) {\r\n    Add-Type -Path \"$PSScriptRoot\\..\\supporting\\validator\\bin\\Newtonsoft.Json.dll\"\r\n    if ($null -ne $substitutions) {\r\n        $jsonpath = substitute $jsonpath $substitutions ($jsonpath -like \"*=~*\")\r\n    }\r\n    try {\r\n        $settings = New-Object -Type Newtonsoft.Json.JsonSerializerSettings\r\n        $settings.DateParseHandling = [Newtonsoft.Json.DateParseHandling]::None\r\n        $obj = [Newtonsoft.Json.JsonConvert]::DeserializeObject($json, $settings)\r\n    } catch [Newtonsoft.Json.JsonReaderException] {\r\n        return $null\r\n    }\r\n    try {\r\n        $result = $obj.SelectTokens($jsonpath, $true)\r\n        if ($reverse) {\r\n            # Return versions in reverse order\r\n            $result = [System.Linq.Enumerable]::Reverse($result)\r\n        }\r\n        if ([System.Linq.Enumerable]::Count($result) -eq 1 -or $single) {\r\n            # Extract First value\r\n            $result = [System.Linq.Enumerable]::First($result)\r\n            # Convert first value to string\r\n            $result = $result.ToString()\r\n        } else {\r\n            $result = [Newtonsoft.Json.JsonConvert]::SerializeObject($result)\r\n        }\r\n        return $result\r\n    } catch [Exception] {\r\n        Write-Host $_ -ForegroundColor DarkRed\r\n    }\r\n\r\n    return $null\r\n}\r\n\r\nfunction json_path_legacy([String] $json, [String] $jsonpath, [Hashtable] $substitutions) {\r\n    $result = $json | ConvertFrom-Json -ea stop\r\n    $isJsonPath = $jsonpath.StartsWith('$')\r\n    $jsonpath.split('.') | ForEach-Object {\r\n        $el = $_\r\n\r\n        # substitute the basename and version varibales into the jsonpath\r\n        if ($null -ne $substitutions) {\r\n            $el = substitute $el $substitutions\r\n        }\r\n\r\n        # skip $ if it's jsonpath format\r\n        if ($el -eq '$' -and $isJsonPath) {\r\n            return\r\n        }\r\n\r\n        # array detection\r\n        if ($el -match '^(?<property>\\w+)?\\[(?<index>\\d+)\\]$') {\r\n            $property = $matches['property']\r\n            if ($property) {\r\n                $result = $result.$property[$matches['index']]\r\n            } else {\r\n                $result = $result[$matches['index']]\r\n            }\r\n            return\r\n        }\r\n\r\n        $result = $result.$el\r\n    }\r\n    return $result\r\n}\r\n\r\nfunction normalize_values([psobject] $json) {\r\n    # Iterate Through Manifest Properties\r\n    $json.PSObject.Properties | ForEach-Object {\r\n        # Recursively edit psobjects\r\n        # If the values is psobjects, its not normalized\r\n        # For example if manifest have architecture and it's architecture have array with single value it's not formatted.\r\n        # @see https://github.com/ScoopInstaller/Scoop/pull/2642#issue-220506263\r\n        if ($_.Value -is [System.Management.Automation.PSCustomObject]) {\r\n            $_.Value = normalize_values $_.Value\r\n        }\r\n\r\n        # Process String Values\r\n        if ($_.Value -is [String]) {\r\n\r\n            # Split on new lines\r\n            [Array] $parts = ($_.Value -split '\\r?\\n').Trim()\r\n\r\n            # Replace with string array if result is multiple lines\r\n            if ($parts.Count -gt 1) {\r\n                $_.Value = $parts\r\n            }\r\n        }\r\n\r\n        # Convert single value array into string\r\n        if ($_.Value -is [Array]) {\r\n            # Array contains only 1 element String or Array\r\n            if ($_.Value.Count -eq 1) {\r\n                # Array\r\n                if ($_.Value[0] -is [Array]) {\r\n                    $_.Value = $_.Value\r\n                } else {\r\n                    # String\r\n                    $_.Value = $_.Value[0]\r\n                }\r\n            } else {\r\n                # Array of Arrays\r\n                $resulted_arrs = @()\r\n                foreach ($element in $_.Value) {\r\n                    if ($element.Count -eq 1) {\r\n                        $resulted_arrs += $element\r\n                    } else {\r\n                        $resulted_arrs += , $element\r\n                    }\r\n                }\r\n\r\n                $_.Value = $resulted_arrs\r\n            }\r\n        }\r\n\r\n        # Process other values as needed...\r\n    }\r\n\r\n    return $json\r\n}\r\n"
  },
  {
    "path": "lib/manifest.ps1",
    "content": "function manifest_path($app, $bucket) {\r\n    (Get-ChildItem (Find-BucketDirectory $bucket) -Filter \"$(sanitary_path $app).json\" -Recurse).FullName\r\n}\r\n\r\nfunction parse_json($path) {\r\n    if ($null -eq $path -or !(Test-Path $path)) { return $null }\r\n    try {\r\n        Get-Content $path -Raw -Encoding UTF8 | ConvertFrom-Json -ErrorAction Stop\r\n    } catch {\r\n        warn \"Error parsing JSON at '$path'.\"\r\n    }\r\n}\r\n\r\nfunction url_manifest($url) {\r\n    $str = $null\r\n    try {\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $data = $wc.DownloadData($url)\r\n        $str = (Get-Encoding($wc)).GetString($data)\r\n    } catch [system.management.automation.methodinvocationexception] {\r\n        warn \"error: $($_.exception.innerexception.message)\"\r\n    } catch {\r\n        throw\r\n    }\r\n    if (!$str) { return $null }\r\n    try {\r\n        $str | ConvertFrom-Json -ErrorAction Stop\r\n    } catch {\r\n        warn \"Error parsing JSON at '$url'.\"\r\n    }\r\n}\r\n\r\nfunction Get-Manifest($app) {\r\n    $bucket, $manifest, $url = $null\r\n    $app = $app.TrimStart('/')\r\n    # check if app is a URL or UNC path\r\n    if ($app -match '^(ht|f)tps?://|\\\\\\\\') {\r\n        $url = $app\r\n        $app = appname_from_url $url\r\n        $manifest = url_manifest $url\r\n    } else {\r\n        # Check if the manifest is already installed\r\n        if (installed $app) {\r\n            $global = installed $app $true\r\n            $ver = Select-CurrentVersion -AppName $app -Global:$global\r\n            if (!$ver) {\r\n                $app, $bucket, $ver = parse_app $app\r\n                $ver = Select-CurrentVersion -AppName $app -Global:$global\r\n            }\r\n            $install_info_path = \"$(versiondir $app $ver $global)\\install.json\"\r\n            if (Test-Path $install_info_path) {\r\n                $install_info = parse_json $install_info_path\r\n                $bucket = $install_info.bucket\r\n                if (!$bucket) {\r\n                    $url = $install_info.url\r\n                    if ($url -match '^(ht|f)tps?://|\\\\\\\\') {\r\n                        $manifest = url_manifest $url\r\n                    }\r\n                    if (!$manifest) {\r\n                        if (Test-Path $url) {\r\n                            $manifest = parse_json $url\r\n                        } else {\r\n                            # Fallback to installed manifest\r\n                            $manifest = installed_manifest $app $ver $global\r\n                        }\r\n                    }\r\n                } else {\r\n                    $manifest = manifest $app $bucket\r\n                    if (!$manifest) {\r\n                        $deprecated_dir = (Find-BucketDirectory -Name $bucket -Root) + '\\deprecated'\r\n                        $manifest = parse_json (Get-ChildItem $deprecated_dir -Filter \"$(sanitary_path $app).json\" -Recurse).FullName\r\n                    }\r\n                }\r\n            }\r\n        } else {\r\n            $app, $bucket, $version = parse_app $app\r\n            if ($bucket) {\r\n                $manifest = manifest $app $bucket\r\n            } else {\r\n                $matched_buckets = @()\r\n                foreach ($tekcub in Get-LocalBucket) {\r\n                    $current_manifest = manifest $app $tekcub\r\n                    if (!$manifest -and $current_manifest) {\r\n                        $manifest = $current_manifest\r\n                        $bucket = $tekcub\r\n                    }\r\n                    if ($current_manifest) {\r\n                        $matched_buckets += $tekcub\r\n                    }\r\n                }\r\n            }\r\n            if (!$manifest) {\r\n                # couldn't find app in buckets: check if it's a local path\r\n                if (Test-Path $app) {\r\n                    $url = Convert-Path $app\r\n                    $app = appname_from_url $url\r\n                    $manifest = parse_json $url\r\n                } else {\r\n                    if (($app -match '\\\\/') -or $app.EndsWith('.json')) { $url = $app }\r\n                    $app = appname_from_url $app\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    if ($matched_buckets.Length -gt 1) {\r\n        warn \"Multiple buckets contain manifest '$app', the current selection is '$bucket/$app'.\"\r\n    }\r\n\r\n    return $app, $manifest, $bucket, $url\r\n}\r\n\r\nfunction manifest($app, $bucket, $url) {\r\n    if ($url) { return url_manifest $url }\r\n    parse_json (manifest_path $app $bucket)\r\n}\r\n\r\nfunction save_installed_manifest($app, $bucket, $dir, $url) {\r\n    if ($url) {\r\n        $wc = New-Object Net.Webclient\r\n        $wc.Headers.Add('User-Agent', (Get-UserAgent))\r\n        $data = $wc.DownloadData($url)\r\n        (Get-Encoding($wc)).GetString($data) | Out-UTF8File \"$dir\\manifest.json\"\r\n    } else {\r\n        Copy-Item (manifest_path $app $bucket) \"$dir\\manifest.json\"\r\n    }\r\n}\r\n\r\nfunction installed_manifest($app, $version, $global) {\r\n    parse_json \"$(versiondir $app $version $global)\\manifest.json\"\r\n}\r\n\r\nfunction save_install_info($info, $dir) {\r\n    $nulls = $info.keys | Where-Object { $null -eq $info[$_] }\r\n    $nulls | ForEach-Object { $info.remove($_) } # strip null-valued\r\n\r\n    $file_content = $info | ConvertToPrettyJson # in 'json.ps1'\r\n    [System.IO.File]::WriteAllLines(\"$dir\\install.json\", $file_content)\r\n}\r\n\r\nfunction install_info($app, $version, $global) {\r\n    $path = \"$(versiondir $app $version $global)\\install.json\"\r\n    if (!(Test-Path $path)) { return $null }\r\n    parse_json $path\r\n}\r\n\r\nfunction arch_specific($prop, $manifest, $architecture) {\r\n    if ($manifest.architecture) {\r\n        $val = $manifest.architecture.$architecture.$prop\r\n        if ($val) { return $val } # else fallback to generic prop\r\n    }\r\n\r\n    if ($manifest.$prop) { return $manifest.$prop }\r\n}\r\n\r\nfunction Get-SupportedArchitecture($manifest, $architecture) {\r\n    if ($architecture -eq 'arm64' -and ($manifest | ConvertToPrettyJson) -notmatch '[''\"]arm64[\"'']') {\r\n        # Windows 10 enables existing unmodified x86 apps to run on Arm devices.\r\n        # Windows 11 adds the ability to run unmodified x64 Windows apps on Arm devices!\r\n        # Ref: https://learn.microsoft.com/en-us/windows/arm/overview\r\n        if ($WindowsBuild -ge 22000) {\r\n            # Windows 11\r\n            $architecture = '64bit'\r\n        } else {\r\n            # Windows 10\r\n            $architecture = '32bit'\r\n        }\r\n    }\r\n    if (![String]::IsNullOrEmpty((arch_specific 'url' $manifest $architecture))) {\r\n        return $architecture\r\n    }\r\n}\r\n\r\nfunction generate_user_manifest($app, $bucket, $version) {\r\n    # 'autoupdate.ps1' 'buckets.ps1' 'manifest.ps1'\r\n    $app, $manifest, $bucket, $null = Get-Manifest \"$bucket/$app\"\r\n    if (\"$($manifest.version)\" -eq \"$version\") {\r\n        return manifest_path $app $bucket\r\n    }\r\n    warn \"Given version ($version) does not match manifest ($($manifest.version))\"\r\n    warn \"Attempting to generate manifest for '$app' ($version)\"\r\n\r\n    ensure (usermanifestsdir) | Out-Null\r\n    $manifest_path = \"$(usermanifestsdir)\\$app.json\"\r\n\r\n    if (get_config USE_SQLITE_CACHE) {\r\n        $cached_manifest = (Get-ScoopDBItem -Name $app -Bucket $bucket -Version $version).manifest\r\n        if ($cached_manifest) {\r\n            $cached_manifest | Out-UTF8File $manifest_path\r\n            return $manifest_path\r\n        }\r\n    }\r\n\r\n    if (!($manifest.autoupdate)) {\r\n        abort \"'$app' does not have autoupdate capability`r`ncouldn't find manifest for '$app@$version'\"\r\n    }\r\n\r\n    try {\r\n        Invoke-AutoUpdate $app $manifest_path $manifest $version $(@{ })\r\n        return $manifest_path\r\n    } catch {\r\n        Write-Host -ForegroundColor DarkRed \"Could not install $app@$version\"\r\n    }\r\n\r\n    return $null\r\n}\r\n\r\nfunction url($manifest, $arch) { arch_specific 'url' $manifest $arch }\r\nfunction installer($manifest, $arch) { arch_specific 'installer' $manifest $arch }\r\nfunction uninstaller($manifest, $arch) { arch_specific 'uninstaller' $manifest $arch }\r\nfunction hash($manifest, $arch) { arch_specific 'hash' $manifest $arch }\r\nfunction extract_dir($manifest, $arch) { arch_specific 'extract_dir' $manifest $arch }\r\nfunction extract_to($manifest, $arch) { arch_specific 'extract_to' $manifest $arch }\r\n"
  },
  {
    "path": "lib/psmodules.ps1",
    "content": "function install_psmodule($manifest, $dir, $global) {\r\n    $psmodule = $manifest.psmodule\r\n    if (!$psmodule) { return }\r\n\r\n    $targetdir = ensure (modulesdir $global)\r\n\r\n    ensure_in_psmodulepath $targetdir $global\r\n\r\n    $module_name = $psmodule.name\r\n    if (!$module_name) {\r\n        abort \"Invalid manifest: The 'name' property is missing from 'psmodule'.\"\r\n    }\r\n\r\n    $linkfrom = \"$targetdir\\$module_name\"\r\n    Write-Host \"Installing PowerShell module '$module_name'\"\r\n\r\n    Write-Host \"Linking $(friendly_path $linkfrom) => $(friendly_path $dir)\"\r\n\r\n    if (Test-Path $linkfrom) {\r\n        warn \"$(friendly_path $linkfrom) already exists. It will be replaced.\"\r\n        Remove-Item -Path $linkfrom -Force -Recurse -ErrorAction SilentlyContinue\r\n    }\r\n\r\n    New-DirectoryJunction $linkfrom $dir | Out-Null\r\n}\r\n\r\nfunction uninstall_psmodule($manifest, $dir, $global) {\r\n    $psmodule = $manifest.psmodule\r\n    if (!$psmodule) { return }\r\n\r\n    $module_name = $psmodule.name\r\n    Write-Host \"Uninstalling PowerShell module '$module_name'.\"\r\n\r\n    $targetdir = modulesdir $global\r\n\r\n    $linkfrom = \"$targetdir\\$module_name\"\r\n    if (Test-Path $linkfrom) {\r\n        Write-Host \"Removing $(friendly_path $linkfrom)\"\r\n        $linkfrom = Convert-Path $linkfrom\r\n        Remove-Item -Path $linkfrom -Force -Recurse -ErrorAction SilentlyContinue\r\n    }\r\n}\r\n\r\nfunction ensure_in_psmodulepath($dir, $global) {\r\n    $path = Get-EnvVar -Name 'PSModulePath' -Global:$global\r\n    if (!$global -and $null -eq $path) {\r\n        $path = \"$env:USERPROFILE\\Documents\\WindowsPowerShell\\Modules\"\r\n    }\r\n    if ($path -notmatch [Regex]::Escape($dir)) {\r\n        Write-Output \"Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) PowerShell module path.\"\r\n\r\n        Set-EnvVar -Name 'PSModulePath' -Value \"$dir;$path\" -Global:$global\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/shortcuts.ps1",
    "content": "# Creates shortcut for the app in the start menu\r\nfunction create_startmenu_shortcuts($manifest, $dir, $global, $arch) {\r\n    $shortcuts = @(arch_specific 'shortcuts' $manifest $arch)\r\n    $shortcuts | Where-Object { $_ -ne $null } | ForEach-Object {\r\n        $target = [System.IO.Path]::Combine($dir, $_.item(0))\r\n        $target = New-Object System.IO.FileInfo($target)\r\n        $name = $_.item(1)\r\n        $arguments = ''\r\n        $icon = $null\r\n        if ($_.length -ge 3) {\r\n            $arguments = $_.item(2)\r\n        }\r\n        if ($_.length -ge 4) {\r\n            $icon = [System.IO.Path]::Combine($dir, $_.item(3))\r\n            $icon = New-Object System.IO.FileInfo($icon)\r\n        }\r\n        $arguments = (substitute $arguments @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir })\r\n        startmenu_shortcut $target $name $arguments $icon $global\r\n    }\r\n}\r\n\r\nfunction shortcut_folder($global) {\r\n    if ($global) {\r\n        $startmenu = 'CommonStartMenu'\r\n    } else {\r\n        $startmenu = 'StartMenu'\r\n    }\r\n    return Convert-Path (ensure ([System.IO.Path]::Combine([Environment]::GetFolderPath($startmenu), 'Programs', 'Scoop Apps')))\r\n}\r\n\r\nfunction startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $arguments, [System.IO.FileInfo]$icon, $global) {\r\n    if (!$target.Exists) {\r\n        Write-Host -f DarkRed \"Creating shortcut for $shortcutName ($(fname $target)) failed: Couldn't find $target\"\r\n        return\r\n    }\r\n    if ($icon -and !$icon.Exists) {\r\n        Write-Host -f DarkRed \"Creating shortcut for $shortcutName ($(fname $target)) failed: Couldn't find icon $icon\"\r\n        return\r\n    }\r\n\r\n    $scoop_startmenu_folder = shortcut_folder $global\r\n    $subdirectory = [System.IO.Path]::GetDirectoryName($shortcutName)\r\n    if ($subdirectory) {\r\n        $subdirectory = ensure $([System.IO.Path]::Combine($scoop_startmenu_folder, $subdirectory))\r\n    }\r\n\r\n    $wsShell = New-Object -ComObject WScript.Shell\r\n    $wsShell = $wsShell.CreateShortcut(\"$scoop_startmenu_folder\\$shortcutName.lnk\")\r\n    $wsShell.TargetPath = $target.FullName\r\n    $wsShell.WorkingDirectory = $target.DirectoryName\r\n    if ($arguments) {\r\n        $wsShell.Arguments = $arguments\r\n    }\r\n    if ($icon -and $icon.Exists) {\r\n        $wsShell.IconLocation = $icon.FullName\r\n    }\r\n    $wsShell.Save()\r\n    Write-Host \"Creating shortcut for $shortcutName ($(fname $target))\"\r\n}\r\n\r\n# Removes the Startmenu shortcut if it exists\r\nfunction rm_startmenu_shortcuts($manifest, $global, $arch) {\r\n    $shortcuts = @(arch_specific 'shortcuts' $manifest $arch)\r\n    $shortcuts | Where-Object { $_ -ne $null } | ForEach-Object {\r\n        $name = $_.item(1)\r\n        $shortcut = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\"$(shortcut_folder $global)\\$name.lnk\")\r\n        Write-Host \"Removing shortcut $(friendly_path $shortcut)\"\r\n        if (Test-Path -Path $shortcut) {\r\n            Remove-Item $shortcut\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/system.ps1",
    "content": "# System-related functions\r\n\r\n## Environment Variables\r\n\r\nfunction Publish-EnvVar {\r\n    if (-not ('Win32.NativeMethods' -as [Type])) {\r\n        Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @'\r\n[DllImport(\"user32.dll\", SetLastError = true, CharSet = CharSet.Auto)]\r\npublic static extern IntPtr SendMessageTimeout(\r\n    IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,\r\n    uint fuFlags, uint uTimeout, out UIntPtr lpdwResult\r\n);\r\n'@\r\n    }\r\n\r\n    $HWND_BROADCAST = [IntPtr] 0xffff\r\n    $WM_SETTINGCHANGE = 0x1a\r\n    $result = [UIntPtr]::Zero\r\n\r\n    [Win32.NativeMethods]::SendMessageTimeout($HWND_BROADCAST,\r\n        $WM_SETTINGCHANGE,\r\n        [UIntPtr]::Zero,\r\n        'Environment',\r\n        2,\r\n        5000,\r\n        [ref] $result\r\n    ) | Out-Null\r\n}\r\n\r\nfunction Get-EnvVar {\r\n    param(\r\n        [string]$Name,\r\n        [switch]$Global\r\n    )\r\n\r\n    $registerKey = if ($Global) {\r\n        Get-Item -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager'\r\n    } else {\r\n        Get-Item -Path 'HKCU:'\r\n    }\r\n    $envRegisterKey = $registerKey.OpenSubKey('Environment')\r\n    $registryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames\r\n    $envRegisterKey.GetValue($Name, $null, $registryValueOption)\r\n}\r\n\r\nfunction Set-EnvVar {\r\n    param(\r\n        [string]$Name,\r\n        [string]$Value,\r\n        [switch]$Global\r\n    )\r\n\r\n    $registerKey = if ($Global) {\r\n        Get-Item -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager'\r\n    } else {\r\n        Get-Item -Path 'HKCU:'\r\n    }\r\n    $envRegisterKey = $registerKey.OpenSubKey('Environment', $true)\r\n    if ($null -eq $Value -or $Value -eq '') {\r\n        if ($envRegisterKey.GetValue($Name)) {\r\n            $envRegisterKey.DeleteValue($Name)\r\n        }\r\n    } else {\r\n        $registryValueKind = if ($Value.Contains('%')) {\r\n            [Microsoft.Win32.RegistryValueKind]::ExpandString\r\n        } elseif ($envRegisterKey.GetValue($Name)) {\r\n            $envRegisterKey.GetValueKind($Name)\r\n        } else {\r\n            [Microsoft.Win32.RegistryValueKind]::String\r\n        }\r\n        $envRegisterKey.SetValue($Name, $Value, $registryValueKind)\r\n    }\r\n    Publish-EnvVar\r\n}\r\n\r\nfunction Split-PathLikeEnvVar {\r\n    param(\r\n        [string[]]$Pattern,\r\n        [string]$Path\r\n    )\r\n\r\n    if ($null -eq $Path -and $Path -eq '') {\r\n        return $null, $null\r\n    } else {\r\n        $splitPattern = $Pattern.Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)\r\n        $splitPath = $Path.Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)\r\n        $inPath = @()\r\n        foreach ($p in $splitPattern) {\r\n            $inPath += $splitPath.Where({ $_ -like $p })\r\n            $splitPath = $splitPath.Where({ $_ -notlike $p })\r\n        }\r\n        return ($inPath -join ';'), ($splitPath -join ';')\r\n    }\r\n}\r\n\r\nfunction Add-Path {\r\n    param(\r\n        [string[]]$Path,\r\n        [string]$TargetEnvVar = 'PATH',\r\n        [switch]$Global,\r\n        [switch]$Force,\r\n        [switch]$Quiet\r\n    )\r\n\r\n    # future sessions\r\n    $inPath, $strippedPath = Split-PathLikeEnvVar $Path (Get-EnvVar -Name $TargetEnvVar -Global:$Global)\r\n    if (!$inPath -or $Force) {\r\n        if (!$Quiet) {\r\n            $Path | ForEach-Object {\r\n                Write-Host \"Adding $(friendly_path $_) to $(if ($Global) {'global'} else {'your'}) path.\"\r\n            }\r\n        }\r\n        Set-EnvVar -Name $TargetEnvVar -Value ((@($Path) + $strippedPath) -join ';') -Global:$Global\r\n    }\r\n    # current session\r\n    $inPath, $strippedPath = Split-PathLikeEnvVar $Path $env:PATH\r\n    if (!$inPath -or $Force) {\r\n        $env:PATH = (@($Path) + $strippedPath) -join ';'\r\n    }\r\n}\r\n\r\nfunction Remove-Path {\r\n    param(\r\n        [string[]]$Path,\r\n        [string]$TargetEnvVar = 'PATH',\r\n        [switch]$Global,\r\n        [switch]$Quiet,\r\n        [switch]$PassThru\r\n    )\r\n\r\n    # future sessions\r\n    $inPath, $strippedPath = Split-PathLikeEnvVar $Path (Get-EnvVar -Name $TargetEnvVar -Global:$Global)\r\n    if ($inPath) {\r\n        if (!$Quiet) {\r\n            $Path | ForEach-Object {\r\n                Write-Host \"Removing $(friendly_path $_) from $(if ($Global) {'global'} else {'your'}) path.\"\r\n            }\r\n        }\r\n        Set-EnvVar -Name $TargetEnvVar -Value $strippedPath -Global:$Global\r\n    }\r\n    # current session\r\n    $inSessionPath, $strippedPath = Split-PathLikeEnvVar $Path $env:PATH\r\n    if ($inSessionPath) {\r\n        $env:PATH = $strippedPath\r\n    }\r\n    if ($PassThru) {\r\n        return $inPath\r\n    }\r\n}\r\n\r\n## Deprecated functions\r\n\r\nfunction env($name, $global, $val) {\r\n    if ($PSBoundParameters.ContainsKey('val')) {\r\n        Show-DeprecatedWarning $MyInvocation 'Set-EnvVar'\r\n        Set-EnvVar -Name $name -Value $val -Global:$global\r\n    } else {\r\n        Show-DeprecatedWarning $MyInvocation 'Get-EnvVar'\r\n        Get-EnvVar -Name $name -Global:$global\r\n    }\r\n}\r\n\r\nfunction strip_path($orig_path, $dir) {\r\n    Show-DeprecatedWarning $MyInvocation 'Split-PathLikeEnvVar'\r\n    Split-PathLikeEnvVar -Pattern @($dir) -Path $orig_path\r\n}\r\n\r\nfunction add_first_in_path($dir, $global) {\r\n    Show-DeprecatedWarning $MyInvocation 'Add-Path'\r\n    Add-Path -Path $dir -Global:$global -Force\r\n}\r\n\r\nfunction remove_from_path($dir, $global) {\r\n    Show-DeprecatedWarning $MyInvocation 'Remove-Path'\r\n    Remove-Path -Path $dir -Global:$global\r\n}\r\n"
  },
  {
    "path": "lib/versions.ps1",
    "content": "function Get-LatestVersion {\r\n    <#\r\n    .SYNOPSIS\r\n        Get latest version of app from manifest\r\n    .PARAMETER AppName\r\n        App's name\r\n    .PARAMETER Bucket\r\n        Bucket which the app belongs to\r\n    .PARAMETER Uri\r\n        Remote app manifest's URI\r\n    #>\r\n    [OutputType([String])]\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [Alias('App')]\r\n        [String]\r\n        $AppName,\r\n        [Parameter(Position = 1)]\r\n        [String]\r\n        $Bucket,\r\n        [Parameter(Position = 2)]\r\n        [String]\r\n        $Uri\r\n    )\r\n    process {\r\n        return (manifest $AppName $Bucket $Uri).version\r\n    }\r\n}\r\n\r\nfunction Select-CurrentVersion { # 'manifest.ps1'\r\n    <#\r\n    .SYNOPSIS\r\n        Select current version of installed app, from 'current\\manifest.json' or modified time of version directory\r\n    .PARAMETER AppName\r\n        App's name\r\n    .PARAMETER Global\r\n        Globally installed application\r\n    #>\r\n    [OutputType([String])]\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [Alias('App')]\r\n        [String]\r\n        $AppName,\r\n        [Parameter(Position = 1)]\r\n        [Switch]\r\n        $Global\r\n    )\r\n    process {\r\n        $currentPath = \"$(appdir $AppName $Global)\\current\"\r\n        if (!(get_config NO_JUNCTION)) {\r\n            $currentVersion = (parse_json \"$currentPath\\manifest.json\").version\r\n            if ($currentVersion -eq 'nightly') {\r\n                $currentVersion = (Get-Item $currentPath).Target | Split-Path -Leaf\r\n            }\r\n        }\r\n        if ($null -eq $currentVersion) {\r\n            $installedVersion = Get-InstalledVersion -AppName $AppName -Global:$Global\r\n            if ($installedVersion) {\r\n                $currentVersion = @($installedVersion)[-1]\r\n            } else {\r\n                $currentVersion = $null\r\n            }\r\n        }\r\n        return $currentVersion\r\n    }\r\n}\r\n\r\nfunction Get-InstalledVersion {\r\n    <#\r\n    .SYNOPSIS\r\n        Get all installed version of app, by checking version directories' 'install.json'\r\n    .PARAMETER AppName\r\n        App's name\r\n    .PARAMETER Global\r\n        Globally installed application\r\n    .NOTES\r\n        Versions are sorted from oldest to newest, i.e., latest installed version is the last one in the output array.\r\n        If no installed version found, empty array will be returned.\r\n    #>\r\n    [OutputType([Object[]])]\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [Alias('App')]\r\n        [String]\r\n        $AppName,\r\n        [Parameter(Position = 1)]\r\n        [Switch]\r\n        $Global\r\n    )\r\n    process {\r\n        $appPath = appdir $AppName $Global\r\n        if (Test-Path $appPath) {\r\n            $versions = @((Get-ChildItem \"$appPath\\*\\install.json\" | Sort-Object -Property LastWriteTimeUtc).Directory.Name)\r\n            return $versions | Where-Object { ($_ -ne 'current') -and ($_ -notlike '_*.old*') }\r\n        } else {\r\n            return @()\r\n        }\r\n    }\r\n    # Deprecated\r\n    # sort_versions (Get-ChildItem $appPath -dir -attr !reparsePoint | Where-Object { $null -ne $(Get-ChildItem $_.FullName) } | ForEach-Object { $_.Name })\r\n}\r\n\r\nfunction Compare-Version {\r\n    <#\r\n    .SYNOPSIS\r\n        Compare versions, mainly according to SemVer's rules\r\n    .PARAMETER ReferenceVersion\r\n        Specifies a version used as a reference for comparison\r\n    .PARAMETER DifferenceVersion\r\n        Specifies the version that are compared to the reference version\r\n    .PARAMETER Delimiter\r\n        Specifies the delimiter of versions\r\n    .OUTPUTS\r\n        System.Int32\r\n            '0' if DifferenceVersion is equal to ReferenceVersion,\r\n            '1' if DifferenceVersion is greater then ReferenceVersion,\r\n            '-1' if DifferenceVersion is less then ReferenceVersion\r\n    #>\r\n    [OutputType([Int32])]\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0)]\r\n        [AllowEmptyString()]\r\n        [String]\r\n        $ReferenceVersion,\r\n        [Parameter(Mandatory = $true, Position = 1, ValueFromPipeline = $true)]\r\n        [AllowEmptyString()]\r\n        [String]\r\n        $DifferenceVersion,\r\n        [String]\r\n        $Delimiter = '-'\r\n    )\r\n    process {\r\n        # Use '+' sign as post-release, see https://github.com/ScoopInstaller/Scoop/pull/3721#issuecomment-553718093\r\n        $ReferenceVersion, $DifferenceVersion = @($ReferenceVersion, $DifferenceVersion) -replace '\\+', '-'\r\n\r\n        # Return 0 if versions are equal\r\n        if ($DifferenceVersion -eq $ReferenceVersion) {\r\n            return 0\r\n        }\r\n\r\n        # Preprocess versions (split, convert and separate)\r\n        $splitReferenceVersion = @(SplitVersion -Version $ReferenceVersion -Delimiter $Delimiter)\r\n        $splitDifferenceVersion = @(SplitVersion -Version $DifferenceVersion -Delimiter $Delimiter)\r\n\r\n        # Nightly versions are always equal unless UPDATE_NIGHTLY is $true\r\n        if ($splitReferenceVersion[0] -eq 'nightly' -and $splitDifferenceVersion[0] -eq 'nightly') {\r\n            if (get_config UPDATE_NIGHTLY) {\r\n                # nightly versions will be compared by date if UPDATE_NIGHTLY is $true\r\n                if ($null -eq $splitReferenceVersion[1]) {\r\n                    $splitReferenceVersion += Get-Date -Format 'yyyyMMdd'\r\n                }\r\n                if ($null -eq $splitDifferenceVersion[1]) {\r\n                    $splitDifferenceVersion += Get-Date -Format 'yyyyMMdd'\r\n                }\r\n                return [Math]::Sign($splitDifferenceVersion[1] - $splitReferenceVersion[1])\r\n            } else {\r\n                return 0\r\n            }\r\n        }\r\n\r\n        for ($i = 0; $i -lt [Math]::Max($splitReferenceVersion.Length, $splitDifferenceVersion.Length); $i++) {\r\n            # '1.1-alpha' is less then '1.1'\r\n            if ($i -ge $splitReferenceVersion.Length) {\r\n                if ($splitDifferenceVersion[$i] -match 'alpha|beta|rc|pre') {\r\n                    return -1\r\n                } else {\r\n                    return 1\r\n                }\r\n            }\r\n            # '1.1' is greater then '1.1-beta'\r\n            if ($i -ge $splitDifferenceVersion.Length) {\r\n                if ($splitReferenceVersion[$i] -match 'alpha|beta|rc|pre') {\r\n                    return 1\r\n                } else {\r\n                    return -1\r\n                }\r\n            }\r\n\r\n            # If some parts of versions have '.', compare them with delimiter '.'\r\n            if (($splitReferenceVersion[$i] -match '\\.') -or ($splitDifferenceVersion[$i] -match '\\.')) {\r\n                $Result = Compare-Version -ReferenceVersion $splitReferenceVersion[$i] -DifferenceVersion $splitDifferenceVersion[$i] -Delimiter '.'\r\n                # If the parts are equal, continue to next part, otherwise return\r\n                if ($Result -ne 0) {\r\n                    return $Result\r\n                } else {\r\n                    continue\r\n                }\r\n            }\r\n\r\n            # If some parts of versions have '_', compare them with delimiter '_'\r\n            if (($splitReferenceVersion[$i] -match '_') -or ($splitDifferenceVersion[$i] -match '_')) {\r\n                $Result = Compare-Version -ReferenceVersion $splitReferenceVersion[$i] -DifferenceVersion $splitDifferenceVersion[$i] -Delimiter '_'\r\n                # If the parts are equal, continue to next part, otherwise return\r\n                if ($Result -ne 0) {\r\n                    return $Result\r\n                } else {\r\n                    continue\r\n                }\r\n            }\r\n\r\n            # Don't try to compare [Long] to [String]\r\n            if ($null -ne $splitReferenceVersion[$i] -and $null -ne $splitDifferenceVersion[$i]) {\r\n                if ($splitReferenceVersion[$i] -is [String] -and $splitDifferenceVersion[$i] -isnot [String]) {\r\n                    $splitDifferenceVersion[$i] = \"$($splitDifferenceVersion[$i])\"\r\n                }\r\n                if ($splitDifferenceVersion[$i] -is [String] -and $splitReferenceVersion[$i] -isnot [String]) {\r\n                    $splitReferenceVersion[$i] = \"$($splitReferenceVersion[$i])\"\r\n                }\r\n            }\r\n\r\n            # Compare [String] or [Long]\r\n            if ($splitDifferenceVersion[$i] -gt $splitReferenceVersion[$i]) {\r\n                return 1\r\n            }\r\n            if ($splitDifferenceVersion[$i] -lt $splitReferenceVersion[$i]) {\r\n                return -1\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n# Helper function\r\nfunction SplitVersion {\r\n    <#\r\n    .SYNOPSIS\r\n        Split version by Delimiter, convert number string to number, and separate letters from numbers\r\n    .PARAMETER Version\r\n        Specifies a version\r\n    .PARAMETER Delimiter\r\n        Specifies the delimiter of version (Literal)\r\n    #>\r\n    [OutputType([Object[]])]\r\n    [CmdletBinding()]\r\n    param (\r\n        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]\r\n        [AllowEmptyString()]\r\n        [String]\r\n        $Version,\r\n        [String]\r\n        $Delimiter = '-'\r\n    )\r\n    process {\r\n        $Version = $Version -replace '[a-zA-Z]+', \"$Delimiter$&$Delimiter\"\r\n        return ($Version -split [Regex]::Escape($Delimiter) -ne '' | ForEach-Object { if ($_ -match '^\\d+$') { [Long]$_ } else { $_ } })\r\n    }\r\n}\r\n\r\n# Deprecated\r\n# Not used anymore in scoop core\r\nfunction qsort($ary, $fn) {\r\n    warn '\"qsort\" is deprecated. Please avoid using it anymore.'\r\n    if ($null -eq $ary) { return @() }\r\n    if (!($ary -is [array])) { return @($ary) }\r\n\r\n    $pivot = $ary[0]\r\n    $rem = $ary[1..($ary.length - 1)]\r\n\r\n    $lesser = qsort ($rem | Where-Object { (& $fn $pivot $_) -lt 0 }) $fn\r\n\r\n    $greater = qsort ($rem | Where-Object { (& $fn $pivot $_) -ge 0 }) $fn\r\n\r\n    return @() + $lesser + @($pivot) + $greater\r\n}\r\n\r\n# Deprecated\r\n# Not used anymore in scoop core\r\nfunction sort_versions($versions) {\r\n    warn '\"sort_versions\" is deprecated. Please avoid using it anymore.'\r\n    qsort $versions Compare-Version\r\n}\r\n\r\nfunction compare_versions($a, $b) {\r\n    Show-DeprecatedWarning $MyInvocation 'Compare-Version'\r\n    # Please note the parameters' sequence\r\n    return Compare-Version -ReferenceVersion $b -DifferenceVersion $a\r\n}\r\n\r\nfunction latest_version($app, $bucket, $url) {\r\n    Show-DeprecatedWarning $MyInvocation 'Get-LatestVersion'\r\n    return Get-LatestVersion -AppName $app -Bucket $bucket -Uri $url\r\n}\r\n\r\nfunction current_version($app, $global) {\r\n    Show-DeprecatedWarning $MyInvocation 'Select-CurrentVersion'\r\n    return Select-CurrentVersion -AppName $app -Global:$global\r\n}\r\n\r\nfunction versions($app, $global) {\r\n    Show-DeprecatedWarning $MyInvocation 'Get-InstalledVersion'\r\n    return Get-InstalledVersion -AppName $app -Global:$global\r\n}\r\n"
  },
  {
    "path": "libexec/scoop-alias.ps1",
    "content": "# Usage: scoop alias <subcommand> [options] [<args>]\r\n# Summary: Manage scoop aliases\r\n# Help: Available subcommands: add, rm, list.\r\n#\r\n# Aliases are custom Scoop subcommands that can be created to make common tasks easier.\r\n#\r\n# To add an alias:\r\n#\r\n#     scoop alias add <name> <command> [<description>]\r\n#\r\n# e.g.,\r\n#\r\n#     scoop alias add rm 'scoop uninstall $args[0]' 'Uninstall an app'\r\n#     scoop alias add upgrade 'scoop update *' 'Update all apps, just like \"brew\" or \"apt\"'\r\n#\r\n# To remove an alias:\r\n#\r\n#     scoop alias rm <name>\r\n#\r\n# To list all aliases:\r\n#\r\n#     scoop alias list [-v|--verbose]\r\n#\r\n# Options:\r\n#   -v, --verbose  Show alias description and table headers (works only for \"list\")\r\n\r\nparam($SubCommand)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n\r\n$SubCommands = @('add', 'rm', 'list')\r\nif ($SubCommand -notin $SubCommands) {\r\n    if (!$SubCommand) {\r\n        error '<subcommand> missing'\r\n    } else {\r\n        error \"'$SubCommand' is not one of available subcommands: $($SubCommands -join ', ')\"\r\n    }\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\n$opt, $other, $err = getopt $Args 'v' 'verbose'\r\nif ($err) { \"scoop alias: $err\"; exit 1 }\r\n\r\n$name, $command, $description = $other\r\n$verbose = $opt.v -or $opt.verbose\r\n\r\nswitch ($SubCommand) {\r\n    'add' {\r\n        if (!$name -or !$command) {\r\n            error \"<name> and <command> must be specified for subcommand 'add'\"\r\n            exit 1\r\n        }\r\n        add_alias $name $command $description\r\n    }\r\n    'rm' {\r\n        if (!$name) {\r\n            error \"<name> must be specified for subcommand 'rm'\"\r\n            exit 1\r\n        }\r\n        rm_alias $name\r\n    }\r\n    'list' {\r\n        list_aliases $verbose\r\n    }\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-bucket.ps1",
    "content": "# Usage: scoop bucket add|list|known|rm [<args>]\r\n# Summary: Manage Scoop buckets\r\n# Help: Add, list or remove buckets.\r\n#\r\n# Buckets are repositories of apps available to install. Scoop comes with\r\n# a default bucket, but you can also add buckets that you or others have\r\n# published.\r\n#\r\n# To add a bucket:\r\n#     scoop bucket add <name> [<repo>]\r\n#\r\n# e.g.:\r\n#     scoop bucket add extras https://github.com/ScoopInstaller/Extras.git\r\n#\r\n# Since the 'extras' bucket is known to Scoop, this can be shortened to:\r\n#     scoop bucket add extras\r\n#\r\n# To list all known buckets, use:\r\n#     scoop bucket known\r\nparam($cmd, $name, $repo)\r\n\r\nif (get_config NO_JUNCTION) {\r\n    . \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n}\r\n\r\nif (get_config USE_SQLITE_CACHE) {\r\n    . \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\database.ps1\"\r\n}\r\n\r\n$usage_add = 'usage: scoop bucket add <name> [<repo>]'\r\n$usage_rm = 'usage: scoop bucket rm <name>'\r\n\r\nswitch ($cmd) {\r\n    'add' {\r\n        if (!$name) {\r\n            '<name> missing'\r\n            $usage_add\r\n            exit 1\r\n        }\r\n        if (!$repo) {\r\n            $repo = known_bucket_repo $name\r\n            if (!$repo) {\r\n                \"Unknown bucket '$name'. Try specifying <repo>.\"\r\n                $usage_add\r\n                exit 1\r\n            }\r\n        }\r\n        $status = add_bucket $name $repo\r\n        exit $status\r\n    }\r\n    'rm' {\r\n        if (!$name) {\r\n            '<name> missing'\r\n            $usage_rm\r\n            exit 1\r\n        }\r\n        $status = rm_bucket $name\r\n        exit $status\r\n    }\r\n    'list' {\r\n        $buckets = list_buckets\r\n        if (!$buckets.Length) {\r\n            warn \"No bucket found. Please run 'scoop bucket add main' to add the default 'main' bucket.\"\r\n            exit 2\r\n        } else {\r\n            $buckets\r\n            exit 0\r\n        }\r\n    }\r\n    'known' {\r\n        known_buckets\r\n        exit 0\r\n    }\r\n    default {\r\n        \"scoop bucket: cmd '$cmd' not supported\"\r\n        my_usage\r\n        exit 1\r\n    }\r\n}\r\n"
  },
  {
    "path": "libexec/scoop-cache.ps1",
    "content": "# Usage: scoop cache show|rm [app(s)]\r\n# Summary: Show or clear the download cache\r\n# Help: Scoop caches downloads so you don't need to download the same files\r\n# when you uninstall and re-install the same version of an app.\r\n#\r\n# You can use\r\n#     scoop cache show\r\n# to see what's in the cache, and\r\n#     scoop cache rm <app> to remove downloads for a specific app.\r\n#\r\n# To clear everything in your cache, use:\r\n#     scoop cache rm *\r\n# You can also use the `-a/--all` switch in place of `*` here\r\n\r\nparam($cmd)\r\n\r\nfunction cacheinfo($file) {\r\n    $app, $version, $url = $file.Name -split '#'\r\n    New-Object PSObject -Property @{ Name = $app; Version = $version; Length = $file.Length }\r\n}\r\n\r\nfunction cacheshow($app) {\r\n    if (!$app -or $app -eq '*') {\r\n        $app = '.*?'\r\n    } else {\r\n        $app = '(' + ($app -join '|') + ')'\r\n    }\r\n    $files = @(Get-ChildItem $cachedir | Where-Object -Property Name -Value \"^$app#\" -Match)\r\n    $totalLength = ($files | Measure-Object -Property Length -Sum).Sum\r\n\r\n    $files | ForEach-Object { cacheinfo $_ } | Select-Object Name, Version, Length\r\n\r\n    Write-Host \"Total: $($files.Length) $(pluralize $files.Length 'file' 'files'), $(filesize $totalLength)\" -ForegroundColor Yellow\r\n}\r\n\r\nfunction cacheremove($app) {\r\n    if (!$app) {\r\n        'ERROR: <app(s)> missing'\r\n        my_usage\r\n        exit 1\r\n    } elseif ($app -eq '*' -or $app -eq '-a' -or $app -eq '--all') {\r\n        $files = @(Get-ChildItem $cachedir)\r\n    } else {\r\n        $app = '(' + ($app -join '|') + ')'\r\n        $files = @(Get-ChildItem $cachedir | Where-Object -Property Name -Value \"^$app#\" -Match)\r\n    }\r\n    $totalLength = ($files | Measure-Object -Property Length -Sum).Sum\r\n\r\n    $files | ForEach-Object {\r\n        $curr = cacheinfo $_\r\n        Write-Host \"Removing $($_.Name)...\"\r\n        Remove-Item $_.FullName\r\n        if(Test-Path \"$cachedir\\$($curr.Name).txt\") {\r\n            Remove-Item \"$cachedir\\$($curr.Name).txt\"\r\n        }\r\n    }\r\n\r\n    Write-Host \"Deleted: $($files.Length) $(pluralize $files.Length 'file' 'files'), $(filesize $totalLength)\" -ForegroundColor Yellow\r\n}\r\n\r\nswitch($cmd) {\r\n    'rm' {\r\n        cacheremove $Args\r\n    }\r\n    'show' {\r\n        cacheshow $Args\r\n    }\r\n    default {\r\n        cacheshow (@($cmd) + $Args)\r\n    }\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-cat.ps1",
    "content": "# Usage: scoop cat <app>\r\n# Summary: Show content of specified manifest.\r\n# Help: Show content of specified manifest.\r\n# If configured, `bat` will be used to pretty-print the JSON.\r\n# See `cat_style` in `scoop help config` for further information.\r\n\r\nparam($app)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'ConvertToPrettyJson'\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Get-Manifest'\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\" # 'Get-UserAgent'\r\n\r\nif (!$app) { error '<app> missing'; my_usage; exit 1 }\r\n\r\n$null, $manifest, $bucket, $url = Get-Manifest $app\r\n\r\nif ($manifest) {\r\n    $style = get_config CAT_STYLE\r\n    if ($style) {\r\n        $manifest | ConvertToPrettyJson | bat --no-paging --style $style --language json\r\n    } else {\r\n        $manifest | ConvertToPrettyJson\r\n    }\r\n} else {\r\n    abort \"Couldn't find manifest for '$app'$(if($bucket) { \" from '$bucket' bucket\" } elseif($url) { \" at '$url'\" }).\"\r\n}\r\n\r\nexit $exitCode\r\n"
  },
  {
    "path": "libexec/scoop-checkup.ps1",
    "content": "# Usage: scoop checkup\r\n# Summary: Check for potential problems\r\n# Help: Performs a series of diagnostic tests to try to identify things that may\r\n# cause problems with Scoop.\r\n\r\n. \"$PSScriptRoot\\..\\lib\\diagnostic.ps1\"\r\n\r\n$issues = 0\r\n$defenderIssues = 0\r\n\r\n$adminPrivileges = ([System.Security.Principal.WindowsPrincipal] [System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)\r\n\r\nif ($adminPrivileges -and $env:USERNAME -ne 'WDAGUtilityAccount') {\r\n    $defenderIssues += !(check_windows_defender $false)\r\n    $defenderIssues += !(check_windows_defender $true)\r\n}\r\n\r\n$issues += !(check_main_bucket)\r\n$issues += !(check_long_paths)\r\n$issues += !(Get-WindowsDeveloperModeStatus)\r\n\r\nif (!(Test-HelperInstalled -Helper 7zip) -and !(get_config USE_EXTERNAL_7ZIP)) {\r\n    warn \"'7-Zip' is not installed! It's required for unpacking most programs. Please Run 'scoop install 7zip'.\"\r\n    $issues++\r\n}\r\n\r\nif (!(Test-HelperInstalled -Helper Innounp)) {\r\n    warn \"'Inno Setup Unpacker' is not installed! It's required for unpacking InnoSetup files. Please run 'scoop install innounp'.\"\r\n    $issues++\r\n}\r\n\r\nif (!(Test-HelperInstalled -Helper Dark)) {\r\n    warn \"'dark' is not installed! It's required for unpacking installers created with the WiX Toolset. Please run 'scoop install dark' or 'scoop install wixtoolset'.\"\r\n    $issues++\r\n}\r\n\r\n$globaldir = New-Object System.IO.DriveInfo($globaldir)\r\nif ($globaldir.DriveFormat -ne 'NTFS') {\r\n    error \"Scoop requires an NTFS volume to work! Please point `$env:SCOOP_GLOBAL or 'global_path' variable in '~/.config/scoop/config.json' to another Drive.\"\r\n    $issues++\r\n}\r\n\r\n$scoopdir = New-Object System.IO.DriveInfo($scoopdir)\r\nif ($scoopdir.DriveFormat -ne 'NTFS') {\r\n    error \"Scoop requires an NTFS volume to work! Please point `$env:SCOOP or 'root_path' variable in '~/.config/scoop/config.json' to another Drive.\"\r\n    $issues++\r\n}\r\n\r\nif ($issues) {\r\n    warn \"Found $issues potential $(pluralize $issues problem problems).\"\r\n} elseif ($defenderIssues) {\r\n    info \"Found $defenderIssues performance $(pluralize $defenderIssues problem problems).\"\r\n    warn \"Security is more important than performance, in most cases.\"\r\n} else {\r\n    success \"No problems identified!\"\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-cleanup.ps1",
    "content": "# Usage: scoop cleanup <app> [options]\r\n# Summary: Cleanup apps by removing old versions\r\n# Help: 'scoop cleanup' cleans Scoop apps by removing old versions.\r\n# 'scoop cleanup <app>' cleans up the old versions of that app if said versions exist.\r\n#\r\n# You can use '*' in place of <app> or `-a`/`--all` switch to cleanup all apps.\r\n#\r\n# Options:\r\n#   -a, --all          Cleanup all apps (alternative to '*')\r\n#   -g, --global       Cleanup a globally installed app\r\n#   -k, --cache        Remove outdated download cache\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Select-CurrentVersion' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\install.ps1\" # persist related\r\n\r\n$opt, $apps, $err = getopt $args 'agk' 'all', 'global', 'cache'\r\nif ($err) { \"scoop cleanup: $err\"; exit 1 }\r\n$global = $opt.g -or $opt.global\r\n$cache = $opt.k -or $opt.cache\r\n$all = $opt.a -or $opt.all\r\n\r\nif (!$apps -and !$all) { 'ERROR: <app> missing'; my_usage; exit 1 }\r\n\r\nif ($global -and !(is_admin)) {\r\n    'ERROR: you need admin rights to cleanup global apps'; exit 1\r\n}\r\n\r\nfunction cleanup($app, $global, $verbose, $cache) {\r\n    $current_version = Select-CurrentVersion -AppName $app -Global:$global\r\n    if ($cache) {\r\n        Remove-Item \"$cachedir\\$app#*\" -Exclude \"$app#$current_version#*\"\r\n    }\r\n    $appDir = appdir $app $global\r\n    $versions = Get-ChildItem $appDir -Name\r\n    $versions = $versions | Where-Object { $current_version -ne $_ -and $_ -ne 'current' }\r\n    if (!$versions) {\r\n        if ($verbose) { success \"$app is already clean\" }\r\n        return\r\n    }\r\n\r\n    Write-Host -f yellow \"Removing $app`:\" -NoNewline\r\n    $versions | ForEach-Object {\r\n        $version = $_\r\n        Write-Host \" $version\" -NoNewline\r\n        $dir = versiondir $app $version $global\r\n        # unlink all potential old link before doing recursive Remove-Item\r\n        unlink_persist_data (installed_manifest $app $version $global) $dir\r\n        Remove-Item $dir -ErrorAction Stop -Recurse -Force\r\n    }\r\n    $leftVersions = Get-ChildItem $appDir\r\n    if ($leftVersions.Length -eq 1 -and $leftVersions.Name -eq 'current' -and $leftVersions.LinkType) {\r\n        attrib $leftVersions.FullName -R /L\r\n        Remove-Item $leftVersions.FullName -ErrorAction Stop -Force\r\n        $leftVersions = $null\r\n    }\r\n    if (!$leftVersions) {\r\n        Remove-Item $appDir -ErrorAction Stop -Force\r\n    }\r\n    Write-Host ''\r\n}\r\n\r\nif ($apps -or $all) {\r\n    if ($apps -eq '*' -or $all) {\r\n        $verbose = $false\r\n        $apps = applist (installed_apps $false) $false\r\n        if ($global) {\r\n            $apps += applist (installed_apps $true) $true\r\n        }\r\n    } else {\r\n        $verbose = $true\r\n        $apps = Confirm-InstallationStatus $apps -Global:$global\r\n    }\r\n\r\n    # $apps is now a list of ($app, $global) tuples\r\n    $apps | ForEach-Object { cleanup @_ $verbose $cache }\r\n\r\n    if ($cache) {\r\n        Remove-Item \"$cachedir\\*.download\" -ErrorAction Ignore\r\n    }\r\n\r\n    if (!$verbose) {\r\n        success 'Everything is shiny now!'\r\n    }\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-config.ps1",
    "content": "# Usage: scoop config [rm] name [value]\r\n# Summary: Get or set configuration values\r\n# Help: The scoop configuration file is saved at ~/.config/scoop/config.json.\r\n#\r\n# To get all configuration settings:\r\n#\r\n#     scoop config\r\n#\r\n# To get a configuration setting:\r\n#\r\n#     scoop config <name>\r\n#\r\n# To set a configuration setting:\r\n#\r\n#     scoop config <name> <value>\r\n#\r\n# To remove a configuration setting:\r\n#\r\n#     scoop config rm <name>\r\n#\r\n# Settings\r\n# --------\r\n#\r\n# use_external_7zip: $true|$false\r\n#       External 7zip (from path) will be used for archives extraction.\r\n#\r\n# use_lessmsi: $true|$false\r\n#       Prefer lessmsi utility over native msiexec.\r\n#\r\n# use_sqlite_cache: $true|$false\r\n#       Use SQLite database for caching. This is useful for speeding up 'scoop search' and 'scoop shim' commands.\r\n#\r\n# no_junction: $true|$false\r\n#       The 'current' version alias will not be used. Shims and shortcuts will point to specific version instead.\r\n#\r\n# scoop_repo: http://github.com/ScoopInstaller/Scoop\r\n#       Git repository containining scoop source code.\r\n#       This configuration is useful for custom forks.\r\n#\r\n# scoop_branch: master|develop\r\n#       Allow to use different branch than master.\r\n#       Could be used for testing specific functionalities before released into all users.\r\n#       If you want to receive updates earlier to test new functionalities use develop (see: 'https://github.com/ScoopInstaller/Scoop/issues/2939')\r\n#\r\n# proxy: [username:password@]host:port\r\n#       By default, Scoop will use the proxy settings from Internet Options, but with anonymous authentication.\r\n#\r\n#       * To use the credentials for the current logged-in user, use 'currentuser' in place of username:password\r\n#       * To use the system proxy settings configured in Internet Options, use 'default' in place of host:port\r\n#       * An empty or unset value for proxy is equivalent to 'default' (with no username or password)\r\n#       * To bypass the system proxy and connect directly, use 'none' (with no username or password)\r\n#\r\n# autostash_on_conflict: $true|$false\r\n#       When a conflict is detected during updating, Scoop will auto-stash the uncommitted changes.\r\n#       (Default is $false, which will abort the update)\r\n#\r\n# default_architecture: 64bit|32bit|arm64\r\n#       Allow to configure preferred architecture for application installation.\r\n#       If not specified, architecture is determined by system.\r\n#\r\n# debug: $true|$false\r\n#       Additional and detailed output will be shown.\r\n#\r\n# force_update: $true|$false\r\n#       Force apps updating to bucket's version.\r\n#\r\n# show_update_log: $true|$false\r\n#       Do not show changed commits on 'scoop update'\r\n#\r\n# show_manifest: $true|$false\r\n#       Displays the manifest of every app that's about to\r\n#       be installed, then asks user if they wish to proceed.\r\n#\r\n# shim: kiennq|scoopcs|71\r\n#       Choose scoop shim build.\r\n#\r\n# root_path: $Env:UserProfile\\scoop\r\n#       Path to Scoop root directory.\r\n#\r\n# global_path: $Env:ProgramData\\scoop\r\n#       Path to Scoop root directory for global apps.\r\n#\r\n# cache_path:\r\n#       For downloads, defaults to 'cache' folder under Scoop root directory.\r\n#\r\n# gh_token:\r\n#       GitHub API token used to make authenticated requests.\r\n#       This is essential for checkver and similar functions to run without\r\n#       incurring rate limits and download from private repositories.\r\n#\r\n# virustotal_api_key:\r\n#       API key used for uploading/scanning files using virustotal.\r\n#       See: 'https://support.virustotal.com/hc/en-us/articles/115002088769-Please-give-me-an-API-key'\r\n#\r\n# cat_style:\r\n#       When set to a non-empty string, Scoop will use 'bat' to display the manifest for\r\n#       the `scoop cat` command and while doing manifest review. This requires 'bat' to be\r\n#       installed (run `scoop install bat` to install it), otherwise errors will be thrown.\r\n#       The accepted values are the same as ones passed to the --style flag of 'bat'.\r\n#\r\n# ignore_running_processes: $true|$false\r\n#       When set to $false (default), Scoop would stop its procedure immediately if it detects\r\n#       any target app process is running. Procedure here refers to reset/uninstall/update.\r\n#       When set to $true, Scoop only displays a warning message and continues procedure.\r\n#\r\n# private_hosts:\r\n#       Array of private hosts that need additional authentication.\r\n#       For example, if you want to access a private GitHub repository,\r\n#       you need to add the host to this list with 'match' and 'headers' strings.\r\n#\r\n# hold_update_until:\r\n#       Disable/Hold Scoop self-updates, until the specified date.\r\n#       `scoop hold scoop` will set the value to one day later.\r\n#       Should be in the format 'YYYY-MM-DD', 'YYYY/MM/DD' or any other forms that accepted by '[System.DateTime]::Parse()'.\r\n#       Ref: https://docs.microsoft.com/dotnet/api/system.datetime.parse?view=netframework-4.5#StringToParse\r\n#\r\n# update_nightly: $true|$false\r\n#       Nightly version is formatted as 'nightly-yyyyMMdd' and will be updated after one day if this is set to $true.\r\n#       Otherwise, nightly version will not be updated unless `--force` is used.\r\n#\r\n# use_isolated_path: $true|$false|[string]\r\n#       When set to $true, Scoop will use `SCOOP_PATH` environment variable to store apps' `PATH`s.\r\n#       When set to arbitrary non-empty string, Scoop will use that string as the environment variable name instead.\r\n#       This is useful when you want to isolate Scoop from the system `PATH`.\r\n#\r\n# ARIA2 configuration\r\n# -------------------\r\n#\r\n# aria2-enabled: $true|$false\r\n#       Aria2c will be used for downloading of artifacts.\r\n#\r\n# aria2-warning-enabled: $true|$false\r\n#       Disable Aria2c warning which is shown while downloading.\r\n#\r\n# aria2-retry-wait: 2\r\n#       Number of seconds to wait between retries.\r\n#       See: 'https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-retry-wait'\r\n#\r\n# aria2-split: 5\r\n#       Number of connections used for downlaod.\r\n#       See: 'https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-s'\r\n#\r\n# aria2-max-connection-per-server: 5\r\n#       The maximum number of connections to one server for each download.\r\n#       See: 'https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-x'\r\n#\r\n# aria2-min-split-size: 5M\r\n#       Downloaded files will be splitted by this configured size and downloaded using multiple connections.\r\n#       See: 'https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-k'\r\n#\r\n# aria2-options:\r\n#       Array of additional aria2 options.\r\n#       See: 'https://aria2.github.io/manual/en/html/aria2c.html#options'\r\n\r\nparam($name, $value)\r\n\r\nif (!$name) {\r\n    $scoopConfig\r\n} elseif ($name -like '--help') {\r\n    my_usage\r\n} elseif ($name -like 'rm') {\r\n    set_config $value $null | Out-Null\r\n    Write-Host \"'$value' has been removed\"\r\n} elseif ($null -ne $value) {\r\n    set_config $name $value | Out-Null\r\n    Write-Host \"'$name' has been set to '$value'\"\r\n} else {\r\n    $value = get_config $name\r\n    if($null -eq $value) {\r\n        Write-Host \"'$name' is not set\"\r\n    } else {\r\n        if ($value -is [System.DateTime]) {\r\n            $value.ToString('o')\r\n        } else {\r\n            $value\r\n        }\r\n    }\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-create.ps1",
    "content": "# Usage: scoop create <url>\r\n# Summary: Create a custom app manifest\r\n# Help: Create your own custom app manifest\r\nparam($url)\r\n\r\nfunction create_manifest($url) {\r\n    $manifest = new_manifest\r\n\r\n    $manifest.url = $url\r\n\r\n    $url_parts = $null\r\n    try {\r\n        $url_parts = parse_url $url\r\n    } catch {\r\n        abort \"Error: $url is not a valid URL\"\r\n    }\r\n\r\n    $name = choose_item $url_parts 'App name'\r\n    $name = if ($name.Length -gt 0) {\r\n        $name\r\n    } else {\r\n        file_name ($url_parts | Select-Object -Last 1)\r\n    }\r\n\r\n    $manifest.version = choose_item $url_parts 'Version'\r\n\r\n    $manifest | ConvertTo-Json | Out-File -FilePath \"$name.json\" -Encoding ASCII\r\n    $manifest_path = Join-Path $pwd \"$name.json\"\r\n    Write-Host \"Created '$manifest_path'.\"\r\n}\r\n\r\nfunction new_manifest() {\r\n    @{ 'homepage' = ''; 'license' = ''; 'version' = ''; 'url' = '';\r\n        'hash' = ''; 'extract_dir' = ''; 'bin' = ''; 'depends' = ''\r\n    }\r\n}\r\n\r\nfunction file_name($segment) {\r\n    $segment.substring(0, $segment.lastindexof('.'))\r\n}\r\n\r\nfunction parse_url($url) {\r\n    $uri = New-Object Uri $url\r\n    $uri.pathandquery.substring(1).split('/')\r\n}\r\n\r\nfunction choose_item($list, $query) {\r\n    for ($i = 0; $i -lt $list.count; $i++) {\r\n        $item = $list[$i]\r\n        Write-Host \"$($i + 1)) $item\"\r\n    }\r\n    $sel = Read-Host $query\r\n\r\n    if ($sel.trim() -match '^[0-9+]$') {\r\n        return $list[$sel - 1]\r\n    }\r\n\r\n    $sel\r\n}\r\n\r\nif (!$url) {\r\n    & \"$PSScriptRoot\\scoop-help.ps1\" create\r\n} else {\r\n    create_manifest $url\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-depends.ps1",
    "content": "# Usage: scoop depends <app>\r\n# Summary: List dependencies for an app, in the order they'll be installed\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\depends.ps1\" # 'Get-Dependency'\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Get-Manifest' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\" # 'Get-UserAgent'\r\n\r\n$opt, $apps, $err = getopt $args 'a:' 'arch='\r\n$app = $apps[0]\r\n\r\nif(!$app) { error '<app> missing'; my_usage; exit 1 }\r\n\r\n$architecture = Get-DefaultArchitecture\r\ntry {\r\n    $architecture = Format-ArchitectureString ($opt.a + $opt.arch)\r\n} catch {\r\n    abort \"ERROR: $_\"\r\n}\r\n\r\n$deps = @()\r\nGet-Dependency $app $architecture | ForEach-Object {\r\n    $dep = [ordered]@{}\r\n\r\n    $app, $null, $bucket, $url = Get-Manifest $_\r\n    if (!$url) {\r\n        $bucket, $app = $_ -split '/'\r\n    }\r\n    $dep.Source = if ($url) { $url } else { $bucket }\r\n    $dep.Name = $app\r\n\r\n    $deps += [PSCustomObject]$dep\r\n}\r\n$deps\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-download.ps1",
    "content": "# Usage: scoop download <app> [options]\r\n# Summary: Download apps in the cache folder and verify hashes\r\n# Help: e.g. The usual way to download an app, without installing it (uses your local 'buckets'):\r\n#      scoop download git\r\n#\r\n# To download a different version of the app\r\n# (note that this will auto-generate the manifest using current version):\r\n#      scoop download gh@2.7.0\r\n#\r\n# To download an app from a manifest at a URL:\r\n#      scoop download https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/runat.json\r\n#\r\n# To download an app from a manifest on your computer\r\n#      scoop download path\\to\\app.json\r\n#\r\n# Options:\r\n#   -f, --force                     Force download (overwrite cache)\r\n#   -s, --skip-hash-check           Skip hash verification (use with caution!)\r\n#   -u, --no-update-scoop           Don't update Scoop before downloading if it's outdated\r\n#   -a, --arch <32bit|64bit|arm64>  Use the specified architecture, if the app supports it\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'autoupdate.ps1' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\autoupdate.ps1\" # 'generate_user_manifest' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'generate_user_manifest' 'Get-Manifest'\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\nif (get_config USE_SQLITE_CACHE) {\r\n    . \"$PSScriptRoot\\..\\lib\\database.ps1\"\r\n}\r\n\r\n$opt, $apps, $err = getopt $args 'fsua:' 'force', 'skip-hash-check', 'no-update-scoop', 'arch='\r\nif ($err) { error \"scoop download: $err\"; exit 1 }\r\n\r\n$check_hash = !($opt.s -or $opt.'skip-hash-check')\r\n$use_cache = !($opt.f -or $opt.force)\r\n$architecture = Get-DefaultArchitecture\r\ntry {\r\n    $architecture = Format-ArchitectureString ($opt.a + $opt.arch)\r\n} catch {\r\n    abort \"ERROR: $_\"\r\n}\r\n\r\nif (!$apps) { error '<app> missing'; my_usage; exit 1 }\r\n\r\nif (is_scoop_outdated) {\r\n    if ($opt.u -or $opt.'no-update-scoop') {\r\n        warn \"Scoop is out of date.\"\r\n    } else {\r\n        & \"$PSScriptRoot\\scoop-update.ps1\"\r\n    }\r\n}\r\n\r\n# we only want to show this warning once\r\nif(!$use_cache) { warn \"Cache is being ignored.\" }\r\n\r\nforeach ($curr_app in $apps) {\r\n    # Prevent leaking variables from previous iteration\r\n    $bucket = $version = $app = $manifest = $url = $null\r\n\r\n    $app, $bucket, $version = parse_app $curr_app\r\n    $app, $manifest, $bucket, $url = Get-Manifest \"$bucket/$app\"\r\n\r\n    info \"Downloading '$app'$(if ($version) { \" ($version)\" }) [$architecture]$(if ($bucket) { \" from $bucket bucket\" })\"\r\n\r\n    # Generate manifest if there is different version in manifest\r\n    if (($null -ne $version) -and ($manifest.version -ne $version)) {\r\n        $generated = generate_user_manifest $app $bucket $version\r\n        if ($null -eq $generated) {\r\n            error 'Manifest cannot be generated with provided version'\r\n            continue\r\n        }\r\n        $manifest = parse_json($generated)\r\n    }\r\n\r\n    if(!$manifest) {\r\n        error \"Couldn't find manifest for '$app'$(if($bucket) { \" from '$bucket' bucket\" } elseif($url) { \" at '$url'\" }).\"\r\n        continue\r\n    }\r\n    $version = $manifest.version\r\n    if(!$version) {\r\n        error \"Manifest doesn't specify a version.\"\r\n        continue\r\n    }\r\n    if($version -match '[^\\w\\.\\-\\+_]') {\r\n        error \"Manifest version has unsupported character '$($matches[0])'.\"\r\n        continue\r\n    }\r\n\r\n    $curr_check_hash = $check_hash\r\n    if ($version -eq 'nightly') {\r\n        $version = nightly_version\r\n        $curr_check_hash = $false\r\n    }\r\n\r\n    $architecture = Get-SupportedArchitecture $manifest $architecture\r\n    if ($null -eq $architecture) {\r\n        error \"'$app' doesn't support current architecture!\"\r\n        continue\r\n    }\r\n\r\n    if(Test-Aria2Enabled) {\r\n        Invoke-CachedAria2Download $app $version $manifest $architecture $cachedir $manifest.cookie $use_cache $curr_check_hash\r\n    } else {\r\n        foreach($url in script:url $manifest $architecture) {\r\n            try {\r\n                Invoke-CachedDownload $app $version $url $null $manifest.cookie $use_cache\r\n            } catch {\r\n                write-host -f darkred $_\r\n                error \"URL $url is not valid\"\r\n                $dl_failure = $true\r\n                continue\r\n            }\r\n\r\n            if($curr_check_hash) {\r\n                $manifest_hash = hash_for_url $manifest $url $architecture\r\n                $cached = cache_path $app $version $url\r\n                $ok, $err = check_hash $cached $manifest_hash (show_app $app $bucket)\r\n\r\n                if(!$ok) {\r\n                    error $err\r\n                    if(test-path $cached) {\r\n                        # rm cached file\r\n                        Remove-Item -force $cached\r\n                    }\r\n                    if ($url -like '*sourceforge.net*') {\r\n                        warn 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'\r\n                    }\r\n                    error (new_issue_msg $app $bucket \"hash check failed\")\r\n                    continue\r\n                }\r\n            } else {\r\n                info \"Skipping hash verification.\"\r\n            }\r\n        }\r\n    }\r\n\r\n    if (!$dl_failure) {\r\n        success \"'$app' ($version) was downloaded successfully!\"\r\n    }\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-export.ps1",
    "content": "# Usage: scoop export > scoopfile.json\r\n# Summary: Exports installed apps, buckets (and optionally configs) in JSON format\r\n# Help: Options:\r\n#   -c, --config       Export the Scoop configuration file too\r\n\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'ConvertToPrettyJson'\r\n\r\n$export = @{}\r\n\r\nif ($args[0] -eq '-c' -or $args[0] -eq '--config') {\r\n    $export.config = $scoopConfig\r\n    # Remove machine-specific properties\r\n    foreach ($prop in 'last_update', 'root_path', 'global_path', 'cache_path', 'alias') {\r\n        $export.config.PSObject.Properties.Remove($prop)\r\n    }\r\n}\r\n\r\n$export.buckets = list_buckets\r\n$export.apps = @(& \"$PSScriptRoot\\scoop-list.ps1\" 6>$null)\r\n\r\n$export | ConvertToPrettyJSON\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-help.ps1",
    "content": "# Usage: scoop help <command>\r\n# Summary: Show help for a command\r\nparam($cmd)\r\n\r\nfunction print_help($cmd) {\r\n    $file = Get-Content (command_path $cmd) -Raw\r\n\r\n    $usage = usage $file\r\n    $help = scoop_help $file\r\n\r\n    if ($usage) { \"$usage`n\" }\r\n    if ($help) { $help }\r\n}\r\n\r\nfunction print_summaries {\r\n    $commands = @()\r\n\r\n    command_files | ForEach-Object {\r\n        $command = [ordered]@{}\r\n        $command.Command = command_name $_\r\n        $command.Summary = summary (Get-Content (command_path $command.Command))\r\n        $commands += [PSCustomObject]$command\r\n    }\r\n\r\n    $commands\r\n}\r\n\r\n$commands = commands\r\n\r\nif(!($cmd)) {\r\n    Write-Host \"Usage: scoop <command> [<args>]\r\n\r\nAvailable commands are listed below.\r\n\r\nType 'scoop help <command>' to get more help for a specific command.\"\r\n    print_summaries\r\n} elseif($commands -contains $cmd) {\r\n    print_help $cmd\r\n} else {\r\n    warn \"scoop help: no such command '$cmd'\"\r\n    exit 1\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-hold.ps1",
    "content": "# Usage: scoop hold <apps>\r\n# Summary: Hold an app to disable updates\r\n# Help: To hold a user-scoped app:\r\n#      scoop hold <app>\r\n#\r\n# To hold a global app:\r\n#      scoop hold -g <app>\r\n#\r\n# Options:\r\n#   -g, --global  Hold globally installed apps\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'save_install_info' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'install_info' 'Select-CurrentVersion' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n\r\n$opt, $apps, $err = getopt $args 'g' 'global'\r\nif ($err) { \"scoop hold: $err\"; exit 1 }\r\n\r\n$global = $opt.g -or $opt.global\r\n\r\nif (!$apps) {\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\nif ($global -and !(is_admin)) {\r\n    error 'You need admin rights to hold a global app.'\r\n    exit 1\r\n}\r\n\r\nforeach ($app in $apps) {\r\n\r\n    if ($app -eq 'scoop') {\r\n        $hold_update_until = [System.DateTime]::Now.AddDays(1)\r\n        set_config HOLD_UPDATE_UNTIL $hold_update_until.ToString('o') | Out-Null\r\n        success \"$app is now held and might not be updated until $($hold_update_until.ToLocalTime()).\"\r\n        continue\r\n    }\r\n    if (!(installed $app $global)) {\r\n        if ($global) {\r\n            error \"'$app' is not installed globally.\"\r\n        } else {\r\n            error \"'$app' is not installed.\"\r\n        }\r\n        continue\r\n    }\r\n\r\n    if (get_config NO_JUNCTION) {\r\n        $version = Select-CurrentVersion -App $app -Global:$global\r\n    } else {\r\n        $version = 'current'\r\n    }\r\n    $dir = versiondir $app $version $global\r\n    $json = install_info $app $version $global\r\n    if (!$json) {\r\n        error \"Failed to hold '$app'.\"\r\n        continue\r\n    }\r\n    $install = @{}\r\n    $json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name)) }\r\n    if ($install.hold) {\r\n        info \"'$app' is already held.\"\r\n        continue\r\n    }\r\n    $install.hold = $true\r\n    save_install_info $install $dir\r\n    success \"$app is now held and can not be updated anymore.\"\r\n}\r\n\r\nexit $exitcode\r\n"
  },
  {
    "path": "libexec/scoop-home.ps1",
    "content": "# Usage: scoop home <app>\r\n# Summary: Opens the app homepage\r\nparam($app)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Get-Manifest'\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\" # 'Get-UserAgent'\r\n\r\nif ($app) {\r\n    $null, $manifest, $bucket, $null = Get-Manifest $app\r\n    if ($manifest) {\r\n        if ($manifest.homepage) {\r\n            Start-Process $manifest.homepage\r\n        } else {\r\n            abort \"Could not find homepage in manifest for '$app'.\"\r\n        }\r\n    } else {\r\n        abort \"Could not find manifest for '$app'.\"\r\n    }\r\n} else {\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-import.ps1",
    "content": "# Usage: scoop import <path/url to scoopfile.json>\r\n# Summary: Imports apps, buckets and configs from a Scoopfile in JSON format\r\n# Help: To replicate a Scoop installation from a file stored on Desktop, run\r\n#      scoop import Desktop\\scoopfile.json\r\n\r\nparam(\r\n    [Parameter(Mandatory)]\r\n    [String]\r\n    $scoopfile\r\n)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n\r\n$import = $null\r\n$bucket_names = @()\r\n$def_arch = Get-DefaultArchitecture\r\n\r\nif (Test-Path $scoopfile) {\r\n    $import = parse_json $scoopfile\r\n} elseif ($scoopfile -match '^(ht|f)tps?://|\\\\\\\\') {\r\n    $import = url_manifest $scoopfile\r\n}\r\n\r\nif (!$import) { abort 'Input file not a valid JSON.' }\r\n\r\nforeach ($item in $import.config.PSObject.Properties) {\r\n    set_config $item.Name $item.Value | Out-Null\r\n    Write-Host \"'$($item.Name)' has been set to '$($item.Value)'\"\r\n}\r\n\r\nforeach ($item in $import.buckets) {\r\n    add_bucket $item.Name $item.Source | Out-Null\r\n    $bucket_names += $item.Name\r\n}\r\n\r\nforeach ($item in $import.apps) {\r\n    $instArgs = @()\r\n    $holdArgs = @()\r\n    $info = $item.Info -Split ', '\r\n    if ('Global install' -in $info) {\r\n        $instArgs += '--global'\r\n        $holdArgs += '--global'\r\n    }\r\n    if ('64bit' -in $info -and '64bit' -ne $def_arch) {\r\n        $instArgs += '--arch', '64bit'\r\n    } elseif ('32bit' -in $info -and '32bit' -ne $def_arch) {\r\n        $instArgs += '--arch', '32bit'\r\n    } elseif ('arm64' -in $info -and 'arm64' -ne $def_arch) {\r\n        $instArgs += '--arch', 'arm64'\r\n    }\r\n\r\n    $app = if ($item.Source -in $bucket_names) {\r\n        \"$($item.Source)/$($item.Name)\"\r\n    } elseif ($item.Source -eq '<auto-generated>') {\r\n        \"$($item.Name)@$($item.Version)\"\r\n    } else {\r\n        $item.Source\r\n    }\r\n\r\n    & \"$PSScriptRoot\\scoop-install.ps1\" $app @instArgs\r\n\r\n    if ('Held package' -in $info) {\r\n        & \"$PSScriptRoot\\scoop-hold.ps1\" $item.Name @holdArgs\r\n    }\r\n}\r\n"
  },
  {
    "path": "libexec/scoop-info.ps1",
    "content": "# Usage: scoop info <app> [options]\r\n# Summary: Display information about an app\r\n# Help: Options:\r\n#   -v, --verbose   Show full paths and URLs\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Get-Manifest'\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Get-InstalledVersion', 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\" # 'Get-RemoteFileSize'\r\n\r\n$opt, $app, $err = getopt $args 'v' 'verbose'\r\n$original_app = $app\r\nif ($err) { error \"scoop info: $err\"; exit 1 }\r\n$verbose = $opt.v -or $opt.verbose\r\n\r\nif (!$app) { my_usage; exit 1 }\r\n\r\n$app, $manifest, $bucket, $url = Get-Manifest $app\r\n\r\nif (!$manifest) {\r\n    abort \"Could not find manifest for '$(show_app $app)' in local buckets.\"\r\n}\r\n\r\n$global = installed $app $true\r\n$status = app_status $app $global\r\n$install = install_info $app $status.version $global\r\n$status.installed = ($bucket -and $install.bucket -eq $bucket) -or (installed $app)\r\n$version_output = $manifest.version\r\n$manifest_file = if ($bucket) {\r\n    manifest_path $app $bucket\r\n} else {\r\n    $url\r\n}\r\n\r\n# Standalone and Source detection\r\nif ((Test-Path $original_app) -or ($original_app -match '^(ht|f)tps?://|\\\\\\\\')) {\r\n    $standalone = $true\r\n    if (Test-Path $original_app) {\r\n        $original_app = (Get-AbsolutePath \"$original_app\")\r\n    }\r\n    if ($install.url) {\r\n        if (Test-Path $install.url) {\r\n            $install_url = (Get-AbsolutePath $install.url)\r\n        } else {\r\n            $install_url = $install.url\r\n        }\r\n    }\r\n    if ($original_app -eq $install_url) {\r\n        $same_source = $true\r\n    }\r\n}\r\n\r\nif ($verbose) {\r\n    $dir = currentdir $app $global\r\n    $original_dir = versiondir $app $manifest.version $global\r\n    $persist_dir = persistdir $app $global\r\n} else {\r\n    $dir, $original_dir, $persist_dir = '<root>', '<root>', '<root>'\r\n}\r\n\r\nif ($status.installed) {\r\n    $manifest_file = manifest_path $app $install.bucket\r\n    if ($install.url) {\r\n        $manifest_file = $install.url\r\n    }\r\n    if ($status.deprecated) {\r\n        $manifest_file = $status.deprecated\r\n    } elseif ($standalone -and !$same_source) {\r\n        $version_output = $manifest.version\r\n    } elseif ($status.version -eq $manifest.version) {\r\n        $version_output = $status.version\r\n    } else {\r\n        $version_output = \"$($status.version) (Update to $($manifest.version) available)\"\r\n    }\r\n\r\n}\r\n\r\n$item = [ordered]@{ Name = $app }\r\nif ($status.deprecated) {\r\n    $item.Name += ' (DEPRECATED)'\r\n}\r\nif ($manifest.description) {\r\n    $item.Description = $manifest.description\r\n}\r\n$item.Version = $version_output\r\n\r\n$item.Source = if ($standalone) {\r\n    $original_app\r\n} else {\r\n    if ($install.bucket) {\r\n        $install.bucket\r\n    } elseif ($install.url) {\r\n        $install.url\r\n    } else {\r\n        $bucket\r\n    }\r\n}\r\n\r\nif ($manifest.homepage) {\r\n    $item.Website = $manifest.homepage.TrimEnd('/')\r\n}\r\n# Show license\r\nif ($manifest.license) {\r\n    $item.License = if ($manifest.license.identifier -and $manifest.license.url) {\r\n        if ($verbose) { \"$($manifest.license.identifier) ($($manifest.license.url))\" } else { $manifest.license.identifier }\r\n    } elseif ($manifest.license -match '^((ht)|f)tps?://') {\r\n        $manifest.license\r\n    } elseif ($manifest.license -match '[|,]') {\r\n        if ($verbose) {\r\n            \"$($manifest.license) ($(($manifest.license -Split '\\||,' | ForEach-Object { \"https://spdx.org/licenses/$_.html\" }) -join ', '))\"\r\n        } else {\r\n            $manifest.license\r\n        }\r\n    } else {\r\n        if ($verbose) { \"$($manifest.license) (https://spdx.org/licenses/$($manifest.license).html)\" } else { $manifest.license }\r\n    }\r\n}\r\n\r\nif ($manifest.depends) {\r\n    $item.Dependencies = $manifest.depends -join ' | '\r\n}\r\n\r\nif (Test-Path $manifest_file) {\r\n    if (Get-Command git -ErrorAction Ignore) {\r\n        $gitinfo = (Invoke-Git -Path (Split-Path $manifest_file) -ArgumentList @('log', '-1', '-s', '--format=%aD#%an', $manifest_file) 2> $null) -Split '#'\r\n    }\r\n    if ($gitinfo) {\r\n        $item.'Updated at' = $gitinfo[0] | Get-Date\r\n        $item.'Updated by' = $gitinfo[1]\r\n    } else {\r\n        $item.'Updated at' = (Get-Item $manifest_file).LastWriteTime\r\n        $item.'Updated by' = (Get-Acl $manifest_file).Owner.Split('\\')[-1]\r\n    }\r\n}\r\n\r\n# Manifest file\r\nif ($verbose) { $item.Manifest = $manifest_file }\r\n\r\nif ($status.installed) {\r\n    # Show installed versions\r\n    if (!$standalone -or $same_source) {\r\n        $installed_output = @()\r\n        Get-InstalledVersion -AppName $app -Global:$global | ForEach-Object {\r\n            $installed_output += if ($verbose) { versiondir $app $_ $global } else { \"$_$(if ($global) { ' *global*' })\" }\r\n        }\r\n        $item.Installed = $installed_output -join \"`n\"\r\n    }\r\n\r\n    if ($verbose) {\r\n        # Show size of installation\r\n        $appsdir = appsdir $global\r\n\r\n        # Collect file list from each location\r\n        $appFiles = Get-ChildItem $appsdir -Filter $app\r\n        $currentFiles = Get-ChildItem $appFiles.FullName -Filter (Select-CurrentVersion $app $global)\r\n        $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data\r\n        $cacheFiles = Get-ChildItem $cachedir -Filter \"$app#*\"\r\n\r\n        # Get the sum of each file list\r\n        $fileTotals = @()\r\n        foreach ($fileType in ($appFiles, $currentFiles, $persistFiles, $cacheFiles)) {\r\n            if ($null -ne $fileType) {\r\n                $fileSum = (Get-ChildItem $fileType.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum\r\n                $fileTotals += coalesce $fileSum 0\r\n            } else {\r\n                $fileTotals += 0\r\n            }\r\n        }\r\n\r\n        # Old versions = app total - current version size\r\n        $fileTotals += $fileTotals[0] - $fileTotals[1]\r\n\r\n        if ($fileTotals[2] + $fileTotals[3] + $fileTotals[4] -eq 0) {\r\n            # Simple app size output if no old versions, persisted data, cached downloads\r\n            $item.'Installed size' = filesize $fileTotals[1]\r\n        } else {\r\n            $fileSizes = [ordered] @{\r\n                'Current version:  ' = $fileTotals[1]\r\n                'Old versions:     ' = $fileTotals[4]\r\n                'Persisted data:   ' = $fileTotals[2]\r\n                'Cached downloads: ' = $fileTotals[3]\r\n                'Total:            ' = $fileTotals[0] + $fileTotals[2] + $fileTotals[3]\r\n            }\r\n\r\n            $fileSizeOutput = @()\r\n\r\n            # Don't output empty categories\r\n            $fileSizes.GetEnumerator() | ForEach-Object {\r\n                if ($_.Value -ne 0) {\r\n                    $fileSizeOutput += $_.Key + (filesize $_.Value)\r\n                }\r\n            }\r\n\r\n            $item.'Installed size' = $fileSizeOutput -join \"`n\"\r\n        }\r\n    }\r\n} else {\r\n    if ($verbose) {\r\n        # Get download size if app not installed\r\n        $totalPackage = 0\r\n        foreach ($url in @(url $manifest (Get-DefaultArchitecture))) {\r\n            try {\r\n                if (Test-Path (cache_path $app $manifest.version $url)) {\r\n                    $cached = ' (latest version is cached)'\r\n                } else {\r\n                    $cached = $null\r\n                }\r\n\r\n                $urlLength = Get-RemoteFileSize $url\r\n                $totalPackage += $urlLength\r\n            } catch [System.Management.Automation.RuntimeException] {\r\n                $totalPackage = 0\r\n                $packageError = \"the server at $(([System.Uri]$url).Host) did not send a Content-Length header\"\r\n                break\r\n            } catch {\r\n                $totalPackage = 0\r\n                $packageError = \"the server at $(([System.Uri]$url).Host) is down\"\r\n                break\r\n            }\r\n        }\r\n        if ($totalPackage -ne 0) {\r\n            $item.'Download size' = \"$(filesize $totalPackage)$cached\"\r\n        } else {\r\n            $item.'Download size' = \"Unknown ($packageError)$cached\"\r\n        }\r\n    }\r\n}\r\n\r\n$binaries = @(arch_specific 'bin' $manifest $install.architecture)\r\nif ($binaries) {\r\n    $binary_output = @()\r\n    $binaries | ForEach-Object {\r\n        if ($_ -is [System.Array]) {\r\n            $binary_output += \"$($_[1]).$($_[0].Split('.')[-1])\"\r\n        } else {\r\n            $binary_output += $_\r\n        }\r\n    }\r\n    $item.Binaries = $binary_output -join ' | '\r\n}\r\n$shortcuts = @(arch_specific 'shortcuts' $manifest $install.architecture)\r\nif ($shortcuts) {\r\n    $shortcut_output = @()\r\n    $shortcuts | ForEach-Object {\r\n        $shortcut_output += $_[1]\r\n    }\r\n    $item.Shortcuts = $shortcut_output -join ' | '\r\n}\r\n$env_set = arch_specific 'env_set' $manifest $install.architecture\r\nif ($env_set) {\r\n    $env_vars = @()\r\n    $env_set | Get-Member -member noteproperty | ForEach-Object {\r\n        $env_vars += \"$($_.name) = $(substitute $env_set.$($_.name) @{ '$dir' = $dir })\"\r\n    }\r\n    $item.Environment = $env_vars -join \"`n\"\r\n}\r\n$env_add_path = arch_specific 'env_add_path' $manifest $install.architecture\r\nif ($env_add_path) {\r\n    $env_path = @()\r\n    $env_add_path | Where-Object { $_ } | ForEach-Object {\r\n        $env_path += if ($_ -eq '.') {\r\n            $dir\r\n        } else {\r\n            \"$dir\\$_\"\r\n        }\r\n    }\r\n    $item.'Path Added' = $env_path -join \"`n\"\r\n}\r\n\r\nif ($manifest.suggest) {\r\n    $suggest_output = @()\r\n    $manifest.suggest.PSObject.Properties | ForEach-Object {\r\n        $suggest_output += $_.Value -join ' | '\r\n    }\r\n    $item.Suggestions = $suggest_output -join ' | '\r\n}\r\n\r\nif ($manifest.notes) {\r\n    # Show notes\r\n    $item.Notes = (substitute $manifest.notes @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir }) -join \"`n\"\r\n}\r\n\r\n[PSCustomObject]$item\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-install.ps1",
    "content": "# Usage: scoop install <app> [options]\r\n# Summary: Install apps\r\n# Help: e.g. The usual way to install an app (uses your local 'buckets'):\r\n#      scoop install git\r\n#\r\n# To install a different version of the app\r\n# (note that this will auto-generate the manifest using current version):\r\n#      scoop install gh@2.7.0\r\n#\r\n# To install an app from a manifest at a URL:\r\n#      scoop install https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/runat.json\r\n#\r\n# To install a different version of the app from a URL:\r\n#       scoop install https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/neovim.json@0.9.0\r\n#\r\n# To install an app from a manifest on your computer\r\n#      scoop install \\path\\to\\app.json\r\n#\r\n# To install an app from a manifest on your computer\r\n#      scoop install \\path\\to\\app.json@version\r\n#\r\n# Options:\r\n#   -g, --global                    Install the app globally\r\n#   -i, --independent               Don't install dependencies automatically\r\n#   -k, --no-cache                  Don't use the download cache\r\n#   -s, --skip-hash-check           Skip hash validation (use with caution!)\r\n#   -u, --no-update-scoop           Don't update Scoop before installing if it's outdated\r\n#   -a, --arch <32bit|64bit|arm64>  Use the specified architecture, if the app supports it\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'autoupdate.ps1' 'manifest.ps1' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\autoupdate.ps1\" # 'generate_user_manifest' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'generate_user_manifest' 'Get-Manifest' 'Select-CurrentVersion' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\system.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\decompress.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\shortcuts.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\psmodules.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\depends.ps1\"\r\nif (get_config USE_SQLITE_CACHE) {\r\n    . \"$PSScriptRoot\\..\\lib\\database.ps1\"\r\n}\r\n\r\n$opt, $apps, $err = getopt $args 'giksua:' 'global', 'independent', 'no-cache', 'skip-hash-check', 'no-update-scoop', 'arch='\r\nif ($err) { \"scoop install: $err\"; exit 1 }\r\n\r\n$global = $opt.g -or $opt.global\r\n$check_hash = !($opt.s -or $opt.'skip-hash-check')\r\n$independent = $opt.i -or $opt.independent\r\n$use_cache = !($opt.k -or $opt.'no-cache')\r\n$architecture = Get-DefaultArchitecture\r\ntry {\r\n    $architecture = Format-ArchitectureString ($opt.a + $opt.arch)\r\n} catch {\r\n    abort \"ERROR: $_\"\r\n}\r\n\r\nif (!$apps) { error '<app> missing'; my_usage; exit 1 }\r\n\r\nif ($global -and !(is_admin)) {\r\n    abort 'ERROR: you need admin rights to install global apps'\r\n}\r\n\r\nif (is_scoop_outdated) {\r\n    if ($opt.u -or $opt.'no-update-scoop') {\r\n        warn \"Scoop is out of date.\"\r\n    } else {\r\n        & \"$PSScriptRoot\\scoop-update.ps1\"\r\n    }\r\n}\r\n\r\nensure_none_failed $apps\r\n\r\nif ($apps.length -eq 1) {\r\n    $app, $null, $version = parse_app $apps\r\n    if ($app.EndsWith('.json')) {\r\n        $app = [System.IO.Path]::GetFileNameWithoutExtension($app)\r\n    }\r\n    $curVersion = Select-CurrentVersion -AppName $app -Global:$global\r\n    if ($null -eq $version -and $curVersion) {\r\n        warn \"'$app' ($curVersion) is already installed.`nUse 'scoop update $app$(if ($global) { ' --global' })' to install a new version.\"\r\n        exit 0\r\n    }\r\n}\r\n\r\n# get any specific versions that we need to handle first\r\n$specific_versions = $apps | Where-Object {\r\n    $null, $null, $version = parse_app $_\r\n    return $null -ne $version\r\n}\r\n\r\n# compare object does not like nulls\r\nif ($specific_versions.Count -gt 0) {\r\n    $difference = Compare-Object -ReferenceObject $apps -DifferenceObject $specific_versions -PassThru\r\n} else {\r\n    $difference = $apps\r\n}\r\n\r\n$specific_versions_paths = $specific_versions | ForEach-Object {\r\n    $app, $bucket, $version = parse_app $_\r\n    if (installed_manifest $app $version) {\r\n        warn \"'$app' ($version) is already installed.`nUse 'scoop update $app$(if ($global) { ' --global' })' to install a new version.\"\r\n        continue\r\n    }\r\n\r\n    generate_user_manifest $app $bucket $version\r\n}\r\n$apps = @((@($specific_versions_paths) + $difference) | Where-Object { $_ } | Select-Object -Unique)\r\n\r\n# remember which were explictly requested so that we can\r\n# differentiate after dependencies are added\r\n$explicit_apps = $apps\r\n\r\nif (!$independent) {\r\n    $apps = $apps | Get-Dependency -Architecture $architecture | Select-Object -Unique # adds dependencies\r\n}\r\nensure_none_failed $apps\r\n\r\n$apps, $skip = prune_installed $apps $global\r\n\r\n$skip | Where-Object { $explicit_apps -contains $_ } | ForEach-Object {\r\n    $app, $null, $null = parse_app $_\r\n    $version = Select-CurrentVersion -AppName $app -Global:$global\r\n    warn \"'$app' ($version) is already installed. Skipping.\"\r\n}\r\n\r\n$suggested = @{ };\r\nif ((Test-Aria2Enabled) -and (get_config 'aria2-warning-enabled' $true)) {\r\n    warn \"Scoop uses 'aria2c' for multi-connection downloads.\"\r\n    warn \"Should it cause issues, run 'scoop config aria2-enabled false' to disable it.\"\r\n    warn \"To disable this warning, run 'scoop config aria2-warning-enabled false'.\"\r\n}\r\n$apps | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache $check_hash }\r\n\r\nshow_suggestions $suggested\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-list.ps1",
    "content": "# Usage: scoop list [query]\r\n# Summary: List installed apps\r\n# Help: Lists all installed apps, or the apps matching the supplied query.\r\nparam($query)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'parse_json' 'Select-CurrentVersion' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\" # 'Get-UserAgent'\r\n\r\n$defaultArchitecture = Get-DefaultArchitecture\r\nif (-not (Get-FormatData ScoopApps)) {\r\n    Update-FormatData \"$PSScriptRoot\\..\\supporting\\formats\\ScoopTypes.Format.ps1xml\"\r\n}\r\n\r\n$local = installed_apps $false | ForEach-Object { @{ name = $_ } }\r\n$global = installed_apps $true | ForEach-Object { @{ name = $_; global = $true } }\r\n\r\n$apps = @($local) + @($global)\r\nif (-not $apps) {\r\n    Write-Host \"There aren't any apps installed.\"\r\n    exit 1\r\n}\r\n\r\n$list = @()\r\nWrite-Host \"Installed apps$(if($query) { `\" matching '$query'`\"}):\"\r\n$apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {\r\n    $app = $_.name\r\n    $global = $_.global\r\n    $item = @{}\r\n    $ver = Select-CurrentVersion -AppName $app -Global:$global\r\n    $item.Name = $app\r\n    $item.Version = $ver\r\n\r\n    $install_info_path = \"$(versiondir $app $ver $global)\\install.json\"\r\n    $updated = (Get-Item (appdir $app $global)).LastWriteTime\r\n    $install_info = $null\r\n    if (Test-Path $install_info_path) {\r\n        $install_info = parse_json $install_info_path\r\n        $updated = (Get-Item $install_info_path).LastWriteTime\r\n    }\r\n\r\n    $item.Source = if ($install_info.bucket) {\r\n        $install_info.bucket\r\n    } elseif ($install_info.url) {\r\n        if ($install_info.url -eq (usermanifest $app)) { '<auto-generated>' }\r\n        else { $install_info.url }\r\n    }\r\n    $item.Updated = $updated\r\n\r\n    $info = @()\r\n    if ((app_status $app $global).deprecated) { $info += 'Deprecated package'}\r\n    if ($global) { $info += 'Global install' }\r\n    if (failed $app $global) { $info += 'Install failed' }\r\n    if ($install_info.hold) { $info += 'Held package' }\r\n    if ($install_info.architecture -and $defaultArchitecture -ne $install_info.architecture) {\r\n        $info += $install_info.architecture\r\n    }\r\n    $item.Info = $info -join ', '\r\n\r\n    $list += [PSCustomObject]$item\r\n}\r\n\r\n$list | Add-Member -TypeName 'ScoopApps' -PassThru\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-prefix.ps1",
    "content": "# Usage: scoop prefix <app>\r\n# Summary: Returns the path to the specified app\r\nparam($app)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'currentdir' (indirectly)\r\n\r\nif (!$app) {\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\n$app_path = currentdir $app $false\r\nif (!(Test-Path $app_path)) {\r\n    $app_path = currentdir $app $true\r\n}\r\n\r\nif (Test-Path $app_path) {\r\n    Write-Output $app_path\r\n} else {\r\n    abort \"Could not find app path for '$app'.\"\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-reset.ps1",
    "content": "# Usage: scoop reset <app>\r\n# Summary: Reset an app to resolve conflicts\r\n# Help: Used to resolve conflicts in favor of a particular app. For example,\r\n# if you've installed 'python' and 'python27', you can use 'scoop reset' to switch between\r\n# using one or the other.\r\n#\r\n# You can use '*' in place of <app> or `-a`/`--all` switch to reset all apps.\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Select-CurrentVersion' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\system.ps1\" # 'env_add_path' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\shortcuts.ps1\"\r\n\r\n$opt, $apps, $err = getopt $args 'a' 'all'\r\nif($err) { \"scoop reset: $err\"; exit 1 }\r\n$all = $opt.a -or $opt.all\r\n\r\nif(!$apps -and !$all) { error '<app> missing'; my_usage; exit 1 }\r\n\r\nif($apps -eq '*' -or $all) {\r\n    $local = installed_apps $false | ForEach-Object { ,@($_, $false) }\r\n    $global = installed_apps $true | ForEach-Object { ,@($_, $true) }\r\n    $apps = @($local) + @($global)\r\n}\r\n\r\n$apps | ForEach-Object {\r\n    ($app, $global) = $_\r\n\r\n    $app, $bucket, $version = parse_app $app\r\n\r\n    if(($global -eq $null) -and (installed $app $true)) {\r\n        # set global flag when running reset command on specific app\r\n        $global = $true\r\n    }\r\n\r\n    if($app -eq 'scoop') {\r\n        # skip scoop\r\n        return\r\n    }\r\n\r\n    if(!(installed $app)) {\r\n        error \"'$app' isn't installed\"\r\n        return\r\n    }\r\n\r\n    if ($null -eq $version) {\r\n        $version = Select-CurrentVersion -AppName $app -Global:$global\r\n    }\r\n\r\n    $manifest = installed_manifest $app $version $global\r\n    # if this is null we know the version they're resetting to\r\n    # is not installed\r\n    if ($manifest -eq $null) {\r\n        error \"'$app ($version)' isn't installed\"\r\n        return\r\n    }\r\n\r\n    if($global -and !(is_admin)) {\r\n        warn \"'$app' ($version) is a global app. You need admin rights to reset it. Skipping.\"\r\n        return\r\n    }\r\n\r\n    write-host \"Resetting $app ($version).\"\r\n\r\n    $dir = Convert-Path (versiondir $app $version $global)\r\n    $original_dir = $dir\r\n    $persist_dir = persistdir $app $global\r\n\r\n    #region Workaround for #2952\r\n    if (test_running_process $app $global) {\r\n        return\r\n    }\r\n    #endregion Workaround for #2952\r\n\r\n    $install = install_info $app $version $global\r\n    $architecture = $install.architecture\r\n\r\n    $dir = link_current $dir\r\n    create_shims $manifest $dir $global $architecture\r\n    create_startmenu_shortcuts $manifest $dir $global $architecture\r\n    # unset all potential old env before re-adding\r\n    env_rm_path $manifest $dir $global $architecture\r\n    env_rm $manifest $global $architecture\r\n    env_add_path $manifest $dir $global $architecture\r\n    env_set $manifest $global $architecture\r\n    # unlink all potential old link before re-persisting\r\n    unlink_persist_data $manifest $original_dir\r\n    persist_data $manifest $original_dir $persist_dir\r\n    persist_permission $manifest $global\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-search.ps1",
    "content": "# Usage: scoop search <query>\r\n# Summary: Search available apps\r\n# Help: Searches for apps that are available to install.\r\n#\r\n# If used with [query], shows app names that match the query.\r\n#   - With 'use_sqlite_cache' enabled, [query] is partially matched against app names, binaries, and shortcuts.\r\n#   - Without 'use_sqlite_cache', [query] can be a regular expression to match against app names and binaries.\r\n# Without [query], shows all the available apps.\r\nparam($query)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'manifest'\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Get-LatestVersion'\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\n\r\n$list = [System.Collections.Generic.List[PSCustomObject]]::new()\r\n\r\nfunction bin_match($manifest, $query) {\r\n    if (!$manifest.bin) { return $false }\r\n    $bins = foreach ($bin in $manifest.bin) {\r\n        $exe, $alias, $args = $bin\r\n        $fname = Split-Path $exe -Leaf -ErrorAction Stop\r\n\r\n        if ((strip_ext $fname) -match $query) { $fname }\r\n        elseif ($alias -match $query) { $alias }\r\n    }\r\n\r\n    if ($bins) { return $bins }\r\n    else { return $false }\r\n}\r\n\r\nfunction bin_match_json($json, $query) {\r\n    [System.Text.Json.JsonElement]$bin = [System.Text.Json.JsonElement]::new()\r\n    if (!$json.RootElement.TryGetProperty('bin', [ref] $bin)) { return $false }\r\n    $bins = @()\r\n    if ($bin.ValueKind -eq [System.Text.Json.JsonValueKind]::String -and [System.IO.Path]::GetFileNameWithoutExtension($bin) -match $query) {\r\n        $bins += [System.IO.Path]::GetFileName($bin)\r\n    } elseif ($bin.ValueKind -eq [System.Text.Json.JsonValueKind]::Array) {\r\n        foreach ($subbin in $bin.EnumerateArray()) {\r\n            if ($subbin.ValueKind -eq [System.Text.Json.JsonValueKind]::String -and [System.IO.Path]::GetFileNameWithoutExtension($subbin) -match $query) {\r\n                $bins += [System.IO.Path]::GetFileName($subbin)\r\n            } elseif ($subbin.ValueKind -eq [System.Text.Json.JsonValueKind]::Array) {\r\n                if ([System.IO.Path]::GetFileNameWithoutExtension($subbin[0]) -match $query) {\r\n                    $bins += [System.IO.Path]::GetFileName($subbin[0])\r\n                } elseif ($subbin.GetArrayLength() -ge 2 -and $subbin[1] -match $query) {\r\n                    $bins += $subbin[1]\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    if ($bins) { return $bins }\r\n    else { return $false }\r\n}\r\n\r\nfunction search_bucket($bucket, $query) {\r\n    $apps = Get-ChildItem (Find-BucketDirectory $bucket) -Filter '*.json' -Recurse\r\n\r\n    $apps | ForEach-Object {\r\n        $filepath = $_.FullName\r\n\r\n        $json = try {\r\n            [System.Text.Json.JsonDocument]::Parse([System.IO.File]::ReadAllText($filepath))\r\n        } catch {\r\n            debug \"Failed to parse manifest file: $filepath (error: $_)\"\r\n            return\r\n        }\r\n\r\n        $name = $_.BaseName\r\n\r\n        if ($name -match $query) {\r\n            $list.Add([PSCustomObject]@{\r\n                    Name     = $name\r\n                    Version  = $json.RootElement.GetProperty('version')\r\n                    Source   = $bucket\r\n                    Binaries = ''\r\n                })\r\n        } else {\r\n            $bin = bin_match_json $json $query\r\n            if ($bin) {\r\n                $list.Add([PSCustomObject]@{\r\n                        Name     = $name\r\n                        Version  = $json.RootElement.GetProperty('version')\r\n                        Source   = $bucket\r\n                        Binaries = $bin -join ' | '\r\n                    })\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n# fallback function for PowerShell 5\r\nfunction search_bucket_legacy($bucket, $query) {\r\n    $apps = Get-ChildItem (Find-BucketDirectory $bucket) -Filter '*.json' -Recurse\r\n\r\n    $apps | ForEach-Object {\r\n        $manifest = [System.IO.File]::ReadAllText($_.FullName) | ConvertFrom-Json -ErrorAction Continue\r\n        $name = $_.BaseName\r\n\r\n        if ($name -match $query) {\r\n            $list.Add([PSCustomObject]@{\r\n                    Name     = $name\r\n                    Version  = $manifest.Version\r\n                    Source   = $bucket\r\n                    Binaries = ''\r\n                })\r\n        } else {\r\n            $bin = bin_match $manifest $query\r\n            if ($bin) {\r\n                $list.Add([PSCustomObject]@{\r\n                        Name     = $name\r\n                        Version  = $manifest.Version\r\n                        Source   = $bucket\r\n                        Binaries = $bin -join ' | '\r\n                    })\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nfunction search_remote($bucket, $query) {\r\n    $uri = [System.Uri](known_bucket_repo $bucket)\r\n    if ($uri.AbsolutePath -match '/([a-zA-Z0-9]*)/([a-zA-Z0-9-]*)(?:.git|/)?') {\r\n        $user = $Matches[1]\r\n        $repo_name = $Matches[2]\r\n        $api_link = \"https://api.github.com/repos/$user/$repo_name/git/trees/HEAD?recursive=1\"\r\n        $result = download_json $api_link | Select-Object -ExpandProperty tree |\r\n            Where-Object -Value \"^bucket/(.*$query.*)\\.json$\" -Property Path -Match |\r\n            ForEach-Object { $Matches[1] }\r\n    }\r\n\r\n    $result\r\n}\r\n\r\nfunction search_remotes($query) {\r\n    $buckets = known_bucket_repos\r\n    $names = $buckets | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name\r\n\r\n    $results = $names | Where-Object { !(Test-Path $(Find-BucketDirectory $_)) } | ForEach-Object {\r\n        @{ 'bucket' = $_; 'results' = (search_remote $_ $query) }\r\n    } | Where-Object { $_.results }\r\n\r\n    if ($results.count -gt 0) {\r\n        Write-Host \"Results from other known buckets...\r\n(add them using 'scoop bucket add <bucket name>')\"\r\n    }\r\n\r\n    $remote_list = @()\r\n    $results | ForEach-Object {\r\n        $bucket = $_.bucket\r\n        $_.results | ForEach-Object {\r\n            $item = [ordered]@{}\r\n            $item.Name = $_\r\n            $item.Source = $bucket\r\n            $remote_list += [PSCustomObject]$item\r\n        }\r\n    }\r\n    $remote_list\r\n}\r\n\r\nif (get_config USE_SQLITE_CACHE) {\r\n    . \"$PSScriptRoot\\..\\lib\\database.ps1\"\r\n    Select-ScoopDBItem $query -From @('name', 'binary', 'shortcut') |\r\n        Select-Object -Property name, version, bucket, binary |\r\n        ForEach-Object {\r\n            $list.Add([PSCustomObject]@{\r\n                    Name     = $_.name\r\n                    Version  = $_.version\r\n                    Source   = $_.bucket\r\n                    Binaries = $_.binary\r\n                })\r\n        }\r\n} else {\r\n    try {\r\n        $query = New-Object Regex $query, 'IgnoreCase'\r\n    } catch {\r\n        abort \"Invalid regular expression: $($_.Exception.InnerException.Message)\"\r\n    }\r\n\r\n    $jsonTextAvailable = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { [System.IO.Path]::GetFileNameWithoutExtension($_.Location) -eq 'System.Text.Json' }\r\n\r\n    Get-LocalBucket | ForEach-Object {\r\n        if ($jsonTextAvailable) {\r\n            search_bucket $_ $query\r\n        } else {\r\n            search_bucket_legacy $_ $query\r\n        }\r\n    }\r\n}\r\n\r\nif ($list.Count -gt 0) {\r\n    Write-Host 'Results from local buckets...'\r\n    $list\r\n}\r\n\r\nif ($list.Count -eq 0 -and !(github_ratelimit_reached)) {\r\n    $remote_results = search_remotes $query\r\n    if (!$remote_results) {\r\n        warn 'No matches found.'\r\n        exit 1\r\n    }\r\n    $remote_results\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-shim.ps1",
    "content": "# Usage: scoop shim <subcommand> [<shim_name>...] [options] [other_args]\r\n# Summary: Manipulate Scoop shims\r\n# Help: Available subcommands: add, rm, list, info, alter.\r\n#\r\n# To add a custom shim, use the 'add' subcommand:\r\n#\r\n#     scoop shim add <shim_name> <command_path> [<args>...]\r\n#\r\n# To remove shims, use the 'rm' subcommand: (CAUTION: this could remove shims added by an app manifest)\r\n#\r\n#     scoop shim rm <shim_name> [<shim_name>...]\r\n#\r\n# To list all shims or matching shims, use the 'list' subcommand:\r\n#\r\n#     scoop shim list [<regex_pattern>...]\r\n#\r\n# To show a shim's information, use the 'info' subcommand:\r\n#\r\n#     scoop shim info <shim_name>\r\n#\r\n# To alternate a shim's target source, use the 'alter' subcommand:\r\n#\r\n#     scoop shim alter <shim_name>\r\n#\r\n# Options:\r\n#   -g, --global       Manipulate global shim(s)\r\n#\r\n# HINT: The FIRST double-hyphen '--', if any, will be treated as the POSIX-style command option terminator\r\n# and will NOT be included in arguments, so if you want to pass arguments like '-g' or '--global' to\r\n# the shim, put them after a '--'. Note that in PowerShell, you must use a QUOTED '--', e.g.,\r\n#\r\n#     scoop shim add myapp 'D:\\path\\myapp.exe' '--' myapp_args --global\r\n\r\nparam($SubCommand)\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\install.ps1\" # for rm_shim\r\n. \"$PSScriptRoot\\..\\lib\\system.ps1\" # 'Add-Path' (indirectly)\r\n\r\nif ($SubCommand -notin @('add', 'rm', 'list', 'info', 'alter')) {\r\n    if (!$SubCommand) {\r\n        error '<subcommand> missing'\r\n    } else {\r\n        error \"'$SubCommand' is not one of available subcommands: add, rm, list, info, alter\"\r\n    }\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\n$opt, $other, $err = getopt $Args 'g' 'global'\r\nif ($err) { \"scoop shim: $err\"; exit 1 }\r\n\r\n$global = $opt.g -or $opt.global\r\n\r\nif ($SubCommand -ne 'list' -and $other.Length -eq 0) {\r\n    error \"<shim_name> must be specified for subcommand '$SubCommand'\"\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\nif (-not (Get-FormatData ScoopShims)) {\r\n    Update-FormatData \"$PSScriptRoot\\..\\supporting\\formats\\ScoopTypes.Format.ps1xml\"\r\n}\r\n\r\n$localShimDir = shimdir $false\r\n$globalShimDir = shimdir $true\r\n\r\nfunction Get-ShimInfo($ShimPath) {\r\n    $info = [Ordered]@{}\r\n    $info.Name = strip_ext (fname $ShimPath)\r\n    $info.Path = $ShimPath -replace 'shim$', 'exe'\r\n    $info.Source = (get_app_name_from_shim $ShimPath) -replace '^$', 'External'\r\n    $info.Type = if ($ShimPath.EndsWith('.ps1')) { 'ExternalScript' } else { 'Application' }\r\n    $altShims = Get-Item -Path \"$ShimPath.*\" -Exclude '*.shim', '*.cmd', '*.ps1'\r\n    if ($altShims) {\r\n        $info.Alternatives = (@($info.Source) + ($altShims | ForEach-Object { $_.Extension.Remove(0, 1) } | Select-Object -Unique)) -join ' '\r\n    }\r\n    $info.IsGlobal = $ShimPath.StartsWith(\"$globalShimDir\")\r\n    $info.IsHidden = !((Get-Command -Name $info.Name).Path -eq $info.Path)\r\n    [PSCustomObject]$info\r\n}\r\n\r\nfunction Get-ShimPath($ShimName, $Global) {\r\n    '.shim', '.ps1' | ForEach-Object {\r\n        $shimPath = Join-Path (shimdir $Global) \"$ShimName$_\"\r\n        if (Test-Path -LiteralPath $shimPath) {\r\n            return $shimPath\r\n        }\r\n    }\r\n}\r\n\r\nswitch ($SubCommand) {\r\n    'add' {\r\n        if ($other.Length -lt 2 -or $other[1] -eq '') {\r\n            error \"<command_path> must be specified for subcommand 'add'\"\r\n            my_usage\r\n            exit 1\r\n        }\r\n        $shimName = $other[0]\r\n        $commandPath = $other[1]\r\n        if ($other.Length -gt 2) {\r\n            $commandArgs = $other[2..($other.Length - 1)]\r\n        }\r\n        if ($commandPath -notmatch '[\\\\/]') {\r\n            $shortPath = $commandPath\r\n            $commandPath = Get-ShimTarget (Get-ShimPath $shortPath $global)\r\n            if (!$commandPath) {\r\n                $exCommand = Get-Command $shortPath -ErrorAction SilentlyContinue\r\n                if ($exCommand -and $exCommand.CommandType -eq 'Application') {\r\n                    $commandPath = $exCommand.Path\r\n                } # TODO - add support for more command types: Alias, Cmdlet, ExternalScript, Filter, Function, Script, and Workflow\r\n            }\r\n        }\r\n        if ($commandPath -and (Test-Path $commandPath)) {\r\n            Write-Host \"Adding $(if ($global) { 'global' } else { 'local' }) shim \" -NoNewline\r\n            Write-Host $shimName -ForegroundColor Cyan -NoNewline\r\n            Write-Host '...'\r\n            shim $commandPath $global $shimName $commandArgs\r\n        } else {\r\n            Write-Host \"ERROR: Command path does not exist: \" -ForegroundColor Red -NoNewline\r\n            Write-Host $($other[1]) -ForegroundColor Cyan\r\n            exit 3\r\n        }\r\n    }\r\n    'rm' {\r\n        $failed = @()\r\n        $other | ForEach-Object {\r\n            if (Get-ShimPath $_ $global) {\r\n                rm_shim $_ (shimdir $global)\r\n            } else {\r\n                $failed += $_\r\n            }\r\n        }\r\n        if ($failed) {\r\n            $failed | ForEach-Object {\r\n                Write-Host \"ERROR: $(if ($global) { 'Global' } else {'Local' }) shim not found: \" -ForegroundColor Red -NoNewline\r\n                Write-Host $_ -ForegroundColor Cyan\r\n            }\r\n            exit 3\r\n        }\r\n    }\r\n    'list' {\r\n        $other = @($other) -ne '*'\r\n        # Validate all given patterns before matching.\r\n        $other | ForEach-Object {\r\n            try {\r\n                $pattern = $_\r\n                [void][Regex]::New($pattern)\r\n            } catch {\r\n                Write-Host \"ERROR: Invalid pattern: \" -ForegroundColor Red -NoNewline\r\n                Write-Host $pattern -ForegroundColor Magenta\r\n                exit 1\r\n            }\r\n        }\r\n        $pattern = $other -join '|'\r\n        $shims = @()\r\n        if (!$global) {\r\n            $shims += Get-ChildItem -Path $localShimDir -Recurse -Include '*.shim', '*.ps1' |\r\n                Where-Object { !$pattern -or ($_.BaseName -match $pattern) } |\r\n                Select-Object -ExpandProperty FullName\r\n        }\r\n        if (Test-Path $globalShimDir) {\r\n            $shims += Get-ChildItem -Path $globalShimDir -Recurse -Include '*.shim', '*.ps1' |\r\n                Where-Object { !$pattern -or ($_.BaseName -match $pattern) } |\r\n                Select-Object -ExpandProperty FullName\r\n        }\r\n        $shims.ForEach({ Get-ShimInfo $_ }) | Add-Member -TypeName 'ScoopShims' -PassThru\r\n    }\r\n    'info' {\r\n        $shimName = $other[0]\r\n        $shimPath = Get-ShimPath $shimName $global\r\n        if ($shimPath) {\r\n            Get-ShimInfo $shimPath\r\n        } else {\r\n            Write-Host \"ERROR: $(if ($global) { 'Global' } else { 'Local' }) shim not found: \" -ForegroundColor Red -NoNewline\r\n            Write-Host $shimName -ForegroundColor Cyan\r\n            if (Get-ShimPath $shimName (!$global)) {\r\n                Write-Host \"But a $(if ($global) { 'local' } else {'global' }) shim exists, \" -NoNewline\r\n                Write-Host \"run 'scoop shim info $shimName$(if (!$global) { ' --global' })' to show its info\"\r\n                exit 2\r\n            }\r\n            exit 3\r\n        }\r\n    }\r\n    'alter' {\r\n        $shimName = $other[0]\r\n        $shimPath = Get-ShimPath $shimName $global\r\n        if ($shimPath) {\r\n            $shimInfo = Get-ShimInfo $shimPath\r\n            if ($null -eq $shimInfo.Alternatives) {\r\n                Write-Host 'ERROR: No alternatives of ' -ForegroundColor Red -NoNewline\r\n                Write-Host $shimName -ForegroundColor Cyan -NoNewline\r\n                Write-Host ' found.' -ForegroundColor Red\r\n                exit 2\r\n            }\r\n            $shimInfo.Alternatives = $shimInfo.Alternatives.Split(' ')\r\n            [System.Management.Automation.Host.ChoiceDescription[]]$altApps = 1..$shimInfo.Alternatives.Length | ForEach-Object {\r\n                New-Object System.Management.Automation.Host.ChoiceDescription \"&$($_)`b$($shimInfo.Alternatives[$_ - 1])\", \"Sets '$shimName' shim from $($shimInfo.Alternatives[$_ - 1]).\"\r\n            }\r\n            $selected = $Host.UI.PromptForChoice(\"Alternatives of '$shimName' command\", \"Please choose one that provides '$shimName' as default:\", $altApps, 0)\r\n            if ($selected -eq 0) {\r\n                Write-Host 'INFO: ' -ForegroundColor Blue -NoNewline\r\n                Write-Host $shimName -ForegroundColor Cyan -NoNewline\r\n                Write-Host ' is already from ' -NoNewline\r\n                Write-Host $shimInfo.Source -ForegroundColor DarkYellow -NoNewline\r\n                Write-Host ', nothing changed.'\r\n            } else {\r\n                $newApp = $shimInfo.Alternatives[$selected]\r\n                Write-Host 'Use ' -NoNewline\r\n                Write-Host $shimName -ForegroundColor Cyan -NoNewline\r\n                Write-Host ' from ' -NoNewline\r\n                Write-Host $newApp -ForegroundColor DarkYellow -NoNewline\r\n                Write-Host ' as default...' -NoNewline\r\n                $pathNoExt = strip_ext $shimPath\r\n                '', '.shim', '.cmd', '.ps1' | ForEach-Object {\r\n                    $oldShimPath = \"$pathNoExt$_\"\r\n                    $newShimPath = \"$oldShimPath.$newApp\"\r\n                    if (Test-Path -Path $oldShimPath -PathType Leaf) {\r\n                        Rename-Item -Path $oldShimPath -NewName \"$oldShimPath.$($shimInfo.Source)\" -Force\r\n                        if (Test-Path -Path $newShimPath -PathType Leaf) {\r\n                            Rename-Item -Path $newShimPath -NewName $oldShimPath -Force\r\n                        }\r\n                    }\r\n                }\r\n                Write-Host 'done.'\r\n            }\r\n        } else {\r\n            Write-Host \"ERROR: $(if ($global) { 'Global' } else { 'Local' }) shim not found: \" -ForegroundColor Red -NoNewline\r\n            Write-Host $shimName -ForegroundColor Cyan\r\n            if (Get-ShimPath $shimName (!$global)) {\r\n                Write-Host \"But a $(if ($global) { 'local' } else {'global' }) shim exists, \" -NoNewline\r\n                Write-Host \"run 'scoop shim alter $shimName$(if (!$global) { ' --global' })' to alternate its source\"\r\n                exit 2\r\n            }\r\n            exit 3\r\n        }\r\n    }\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-status.ps1",
    "content": "# Usage: scoop status\r\n# Summary: Show status and check for new app versions\r\n# Help: Options:\r\n#   -l, --local         Checks the status for only the locally installed apps,\r\n#                       and disables remote fetching/checking for Scoop and buckets\r\n\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'manifest' 'parse_json' \"install_info\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\" # 'Get-UserAgent'\r\n\r\n# check if scoop needs updating\r\n$currentdir = versiondir 'scoop' 'current'\r\n$needs_update = $false\r\n$bucket_needs_update = $false\r\n$script:network_failure = $false\r\n$no_remotes = $args[0] -eq '-l' -or $args[0] -eq '--local'\r\nif (!(Get-Command git -ErrorAction SilentlyContinue)) { $no_remotes = $true }\r\n$list = @()\r\nif (!(Get-FormatData ScoopStatus)) {\r\n    Update-FormatData \"$PSScriptRoot\\..\\supporting\\formats\\ScoopTypes.Format.ps1xml\"\r\n}\r\n\r\nfunction Test-UpdateStatus($repopath) {\r\n    if (Test-Path \"$repopath\\.git\") {\r\n        Invoke-Git -Path $repopath -ArgumentList @('fetch', '-q', 'origin')\r\n        $script:network_failure = 128 -eq $LASTEXITCODE\r\n        $branch  = Invoke-Git -Path $repopath -ArgumentList @('branch', '--show-current')\r\n        $commits = Invoke-Git -Path $repopath -ArgumentList @('log', \"HEAD..origin/$branch\", '--oneline')\r\n        if ($commits) { return $true }\r\n        else { return $false }\r\n    } else {\r\n        return $true\r\n    }\r\n}\r\n\r\nif (!$no_remotes) {\r\n    $needs_update = Test-UpdateStatus $currentdir\r\n    foreach ($bucket in Get-LocalBucket) {\r\n        if (Test-UpdateStatus (Find-BucketDirectory $bucket -Root)) {\r\n            $bucket_needs_update = $true\r\n            break\r\n        }\r\n    }\r\n}\r\n\r\nif ($needs_update) {\r\n    warn \"Scoop out of date. Run 'scoop update' to get the latest changes.\"\r\n} elseif ($bucket_needs_update) {\r\n    warn \"Scoop bucket(s) out of date. Run 'scoop update' to get the latest changes.\"\r\n} elseif (!$script:network_failure -and !$no_remotes) {\r\n    success 'Scoop is up to date.'\r\n}\r\n\r\n$true, $false | ForEach-Object { # local and global apps\r\n    $global = $_\r\n    $dir = appsdir $global\r\n    if (!(Test-Path $dir)) { return }\r\n\r\n    Get-ChildItem $dir | Where-Object name -NE 'scoop' | ForEach-Object {\r\n        $app = $_.name\r\n        $status = app_status $app $global\r\n        if (!$status.outdated -and !$status.failed -and !$status.deprecated -and !$status.removed -and !$status.missing_deps) { return }\r\n\r\n        $item = [ordered]@{}\r\n        $item.Name = $app\r\n        $item.'Installed Version' = $status.version\r\n        $item.'Latest Version' = if ($status.outdated) { $status.latest_version } else { \"\" }\r\n        $item.'Missing Dependencies' = $status.missing_deps -Split ' ' -Join ' | '\r\n        $info = @()\r\n        if ($status.failed)     { $info += 'Install failed' }\r\n        if ($status.hold)       { $info += 'Held package' }\r\n        if ($status.deprecated) { $info += 'Deprecated' }\r\n        if ($status.removed)    { $info += 'Manifest removed' }\r\n        $item.Info = $info -join ', '\r\n        $list += [PSCustomObject]$item\r\n    }\r\n}\r\n\r\nif ($list.Length -eq 0 -and !$needs_update -and !$bucket_needs_update -and !$script:network_failure) {\r\n    success 'Everything is ok!'\r\n}\r\n\r\n$list | Add-Member -TypeName ScoopStatus -PassThru\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-unhold.ps1",
    "content": "# Usage: scoop unhold <app>\r\n# Summary: Unhold an app to enable updates\r\n# Help: To unhold a user-scoped app:\r\n#      scoop unhold <app>\r\n#\r\n# To unhold a global app:\r\n#      scoop unhold -g <app>\r\n#\r\n# Options:\r\n#   -g, --global  Unhold globally installed apps\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'save_install_info' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'install_info' 'Select-CurrentVersion' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n\r\n$opt, $apps, $err = getopt $args 'g' 'global'\r\nif ($err) { \"scoop unhold: $err\"; exit 1 }\r\n\r\n$global = $opt.g -or $opt.global\r\n\r\nif (!$apps) {\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\nif ($global -and !(is_admin)) {\r\n    error 'You need admin rights to unhold a global app.'\r\n    exit 1\r\n}\r\n\r\n$apps | ForEach-Object {\r\n    $app = $_\r\n\r\n    if ($app -eq 'scoop') {\r\n        set_config HOLD_UPDATE_UNTIL $null | Out-Null\r\n        success \"$app is no longer held and can be updated again.\"\r\n        return\r\n    }\r\n    if (!(installed $app $global)) {\r\n        if ($global) {\r\n            error \"'$app' is not installed globally.\"\r\n        } else {\r\n            error \"'$app' is not installed.\"\r\n        }\r\n        return\r\n    }\r\n\r\n    if (get_config NO_JUNCTION){\r\n        $version = Select-CurrentVersion -App $app -Global:$global\r\n    } else {\r\n        $version = 'current'\r\n    }\r\n    $dir = versiondir $app $version $global\r\n    $json = install_info $app $version $global\r\n    if (!$json) {\r\n        error \"Failed to unhold '$app'\"\r\n        continue\r\n    }\r\n    $install = @{}\r\n    $json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name)) }\r\n    if (!$install.hold) {\r\n        info \"'$app' is not held.\"\r\n        continue\r\n    }\r\n    $install.hold = $null\r\n    save_install_info $install $dir\r\n    success \"$app is no longer held and can be updated again.\"\r\n}\r\n\r\nexit $exitcode\r\n"
  },
  {
    "path": "libexec/scoop-uninstall.ps1",
    "content": "# Usage: scoop uninstall <app> [options]\r\n# Summary: Uninstall an app\r\n# Help: e.g. scoop uninstall git\r\n#\r\n# Options:\r\n#   -g, --global   Uninstall a globally installed app\r\n#   -p, --purge    Remove all persistent data\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Get-Manifest' 'Select-CurrentVersion' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\system.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\shortcuts.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\psmodules.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n\r\n# options\r\n$opt, $apps, $err = getopt $args 'gp' 'global', 'purge'\r\n\r\nif ($err) {\r\n    error \"scoop uninstall: $err\"\r\n    exit 1\r\n}\r\n\r\n$global = $opt.g -or $opt.global\r\n$purge = $opt.p -or $opt.purge\r\n\r\nif (!$apps) {\r\n    error '<app> missing'\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\nif ($global -and !(is_admin)) {\r\n    error 'You need admin rights to uninstall global apps.'\r\n    exit 1\r\n}\r\n\r\nif ($apps -eq 'scoop') {\r\n    & \"$PSScriptRoot\\..\\bin\\uninstall.ps1\" $global $purge\r\n    exit\r\n}\r\n\r\n$apps = Confirm-InstallationStatus $apps -Global:$global\r\nif (!$apps) { exit 0 }\r\n\r\n:app_loop foreach ($_ in $apps) {\r\n    ($app, $global) = $_\r\n\r\n    $version = Select-CurrentVersion -AppName $app -Global:$global\r\n    $appDir = appdir $app $global\r\n    if ($version) {\r\n        Write-Host \"Uninstalling '$app' ($version).\"\r\n\r\n        $dir = versiondir $app $version $global\r\n        $persist_dir = persistdir $app $global\r\n\r\n        $manifest = installed_manifest $app $version $global\r\n        $install = install_info $app $version $global\r\n        $architecture = $install.architecture\r\n\r\n        Invoke-HookScript -HookType 'pre_uninstall' -Manifest $manifest -Arch $architecture\r\n\r\n        #region Workaround for #2952\r\n        if (test_running_process $app $global) {\r\n            continue\r\n        }\r\n        #endregion Workaround for #2952\r\n\r\n        try {\r\n            Test-Path $dir -ErrorAction Stop | Out-Null\r\n        } catch [UnauthorizedAccessException] {\r\n            error \"Access denied: $dir. You might need to restart.\"\r\n            continue\r\n        }\r\n\r\n        Invoke-Installer -Path $dir -Manifest $manifest -ProcessorArchitecture $architecture -Global $global -Uninstall\r\n        rm_shims $app $manifest $global $architecture\r\n        rm_startmenu_shortcuts $manifest $global $architecture\r\n\r\n        # If a junction was used during install, that will have been used\r\n        # as the reference directory. Otherwise it will just be the version\r\n        # directory.\r\n        $refdir = unlink_current $dir\r\n\r\n        uninstall_psmodule $manifest $refdir $global\r\n\r\n        env_rm_path $manifest $refdir $global $architecture\r\n        env_rm $manifest $global $architecture\r\n\r\n        try {\r\n            # unlink all potential old link before doing recursive Remove-Item\r\n            unlink_persist_data $manifest $dir\r\n            Remove-Item $dir -Recurse -Force -ErrorAction Stop\r\n        } catch {\r\n            if (Test-Path $dir) {\r\n                error \"Couldn't remove '$(friendly_path $dir)'; it may be in use.\"\r\n                continue\r\n            }\r\n        }\r\n\r\n        Invoke-HookScript -HookType 'post_uninstall' -Manifest $manifest -Arch $architecture\r\n    }\r\n    # remove older versions\r\n    $oldVersions = @(Get-ChildItem $appDir -Name -Exclude 'current')\r\n    foreach ($version in $oldVersions) {\r\n        Write-Host \"Removing older version ($version).\"\r\n        $dir = versiondir $app $version $global\r\n        try {\r\n            # unlink all potential old link before doing recursive Remove-Item\r\n            unlink_persist_data $manifest $dir\r\n            Remove-Item $dir -Recurse -Force -ErrorAction Stop\r\n        } catch {\r\n            error \"Couldn't remove '$(friendly_path $dir)'; it may be in use.\"\r\n            continue app_loop\r\n        }\r\n    }\r\n    if (Test-Path ($currentDir = Join-Path $appDir 'current')) {\r\n        attrib $currentDir -R /L\r\n        Remove-Item $currentDir -ErrorAction Stop -Force\r\n    }\r\n    if (!(Get-ChildItem $appDir)) {\r\n        try {\r\n            # if last install failed, the directory seems to be locked and this\r\n            # will throw an error about the directory not existing\r\n            Remove-Item $appdir -Recurse -Force -ErrorAction Stop\r\n        } catch {\r\n            if ((Test-Path $appdir)) { throw } # only throw if the dir still exists\r\n        }\r\n    }\r\n\r\n    # purge persistant data\r\n    if ($purge) {\r\n        Write-Host 'Removing persisted data.'\r\n        $persist_dir = persistdir $app $global\r\n\r\n        if (Test-Path $persist_dir) {\r\n            try {\r\n                Remove-Item $persist_dir -Recurse -Force -ErrorAction Stop\r\n            } catch {\r\n                error \"Couldn't remove '$(friendly_path $persist_dir)'; it may be in use.\"\r\n                continue\r\n            }\r\n        }\r\n    }\r\n\r\n    success \"'$app' was uninstalled.\"\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-update.ps1",
    "content": "# Usage: scoop update <app> [options]\r\n# Summary: Update apps, or Scoop itself\r\n# Help: 'scoop update' updates Scoop to the latest version.\r\n# 'scoop update <app>' installs a new version of that app, if there is one.\r\n#\r\n# You can use '*' in place of <app> to update all apps.\r\n#\r\n# Options:\r\n#   -f, --force            Force update even when there isn't a newer version\r\n#   -g, --global           Update a globally installed app\r\n#   -i, --independent      Don't install dependencies automatically\r\n#   -k, --no-cache         Don't use the download cache\r\n#   -s, --skip-hash-check  Skip hash validation (use with caution!)\r\n#   -q, --quiet            Hide extraneous messages\r\n#   -a, --all              Update all apps (alternative to '*')\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'save_install_info' in 'manifest.ps1' (indirectly)\r\n. \"$PSScriptRoot\\..\\lib\\system.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\shortcuts.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\psmodules.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\decompress.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\depends.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\nif (get_config USE_SQLITE_CACHE) {\r\n    . \"$PSScriptRoot\\..\\lib\\database.ps1\"\r\n}\r\n\r\n$opt, $apps, $err = getopt $args 'gfiksqa' 'global', 'force', 'independent', 'no-cache', 'skip-hash-check', 'quiet', 'all'\r\nif ($err) { \"scoop update: $err\"; exit 1 }\r\n$global = $opt.g -or $opt.global\r\n$force = $opt.f -or $opt.force\r\n$check_hash = !($opt.s -or $opt.'skip-hash-check')\r\n$use_cache = !($opt.k -or $opt.'no-cache')\r\n$quiet = $opt.q -or $opt.quiet\r\n$independent = $opt.i -or $opt.independent\r\n$all = $opt.a -or $opt.all\r\n\r\n# load config\r\n$configRepo = get_config SCOOP_REPO\r\nif (!$configRepo) {\r\n    $configRepo = 'https://github.com/ScoopInstaller/Scoop'\r\n    set_config SCOOP_REPO $configRepo | Out-Null\r\n}\r\n\r\n# Find current update channel from config\r\n$configBranch = get_config SCOOP_BRANCH\r\nif (!$configBranch) {\r\n    $configBranch = 'master'\r\n    set_config SCOOP_BRANCH $configBranch | Out-Null\r\n}\r\n\r\nif (($PSVersionTable.PSVersion.Major) -lt 5) {\r\n    # check powershell version\r\n    Write-Output 'PowerShell 5 or later is required to run Scoop.'\r\n    Write-Output 'Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows'\r\n    break\r\n}\r\n$show_update_log = get_config SHOW_UPDATE_LOG $true\r\n\r\nfunction Sync-Scoop {\r\n    [CmdletBinding()]\r\n    Param (\r\n        [Switch]$Log\r\n    )\r\n    # Test if Scoop Core is hold\r\n    if (Test-ScoopCoreOnHold) {\r\n        return\r\n    }\r\n\r\n    # check for git\r\n    if (!(Test-GitAvailable)) { abort \"Scoop uses Git to update itself. Run 'scoop install git' and try again.\" }\r\n\r\n    Write-Host 'Updating Scoop...'\r\n    $currentdir = versiondir 'scoop' 'current'\r\n    if (!(Test-Path \"$currentdir\\.git\")) {\r\n        $newdir = \"$currentdir\\..\\new\"\r\n        $olddir = \"$currentdir\\..\\old\"\r\n\r\n        # get git scoop\r\n        Invoke-Git -ArgumentList @('clone', '-q', $configRepo, '--branch', $configBranch, '--single-branch', $newdir)\r\n\r\n        # check if scoop was successful downloaded\r\n        if (!(Test-Path \"$newdir\\bin\\scoop.ps1\")) {\r\n            Remove-Item $newdir -Force -Recurse\r\n            abort \"Scoop download failed. If this appears several times, try removing SCOOP_REPO by 'scoop config rm SCOOP_REPO'\"\r\n        } else {\r\n            # replace non-git scoop with the git version\r\n            try {\r\n                Rename-Item $currentdir 'old' -ErrorAction Stop\r\n                Rename-Item $newdir 'current' -ErrorAction Stop\r\n            } catch {\r\n                Write-Warning $_\r\n                abort \"Scoop update failed. Folder in use. Please rename folders $currentdir to ``old`` and $newdir to ``current``.\"\r\n            }\r\n        }\r\n    } else {\r\n        if (Test-Path \"$currentdir\\..\\old\") {\r\n            Remove-Item \"$currentdir\\..\\old\" -Recurse -Force -ErrorAction SilentlyContinue\r\n        }\r\n\r\n        $previousCommit = Invoke-Git -Path $currentdir -ArgumentList @('rev-parse', 'HEAD')\r\n        $currentRepo = Invoke-Git -Path $currentdir -ArgumentList @('config', 'remote.origin.url')\r\n        $currentBranch = Invoke-Git -Path $currentdir -ArgumentList @('branch')\r\n\r\n        $isRepoChanged = !($currentRepo -match $configRepo)\r\n        $isBranchChanged = !($currentBranch -match \"\\*\\s+$configBranch\")\r\n\r\n        # Stash uncommitted changes\r\n        if (Invoke-Git -Path $currentdir -ArgumentList @('diff', 'HEAD', '--name-only')) {\r\n            if (get_config AUTOSTASH_ON_CONFLICT) {\r\n                warn 'Uncommitted changes detected. Stashing...'\r\n                Invoke-Git -Path $currentdir -ArgumentList @('stash', 'push', '-m', \"WIP at $([System.DateTime]::Now.ToString('o'))\", '-u', '-q')\r\n            } else {\r\n                warn 'Uncommitted changes detected. Update aborted.'\r\n                return\r\n            }\r\n        }\r\n\r\n        # Change remote url if the repo is changed\r\n        if ($isRepoChanged) {\r\n            Invoke-Git -Path $currentdir -ArgumentList @('config', 'remote.origin.url', $configRepo)\r\n        }\r\n\r\n        # Fetch and reset local repo if the repo or the branch is changed\r\n        if ($isRepoChanged -or $isBranchChanged) {\r\n            # Reset git fetch refs, so that it can fetch all branches (GH-3368)\r\n            Invoke-Git -Path $currentdir -ArgumentList @('config', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*')\r\n            # fetch remote branch\r\n            Invoke-Git -Path $currentdir -ArgumentList @('fetch', '--force', 'origin', \"refs/heads/$configBranch`:refs/remotes/origin/$configBranch\", '-q')\r\n            # checkout and track the branch\r\n            Invoke-Git -Path $currentdir -ArgumentList @('checkout', '-B', $configBranch, '-t', \"origin/$configBranch\", '-q')\r\n            # reset branch HEAD\r\n            Invoke-Git -Path $currentdir -ArgumentList @('reset', '--hard', \"origin/$configBranch\", '-q')\r\n        } else {\r\n            Invoke-Git -Path $currentdir -ArgumentList @('pull', '-q')\r\n        }\r\n\r\n        $res = $lastexitcode\r\n        if ($Log) {\r\n            Invoke-GitLog -Path $currentdir -CommitHash $previousCommit\r\n        }\r\n\r\n        if ($res -ne 0) {\r\n            abort 'Update failed.'\r\n        }\r\n    }\r\n\r\n    shim \"$currentdir\\bin\\scoop.ps1\" $false\r\n}\r\n\r\nfunction Sync-Bucket {\r\n    Param (\r\n        [Switch]$Log\r\n    )\r\n    Write-Host 'Updating Buckets...'\r\n\r\n    if (!(Test-Path (Join-Path (Find-BucketDirectory 'main' -Root) '.git'))) {\r\n        info \"Converting 'main' bucket to git repo...\"\r\n        $status = rm_bucket 'main'\r\n        if ($status -ne 0) {\r\n            abort \"Failed to remove local 'main' bucket.\"\r\n        }\r\n        $status = add_bucket 'main' (known_bucket_repo 'main')\r\n        if ($status -ne 0) {\r\n            abort \"Failed to add remote 'main' bucket.\"\r\n        }\r\n    }\r\n\r\n\r\n    $buckets = Get-LocalBucket | ForEach-Object {\r\n        $path = Find-BucketDirectory $_ -Root\r\n        return @{\r\n            name  = $_\r\n            valid = Test-Path (Join-Path $path '.git')\r\n            path  = $path\r\n        }\r\n    }\r\n\r\n    $buckets | Where-Object { !$_.valid } | ForEach-Object { Write-Host \"'$($_.name)' is not a git repository. Skipped.\" }\r\n\r\n    $updatedFiles = [System.Collections.ArrayList]::Synchronized([System.Collections.ArrayList]::new())\r\n    $removedFiles = [System.Collections.ArrayList]::Synchronized([System.Collections.ArrayList]::new())\r\n    if ($PSVersionTable.PSVersion.Major -ge 7) {\r\n        # Parallel parameter is available since PowerShell 7\r\n        $buckets | Where-Object { $_.valid } | ForEach-Object -ThrottleLimit 5 -Parallel {\r\n            . \"$using:PSScriptRoot\\..\\lib\\core.ps1\"\r\n            . \"$using:PSScriptRoot\\..\\lib\\buckets.ps1\"\r\n\r\n            $name = $_.name\r\n            $bucketLoc = $_.path\r\n            $innerBucketLoc = Find-BucketDirectory $name\r\n\r\n            $previousCommit = Invoke-Git -Path $bucketLoc -ArgumentList @('rev-parse', 'HEAD')\r\n            Invoke-Git -Path $bucketLoc -ArgumentList @('pull', '-q')\r\n            if ($using:Log) {\r\n                Invoke-GitLog -Path $bucketLoc -Name $name -CommitHash $previousCommit\r\n            }\r\n            if (get_config USE_SQLITE_CACHE) {\r\n                Invoke-Git -Path $bucketLoc -ArgumentList @('diff', '--name-status', $previousCommit) | ForEach-Object {\r\n                    $status, $file = $_ -split '\\s+', 2\r\n                    $filePath = Join-Path $bucketLoc $file\r\n                    if ($filePath -match \"^$([regex]::Escape($innerBucketLoc)).*\\.json$\") {\r\n                        switch ($status) {\r\n                            { $_ -in 'A', 'M', 'R' } {\r\n                                [void]($using:updatedFiles).Add($filePath)\r\n                            }\r\n                            'D' {\r\n                                [void]($using:removedFiles).Add([pscustomobject]@{\r\n                                        Name   = ([System.IO.FileInfo]$file).BaseName\r\n                                        Bucket = $name\r\n                                    })\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    } else {\r\n        $buckets | Where-Object { $_.valid } | ForEach-Object {\r\n            $name = $_.name\r\n            $bucketLoc = $_.path\r\n            $innerBucketLoc = Find-BucketDirectory $name\r\n\r\n            $previousCommit = Invoke-Git -Path $bucketLoc -ArgumentList @('rev-parse', 'HEAD')\r\n            Invoke-Git -Path $bucketLoc -ArgumentList @('pull', '-q')\r\n            if ($Log) {\r\n                Invoke-GitLog -Path $bucketLoc -Name $name -CommitHash $previousCommit\r\n            }\r\n            if (get_config USE_SQLITE_CACHE) {\r\n                Invoke-Git -Path $bucketLoc -ArgumentList @('diff', '--name-status', $previousCommit) | ForEach-Object {\r\n                    $status, $file = $_ -split '\\s+', 2\r\n                    $filePath = Join-Path $bucketLoc $file\r\n                    if ($filePath -match \"^$([regex]::Escape($innerBucketLoc)).*\\.json$\") {\r\n                        switch ($status) {\r\n                            { $_ -in 'A', 'M', 'R' } {\r\n                                [void]($updatedFiles).Add($filePath)\r\n                            }\r\n                            'D' {\r\n                                [void]($removedFiles).Add([pscustomobject]@{\r\n                                        Name   = ([System.IO.FileInfo]$file).BaseName\r\n                                        Bucket = $name\r\n                                    })\r\n                            }\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n    if ((get_config USE_SQLITE_CACHE) -and ($updatedFiles.Count -gt 0 -or $removedFiles.Count -gt 0)) {\r\n        info 'Updating cache...'\r\n        Set-ScoopDB -Path $updatedFiles\r\n        $removedFiles | Remove-ScoopDBItem\r\n    }\r\n}\r\n\r\nfunction update($app, $global, $quiet = $false, $independent, $suggested, $use_cache = $true, $check_hash = $true) {\r\n    $old_version = Select-CurrentVersion -AppName $app -Global:$global\r\n    $old_manifest = installed_manifest $app $old_version $global\r\n    $install = install_info $app $old_version $global\r\n\r\n    # re-use architecture, bucket and url from first install\r\n    $architecture = Format-ArchitectureString $install.architecture\r\n    $bucket = $install.bucket\r\n    if ($null -eq $bucket) {\r\n        $bucket = 'main'\r\n    }\r\n    $url = $install.url\r\n\r\n    $manifest = manifest $app $bucket $url\r\n    $version = $manifest.version\r\n    $is_nightly = $version -eq 'nightly'\r\n    if ($is_nightly) {\r\n        $version = nightly_version $quiet\r\n        $check_hash = $false\r\n    }\r\n\r\n    if (!$force -and ($old_version -eq $version)) {\r\n        if (!$quiet) {\r\n            warn \"The latest version of '$app' ($version) is already installed.\"\r\n        }\r\n        return\r\n    }\r\n    if (!$version) {\r\n        # installed from a custom bucket/no longer supported\r\n        error \"No manifest available for '$app'.\"\r\n        return\r\n    }\r\n\r\n    Write-Host \"Updating '$app' ($old_version -> $version)\"\r\n\r\n    #region Workaround for #2952\r\n    if (test_running_process $app $global) {\r\n        Write-Host 'Running process detected, skip updating.'\r\n        return\r\n    }\r\n    #endregion Workaround for #2952\r\n\r\n    # region Workaround\r\n    # Workaround for https://github.com/ScoopInstaller/Scoop/issues/2220 until install is refactored\r\n    # Remove and replace whole region after proper fix\r\n    Write-Host 'Downloading new version'\r\n    if (Test-Aria2Enabled) {\r\n        Invoke-CachedAria2Download $app $version $manifest $architecture $cachedir $manifest.cookie $true $check_hash\r\n    } else {\r\n        $urls = script:url $manifest $architecture\r\n\r\n        foreach ($url in $urls) {\r\n            Invoke-CachedDownload $app $version $url $null $manifest.cookie $true\r\n\r\n            if ($check_hash) {\r\n                $manifest_hash = hash_for_url $manifest $url $architecture\r\n                $source = cache_path $app $version $url\r\n                $ok, $err = check_hash $source $manifest_hash $(show_app $app $bucket)\r\n\r\n                if (!$ok) {\r\n                    error $err\r\n                    if (Test-Path $source) {\r\n                        # rm cached file\r\n                        Remove-Item -Force $source\r\n                    }\r\n                    if ($url.Contains('sourceforge.net')) {\r\n                        Write-Host -f yellow 'SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'\r\n                    }\r\n                    abort $(new_issue_msg $app $bucket 'hash check failed')\r\n                }\r\n            }\r\n        }\r\n    }\r\n    # There is no need to check hash again while installing\r\n    $check_hash = $false\r\n    # endregion Workaround\r\n\r\n    $dir = versiondir $app $old_version $global\r\n    $persist_dir = persistdir $app $global\r\n\r\n    Invoke-HookScript -HookType 'pre_uninstall' -Manifest $old_manifest -Arch $architecture\r\n\r\n    Write-Host \"Uninstalling '$app' ($old_version)\"\r\n    Invoke-Installer -Path $dir -Manifest $old_manifest -ProcessorArchitecture $architecture -Uninstall\r\n    rm_shims $app $old_manifest $global $architecture\r\n\r\n    # If a junction was used during install, that will have been used\r\n    # as the reference directory. Otherwise it will just be the version\r\n    # directory.\r\n    $refdir = unlink_current $dir\r\n    uninstall_psmodule $old_manifest $refdir $global\r\n    env_rm_path $old_manifest $refdir $global $architecture\r\n    env_rm $old_manifest $global $architecture\r\n\r\n    if ($force -and ($old_version -eq $version)) {\r\n        if (!(Test-Path \"$dir/../_$version.old\")) {\r\n            Move-Item \"$dir\" \"$dir/../_$version.old\"\r\n        } else {\r\n            $i = 1\r\n            While (Test-Path \"$dir/../_$version.old($i)\") {\r\n                $i++\r\n            }\r\n            Move-Item \"$dir\" \"$dir/../_$version.old($i)\"\r\n        }\r\n    }\r\n\r\n    Invoke-HookScript -HookType 'post_uninstall' -Manifest $old_manifest -Arch $architecture\r\n\r\n    if ($bucket) {\r\n        # add bucket name it was installed from\r\n        $app = \"$bucket/$app\"\r\n    }\r\n    if ($install.url) {\r\n        # use the url of the install json if the application was installed through url\r\n        $app = $install.url\r\n    }\r\n\r\n    if ($independent) {\r\n        install_app $app $architecture $global $suggested $use_cache $check_hash\r\n    } else {\r\n        # Also add missing dependencies\r\n        $apps = @(Get-Dependency $app $architecture) -ne $app\r\n        ensure_none_failed $apps\r\n        $apps.Where({ !(installed $_) }) + $app | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache $check_hash }\r\n    }\r\n}\r\n\r\nif (-not ($apps -or $all)) {\r\n    if ($global) {\r\n        error 'scoop update: --global is invalid when <app> is not specified.'\r\n        exit 1\r\n    }\r\n    if (!$use_cache) {\r\n        error 'scoop update: --no-cache is invalid when <app> is not specified.'\r\n        exit 1\r\n    }\r\n    Sync-Scoop -Log:$show_update_log\r\n    Sync-Bucket -Log:$show_update_log\r\n    set_config LAST_UPDATE ([System.DateTime]::Now.ToString('o')) | Out-Null\r\n    success 'Scoop was updated successfully!'\r\n} else {\r\n    if ($global -and !(is_admin)) {\r\n        'ERROR: You need admin rights to update global apps.'; exit 1\r\n    }\r\n\r\n    $outdated = @()\r\n    $updateScoop = $null -ne ($apps | Where-Object { $_ -eq 'scoop' }) -or (is_scoop_outdated)\r\n    $apps = $apps | Where-Object { $_ -ne 'scoop' }\r\n    $apps_param = $apps\r\n\r\n    if ($updateScoop) {\r\n        Sync-Scoop -Log:$show_update_log\r\n        Sync-Bucket -Log:$show_update_log\r\n        set_config LAST_UPDATE ([System.DateTime]::Now.ToString('o')) | Out-Null\r\n        success 'Scoop was updated successfully!'\r\n    }\r\n\r\n    if ($apps_param -eq '*' -or $all) {\r\n        $apps = applist (installed_apps $false) $false\r\n        if ($global) {\r\n            $apps += applist (installed_apps $true) $true\r\n        }\r\n    } else {\r\n        if ($apps_param) {\r\n            $apps = Confirm-InstallationStatus $apps_param -Global:$global\r\n        }\r\n    }\r\n    if ($apps) {\r\n        $apps | ForEach-Object {\r\n            ($app, $global) = $_\r\n            $status = app_status $app $global\r\n            if ($status.installed -and ($force -or $status.outdated)) {\r\n                if (!$status.hold) {\r\n                    $outdated += applist $app $global\r\n                    Write-Host -f yellow (\"$app`: $($status.version) -> $($status.latest_version){0}\" -f ('', ' (global)')[$global])\r\n                } else {\r\n                    warn \"'$app' is held to version $($status.version)\"\r\n                }\r\n            } elseif ($apps_param -ne '*' -and !$all) {\r\n                if ($status.installed) {\r\n                    ensure_none_failed $app\r\n                    Write-Host \"$app`: $($status.version) (latest version)\" -ForegroundColor Green\r\n                } else {\r\n                    info 'Please reinstall it or fix the manifest.'\r\n                }\r\n            }\r\n        }\r\n\r\n        if ($outdated -and ((Test-Aria2Enabled) -and (get_config 'aria2-warning-enabled' $true))) {\r\n            warn \"Scoop uses 'aria2c' for multi-connection downloads.\"\r\n            warn \"Should it cause issues, run 'scoop config aria2-enabled false' to disable it.\"\r\n            warn \"To disable this warning, run 'scoop config aria2-warning-enabled false'.\"\r\n        }\r\n        if ($outdated.Length -gt 1) {\r\n            Write-Host -f DarkCyan \"Updating $($outdated.Length) outdated apps:\"\r\n        } elseif ($outdated.Length -eq 0) {\r\n            Write-Host -f Green \"Latest versions for all apps are installed! For more information try 'scoop status'\"\r\n        } else {\r\n            Write-Host -f DarkCyan 'Updating one outdated app:'\r\n        }\r\n    }\r\n\r\n    $suggested = @{}\r\n    # $outdated is a list of ($app, $global) tuples\r\n    $outdated | ForEach-Object { update @_ $quiet $independent $suggested $use_cache $check_hash }\r\n}\r\n\r\nexit 0\r\n"
  },
  {
    "path": "libexec/scoop-virustotal.ps1",
    "content": "# Usage: scoop virustotal [* | app1 app2 ...] [options]\r\n# Summary: Look for app's hash or url on virustotal.com\r\n# Help: Look for app's hash or url on virustotal.com\r\n#\r\n# Use a single '*' or the '-a/--all' switch to check all installed apps.\r\n#\r\n# To use this command, you have to sign up to VirusTotal's community,\r\n# and get an API key. Then, tell scoop about your API key with:\r\n#\r\n#   scoop config virustotal_api_key <your API key: 64 lower case hex digits>\r\n#\r\n# Exit codes:\r\n#  0 -> success\r\n#  1 -> problem parsing arguments\r\n#  2 -> at least one package was marked unsafe by VirusTotal\r\n#  4 -> at least one exception was raised while looking for info\r\n#  8 -> at least one package couldn't be queried because the manifest couldn't be found\r\n# 16 -> VirusTotal API key is not configured\r\n# Note: the exit codes (2, 4 & 8) may be combined, e.g. 6 -> exit codes\r\n#       2 & 4 combined\r\n#\r\n# Options:\r\n#   -a, --all                 Check for all installed apps\r\n#   -s, --scan                For packages where VirusTotal has no information, send download URL\r\n#                             for analysis (and future retrieval). This requires you to configure\r\n#                             your virustotal_api_key.\r\n#   -n, --no-depends          By default, all dependencies are checked too. This flag avoids it.\r\n#   -u, --no-update-scoop     Don't update Scoop before checking if it's outdated\r\n#   -p, --passthru            Return reports as objects\r\n\r\n. \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n. \"$PSScriptRoot\\..\\lib\\versions.ps1\" # 'Select-CurrentVersion'\r\n. \"$PSScriptRoot\\..\\lib\\manifest.ps1\" # 'Get-Manifest'\r\n. \"$PSScriptRoot\\..\\lib\\json.ps1\" # 'json_path'\r\n. \"$PSScriptRoot\\..\\lib\\download.ps1\" # 'hash_for_url'\r\n. \"$PSScriptRoot\\..\\lib\\depends.ps1\" # 'Get-Dependency'\r\n\r\n$opt, $apps, $err = getopt $args 'asnup' @('all', 'scan', 'no-depends', 'no-update-scoop', 'passthru')\r\nif ($err) { \"scoop virustotal: $err\"; exit 1 }\r\n$all = $apps -eq '*' -or $opt.a -or $opt.all\r\nif (!$apps -and !$all) { my_usage; exit 1 }\r\n$architecture = Get-DefaultArchitecture\r\n\r\nif (is_scoop_outdated) {\r\n    if ($opt.u -or $opt.'no-update-scoop') {\r\n        warn 'Scoop is out of date.'\r\n    } else {\r\n        & \"$PSScriptRoot\\scoop-update.ps1\"\r\n    }\r\n}\r\n\r\nif ($all) {\r\n    $apps = (installed_apps $false) + (installed_apps $true)\r\n}\r\n\r\nif (!$opt.n -and !$opt.'no-depends') {\r\n    $apps = $apps | Get-Dependency -Architecture $architecture | Select-Object -Unique\r\n}\r\n\r\n$_ERR_UNSAFE = 2\r\n$_ERR_EXCEPTION = 4\r\n$_ERR_NO_INFO = 8\r\n$_ERR_NO_API_KEY = 16\r\n\r\n$exit_code = 0\r\n\r\n# Global API key:\r\n$api_key = get_config VIRUSTOTAL_API_KEY\r\nif (!$api_key) {\r\n    abort (\"VirusTotal API key is not configured`n\" +\r\n        \"  You could get one from https://www.virustotal.com/gui/my-apikey and set with`n\" +\r\n        \"  scoop config virustotal_api_key <API key>\") $_ERR_NO_API_KEY\r\n}\r\n\r\n# Global flag to explain only once about sleep between requests\r\n$explained_rate_limit_sleeping = $False\r\n\r\n# Requests counter to slow down requests submitted to VirusTotal as\r\n# script execution progresses\r\n$requests = 0\r\n\r\nFunction ConvertTo-VirusTotalUrlId ($url) {\r\n    $url_id = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($url))\r\n    $url_id = $url_id -replace '\\+', '-'\r\n    $url_id = $url_id -replace '/', '_'\r\n    $url_id = $url_id -replace '=', ''\r\n    $url_id\r\n}\r\n\r\nFunction Get-VirusTotalResultByHash ($hash, $url, $app) {\r\n    $hash = $hash.ToLower()\r\n    $api_url = \"https://www.virustotal.com/api/v3/files/$hash\"\r\n    $headers = @{}\r\n    $headers.Add('Accept', 'application/json')\r\n    $headers.Add('x-apikey', $api_key)\r\n    $response = Invoke-WebRequest -Uri $api_url -Method GET -Headers $headers -UseBasicParsing\r\n    $result = $response.Content\r\n    $stats = json_path $result '$.data.attributes.last_analysis_stats'\r\n    [int]$malicious = json_path $stats '$.malicious'\r\n    [int]$suspicious = json_path $stats '$.suspicious'\r\n    [int]$timeout = json_path $stats '$.timeout'\r\n    [int]$undetected = json_path $stats '$.undetected'\r\n    [int]$unsafe = $malicious + $suspicious\r\n    [int]$total = $unsafe + $undetected\r\n    [int]$fileSize = json_path $result '$.data.attributes.size'\r\n    $report_hash = json_path $result '$.data.attributes.sha256'\r\n    $report_url = \"https://www.virustotal.com/gui/file/$report_hash\"\r\n    if ($total -eq 0) {\r\n        info \"$app`: Analysis in progress.\"\r\n        [PSCustomObject] @{\r\n            'App.Name'        = $app\r\n            'App.Url'         = $url\r\n            'App.Hash'        = $hash\r\n            'App.HashType'    = $null\r\n            'App.Size'        = filesize $fileSize\r\n            'FileReport.Url'  = $report_url\r\n            'FileReport.Hash' = $report_hash\r\n            'UrlReport.Url'   = $null\r\n        }\r\n    } else {\r\n        $vendorResults = (ConvertFrom-Json((json_path $result '$.data.attributes.last_analysis_results'))).PSObject.Properties.Value\r\n        switch ($unsafe) {\r\n            0 {\r\n                success \"$app`: $unsafe/$total, see $report_url\"\r\n            }\r\n            1 {\r\n                warn \"$app`: $unsafe/$total, see $report_url\"\r\n            }\r\n            2 {\r\n                warn \"$app`: $unsafe/$total, see $report_url\"\r\n            }\r\n            Default {\r\n                warn \"$([char]0x1b)[31m$app`: $unsafe/$total, see $report_url$([char]0x1b)[0m\"\r\n            }\r\n        }\r\n        $maliciousResults = $vendorResults |\r\n            Where-Object -Property category -EQ 'malicious' |\r\n            Select-Object -ExpandProperty engine_name\r\n        $suspiciousResults = $vendorResults |\r\n            Where-Object -Property category -EQ 'suspicious' |\r\n            Select-Object -ExpandProperty engine_name\r\n        [PSCustomObject] @{\r\n            'App.Name'              = $app\r\n            'App.Url'               = $url\r\n            'App.Hash'              = $hash\r\n            'App.HashType'          = $null\r\n            'App.Size'              = filesize $fileSize\r\n            'FileReport.Url'        = $report_url\r\n            'FileReport.Hash'       = $report_hash\r\n            'FileReport.Malicious'  = if ($maliciousResults) { $maliciousResults } else { 0 }\r\n            'FileReport.Suspicious' = if ($suspiciousResults) { $suspiciousResults } else { 0 }\r\n            'FileReport.Timeout'    = $timeout\r\n            'FileReport.Undetected' = $undetected\r\n            'UrlReport.Url'         = $null\r\n        }\r\n    }\r\n    if ($unsafe -gt 0) {\r\n        $Script:exit_code = $exit_code -bor $_ERR_UNSAFE\r\n    }\r\n}\r\n\r\nFunction Get-VirusTotalResultByUrl ($url, $app) {\r\n    $id = ConvertTo-VirusTotalUrlId $url\r\n    $api_url = \"https://www.virustotal.com/api/v3/urls/$id\"\r\n    $headers = @{}\r\n    $headers.Add('Accept', 'application/json')\r\n    $headers.Add('x-apikey', $api_key)\r\n    $response = Invoke-WebRequest -Uri $api_url -Method GET -Headers $headers -UseBasicParsing\r\n    $result = $response.Content\r\n    $id = json_path $result '$.data.id'\r\n    $hash = json_path $result '$.data.attributes.last_http_response_content_sha256' 6>$null\r\n    $last_analysis_date = json_path $result '$.data.attributes.last_analysis_date' 6>$null\r\n    $url_report_url = \"https://www.virustotal.com/gui/url/$id\"\r\n    info \"$app`: Url report found.\"\r\n    if (!$hash) {\r\n        if (!$last_analysis_date) {\r\n            info \"$app`: Analysis in progress.\"\r\n        } else {\r\n            info \"$app`: Related file report not found.\"\r\n            warn \"$app`: Manual file upload is required (instead of url submission).\"\r\n        }\r\n        [PSCustomObject] @{\r\n            'App.Name'       = $app\r\n            'App.Url'        = $url\r\n            'App.Hash'       = $null\r\n            'App.HashType'   = $null\r\n            'FileReport.Url' = $null\r\n            'UrlReport.Url'  = $url_report_url\r\n            'UrlReport.Hash' = $null\r\n        }\r\n    } else {\r\n        info \"$app`: Related file report found.\"\r\n        [PSCustomObject] @{\r\n            'App.Name'       = $app\r\n            'App.Url'        = $url\r\n            'App.Hash'       = $null\r\n            'App.HashType'   = $null\r\n            'FileReport.Url' = $null\r\n            'UrlReport.Url'  = $url_report_url\r\n            'UrlReport.Hash' = $hash\r\n        }\r\n    }\r\n}\r\n\r\n# Submit-ToVirusTotal\r\n# - $url: where file to check can be downloaded\r\n# - $app: Name of the application (used for reporting)\r\n# - $do_scan: [boolean flag] whether to actually submit to VirusTotal\r\n#             This is a parameter instead of conditionnally calling\r\n#             the function to consolidate the warning message\r\n# - $retrying: [boolean] Optional, for internal use to retry\r\n#              submitting the file after a delay if the rate limit is\r\n#              exceeded, without risking an infinite loop (as stack\r\n#              overflow) if the submission keeps failing.\r\nFunction Submit-ToVirusTotal ($url, $app, $do_scan, $retrying = $False) {\r\n    if (!$do_scan) {\r\n        warn \"$app`: not found`: you can manually submit $url\"\r\n        return\r\n    }\r\n\r\n    try {\r\n        $requests += 1\r\n\r\n        $encoded_url = [System.Web.HttpUtility]::UrlEncode($url)\r\n        $api_url = 'https://www.virustotal.com/api/v3/urls'\r\n        $content_type = 'application/x-www-form-urlencoded'\r\n        $headers = @{}\r\n        $headers.Add('Accept', 'application/json')\r\n        $headers.Add('x-apikey', $api_key)\r\n        $headers.Add('Content-Type', $content_type)\r\n        $body = \"url=$encoded_url\"\r\n        $result = Invoke-WebRequest -Uri $api_url -Method POST -Headers $headers -ContentType $content_type -Body $body -UseBasicParsing\r\n        if ($result.StatusCode -eq 200) {\r\n            $id = ((json_path $result '$.data.id') -split '-')[1]\r\n            $url_report_url = \"https://www.virustotal.com/gui/url/$id\"\r\n            $fileSize = Get-RemoteFileSize $url\r\n            if ($fileSize -gt 80000000) {\r\n                info \"$app`: Remote file size: $(filesize $fileSize). Large files might require manual file upload instead of url submission.\"\r\n            }\r\n            info \"$app`: Analysis in progress.\"\r\n            [PSCustomObject] @{\r\n                'App.Name'       = $app\r\n                'App.Url'        = $url\r\n                'App.Size'       = filesize $fileSize\r\n                'FileReport.Url' = $null\r\n                'UrlReport.Url'  = $url_report_url\r\n            }\r\n            return\r\n        }\r\n\r\n        # EAFP: submission failed -> sleep, then retry\r\n        if (!$retrying) {\r\n            if (!$explained_rate_limit_sleeping) {\r\n                $explained_rate_limit_sleeping = $True\r\n                info \"Sleeping 60+ seconds between requests due to VirusTotal's 4/min limit\"\r\n            }\r\n            Start-Sleep -s (60 + $requests)\r\n            Submit-ToVirusTotal $url $app $do_scan $True\r\n        } else {\r\n            warn \"$app`: VirusTotal submission of $url failed`:`n\" +\r\n            \"`tAPI returned $($result.StatusCode) after retrying\"\r\n        }\r\n    } catch [Exception] {\r\n        warn \"$app`: VirusTotal submission failed`: $($_.Exception.Message)\"\r\n        return\r\n    }\r\n}\r\n\r\n$reports = $apps | ForEach-Object {\r\n    $app = $_\r\n    $null, $manifest, $bucket, $null = Get-Manifest $app\r\n    if (!$manifest) {\r\n        $exit_code = $exit_code -bor $_ERR_NO_INFO\r\n        warn \"$app`: manifest not found\"\r\n        return\r\n    }\r\n\r\n    [int]$index = 0\r\n    $urls = script:url $manifest $architecture\r\n    $urls | ForEach-Object {\r\n        $url = $_\r\n        $index++\r\n        if ($urls.GetType().IsArray) {\r\n            info \"$app`: url $index\"\r\n        }\r\n        $hash = hash_for_url $manifest $url $architecture\r\n\r\n        try {\r\n            $isHashUnsupported = $false\r\n            if ($hash -match '(?<algo>[^:]+):(?<hash>.*)') {\r\n                $algo = $matches.algo\r\n                $hash = $matches.hash\r\n                if ($matches.algo -inotin 'md5', 'sha1', 'sha256') {\r\n                    $hash = $null\r\n                    $isHashUnsupported = $true\r\n                    warn \"$app`: Unsupported hash $($matches.algo). Will search by url instead.\"\r\n                }\r\n            } elseif ($hash) {\r\n                $algo = 'sha256'\r\n            }\r\n            if ($hash) {\r\n                $file_report = Get-VirusTotalResultByHash $hash $url $app\r\n                $file_report.'App.HashType' = $algo\r\n                $file_report\r\n                return\r\n            } elseif (!$isHashUnsupported) {\r\n                warn \"$app`: Hash not found. Will search by url instead.\"\r\n            }\r\n        } catch [Exception] {\r\n            $exit_code = $exit_code -bor $_ERR_EXCEPTION\r\n            if ($_.Exception.Response.StatusCode -eq 404) {\r\n                $file_report_not_found = $true\r\n                warn \"$app`: File report not found. Will search by url instead.\"\r\n            } else {\r\n                if ($_.Exception.Response.StatusCode -in 204, 429) {\r\n                    abort \"$app`: VirusTotal request failed`: $($_.Exception.Message)\" $exit_code\r\n                }\r\n                warn \"$app`: VirusTotal request failed`: $($_.Exception.Message)\"\r\n                return\r\n            }\r\n        }\r\n\r\n        try {\r\n            $url_report = Get-VirusTotalResultByUrl $url $app\r\n            $url_report.'App.Hash' = $hash\r\n            $url_report.'App.HashType' = $algo\r\n            if ($url_report.'UrlReport.Hash' -and ($file_report_not_found -eq $true) -and $hash) {\r\n                if ($algo -eq 'sha256') {\r\n                    if ($url_report.'UrlReport.Hash' -eq $hash) {\r\n                        warn \"$app`: Manual file upload is required (instead of url submission) for $url\"\r\n                    } else {\r\n                        error \"$app`: Hash not matched for $url\"\r\n                    }\r\n                } else {\r\n                    error \"$app`: Hash not matched or manual file upload is required (instead of url submission) for $url\"\r\n                }\r\n                $url_report\r\n                return\r\n            }\r\n            if (!$url_report.'UrlReport.Hash') {\r\n                $url_report\r\n                return\r\n            }\r\n        } catch [Exception] {\r\n            $exit_code = $exit_code -bor $_ERR_EXCEPTION\r\n            if ($_.Exception.Response.StatusCode -eq 404) {\r\n                warn \"$app`: Url report not found. Will submit $url\"\r\n                Submit-ToVirusTotal $url $app ($opt.scan -or $opt.s)\r\n                return\r\n            } else {\r\n                if ($_.Exception.Response.StatusCode -in 204, 429) {\r\n                    abort \"$app`: VirusTotal request failed`: $($_.Exception.Message)\" $exit_code\r\n                }\r\n                warn \"$app`: VirusTotal request failed`: $($_.Exception.Message)\"\r\n                return\r\n            }\r\n        }\r\n\r\n        try {\r\n            $file_report = Get-VirusTotalResultByHash $url_report.'UrlReport.Hash' $url $app\r\n            $file_report.'App.Hash' = $hash\r\n            $file_report.'App.HashType' = $algo\r\n            $file_report.'UrlReport.Url' = $url_report.'UrlReport.Url'\r\n            $file_report\r\n            warn \"$app`: Unable to check hash match for $url\"\r\n        } catch [Exception] {\r\n            $exit_code = $exit_code -bor $_ERR_EXCEPTION\r\n            if ($_.Exception.Response.StatusCode -eq 404) {\r\n                warn \"$app`: File report not found for unknown reason. Manual file upload is required (instead of url submission).\"\r\n                $url_report\r\n            } else {\r\n                if ($_.Exception.Response.StatusCode -in 204, 429) {\r\n                    abort \"$app`: VirusTotal request failed`: $($_.Exception.Message)\" $exit_code\r\n                }\r\n                warn \"$app`: VirusTotal request failed`: $($_.Exception.Message)\"\r\n                return\r\n            }\r\n        }\r\n    }\r\n}\r\nif ($opt.p -or $opt.'passthru') {\r\n    $reports\r\n}\r\n\r\nexit $exit_code\r\n"
  },
  {
    "path": "libexec/scoop-which.ps1",
    "content": "# Usage: scoop which <command>\r\n# Summary: Locate a shim/executable (similar to 'which' on Linux)\r\n# Help: Locate the path to a shim/executable that was installed with Scoop (similar to 'which' on Linux)\r\nparam($command)\r\n\r\nif (!$command) {\r\n    error '<command> missing'\r\n    my_usage\r\n    exit 1\r\n}\r\n\r\n$path = Get-CommandPath $command\r\n\r\nif ($null -eq $path) {\r\n    warn \"'$command' not found, not a scoop shim, or a broken shim.\"\r\n    exit 2\r\n} else {\r\n    friendly_path $path\r\n    exit 0\r\n}\r\n"
  },
  {
    "path": "schema.json",
    "content": "{\r\n    \"$id\": \"http://scoop.sh/draft/schema#\",\r\n    \"$schema\": \"http://json-schema.org/draft-07/schema#\",\r\n    \"additionalProperties\": false,\r\n    \"definitions\": {\r\n        \"hashPattern\": {\r\n            \"pattern\": \"^([a-fA-F0-9]{64}|(sha1|sha256|sha512|md5):([a-fA-F0-9]{32}|[a-fA-F0-9]{40}|[a-fA-F0-9]{64}|[a-fA-F0-9]{128}))$\",\r\n            \"type\": \"string\"\r\n        },\r\n        \"jsonPathPattern\": {\r\n            \"pattern\": \"^\\\\$[.\\\\[].*$\",\r\n            \"type\": \"string\"\r\n        },\r\n        \"hash\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"$ref\": \"#/definitions/hashPattern\"\r\n                },\r\n                {\r\n                    \"items\": {\r\n                        \"$ref\": \"#/definitions/hashPattern\"\r\n                    },\r\n                    \"minItems\": 1,\r\n                    \"type\": \"array\",\r\n                    \"uniqueItems\": true\r\n                }\r\n            ]\r\n        },\r\n        \"hashExtraction\": {\r\n            \"additionalProperties\": false,\r\n            \"properties\": {\r\n                \"find\": {\r\n                    \"format\": \"regex\",\r\n                    \"type\": \"string\",\r\n                    \"description\": \"Same as 'regex'\"\r\n                },\r\n                \"regex\": {\r\n                    \"format\": \"regex\",\r\n                    \"type\": \"string\"\r\n                },\r\n                \"jp\": {\r\n                    \"$ref\": \"#/definitions/jsonPathPattern\",\r\n                    \"description\": \"Same as 'jsonpath'\"\r\n                },\r\n                \"jsonpath\": {\r\n                    \"$ref\": \"#/definitions/jsonPathPattern\"\r\n                },\r\n                \"xpath\": {\r\n                    \"type\": \"string\"\r\n                },\r\n                \"mode\": {\r\n                    \"enum\": [\r\n                        \"download\",\r\n                        \"extract\",\r\n                        \"json\",\r\n                        \"xpath\",\r\n                        \"rdf\",\r\n                        \"metalink\",\r\n                        \"fosshub\",\r\n                        \"sourceforge\"\r\n                    ]\r\n                },\r\n                \"type\": {\r\n                    \"enum\": [\r\n                        \"md5\",\r\n                        \"sha1\",\r\n                        \"sha256\",\r\n                        \"sha512\"\r\n                    ],\r\n                    \"description\": \"Deprecated, hash type is determined automatically\"\r\n                },\r\n                \"url\": {\r\n                    \"anyOf\": [\r\n                        {\r\n                            \"format\": \"uri\",\r\n                            \"type\": \"string\"\r\n                        },\r\n                        {\r\n                            \"pattern\": \"^(\\\\$url|\\\\$baseurl).[\\\\w\\\\d]+$\",\r\n                            \"type\": \"string\"\r\n                        },\r\n                        {\r\n                            \"pattern\": \"^.*(\\\\$url|\\\\$baseurl).*$\",\r\n                            \"type\": \"string\"\r\n                        }\r\n                    ]\r\n                }\r\n            },\r\n            \"type\": \"object\"\r\n        },\r\n        \"hashExtractionOrArrayOfHashExtractions\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"$ref\": \"#/definitions/hashExtraction\"\r\n                },\r\n                {\r\n                    \"items\": {\r\n                        \"$ref\": \"#/definitions/hashExtraction\"\r\n                    },\r\n                    \"minItems\": 1,\r\n                    \"type\": \"array\",\r\n                    \"uniqueItems\": false\r\n                }\r\n            ]\r\n        },\r\n        \"architecture\": {\r\n            \"additionalProperties\": false,\r\n            \"properties\": {\r\n                \"bin\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStringsOrAnArrayOfArrayOfStrings\"\r\n                },\r\n                \"checkver\": {\r\n                    \"$ref\": \"#/definitions/checkver\"\r\n                },\r\n                \"env_add_path\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"env_set\": {\r\n                    \"type\": \"object\"\r\n                },\r\n                \"extract_dir\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"hash\": {\r\n                    \"$ref\": \"#/definitions/hash\"\r\n                },\r\n                \"installer\": {\r\n                    \"$ref\": \"#/definitions/installer\"\r\n                },\r\n                \"post_install\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"post_uninstall\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"pre_install\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"pre_uninstall\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"shortcuts\": {\r\n                    \"$ref\": \"#/definitions/shortcutsArray\"\r\n                },\r\n                \"uninstaller\": {\r\n                    \"$ref\": \"#/definitions/uninstaller\"\r\n                },\r\n                \"url\": {\r\n                    \"$ref\": \"#/definitions/uriOrArrayOfUris\"\r\n                }\r\n            },\r\n            \"type\": \"object\"\r\n        },\r\n        \"arrayOfArrayOfStrings\": {\r\n            \"items\": {\r\n                \"items\": {\r\n                    \"type\": \"string\"\r\n                },\r\n                \"minItems\": 1,\r\n                \"type\": \"array\"\r\n            },\r\n            \"minItems\": 1,\r\n            \"type\": \"array\"\r\n        },\r\n        \"shortcutsArray\": {\r\n            \"items\": {\r\n                \"items\": {\r\n                    \"type\": \"string\"\r\n                },\r\n                \"minItems\": 2,\r\n                \"maxItems\": 4,\r\n                \"type\": \"array\"\r\n            },\r\n            \"minItems\": 1,\r\n            \"type\": \"array\"\r\n        },\r\n        \"autoupdateArch\": {\r\n            \"type\": \"object\",\r\n            \"additionalProperties\": false,\r\n            \"properties\": {\r\n                \"bin\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStringsOrAnArrayOfArrayOfStrings\"\r\n                },\r\n                \"env_add_path\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"env_set\": {\r\n                    \"type\": \"object\"\r\n                },\r\n                \"extract_dir\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"hash\": {\r\n                    \"$ref\": \"#/definitions/hashExtractionOrArrayOfHashExtractions\"\r\n                },\r\n                \"installer\": {\r\n                    \"type\": \"object\",\r\n                    \"additionalProperties\": false,\r\n                    \"properties\": {\r\n                        \"file\": {\r\n                            \"type\": \"string\"\r\n                        }\r\n                    }\r\n                },\r\n                \"shortcuts\": {\r\n                    \"$ref\": \"#/definitions/shortcutsArray\"\r\n                },\r\n                \"url\": {\r\n                    \"$ref\": \"#/definitions/autoupdateUriOrArrayOfAutoupdateUris\"\r\n                }\r\n            }\r\n        },\r\n        \"autoupdate\": {\r\n            \"type\": \"object\",\r\n            \"additionalProperties\": false,\r\n            \"properties\": {\r\n                \"architecture\": {\r\n                    \"type\": \"object\",\r\n                    \"additionalProperties\": false,\r\n                    \"properties\": {\r\n                        \"32bit\": {\r\n                            \"$ref\": \"#/definitions/autoupdateArch\"\r\n                        },\r\n                        \"64bit\": {\r\n                            \"$ref\": \"#/definitions/autoupdateArch\"\r\n                        },\r\n                        \"arm64\": {\r\n                            \"$ref\": \"#/definitions/autoupdateArch\"\r\n                        }\r\n                    }\r\n                },\r\n                \"bin\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStringsOrAnArrayOfArrayOfStrings\"\r\n                },\r\n                \"env_add_path\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"env_set\": {\r\n                    \"type\": \"object\"\r\n                },\r\n                \"extract_dir\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"hash\": {\r\n                    \"$ref\": \"#/definitions/hashExtractionOrArrayOfHashExtractions\"\r\n                },\r\n                \"installer\": {\r\n                    \"type\": \"object\",\r\n                    \"additionalProperties\": false,\r\n                    \"properties\": {\r\n                        \"file\": {\r\n                            \"type\": \"string\"\r\n                        }\r\n                    }\r\n                },\r\n                \"license\": {\r\n                    \"$ref\": \"#/definitions/license\"\r\n                },\r\n                \"notes\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"persist\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStringsOrAnArrayOfArrayOfStrings\"\r\n                },\r\n                \"psmodule\": {\r\n                    \"type\": \"object\",\r\n                    \"additionalProperties\": false,\r\n                    \"properties\": {\r\n                        \"name\": {\r\n                            \"type\": \"string\"\r\n                        }\r\n                    }\r\n                },\r\n                \"shortcuts\": {\r\n                    \"$ref\": \"#/definitions/shortcutsArray\"\r\n                },\r\n                \"url\": {\r\n                    \"$ref\": \"#/definitions/autoupdateUriOrArrayOfAutoupdateUris\"\r\n                }\r\n            }\r\n        },\r\n        \"checkver\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"format\": \"regex\",\r\n                    \"type\": \"string\"\r\n                },\r\n                {\r\n                    \"additionalProperties\": false,\r\n                    \"properties\": {\r\n                        \"github\": {\r\n                            \"format\": \"uri\",\r\n                            \"type\": \"string\"\r\n                        },\r\n                        \"re\": {\r\n                            \"format\": \"regex\",\r\n                            \"type\": \"string\",\r\n                            \"description\": \"Same as 'regex'\"\r\n                        },\r\n                        \"regex\": {\r\n                            \"format\": \"regex\",\r\n                            \"type\": \"string\"\r\n                        },\r\n                        \"url\": {\r\n                            \"format\": \"uri\",\r\n                            \"type\": \"string\"\r\n                        },\r\n                        \"jp\": {\r\n                            \"$ref\": \"#/definitions/jsonPathPattern\",\r\n                            \"description\": \"Same as 'jsonpath'\"\r\n                        },\r\n                        \"jsonpath\": {\r\n                            \"$ref\": \"#/definitions/jsonPathPattern\"\r\n                        },\r\n                        \"xpath\": {\r\n                            \"type\": \"string\"\r\n                        },\r\n                        \"reverse\": {\r\n                            \"description\": \"Reverse the order of regex matches\",\r\n                            \"type\": \"boolean\"\r\n                        },\r\n                        \"replace\": {\r\n                            \"description\": \"Allows rearrange the regexp matches\",\r\n                            \"type\": \"string\"\r\n                        },\r\n                        \"useragent\": {\r\n                            \"type\": \"string\"\r\n                        },\r\n                        \"script\": {\r\n                            \"$ref\": \"#/definitions/stringOrArrayOfStrings\",\r\n                            \"description\": \"Custom PowerShell script to retrieve application version using more complex approach.\"\r\n                        },\r\n                        \"sourceforge\": {\r\n                            \"anyOf\": [\r\n                                {\r\n                                    \"type\": \"string\"\r\n                                },\r\n                                {\r\n                                    \"additionalProperties\": false,\r\n                                    \"properties\": {\r\n                                        \"project\": {\r\n                                            \"type\": \"string\"\r\n                                        },\r\n                                        \"path\": {\r\n                                            \"type\": \"string\"\r\n                                        }\r\n                                    },\r\n                                    \"type\": \"object\"\r\n                                }\r\n                            ]\r\n                        }\r\n                    },\r\n                    \"type\": \"object\"\r\n                }\r\n            ]\r\n        },\r\n        \"installer\": {\r\n            \"additionalProperties\": false,\r\n            \"properties\": {\r\n                \"_comment\": {\r\n                    \"description\": \"Undocumented: only used in scoop-extras/oraclejdk* and scoop-extras/appengine-go\",\r\n                    \"type\": \"string\"\r\n                },\r\n                \"args\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"file\": {\r\n                    \"type\": \"string\"\r\n                },\r\n                \"script\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"keep\": {\r\n                    \"type\": \"boolean\"\r\n                }\r\n            },\r\n            \"type\": \"object\"\r\n        },\r\n        \"stringOrArrayOfStrings\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"type\": \"string\"\r\n                },\r\n                {\r\n                    \"items\": {\r\n                        \"type\": \"string\"\r\n                    },\r\n                    \"minItems\": 1,\r\n                    \"type\": \"array\"\r\n                }\r\n            ]\r\n        },\r\n        \"stringOrArrayOfStringsOrAnArrayOfArrayOfStrings\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"type\": \"string\"\r\n                },\r\n                {\r\n                    \"items\": {\r\n                        \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                    },\r\n                    \"minItems\": 1,\r\n                    \"type\": \"array\"\r\n                }\r\n            ]\r\n        },\r\n        \"uninstaller\": {\r\n            \"properties\": {\r\n                \"args\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                },\r\n                \"file\": {\r\n                    \"type\": \"string\"\r\n                },\r\n                \"script\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                }\r\n            },\r\n            \"oneOf\": [\r\n                {\r\n                    \"required\": [\r\n                        \"file\"\r\n                    ]\r\n                },\r\n                {\r\n                    \"required\": [\r\n                        \"script\"\r\n                    ]\r\n                }\r\n            ],\r\n            \"type\": \"object\"\r\n        },\r\n        \"uriOrArrayOfUris\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"format\": \"uri\",\r\n                    \"not\": {\r\n                        \"pattern\": \"(\\\\$)\"\r\n                    },\r\n                    \"type\": \"string\"\r\n                },\r\n                {\r\n                    \"items\": {\r\n                        \"format\": \"uri\",\r\n                        \"not\": {\r\n                            \"pattern\": \"(\\\\$)\"\r\n                        },\r\n                        \"type\": \"string\"\r\n                    },\r\n                    \"minItems\": 1,\r\n                    \"type\": \"array\",\r\n                    \"uniqueItems\": true\r\n                }\r\n            ]\r\n        },\r\n        \"autoupdateUriOrArrayOfAutoupdateUris\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"format\": \"uri\",\r\n                    \"type\": \"string\"\r\n                },\r\n                {\r\n                    \"items\": {\r\n                        \"format\": \"uri\",\r\n                        \"type\": \"string\"\r\n                    },\r\n                    \"minItems\": 1,\r\n                    \"type\": \"array\",\r\n                    \"uniqueItems\": true\r\n                }\r\n            ]\r\n        },\r\n        \"licenseIdentifiers\": {\r\n            \"type\": \"string\",\r\n            \"description\": \"License identifier based on SPDX License List https://spdx.org/licenses/\",\r\n            \"examples\": [\r\n                \"Apache-2.0\",\r\n                \"BSD-3-Clause\",\r\n                \"Freeware\",\r\n                \"GPL-2.0-only\",\r\n                \"GPL-2.0-or-later\",\r\n                \"GPL-3.0-only\",\r\n                \"GPL-3.0-or-later\",\r\n                \"ISC\",\r\n                \"LGPL-2.0-only\",\r\n                \"LGPL-2.0-or-later\",\r\n                \"LGPL-2.1-only\",\r\n                \"LGPL-2.1-or-later\",\r\n                \"LGPL-3.0-only\",\r\n                \"LGPL-3.0-or-later\",\r\n                \"MIT\",\r\n                \"MS-PL\",\r\n                \"Proprietary\",\r\n                \"Public Domain\",\r\n                \"Shareware\",\r\n                \"Unlicense\"\r\n            ]\r\n        },\r\n        \"license\": {\r\n            \"anyOf\": [\r\n                {\r\n                    \"$ref\": \"#/definitions/licenseIdentifiers\"\r\n                },\r\n                {\r\n                    \"additionalProperties\": false,\r\n                    \"properties\": {\r\n                        \"url\": {\r\n                            \"format\": \"uri\",\r\n                            \"type\": \"string\"\r\n                        },\r\n                        \"identifier\": {\r\n                            \"$ref\": \"#/definitions/licenseIdentifiers\"\r\n                        }\r\n                    },\r\n                    \"required\": [\r\n                        \"identifier\"\r\n                    ],\r\n                    \"type\": \"object\"\r\n                }\r\n            ]\r\n        }\r\n    },\r\n    \"properties\": {\r\n        \"$schema\": {\r\n            \"type\": \"string\",\r\n            \"format\": \"uri\"\r\n        },\r\n        \"_comment\": {\r\n            \"description\": \"Deprecated. Use ## instead.\",\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"##\": {\r\n            \"description\": \"A comment.\",\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"architecture\": {\r\n            \"additionalProperties\": false,\r\n            \"properties\": {\r\n                \"32bit\": {\r\n                    \"$ref\": \"#/definitions/architecture\"\r\n                },\r\n                \"64bit\": {\r\n                    \"$ref\": \"#/definitions/architecture\"\r\n                },\r\n                \"arm64\": {\r\n                    \"$ref\": \"#/definitions/architecture\"\r\n                }\r\n            },\r\n            \"type\": \"object\"\r\n        },\r\n        \"autoupdate\": {\r\n            \"$ref\": \"#/definitions/autoupdate\"\r\n        },\r\n        \"bin\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStringsOrAnArrayOfArrayOfStrings\"\r\n        },\r\n        \"persist\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStringsOrAnArrayOfArrayOfStrings\"\r\n        },\r\n        \"checkver\": {\r\n            \"$ref\": \"#/definitions/checkver\"\r\n        },\r\n        \"cookie\": {\r\n            \"description\": \"Undocumented: Found at https://github.com/se35710/scoop-java/search?l=JSON&q=cookie\",\r\n            \"type\": \"object\"\r\n        },\r\n        \"depends\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"description\": {\r\n            \"type\": \"string\"\r\n        },\r\n        \"env_add_path\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"env_set\": {\r\n            \"type\": \"object\"\r\n        },\r\n        \"extract_dir\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"extract_to\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"hash\": {\r\n            \"$ref\": \"#/definitions/hash\"\r\n        },\r\n        \"homepage\": {\r\n            \"format\": \"uri\",\r\n            \"type\": \"string\"\r\n        },\r\n        \"innosetup\": {\r\n            \"description\": \"True if the installer InnoSetup based. Found in https://github.com/ScoopInstaller/Main/search?l=JSON&q=innosetup\",\r\n            \"type\": \"boolean\"\r\n        },\r\n        \"installer\": {\r\n            \"$ref\": \"#/definitions/installer\"\r\n        },\r\n        \"license\": {\r\n            \"$ref\": \"#/definitions/license\"\r\n        },\r\n        \"notes\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"post_install\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"post_uninstall\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"pre_install\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"pre_uninstall\": {\r\n            \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n        },\r\n        \"psmodule\": {\r\n            \"additionalProperties\": false,\r\n            \"properties\": {\r\n                \"name\": {\r\n                    \"type\": \"string\"\r\n                }\r\n            },\r\n            \"type\": \"object\"\r\n        },\r\n        \"shortcuts\": {\r\n            \"$ref\": \"#/definitions/shortcutsArray\"\r\n        },\r\n        \"suggest\": {\r\n            \"additionalProperties\": false,\r\n            \"patternProperties\": {\r\n                \"^(.*)$\": {\r\n                    \"$ref\": \"#/definitions/stringOrArrayOfStrings\"\r\n                }\r\n            },\r\n            \"type\": \"object\"\r\n        },\r\n        \"uninstaller\": {\r\n            \"$ref\": \"#/definitions/uninstaller\"\r\n        },\r\n        \"url\": {\r\n            \"$ref\": \"#/definitions/uriOrArrayOfUris\"\r\n        },\r\n        \"version\": {\r\n            \"pattern\": \"^[\\\\w\\\\.\\\\-+_]+$\",\r\n            \"type\": \"string\"\r\n        }\r\n    },\r\n    \"if\": {\r\n        \"properties\": {\r\n            \"architecture\": {\r\n                \"properties\": {\r\n                    \"64bit\": {\r\n                        \"properties\": {\r\n                            \"url\": false\r\n                        }\r\n                    },\r\n                    \"32bit\": {\r\n                        \"properties\": {\r\n                            \"url\": false\r\n                        }\r\n                    },\r\n                    \"arm64\": {\r\n                        \"properties\": {\r\n                            \"url\": false\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    },\r\n    \"then\": {\r\n        \"required\": [\r\n            \"url\"\r\n        ]\r\n    },\r\n    \"required\": [\r\n        \"version\",\r\n        \"homepage\",\r\n        \"license\"\r\n    ],\r\n    \"title\": \"scoop app manifest schema\",\r\n    \"type\": \"object\"\r\n}\r\n"
  },
  {
    "path": "supporting/formats/ScoopTypes.Format.ps1xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Configuration>\r\n    <ViewDefinitions>\r\n        <View>\r\n            <Name>ScoopAppsType</Name>\r\n            <ViewSelectedBy>\r\n                <TypeName>ScoopApps</TypeName>\r\n            </ViewSelectedBy>\r\n            <TableControl>\r\n                <TableRowEntries>\r\n                    <TableRowEntry>\r\n                        <TableColumnItems>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Name</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Version</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Source</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Updated</PropertyName>\r\n                                <FormatString>yyyy-MM-dd HH:mm:ss</FormatString>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Info</PropertyName>\r\n                            </TableColumnItem>\r\n                        </TableColumnItems>\r\n                    </TableRowEntry>\r\n                </TableRowEntries>\r\n            </TableControl>\r\n        </View>\r\n        <View>\r\n            <Name>ScoopShimsType</Name>\r\n            <ViewSelectedBy>\r\n                <TypeName>ScoopShims</TypeName>\r\n            </ViewSelectedBy>\r\n            <TableControl>\r\n                <TableRowEntries>\r\n                    <TableRowEntry>\r\n                        <TableColumnItems>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Name</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Source</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Alternatives</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>IsGlobal</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>IsHidden</PropertyName>\r\n                            </TableColumnItem>\r\n                        </TableColumnItems>\r\n                    </TableRowEntry>\r\n                </TableRowEntries>\r\n            </TableControl>\r\n        </View>\r\n        <View>\r\n            <Name>ScoopStatusType</Name>\r\n            <ViewSelectedBy>\r\n                <TypeName>ScoopStatus</TypeName>\r\n            </ViewSelectedBy>\r\n            <TableControl>\r\n                <TableRowEntries>\r\n                    <TableRowEntry>\r\n                        <TableColumnItems>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Name</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Installed Version</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Latest Version</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Missing Dependencies</PropertyName>\r\n                            </TableColumnItem>\r\n                            <TableColumnItem>\r\n                                <PropertyName>Info</PropertyName>\r\n                            </TableColumnItem>\r\n                        </TableColumnItems>\r\n                    </TableRowEntry>\r\n                </TableRowEntries>\r\n            </TableControl>\r\n        </View>\r\n    </ViewDefinitions>\r\n</Configuration>\r\n"
  },
  {
    "path": "supporting/shims/71/checksum.sha256",
    "content": "70d4690b8ac3b3f715f537cdea6e07a39fda4bc0347bf6b958e4f3ff2f0e04d4  shim.exe\r\n"
  },
  {
    "path": "supporting/shims/71/checksum.sha512",
    "content": "ecde07b32192846c4885cf4d2208eedc170765ea115ae49b81509fed0ce474e21064100bb2f3d815ee79f1c12463d32ef013d4182647eae71855cd18e4196176  shim.exe\r\n"
  },
  {
    "path": "supporting/shims/kiennq/checksum.sha256",
    "content": "140e3801d8adeda639a21b14e62b93a4c7d26b7a758421f43c82be59753be49b *shim.exe\r\n"
  },
  {
    "path": "supporting/shims/kiennq/checksum.sha512",
    "content": "59d9da9f9714003b915bcafbe1b41f53b121dde206ecc23984f62273e957766eece8d64ffc53011c328d3a2ad627aa0f4f7c39bbec8e7b64d0d2ee7b7e771423 *shim.exe\r\n"
  },
  {
    "path": "supporting/shims/kiennq/version.txt",
    "content": "v3.1.2\r\n"
  },
  {
    "path": "supporting/shims/scoopcs/checksum.sha256",
    "content": "0116068768fc992fc536738396b33db3dafe6b0cf0e6f54f6d1aa8b0331f3cec *shim.exe\r\n"
  },
  {
    "path": "supporting/shims/scoopcs/checksum.sha512",
    "content": "d734c528e9f20581ed3c7aa71a458f7dff7e2780fa0c319ccb9c813cd8dbf656bd7e550b81d2aa3ee8775bff9a4e507bc0b25f075697405adca0f47d37835848 *shim.exe\r\n"
  },
  {
    "path": "supporting/shims/scoopcs/version.txt",
    "content": "1.1.0\r\n"
  },
  {
    "path": "supporting/validator/.gitignore",
    "content": "packages/\r\n"
  },
  {
    "path": "supporting/validator/Scoop.Validator.cs",
    "content": "using System;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Text;\r\nusing Newtonsoft.Json;\r\nusing Newtonsoft.Json.Linq;\r\nusing Newtonsoft.Json.Schema;\r\n\r\nnamespace Scoop\r\n{\r\n    public class JsonParserException : Exception\r\n    {\r\n        public string FileName { get; set; }\r\n        public JsonParserException(string file, string message) : base(message) { this.FileName = file; }\r\n        public JsonParserException(string file, string message, Exception inner) : base(message, inner) { this.FileName = file; }\r\n    }\r\n\r\n    public class Validator\r\n    {\r\n        private bool CI { get; set; }\r\n        public JSchema Schema { get; private set; }\r\n        public FileInfo SchemaFile { get; private set; }\r\n        public JObject Manifest { get; private set; }\r\n        public FileInfo ManifestFile { get; private set; }\r\n        public IList<string> Errors { get; private set; }\r\n        public string ErrorsAsString\r\n        {\r\n            get\r\n            {\r\n                return String.Join(System.Environment.NewLine, this.Errors);\r\n            }\r\n        }\r\n\r\n        private JSchema ParseSchema(string file)\r\n        {\r\n            try\r\n            {\r\n                return JSchema.Parse(File.ReadAllText(file, System.Text.Encoding.UTF8));\r\n            }\r\n            catch (Newtonsoft.Json.JsonReaderException e)\r\n            {\r\n                throw new JsonParserException(Path.GetFileName(file), e.Message, e);\r\n            }\r\n            catch (FileNotFoundException e)\r\n            {\r\n                throw e;\r\n            }\r\n        }\r\n\r\n        private JObject ParseManifest(string file)\r\n        {\r\n            try\r\n            {\r\n                return JObject.Parse(File.ReadAllText(file, System.Text.Encoding.UTF8));\r\n            }\r\n            catch (Newtonsoft.Json.JsonReaderException e)\r\n            {\r\n                throw new JsonParserException(Path.GetFileName(file), e.Message, e);\r\n            }\r\n            catch (FileNotFoundException e)\r\n            {\r\n                throw e;\r\n            }\r\n        }\r\n\r\n        public Validator(string schemaFile)\r\n        {\r\n            this.SchemaFile = new FileInfo(schemaFile);\r\n            this.Errors = new List<string>();\r\n        }\r\n\r\n        public Validator(string schemaFile, bool ci)\r\n        {\r\n            this.SchemaFile = new FileInfo(schemaFile);\r\n            this.Errors = new List<string>();\r\n            this.CI = ci;\r\n        }\r\n\r\n        public bool Validate(string file)\r\n        {\r\n            this.ManifestFile = new FileInfo(file);\r\n            return this.Validate();\r\n        }\r\n\r\n        public bool Validate()\r\n        {\r\n            if (!this.SchemaFile.Exists)\r\n            {\r\n                Console.WriteLine(\"ERROR: Please provide schema.json!\");\r\n                return false;\r\n            }\r\n            if (!this.ManifestFile.Exists)\r\n            {\r\n                Console.WriteLine(\"ERROR: Please provide manifest.json!\");\r\n                return false;\r\n            }\r\n            this.Errors.Clear();\r\n            try\r\n            {\r\n                if (this.Schema == null)\r\n                {\r\n                    this.Schema = this.ParseSchema(this.SchemaFile.FullName);\r\n                }\r\n                this.Manifest = this.ParseManifest(this.ManifestFile.FullName);\r\n            }\r\n            catch (FileNotFoundException e)\r\n            {\r\n                this.Errors.Add(e.Message);\r\n            }\r\n            catch (JsonParserException e)\r\n            {\r\n                this.Errors.Add(String.Format(\"{0}{1}: {2}\", (this.CI ? \"    [*] \" : \"\"), e.FileName, e.Message));\r\n            }\r\n\r\n            if (this.Schema == null || this.Manifest == null)\r\n                return false;\r\n\r\n            IList<ValidationError> validationErrors = new List<ValidationError>();\r\n\r\n            this.Manifest.IsValid(this.Schema, out validationErrors);\r\n\r\n            if (validationErrors.Count == 0)\r\n            {\r\n                return true;\r\n            }\r\n            traverseErrors(validationErrors, this.CI ? 3 : 1);\r\n\r\n            return (this.Errors.Count == 0);\r\n        }\r\n\r\n        public void traverseErrors(IList<ValidationError> errors, int level = 1) {\r\n            if(errors == null) {\r\n                return;\r\n            }\r\n            foreach (ValidationError error in errors)\r\n            {\r\n                StringBuilder sb = new StringBuilder();\r\n                sb.Insert(sb.Length, \" \", level * 2);\r\n                sb.Insert(sb.Length, this.CI ? \"[*] \" : \"- \");\r\n                sb.AppendFormat(\"Error: {0}\\n\", error.Message);\r\n\r\n                sb.Insert(sb.Length, \" \", level * 2);\r\n                sb.Insert(sb.Length, this.CI ? \"  [^] \" : \"  \");\r\n                sb.AppendFormat(\"Line: {0}:{1}:{2}\\n\", this.ManifestFile.FullName, error.LineNumber, error.LinePosition);\r\n\r\n                sb.Insert(sb.Length, \" \", level * 2);\r\n                sb.Insert(sb.Length, this.CI ? \"  [^] \" : \"  \");\r\n                sb.AppendFormat(\"Path: {0}/{1}\", error.SchemaId, error.ErrorType);\r\n\r\n                if(!this.CI) {\r\n                    sb.Insert(sb.Length, \"\\n\");\r\n                }\r\n\r\n                this.Errors.Add(sb.ToString());\r\n\r\n                if(error.ChildErrors != null || error.ChildErrors.Count > 0) {\r\n                    traverseErrors(error.ChildErrors, level + 1);\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "supporting/validator/bin/checksum.sha256",
    "content": "e1e27af7b07eeedf5ce71a9255f0422816a6fc5849a483c6714e1b472044fa9d *Newtonsoft.Json.dll\r\n7496d5349a123a6e3696085662b2ff17b156ccdb0e30e0c396ac72d2da36ce1c *Newtonsoft.Json.Schema.dll\r\n83b1006443e8c340ca4c631614fc2ce0d5cb9a28c851e3b59724299f58b1397f *Scoop.Validator.dll\r\n87f8f8db2202a3fbef6f431d0b7e20cec9d32095c441927402041f3c4076c1b6 *validator.exe\r\n"
  },
  {
    "path": "supporting/validator/bin/checksum.sha512",
    "content": "56eb7f070929b239642dab729537dde2c2287bdb852ad9e80b5358c74b14bc2b2dded910d0e3b6304ea27eb587e5f19db0a92e1cbae6a70fb20b4ef05057e4ac *Newtonsoft.Json.dll\r\n78b12beb1e67ac4f6efa0fcba57b4b34ea6a31d8b369934d6b6a6617386ef9939ea453ac262916e5857ce0359eb809424ea33c676a87a8fdfd77a59b2ce96db0 *Newtonsoft.Json.Schema.dll\r\ne9da4370aee4df47eedcf15d9749712eee513e5a9115b808617ddfcfde5bc47a0410edfb57508fcf51033c0be967611b2fd2c2ba944de7290c020cc67f77ac57 *Scoop.Validator.dll\r\n58a0c37e98cac17822c7756bf6686a5fb74e711b8d986d13bd2f689f6b3b1f485fcd908d92cbc6a162a0e5974c2c5a43de57d15f1996be0aa405e41ec2ec8393 *validator.exe\r\n"
  },
  {
    "path": "supporting/validator/build.ps1",
    "content": "Param([Switch]$Fast)\r\nPush-Location $PSScriptRoot\r\n. \"$PSScriptRoot\\..\\..\\lib\\core.ps1\"\r\n. \"$PSScriptRoot\\..\\..\\lib\\install.ps1\"\r\n\r\nif (!$Fast) {\r\n    Write-Host 'Install dependencies ...'\r\n    & \"$PSScriptRoot\\install.ps1\"\r\n}\r\n\r\n$output = \"$PSScriptRoot\\bin\"\r\nif (!$Fast) {\r\n    Get-ChildItem \"$PSScriptRoot\\packages\\Newtonsoft.*\\lib\\net45\\*.dll\" -File | ForEach-Object { Copy-Item $_ $output }\r\n}\r\nWrite-Output 'Compiling Scoop.Validator.cs ...'\r\n& \"$PSScriptRoot\\packages\\Microsoft.Net.Compilers.Toolset\\tasks\\net472\\csc.exe\" -deterministic -platform:anycpu -nologo -optimize -target:library -reference:\"$output\\Newtonsoft.Json.dll\" -reference:\"$output\\Newtonsoft.Json.Schema.dll\" -out:\"$output\\Scoop.Validator.dll\" Scoop.Validator.cs\r\nWrite-Output 'Compiling validator.cs ...'\r\n& \"$PSScriptRoot\\packages\\Microsoft.Net.Compilers.Toolset\\tasks\\net472\\csc.exe\" -deterministic -platform:anycpu -nologo -optimize -target:exe -reference:\"$output\\Scoop.Validator.dll\" -reference:\"$output\\Newtonsoft.Json.dll\" -reference:\"$output\\Newtonsoft.Json.Schema.dll\" -out:\"$output\\validator.exe\" validator.cs\r\n\r\nWrite-Output 'Computing checksums ...'\r\nRemove-Item \"$PSScriptRoot\\bin\\checksum.sha256\" -ErrorAction Ignore\r\nRemove-Item \"$PSScriptRoot\\bin\\checksum.sha512\" -ErrorAction Ignore\r\nGet-ChildItem \"$PSScriptRoot\\bin\\*\" -Include *.exe, *.dll | ForEach-Object {\r\n    \"$((Get-FileHash -Path $_ -Algorithm SHA256).Hash.ToLower()) *$($_.Name)\" | Out-File \"$PSScriptRoot\\bin\\checksum.sha256\" -Append -Encoding oem\r\n    \"$((Get-FileHash -Path $_ -Algorithm SHA512).Hash.ToLower()) *$($_.Name)\" | Out-File \"$PSScriptRoot\\bin\\checksum.sha512\" -Append -Encoding oem\r\n}\r\nPop-Location\r\n"
  },
  {
    "path": "supporting/validator/install.ps1",
    "content": "# https://github.com/edymtt/nugetstandalone\r\n$destinationFolder = \"$PSScriptRoot\\packages\"\r\nif ((Test-Path -Path $destinationFolder)) {\r\n    Remove-Item -Path $destinationFolder -Recurse | Out-Null\r\n}\r\n\r\nNew-Item $destinationFolder -Type Directory | Out-Null\r\nnuget install packages.config -o $destinationFolder -ExcludeVersion\r\n"
  },
  {
    "path": "supporting/validator/packages.config",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<packages>\r\n    <package id=\"Newtonsoft.Json\" version=\"13.0.3\" targetFramework=\"net45\" />\r\n    <package id=\"Newtonsoft.Json.Schema\" version=\"4.0.1\" targetFramework=\"net45\" />\r\n    <package id=\"Microsoft.Net.Compilers.Toolset\" version=\"4.10.0\" targetFramework=\"net45\"\r\n        developmentDependency=\"true\" />\r\n</packages>\r\n"
  },
  {
    "path": "supporting/validator/update.ps1",
    "content": "# https://github.com/edymtt/nugetstandalone\r\n$destinationFolder = \"$PSScriptRoot\\packages\"\r\nif (!(Test-Path -Path $destinationFolder)) {\r\n    Write-Host -f Red \"Run .\\install.ps1 first!\"\r\n    exit 1\r\n}\r\n\r\nnuget update packages.config -r $destinationFolder\r\nRemove-Item $destinationFolder -Force -Recurse | Out-Null\r\nnuget install packages.config -o $destinationFolder -ExcludeVersion\r\n"
  },
  {
    "path": "supporting/validator/validator.cs",
    "content": "using System;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Linq;\r\n\r\nnamespace Scoop\r\n{\r\n    public class Program\r\n    {\r\n        public static int Main(string[] args)\r\n        {\r\n            bool ci = String.Format(\"{0}\", Environment.GetEnvironmentVariable(\"CI\")).ToLower() == \"true\";\r\n            bool valid = true;\r\n\r\n            if (args.Length < 2)\r\n            {\r\n                Console.WriteLine(\"Usage: validator.exe <schema> <manifest> [<manifest>...]\");\r\n                return 1;\r\n            }\r\n\r\n\r\n            IList<string> manifests = args.ToList<String>();\r\n            String schema = manifests.First();\r\n            manifests.RemoveAt(0);\r\n            String combinedArgs = String.Join(\"\", manifests);\r\n            if(combinedArgs.Contains(\"*\") || combinedArgs.Contains(\"?\")) {\r\n                try {\r\n                    var path = new Uri(Path.Combine(Directory.GetCurrentDirectory(), combinedArgs)).LocalPath;\r\n                    var drive = Path.GetPathRoot(path);\r\n                    var pattern = path.Replace(drive, \"\");\r\n                    manifests = Directory.GetFiles(drive, pattern).ToList<String>();\r\n                } catch (System.ArgumentException ex) {\r\n                    Console.WriteLine(\"Invalid path provided! ({0})\", ex.Message);\r\n                    return 1;\r\n                }\r\n            }\r\n\r\n            Scoop.Validator validator = new Scoop.Validator(schema, ci);\r\n            foreach(var manifest in manifests) {\r\n                if (validator.Validate(manifest))\r\n                {\r\n                    if(ci) {\r\n                        Console.WriteLine(\"      [+] {0} validates against the schema!\", Path.GetFileName(manifest));\r\n                    } else {\r\n                        Console.WriteLine(\"- {0} validates against the schema!\", Path.GetFileName(manifest));\r\n                    }\r\n                }\r\n                else\r\n                {\r\n                    if(ci) {\r\n                        Console.WriteLine(\"      [-] {0} has {1} Error{2}!\", Path.GetFileName(manifest), validator.Errors.Count, validator.Errors.Count > 1 ? \"s\" : \"\");\r\n                    } else {\r\n                        Console.WriteLine(\"- {0} has {1} Error{2}!\", Path.GetFileName(manifest), validator.Errors.Count, validator.Errors.Count > 1 ? \"s\" : \"\");\r\n                    }\r\n                    valid = false;\r\n                    foreach (var error in validator.Errors)\r\n                    {\r\n                        Console.WriteLine(error);\r\n                    }\r\n                }\r\n            }\r\n\r\n            return valid ? 0 : 1;\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "supporting/validator/validator.csproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"15.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n    <Import\r\n        Project=\"packages\\Microsoft.Net.Compilers.Toolset.4.10.0\\build\\Microsoft.Net.Compilers.Toolset.props\"\r\n        Condition=\"Exists('packages\\Microsoft.Net.Compilers.Toolset.4.10.0\\build\\Microsoft.Net.Compilers.Toolset.props')\" />\r\n    <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\"\r\n        Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />\r\n    <PropertyGroup>\r\n        <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>\r\n        <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>\r\n        <ProjectGuid>{8EB9B38A-1BAB-4D89-B4CB-ACE5E7C1073B}</ProjectGuid>\r\n        <OutputType>Exe</OutputType>\r\n        <RootNamespace>Scoop.Validator</RootNamespace>\r\n        <AssemblyName>Scoop.Validator</AssemblyName>\r\n        <TargetFrameworkVersion>v4.5.0</TargetFrameworkVersion>\r\n        <FileAlignment>512</FileAlignment>\r\n        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>\r\n    </PropertyGroup>\r\n    <ItemGroup>\r\n        <Reference\r\n            Include=\"Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed\">\r\n            <HintPath>packages\\Newtonsoft.Json.13.0.3\\lib\\net45\\Newtonsoft.Json.dll</HintPath>\r\n            <Private>True</Private>\r\n        </Reference>\r\n        <Reference\r\n            Include=\"Newtonsoft.Json.Schema, Version=4.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed\">\r\n            <HintPath>packages\\Newtonsoft.Json.Schema.4.0.1\\lib\\net45\\Newtonsoft.Json.Schema.dll</HintPath>\r\n            <Private>True</Private>\r\n        </Reference>\r\n        <Reference Include=\"System\" />\r\n        <Reference Include=\"System.Core\" />\r\n        <Reference Include=\"System.Xml.Linq\" />\r\n        <Reference Include=\"System.Data.DataSetExtensions\" />\r\n        <Reference Include=\"Microsoft.CSharp\" />\r\n        <Reference Include=\"System.Data\" />\r\n        <Reference Include=\"System.Net.Http\" />\r\n        <Reference Include=\"System.Xml\" />\r\n    </ItemGroup>\r\n    <ItemGroup>\r\n        <Compile Include=\"validator.cs\" />\r\n        <Compile Include=\"Scoop.Validator.cs\" />\r\n    </ItemGroup>\r\n    <ItemGroup>\r\n        <None Include=\"packages.config\" />\r\n    </ItemGroup>\r\n    <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />\r\n    <Target Name=\"EnsureNuGetPackageBuildImports\" BeforeTargets=\"PrepareForBuild\">\r\n        <PropertyGroup>\r\n            <ErrorText>This project references NuGet package(s) that are missing on this computer.\r\n                Enable NuGet Package Restore to download them. For more information, see\r\n                http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>\r\n        </PropertyGroup>\r\n        <Error\r\n            Condition=\"!Exists('packages\\Microsoft.Net.Compilers.Toolset.4.10.0\\build\\Microsoft.Net.Compilers.Toolset.props')\"\r\n            Text=\"$([System.String]::Format('$(ErrorText)', 'packages\\Microsoft.Net.Compilers.Toolset.4.10.0\\build\\Microsoft.Net.Compilers.Toolset.props'))\" />\r\n    </Target>\r\n</Project>\r\n"
  },
  {
    "path": "test/Import-Bucket-Tests.ps1",
    "content": "#Requires -Version 5.1\r\n#Requires -Modules @{ ModuleName = 'BuildHelpers'; ModuleVersion = '2.0.1' }\r\n#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.2.0' }\r\nparam(\r\n    [String] $BucketPath = $MyInvocation.PSScriptRoot\r\n)\r\n\r\n. \"$PSScriptRoot\\Scoop-00File.Tests.ps1\" -TestPath $BucketPath\r\n\r\nDescribe 'Manifest validates against the schema' {\r\n    BeforeDiscovery {\r\n        $bucketDir = if (Test-Path \"$BucketPath\\bucket\") {\r\n            \"$BucketPath\\bucket\"\r\n        } else {\r\n            $BucketPath\r\n        }\r\n        if ($env:CI -eq $true) {\r\n            Set-BuildEnvironment -Force\r\n            $manifestFiles = @(Get-GitChangedFile -Path $bucketDir -Include '*.json' -Commit $env:BHCommitHash)\r\n        } else {\r\n            $manifestFiles = (Get-ChildItem $bucketDir -Filter '*.json' -Recurse).FullName\r\n        }\r\n    }\r\n    BeforeAll {\r\n        Add-Type -Path \"$PSScriptRoot\\..\\supporting\\validator\\bin\\Scoop.Validator.dll\"\r\n        # Could not use backslash '\\' in Linux/macOS for .NET object 'Scoop.Validator'\r\n        $validator = New-Object Scoop.Validator(\"$PSScriptRoot/../schema.json\", $true)\r\n        $global:quotaExceeded = $false\r\n    }\r\n    It '<_>' -TestCases $manifestFiles {\r\n        if ($global:quotaExceeded) {\r\n            Set-ItResult -Skipped -Because 'Schema validation limit exceeded.'\r\n        } else {\r\n            $file = $_ # exception handling may overwrite $_\r\n            try {\r\n                $validator.Validate($file)\r\n                if ($validator.Errors.Count -gt 0) {\r\n                    Write-Host \"  [-] $_ has $($validator.Errors.Count) Error$(If($validator.Errors.Count -gt 1) { 's' })!\" -ForegroundColor Red\r\n                    Write-Host $validator.ErrorsAsString -ForegroundColor Yellow\r\n                }\r\n                $validator.Errors.Count | Should -Be 0\r\n            } catch {\r\n                if ($_.Exception.Message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') {\r\n                    $global:quotaExceeded = $true\r\n                    Set-ItResult -Skipped -Because 'Schema validation limit exceeded.'\r\n                } else {\r\n                    throw\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-00File.Tests.ps1",
    "content": "param(\r\n    [String] $TestPath = \"$PSScriptRoot\\..\"\r\n)\r\n\r\nBeforeDiscovery {\r\n    $project_file_exclusions = @(\r\n        '[\\\\/]\\.git[\\\\/]',\r\n        '\\.sublime-workspace$',\r\n        '\\.DS_Store$',\r\n        'supporting(\\\\|/)validator(\\\\|/)packages(\\\\|/)*'\r\n    )\r\n    $repo_files = (Get-ChildItem $TestPath -File -Recurse).FullName |\r\n        Where-Object { $_ -inotmatch $($project_file_exclusions -join '|') }\r\n}\r\n\r\nDescribe 'Code Syntax' -ForEach @(, $repo_files) -Tag 'File' {\r\n    BeforeAll {\r\n        $files = @(\r\n            $_ | Where-Object { $_ -imatch '.(ps1|psm1)$' }\r\n        )\r\n        function Test-PowerShellSyntax {\r\n            # ref: http://powershell.org/wp/forums/topic/how-to-check-syntax-of-scripts-automatically @@ https://archive.is/xtSv6\r\n            # originally created by Alexander Petrovskiy & Dave Wyatt\r\n            [CmdletBinding()]\r\n            param (\r\n                [Parameter(Mandatory = $true, ValueFromPipeline = $true)]\r\n                [string[]]\r\n                $Path\r\n            )\r\n\r\n            process {\r\n                foreach ($scriptPath in $Path) {\r\n                    $contents = Get-Content -Path $scriptPath\r\n\r\n                    if ($null -eq $contents) {\r\n                        continue\r\n                    }\r\n\r\n                    $errors = $null\r\n                    $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)\r\n\r\n                    New-Object psobject -Property @{\r\n                        Path              = $scriptPath\r\n                        SyntaxErrorsFound = ($errors.Count -gt 0)\r\n                    }\r\n                }\r\n            }\r\n        }\r\n\r\n    }\r\n\r\n    It 'PowerShell code files do not contain syntax errors' {\r\n        $badFiles = @(\r\n            foreach ($file in $files) {\r\n                if ( (Test-PowerShellSyntax $file).SyntaxErrorsFound ) {\r\n                    $file\r\n                }\r\n            }\r\n        )\r\n\r\n        if ($badFiles.Count -gt 0) {\r\n            throw \"The following files have syntax errors: `r`n`r`n$($badFiles -join \"`r`n\")\"\r\n        }\r\n    }\r\n\r\n}\r\n\r\nDescribe 'Style constraints for non-binary project files' -ForEach @(, $repo_files) -Tag 'File' {\r\n    BeforeAll {\r\n        $files = @(\r\n            # gather all files except '*.exe', '*.zip', or any .git repository files\r\n            $_ |\r\n                Where-Object { $_ -inotmatch '(.exe|.zip|.dll)$' } |\r\n                Where-Object { $_ -inotmatch '(unformatted)' }\r\n        )\r\n    }\r\n\r\n    It 'files do not contain leading UTF-8 BOM' {\r\n        # UTF-8 BOM == 0xEF 0xBB 0xBF\r\n        # see http://www.powershellmagazine.com/2012/12/17/pscxtip-how-to-determine-the-byte-order-mark-of-a-text-file @@ https://archive.is/RgT42\r\n        # ref: http://poshcode.org/2153 @@ https://archive.is/sGnnu\r\n        $badFiles = @(\r\n            foreach ($file in $files) {\r\n                if ((Get-Command Get-Content).parameters.ContainsKey('AsByteStream')) {\r\n                    # PowerShell Core (6.0+) '-Encoding byte' is replaced by '-AsByteStream'\r\n                    $content = ([char[]](Get-Content $file -AsByteStream -TotalCount 3) -join '')\r\n                } else {\r\n                    $content = ([char[]](Get-Content $file -Encoding byte -TotalCount 3) -join '')\r\n                }\r\n                if ([regex]::match($content, '(?ms)^\\xEF\\xBB\\xBF').success) {\r\n                    $file\r\n                }\r\n            }\r\n        )\r\n\r\n        if ($badFiles.Count -gt 0) {\r\n            throw \"The following files have utf-8 BOM: `r`n`r`n$($badFiles -join \"`r`n\")\"\r\n        }\r\n    }\r\n\r\n    It 'files end with a newline' {\r\n        $badFiles = @(\r\n            foreach ($file in $files) {\r\n                # Ignore previous TestResults.xml\r\n                if ($file -match 'TestResults.xml') {\r\n                    continue\r\n                }\r\n                $string = [System.IO.File]::ReadAllText($file)\r\n                if ($string.Length -gt 0 -and $string[-1] -ne \"`n\") {\r\n                    $file\r\n                }\r\n            }\r\n        )\r\n\r\n        if ($badFiles.Count -gt 0) {\r\n            throw \"The following files do not end with a newline: `r`n`r`n$($badFiles -join \"`r`n\")\"\r\n        }\r\n    }\r\n\r\n    It 'file newlines are CRLF' {\r\n        $badFiles = @(\r\n            foreach ($file in $files) {\r\n                $content = [System.IO.File]::ReadAllText($file)\r\n                if (!$content) {\r\n                    throw \"File contents are null: $($file)\"\r\n                }\r\n                $lines = [regex]::split($content, '\\r\\n')\r\n                $lineCount = $lines.Count\r\n\r\n                for ($i = 0; $i -lt $lineCount; $i++) {\r\n                    if ( [regex]::match($lines[$i], '\\r|\\n').success ) {\r\n                        $file\r\n                        break\r\n                    }\r\n                }\r\n            }\r\n        )\r\n\r\n        if ($badFiles.Count -gt 0) {\r\n            throw \"The following files have non-CRLF line endings: `r`n`r`n$($badFiles -join \"`r`n\")\"\r\n        }\r\n    }\r\n\r\n    It 'files have no lines containing trailing whitespace' {\r\n        $badLines = @(\r\n            foreach ($file in $files) {\r\n                # Ignore previous TestResults.xml\r\n                if ($file -match 'TestResults.xml') {\r\n                    continue\r\n                }\r\n                $lines = [System.IO.File]::ReadAllLines($file)\r\n                $lineCount = $lines.Count\r\n\r\n                for ($i = 0; $i -lt $lineCount; $i++) {\r\n                    if ($lines[$i] -match '\\s+$') {\r\n                        'File: {0}, Line: {1}' -f $file, ($i + 1)\r\n                    }\r\n                }\r\n            }\r\n        )\r\n\r\n        if ($badLines.Count -gt 0) {\r\n            throw \"The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join \"`r`n\")\"\r\n        }\r\n    }\r\n\r\n    It 'any leading whitespace consists only of spaces (excepting makefiles)' {\r\n        $badLines = @(\r\n            foreach ($file in $files) {\r\n                if ($file -inotmatch '(^|.)makefile$') {\r\n                    $lines = [System.IO.File]::ReadAllLines($file)\r\n                    $lineCount = $lines.Count\r\n\r\n                    for ($i = 0; $i -lt $lineCount; $i++) {\r\n                        if ($lines[$i] -notmatch '^[ ]*(\\S|$)') {\r\n                            'File: {0}, Line: {1}' -f $file, ($i + 1)\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        )\r\n\r\n        if ($badLines.Count -gt 0) {\r\n            throw \"The following $($badLines.Count) lines contain TABs within leading whitespace: `r`n`r`n$($badLines -join \"`r`n\")\"\r\n        }\r\n    }\r\n\r\n}\r\n"
  },
  {
    "path": "test/Scoop-00Linting.Tests.ps1",
    "content": "Describe 'PSScriptAnalyzer' -Tag 'Linter' {\r\n    BeforeDiscovery {\r\n        $scriptDir = @('.', 'bin', 'lib', 'libexec', 'test')\r\n    }\r\n\r\n    BeforeAll {\r\n        $lintSettings = \"$PSScriptRoot\\..\\PSScriptAnalyzerSettings.psd1\"\r\n    }\r\n\r\n    It 'PSScriptAnalyzerSettings.ps1 should exist' {\r\n        $lintSettings | Should -Exist\r\n    }\r\n\r\n    Context 'Linting all *.psd1, *.psm1 and *.ps1 files' {\r\n        BeforeEach {\r\n            $analysis = Invoke-ScriptAnalyzer -Path \"$PSScriptRoot\\..\\$_\" -Settings $lintSettings\r\n        }\r\n        It 'Should pass: <_>' -TestCases $scriptDir {\r\n            $analysis | Should -HaveCount 0\r\n            if ($analysis) {\r\n                foreach ($result in $analysis) {\r\n                    switch -wildCard ($result.ScriptName) {\r\n                        '*.psm1' { $type = 'Module' }\r\n                        '*.ps1' { $type = 'Script' }\r\n                        '*.psd1' { $type = 'Manifest' }\r\n                    }\r\n                    Write-Warning \"     [*] $($result.Severity): $($result.Message)\"\r\n                    Write-Warning \"         $($result.RuleName) in $type`: $directory\\$($result.ScriptName):$($result.Line)\"\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Commands.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\commands.ps1\"\r\n}\r\n\r\nDescribe 'Manipulate Alias' -Tag 'Scoop' {\r\n    BeforeAll {\r\n        Mock shimdir { \"$TestDrive\\shims\" }\r\n        Mock set_config {}\r\n        Mock get_config { @{} }\r\n\r\n        $shimdir = shimdir\r\n        ensure $shimdir\r\n    }\r\n\r\n    It 'Creates a new alias if it does not exist' {\r\n        $alias_script = \"$shimdir\\scoop-rm.ps1\"\r\n        $alias_script | Should -Not -Exist\r\n\r\n        add_alias 'rm' '\"hello, world!\"'\r\n        & $alias_script | Should -Be 'hello, world!'\r\n    }\r\n\r\n    It 'Skips an existing alias' {\r\n        $alias_script = \"$shimdir\\scoop-rm.ps1\"\r\n        Mock abort {}\r\n        New-Item $alias_script -Type File -Force\r\n        $alias_script | Should -Exist\r\n\r\n        add_alias 'rm' '\"test\"'\r\n        Should -Invoke -CommandName abort -Times 1 -ParameterFilter { $msg -eq \"File 'scoop-rm.ps1' already exists in shims directory.\" }\r\n    }\r\n\r\n    It 'Removes an existing alias' {\r\n        $alias_script = \"$shimdir\\scoop-rm.ps1\"\r\n        $alias_script | Should -Exist\r\n        Mock get_config { @(@{'rm' = 'scoop-rm' }) }\r\n        Mock info {}\r\n\r\n        rm_alias 'rm'\r\n        $alias_script | Should -Not -Exist\r\n        Should -Invoke -CommandName info -Times 1 -ParameterFilter { $msg -eq \"Removing alias 'rm'...\" }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Config.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n}\r\n\r\nDescribe 'config' -Tag 'Scoop' {\r\n    BeforeAll {\r\n        $configFile = [IO.Path]::GetTempFileName()\r\n        $unicode = [Regex]::Unescape('\\u4f60\\u597d\\u3053\\u3093\\u306b\\u3061\\u306f') # 你好こんにちは\r\n    }\r\n\r\n    AfterAll {\r\n        Remove-Item -Path $configFile -Force\r\n    }\r\n\r\n    It 'load_cfg should return null if config file does not exist' {\r\n        load_cfg $configFile | Should -Be $null\r\n    }\r\n\r\n    It 'set_config should be able to save typed values correctly' {\r\n        # number\r\n        $scoopConfig = set_config 'one' 1\r\n        $scoopConfig.one | Should -BeExactly 1\r\n\r\n        # boolean\r\n        $scoopConfig = set_config 'two' $true\r\n        $scoopConfig.two | Should -BeTrue\r\n        $scoopConfig = set_config 'three' $false\r\n        $scoopConfig.three | Should -BeFalse\r\n\r\n        # underline key\r\n        $scoopConfig = set_config 'under_line' 'four'\r\n        $scoopConfig.under_line | Should -BeExactly 'four'\r\n\r\n        # string\r\n        $scoopConfig = set_config 'five' 'not null'\r\n\r\n        # datetime\r\n        $scoopConfig = set_config 'time' ([System.DateTime]::Parse('2019-03-18T15:22:09.3930000+00:00', $null, [System.Globalization.DateTimeStyles]::AdjustToUniversal))\r\n        $scoopConfig.time | Should -BeOfType [System.DateTime]\r\n\r\n        # non-ASCII\r\n        $scoopConfig = set_config 'unicode' $unicode\r\n        $scoopConfig.unicode | Should -Be $unicode\r\n    }\r\n\r\n    It 'load_cfg should return PSObject if config file exist' {\r\n        $scoopConfig = load_cfg $configFile\r\n        $scoopConfig | Should -Not -BeNullOrEmpty\r\n        $scoopConfig | Should -BeOfType [System.Management.Automation.PSObject]\r\n        $scoopConfig.one | Should -BeExactly 1\r\n        $scoopConfig.two | Should -BeTrue\r\n        $scoopConfig.three | Should -BeFalse\r\n        $scoopConfig.under_line | Should -BeExactly 'four'\r\n        $scoopConfig.five | Should -Be 'not null'\r\n        $scoopConfig.time | Should -BeOfType [System.DateTime]\r\n        $scoopConfig.time | Should -Be ([System.DateTime]::Parse('2019-03-18T15:22:09.3930000+00:00', $null, [System.Globalization.DateTimeStyles]::AdjustToUniversal))\r\n        $scoopConfig.unicode | Should -Be $unicode\r\n    }\r\n\r\n    It 'get_config should return exactly the same values' {\r\n        $scoopConfig = load_cfg $configFile\r\n        (get_config 'one') | Should -BeExactly 1\r\n        (get_config 'two') | Should -BeTrue\r\n        (get_config 'three') | Should -BeFalse\r\n        (get_config 'under_line') | Should -BeExactly 'four'\r\n        (get_config 'five') | Should -Be 'not null'\r\n        (get_config 'time') | Should -BeOfType [System.DateTime]\r\n        (get_config 'time') | Should -Be ([System.DateTime]::Parse('2019-03-18T15:22:09.3930000+00:00', $null, [System.Globalization.DateTimeStyles]::AdjustToUniversal))\r\n        (get_config 'unicode') | Should -Be $unicode\r\n    }\r\n\r\n    It 'set_config should remove a value if being set to $null' {\r\n        $scoopConfig = load_cfg $configFile\r\n        $scoopConfig = set_config 'five' $null\r\n        $scoopConfig.five | Should -BeNullOrEmpty\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Core.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\system.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n}\r\n\r\nDescribe 'Get-AppFilePath' -Tag 'Scoop' {\r\n    BeforeAll {\r\n        $working_dir = setup_working 'is_directory'\r\n        Mock currentdir { 'local' } -Verifiable -ParameterFilter { $global -eq $false }\r\n        Mock currentdir { 'global' } -Verifiable -ParameterFilter { $global -eq $true }\r\n    }\r\n\r\n    It 'should return locally installed program' {\r\n        Mock Test-Path { $true } -Verifiable -ParameterFilter { $Path -eq 'local\\i_am_a_file.txt' }\r\n        Mock Test-Path { $false } -Verifiable -ParameterFilter { $Path -eq 'global\\i_am_a_file.txt' }\r\n        Get-AppFilePath -App 'is_directory' -File 'i_am_a_file.txt' | Should -Be 'local\\i_am_a_file.txt'\r\n    }\r\n\r\n    It 'should return globally installed program' {\r\n        Mock Test-Path { $false } -Verifiable -ParameterFilter { $Path -eq 'local\\i_am_a_file.txt' }\r\n        Mock Test-Path { $true } -Verifiable -ParameterFilter { $Path -eq 'global\\i_am_a_file.txt' }\r\n        Get-AppFilePath -App 'is_directory' -File 'i_am_a_file.txt' | Should -Be 'global\\i_am_a_file.txt'\r\n    }\r\n\r\n    It 'should return null if program is not installed' {\r\n        Get-AppFilePath -App 'is_directory' -File 'i_do_not_exist' | Should -BeNullOrEmpty\r\n    }\r\n\r\n    It 'should throw if parameter is wrong or missing' {\r\n        { Get-AppFilePath -App 'is_directory' -File } | Should -Throw\r\n        { Get-AppFilePath -App -File 'i_am_a_file.txt' } | Should -Throw\r\n        { Get-AppFilePath -App -File } | Should -Throw\r\n    }\r\n}\r\n\r\nDescribe 'Get-HelperPath' -Tag 'Scoop' {\r\n    BeforeAll {\r\n        $working_dir = setup_working 'is_directory'\r\n    }\r\n    It 'should return path if program is installed' {\r\n        Mock Get-AppFilePath { '7zip\\current\\7z.exe' }\r\n        Get-HelperPath -Helper 7zip | Should -Be '7zip\\current\\7z.exe'\r\n    }\r\n\r\n    It 'should return null if program is not installed' {\r\n        Mock Get-AppFilePath { $null }\r\n        Get-HelperPath -Helper 7zip | Should -BeNullOrEmpty\r\n    }\r\n\r\n    It 'should throw if parameter is wrong or missing' {\r\n        { Get-HelperPath -Helper } | Should -Throw\r\n        { Get-HelperPath -Helper Wrong } | Should -Throw\r\n    }\r\n}\r\n\r\n\r\nDescribe 'Test-HelperInstalled' -Tag 'Scoop' {\r\n    It 'should return true if program is installed' {\r\n        Mock Get-HelperPath { '7z.exe' }\r\n        Test-HelperInstalled -Helper 7zip | Should -BeTrue\r\n    }\r\n\r\n    It 'should return false if program is not installed' {\r\n        Mock Get-HelperPath { $null }\r\n        Test-HelperInstalled -Helper 7zip | Should -BeFalse\r\n    }\r\n\r\n    It 'should throw if parameter is wrong or missing' {\r\n        { Test-HelperInstalled -Helper } | Should -Throw\r\n        { Test-HelperInstalled -Helper Wrong } | Should -Throw\r\n    }\r\n}\r\n\r\nDescribe 'Test-CommandAvailable' -Tag 'Scoop' {\r\n    It 'should return true if command exists' {\r\n        Test-CommandAvailable 'Write-Host' | Should -BeTrue\r\n    }\r\n\r\n    It \"should return false if command doesn't exist\" {\r\n        Test-CommandAvailable 'Write-ThisWillProbablyNotExist' | Should -BeFalse\r\n    }\r\n\r\n    It 'should throw if parameter is wrong or missing' {\r\n        { Test-CommandAvailable } | Should -Throw\r\n    }\r\n}\r\n\r\n\r\nDescribe 'is_directory' -Tag 'Scoop' {\r\n    BeforeAll {\r\n        $working_dir = setup_working 'is_directory'\r\n    }\r\n\r\n    It 'is_directory recognize directories' {\r\n        is_directory \"$working_dir\\i_am_a_directory\" | Should -Be $true\r\n    }\r\n    It 'is_directory recognize files' {\r\n        is_directory \"$working_dir\\i_am_a_file.txt\" | Should -Be $false\r\n    }\r\n\r\n    It 'is_directory is falsey on unknown path' {\r\n        is_directory \"$working_dir\\i_do_not_exist\" | Should -Be $false\r\n    }\r\n}\r\n\r\nDescribe 'movedir' -Tag 'Scoop', 'Windows' {\r\n    BeforeAll {\r\n        $working_dir = setup_working 'movedir'\r\n        $extract_dir = 'subdir'\r\n        $extract_to = $null\r\n    }\r\n\r\n    It 'moves directories with no spaces in path' {\r\n        $dir = \"$working_dir\\user\"\r\n        movedir \"$dir\\_tmp\\$extract_dir\" \"$dir\\$extract_to\"\r\n\r\n        \"$dir\\test.txt\" | Should -FileContentMatch 'this is the one'\r\n        \"$dir\\_tmp\\$extract_dir\" | Should -Not -Exist\r\n    }\r\n\r\n    It 'moves directories with spaces in path' {\r\n        $dir = \"$working_dir\\user with space\"\r\n        movedir \"$dir\\_tmp\\$extract_dir\" \"$dir\\$extract_to\"\r\n\r\n        \"$dir\\test.txt\" | Should -FileContentMatch 'this is the one'\r\n        \"$dir\\_tmp\\$extract_dir\" | Should -Not -Exist\r\n\r\n        # test trailing \\ in from dir\r\n        movedir \"$dir\\_tmp\\$null\" \"$dir\\another\"\r\n        \"$dir\\another\\test.txt\" | Should -FileContentMatch 'testing'\r\n        \"$dir\\_tmp\" | Should -Not -Exist\r\n    }\r\n\r\n    It 'moves directories with quotes in path' {\r\n        $dir = \"$working_dir\\user with 'quote\"\r\n        movedir \"$dir\\_tmp\\$extract_dir\" \"$dir\\$extract_to\"\r\n\r\n        \"$dir\\test.txt\" | Should -FileContentMatch 'this is the one'\r\n        \"$dir\\_tmp\\$extract_dir\" | Should -Not -Exist\r\n    }\r\n}\r\n\r\nDescribe 'shim' -Tag 'Scoop', 'Windows' {\r\n    BeforeAll {\r\n        $working_dir = setup_working 'shim'\r\n        $shimdir = shimdir\r\n        Add-Path $shimdir\r\n    }\r\n\r\n    It \"links a file onto the user's path\" {\r\n        { Get-Command 'shim-test' -ea stop } | Should -Throw\r\n        { Get-Command 'shim-test.ps1' -ea stop } | Should -Throw\r\n        { Get-Command 'shim-test.cmd' -ea stop } | Should -Throw\r\n        { shim-test } | Should -Throw\r\n\r\n        shim \"$working_dir\\shim-test.ps1\" $false 'shim-test'\r\n        { Get-Command 'shim-test' -ea stop } | Should -Not -Throw\r\n        { Get-Command 'shim-test.ps1' -ea stop } | Should -Not -Throw\r\n        { Get-Command 'shim-test.cmd' -ea stop } | Should -Not -Throw\r\n        shim-test | Should -Be 'Hello, world!'\r\n    }\r\n\r\n    It 'shims a file with quote in path' {\r\n        { Get-Command 'shim-test' -ea stop } | Should -Throw\r\n        { shim-test } | Should -Throw\r\n\r\n        shim \"$working_dir\\user with 'quote\\shim-test.ps1\" $false 'shim-test'\r\n        { Get-Command 'shim-test' -ea stop } | Should -Not -Throw\r\n        shim-test | Should -Be 'Hello, world!'\r\n    }\r\n\r\n    AfterEach {\r\n        rm_shim 'shim-test' $shimdir\r\n    }\r\n}\r\n\r\nDescribe 'rm_shim' -Tag 'Scoop', 'Windows' {\r\n    BeforeAll {\r\n        $working_dir = setup_working 'shim'\r\n        $shimdir = shimdir\r\n        Add-Path $shimdir\r\n    }\r\n\r\n    It 'removes shim from path' {\r\n        shim \"$working_dir\\shim-test.ps1\" $false 'shim-test'\r\n\r\n        rm_shim 'shim-test' $shimdir\r\n\r\n        { Get-Command 'shim-test' -ea stop } | Should -Throw\r\n        { Get-Command 'shim-test.ps1' -ea stop } | Should -Throw\r\n        { Get-Command 'shim-test.cmd' -ea stop } | Should -Throw\r\n        { shim-test } | Should -Throw\r\n    }\r\n}\r\n\r\nDescribe 'get_app_name_from_shim' -Tag 'Scoop', 'Windows' {\r\n    BeforeAll {\r\n        $working_dir = setup_working 'shim'\r\n        $shimdir = shimdir\r\n        Add-Path $shimdir\r\n        Mock appsdir { $working_dir }\r\n    }\r\n\r\n    It 'returns empty string if file does not exist' {\r\n        get_app_name_from_shim 'non-existent-file' | Should -Be ''\r\n    }\r\n\r\n    It 'returns app name if file exists and is a shim to an app' {\r\n        ensure \"$working_dir/mockapp/current/\"\r\n        Write-Output '' | Out-File \"$working_dir/mockapp/current/mockapp1.ps1\"\r\n        shim \"$working_dir/mockapp/current/mockapp1.ps1\" $false 'shim-test1'\r\n        $shim_path1 = (Get-Command 'shim-test1.ps1').Path\r\n        get_app_name_from_shim \"$shim_path1\" | Should -Be 'mockapp'\r\n        ensure \"$working_dir/mockapp/1.0.0/\"\r\n        Write-Output '' | Out-File \"$working_dir/mockapp/1.0.0/mockapp2.ps1\"\r\n        shim \"$working_dir/mockapp/1.0.0/mockapp2.ps1\" $false 'shim-test2'\r\n        $shim_path2 = (Get-Command 'shim-test2.ps1').Path\r\n        get_app_name_from_shim \"$shim_path2\" | Should -Be 'mockapp'\r\n    }\r\n\r\n    It 'returns empty string if file exists and is not a shim' {\r\n        Write-Output 'lorem ipsum' | Out-File -Encoding ascii \"$working_dir/mock-shim.ps1\"\r\n        get_app_name_from_shim \"$working_dir/mock-shim.ps1\" | Should -Be ''\r\n    }\r\n\r\n    AfterAll {\r\n        if (Get-Command 'shim-test1' -ErrorAction SilentlyContinue) {\r\n            rm_shim 'shim-test1' $shimdir -ErrorAction SilentlyContinue\r\n        }\r\n        if (Get-Command 'shim-test2' -ErrorAction SilentlyContinue) {\r\n            rm_shim 'shim-test2' $shimdir -ErrorAction SilentlyContinue\r\n        }\r\n        Remove-Item -Force -Recurse -ErrorAction SilentlyContinue \"$working_dir/mockapp\"\r\n        Remove-Item -Force -ErrorAction SilentlyContinue \"$working_dir/moch-shim.ps1\"\r\n    }\r\n}\r\n\r\nDescribe 'cache_path' -Tag 'Scoop' {\r\n    It 'returns the correct cache path for a given input' {\r\n        $url = 'https://example.com/git.zip'\r\n        $ret = cache_path 'git' '2.44.0' $url\r\n        $inputStream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($url))\r\n        $sha = (Get-FileHash -Algorithm SHA256 -InputStream $inputStream).Hash.ToLower().Substring(0, 7)\r\n        $ret | Should -Be \"$cachedir\\git#2.44.0#$sha.zip\"\r\n    }\r\n\r\n    # # NOTE: Remove this 6 months after the feature ships.\r\n    It 'returns the old format cache path for a given input' {\r\n        Mock Test-Path { $true }\r\n        $ret = cache_path 'git' '2.44.0' 'https://example.com/git.zip'\r\n        $ret | Should -Be \"$cachedir\\git#2.44.0#https_example.com_git.zip\"\r\n    }\r\n}\r\n\r\nDescribe 'sanitary_path' -Tag 'Scoop' {\r\n    It 'removes invalid path characters from a string' {\r\n        $path = 'test?.json'\r\n        $valid_path = sanitary_path $path\r\n\r\n        $valid_path | Should -Be 'test.json'\r\n    }\r\n}\r\n\r\nDescribe 'app' -Tag 'Scoop' {\r\n    It 'parses the bucket name from an app query' {\r\n        $query = 'C:\\test.json'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'C:\\test.json'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'test.json'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test.json'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = '.\\test.json'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be '.\\test.json'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = '..\\test.json'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be '..\\test.json'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = '\\\\share\\test.json'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be '\\\\share\\test.json'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'https://example.com/test.json'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'https://example.com/test.json'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'test'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'extras/enso'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'enso'\r\n        $bucket | Should -Be 'extras'\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'test-app'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test-app'\r\n        $bucket | Should -BeNullOrEmpty\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'test-bucket/test-app'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test-app'\r\n        $bucket | Should -Be 'test-bucket'\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'test-bucket/test-app@1.8.0'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test-app'\r\n        $bucket | Should -Be 'test-bucket'\r\n        $version | Should -Be '1.8.0'\r\n\r\n        $query = 'test-bucket/test-app@1.8.0-rc2'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test-app'\r\n        $bucket | Should -Be 'test-bucket'\r\n        $version | Should -Be '1.8.0-rc2'\r\n\r\n        $query = 'test-bucket/test_app'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test_app'\r\n        $bucket | Should -Be 'test-bucket'\r\n        $version | Should -BeNullOrEmpty\r\n\r\n        $query = 'test-bucket/test_app@1.8.0'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test_app'\r\n        $bucket | Should -Be 'test-bucket'\r\n        $version | Should -Be '1.8.0'\r\n\r\n        $query = 'test-bucket/test_app@1.8.0-rc2'\r\n        $app, $bucket, $version = parse_app $query\r\n        $app | Should -Be 'test_app'\r\n        $bucket | Should -Be 'test-bucket'\r\n        $version | Should -Be '1.8.0-rc2'\r\n    }\r\n}\r\n\r\nDescribe 'Format Architecture String' -Tag 'Scoop' {\r\n    It 'should keep correct architectures' {\r\n        Format-ArchitectureString '32bit' | Should -Be '32bit'\r\n        Format-ArchitectureString '32' | Should -Be '32bit'\r\n        Format-ArchitectureString 'x86' | Should -Be '32bit'\r\n        Format-ArchitectureString 'X86' | Should -Be '32bit'\r\n        Format-ArchitectureString 'i386' | Should -Be '32bit'\r\n        Format-ArchitectureString '386' | Should -Be '32bit'\r\n        Format-ArchitectureString 'i686' | Should -Be '32bit'\r\n\r\n        Format-ArchitectureString '64bit' | Should -Be '64bit'\r\n        Format-ArchitectureString '64' | Should -Be '64bit'\r\n        Format-ArchitectureString 'x64' | Should -Be '64bit'\r\n        Format-ArchitectureString 'X64' | Should -Be '64bit'\r\n        Format-ArchitectureString 'amd64' | Should -Be '64bit'\r\n        Format-ArchitectureString 'AMD64' | Should -Be '64bit'\r\n        Format-ArchitectureString 'x86_64' | Should -Be '64bit'\r\n        Format-ArchitectureString 'x86-64' | Should -Be '64bit'\r\n\r\n        Format-ArchitectureString 'arm64' | Should -Be 'arm64'\r\n        Format-ArchitectureString 'arm' | Should -Be 'arm64'\r\n        Format-ArchitectureString 'aarch64' | Should -Be 'arm64'\r\n        Format-ArchitectureString 'ARM64' | Should -Be 'arm64'\r\n        Format-ArchitectureString 'ARM' | Should -Be 'arm64'\r\n        Format-ArchitectureString 'AARCH64' | Should -Be 'arm64'\r\n    }\r\n\r\n    It 'should fallback to the default architecture on empty input' {\r\n        Format-ArchitectureString '' | Should -Be $(Get-DefaultArchitecture)\r\n        Format-ArchitectureString $null | Should -Be $(Get-DefaultArchitecture)\r\n    }\r\n\r\n    It 'should show an error with an invalid architecture' {\r\n        { Format-ArchitectureString 'PPC' } | Should -Throw \"Invalid architecture: 'ppc'\"\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Decompress.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\decompress.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n}\r\n\r\nDescribe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {\r\n\r\n    BeforeAll {\r\n        $working_dir = setup_working 'decompress'\r\n\r\n        function test_extract($extract_fn, $from, $removal) {\r\n            $to = (strip_ext $from) -replace '\\.tar$', ''\r\n            & $extract_fn ($from -replace '/', '\\') ($to -replace '/', '\\') -Removal:$removal -ExtractDir $args[0]\r\n            return $to\r\n        }\r\n\r\n    }\r\n    Context 'Decompression test cases should exist' {\r\n        BeforeAll {\r\n            $testcases = \"$working_dir\\TestCases.zip\"\r\n        }\r\n        It 'Test cases should exist and hash should match' {\r\n            $testcases | Should -Exist\r\n            (Get-FileHash -Path $testcases -Algorithm SHA256).Hash.ToLower() | Should -Be '591072faabd419b77932b7023e5899b4e05c0bf8e6859ad367398e6bfe1eb203'\r\n        }\r\n        It 'Test cases should be extracted correctly' {\r\n            { Microsoft.PowerShell.Archive\\Expand-Archive -Path $testcases -DestinationPath $working_dir } | Should -Not -Throw\r\n        }\r\n    }\r\n\r\n    Context '7zip extraction' {\r\n\r\n        BeforeAll {\r\n            if ($env:CI) {\r\n                Mock Get-AppFilePath { (Get-Command 7z.exe).Path }\r\n            } elseif (!(installed 7zip)) {\r\n                scoop install 7zip\r\n            }\r\n            $test1 = \"$working_dir\\7ZipTest1.7z\"\r\n            $test2 = \"$working_dir\\7ZipTest2.tgz\"\r\n            $test3 = \"$working_dir\\7ZipTest3.tar.bz2\"\r\n            $test4 = \"$working_dir\\7ZipTest4.tar.gz\"\r\n            $test5_1 = \"$working_dir\\7ZipTest5.7z.001\"\r\n            $test5_2 = \"$working_dir\\7ZipTest5.7z.002\"\r\n            $test5_3 = \"$working_dir\\7ZipTest5.7z.003\"\r\n            $test6_1 = \"$working_dir\\7ZipTest6.part01.rar\"\r\n            $test6_2 = \"$working_dir\\7ZipTest6.part02.rar\"\r\n            $test6_3 = \"$working_dir\\7ZipTest6.part03.rar\"\r\n            $test7 = \"$working_dir\\NSISTest.exe\"\r\n        }\r\n\r\n        AfterEach {\r\n            Remove-Item -Path $to -Recurse -Force\r\n        }\r\n\r\n        It 'extract normal compressed file' {\r\n            $to = test_extract 'Expand-7zipArchive' $test1\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 4\r\n        }\r\n\r\n        It 'extract \"extract_dir\" correctly' {\r\n            $to = test_extract 'Expand-7zipArchive' $test1 $false 'tmp'\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract \"extract_dir\" with spaces correctly' {\r\n            $to = test_extract 'Expand-7zipArchive' $test1 $false 'tmp 2'\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract \"extract_dir\" with nested folder with same name' {\r\n            $to = test_extract 'Expand-7zipArchive' $test1 $false 'keep\\sub'\r\n            $to | Should -Exist\r\n            \"$to\\keep\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n            (Get-ChildItem \"$to\\keep\").Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract nested compressed file' {\r\n            # file ext: tgz\r\n            $to = test_extract 'Expand-7zipArchive' $test2\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n\r\n            # file ext: tar.bz2\r\n            $to = test_extract 'Expand-7zipArchive' $test3\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract nested compressed file with different inner name' {\r\n            $to = test_extract 'Expand-7zipArchive' $test4\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract splited 7z archives (.001, .002, ...)' {\r\n            $to = test_extract 'Expand-7zipArchive' $test5_1\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract splited RAR archives (.part01.rar, .part02.rar, ...)' {\r\n            $to = test_extract 'Expand-7zipArchive' $test6_1\r\n            $to | Should -Exist\r\n            \"$to\\dummy\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract NSIS installer' {\r\n            $to = test_extract 'Expand-7zipArchive' $test7\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'self-extract NSIS installer' {\r\n            $to = \"$working_dir\\NSIS Test\"\r\n            $null = Invoke-ExternalCommand -FilePath $test7 -ArgumentList @('/S', '/NCRC', \"/D=$to\")\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'works with \"-Removal\" switch ($removal param)' {\r\n            $test1 | Should -Exist\r\n            $to = test_extract 'Expand-7zipArchive' $test1 $true\r\n            $to | Should -Exist\r\n            $test1 | Should -Not -Exist\r\n            $test5_1 | Should -Exist\r\n            $test5_2 | Should -Exist\r\n            $test5_3 | Should -Exist\r\n            $to = test_extract 'Expand-7zipArchive' $test5_1 $true\r\n            $to | Should -Exist\r\n            $test5_1 | Should -Not -Exist\r\n            $test5_2 | Should -Not -Exist\r\n            $test5_3 | Should -Not -Exist\r\n            $test6_1 | Should -Exist\r\n            $test6_2 | Should -Exist\r\n            $test6_3 | Should -Exist\r\n            $to = test_extract 'Expand-7zipArchive' $test6_1 $true\r\n            $to | Should -Exist\r\n            $test6_1 | Should -Not -Exist\r\n            $test6_2 | Should -Not -Exist\r\n            $test6_3 | Should -Not -Exist\r\n        }\r\n    }\r\n\r\n    Context 'msi extraction' {\r\n\r\n        BeforeAll {\r\n            if ($env:CI) {\r\n                Mock Get-AppFilePath { $env:SCOOP_LESSMSI_PATH }\r\n            } elseif (!(installed lessmsi)) {\r\n                scoop install lessmsi\r\n            }\r\n            Copy-Item \"$working_dir\\MSITest.msi\" \"$working_dir\\MSI Test.msi\"\r\n            $test1 = \"$working_dir\\MSITest.msi\"\r\n            $test2 = \"$working_dir\\MSI Test.msi\"\r\n            $test3 = \"$working_dir\\MSITestNull.msi\"\r\n        }\r\n\r\n        It 'extract normal MSI file using msiexec' {\r\n            Mock get_config { $false }\r\n            $to = test_extract 'Expand-MsiArchive' $test1\r\n            $to | Should -Exist\r\n            \"$to\\MSITest\\empty\" | Should -Exist\r\n            (Get-ChildItem \"$to\\MSITest\").Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract normal MSI file with whitespace in path using msiexec' {\r\n            Mock get_config { $false }\r\n            $to = test_extract 'Expand-MsiArchive' $test2\r\n            $to | Should -Exist\r\n            \"$to\\MSITest\\empty\" | Should -Exist\r\n            (Get-ChildItem \"$to\\MSITest\").Count | Should -Be 1\r\n        }\r\n\r\n        It 'extract normal MSI file using lessmsi' {\r\n            Mock get_config { $true }\r\n            $to = test_extract 'Expand-MsiArchive' $test1\r\n            $to | Should -Exist\r\n        }\r\n\r\n        It 'extract normal MSI file with whitespace in path using lessmsi' {\r\n            Mock get_config { $true }\r\n            $to = test_extract 'Expand-MsiArchive' $test2\r\n            $to | Should -Exist\r\n        }\r\n\r\n        It 'extract empty MSI file using lessmsi' {\r\n            Mock get_config { $true }\r\n            $to = test_extract 'Expand-MsiArchive' $test3\r\n            $to | Should -Exist\r\n        }\r\n\r\n        It 'works with \"-Removal\" switch ($removal param)' {\r\n            Mock get_config { $false }\r\n            $test1 | Should -Exist\r\n            test_extract 'Expand-MsiArchive' $test1 $true\r\n            $test1 | Should -Not -Exist\r\n        }\r\n    }\r\n\r\n    Context 'inno extraction' {\r\n\r\n        BeforeAll {\r\n            if ($env:CI) {\r\n                Mock Get-AppFilePath { $env:SCOOP_INNOUNP_PATH }\r\n            } elseif (!(installed innounp)) {\r\n                scoop install innounp\r\n            }\r\n            $test = \"$working_dir\\InnoTest.exe\"\r\n        }\r\n\r\n        It 'extract Inno Setup file' {\r\n            $to = test_extract 'Expand-InnoArchive' $test\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'works with \"-Removal\" switch ($removal param)' {\r\n            $test | Should -Exist\r\n            test_extract 'Expand-InnoArchive' $test $true\r\n            $test | Should -Not -Exist\r\n        }\r\n    }\r\n\r\n    Context 'zip extraction' {\r\n\r\n        BeforeAll {\r\n            $test = \"$working_dir\\ZipTest.zip\"\r\n        }\r\n\r\n        It 'extract compressed file' {\r\n            $to = test_extract 'Expand-ZipArchive' $test\r\n            $to | Should -Exist\r\n            \"$to\\empty\" | Should -Exist\r\n            (Get-ChildItem $to).Count | Should -Be 1\r\n        }\r\n\r\n        It 'works with \"-Removal\" switch ($removal param)' {\r\n            $test | Should -Exist\r\n            test_extract 'Expand-ZipArchive' $test $true\r\n            $test | Should -Not -Exist\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Depends.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\depends.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\buckets.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n}\r\n\r\nDescribe 'Package Dependencies' -Tag 'Scoop' {\r\n    Context 'Requirement function' {\r\n        It 'Test 7zip requirement' {\r\n            Test-7zipRequirement -Uri 'test.xz' | Should -BeTrue\r\n            Test-7zipRequirement -Uri 'test.bin' | Should -BeFalse\r\n            Test-7zipRequirement -Uri @('test.xz', 'test.bin') | Should -BeTrue\r\n        }\r\n        It 'Test lessmsi requirement' {\r\n            Mock get_config { $true }\r\n            Test-LessmsiRequirement -Uri 'test.msi' | Should -BeTrue\r\n            Test-LessmsiRequirement -Uri 'test.bin' | Should -BeFalse\r\n            Test-LessmsiRequirement -Uri @('test.msi', 'test.bin') | Should -BeTrue\r\n        }\r\n        It 'Allow $Uri be $null' {\r\n            Test-7zipRequirement -Uri $null | Should -BeFalse\r\n            Test-LessmsiRequirement -Uri $null | Should -BeFalse\r\n        }\r\n    }\r\n\r\n    Context 'InstallationHelper function' {\r\n        BeforeAll {\r\n            $working_dir = setup_working 'format/formatted'\r\n            $manifest1 = parse_json (Join-Path $working_dir '3-array-with-single-and-multi.json')\r\n            $manifest2 = parse_json (Join-Path $working_dir '4-script-block.json')\r\n            Mock Test-HelperInstalled { $false }\r\n        }\r\n        It 'Get helpers from URL' {\r\n            Mock get_config { $true }\r\n            Get-InstallationHelper -Manifest $manifest1 -Architecture '32bit' | Should -Be @('lessmsi')\r\n        }\r\n        It 'Get helpers from script' {\r\n            Mock get_config { $false }\r\n            Get-InstallationHelper -Manifest $manifest2 -Architecture '32bit' | Should -Be @('7zip')\r\n        }\r\n        It 'Helpers reflect config changes' {\r\n            Mock get_config { $false } -ParameterFilter { $name -eq 'USE_LESSMSI' }\r\n            Mock get_config { $true } -ParameterFilter { $name -eq 'USE_EXTERNAL_7ZIP' }\r\n            Get-InstallationHelper -Manifest $manifest1 -Architecture '32bit' | Should -BeNullOrEmpty\r\n            Get-InstallationHelper -Manifest $manifest2 -Architecture '32bit' | Should -BeNullOrEmpty\r\n        }\r\n        It 'Not return installed helpers' {\r\n            Mock get_config { $true } -ParameterFilter { $name -eq 'USE_LESSMSI' }\r\n            Mock get_config { $false } -ParameterFilter { $name -eq 'USE_EXTERNAL_7ZIP' }\r\n            Mock Test-HelperInstalled { $true }-ParameterFilter { $Helper -eq '7zip' }\r\n            Mock Test-HelperInstalled { $false }-ParameterFilter { $Helper -eq 'Lessmsi' }\r\n            Get-InstallationHelper -Manifest $manifest1 -Architecture '32bit' | Should -Be @('lessmsi')\r\n            Get-InstallationHelper -Manifest $manifest2 -Architecture '32bit' | Should -BeNullOrEmpty\r\n            Mock Test-HelperInstalled { $false }-ParameterFilter { $Helper -eq '7zip' }\r\n            Mock Test-HelperInstalled { $true }-ParameterFilter { $Helper -eq 'Lessmsi' }\r\n            Get-InstallationHelper -Manifest $manifest1 -Architecture '32bit' | Should -BeNullOrEmpty\r\n            Get-InstallationHelper -Manifest $manifest2 -Architecture '32bit' | Should -Be @('7zip')\r\n        }\r\n    }\r\n\r\n    Context 'Dependencies resolution' {\r\n        BeforeAll {\r\n            Mock Test-HelperInstalled { $false }\r\n            Mock get_config { $true } -ParameterFilter { $name -eq 'USE_LESSMSI' }\r\n            Mock get_config { $false } -ParameterFilter { $name -eq 'USE_EXTERNAL_7ZIP' }\r\n            Mock Get-Manifest { 'lessmsi', @{}, $null, $null } -ParameterFilter { $app -eq 'lessmsi' }\r\n            Mock Get-Manifest { '7zip', @{ url = 'test.msi' }, $null, $null } -ParameterFilter { $app -eq '7zip' }\r\n            Mock Get-Manifest { 'innounp', @{}, $null, $null } -ParameterFilter { $app -eq 'innounp' }\r\n        }\r\n\r\n        It 'Resolve install dependencies' {\r\n            Mock Get-Manifest { 'test', @{ url = 'test.7z' }, $null, $null }\r\n            Get-Dependency -AppName 'test' -Architecture '32bit' | Should -Be @('lessmsi', '7zip', 'test')\r\n            Mock Get-Manifest { 'test', @{ innosetup = $true }, $null, $null }\r\n            Get-Dependency -AppName 'test' -Architecture '32bit' | Should -Be @('innounp', 'test')\r\n        }\r\n        It 'Resolve script dependencies' {\r\n            Mock Get-Manifest { 'test', @{ pre_install = 'Expand-7zipArchive ' }, $null, $null }\r\n            Get-Dependency -AppName 'test' -Architecture '32bit' | Should -Be @('lessmsi', '7zip', 'test')\r\n        }\r\n        It 'Resolve runtime dependencies' {\r\n            Mock Get-Manifest { 'depends', @{}, $null, $null } -ParameterFilter { $app -eq 'depends' }\r\n            Mock Get-Manifest { 'test', @{ depends = 'depends' }, $null, $null }\r\n            Get-Dependency -AppName 'test' -Architecture '32bit' | Should -Be @('depends', 'test')\r\n        }\r\n        It 'Keep bucket name of app' {\r\n            Mock Get-Manifest { 'depends', @{}, 'anotherbucket', $null } -ParameterFilter { $app -eq 'anotherbucket/depends' }\r\n            Mock Get-Manifest { 'test', @{ depends = 'anotherbucket/depends' }, 'bucket', $null }\r\n            Get-Dependency -AppName 'bucket/test' -Architecture '32bit' | Should -Be @('anotherbucket/depends', 'bucket/test')\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Download.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\download.ps1\"\r\n}\r\n\r\nDescribe 'Test-Aria2Enabled' -Tag 'Scoop' {\r\n    It 'should return true if aria2 is installed' {\r\n        Mock Test-HelperInstalled { $true }\r\n        Mock get_config { $true }\r\n        Test-Aria2Enabled | Should -BeTrue\r\n    }\r\n\r\n    It 'should return false if aria2 is not installed' {\r\n        Mock Test-HelperInstalled { $false }\r\n        Mock get_config { $false }\r\n        Test-Aria2Enabled | Should -BeFalse\r\n\r\n        Mock Test-HelperInstalled { $false }\r\n        Mock get_config { $true }\r\n        Test-Aria2Enabled | Should -BeFalse\r\n\r\n        Mock Test-HelperInstalled { $true }\r\n        Mock get_config { $false }\r\n        Test-Aria2Enabled | Should -BeFalse\r\n    }\r\n}\r\n\r\nDescribe 'url_filename' -Tag 'Scoop' {\r\n    It 'should extract the real filename from an url' {\r\n        url_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'\r\n        url_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'\r\n    }\r\n\r\n    It 'can be tricked with a hash to override the real filename' {\r\n        url_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo.zip'\r\n    }\r\n}\r\n\r\nDescribe 'url_remote_filename' -Tag 'Scoop' {\r\n    It 'should extract the real filename from an url' {\r\n        url_remote_filename 'http://example.org/foo.txt' | Should -Be 'foo.txt'\r\n        url_remote_filename 'http://example.org/foo.txt?var=123' | Should -Be 'foo.txt'\r\n    }\r\n\r\n    It 'can not be tricked with a hash to override the real filename' {\r\n        url_remote_filename 'http://example.org/foo-v2.zip#/foo.zip' | Should -Be 'foo-v2.zip'\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-GetOpts.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\getopt.ps1\"\r\n}\r\n\r\nDescribe 'getopt' -Tag 'Scoop' {\r\n    It 'handle short option with required argument missing' {\r\n        $null, $null, $err = getopt '-x' 'x:' ''\r\n        $err | Should -Be 'Option -x requires an argument.'\r\n\r\n        $null, $null, $err = getopt '-xy' 'x:y' ''\r\n        $err | Should -Be 'Option -x requires an argument.'\r\n    }\r\n\r\n    It 'handle long option with required argument missing' {\r\n        $null, $null, $err = getopt '--arb' '' 'arb='\r\n        $err | Should -Be 'Option --arb requires an argument.'\r\n    }\r\n\r\n    It 'handle space in quote' {\r\n        $opt, $rem, $err = getopt '-x', 'space arg' 'x:' ''\r\n        $err | Should -BeNullOrEmpty\r\n        $opt.x | Should -Be 'space arg'\r\n    }\r\n\r\n    It 'handle unrecognized short option' {\r\n        $null, $null, $err = getopt '-az' 'a' ''\r\n        $err | Should -Be 'Option -z not recognized.'\r\n    }\r\n\r\n    It 'handle unrecognized long option' {\r\n        $null, $null, $err = getopt '--non-exist' '' ''\r\n        $err | Should -Be 'Option --non-exist not recognized.'\r\n\r\n        $null, $null, $err = getopt '--global', '--another' 'abc:de:' 'global', 'one'\r\n        $err | Should -Be 'Option --another not recognized.'\r\n    }\r\n\r\n    It 'remaining args returned' {\r\n        $opt, $rem, $err = getopt '-g', 'rem' 'g' ''\r\n        $err | Should -BeNullOrEmpty\r\n        $opt.g | Should -BeTrue\r\n        $rem | Should -Not -BeNullOrEmpty\r\n        $rem.length | Should -Be 1\r\n        $rem[0] | Should -Be 'rem'\r\n    }\r\n\r\n    It 'get a long flag and a short option with argument' {\r\n        $a = '--global -a 32bit test' -split ' '\r\n        $opt, $rem, $err = getopt $a 'ga:' 'global', 'arch='\r\n\r\n        $err | Should -BeNullOrEmpty\r\n        $opt.global | Should -BeTrue\r\n        $opt.a | Should -Be '32bit'\r\n    }\r\n\r\n    It 'handles regex characters' {\r\n        $a = '-?'\r\n        { $opt, $rem, $err = getopt $a 'ga:' 'global' 'arch=' } | Should -Not -Throw\r\n        { $null, $null, $null = getopt $a '?:' 'help' | Should -Not -Throw }\r\n    }\r\n\r\n    It 'handles short option without required argument' {\r\n        $null, $null, $err = getopt '-x' 'x' ''\r\n        $err | Should -BeNullOrEmpty\r\n    }\r\n\r\n    It 'handles long option without required argument' {\r\n        $opt, $null, $err = getopt '--long-arg' '' 'long-arg'\r\n        $err | Should -BeNullOrEmpty\r\n        $opt.'long-arg' | Should -BeTrue\r\n    }\r\n\r\n    It 'handles long option with required argument' {\r\n        $opt, $null, $err = getopt '--long-arg', 'test' '' 'long-arg='\r\n        $err | Should -BeNullOrEmpty\r\n        $opt.'long-arg' | Should -Be 'test'\r\n    }\r\n\r\n    It 'handles the option terminator' {\r\n        $opt, $rem, $err = getopt '--long-arg', '--' '' 'long-arg'\r\n        $err | Should -BeNullOrEmpty\r\n        $opt.'long-arg' | Should -BeTrue\r\n        $rem[0] | Should -BeNullOrEmpty\r\n        $opt, $rem, $err = getopt '--long-arg', '--', '-x', '-y' 'xy' 'long-arg'\r\n        $err | Should -BeNullOrEmpty\r\n        $opt.'long-arg' | Should -BeTrue\r\n        $opt.'x' | Should -BeNullOrEmpty\r\n        $opt.'y' | Should -BeNullOrEmpty\r\n        $rem[0] | Should -Be '-x'\r\n        $rem[1] | Should -Be '-y'\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Install.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\core.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\system.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\install.ps1\"\r\n}\r\n\r\nDescribe 'appname_from_url' -Tag 'Scoop' {\r\n    It 'should extract the correct name' {\r\n        appname_from_url 'https://example.org/directory/foobar.json' | Should -Be 'foobar'\r\n    }\r\n}\r\n\r\nDescribe 'is_in_dir' -Tag 'Scoop', 'Windows' {\r\n    It 'should work correctly' {\r\n        is_in_dir 'C:\\test' 'C:\\foo' | Should -BeFalse\r\n        is_in_dir 'C:\\test' 'C:\\test\\foo\\baz.zip' | Should -BeTrue\r\n        is_in_dir \"$PSScriptRoot\\..\\\" \"$PSScriptRoot\" | Should -BeFalse\r\n    }\r\n}\r\n\r\nDescribe 'env add and remove path' -Tag 'Scoop', 'Windows' {\r\n    BeforeAll {\r\n        # test data\r\n        $manifest = @{\r\n            'env_add_path' = @('foo', 'bar', '.', '..')\r\n        }\r\n        $testdir = Join-Path $PSScriptRoot 'path-test-directory'\r\n        $global = $false\r\n    }\r\n\r\n    It 'should concat the correct path' {\r\n        Mock Add-Path {}\r\n        Mock Remove-Path {}\r\n\r\n        # adding\r\n        env_add_path $manifest $testdir $global\r\n        Should -Invoke -CommandName Add-Path -Times 1 -ParameterFilter { $Path -like \"$testdir\\foo\" }\r\n        Should -Invoke -CommandName Add-Path -Times 1 -ParameterFilter { $Path -like \"$testdir\\bar\" }\r\n        Should -Invoke -CommandName Add-Path -Times 1 -ParameterFilter { $Path -like $testdir }\r\n        Should -Invoke -CommandName Add-Path -Times 0 -ParameterFilter { $Path -like $PSScriptRoot }\r\n\r\n        env_rm_path $manifest $testdir $global\r\n        Should -Invoke -CommandName Remove-Path -Times 1 -ParameterFilter { $Path -like \"$testdir\\foo\" }\r\n        Should -Invoke -CommandName Remove-Path -Times 1 -ParameterFilter { $Path -like \"$testdir\\bar\" }\r\n        Should -Invoke -CommandName Remove-Path -Times 1 -ParameterFilter { $Path -like $testdir }\r\n        Should -Invoke -CommandName Remove-Path -Times 0 -ParameterFilter { $Path -like $PSScriptRoot }\r\n    }\r\n}\r\n\r\nDescribe 'shim_def' -Tag 'Scoop' {\r\n    It 'should use strings correctly' {\r\n        $target, $name, $shimArgs = shim_def 'command.exe'\r\n        $target | Should -Be 'command.exe'\r\n        $name | Should -Be 'command'\r\n        $shimArgs | Should -BeNullOrEmpty\r\n    }\r\n\r\n    It 'should expand the array correctly' {\r\n        $target, $name, $shimArgs = shim_def @('foo.exe', 'bar')\r\n        $target | Should -Be 'foo.exe'\r\n        $name | Should -Be 'bar'\r\n        $shimArgs | Should -BeNullOrEmpty\r\n\r\n        $target, $name, $shimArgs = shim_def @('foo.exe', 'bar', '--test')\r\n        $target | Should -Be 'foo.exe'\r\n        $name | Should -Be 'bar'\r\n        $shimArgs | Should -Be '--test'\r\n    }\r\n}\r\n\r\nDescribe 'persist_def' -Tag 'Scoop' {\r\n    It 'parses string correctly' {\r\n        $source, $target = persist_def 'test'\r\n        $source | Should -Be 'test'\r\n        $target | Should -Be 'test'\r\n    }\r\n\r\n    It 'should handle sub-folder' {\r\n        $source, $target = persist_def 'foo/bar'\r\n        $source | Should -Be 'foo/bar'\r\n        $target | Should -Be 'foo/bar'\r\n    }\r\n\r\n    It 'should handle arrays' {\r\n        # both specified\r\n        $source, $target = persist_def @('foo', 'bar')\r\n        $source | Should -Be 'foo'\r\n        $target | Should -Be 'bar'\r\n\r\n        # only first specified\r\n        $source, $target = persist_def @('foo')\r\n        $source | Should -Be 'foo'\r\n        $target | Should -Be 'foo'\r\n\r\n        # null value specified\r\n        $source, $target = persist_def @('foo', $null)\r\n        $source | Should -Be 'foo'\r\n        $target | Should -Be 'foo'\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Manifest.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\..\\lib\\json.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\manifest.ps1\"\r\n}\r\n\r\nDescribe 'JSON parse and beautify' -Tag 'Scoop' {\r\n    Context 'Parse JSON' {\r\n        It 'success with valid json' {\r\n            { parse_json \"$PSScriptRoot\\fixtures\\manifest\\wget.json\" } | Should -Not -Throw\r\n        }\r\n        It 'fails with invalid json' {\r\n            { parse_json \"$PSScriptRoot\\fixtures\\manifest\\broken_wget.json\" } | Should -Throw\r\n        }\r\n    }\r\n    Context 'Beautify JSON' {\r\n        BeforeDiscovery {\r\n            $manifests = (Get-ChildItem \"$PSScriptRoot\\fixtures\\format\\formatted\" -File -Filter '*.json').Name\r\n        }\r\n        BeforeAll {\r\n            $format = \"$PSScriptRoot\\fixtures\\format\"\r\n        }\r\n        It '<_>' -ForEach $manifests {\r\n            $pretty_json = (parse_json \"$format\\unformatted\\$_\") | ConvertToPrettyJson\r\n            $correct = (Get-Content \"$format\\formatted\\$_\") -join \"`r`n\"\r\n            $correct.CompareTo($pretty_json) | Should -Be 0\r\n        }\r\n    }\r\n}\r\n\r\nDescribe 'Handle ARM64 and correctly fallback' -Tag 'Scoop' {\r\n    It 'Should return \"arm64\" if supported' {\r\n        $manifest1 = @{ url = 'test'; architecture = @{ 'arm64' = @{ pre_install = 'test' } } }\r\n        $manifest2 = @{ url = 'test'; pre_install = \"'arm64'\" }\r\n        $manifest3 = @{ architecture = @{ 'arm64' = @{ url = 'test' } } }\r\n        Get-SupportedArchitecture $manifest1 'arm64' | Should -Be 'arm64'\r\n        Get-SupportedArchitecture $manifest2 'arm64' | Should -Be 'arm64'\r\n        Get-SupportedArchitecture $manifest3 'arm64' | Should -Be 'arm64'\r\n    }\r\n    It 'Should return \"64bit\" if unsupported on Windows 11' {\r\n        $WindowsBuild = 22000\r\n        $manifest1 = @{ url = 'test' }\r\n        $manifest2 = @{ architecture = @{ '64bit' = @{ url = 'test' } } }\r\n        Get-SupportedArchitecture $manifest1 'arm64' | Should -Be '64bit'\r\n        Get-SupportedArchitecture $manifest2 'arm64' | Should -Be '64bit'\r\n    }\r\n    It 'Should return \"32bit\" if unsupported on Windows 10' {\r\n        $WindowsBuild = 19044\r\n        $manifest2 = @{ url = 'test' }\r\n        $manifest1 = @{ url = 'test'; architecture = @{ '64bit' = @{ pre_install = 'test' } } }\r\n        $manifest3 = @{ architecture = @{ '64bit' = @{ url = 'test' } } }\r\n        Get-SupportedArchitecture $manifest1 'arm64' | Should -Be '32bit'\r\n        Get-SupportedArchitecture $manifest2 'arm64' | Should -Be '32bit'\r\n        Get-SupportedArchitecture $manifest3 'arm64' | Should -BeNullOrEmpty\r\n    }\r\n}\r\n\r\nDescribe 'Manifest Validator' -Tag 'Validator' {\r\n    # Could not use backslash '\\' in Linux/macOS for .NET object 'Scoop.Validator'\r\n    BeforeAll {\r\n        Add-Type -Path \"$PSScriptRoot\\..\\supporting\\validator\\bin\\Scoop.Validator.dll\"\r\n        $schema = \"$PSScriptRoot/../schema.json\"\r\n    }\r\n\r\n    It 'Scoop.Validator is available' {\r\n            ([System.Management.Automation.PSTypeName]'Scoop.Validator').Type | Should -Be 'Scoop.Validator'\r\n    }\r\n    It 'fails with broken schema' {\r\n        $validator = New-Object Scoop.Validator(\"$PSScriptRoot/fixtures/manifest/broken_schema.json\", $true)\r\n        $validator.Validate(\"$PSScriptRoot/fixtures/manifest/wget.json\") | Should -BeFalse\r\n        $validator.Errors.Count | Should -Be 1\r\n        $validator.Errors | Select-Object -First 1 | Should -Match 'broken_schema.*(line 6).*(position 4)'\r\n    }\r\n    It 'fails with broken manifest' {\r\n        $validator = New-Object Scoop.Validator($schema, $true)\r\n        $validator.Validate(\"$PSScriptRoot/fixtures/manifest/broken_wget.json\") | Should -BeFalse\r\n        $validator.Errors.Count | Should -Be 1\r\n        $validator.Errors | Select-Object -First 1 | Should -Match 'broken_wget.*(line 5).*(position 4)'\r\n    }\r\n    It 'fails with invalid manifest' {\r\n        $validator = New-Object Scoop.Validator($schema, $true)\r\n        $validator.Validate(\"$PSScriptRoot/fixtures/manifest/invalid_wget.json\") | Should -BeFalse\r\n        $validator.Errors.Count | Should -Be 16\r\n        $validator.Errors | Select-Object -First 1 | Should -Match \"Property 'randomproperty' has not been defined and the schema does not allow additional properties\\.\"\r\n        $validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version\\.'\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/Scoop-TestLib.ps1",
    "content": "# copies fixtures to a working directory\r\nfunction setup_working($name) {\r\n    $fixtures = \"$PSScriptRoot\\fixtures\\$name\"\r\n    if (!(Test-Path $fixtures)) {\r\n        Write-Host \"couldn't find fixtures for $name at $fixtures\" -f red\r\n        exit 1\r\n    }\r\n\r\n    # reset working dir\r\n    $working_dir = \"$([IO.Path]::GetTempPath())ScoopTestFixtures\\$name\"\r\n\r\n    if (Test-Path $working_dir) {\r\n        Remove-Item -Recurse -Force $working_dir\r\n    }\r\n\r\n    # set up\r\n    Copy-Item $fixtures -Destination $working_dir -Recurse\r\n\r\n    return $working_dir\r\n}\r\n"
  },
  {
    "path": "test/Scoop-Versions.Tests.ps1",
    "content": "BeforeAll {\r\n    . \"$PSScriptRoot\\Scoop-TestLib.ps1\"\r\n    . \"$PSScriptRoot\\..\\lib\\versions.ps1\"\r\n}\r\n\r\nDescribe 'versions comparison' -Tag 'Scoop' {\r\n    Context 'semver compliant versions' {\r\n        It 'handles major.minor.patch progressing' {\r\n            Compare-Version '0.1.0' '0.1.1' | Should -Be 1\r\n            Compare-Version '0.1.1' '0.2.0' | Should -Be 1\r\n            Compare-Version '0.2.0' '1.0.0' | Should -Be 1\r\n        }\r\n\r\n        It 'handles pre-release versioning progression' {\r\n            Compare-Version '0.4.0' '0.5.0-alpha.1' | Should -Be 1\r\n            Compare-Version '0.5.0-alpha.1' '0.5.0-alpha.2' | Should -Be 1\r\n            Compare-Version '0.5.0-alpha.2' '0.5.0-alpha.10' | Should -Be 1\r\n            Compare-Version '0.5.0-alpha.10' '0.5.0-beta' | Should -Be 1\r\n            Compare-Version '0.5.0-beta' '0.5.0-alpha.10' | Should -Be -1\r\n            Compare-Version '0.5.0-beta' '0.5.0-beta.0' | Should -Be 1\r\n        }\r\n\r\n        It 'handles the pre-release tags in an alphabetic order' {\r\n            Compare-Version '0.5.0-rc.1' '0.5.0-z' | Should -Be 1\r\n            Compare-Version '0.5.0-rc.1' '0.5.0-howdy' | Should -Be -1\r\n            Compare-Version '0.5.0-howdy' '0.5.0-rc.1' | Should -Be 1\r\n        }\r\n    }\r\n\r\n    Context 'semver semi-compliant versions' {\r\n        It 'handles Windows-styled major.minor.patch.build progression' {\r\n            Compare-Version '0.0.0.0' '0.0.0.1' | Should -Be 1\r\n            Compare-Version '0.0.0.1' '0.0.0.2' | Should -Be 1\r\n            Compare-Version '0.0.0.2' '0.0.1.0' | Should -Be 1\r\n            Compare-Version '0.0.1.0' '0.0.1.1' | Should -Be 1\r\n            Compare-Version '0.0.1.1' '0.0.1.2' | Should -Be 1\r\n            Compare-Version '0.0.1.2' '0.0.2.0' | Should -Be 1\r\n            Compare-Version '0.0.2.0' '0.1.0.0' | Should -Be 1\r\n            Compare-Version '0.1.0.0' '0.1.0.1' | Should -Be 1\r\n            Compare-Version '0.1.0.1' '0.1.0.2' | Should -Be 1\r\n            Compare-Version '0.1.0.2' '0.1.1.0' | Should -Be 1\r\n            Compare-Version '0.1.1.0' '0.1.1.1' | Should -Be 1\r\n            Compare-Version '0.1.1.1' '0.1.1.2' | Should -Be 1\r\n            Compare-Version '0.1.1.2' '0.2.0.0' | Should -Be 1\r\n            Compare-Version '0.2.0.0' '1.0.0.0' | Should -Be 1\r\n        }\r\n\r\n        It 'handles partial semver version differences' {\r\n            Compare-Version '1' '1.1' | Should -Be 1\r\n            Compare-Version '1' '1.0' | Should -Be 1\r\n            Compare-Version '1.1.0.0' '1.1' | Should -Be -1\r\n            Compare-Version '1.4' '1.3.0' | Should -Be -1\r\n            Compare-Version '1.4' '1.3.255.255' | Should -Be -1\r\n            Compare-Version '1.4' '1.4.4' | Should -Be 1\r\n            Compare-Version '1.1.1_8' '1.1.1' | Should -Be -1\r\n            Compare-Version '1.1.1_8' '1.1.1_9' | Should -Be 1\r\n            Compare-Version '1.1.1_10' '1.1.1_9' | Should -Be -1\r\n            Compare-Version '1.1.1b' '1.1.1a' | Should -Be -1\r\n            Compare-Version '1.1.1a' '1.1.1b' | Should -Be 1\r\n            Compare-Version '1.1a2' '1.1a3' | Should -Be 1\r\n            Compare-Version '1.1.1a10' '1.1.1b1' | Should -Be 1\r\n        }\r\n\r\n        It 'handles dash-style versions' {\r\n            Compare-Version '1.8.9' '1.8.5-1' | Should -Be -1\r\n            Compare-Version '7.0.4-9' '7.0.4-10' | Should -Be 1\r\n            Compare-Version '7.0.4-9' '7.0.4-8' | Should -Be -1\r\n            Compare-Version '2019-01-01' '2019-01-02' | Should -Be 1\r\n            Compare-Version '2019-01-02' '2019-01-01' | Should -Be -1\r\n            Compare-Version '2018-01-01' '2019-01-01' | Should -Be 1\r\n            Compare-Version '2019-01-01' '2018-01-01' | Should -Be -1\r\n        }\r\n        It 'handles post-release tagging (\"+\")' {\r\n            Compare-Version '1' '1+hotfix.0' | Should -Be 1\r\n            Compare-Version '1.0.0' '1.0.0+hotfix.0' | Should -Be 1\r\n            Compare-Version '1.0.0+hotfix.0' '1.0.0+hotfix.1' | Should -Be 1\r\n            Compare-Version '1.0.0+hotfix.1' '1.0.1' | Should -Be 1\r\n            Compare-Version '1.0.0+1.1' '1.0.0+1' | Should -Be -1\r\n        }\r\n    }\r\n\r\n    Context 'other misc versions' {\r\n        It 'handles plain text string' {\r\n            Compare-Version 'latest' '20150405' | Should -Be -1\r\n            Compare-Version '0.5alpha' '0.5' | Should -Be 1\r\n            Compare-Version '0.5' '0.5Beta' | Should -Be -1\r\n            Compare-Version '0.4' '0.5Beta' | Should -Be 1\r\n        }\r\n\r\n        It 'handles empty string' {\r\n            Compare-Version '7.0.4-9' '' | Should -Be -1\r\n        }\r\n\r\n        It 'handles equal versions' {\r\n            function get_config { $null }\r\n            Compare-Version '12.0' '12.0' | Should -Be 0\r\n            Compare-Version '7.0.4-9' '7.0.4-9' | Should -Be 0\r\n            Compare-Version 'nightly-20190801' 'nightly' | Should -Be 0\r\n            Compare-Version 'nightly-20190801' 'nightly-20200801' | Should -Be 0\r\n        }\r\n\r\n        It \"handles nightly versions with 'update_nightly'\" {\r\n            function get_config { $true }\r\n            Mock Get-Date { '20200801' }\r\n            Compare-Version 'nightly-20200801' 'nightly' | Should -Be 0\r\n            Compare-Version 'nightly-20200730' 'nightly' | Should -Be 1\r\n            Compare-Version 'nightly-20200730' 'nightly-20200801' | Should -Be 1\r\n            Compare-Version 'nightly-20200802' 'nightly' | Should -Be -1\r\n            Compare-Version 'nightly-20200802' 'nightly-20200801' | Should -Be -1\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/bin/init.ps1",
    "content": "#Requires -Version 5.1\r\nWrite-Output \"PowerShell: $($PSVersionTable.PSVersion)\"\r\nWrite-Output 'Check and install testsuite dependencies ...'\r\nif (Get-InstalledModule -Name Pester -MinimumVersion 5.2 -MaximumVersion 5.99 -ErrorAction SilentlyContinue) {\r\n    Write-Output 'Pester 5 is already installed.'\r\n} else {\r\n    Write-Output 'Installing Pester 5 ...'\r\n    Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name Pester -MinimumVersion 5.2 -MaximumVersion 5.99 -SkipPublisherCheck\r\n}\r\nif (Get-InstalledModule -Name PSScriptAnalyzer -MinimumVersion 1.17 -ErrorAction SilentlyContinue) {\r\n    Write-Output 'PSScriptAnalyzer is already installed.'\r\n} else {\r\n    Write-Output 'Installing PSScriptAnalyzer ...'\r\n    Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name PSScriptAnalyzer -SkipPublisherCheck\r\n}\r\nif (Get-InstalledModule -Name BuildHelpers -MinimumVersion 2.0 -ErrorAction SilentlyContinue) {\r\n    Write-Output 'BuildHelpers is already installed.'\r\n} else {\r\n    Write-Output 'Installing BuildHelpers ...'\r\n    Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name BuildHelpers -SkipPublisherCheck\r\n}\r\n"
  },
  {
    "path": "test/bin/test.ps1",
    "content": "#Requires -Version 5.1\r\n#Requires -Modules @{ ModuleName = 'BuildHelpers'; ModuleVersion = '2.0.1' }\r\n#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.2.0' }\r\n#Requires -Modules @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.17.1' }\r\nparam(\r\n    [String] $TestPath = (Convert-Path \"$PSScriptRoot\\..\")\r\n)\r\n\r\n$pesterConfig = New-PesterConfiguration -Hashtable @{\r\n    Run    = @{\r\n        Path     = $TestPath\r\n        PassThru = $true\r\n    }\r\n    Output = @{\r\n        Verbosity = 'Detailed'\r\n    }\r\n}\r\n$excludes = @()\r\n\r\nif ($IsLinux -or $IsMacOS) {\r\n    Write-Warning 'Skipping Windows-only tests on Linux/macOS'\r\n    $excludes += 'Windows'\r\n}\r\n\r\nif ($env:CI -eq $true) {\r\n    Write-Host \"Load 'BuildHelpers' environment variables ...\"\r\n    Set-BuildEnvironment -Force\r\n\r\n    # Check if tests are called from the Core itself, if so, adding excludes\r\n    if ($TestPath -eq (Convert-Path \"$PSScriptRoot\\..\")) {\r\n        if ($env:BHCommitMessage -match '!linter') {\r\n            Write-Warning \"Skipping code linting per commit flag '!linter'\"\r\n            $excludes += 'Linter'\r\n        }\r\n\r\n        $changedScripts = (Get-GitChangedFile -Include '*.ps1', '*.psd1', '*.psm1' -Commit $env:BHCommitHash)\r\n        if (!$changedScripts) {\r\n            Write-Warning \"Skipping tests and code linting for PowerShell scripts because they didn't change\"\r\n            $excludes += 'Linter'\r\n            $excludes += 'Scoop'\r\n        }\r\n\r\n        if (!($changedScripts -like '*decompress.ps1') -and !($changedScripts -like '*Decompress.Tests.ps1')) {\r\n            Write-Warning \"Skipping tests and code linting for decompress.ps1 files because it didn't change\"\r\n            $excludes += 'Decompress'\r\n        }\r\n\r\n        if ('Decompress' -notin $excludes -and 'Windows' -notin $excludes) {\r\n            Write-Host 'Install decompress dependencies ...'\r\n\r\n            Write-Host (7z.exe | Select-String -Pattern '7-Zip').ToString()\r\n\r\n            $env:SCOOP_HELPERS_PATH = 'C:\\projects\\helpers'\r\n            if (!(Test-Path $env:SCOOP_HELPERS_PATH)) {\r\n                New-Item -ItemType Directory -Path $env:SCOOP_HELPERS_PATH | Out-Null\r\n            }\r\n\r\n            $env:SCOOP_LESSMSI_PATH = \"$env:SCOOP_HELPERS_PATH\\lessmsi\\lessmsi.exe\"\r\n            if (!(Test-Path $env:SCOOP_LESSMSI_PATH)) {\r\n                $source = 'https://github.com/activescott/lessmsi/releases/download/v1.10.0/lessmsi-v1.10.0.zip'\r\n                $destination = \"$env:SCOOP_HELPERS_PATH\\lessmsi.zip\"\r\n                Invoke-WebRequest -Uri $source -OutFile $destination\r\n                & 7z.exe x \"$env:SCOOP_HELPERS_PATH\\lessmsi.zip\" -o\"$env:SCOOP_HELPERS_PATH\\lessmsi\" -y | Out-Null\r\n            }\r\n\r\n            $env:SCOOP_INNOUNP_PATH = \"$env:SCOOP_HELPERS_PATH\\innounp\\innounp.exe\"\r\n            if (!(Test-Path $env:SCOOP_INNOUNP_PATH)) {\r\n                $source = 'https://raw.githubusercontent.com/ScoopInstaller/Binary/master/innounp/innounp050.rar'\r\n                $destination = \"$env:SCOOP_HELPERS_PATH\\innounp.rar\"\r\n                Invoke-WebRequest -Uri $source -OutFile $destination\r\n                & 7z.exe x \"$env:SCOOP_HELPERS_PATH\\innounp.rar\" -o\"$env:SCOOP_HELPERS_PATH\\innounp\" -y | Out-Null\r\n            }\r\n        }\r\n    }\r\n\r\n    # Display CI environment variables\r\n    $buildVariables = (Get-ChildItem -Path 'Env:').Where({ $_.Name -match '^(?:BH|CI(?:_|$)|APPVEYOR|GITHUB_|RUNNER_|SCOOP_)' })\r\n    $details = $buildVariables |\r\n        Where-Object -FilterScript { $_.Name -notmatch 'EMAIL' } |\r\n        Sort-Object -Property 'Name' |\r\n        Format-Table -AutoSize -Property 'Name', 'Value' |\r\n        Out-String\r\n    Write-Host 'CI variables:'\r\n    Write-Host $details -ForegroundColor DarkGray\r\n}\r\n\r\nif ($excludes.Length -gt 0) {\r\n    $pesterConfig.Filter.ExcludeTag = $excludes\r\n}\r\n\r\nif ($env:BHBuildSystem -eq 'AppVeyor') {\r\n    # AppVeyor\r\n    $resultsXml = \"$PSScriptRoot\\TestResults.xml\"\r\n    $pesterConfig.TestResult.Enabled = $true\r\n    $pesterConfig.TestResult.OutputPath = $resultsXml\r\n    $result = Invoke-Pester -Configuration $pesterConfig\r\n    Add-TestResultToAppveyor -TestFile $resultsXml\r\n} else {\r\n    # GitHub Actions / Local\r\n    $result = Invoke-Pester -Configuration $pesterConfig\r\n}\r\n\r\nexit $result.FailedCount\r\n"
  },
  {
    "path": "test/fixtures/format/formatted/1-easy.json",
    "content": "{\r\n    \"bin\": \"single\"\r\n}\r\n"
  },
  {
    "path": "test/fixtures/format/formatted/2-whitespaces-mess.json",
    "content": "{\r\n    \"version\": \"0.5.18\",\r\n    \"url\": \"https://whatever\",\r\n    \"hash\": \"whatever\",\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"installer\": {\r\n                \"script\": [\r\n                    \"Do something\",\r\n                    \"cosi\"\r\n                ]\r\n            }\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/fixtures/format/formatted/3-array-with-single-and-multi.json",
    "content": "{\r\n    \"homepage\": \"http://www.7-zip.org/\",\r\n    \"description\": \"A multi-format file archiver with high compression ratios\",\r\n    \"license\": {\r\n        \"identifier\": \"LGPL-2.0-only,BSD-3-Clause\",\r\n        \"url\": \"https://www.7-zip.org/license.txt\"\r\n    },\r\n    \"version\": \"18.05\",\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"url\": \"https://7-zip.org/a/7z1805-x64.msi\",\r\n            \"hash\": \"898c1ca0015183fe2ba7d55cacf0a1dea35e873bf3f8090f362a6288c6ef08d7\"\r\n        },\r\n        \"32bit\": {\r\n            \"url\": \"https://7-zip.org/a/7z1805.msi\",\r\n            \"hash\": \"c554238bee18a03d736525e06d9258c9ecf7f64ead7c6b0d1eb04db2c0de30d0\"\r\n        }\r\n    },\r\n    \"extract_dir\": \"Files/7-Zip\",\r\n    \"bin\": [\r\n        \"single\",\r\n        [\r\n            \"7z.exe\",\r\n            \"cosi\"\r\n        ],\r\n        [\r\n            \"7z.exe\",\r\n            \"cosi\",\r\n            \"param\",\r\n            \"icon\"\r\n        ],\r\n        [\r\n            \"7z.exe\",\r\n            \"empty\",\r\n            \"\",\r\n            \"\"\r\n        ],\r\n        \"singtwo\"\r\n    ],\r\n    \"checkver\": \"Download 7-Zip ([\\\\d.]+)\",\r\n    \"autoupdate\": {\r\n        \"architecture\": {\r\n            \"64bit\": {\r\n                \"url\": \"https://7-zip.org/a/7z$cleanVersion-x64.msi\"\r\n            },\r\n            \"32bit\": {\r\n                \"url\": \"https://7-zip.org/a/7z$cleanVersion.msi\"\r\n            }\r\n        }\r\n    },\r\n    \"shortcuts\": [\r\n        [\r\n            \"7zFM.exe\",\r\n            \"7-Zip\"\r\n        ],\r\n        [\r\n            \"name with spaces.exe\",\r\n            \"Shortcut with spaces in name\"\r\n        ]\r\n    ]\r\n}\r\n"
  },
  {
    "path": "test/fixtures/format/formatted/4-script-block.json",
    "content": "{\r\n    \"version\": \"1.0.6\",\r\n    \"description\": \"Rambox Pro. Free, Open Source and Cross Platform messaging and emailing app that combines common web applications into one.\",\r\n    \"homepage\": \"https://rambox.pro/\",\r\n    \"url\": \"https://github.com/ramboxapp/download/releases/download/v1.0.6/RamboxPro-1.0.6-win.exe#/cosi.7z\",\r\n    \"hash\": \"sha512:f4a1b5e12ae15c9a1339fef56b0522b6619d6c23b0ab806f128841c2ba7ce9d9c997fea81f5bc4a24988aed672a4415ff353542535dc7869b5e496f2f1e1efff\",\r\n    \"extract_dir\": \"\\\\$PLUGINSDIR\",\r\n    \"pre_install\": \"Get-ChildItem \\\"$dir\\\" -Exclude 'app-64.7z', 'app-32.7z' | Remove-Item -Force -Recurse\",\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"installer\": {\r\n                \"script\": \"Expand-7zipArchive \\\"$dir\\\\app-64.7z\\\" \\\"$dir\\\"\"\r\n            }\r\n        },\r\n        \"32bit\": {\r\n            \"installer\": {\r\n                \"script\": \"Expand-7zipArchive \\\"$dir\\\\app-32.7z\\\" \\\"$dir\\\"\"\r\n            }\r\n        }\r\n    },\r\n    \"post_install\": \"Remove-Item \\\"$dir\\\\app-64.7z\\\", \\\"$dir\\\\app-32.7z\\\"\",\r\n    \"shortcuts\": [\r\n        [\r\n            \"RamboxPro.exe\",\r\n            \"RamboxPro\"\r\n        ]\r\n    ],\r\n    \"checkver\": {\r\n        \"github\": \"https://github.com/ramboxapp/download/\"\r\n    },\r\n    \"autoupdate\": {\r\n        \"url\": \"https://github.com/ramboxapp/download/releases/download/v$version/RamboxPro-$version-win.exe#/cosi.7z\",\r\n        \"hash\": {\r\n            \"url\": \"https://github.com/ramboxapp/download/releases/download/v$version/latest.yml\",\r\n            \"find\": \"sha512:\\\\s+(.*)\"\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/fixtures/format/unformatted/1-easy.json",
    "content": "{ \"bin\": [\"single\"]}\r\n"
  },
  {
    "path": "test/fixtures/format/unformatted/2-whitespaces-mess.json",
    "content": "{\r\n    \"version\": \"0.5.18\",\r\n    \"url\": \"https://whatever\",\r\n\r\n    \"hash\": \"whatever\",\r\n  \"architecture\": {\r\n  \t\t\t     \"64bit\": {          \"installer\": {\r\n\r\n   \"script\": [\r\n                    \"Do something\"    , \"cosi\"\r\n                ]\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n"
  },
  {
    "path": "test/fixtures/format/unformatted/3-array-with-single-and-multi.json",
    "content": "{\r\n    \"homepage\": \"http://www.7-zip.org/\",\r\n    \"description\": \"A multi-format file archiver with high compression ratios\",\r\n    \"license\": {\r\n        \"identifier\": \"LGPL-2.0-only,BSD-3-Clause\",\r\n        \"url\": \"https://www.7-zip.org/license.txt\"\r\n    },\r\n    \"version\": \"18.05\",\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"url\": \"https://7-zip.org/a/7z1805-x64.msi\",\r\n            \"hash\": [\r\n                \"898c1ca0015183fe2ba7d55cacf0a1dea35e873bf3f8090f362a6288c6ef08d7\"\r\n            ]\r\n        },\r\n        \"32bit\": {\r\n            \"url\": \"https://7-zip.org/a/7z1805.msi\",\r\n            \"hash\": \"c554238bee18a03d736525e06d9258c9ecf7f64ead7c6b0d1eb04db2c0de30d0\"\r\n        }\r\n    },\r\n    \"extract_dir\": \"Files/7-Zip\",\r\n    \"bin\": [\r\n        [\r\n            \"single\"\r\n        ],\r\n        [\r\n            \"7z.exe\",\r\n            \"cosi\"\r\n        ],\r\n                        [\r\n            \"7z.exe\",\r\n            \"cosi\",\r\n    \"param\",\r\n            \"icon\"\r\n        ],\r\n        [\r\n                        \"7z.exe\",\r\n            \"empty\",\r\n     \"\",\r\n              \"\"\r\n        ],\r\n        [\r\n            \"singtwo\"\r\n        ]\r\n    ],\r\n    \"checkver\":                       \"Download 7-Zip ([\\\\d.]+)\",\r\n    \"autoupdate\": {\r\n        \"architecture\": {\r\n            \"64bit\": {\r\n                \"url\": \"https://7-zip.org/a/7z$cleanVersion-x64.msi\"\r\n            },        \"32bit\": {\r\n                \"url\": \"https://7-zip.org/a/7z$cleanVersion.msi\"\r\n       }\r\n        }\r\n    },\r\n    \"shortcuts\": [\r\n        [   \"7zFM.exe\",\r\n            \"7-Zip\"\r\n], [\"name with spaces.exe\", \"Shortcut with spaces in name\"]    ]}\r\n"
  },
  {
    "path": "test/fixtures/format/unformatted/4-script-block.json",
    "content": "{\r\n    \"version\": \"1.0.6\",\r\n    \"description\": \"Rambox Pro. Free, Open Source and Cross Platform messaging and emailing app that combines common web applications into one.\",\r\n    \"homepage\": \"https://rambox.pro/\",\r\n    \"url\": \"https://github.com/ramboxapp/download/releases/download/v1.0.6/RamboxPro-1.0.6-win.exe#/cosi.7z\",\r\n    \"hash\": \"sha512:f4a1b5e12ae15c9a1339fef56b0522b6619d6c23b0ab806f128841c2ba7ce9d9c997fea81f5bc4a24988aed672a4415ff353542535dc7869b5e496f2f1e1efff\",\r\n    \"extract_dir\": \"\\\\$PLUGINSDIR\",\r\n    \"pre_install\": [\"Get-ChildItem \\\"$dir\\\" -Exclude 'app-64.7z', 'app-32.7z' | Remove-Item -Force -Recurse\"],\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"installer\": {\r\n                \"script\": [\r\n                    \"Expand-7zipArchive \\\"$dir\\\\app-64.7z\\\" \\\"$dir\\\"\"\r\n                ]\r\n            }\r\n        },\r\n        \"32bit\": {\r\n            \"installer\": {\r\n                \"script\": [\r\n                    \"Expand-7zipArchive \\\"$dir\\\\app-32.7z\\\" \\\"$dir\\\"\"\r\n                ]\r\n            }\r\n        }\r\n    },\r\n    \"post_install\": [\"Remove-Item \\\"$dir\\\\app-64.7z\\\", \\\"$dir\\\\app-32.7z\\\"\"],\r\n    \"shortcuts\": [\r\n        [\r\n            \"RamboxPro.exe\",\r\n            \"RamboxPro\"\r\n        ]\r\n    ],\r\n    \"checkver\": {\r\n        \"github\": \"https://github.com/ramboxapp/download/\"\r\n    },\r\n    \"autoupdate\": {\r\n        \"url\": \"https://github.com/ramboxapp/download/releases/download/v$version/RamboxPro-$version-win.exe#/cosi.7z\",\r\n        \"hash\": {\r\n            \"url\": \"https://github.com/ramboxapp/download/releases/download/v$version/latest.yml\",\r\n            \"find\": \"sha512:\\\\s+(.*)\"\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/fixtures/is_directory/i_am_a_directory/.gitkeep",
    "content": "need some content to not fail tests\r\n"
  },
  {
    "path": "test/fixtures/is_directory/i_am_a_file.txt",
    "content": "dummy content\r\n"
  },
  {
    "path": "test/fixtures/manifest/broken_schema.json",
    "content": "{\r\n    \"$id\": \"http://scoop.sh/draft/schema#\",\r\n    \"$schema\": \"http://scoop.sh/draft/schema#\",\r\n    \"title\": \"scoop app manifest schema\",\r\n    \"type\": \"object\"\r\n    \"properties\": {\r\n      \"version\": {\r\n        \"type\": \"string\"\r\n      }\r\n    }\r\n}\r\n"
  },
  {
    "path": "test/fixtures/manifest/broken_wget.json",
    "content": "{\r\n    \"homepage\": \"https://eternallybored.org/misc/wget/\",\r\n    \"license\": \"GPL3\",\r\n    \"version\": \"1.16.3\"\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"url\": [\r\n                \"https://eternallybored.org/misc/wget/wget-1.16.3-win64.zip\",\r\n                \"http://curl.haxx.se/ca/cacert.pem\"\r\n            ],\r\n            \"hash\": [\r\n                \"85e5393ffd473f7bec40b57637fd09b6808df86c06f846b6885b261a8acac8c5\",\r\n                \"\"\r\n            ]\r\n        },\r\n        \"32bit\": {\r\n            \"url\": [\r\n                \"https://eternallybored.org/misc/wget/wget-1.16.3-win32.zip\",\r\n                \"http://curl.haxx.se/ca/cacert.pem\"\r\n            ],\r\n            \"hash\": [\r\n                \"2ef82af3070abfdaf3862baff0bffdcb3c91c8d75e2f02c8720d90adb9d7a8f7\",\r\n                \"\"\r\n            ]\r\n        }\r\n    },\r\n    \"bin\": \"wget.exe\",\r\n    \"post_install\": \"\\\"ca_certificate=$dir\\\\cacert.pem\\\" | out-file $dir\\\\wget.ini -encoding default\"\r\n}\r\n"
  },
  {
    "path": "test/fixtures/manifest/invalid_wget.json",
    "content": "{\r\n    \"homepage\": \"https://eternallybored.org/misc/wget/\",\r\n    \"randomproperty\": \"should fail\",\r\n    \"license\": \"GPL3\",\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"url\": [\r\n                \"https://eternallybored.org/misc/wget/wget-$version-win64.zip\",\r\n                \"http://curl.haxx.se/ca/cacert.pem\"\r\n            ],\r\n            \"hash\": [\r\n                \"85e5393ffd473f7bec40b57637fd09b6808df86c06f846b6885b261a8acac8c5\",\r\n                \"\"\r\n            ]\r\n        },\r\n        \"32bit\": {\r\n            \"url\": [\r\n                \"https://eternallybored.org/misc/wget/wget-$version-win32.zip\",\r\n                \"http://curl.haxx.se/ca/cacert.pem\"\r\n            ],\r\n            \"hash\": [\r\n                \"2ef82af3070abfdaf3862baff0bffdcb3c91c8d75e2f02c8720d90adb9d7a8f7\",\r\n                \"\"\r\n            ]\r\n        }\r\n    },\r\n    \"bin\": \"wget.exe\",\r\n    \"post_install\": \"\\\"ca_certificate=$dir\\\\cacert.pem\\\" | out-file $dir\\\\wget.ini -encoding default\"\r\n}\r\n"
  },
  {
    "path": "test/fixtures/manifest/wget.json",
    "content": "{\r\n    \"homepage\": \"https://eternallybored.org/misc/wget/\",\r\n    \"license\": \"GPL3\",\r\n    \"version\": \"1.16.3\",\r\n    \"architecture\": {\r\n        \"64bit\": {\r\n            \"url\": [\r\n                \"https://eternallybored.org/misc/wget/wget-1.16.3-win64.zip\",\r\n                \"http://curl.haxx.se/ca/cacert.pem\"\r\n            ],\r\n            \"hash\": [\r\n                \"85e5393ffd473f7bec40b57637fd09b6808df86c06f846b6885b261a8acac8c5\",\r\n                \"\"\r\n            ]\r\n        },\r\n        \"32bit\": {\r\n            \"url\": [\r\n                \"https://eternallybored.org/misc/wget/wget-1.16.3-win32.zip\",\r\n                \"http://curl.haxx.se/ca/cacert.pem\"\r\n            ],\r\n            \"hash\": [\r\n                \"2ef82af3070abfdaf3862baff0bffdcb3c91c8d75e2f02c8720d90adb9d7a8f7\",\r\n                \"\"\r\n            ]\r\n        }\r\n    },\r\n    \"bin\": \"wget.exe\",\r\n    \"post_install\": \"\\\"ca_certificate=$dir\\\\cacert.pem\\\" | out-file $dir\\\\wget.ini -encoding default\"\r\n}\r\n"
  },
  {
    "path": "test/fixtures/movedir/user/_tmp/subdir/test.txt",
    "content": "this is the one\r\n"
  },
  {
    "path": "test/fixtures/movedir/user/_tmp/test.txt",
    "content": "testing\r\n"
  },
  {
    "path": "test/fixtures/movedir/user with 'quote/_tmp/subdir/test.txt",
    "content": "this is the one\r\n"
  },
  {
    "path": "test/fixtures/movedir/user with 'quote/_tmp/test.txt",
    "content": "testing\r\n"
  },
  {
    "path": "test/fixtures/movedir/user with space/_tmp/subdir/test.txt",
    "content": "this is the one\r\n"
  },
  {
    "path": "test/fixtures/movedir/user with space/_tmp/test.txt",
    "content": "testing\r\n"
  },
  {
    "path": "test/fixtures/shim/shim-test.ps1",
    "content": "'Hello, world!'\r\n"
  },
  {
    "path": "test/fixtures/shim/user with 'quote/shim-test.ps1",
    "content": "'Hello, world!'\r\n"
  }
]