mirror of
https://github.com/freedbygrace/PSOPNSenseAPI.git
synced 2026-08-24 08:56:46 +00:00
Update PSM1 files to use Add-Type instead of Assembly.Load
This commit is contained in:
@@ -1,36 +1,13 @@
|
|||||||
# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes
|
# Load the main assembly directly
|
||||||
# This avoids file lock issues when the module is loaded
|
$mainDllPath = Join-Path $PSScriptRoot "lib\PSOPNSenseAPI.dll"
|
||||||
|
|
||||||
$libPath = Join-Path $PSScriptRoot -ChildPath "lib"
|
Write-Verbose "Loading assembly from $mainDllPath"
|
||||||
|
|
||||||
$DLLFileList = Get-ChildItem -Path $libPath -Filter "*.dll"
|
try {
|
||||||
|
Add-Type -Path $mainDllPath
|
||||||
$DLLFileListCount = ($DLLFileList | Measure-Object).Count
|
Write-Verbose "Successfully loaded assembly from $mainDllPath"
|
||||||
|
} catch {
|
||||||
$DLLFileListCounter = 1
|
$errorMessage = $_.Exception.Message
|
||||||
|
Write-Error "Failed to load assembly from $($mainDllPath): $($errorMessage)"
|
||||||
For ($DLLFileListIndex = 0; $DLLFileListIndex -lt $DLLFileListCount; $DLLFileListIndex++)
|
throw
|
||||||
{
|
|
||||||
Try
|
|
||||||
{
|
|
||||||
$DLLFile = $DLLFileList[$DLLFileListIndex]
|
|
||||||
|
|
||||||
Write-Verbose "Attempting to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount). Please Wait..."
|
|
||||||
|
|
||||||
Write-Verbose "Path: $($DLLFile)"
|
|
||||||
|
|
||||||
$DLLFileBytes = [System.IO.File]::ReadAllBytes($DLLFile.FullName)
|
|
||||||
|
|
||||||
$Null = [System.Reflection.Assembly]::Load($DLLFileBytes)
|
|
||||||
|
|
||||||
Write-Verbose "Successfully loaded DLL assembly $($DLLFileListCounter) of $($DLLFileListCount)"
|
|
||||||
}
|
|
||||||
Catch
|
|
||||||
{
|
|
||||||
Write-Warning "Failed to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount): $($_.Exception.Message)"
|
|
||||||
}
|
|
||||||
Finally
|
|
||||||
{
|
|
||||||
$DLLFileListCounter++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1,36 +1,13 @@
|
|||||||
# Load assemblies from the lib folder using System.Reflection.Assembly::LoadBytes
|
# Load the main assembly directly
|
||||||
# This avoids file lock issues when the module is loaded
|
$mainDllPath = Join-Path $PSScriptRoot "lib\PSOPNSenseAPI.dll"
|
||||||
|
|
||||||
$libPath = Join-Path $PSScriptRoot -ChildPath "lib"
|
Write-Verbose "Loading assembly from $mainDllPath"
|
||||||
|
|
||||||
$DLLFileList = Get-ChildItem -Path $libPath -Filter "*.dll"
|
try {
|
||||||
|
Add-Type -Path $mainDllPath
|
||||||
$DLLFileListCount = ($DLLFileList | Measure-Object).Count
|
Write-Verbose "Successfully loaded assembly from $mainDllPath"
|
||||||
|
} catch {
|
||||||
$DLLFileListCounter = 1
|
$errorMessage = $_.Exception.Message
|
||||||
|
Write-Error "Failed to load assembly from $($mainDllPath): $($errorMessage)"
|
||||||
For ($DLLFileListIndex = 0; $DLLFileListIndex -lt $DLLFileListCount; $DLLFileListIndex++)
|
throw
|
||||||
{
|
|
||||||
Try
|
|
||||||
{
|
|
||||||
$DLLFile = $DLLFileList[$DLLFileListIndex]
|
|
||||||
|
|
||||||
Write-Verbose "Attempting to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount). Please Wait..."
|
|
||||||
|
|
||||||
Write-Verbose "Path: $($DLLFile)"
|
|
||||||
|
|
||||||
$DLLFileBytes = [System.IO.File]::ReadAllBytes($DLLFile.FullName)
|
|
||||||
|
|
||||||
$Null = [System.Reflection.Assembly]::Load($DLLFileBytes)
|
|
||||||
|
|
||||||
Write-Verbose "Successfully loaded DLL assembly $($DLLFileListCounter) of $($DLLFileListCount)"
|
|
||||||
}
|
|
||||||
Catch
|
|
||||||
{
|
|
||||||
Write-Warning "Failed to load DLL assembly $($DLLFileListCounter) of $($DLLFileListCount): $($_.Exception.Message)"
|
|
||||||
}
|
|
||||||
Finally
|
|
||||||
{
|
|
||||||
$DLLFileListCounter++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user