@@ -33,6 +33,33 @@ 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+ return $release
61+ }
62+
3663function Get-GitHubReleaseAssets {
3764 param (
3865 [string ]$Repository ,
@@ -58,6 +85,7 @@ function Get-GitHubReleaseAssets {
5885 }
5986 }
6087
88+ <<<<<<< Updated upstream
6189 if ($ReleaseTag -like ' latest' ) {
6290 $apiUrl = " https://api.github.com/repos/$repositoryOwner /$repositoryName /releases/latest"
6391 } else {
@@ -70,6 +98,9 @@ function Get-GitHubReleaseAssets {
7098
7199 $release = Invoke-RestMethod - Uri $apiUrl - Method Get - Headers $headers
72100
101+ =======
102+ $release = Get-GitHubReleaseInformation - Repository $Repository - ReleaseTag $ReleaseTag
103+ >>>>>>> Stashed changes
73104 $assets = $release.assets
74105 if ($assets.Count -eq 0 ) { Throw " No assets found for release '$displayPath '" }
75106
@@ -99,6 +130,51 @@ function Get-GitHubReleaseAssets {
99130 return $downloadFolder
100131}
101132
133+ <<<<<<< Updated upstream
134+ =======
135+ function Get-GitHubReleaseFile {
136+ param (
137+ [string ]$Repository ,
138+ [string ]$ReleaseTag = ' latest' ,
139+ [string ]$FileName ,
140+ )
141+
142+ $repositoryOwner , $repositoryName = ($Repository -split " /" )[0 , 1 ]
143+ if ([string ]::IsNullOrEmpty($repositoryOwner )) { Throw " Invalid repository path, missing repository owner." }
144+ if ([string ]::IsNullOrEmpty($repositoryName )) { Throw " Invalid repository path, missing repository name." }
145+
146+ $displayPath = " $repositoryOwner /$repositoryName /$ReleaseTag /$FileName "
147+ $previousHeader = Set-MessageHeader " Download-$displayPath "
148+
149+ $downloadFolderName = $displayPath.Split ([IO.Path ]::GetInvalidFileNameChars()) -join ' _'
150+ $downloadFolder = Join-Path $PathDownloads $downloadFolderName
151+ $downloadDestination = Join-Path $downloadFolder $FileName
152+ if (Test-Path - Path $downloadFolder ) {
153+ if ((Get-ChildItem - Path " $downloadFolder " | Measure-Object ).Count -gt 0 ) {
154+ Show-Message " $displayPath is already present, skipping re-download..." $StyleQuiet
155+
156+ [void ](Set-MessageHeader $previousHeader )
157+ return $downloadDestination
158+ }
159+ }
160+
161+ $release = Get-GitHubReleaseInformation - Repository $Repository - ReleaseTag $ReleaseTag
162+ $tag = $release.tag_name
163+
164+ $downloadUrl = " https://raw.githubusercontent.com/$repositoryOwner /$repositoryName /refs/tags/$tag /$FileName "
165+
166+ $previousHeaderAsset = Set-MessageHeader " File-$FileName "
167+ Show-Message " Downloading..." $StyleAction
168+ Show-Message " Source: $downloadUrl " $StyleCommand
169+ Show-Message " Destination: $downloadDestination " $StyleCommand
170+ [void ](New-Item - ItemType Directory - Path $downloadFolder - Force)
171+ [void ](New-Object System.Net.WebClient).DownloadFile($downloadUrl , $downloadDestination )
172+ Show-Message " Download completed" $StyleStatus
173+
174+ return $downloadDestination
175+ }
176+
177+ >>>>>>> Stashed changes
102178function Invoke-UnzipAllInPlace {
103179 param (
104180 [string ]$FolderPath
@@ -179,6 +255,40 @@ function Install-Ahk2Exe {
179255 return $installPath
180256}
181257
258+ <<<<<<< Updated upstream
259+ =======
260+ function Install-BinMod {
261+ param (
262+ [string ]$Ahk2ExePath
263+ )
264+ $previousHeader = Set-MessageHeader " Install-BinMod"
265+
266+ Show-Message " Installing..." $StyleAction
267+ $downloadFile = Get-GitHubReleaseFile - Repository " $env: Ahk2ExeRepo " - ReleaseTag " $env: Ahk2ExeTag " - FileName " BinMod.ahk"
268+
269+ $exeName = ' BinMod.exe'
270+ $ahk2exeFolder = Split-Path - Path $Ahk2ExePath - Parent
271+ $installPath = Join-Path $ahk2exeFolder $exeName
272+ if ([System.IO.File ]::Exists($installPath )) {
273+ Show-Message " BinMod is already installed, skipping re-installation..." $StyleQuiet
274+
275+ [void ](Set-MessageHeader $previousHeader )
276+ return
277+ }
278+
279+
280+ Invoke-Ahk2Exe - Path " $ahk2exePath " - Base " $ahk2exePath " -In " $downloadFile " - Out " $installPath " - Icon " " - Compression " none" - ResourceId " "
281+
282+ Show-Message " Verifying compilation..." $StyleAction
283+ if (! [System.IO.File ]::Exists($installPath )) { Throw " Missing BinMod Executable '$exeName '." }
284+ Show-Message " Installation path: $installPath " $StyleCommand
285+ Show-Message " Installation completed" $StyleStatus
286+
287+ [void ](Set-MessageHeader $previousHeader )
288+ return $installPath
289+ }
290+
291+ >>>>>>> Stashed changes
182292function Install-UPX {
183293 param (
184294 [string ]$Ahk2ExePath
@@ -273,6 +383,11 @@ function Invoke-Action {
273383
274384 $ahkPath = Install-AutoHotkey
275385 $ahk2exePath = Install-Ahk2Exe
386+ <<<<<<< Updated upstream
387+ =======
388+
389+ [void ](Install-BinMod - Ahk2ExePath $ahk2exePath )
390+ >>>>>>> Stashed changes
276391
277392 if (" $env: Compression " -eq " upx" ) {
278393 [void ](Install-UPX - Ahk2ExePath $ahk2exePath )
0 commit comments