@@ -33,6 +33,35 @@ function Show-Message {
3333 Write-Host " $message_style$message $ ( $PSStyle.Reset ) "
3434}
3535
36+ function Get-GitHubReleaseInformation {
37+ param (
38+ [string ]$Repository ,
39+ [string ]$ReleaseTag = ' latest'
40+ )
41+
42+ $repositoryOwner , $repositoryName = ($Repository -split " /" )[0 , 1 ]
43+ if ([string ]::IsNullOrEmpty($repositoryOwner )) { Throw " Invalid repository path, missing repository owner." }
44+ if ([string ]::IsNullOrEmpty($repositoryName )) { Throw " Invalid repository path, missing repository name." }
45+
46+ $displayPath = " $repositoryOwner /$repositoryName /$ReleaseTag "
47+ $previousHeader = Set-MessageHeader " Query-$displayPath "
48+
49+ if ($ReleaseTag -like ' latest' ) {
50+ $apiUrl = " https://api.github.com/repos/$repositoryOwner /$repositoryName /releases/latest"
51+ } else {
52+ $apiUrl = " https://api.github.com/repos/$repositoryOwner /$repositoryName /releases/tags/$ReleaseTag "
53+ }
54+
55+ Show-Message " Getting release information..." $StyleAction
56+ $headers = @ { " User-Agent" = " PowerShell-ahk2exe-action" }
57+ if (! [string ]::IsNullOrEmpty($env: GitHubToken )) { $headers [" Authorization" ] = " token $env: GitHubToken " }
58+
59+ $release = Invoke-RestMethod - Uri $apiUrl - Method Get - Headers $headers
60+
61+ [void ](Set-MessageHeader $previousHeader )
62+ return $release
63+ }
64+
3665function Get-GitHubReleaseAssets {
3766 param (
3867 [string ]$Repository ,
@@ -49,7 +78,7 @@ function Get-GitHubReleaseAssets {
4978
5079 $downloadFolderName = $displayPath.Split ([IO.Path ]::GetInvalidFileNameChars()) -join ' _'
5180 $downloadFolder = Join-Path $PathDownloads $downloadFolderName
52- if (Test-Path - Path $downloadFolder ) {
81+ if (Test-Path - Path $downloadFolder ) {
5382 if ((Get-ChildItem - Path " $downloadFolder " | Measure-Object ).Count -gt 0 ) {
5483 Show-Message " $displayPath is already present, skipping re-download..." $StyleQuiet
5584
@@ -58,18 +87,9 @@ function Get-GitHubReleaseAssets {
5887 }
5988 }
6089
61- if ($ReleaseTag -like ' latest' ) {
62- $apiUrl = " https://api.github.com/repos/$repositoryOwner /$repositoryName /releases/latest"
63- } else {
64- $apiUrl = " https://api.github.com/repos/$repositoryOwner /$repositoryName /releases/tags/$ReleaseTag "
65- }
6690
67- Show-Message " Getting release information..." $StyleAction
68- $headers = @ { " User-Agent" = " PowerShell-ahk2exe-action" }
69- if (! [string ]::IsNullOrEmpty($env: GitHubToken )) { $headers [" Authorization" ] = " token $env: GitHubToken " }
91+ $release = Get-GitHubReleaseInformation - Repository $Repository - ReleaseTag $ReleaseTag
7092
71- $release = Invoke-RestMethod - Uri $apiUrl - Method Get - Headers $headers
72-
7393 $assets = $release.assets
7494 if ($assets.Count -eq 0 ) { Throw " No assets found for release '$displayPath '" }
7595
@@ -99,6 +119,48 @@ function Get-GitHubReleaseAssets {
99119 return $downloadFolder
100120}
101121
122+ function Get-GitHubReleaseFile {
123+ param (
124+ [string ]$Repository ,
125+ [string ]$ReleaseTag = ' latest' ,
126+ [string ]$FileName
127+ )
128+
129+ $repositoryOwner , $repositoryName = ($Repository -split " /" )[0 , 1 ]
130+ if ([string ]::IsNullOrEmpty($repositoryOwner )) { Throw " Invalid repository path, missing repository owner." }
131+ if ([string ]::IsNullOrEmpty($repositoryName )) { Throw " Invalid repository path, missing repository name." }
132+
133+ $displayPath = " $repositoryOwner /$repositoryName /$ReleaseTag /$FileName "
134+ $previousHeader = Set-MessageHeader " Download-$displayPath "
135+
136+ $downloadFolderName = $displayPath.Split ([IO.Path ]::GetInvalidFileNameChars()) -join ' _'
137+ $downloadFolder = Join-Path $PathDownloads $downloadFolderName
138+ $downloadDestination = Join-Path $downloadFolder $FileName
139+ if (Test-Path - Path $downloadFolder ) {
140+ if ((Get-ChildItem - Path " $downloadFolder " | Measure-Object ).Count -gt 0 ) {
141+ Show-Message " $displayPath is already present, skipping re-download..." $StyleQuiet
142+
143+ [void ](Set-MessageHeader $previousHeader )
144+ return $downloadDestination
145+ }
146+ }
147+
148+ $release = Get-GitHubReleaseInformation - Repository $Repository - ReleaseTag $ReleaseTag
149+ $tag = $release.tag_name
150+
151+ $downloadUrl = " https://raw.githubusercontent.com/$repositoryOwner /$repositoryName /refs/tags/$tag /$FileName "
152+
153+ $previousHeaderAsset = Set-MessageHeader " File-$FileName "
154+ Show-Message " Downloading..." $StyleAction
155+ Show-Message " Source: $downloadUrl " $StyleCommand
156+ Show-Message " Destination: $downloadDestination " $StyleCommand
157+ [void ](New-Item - ItemType Directory - Path $downloadFolder - Force)
158+ [void ](New-Object System.Net.WebClient).DownloadFile($downloadUrl , $downloadDestination )
159+ Show-Message " Download completed" $StyleStatus
160+
161+ return $downloadDestination
162+ }
163+
102164function Invoke-UnzipAllInPlace {
103165 param (
104166 [string ]$FolderPath
@@ -115,24 +177,24 @@ function Invoke-UnzipAllInPlace {
115177
116178function Install-AutoHotkey {
117179 $previousHeader = Set-MessageHeader " Install-Autohotkey"
118-
180+
119181 Show-Message " Installing..." $StyleAction
120182 $downloadFolder = Get-GitHubReleaseAssets - Repository " $env: AutoHotkeyRepo " - ReleaseTag " $env: AutoHotkeyTag " - FileTypeFilter " *.zip"
121183
122184 switch ($env: Target ) {
123- ' x64' {
124- $exeName = ' AutoHotkey64.exe'
185+ ' x64' {
186+ $exeName = ' AutoHotkey64.exe'
125187 $searchFilter = ' AutoHotkey(U)?64\.exe'
126188 }
127- ' x86' {
128- $exeName = ' AutoHotkey32.exe'
189+ ' x86' {
190+ $exeName = ' AutoHotkey32.exe'
129191 $searchFilter = ' AutoHotkey(U)?32\.exe'
130192 }
131193 Default { Throw " Unsupported Architecture: '$target '. Valid Options: x64, x86" }
132194 }
133195
134196 $installPath = (Get-ChildItem - Path $downloadFolder - Recurse | Where-Object { $_.Name -match " ^$searchFilter $" } | Select-Object - First 1 )
135- if ([System.IO.File ]::Exists($installPath )) {
197+ if ([System.IO.File ]::Exists($installPath )) {
136198 Show-Message " Autohotkey is already installed, skipping re-installation..." $StyleQuiet
137199
138200 [void ](Set-MessageHeader $previousHeader )
@@ -160,7 +222,7 @@ function Install-Ahk2Exe {
160222 $exeName = ' Ahk2Exe.exe'
161223
162224 $installPath = (Get-ChildItem - Path $downloadFolder - Recurse - Filter $exeName | Select-Object - First 1 )
163- if ([System.IO.File ]::Exists($installPath )) {
225+ if ([System.IO.File ]::Exists($installPath )) {
164226 Show-Message " Ahk2Exe is already installed, skipping re-installation..." $StyleQuiet
165227
166228 [void ](Set-MessageHeader $previousHeader )
@@ -179,6 +241,36 @@ function Install-Ahk2Exe {
179241 return $installPath
180242}
181243
244+ function Install-BinMod {
245+ param (
246+ [string ]$Ahk2ExePath
247+ )
248+ $previousHeader = Set-MessageHeader " Install-BinMod"
249+
250+ Show-Message " Installing..." $StyleAction
251+ $downloadFile = Get-GitHubReleaseFile - Repository " $env: Ahk2ExeRepo " - ReleaseTag " $env: Ahk2ExeTag " - FileName " BinMod.ahk"
252+
253+ $exeName = ' BinMod.exe'
254+ $ahk2exeFolder = Split-Path - Path $Ahk2ExePath - Parent
255+ $installPath = Join-Path $ahk2exeFolder $exeName
256+ if ([System.IO.File ]::Exists($installPath )) {
257+ Show-Message " BinMod is already installed, skipping re-installation..." $StyleQuiet
258+
259+ [void ](Set-MessageHeader $previousHeader )
260+ return
261+ }
262+
263+ Invoke-Ahk2Exe - Path " $ahk2exePath " - Base " $ahk2exePath " -In " $downloadFile " - Out " $installPath " - Icon " " - Compression " none" - ResourceId " "
264+
265+ Show-Message " Verifying installation..." $StyleAction
266+ if (! [System.IO.File ]::Exists($installPath )) { Throw " Missing BinMod Executable '$exeName '." }
267+ Show-Message " Installation path: $installPath " $StyleCommand
268+ Show-Message " Installation completed" $StyleStatus
269+
270+ [void ](Set-MessageHeader $previousHeader )
271+ return $installPath
272+ }
273+
182274function Install-UPX {
183275 param (
184276 [string ]$Ahk2ExePath
@@ -190,7 +282,7 @@ function Install-UPX {
190282 $downloadFolder = Get-GitHubReleaseAssets - Repository " $env: UPXRepo " - ReleaseTag " $env: UPXTag " - FileTypeFilter " *win64.zip"
191283
192284 $exeName = ' upx.exe'
193- $ahk2exeFolder = Split-Path - Path $Ahk2ExePath - Parent
285+ $ahk2exeFolder = Split-Path - Path $Ahk2ExePath - Parent
194286
195287 $installPath = Join-Path $ahk2exeFolder $exeName
196288 if ([System.IO.File ]::Exists($installPath )) {
@@ -239,13 +331,13 @@ function Invoke-Ahk2Exe {
239331
240332 Switch ($compression ) {
241333 ' none' { $ahk2exe_args += " /compress 0" }
242- ' upx' { $ahk2exe_args += " /compress 2" }
334+ ' upx' { $ahk2exe_args += " /compress 2" }
243335 Default { Throw " Unsupported Compression Type: '$compression '. Valid Options: none, upx" }
244336 }
245337
246- if (! [string ]::IsNullOrEmpty($Out )) {
338+ if (! [string ]::IsNullOrEmpty($Out )) {
247339 [void ](New-Item - Path $Out - ItemType File - Force)
248- $ahk2exe_args += " /out `" $Out `" "
340+ $ahk2exe_args += " /out `" $Out `" "
249341 }
250342 $ahk2exe_args += if (! [string ]::IsNullOrEmpty($Icon )) { " /icon `" $Icon `" " }
251343 $ahk2exe_args += if (! [string ]::IsNullOrEmpty($ResourceId )) { " /resourceid `" $ResourceId `" " }
@@ -267,13 +359,15 @@ function Invoke-Ahk2Exe {
267359function Invoke-Action {
268360 Show-Message " Starting..." $StyleAction
269361
270- if ([string ]::IsNullOrEmpty($env: GitHubToken )) {
271- Show-Message " GitHubToken environment variable is not set. API calls may be rate limited." $StyleAlert
362+ if ([string ]::IsNullOrEmpty($env: GitHubToken )) {
363+ Show-Message " GitHubToken environment variable is not set. API calls may be rate limited." $StyleAlert
272364 }
273365
274366 $ahkPath = Install-AutoHotkey
275367 $ahk2exePath = Install-Ahk2Exe
276368
369+ [void ](Install-BinMod - Ahk2ExePath $ahk2exePath )
370+
277371 if (" $env: Compression " -eq " upx" ) {
278372 [void ](Install-UPX - Ahk2ExePath $ahk2exePath )
279373 }
@@ -282,4 +376,4 @@ function Invoke-Action {
282376 Show-Message " Finished" $StyleStatus
283377}
284378
285- Invoke-Action
379+ Invoke-Action
0 commit comments