Repository navigation
Expand file tree
/
Copy pathRDPControl.psm1
More file actions
174 lines (131 loc) · 5.06 KB
/
Copy pathRDPControl.psm1
File metadata and controls
174 lines (131 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#Requires -Version 5.1
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
#region Bootstrap
$Script:ModuleRoot = $PSScriptRoot
$Script:SourceRoot = Join-Path -Path $Script:ModuleRoot -ChildPath 'src'
$Script:LibRoot = Join-Path -Path $Script:ModuleRoot -ChildPath 'lib'
$Script:Runtime = if ($PSVersionTable.PSEdition -eq 'Core') {
'netstandard2.0'
} else {
'net46'
}
$Script:Architecture = if ([System.Environment]::Is64BitProcess) {
'x64'
} else {
'x86'
}
#endregion
#region SQLite - Native interop path
$Script:NativeInteropDirectory = Join-Path -Path $Script:LibRoot -ChildPath (
'{0}\{1}' -f $Script:Runtime, $Script:Architecture
)
if (Test-Path -LiteralPath $Script:NativeInteropDirectory -PathType Container) {
$pathEntries = $env:PATH -split ';'
if ($pathEntries -notcontains $Script:NativeInteropDirectory) {
$env:PATH = '{0};{1}' -f $Script:NativeInteropDirectory, $env:PATH
}
} else {
Write-Warning -Message "[RDPControl] SQLite native interop directory not found: $Script:NativeInteropDirectory"
}
#endregion
#region SQLite - Managed assembly
$Script:ManagedAssemblyPath = Join-Path -Path $Script:LibRoot -ChildPath (
'{0}\System.Data.SQLite.dll' -f $Script:Runtime
)
if (-not (Test-Path -LiteralPath $Script:ManagedAssemblyPath -PathType Leaf)) {
Write-Warning -Message "[RDPControl] SQLite managed assembly not found: $Script:ManagedAssemblyPath"
} else {
$alreadyLoaded = [System.AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object -FilterScript { $_.Location -eq $Script:ManagedAssemblyPath }
if (-not $alreadyLoaded) {
try {
[void][System.Reflection.Assembly]::LoadFrom($Script:ManagedAssemblyPath)
} catch {
Write-Warning -Message "[RDPControl] Failed to load SQLite assembly: $($_.Exception.Message)"
}
}
try {
[void][System.Data.SQLite.SQLiteConnection]
} catch {
Write-Warning -Message "[RDPControl] SQLite assembly validation failed: $($_.Exception.Message)"
}
}
#endregion
#region Interop bootstrap
$Script:InteropPath = Join-Path -Path $Script:SourceRoot -ChildPath 'Private\Interop\RdpControlInterop.ps1'
if (Test-Path -LiteralPath $Script:InteropPath -PathType Leaf) {
try {
. $Script:InteropPath
} catch {
Write-Warning -Message "[RDPControl] Failed to load interop bootstrap: $($_.Exception.Message)"
}
} else {
Write-Warning -Message "[RDPControl] Interop bootstrap not found: $Script:InteropPath"
}
#endregion
#region Private functions
$Script:PrivateDomains = @(
'Assembly'
'Engine'
'Store\Providers'
'Store\Core'
'Enforcement'
)
foreach ($domain in $Script:PrivateDomains) {
$domainPath = Join-Path -Path $Script:SourceRoot -ChildPath "Private\$domain"
if (-not (Test-Path -LiteralPath $domainPath -PathType Container)) {
Write-Warning -Message "[RDPControl] Private domain directory not found: $domainPath"
continue
}
$files = Get-ChildItem -Path $domainPath -Filter '*.ps1' -File -Recurse | Sort-Object -Property FullName
foreach ($file in $files) {
try {
. $file.FullName
$fn = Get-Command -Name $file.BaseName -CommandType Function -ErrorAction SilentlyContinue
if (-not $fn) {
Write-Warning -Message "[RDPControl] Expected function [$($file.BaseName)] not found after loading [$($file.Name)]."
} else {
Write-Verbose -Message "[RDPControl] Loaded private: $($file.BaseName)"
}
} catch {
Write-Warning -Message "[RDPControl] Failed to load private script [$($file.Name)]: $($_.Exception.Message)"
}
}
}
#endregion
#region Public functions
$Script:PublicDomains = @(
'Policy'
'Snapshot'
'Watchdog'
'User'
'Session'
)
$Script:ExportedFunctions = [System.Collections.Generic.List[string]]::new()
foreach ($domain in $Script:PublicDomains) {
$domainPath = Join-Path -Path $Script:SourceRoot -ChildPath "Public\$domain"
if (-not (Test-Path -LiteralPath $domainPath -PathType Container)) {
Write-Warning -Message "[RDPControl] Public domain directory not found: $domainPath"
continue
}
$files = Get-ChildItem -Path $domainPath -Filter '*.ps1' -File | Sort-Object -Property FullName
foreach ($file in $files) {
try {
. $file.FullName
$fn = Get-Command -Name $file.BaseName -CommandType Function -ErrorAction SilentlyContinue
if (-not $fn) {
Write-Warning -Message "[RDPControl] Expected function [$($file.BaseName)] not found after loading [$($file.Name)]."
} else {
[void]$Script:ExportedFunctions.Add($file.BaseName)
Write-Verbose -Message "[RDPControl] Loaded public: $($file.BaseName)"
}
} catch {
Write-Warning -Message "[RDPControl] Failed to load public script [$($file.Name)]: $($_.Exception.Message)"
}
}
}
#endregion
#region Export
Export-ModuleMember -Function $Script:ExportedFunctions
#endregion