Skip to content

Instantly share code, notes, and snippets.

@meitinger
Last active June 19, 2017 20:59
Show Gist options
  • Save meitinger/007efc06d661ab4f92d9b1feca44f889 to your computer and use it in GitHub Desktop.
Save meitinger/007efc06d661ab4f92d9b1feca44f889 to your computer and use it in GitHub Desktop.
Script that splits the 32bit and 64bit part of Gimp after unpacking it with innounp -x -a
Param (
[Parameter(Mandatory=$true)][string] $Path
)
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
Set-StrictMode -Version Latest
$section = $null
$lines = @{}
$components = @{}
$trueComponents = @('gs')
$falseComponents = @('gimp32on64','py','gimp32on64\py','gimp32on64\compat','deps32\compat')
$files = @{
'32' = @{}
'64' = @{}
}
Switch -Regex -File (Join-Path -Path $Path -ChildPath 'install_script.iss') {
'^\[(?<section>[^\]]*)\]$' {
$section = $matches['section']
$lines.Add($section, [System.Collections.Generic.LinkedList[string]]::New())
}
'^(;.*|\s*)$' {
}
Default {
$lines[$section].Add($_)
}
}
Switch -Regex ($lines['Components']) {
'^Name: "(?<name>[^"]*)"; Description: "[^"]*"; Types: "[^"]*";( Check: "Check3264\(''(?<architecture>[^'']*)''\)";)?' {
$components[$matches['name']] = $matches['architecture']
}
Default {
Write-Warning -Message "Ignoring component line: $_"
}
}
Switch -Regex ($lines['Files']) {
'^Source: "(?<source>\{app\}\\[^"]*)"; DestDir: "(?<destdir>\{app\}\\[^"]*)";( DestName: "(?<destname>[^"]*)";)? Components: (?<components>[^;]*);' {
ForEach ($arch in $files.Keys) {
$eval = [regex]::Replace($matches['components'], '(?<=^|\(|\s+)[^()\s+]+(?=$|\)|\s+)', {
Param (
[System.Text.RegularExpressions.Match]$m
)
$component = $($m.Value)
If ($component -in 'not','or','and') {
Return "-$component"
}
ElseIf ($component -in $falseComponents) {
Return '$false'
}
ElseIf ($component -in $trueComponents) {
Return '$true'
}
ElseIf ($components.ContainsKey($component)) {
If ($components[$component] -in $null,$arch) {
Return '$true'
}
Else {
Return '$false'
}
}
Else {
Write-Warning -Message "Ignoring unknown component: $component"
Return '$false'
}
})
If (Invoke-Expression -Command $eval) {
$sourcePath = Join-Path -Path $Path -ChildPath $matches['source']
$filePath = $matches['destdir'] + '\'
If ($matches['destname']) {
$filePath += $matches['destname']
}
Else {
$filePath += Split-Path -Leaf -Path $sourcePath
}
If ($files[$arch].ContainsKey($filePath) -and ((Get-FileHash -Algorithm SHA256 -Path $files[$arch][$filePath]).Hash -ne (Get-FileHash -Algorithm SHA256 -Path $sourcePath).Hash)) {
Write-Warning -Message "Destination file with different sources: $filePath"
}
Else {
$files[$arch][$filePath] = $sourcePath
}
}
}
}
Default {
Write-Warning -Message "Ignoring file line: $_"
}
}
ForEach ($arch in $files.Keys) {
$files[$arch].GetEnumerator() | % {
$targetPath = Join-Path -Path $Path -ChildPath $_.Key.Replace('{app}',$arch)
$targetFile = New-Item -Path $targetPath -ItemType File -Force
Copy-Item -Path $_.Value -Destination $targetFile -Force
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment