[CmdletBinding()] param( [string]$Version = 'latest', [string]$Repo = 'yebisu0529-ship-it/RustEndTask', [string]$InstallDir = '', [switch]$NoStartup, [switch]$NoPath, [switch]$NoStart, [switch]$Uninstall ) $prevErrorAction = $ErrorActionPreference $prevSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol $ErrorActionPreference = 'Stop' [Net.ServicePointManager]::SecurityProtocol = $prevSecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $isJa = ([System.Globalization.CultureInfo]::CurrentUICulture.TwoLetterISOLanguageName -eq 'ja') function Decode-Utf8([string]$B64) { [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($B64)) } function Say([string]$En, [string]$JaB64, [string]$Suffix = '') { if ($isJa) { Write-Host ((Decode-Utf8 $JaB64) + $Suffix) } else { Write-Host ($En + $Suffix) } } $prevInstallDir = $env:RET_INSTALL_DIR $prevOutEnc = [Console]::OutputEncoding $tmpDir = $null try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 if (-not [string]::IsNullOrWhiteSpace($InstallDir)) { $env:RET_INSTALL_DIR = $InstallDir } $effectiveRoot = if (-not [string]::IsNullOrWhiteSpace($InstallDir)) { $InstallDir } else { Join-Path $env:LOCALAPPDATA 'RustEndTask' } if ($Uninstall) { $installedRet = Join-Path $effectiveRoot 'bin\ret.exe' if (Test-Path -LiteralPath $installedRet) { & $installedRet uninstall if ($LASTEXITCODE -ne 0) { throw "ret uninstall failed with exit code $LASTEXITCODE" } Say 'RustEndTask uninstalled.' 'UnVzdEVuZFRhc2sg44KS44Ki44Oz44Kk44Oz44K544OI44O844Or44GX44G+44GX44Gf44CC' return } throw "ret.exe not found at $installedRet" } $retExe = $null $scriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { '' } if ($scriptDir) { $localRet = Join-Path $scriptDir 'ret.exe' $localHost = Join-Path $scriptDir 'ret-host.exe' if ((Test-Path -LiteralPath $localRet) -and (Test-Path -LiteralPath $localHost)) { $retExe = $localRet } } if (-not $retExe) { $apiUrl = if ($Version -eq 'latest') { "https://api.github.com/repos/$Repo/releases/latest" } else { $tag = if ($Version.StartsWith('v')) { $Version } else { "v$Version" } "https://api.github.com/repos/$Repo/releases/tags/$tag" } Say "Fetching RustEndTask release metadata ($Version)..." 'UnVzdEVuZFRhc2sg44Gu44Oq44Oq44O844K55oOF5aCx44KS5Y+W5b6X44GX44Gm44GE44G+44GZ' " ($Version)..." $headers = @{ 'User-Agent' = 'RustEndTask-Installer' } $release = Invoke-RestMethod -Uri $apiUrl -Headers $headers $zipAsset = $release.assets | Where-Object { $_.name -like '*x86_64-pc-windows-msvc.zip' } | Select-Object -First 1 $sumsAsset = $release.assets | Where-Object { $_.name -eq 'SHA256SUMS.txt' } | Select-Object -First 1 if (-not $zipAsset) { throw "Release $($release.tag_name) does not contain a Windows x64 zip asset." } if (-not $sumsAsset) { throw "Release $($release.tag_name) does not contain SHA256SUMS.txt." } $tmpDir = Join-Path ([IO.Path]::GetTempPath()) ('rustendtask-' + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null $zipPath = Join-Path $tmpDir $zipAsset.name $sumsPath = Join-Path $tmpDir 'SHA256SUMS.txt' if ($isJa) { Write-Host ($zipAsset.name + (Decode-Utf8 '44KS44OA44Km44Oz44Ot44O844OJ44GX44Gm44GE44G+44GZLi4u')) } else { Write-Host "Downloading $($zipAsset.name)..." } Invoke-WebRequest -Uri $zipAsset.browser_download_url -OutFile $zipPath -Headers $headers -UseBasicParsing Invoke-WebRequest -Uri $sumsAsset.browser_download_url -OutFile $sumsPath -Headers $headers -UseBasicParsing $expectedHash = $null foreach ($line in (Get-Content -LiteralPath $sumsPath)) { if ($line -match '^\s*([0-9a-fA-F]{64})\s+\*?(.+?)\s*$') { if ($Matches[2] -eq $zipAsset.name) { $expectedHash = $Matches[1].ToLowerInvariant() break } } } if (-not $expectedHash) { throw "SHA-256 entry for $($zipAsset.name) not found in SHA256SUMS.txt." } $actualHash = (Get-FileHash -LiteralPath $zipPath -Algorithm SHA256).Hash.ToLowerInvariant() if ($actualHash -ne $expectedHash) { throw "SHA-256 mismatch for $($zipAsset.name): expected $expectedHash, got $actualHash" } Say "SHA-256 verified ($($release.tag_name))." 'U0hBLTI1NiDmpJzoqLzjgavmiJDlip/jgZfjgb7jgZfjgZ8=' " ($($release.tag_name))." $extractDir = Join-Path $tmpDir 'extracted' Expand-Archive -LiteralPath $zipPath -DestinationPath $extractDir -Force $foundRet = Get-ChildItem -LiteralPath $extractDir -Filter 'ret.exe' -Recurse -File | Select-Object -First 1 $foundHost = Get-ChildItem -LiteralPath $extractDir -Filter 'ret-host.exe' -Recurse -File | Select-Object -First 1 if (-not $foundRet -or -not $foundHost) { throw 'Downloaded archive is missing ret.exe or ret-host.exe.' } if ($foundRet.DirectoryName -ne $foundHost.DirectoryName) { Copy-Item -LiteralPath $foundHost.FullName -Destination (Join-Path $foundRet.DirectoryName 'ret-host.exe') -Force } $retExe = $foundRet.FullName } $installArgs = @('install') if ($NoStartup) { $installArgs += '--no-startup' } if ($NoPath) { $installArgs += '--no-path' } if ($NoStart) { $installArgs += '--no-start' } & $retExe @installArgs if ($LASTEXITCODE -ne 0) { throw "ret install failed with exit code $LASTEXITCODE" } $binDir = Join-Path $effectiveRoot 'bin' if (-not $NoPath) { $parts = ($env:Path -split ';') | Where-Object { $_ } if ($parts -notcontains $binDir) { $env:Path = "$env:Path;$binDir" } } if ($NoStart) { Say "Done! Files installed (ret-host.exe not started due to -NoStart). Run 'ret start' to start monitoring." '5a6M5LqG44GX44G+44GX44Gf44CC44OV44Kh44Kk44Or44KS6YWN572u44GX44G+44GX44Gf77yILU5vU3RhcnQg5oyH5a6a44Gu44Gf44KB5bi46aeQ44OX44Ot44K744K544Gv5pyq6LW35YuV44Gn44GZ77yJ44CC6ZaL5aeL44GZ44KL44Gr44GvIHJldCBzdGFydCDjgpLlrp/ooYzjgZfjgabjgY/jgaDjgZXjgYTjgII=' } else { Say 'Done! Right-click any running app on your taskbar to use End task.' '5a6M5LqG44GX44G+44GX44Gf77yB44K/44K544Kv44OQ44O85LiK44Gu44Ki44OX44Oq44KS5Y+z44Kv44Oq44OD44Kv44GZ44KL44Go44CM44K/44K544Kv44KS57WC5LqG44CN44GM44GZ44GQ5L2/44GI44G+44GZ44CC' } } finally { $ErrorActionPreference = $prevErrorAction [Net.ServicePointManager]::SecurityProtocol = $prevSecurityProtocol [Console]::OutputEncoding = $prevOutEnc if ($null -eq $prevInstallDir) { Remove-Item Env:RET_INSTALL_DIR -ErrorAction SilentlyContinue } else { $env:RET_INSTALL_DIR = $prevInstallDir } if ($tmpDir -and (Test-Path -LiteralPath $tmpDir)) { Remove-Item -LiteralPath $tmpDir -Recurse -Force -ErrorAction SilentlyContinue } }