As you may know, the recent move to deprecate Jenkins has broken some auto-updaters. I can't find any Windows auto-updaters that work on my (Windows 11) system. I'm a systems engineer and PowerShell fanboy in "real life," so I decided to explore the possibilities of a PowerShell script. I found some code online, "borrowed" it, tweaked it to my liking, and here we are:
I'm not claiming this script is perfect. It can be improved, but it does get the job done. When you run it, it'll download the latest daily build to the same directory in which the script is located. It'll copy the build to "KoLmafia-latest.jar" (for convenience). Lastly, it'll keep the last three builds you've downloaded and delete any older ones.
Share and enjoy, and please feel free to share any improvements!
NOTE: Buckets reminded me about PowerShell execution policies. By default, your Windows PC won't run a PowerShell script. This safety measure is a good thing for my mother and other folks who are uncomfortable with technology, but it gets in our way. To allow your scripts to run, you will need to type the following command at a PowerShell prompt with Administrator privileges:
This setting will require any remotely-hosted scripts to be cryptographically signed, but local scripts (like the above) will run just fine. Other settings exist and will work, but I've found "RemoteSigned" to be a fair compromise between security and usability.
Code:
$repoName = "kolmafia/kolmafia"
$assetPattern = "*.jar"
$extractDirectory = Split-Path -Parent $PSCommandPath
$releasesUri = "https://api.github.com/repos/$repoName/releases/latest"
$asset = (Invoke-WebRequest $releasesUri | ConvertFrom-Json).assets | Where-Object name -like $assetPattern
$downloadUri = $asset.browser_download_url
$mafiaVersions = Get-ChildItem -File "KoLmafia-*.jar" | Where-Object {!($_.Name -ilike "*latest*" )} | Sort-Object Name -Descending
$latestName = ($mafiaVersions[0]).Name
if ($latestName -eq $asset.name) {
Write-Output "You already have the latest version of KoLmafia! This script will now exit."
Start-Sleep -Seconds 5
} else {
$extractPath = [System.IO.Path]::Combine($extractDirectory, $asset.name)
Write-Output "Downloading to: $extractPath"
try {
Invoke-WebRequest -Uri $downloadUri -Out $extractPath
}
catch {
Write-Warning "Something went terribly wrong!"
Write-Output "Checking URL: $relasesUri"
Write-Output "Checking for: $assetPattern"
Write-Output "Downloading to: $extractDirectory"
Write-Output "That's all the information I have for you. Go forth and debug!"
}
}
$i = 0
$latestPath = [System.IO.Path]::Combine($extractDirectory, "KoLmafia-latest.jar")
$mafiaVersions = Get-ChildItem -File "KoLmafia-*.jar" | Sort-Object Name -Descending
ForEach ($mafiaVersion in $mafiaVersions) {
if ($i -eq 1) {
$mafiaVersion | Copy-Item -Destination $latestPath -Force
}
if ($i -gt 3) {
$mafiaVersion | Remove-Item -Force
}
$i++
}
I'm not claiming this script is perfect. It can be improved, but it does get the job done. When you run it, it'll download the latest daily build to the same directory in which the script is located. It'll copy the build to "KoLmafia-latest.jar" (for convenience). Lastly, it'll keep the last three builds you've downloaded and delete any older ones.
Share and enjoy, and please feel free to share any improvements!
NOTE: Buckets reminded me about PowerShell execution policies. By default, your Windows PC won't run a PowerShell script. This safety measure is a good thing for my mother and other folks who are uncomfortable with technology, but it gets in our way. To allow your scripts to run, you will need to type the following command at a PowerShell prompt with Administrator privileges:
Code:
Set-ExecutionPolicy RemoteSigned
Last edited: