forked from couleur-tweak-tips/TweakList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Master.ps1
5508 lines (4679 loc) · 194 KB
/
Master.ps1
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file is automatically built at every push to combine every function into a single file
using namespace System.Management.Automation # Required by Invoke-NGENpsosh
Remove-Module TweakList -ErrorAction Ignore
New-Module TweakList ([ScriptBlock]::Create({
function Assert-Choice {
if (-Not(Get-Command choice.exe -ErrorAction Ignore)){
Write-Host "[!] Unable to find choice.exe (it comes with Windows, did a little bit of unecessary debloating?)" -ForegroundColor Red
PauseNul
exit 1
}
}
function Assert-Path {
param(
$Path
)
if (-Not(Test-Path -Path $Path)) {
New-Item -Path $Path -Force | Out-Null
}
}
function FindInText{
<#
Recreated a simple grep for finding shit in TweakList,
I mostly use this to check if a function/word has ever been mentionned in all my code
#>
param(
[String]$String,
$Path = (Get-Location),
[Array]$Exclude,
[Switch]$Recurse
)
$Exclude += @(
'*.exe','*.bin','*.dll'
'*.png','*.jpg'
'*.mkv','*.mp4','*.webm'
'*.zip','*.tar','*.gz','*.rar','*.7z','*.so'
'*.pyc','*.pyd'
)
$Parameters = @{
Path = $Path
Recurse = $Recurse
Exclude = $Exclude
}
$script:FoundOnce = $False
$script:Match = $null
Get-ChildItem @Parameters -File | ForEach-Object {
$Match = $null
Write-Verbose ("Checking " + $PSItem.Name)
$Match = Get-Content $PSItem.FullName | Where-Object {$_ -Like "*$String*"}
if ($Match){
$script:FoundOnce = $True
Write-Host "- Found in $($_.Name) ($($_.FullName))" -ForegroundColor Green
$Match
}
}
if (!$FoundOnce){
Write-Host "Not found" -ForegroundColor red
}
}
function Get-7zPath {
if (Get-Command 7z.exe -Ea Ignore){return (Get-Command 7z.exe).Source}
$DefaultPath = "$env:ProgramFiles\7-Zip\7z.exe"
if (Test-Path $DefaultPath) {return $DefaultPath}
Try {
$InstallLocation = (Get-Package 7-Zip* -ErrorAction Stop).Metadata['InstallLocation'] # Compatible with 7-Zip installed normally / with winget
if (Test-Path $InstallLocation -ErrorAction Stop){
return "$InstallLocation`7z.exe"
}
}Catch{} # If there's an error it's probably not installed anyways
if (Get-Boolean "7-Zip could not be found, would you like to download it using Scoop?"){
Install-Scoop
scoop install 7zip
if (Get-Command 7z -Ea Ignore){
return (Get-Command 7z.exe).Source
}else{
Write-Error "7-Zip could not be installed"
return
}
}else{return}
# leaving this here if anyone knows a smart way to implement this ))
# $7Zip = (Get-ChildItem -Path "$env:HOMEDRIVE\*7z.exe" -Recurse -Force -ErrorAction Ignore).FullName | Select-Object -First 1
}
function Get-Boolean {
param(
$Message
)
$null = $Response
$Response = Read-Host $Message
While ($Response -NotIn 'yes','y','n','no'){
Write-Host "Answer must be 'yes','y','n' or 'no'" -ForegroundColor Red
$Response = Read-Host $Message
}
if ($Response -in 'yes','y'){return $true}
elseif($Response -in 'n','no'){return $false}
else{Write-Error "Invalid response";pause;exit}
}
function Get-EncodingArgs{
[alias('genca')]
param(
[String]$Resolution = '3840x2160',
[Switch]$Silent,
[Switch]$EzEncArgs
)
Install-FFmpeg
$DriverVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B2FE1952-0186-46C3-BAEC-A80AA35AC5B8}_Display.Driver" -ErrorAction Ignore).DisplayVersion
if ($DriverVersion){ # Only triggers if it parsed a NVIDIA driver version, else it can probably be an NVIDIA GPU
if ($DriverVersion -lt 477.41){ # Oldest NVIDIA version capable
Write-Warning "Outdated NVIDIA Drivers detected ($DriverVersion), you won't be able to encode using NVENC util you update them."
}
}
$EncCommands = [ordered]@{
'HEVC NVENC' = 'hevc_nvenc -rc vbr -preset p7 -b:v 400M -cq 19'
'H264 NVENC' = 'h264_nvenc -rc vbr -preset p7 -b:v 400M -cq 16'
'HEVC AMF' = 'hevc_amf -quality quality -qp_i 16 -qp_p 18 -qp_b 20'
'H264 AMF' = 'h264_amf -quality quality -qp_i 12 -qp_p 12 -qp_b 12'
'HEVC QSV' = 'hevc_qsv -preset veryslow -global_quality:v 18'
'H264 QSV' = 'h264_qsv -preset veryslow -global_quality:v 15'
'H264 CPU' = 'libx264 -preset slow -crf 16 -x265-params aq-mode=3'
'HEVC CPU' = 'libx265 -preset medium -crf 18 -x265-params aq-mode=3:no-sao=1:frame-threads=1'
}
$EncCommands.Keys | ForEach-Object -Begin {
$script:shouldStop = $false
} -Process {
if ($shouldStop -eq $true) { return }
Invoke-Expression "ffmpeg.exe -loglevel fatal -f lavfi -i nullsrc=$Resolution -t 0.1 -c:v $($EncCommands.$_) -f null NUL"
if ($LASTEXITCODE -eq 0){
$script:valid_args = $EncCommands.$_
$script:valid_ezenc = $_
if ($Silent){
Write-Host ("Found compatible encoding settings using $PSItem`: {0}" -f ($EncCommands.$_)) -ForegroundColor Green
}
$shouldStop = $true # Crappy way to stop the loop since most people that'll execute this will technically be parsing the raw URL as a scriptblock
}
}
if (-Not($script:valid_args)){
Write-Host "No compatible encoding settings found (should not happen, is FFmpeg installed?)" -ForegroundColor DarkRed
Get-Command FFmpeg -Ea Ignore
pause
return
}
if ($EzEncArgs){
return $script:valid_ezenc
}else{
return $valid_args
}
}
function Get-FunctionContent {
[alias('gfc')]
[CmdletBinding()]
param([Parameter()]
[String[]]$Functions,
[Switch]$Dependencies,
[Switch]$ReturnNames
)
$FunctionsPassed = [System.Collections.ArrayList]@()
$Content = [System.Collections.ArrayList]@()
Get-Command $Functions -ErrorAction Stop | ForEach-Object { # Loop through all functions
if ($Resolved = $_.ResolvedCommand){ # Checks if $_.ResolveCommand exists, also assigns it to $Resolved
Write-Verbose "Switching from alias $_ to function $($Resolved.Name)" -Verbose
$_ = Get-Command $Resolved.Name
}
if ($_ -NotIn $FunctionsPassed){ # If it hasn't been looped over yet
$Content += ($Block = $_.ScriptBlock.Ast.Extent.Text)
# Assigns function block to $Block and appends to $Content
$FunctionsPassed.Add($_) | Out-Null # So it doesn't get checked again
if ($Dependencies){
if (!$TL_FUNCTIONS){
if (Get-Module -Name TweakList -ErrorAction Ignore){
$TL_FUNCTIONS = [String[]](Get-Module -Name TweakList).ExportedFunctions.Keys
}else {
throw "TL_FUNCTIONS variable is not defined, which is needed to get available TweakList functions"
}
}
$AST = [System.Management.Automation.Language.Parser]::ParseInput($Block, [ref]$null, [ref]$null)
$DepMatches = $AST.FindAll({
param ($node)
$node.GetType().Name -eq 'CommandAst'
}, $true) | #It gets all cmdlets from the Abstract Syntax Tree
ForEach-Object {$_.CommandElements[0].Value} | # Returns their name
Where-Object { # Filters out only TweakList functions
$_ -In ($TL_FUNCTIONS | Where-Object {$_ -ne $_.Name})
} | Select-Object -Unique
ForEach($Match in $DepMatches){
$FunctionsPassed.Add((Get-Command -Name $Match -CommandType Function)) | Out-Null
$Content += (Get-Command -Name $Match -CommandType Function).ScriptBlock.Ast.Extent.Text
}
}
}
}
if ($Content){
$Content = "#region gfc`n" + $Content + "`n#endregion"
}
if($ReturnNames){
return $FunctionsPassed | Select-Object -Unique # | Where-Object {$_ -notin $Functions}
} else {
return $Content
}
}
function Get-HeaderSize {
param(
$URL,
$FileName = "file"
)
Try {
$Size = (Invoke-WebRequest -Useb $URL -Method Head -ErrorAction Stop).Headers.'Content-Length'
}Catch{
Write-Host "Failed to parse $FileName size (Invalid URL?):" -ForegroundColor DarkRed
Write-Host $_.Exception.Message -ForegroundColor Red
return
}
return [Math]::Round((($Size | Select-Object -First 1) / 1MB), 2)
}
function Get-Path {
[alias('gpa')]
param($File)
if (-Not(Get-Command $File -ErrorAction Ignore)){return $null}
$BaseName, $Extension = $File.Split('.')
if (Get-Command "$BaseName.shim" -ErrorAction Ignore){
return (Get-Content (Get-Command "$BaseName.shim").Source | Select-Object -First 1).Trim('path = ').replace('"','')
}elseif($Extension){
return (Get-Command "$BaseName.$Extension").Source
}else{
return (Get-Command $BaseName).Source
}
}
function Get-ScoopApp {
[CmdletBinding()] param (
[Parameter(ValueFromRemainingArguments = $true)]
[System.Collections.Arraylist]
$Apps # Not necessarily plural
)
Install-Scoop
$Scoop = (Get-Item (Get-Command scoop).Source).Directory | Split-Path
$ToInstall = $Apps | Where-Object {$PSItem -NotIn (Get-ChildItem "$Scoop\apps")}
$Available = (Get-ChildItem "$Scoop\buckets\*\bucket\*").BaseName
$Buckets = (Get-ChildItem "$Scoop\buckets" -Directory).Name
$Installed = (Get-ChildItem "$Scoop\apps" -Directory).Name
$script:FailedToInstall = @()
function Get-Git {
if ('git' -NotIn $Installed){
scoop install git
if ($LASTEXITCODE -ne 0){
Write-Host "Failed to install Git." -ForegroundColor Red
return
}
}
$ToInstall = $ToInstall | Where-Object {$_ -ne 'git'}
}
$Repos = @{
main = @{org = 'ScoopInstaller' ;repo = 'main' ;branch = 'master'}
extras = @{org = 'ScoopInstaller' ;repo = 'extras' ;branch = 'master'}
utils = @{org = 'couleur-tweak-tips' ;repo = 'utils' ;branch = 'main' }
nirsoft = @{org = 'kodybrown' ;repo = 'scoop-nirsoft' ;branch = 'master'}
'games' = @{org = 'Calinou' ;repo = 'scoop-games' ;branch = 'master'}
'nerd-fonts' = @{org = 'matthewjberger' ;repo = 'scoop-nerd-fonts' ;branch = 'master'}
versions = @{org = 'ScoopInstaller' ;repo = 'versions' ;branch = 'master'}
java = @{org = 'ScoopInstaller' ;repo = 'java' ;branch = 'master'}
}
$RepoNames = $Repos.Keys -Split('\r?\n')
Foreach($App in $ToInstall){
if ($App.Split('/').Count -eq 2){
$Bucket, $App = $App.Split('/')
if ($Bucket -NotIn $RepoNames){
Write-Host "Bucket $Bucket is not known, add it yourself by typing 'scoop.cmd bucket add bucketname https://bucket.repo/url'"
continue
}elseif (($Bucket -NotIn $Buckets) -And ($Bucket -In $RepoNames)){
Get-Git
scoop bucket add $Repos.$Bucket.repo https://github.com/$($Repos.$Bucket.org)/$($Repos.$Bucket.repo)
}
}
$Available = (Get-ChildItem "$Scoop\buckets\*\bucket\*").BaseName
if ($App -NotIn $Available){
Remove-Variable -Name Found -ErrorAction Ignore
ForEach($Bucket in $RepoNames){
if ($Found){continue}
Write-Host "`rCould not find $App, looking for it in the $Bucket bucket.." -NoNewline
$Response = Invoke-RestMethod "https://api.github.com/repos/$($Repos.$Bucket.org)/$($Repos.$Bucket.repo)/git/trees//$($Repos.$Bucket.branch)?recursive=1"
$Manifests = $Response.tree.path | Where-Object {$_ -Like "bucket/*.json"}
$Manifests = ($Manifests).Replace('bucket/','').Replace('.json','')
if ($App -in $Manifests){
$script:Found = $True
''
Get-Git
scoop bucket add $Repos.$Bucket.repo https://github.com/$($Repos.$Bucket.org)/$($Repos.$Bucket.repo)
}else{''} # Fixes the -NoNewLine
}
}
# Wait-Debugger
scoop install $App
if ($LASTEXITCODE -ne 0){
$script:FailedToInstall += $App
Write-Verbose "$App exitted with code $LASTEXITCODE"
}
}
}
function Get-ShortcutTarget {
[alias('gst')]
param([String]$ShortcutPath)
Try {
$null = Get-Item $ShortcutPath -ErrorAction Stop
} Catch {
throw
}
return (New-Object -ComObject WScript.Shell).CreateShortcut($ShortcutPath).TargetPath
}
function Install-FFmpeg {
$IsFFmpegScoop = (Get-Command ffmpeg -Ea Ignore).Source -Like "*\shims\*"
if(Get-Command ffmpeg -Ea Ignore){
$IsFFmpeg5 = (ffmpeg -hide_banner -h filter=libplacebo) -ne "Unknown filter 'libplacebo'."
if (-Not($IsFFmpeg5)){
if ($IsFFmpegScoop){
Get Scoop
scoop update ffmpeg
}else{
Write-Warning @"
An old FFmpeg installation was detected @ ($((Get-Command FFmpeg).Source)),
You could encounter errors such as:
- Encoding with NVENC failing (in simple terms not being able to render with your GPU)
- Scripts using new filters (e.g libplacebo)
If you want to update FFmpeg yourself, you can remove it and use the following command to install ffmpeg and add it to the path:
iex(irm tl.ctt.cx);Get FFmpeg
If you're using it because you prefer old NVIDIA drivers (why) here be dragons!
"@
pause
}
}
}else{
Get Scoop
$Scoop = (Get-Command Scoop.ps1).Source | Split-Path | Split-Path
if (-Not(Test-Path "$Scoop\buckets\main")){
if (-Not(Test-Path "$Scoop\apps\git\current\bin\git.exe")){
scoop install git
}
scoop bucket add main
}
$Local = ((scoop cat ffmpeg) | ConvertFrom-Json).version
$Latest = (Invoke-RestMethod https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/ffmpeg.json).version
if ($Local -ne $Latest){
"FFmpeg version installed using scoop is outdated, updating Scoop.."
if (-not(Test-Path "$Scoop\apps\git")){
scoop install git
}
scoop update
}
scoop install ffmpeg
if ($LASTEXITCODE -ne 0){
Write-Warning "Failed to install FFmpeg"
pause
}
}
}
function Install-Scoop {
param(
[String]$InstallDir
)
Set-ExecutionPolicy Bypass -Scope Process -Force
if (-Not(Get-Command scoop -Ea Ignore)){
$RunningAsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')
if($InstallDir){
$env:SCOOP = $InstallDir
[Environment]::SetEnvironmentVariable('SCOOP', $env:SCOOP, 'User')
}
If (-Not($RunningAsAdmin)){
Invoke-Expression (Invoke-RestMethod -Uri http://get.scoop.sh)
}else{
Invoke-Expression "& {$(Invoke-RestMethod -Uri https://get.scoop.sh)} -RunAsAdmin"
}
}
Try {
scoop -ErrorAction Stop | Out-Null
} Catch {
Write-Host "Failed to install Scoop" -ForegroundColor DarkRed
Write-Host $_.Exception.Message -ForegroundColor Red
return
}
}
<#
.LINK
Frankensteined from Inestic's WindowsFeatures Sophia Script function
https://github.com/Inestic
https://github.com/farag2/Sophia-Script-for-Windows/blob/06a315c643d5939eae75bf6e24c3f5c6baaf929e/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1#L4946
.SYNOPSIS
User gets a nice checkbox-styled menu in where they can select
.EXAMPLE
Screenshot: https://i.imgur.com/zrCtR3Y.png
$ToInstall = Invoke-CheckBox -Items "7-Zip", "PowerShell", "Discord"
Or you can have each item have a description by passing an array of hashtables:
$ToInstall = Invoke-CheckBox -Items @(
@{
DisplayName = "7-Zip"
# Description = "Cool Unarchiver"
},
@{
DisplayName = "Windows Sandbox"
Description = "Windows' Virtual machine"
},
@{
DisplayName = "Firefox"
Description = "A great browser"
},
@{
DisplayName = "PowerShell 777"
Description = "PowerShell on every system!"
}
)
#>
function Invoke-Checkbox{
param(
$Title = "Select an option",
$ButtonName = "Confirm",
$Items = @("Fill this", "With passing an array", "to the -Item param!")
)
if (!$Items.Description){
$NewItems = @()
ForEach($Item in $Items){
$NewItems += @{DisplayName = $Item}
}
$Items = $NewItems
}
Add-Type -AssemblyName PresentationCore, PresentationFramework, System.Drawing, System.Windows.Forms, WindowsFormsIntegration
# Initialize an array list to store the selected Windows features
$SelectedFeatures = New-Object -TypeName System.Collections.ArrayList($null)
$ToReturn = New-Object -TypeName System.Collections.ArrayList($null)
#region XAML Markup
# The section defines the design of the upcoming dialog box
[xml]$XAML = '
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="Window"
MinHeight="450" MinWidth="400"
SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
FontFamily="Arial" FontSize="16" ShowInTaskbar="True"
Background="#F1F1F1" Foreground="#262626">
<Window.TaskbarItemInfo>
<TaskbarItemInfo/>
</Window.TaskbarItemInfo>
<Window.Resources>
<Style TargetType="StackPanel">
<Setter Property="Orientation" Value="Horizontal"/>
<Setter Property="VerticalAlignment" Value="Top"/>
</Style>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="10, 10, 5, 10"/>
<Setter Property="IsChecked" Value="True"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="5, 10, 10, 10"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="25"/>
<Setter Property="Padding" Value="15"/>
</Style>
<Style TargetType="Border">
<Setter Property="Grid.Row" Value="1"/>
<Setter Property="CornerRadius" Value="0"/>
<Setter Property="BorderThickness" Value="0, 1, 0, 1"/>
<Setter Property="BorderBrush" Value="#000000"/>
</Style>
<Style TargetType="ScrollViewer">
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="BorderBrush" Value="#000000"/>
<Setter Property="BorderThickness" Value="0, 1, 0, 1"/>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer Name="Scroll" Grid.Row="0"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto">
<StackPanel Name="PanelContainer" Orientation="Vertical"/>
</ScrollViewer>
<Button Name="Button" Grid.Row="2"/>
</Grid>
</Window>
'
#endregion XAML Markup
$Form = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml))
$XAML.SelectNodes("//*[@Name]") | ForEach-Object {
Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)
}
#region Functions
function Get-CheckboxClicked
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$CheckBox
)
$Feature = $Items | Where-Object -FilterScript {$_.DisplayName -eq $CheckBox.Content}
if ($CheckBox.IsChecked) {
[void]$SelectedFeatures.Add($Feature)
}
else {
[void]$SelectedFeatures.Remove($Feature)
}
if ($SelectedFeatures.Count -gt 0) {
$Button.Content = $ButtonName
$Button.IsEnabled = $true
}
else {
$Button.Content = "Cancel"
$Button.IsEnabled = $true
}
}
function Add-FeatureControl
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[ValidateNotNull()]
$Feature
)
process {
$StackPanel = New-Object -TypeName System.Windows.Controls.StackPanel
$CheckBox = New-Object -TypeName System.Windows.Controls.CheckBox
$CheckBox.Add_Click({Get-CheckboxClicked -CheckBox $_.Source})
$Checkbox.Content = $Feature.DisplayName
if ($Feature.Description){
$CheckBox.ToolTip = $Feature.Description
}
$Checkbox.IsChecked = $False
[void]$StackPanel.Children.Add($CheckBox)
[void]$PanelContainer.Children.Add($StackPanel)
}
}
$Window.Add_Loaded({$Items | Add-FeatureControl})
$Button.Content = $ButtonName
$Button.Add_Click({
[void]$Window.Close()
$ToReturn.Add($SelectedFeatures.DisplayName)
})
$Window.Title = $Title
# ty chrissy <3 https://blog.netnerds.net/2016/01/adding-toolbar-icons-to-your-powershell-wpf-guis/
$base64 = "iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAMAAADyHTlpAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAPUExURQAAAP///+vr6+fn5wAAAD8IT84AAAAFdFJOU/////8A+7YOUwAAAAlwSFlzAAALEwAACxMBAJqcGAAAANBJREFUSEut08ESgjAMRVFQ/v+bDbxLm9Q0lRnvQtrkDBt1O4a2FoNWHIBajJW/sQ+xOnNnlkMsrXZkkwRolHHaTXiUYfS5SOgXKfuQci0T5bLoIeWYt/O0FnTfu62pyW5X7/S26D/yFca19AvBXMaVbrnc3n6p80QGq9NUOqtnIRshhi7/ffHeK0a94TfQLQPX+HO5LVef0cxy8SX/gokU/bIcQvxjB5t1qYd0aYWuz4XF6FHam/AsLKDTGWZpuWNqWZ358zdmrOLNAlkM6Dg+78AGkhvs7wgAAAAASUVORK5CYII="
# Create a streaming image by streaming the base64 string to a bitmap streamsource
$bitmap = New-Object System.Windows.Media.Imaging.BitmapImage
$bitmap.BeginInit()
$bitmap.StreamSource = [System.IO.MemoryStream][System.Convert]::FromBase64String($base64)
$bitmap.EndInit()
$bitmap.Freeze()
# This is the toolbar icon and description
$Form.TaskbarItemInfo.Overlay = $bitmap
$Form.TaskbarItemInfo.Description = $window.Title
$Window.Add_Closing({[System.Windows.Forms.Application]::Exit()})
$Form.Show()
# This makes it pop up
$Form.Activate() | Out-Null
# Create an application context for it to all run within.
# This helps with responsiveness and threading.
$appContext = New-Object System.Windows.Forms.ApplicationContext
[void][System.Windows.Forms.Application]::Run($appContext)
return $ToReturn
}
#using namespace System.Management.Automation # this can't be a function but whatever, it doesn't slow down anything
# Author: Collin Chaffin
# License: MIT (https://github.com/CollinChaffin/psNGENposh/blob/master/LICENSE)
function Invoke-NGENposh {
<#
.SYNOPSIS
This Powershell function performs various SYNCHRONOUS ngen functions
.DESCRIPTION
This Powershell function performs various SYNCHRONOUS ngen functions
Since the purpose of this module is to for interactive use,
I intentionally did not include any "Queue" options.
.PARAMETER All
Regenerate cache for all system assemblies
.PARAMETER Force
Invoke ngen on currently loaded assembles (ensure up to date even if cached)
.EXAMPLE
To invoke ngen on currently loaded assembles, skipping those already generated:
PS C:\> Invoke-NGENposh
.EXAMPLE
To invoke ngen on currently loaded assembles (ensure up to date even if cached):
PS C:\> Invoke-NGENposh -Force
.EXAMPLE
To invoke ngen to regenerate cache for all system assemblies (*SEE WARNING BELOW**):
PS C:\> Invoke-NGENposh -All
.NOTES
**WARNING: The '-All' switch since the execution is SYNCHRONOUS will
take considerable time, and literally regenerate all the
global assembly cache. There should theoretically be no
downside to this, but bear in mind other than time (and cpu)
that since all the generated cache files are new, any
system backups will consider those files as new and may
likely cause your next incremental backup to be much larger
#>
param
(
[switch]$All,
[switch]$Force,
[switch]$Confirm
)
if (!$Confirm){
Write-Host "Press enter to continue and start using NGENPosh, or press CTRL+C to cancel"
pause
}
# INTERNAL HELPER
function Write-InfoInColor
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$Message,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.ConsoleColor[]]$Background = $Host.UI.RawUI.BackgroundColor,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[System.ConsoleColor[]]$Foreground = $Host.UI.RawUI.ForegroundColor,
[Switch]$NoNewline
)
[HostInformationMessage]$outMessage = @{
Message = $Message
ForegroundColor = $Foreground
BackgroundColor = $Background
NoNewline = $NoNewline
}
Write-Information $outMessage -InformationAction Continue
}
Write-InfoInColor "`n===================================================================================" -Foreground 'DarkCyan'
Write-InfoInColor " BEGINNING TO NGEN " -Foreground 'Cyan'
Write-InfoInColor "===================================================================================`n" -Foreground 'DarkCyan'
Set-Alias ngenpsh (Join-Path ([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) ngen.exe) -Force
if ($All)
{
Write-InfoInColor "EXECUTING GLOBAL NGEN`n`n" -Foreground 'Cyan'
ngenpsh update /nologo /force
}
else
{
Write-InfoInColor "EXECUTING TARGETED NGEN`n`n" -Foreground 'Cyan'
[AppDomain]::CurrentDomain.GetAssemblies() |
ForEach-Object {
if ($_.Location)
{
$Name = (Split-Path $_.location -leaf)
if ((!($Force)) -and [System.Runtime.InteropServices.RuntimeEnvironment]::FromGlobalAccessCache($_))
{
Write-InfoInColor "[SKIPPED]" -Foreground 'Yellow' -NoNewLine
Write-InfoInColor " :: " -Foreground 'White' -NoNewline
Write-InfoInColor "[ $Name ]" -Foreground 'Cyan'
}
else
{
ngenpsh install $_.location /nologo | ForEach-Object {
if ($?)
{
Write-InfoInColor "[SUCCESS]" -Foreground 'Green' -NoNewLine
Write-InfoInColor " :: " -Foreground 'White' -NoNewline
Write-InfoInColor "[ $Name ]" -Foreground 'Cyan'
}
else
{
Write-InfoInColor "[FAILURE]" -Foreground 'Red' -NoNewLine
Write-InfoInColor " :: " -Foreground 'White' -NoNewline
Write-InfoInColor "[ $Name ]" -Foreground 'Cyan'
}
}
}
}
}
}
Write-InfoInColor "`n===================================================================================" -Foreground 'DarkCyan'
Write-InfoInColor " COMPLETED NGEN " -Foreground 'Cyan'
Write-InfoInColor "===================================================================================`n" -Foreground 'DarkCyan'
}
function Invoke-Registry {
[alias('ireg')]
param(
[Parameter(
Position = 0,
Mandatory=$true,
ValueFromPipeline = $true
)
][Array]$Path,
[Parameter(
Position = 1,
Mandatory=$true
)
][HashTable]$HashTable
)
Process {
"doing $path"
$Path = "REGISTRY::$($Path -replace 'REGISTRY::','')"
"now its $path"
if (-Not(Test-Path -LiteralPath $Path)){
New-Item -ItemType Key -Path $Path -Force
}
ForEach($Key in $HashTable.Keys){
Set-ItemProperty -LiteralPath $Path -Name $Key -Value $HashTable.$Key
}
}
}
function IsCustomISO {
switch (
Get-ItemProperty "REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation"
){
{$_.SupportURL -Like "https://atlasos.net*"}{return 'AtlasOS'}
{$_.Manufacturer -eq "Revision"}{return 'Revision'}
{$_.Manufacturer -eq "ggOS"}{return 'ggOS'}
}
return $False
}
# https://github.com/chrisseroka/ps-menu
function Menu {
param ([array]$menuItems, [switch]$ReturnIndex=$false, [switch]$Multiselect)
function DrawMenu {
param ($menuItems, $menuPosition, $Multiselect, $selection)
$l = $menuItems.length
for ($i = 0; $i -le $l;$i++) {
if ($menuItems[$i] -ne $null){
$item = $menuItems[$i]
if ($Multiselect)
{
if ($selection -contains $i){
$item = '[x] ' + $item
}
else {
$item = '[ ] ' + $item
}
}
if ($i -eq $menuPosition) {
Write-Host "> $($item)" -ForegroundColor Green
} else {
Write-Host " $($item)"
}
}
}
}
function Toggle-Selection {
param ($pos, [array]$selection)
if ($selection -contains $pos){
$result = $selection | where {$_ -ne $pos}
}
else {
$selection += $pos
$result = $selection
}
$result
}
$vkeycode = 0
$pos = 0
$selection = @()
if ($menuItems.Length -gt 0)
{
try {
[console]::CursorVisible=$false #prevents cursor flickering
DrawMenu $menuItems $pos $Multiselect $selection
While ($vkeycode -ne 13 -and $vkeycode -ne 27) {
$press = $host.ui.rawui.readkey("NoEcho,IncludeKeyDown")
$vkeycode = $press.virtualkeycode
If ($vkeycode -eq 38 -or $press.Character -eq 'k') {$pos--}
If ($vkeycode -eq 40 -or $press.Character -eq 'j') {$pos++}
If ($vkeycode -eq 36) { $pos = 0 }
If ($vkeycode -eq 35) { $pos = $menuItems.length - 1 }
If ($press.Character -eq ' ') { $selection = Toggle-Selection $pos $selection }
if ($pos -lt 0) {$pos = 0}
If ($vkeycode -eq 27) {$pos = $null }
if ($pos -ge $menuItems.length) {$pos = $menuItems.length -1}
if ($vkeycode -ne 27)
{
$startPos = [System.Console]::CursorTop - $menuItems.Length
[System.Console]::SetCursorPosition(0, $startPos)
DrawMenu $menuItems $pos $Multiselect $selection
}
}
}
finally {
[System.Console]::SetCursorPosition(0, $startPos + $menuItems.Length)
[console]::CursorVisible = $true
}
}
else {
$pos = $null
}
if ($ReturnIndex -eq $false -and $pos -ne $null)
{
if ($Multiselect){
return $menuItems[$selection]
}
else {
return $menuItems[$pos]
}
}
else
{
if ($Multiselect){
return $selection
}
else {
return $pos
}
}
}
<#
$Original = @{
lets = 'go'
Sub = @{
Foo = 'bar'
big = 'ya'
}
finish = 'fish'
}
$Patch = @{
lets = 'arrive'
Sub = @{
Foo = 'baz'
}
finish ='cum'
New="Ye"
}
#>
function Merge-Hashtables {
param(
$Original,
$Patch
)
$Merged = @{} # Final Merged settings
if (!$Original){$Original = @{}}
if ($Original.GetType().Name -in 'PSCustomObject','PSObject'){
$Temp = [ordered]@{}