Created
November 13, 2021 03:41
-
-
Save Vresod/8352e5306161425c249d3c798612ae01 to your computer and use it in GitHub Desktop.
Automatically add MultiMC instances to the Windows start menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$SourceExe, | |
[string]$DestinationPath, | |
[bool]$Save = $true | |
) | |
$Path = "$(Resolve-Path $DestinationPath.SubString(0, $DestinationPath.LastIndexOf('\')))\$($DestinationPath.Split('\')[-1])" | |
$WshShell = New-Object -ComObject WScript.Shell | |
$Shortcut = $WshShell.CreateShortcut($Path) | |
$Shortcut.TargetPath = $SourceExe | |
if($Save) {$Shortcut.Save()} | |
$Shortcut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( [string]$MultiMCPath ) | |
$StartMenu = New-Item -ItemType Directory -Path "$env:AppData\Microsoft\Windows\Start Menu\Programs\MultiMC" -ErrorAction SilentlyContinue | |
if ($null -eq $StartMenu) { | |
$StartMenu = Get-Item -Path "$env:AppData\Microsoft\Windows\Start Menu\Programs\MultiMC" | |
} | |
$null = .\New-Shortcut.ps1 -SourceExe "$MultiMCPath\MultiMC.exe" -DestinationPath "$($StartMenu.FullName)\MultiMC.lnk" | |
$instances = Get-ChildItem "$MultiMCPath\instances" -Directory -Exclude "_MMC_TEMP" | |
for ($i = 0; $i -lt $instances.Length; $i++) { | |
# if ([bool](Get-Item "$($instances[$i])\instance.cfg" -ErrorAction SilentlyContinue)) { | |
# continue | |
# } | |
$FancyInstanceName = (Select-String -Path "$($instances[$i])\instance.cfg" -Pattern "name=" -Raw).Split("=")[1] | |
$StoredInstanceName = ($instances[$i]).Name | |
$InstanceIcon = (Select-String -Path "$($instances[$i])\instance.cfg" -Pattern "IconKey=" -Raw).Split("=")[1] | |
$IconExists = [bool](Get-Item "$MultiMCPath\icons\$InstanceIcon" -ErrorAction SilentlyContinue) | |
$Shortcut = .\New-Shortcut.ps1 -SourceExe "$MultiMCPath\MultiMC.exe" -DestinationPath "$($StartMenu.FullName)\$FancyInstanceName.lnk" | |
$Shortcut.arguments = "-l $StoredInstanceName" | |
Write-Output "Writing shortcut: $StoredInstanceName" | |
if($IconExists) { | |
# the only "external" command this script relies on | |
magick convert -resize !256x256 "$MultiMCPath\icons\$InstanceIcon" "$MultiMCPath\icons\$InstanceIcon.ico" | |
$Shortcut.IconLocation = "$MultiMCPath\icons\$InstanceIcon.ico,0" | |
} else { | |
$InstanceVersion = ((ConvertFrom-Json ([string](Get-Content "$($instances[$i])\mmc-pack.json"))).components|ForEach-Object {if($_.uid -eq "net.minecraft") {$_.version}}) | |
magick convert -background "#0000" -fill black -gravity center -size 256x128 caption:"$InstanceVersion" ".\multimc.ico" +swap -gravity south -composite "$MultiMCPath\icons\$InstanceVersion.ico" | |
$Shortcut.IconLocation = "$MultiMCPath\icons\$InstanceVersion.ico,0" | |
} | |
$Shortcut.Save() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment