Skip to content

Commit

Permalink
chore: update SymLink script
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbutt committed Sep 26, 2024
1 parent 6e5ebaf commit fbf3204
Showing 1 changed file with 61 additions and 32 deletions.
93 changes: 61 additions & 32 deletions SymLink.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env pwsh
#Requires -RunAsAdministrator

<#
Expand Down Expand Up @@ -35,62 +36,90 @@ SOFTWARE.

param (
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]
$Path = ".",
$ModulePath = "C:\Program Files (x86)\Common Files\AMXShare\Duet\module",

[Parameter(Mandatory = $false)]
[string]
$ModulePath = "C:\Program Files (x86)\Common Files\AMXShare\Duet\module",
$IncludePath = "C:\Program Files (x86)\Common Files\AMXShare\AXIs",

[Parameter(Mandatory = $false)]
[string]
$IncludePath = "C:\Program Files (x86)\Common Files\AMXShare\AXIs"
[switch]
$Delete = $false
)

try {
$Path = Resolve-Path $Path
$prevPWD = $PWD
Set-Location $PSScriptRoot

$directories = Get-ChildItem -Path $Path -Directory -Recurse | Where-Object { $_.FullName -notmatch "(.git|.history|node_modules)" }
try {
$moduleFiles = Get-ChildItem -File "**/*.axs" -ErrorAction SilentlyContinue | Where-Object { $_.FullName -notmatch "(.git|.history|node_modules)" }
$includeFiles = Get-ChildItem -File "**/*.axi" -ErrorAction SilentlyContinue | Where-Object { $_.FullName -notmatch "(.git|.history|node_modules)" }

$moduleFiles = $directories | Get-ChildItem -File -Include *.axs -ErrorAction SilentlyContinue
$includeFiles = $directories | Get-ChildItem -File -Include *.axi -ErrorAction SilentlyContinue
if (!$moduleFiles) {
Write-Host "No module files found"
exit 1
}

if (!$moduleFiles -and !$includeFiles) {
Write-Host "No files found in $Path" -ForegroundColor Yellow
exit
# Ensure there is a compiled TKO file for each AXS file
foreach ($file in $moduleFiles) {
if (!(Test-Path $($file.FullName -replace ".axs", ".tko"))) {
Write-Host "TKO file not found for $file" -ForegroundColor Yellow
exit 1
}
}

foreach ($file in $includeFiles) {
$path = Join-Path -Path $IncludePath -ChildPath $file.Name
$target = $file.FullName
$ModulePath = Resolve-Path $ModulePath
$IncludePath = Resolve-Path $IncludePath

!$Delete ? (Write-Host "Creating symlinks...") : (Write-Host "Deleting symlinks...")

# It's possible to have a module without any AXI files
if ($includeFiles) {
foreach ($file in $includeFiles) {
$path = "$IncludePath\$($file.Name)"

if ($Delete) {
Write-Verbose "Deleting symlink: $path"
Remove-Item -Path $path -Force | Out-Null
continue
}

Write-Host "Creating symlink: $path -> $target" -ForegroundColor Green
New-Item -ItemType SymbolicLink -Path $path -Target $target -Force | Out-Null
$target = $file.FullName

Write-Verbose "Creating symlink: $path -> $target"
New-Item -ItemType SymbolicLink -Path $path -Target $target -Force | Out-Null
}
}

foreach ($file in $moduleFiles) {
if (!(Test-Path $($file.FullName -replace ".axs", ".tko"))) {
Write-Host "TKO file not found for $file" -ForegroundColor Yellow
continue
}
$axsPath = "$ModulePath\$($file.Name)"
$tkoPath = "$ModulePath\$($file.Name -replace ".axs", ".tko")"

$path = Join-Path -Path $ModulePath -ChildPath $file.Name
$target = $file.FullName
$axsTarget = $file.FullName
$tkoTarget = $file.FullName -replace ".axs", ".tko"

Write-Host "Creating symlink: $path -> $target" -ForegroundColor Green
New-Item -ItemType SymbolicLink -Path $path -Target $target -Force | Out-Null
if ($Delete) {
Write-Verbose "Deleting symlink: $axsPath"
Remove-Item -Path $axsPath -Force | Out-Null

$path = Join-Path -Path $ModulePath -ChildPath $($file.Name -replace ".axs", ".tko")
$target = $file.FullName -replace ".axs", ".tko"
Write-Verbose "Deleting symlink: $tkoPath"
Remove-Item -Path $tkoPath -Force | Out-Null

Write-Host "Creating symlink: $path -> $target" -ForegroundColor Green
New-Item -ItemType SymbolicLink -Path $path -Target $target -Force | Out-Null
continue
}

Write-Verbose "Creating symlink: $axsPath -> $axsTarget"
New-Item -ItemType SymbolicLink -Path $axsPath -Target $axsTarget -Force | Out-Null

Write-Verbose "Creating symlink: $tkoPath -> $tkoTarget"
New-Item -ItemType SymbolicLink -Path $tkoPath -Target $tkoTarget -Force | Out-Null
}
}
catch {
Write-Host $_.Exception.GetBaseException().Message -ForegroundColor Red
exit 1
}

Write-Host
Read-Host -Prompt "Press any key to exit..."
finally {
Set-Location $prevPWD
}

0 comments on commit fbf3204

Please sign in to comment.