Add support for external LibTSforge.dll if found in BIN folder

This commit is contained in:
WindowsAddict 2025-04-16 05:30:31 +05:30
parent 294837dfe0
commit 70162c4130
2 changed files with 38 additions and 18 deletions

View File

@ -154,6 +154,7 @@ goto dk_done
set "_work=%~dp0" set "_work=%~dp0"
if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%" if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%"
set "_workp=%_work:'=''%"
set "_batf=%~f0" set "_batf=%~f0"
set "_batp=%_batf:'=''%" set "_batp=%_batf:'=''%"
@ -8826,17 +8827,26 @@ namespace LibTSforge.PhysicalStore
} }
'@ '@
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
$cp = [CodeDom.Compiler.CompilerParameters] [string[]]@("System.dll", "System.Core.dll", "System.ServiceProcess.dll", "System.Xml.dll") $binPath = Join-Path -Path $env:_workp -ChildPath "BIN\LibTSforge.dll"
$cp.CompilerOptions = "/unsafe"
$lang = If ((Get-Host).Version.Major -gt 2) { "CSharp" } Else { "CSharpVersion3" }
$ctemp = "$env:SystemRoot\Temp\" if (Test-Path -Path $binPath) {
if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null } Write-Host "LibTSforge.dll found in BIN folder. Loading the DLL..."
$env:TMP = $ctemp Add-Type -Path $binPath
$env:TEMP = $ctemp }
else {
$cp = [CodeDom.Compiler.CompilerParameters] [string[]]@("System.dll", "System.Core.dll", "System.ServiceProcess.dll", "System.Xml.dll")
$cp.CompilerOptions = "/unsafe"
$lang = If ((Get-Host).Version.Major -gt 2) { "CSharp" } Else { "CSharpVersion3" }
$ctemp = "$env:SystemRoot\Temp\"
if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null }
$env:TMP = $ctemp
$env:TEMP = $ctemp
$cp.GenerateInMemory = $true
Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp
}
$cp.GenerateInMemory = $true
Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp
if ($env:_debug -eq '0') { if ($env:_debug -eq '0') {
[LibTSforge.Logger]::HideOutput = $true [LibTSforge.Logger]::HideOutput = $true
} }

View File

@ -221,6 +221,7 @@ goto dk_done
set "_work=%~dp0" set "_work=%~dp0"
if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%" if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%"
set "_workp=%_work:'=''%"
set "_batf=%~f0" set "_batf=%~f0"
set "_batp=%_batf:'=''%" set "_batp=%_batf:'=''%"
@ -6709,17 +6710,26 @@ namespace LibTSforge.PhysicalStore
} }
'@ '@
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
$cp = [CodeDom.Compiler.CompilerParameters] [string[]]@("System.dll", "System.Core.dll", "System.ServiceProcess.dll", "System.Xml.dll") $binPath = Join-Path -Path $env:_workp -ChildPath "BIN\LibTSforge.dll"
$cp.CompilerOptions = "/unsafe"
$lang = If ((Get-Host).Version.Major -gt 2) { "CSharp" } Else { "CSharpVersion3" }
$ctemp = "$env:SystemRoot\Temp\" if (Test-Path -Path $binPath) {
if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null } Write-Host "LibTSforge.dll found in BIN folder. Loading the DLL..."
$env:TMP = $ctemp Add-Type -Path $binPath
$env:TEMP = $ctemp }
else {
$cp = [CodeDom.Compiler.CompilerParameters] [string[]]@("System.dll", "System.Core.dll", "System.ServiceProcess.dll", "System.Xml.dll")
$cp.CompilerOptions = "/unsafe"
$lang = If ((Get-Host).Version.Major -gt 2) { "CSharp" } Else { "CSharpVersion3" }
$ctemp = "$env:SystemRoot\Temp\"
if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null }
$env:TMP = $ctemp
$env:TEMP = $ctemp
$cp.GenerateInMemory = $true
Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp
}
$cp.GenerateInMemory = $true
Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp
if ($env:_debug -eq '0') { if ($env:_debug -eq '0') {
[LibTSforge.Logger]::HideOutput = $true [LibTSforge.Logger]::HideOutput = $true
} }