Skip to content

Instantly share code, notes, and snippets.

@GhostTypes
Created August 8, 2022 17:29
Show Gist options
  • Select an option

  • Save GhostTypes/08b6f1014d8c78f615375cc574ee2461 to your computer and use it in GitHub Desktop.

Select an option

Save GhostTypes/08b6f1014d8c78f615375cc574ee2461 to your computer and use it in GitHub Desktop.
Bulk sort meteor client jars (archival purposes)
$root = Join-Path $PWD "\meteor_archive"
$119 = Join-Path $root "\1.19.X"
$118 = Join-Path $root "\1.18.X"
$117 = Join-Path $root "\1.17.X"
mkdir -Path $root *> $null
mkdir -Path $119 *> $null
mkdir -Path $118 *> $null
mkdir -Path $117 *> $null
Add-Type -AssemblyName System.IO.Compression.FileSystem
function SortJar {
param ([Parameter()][string] $jar_path)
if (Test-Path -Path $jar_path) {
} else {
Write-Host -ForegroundColor Red "SortJar error (input not found)"
return
}
Write-Host "Scanning" $jar_path
$zip = $null
try { #read jar as zip
$zip = [System.IO.Compression.ZipFile]::OpenRead($jar_path)
}
catch {
Write-Host -ForegroundColor Red "Error reading input" $jar_path
return
}
$zip.Entries | Where-Object {$_.Name -eq "fabric.mod.json"} | ForEach-Object { #find fabric.mod.json + extract
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$root\temp.json", $true)
}
$zip.Dispose()
if (Test-Path $root\temp.json) {
} else {
Write-Host -ForegroundColor Red "Couldn't find fabric.mod.json in jar?"
return
}
$fabric_json = Get-Content -Path $root\temp.json
if ($fabric_json) {
} else {
Write-Host -ForegroundColor Red "Error reading fabric json.."
return
}
$java_ver = $null
$mc_ver = $null
$meteor_ver = $null
try { #parse versions
$java_ver = $fabric_json | Select-String '"java"'
$mc_ver = $fabric_json | Select-String '"minecraft"'
$meteor_ver = $fabric_json | Select-String '"version"'
$java_ver = $java_ver -split '"'
$mc_ver = $mc_ver -split '"'
$meteor_ver = $meteor_ver -split '"'
$java_ver = $java_ver[3]
$mc_ver = $mc_ver[3]
$meteor_ver = $meteor_ver[3]
} catch {
Write-Host -ForegroundColor Red "Failed to parse fabric json..."
return
}
$out_folder = $null #find output folder
if ($mc_ver -like "*1.19*") {
$mc_ver = "1.19.X"
$out_folder = $119
} elseif ($mc_ver -like "*1.18*") {
$mc_ver = "1.18.X"
$out_folder = $118
} elseif ($mc_ver -like "*1.17*") {
mc_ver = "1.17.X"
$out_folder = $117
} else {
Write-Host "Version ($mc_ver) is too old and pointless to archive."
return
}
Write-Host -ForegroundColor Green "Detected Meteor v$meteor_ver for Minecraft $mc_ver"
$out_path = Join-Path $out_folder "\meteor-client-$meteor_ver.jar"
if (Test-Path $out_path) {
Write-Host -ForegroundColor Yellow "This version is already archived!"
try {
Remove-Item $jar_path *> $null
return
}
catch {
return
}
}
Write-Host -ForegroundColor Yellow "Copying to" $out_path
Move-Item -Path $jar_path -Destination $out_path *> $null
}
foreach ($jar in Get-Item -Path $PWD\*jar) {
SortJar -jar_path $jar.Name
}
Remove-Item -Path $root\temp.json *> $null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment