forked from DrEmpiricism/Optimize-Offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOffline-Resources.psm1
188 lines (179 loc) · 12.4 KB
/
Offline-Resources.psm1
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
Using namespace System.Collections.Generic
#Requires -RunAsAdministrator
#Requires -Version 5.1
<#
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2019 v5.7.182
Created on: 11/20/2019 11:53 AM
Created by: BenTheGreat
Filename: Offline-Resources.psm1
Last updated: 11/13/2020
-------------------------------------------------------------------------
Module Name: Offline-Resources
===========================================================================
#>
#region Set Local Variables
$ResourcesRoot = $PSScriptRoot
$ModuleRoot = Split-Path -Path $ResourcesRoot
#endregion Set Local Variables
#region Import Resource Functions
$PublicFunctions = @(Get-ChildItem -Path (Join-Path -Path $ResourcesRoot -ChildPath Public) -Filter *.ps1 -ErrorAction SilentlyContinue)
$PrivateFunctions = @(Get-ChildItem -Path (Join-Path -Path $ResourcesRoot -ChildPath Private) -Filter *.ps1 -ErrorAction SilentlyContinue)
ForEach ($Function In @($PublicFunctions + $PrivateFunctions))
{
Try { . $Function.FullName }
Catch { Write-Warning ('Failed to import the required function "{0}", {1}' -f $Function.FullName, $PSItem); Break }
}
#endregion Import Resource Functions
#region Module Path Declarations
$OfflineResources = [Collections.Specialized.OrderedDictionary]::New()
$OfflineResources.Path = (Resolve-FullPath -Path $ResourcesRoot -Child Offline-Resources.psm1)
$OfflineResources.Name = (Resolve-FullPath -Path $OfflineResources.Path -Split Leaf)
$OfflineResources.BaseName = ([IO.Path]::GetFileNameWithoutExtension($OfflineResources.Name))
$OfflineResources.Directory = (Resolve-FullPath -Path $OfflineResources.Path -Split Parent)
$OptimizeOffline = [Collections.Specialized.OrderedDictionary]::New()
$OptimizeOffline.Path = (Resolve-FullPath -Path $ModuleRoot -Child Optimize-Offline.psm1)
$OptimizeOffline.Name = (Resolve-FullPath $OptimizeOffline.Path -Split Leaf)
$OptimizeOffline.BaseName = ([IO.Path]::GetFileNameWithoutExtension($OptimizeOffline.Name))
$OptimizeOffline.Directory = (Resolve-FullPath -Path $OptimizeOffline.Path -Split Parent)
$OptimizeOffline.Culture = 'en-US'
$OptimizeOffline.Resources = (Resolve-FullPath -Path $OptimizeOffline.Directory -Child Src)
$OptimizeOffline.Content = (Resolve-FullPath -Path $OptimizeOffline.Directory -Child Content)
$OptimizeOffline.LocalizedData = (Resolve-FullPath -Path $OptimizeOffline.Directory -Child $OptimizeOffline.Culture)
$OptimizeOffline.Additional = (Resolve-FullPath -Path $OptimizeOffline.Content -Child Additional)
$OptimizeOffline.Packages = (Resolve-FullPath -Path $OptimizeOffline.Directory -Child Packages)
$OptimizeOffline.LocalizedDataStrings = (Resolve-FullPath -Path $OptimizeOffline.LocalizedData -Child Optimize-Offline.strings.psd1)
$OptimizeOffline.ConfigurationJSON = (Resolve-FullPath -Path $OptimizeOffline.Directory -Child Configuration.json)
$OptimizeOffline.ManifestDataFile = (Resolve-FullPath -Path $OptimizeOffline.Directory -Child Optimize-Offline.psd1)
$OptimizeOffline.AppxWhitelist = (Resolve-FullPath -Path $OptimizeOffline.Content -Child AppxWhitelist.json)
$OptimizeOffline.CustomAppAssociations = (Resolve-FullPath -Path $OptimizeOffline.Content -Child CustomAppAssociations.xml)
$OptimizeOffline.DevMode = (Resolve-FullPath -Path $OptimizeOffline.Packages -Child DeveloperMode)
$OptimizeOffline.WindowsStore = (Resolve-FullPath -Path $OptimizeOffline.Packages -Child WindowsStore)
$OptimizeOffline.MicrosoftEdge = (Resolve-FullPath -Path $OptimizeOffline.Packages -Child MicrosoftEdge)
$OptimizeOffline.Win32Calc = (Resolve-FullPath -Path $OptimizeOffline.Packages -Child Win32Calc)
$OptimizeOffline.Dedup = (Resolve-FullPath -Path $OptimizeOffline.Packages -Child Deduplication)
$OptimizeOffline.DaRT = (Resolve-FullPath -Path $OptimizeOffline.Packages -Child DaRT)
$OptimizeOffline.Setup = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child Setup)
$OptimizeOffline.Wallpaper = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child Wallpaper)
$OptimizeOffline.SystemLogo = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child SystemLogo)
$OptimizeOffline.LockScreen = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child LockScreen)
$OptimizeOffline.RegistryTemplates = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child RegistryTemplates)
$OptimizeOffline.LayoutModification = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child LayoutModification)
$OptimizeOffline.Unattend = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child Unattend)
$OptimizeOffline.Drivers = (Resolve-FullPath -Path $OptimizeOffline.Additional -Child Drivers)
$OptimizeOffline.InstallDrivers = (Resolve-FullPath -Path $OptimizeOffline.Drivers -Child Install)
$OptimizeOffline.BootDrivers = (Resolve-FullPath -Path $OptimizeOffline.Drivers -Child Boot)
$OptimizeOffline.RecoveryDrivers = (Resolve-FullPath -Path $OptimizeOffline.Drivers -Child Recovery)
#endregion Module Path Declarations
#region Data Declarations
Try { $ManifestData = Import-PowerShellDataFile -Path $OptimizeOffline.ManifestDataFile -ErrorAction Stop }
Catch { Write-Warning ('Failed to import the manifest data file: "{0}"' -f (Resolve-FullPath -Path $OptimizeOffline.ManifestDataFile -Split Leaf)); Break }
Try { Import-LocalizedData -BaseDirectory $OptimizeOffline.Directory -FileName Optimize-Offline.strings.psd1 -BindingVariable OptimizeData -ErrorAction Stop }
Catch { Write-Warning ('Failed to import the localized data file: "{0}"' -f (Resolve-FullPath -Path $OptimizeOffline.LocalizedDataStrings -Split Leaf)); Break }
#endregion Data Declarations
#region Variable Declarations
$LocalScope = [PSCustomObject]::New()
$OptimizeOfflineParams = [PSCustomObject]::New()
$DynamicParams = [Collections.Hashtable]::New()
$ConfigParams = [Collections.Specialized.OrderedDictionary]::New()
$OptimizeErrors = [List[Object]]::New()
$TempDirectory = (Resolve-FullPath -Path $OptimizeOffline.Directory -Child OfflineTemp_$(Get-Random))
$LogFolder = (Resolve-FullPath -Path $TempDirectory -Child LogOffline)
$WorkFolder = (Resolve-FullPath -Path $TempDirectory -Child WorkOffline)
$ScratchFolder = (Resolve-FullPath -Path $TempDirectory -Child ScratchOffline)
$ImageFolder = (Resolve-FullPath -Path $TempDirectory -Child ImageOffline)
$InstallMount = (Resolve-FullPath -Path $TempDirectory -Child InstallMountOffline)
$BootMount = (Resolve-FullPath -Path $TempDirectory -Child BootMountOffline)
$RecoveryMount = (Resolve-FullPath -Path $TempDirectory -Child RecoveryMountOffline)
$ModuleLog = (Resolve-FullPath -Path $LogFolder -Child Optimize-Offline.log)
$ErrorLog = (Resolve-FullPath -Path $LogFolder -Child OptimizeErrors.log)
$RegistryLog = (Resolve-FullPath -Path $LogFolder -Child RegistrySettings.log)
$DISMLog = (Resolve-FullPath -Path $LogFolder -Child DISM.log)
$DISM = If (Get-DeploymentTool) { Resolve-FullPath -Path $(Get-DeploymentTool) -Child dism.exe } Else { Resolve-FullPath -Path $Env:SystemRoot -Child 'System32\dism.exe' }
$OSCDIMG = If (Get-DeploymentTool -OSCDIMG) { Resolve-FullPath -Path $(Get-DeploymentTool -OSCDIMG) -Child oscdimg.exe } Else { $null }
$REG = (Resolve-FullPath -Path $Env:SystemRoot -Child 'System32\reg.exe')
$REGEDIT = (Resolve-FullPath -Path $Env:SystemRoot -Child regedit.exe)
$EXPAND = (Resolve-FullPath -Path $Env:SystemRoot -Child 'System32\expand.exe')
#endregion Variable Declarations
#region Resource Alias Creation
New-Alias -Name Create -Value New-Container
New-Alias -Name Purge -Value Remove-Container
New-Alias -Name StartExe -Value Start-Executable
New-Alias -Name Log -Value Write-Log
New-Alias -Name RegKey -Value Set-KeyProperty
New-Alias -Name RegHives -Value Get-OfflineHives
New-Alias -Name GetPath -Value Resolve-FullPath
#endregion Resource Alias Creation
$ExportResourceParams = @{
Function = $PublicFunctions.Basename
Variable = 'OptimizeOffline', 'ManifestData', 'OptimizeData', 'LocalScope', 'OptimizeParams', 'DynamicParams', 'ConfigParams', 'OptimizeErrors', 'TempDirectory', 'LogFolder', 'WorkFolder', 'ScratchFolder', 'ImageFolder', 'InstallMount', 'BootMount', 'RecoveryMount', 'ModuleLog', 'ErrorLog', 'RegistryLog', 'DISMLog', 'DISM', 'OSCDIMG', 'REG', 'REGEDIT', 'EXPAND'
Alias = '*'
}
Export-ModuleMember @ExportResourceParams
# SIG # Begin signature block
# MIIMFAYJKoZIhvcNAQcCoIIMBTCCDAECAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUJEtFCcJUCgrg3LUnsuvNRKks
# Sh2gggjkMIIDZTCCAk2gAwIBAgIQcvzm3AoNiblMifO61mXaqjANBgkqhkiG9w0B
# AQsFADBFMRQwEgYKCZImiZPyLGQBGRYEVEVDSDEVMBMGCgmSJomT8ixkARkWBU9N
# TklDMRYwFAYDVQQDEw1PTU5JQy5URUNILUNBMB4XDTE5MDUxNTEyMDYwN1oXDTI0
# MDUxNTEyMTYwN1owRTEUMBIGCgmSJomT8ixkARkWBFRFQ0gxFTATBgoJkiaJk/Is
# ZAEZFgV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