-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeardownModsManager.ps1
1783 lines (1539 loc) · 127 KB
/
TeardownModsManager.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
<# Teardown Mods Manager v2.1.2 | by Timothy Gruber
Designed and written by Timothy Gruber:
https://timothygruber.com
https://github.com/tjgruber/TeardownModsManager
#>
#region Run script as elevated admin and unrestricted executionpolicy
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID)
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator
if ($myWindowsPrincipal.IsInRole($adminRole)) {
$Host.UI.RawUI.WindowTitle = "Teardown Mods Manager v2.1.2 | by Timothy Gruber"
$Host.UI.RawUI.BackgroundColor = "DarkBlue"
Clear-Host
} else {
Start-Process PowerShell.exe -ArgumentList "-ExecutionPolicy Unrestricted -NoExit $($script:MyInvocation.MyCommand.Path)" -Verb RunAs
Exit
}
#endregion
Write-Host "Running Teardown Mods Manager v2.1.2 | by Timothy Gruber...`n`nClosing this window will close Teardown Mods Manager.`n"
# ███ ███ █████ ██ ███ ██ ██ ██ ██ ███ ██ ██████ ██████ ██ ██
# ████ ████ ██ ██ ██ ████ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██
# ██ ████ ██ ███████ ██ ██ ██ ██ ██ █ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █ ██
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
# ██ ██ ██ ██ ██ ██ ████ ███ ███ ██ ██ ████ ██████ ██████ ███ ███
#region MAIN WINDOW
$syncHash = [hashtable]::Synchronized(@{})
$manWindowRunspace = [runspacefactory]::CreateRunspace()
$manWindowRunspace.Name = "MainWindow"
$manWindowRunspace.ApartmentState = "STA"
$manWindowRunspace.ThreadOptions = "ReuseThread"
$manWindowRunspace.Open()
$manWindowRunspace.SessionStateProxy.SetVariable("syncHash", $syncHash)
$manWindowRunspaceScript = [PowerShell]::Create().AddScript({
Add-Type -AssemblyName PresentationCore,PresentationFramework
#############################################
#############################################
#region FUNCTIONS
#############################################
#############################################
function Write-Log {
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline=$true,Mandatory,Position=0)]
[string]$Message,
[switch]$ClearLog,
[switch]$WriteOut
)
begin {
if (($ClearLog) -or ($syncHash.tmmLog -notmatch "Log initialized:")) {
$syncHash.tmmLog = @"
Log initialized: $(Get-Date)
"@
}
}
process {
$timestamp = "$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')"
$logText = "[$timestamp]`t$Message"
$syncHash.tmmLog += "`n$logText"
}
end {
if ($WriteOut) {
Write-Output -InputObject $syncHash.tmmLog
}
}
}
Function Update-Window {
Param (
$Control,
$Property,
$Value,
[switch]$AppendContent
)
If ($Property -eq "Close") {
$syncHash.Window.Dispatcher.invoke([action]{$syncHash.Window.Close()},"Normal")
Return
}
$syncHash.$Control.Dispatcher.Invoke([action]{
If ($PSBoundParameters['AppendContent']) {
$syncHash.$Control.AppendText($Value)
} Else {
$syncHash.$Control.$Property = $Value
}
}, "Normal")
if ($Control -eq 'StatusBarText' -and $Property -eq 'Text') {
Write-Log -Message $Value
}
}
function Invoke-TablePrep {
$columns = @(
'ModName'
'ModVersion'
'ModAuthor'
'ModDescription'
'ModPath'
'ModWebpage'
'ModDownloadLink'
)
$syncHash.dataTable = New-Object System.Data.DataTable
$syncHash.dataTable.Columns.AddRange($columns)
$syncHash.headerRow = $syncHash.dataTable.NewRow()
$syncHash.headerRow.ModName = 'Mod Name'
$syncHash.headerRow.ModVersion = 'Mod Version'
$syncHash.headerRow.ModAuthor = 'Mod Author'
$syncHash.headerRow.ModDescription = 'Mod Description'
$syncHash.headerRow.ModPath = 'Mod Path'
$syncHash.headerRow.ModWebpage = 'Mod Webpage'
$syncHash.headerRow.ModDownloadLink = 'Mod Download Link'
$syncHash.dataTable.Rows.Add($syncHash.headerRow)
$syncHash.ModsListDataGrid.ItemsSource = $syncHash.dataTable.DefaultView
$syncHash.ModsListDataGrid.IsReadOnly = $True
$syncHash.ModsListDataGrid.CanUserAddRows = $False
$syncHash.ModsListDataGrid.Visibility = "Visible"
}
function Get-ModDeets {
[CmdletBinding()]
param (
[String]$ModDir,
[Switch]$Single
)
"Running Get-ModDeets function" | Write-Log
if (-not $ModDir) {
if ($true -eq (Test-Path -Path "$env:USERPROFILE\Documents\Teardown\mods" -PathType Container)) {
$ModDir = "$env:USERPROFILE\Documents\Teardown\mods"
$allMods = Get-ChildItem -Path $modDir -Directory
}
} else {
"ModDir is [$ModDir]" | Write-Log
if ($true -eq (Test-Path -Path $ModDir -PathType Container)) {
"ModDir [$ModDir] tests good" | Write-Log
if ($Single) {
$allMods = Get-Item -Path $modDir
} else {
$allMods = Get-ChildItem -Path $modDir -Directory
}
} else {"ERROR: ModDir [$ModDir] test failed." | Write-Log}
}
$crestaNameFilter = "500 Magnum|AC130 Airstrike|AK-47|AWP|Black Hole|Charge Shotgun|Desert Eagle|Dragonslayer|Dual Berettas|Dual Miniguns|Exploding Star|Guided Missile|Hadouken|Holy Grenade|Laser Cutter|Lightkatana|M4A1|M249|MGL|Minigun|Mjolner|Nova|P90|RPG|SCAR-20|Scorpion|SG-553"
$crestaAuthorFilter = "My Cresta"
$crestaMods = foreach ($mod in $allMods | Where-Object {$_.Name -match $crestaNameFilter}) {
$modInfo = Get-Content -Path "$($mod.Fullname)\info.txt"
$modAuthor = if (($modInfo -match 'author = ' -split 'author = ')[1].Length -gt 2) {($modInfo -match 'author = ' -split 'author = ')[1]} else {"modAuthor not found"}
if ($modAuthor -eq $crestaAuthorFilter) {
$mod
}
}
$crestaMod = $crestaMods | Select-Object -First 1
$allModsDeets = foreach ($mod in $allMods) {
$modInfo = Get-Content -Path "$($mod.Fullname)\info.txt"
$modName = if (($modInfo -match 'name = ' -split 'name = ')[1].Length -gt 2) {($modInfo -match 'name = ' -split 'name = ')[1] -replace "_",' '} else {"name not found in mod info.txt"}
$modVersion = if (($modInfo -match 'version = ' -split 'version = ')[1].Length -gt 2) {($modInfo -match 'version = ' -split 'version = ')[1] -replace "_",' '} else {"version missing in mod info.txt"}
$modAuthor = if (($modInfo -match 'author = ' -split 'author = ')[1].Length -gt 2) {($modInfo -match 'author = ' -split 'author = ')[1]} else {"author not found in mod info.txt"}
$modDescription = if (($modInfo -match 'description = ' -split 'description = ')[1].Length -gt 2) {($modInfo -match 'description = ' -split 'description = ')[1]} else {"description not found in mod info.txt"}
# Valid mod check:
if(($modInfo -match 'name = ' -split 'name = ')[1].Length -lt 2) {
"WARNING: [$($mod.Fullname)] is not a valid mod." | Write-Log
Continue
}
# MyCresta Check
if (($modAuthor -eq "My Cresta") -and ($mod -ne $crestaMod)) {
Continue
}
#Write-Host "Processing mod: [$modName]"
if (($modName -split " ").Count -eq 1) {
$modSearchName = $modName -replace "'s",''
} elseif (($modName -split " ").Count -eq 2) {
$modSearchNameSplit = $modName -split " "
$modSearchName = $modSearchNameSplit[0] + " " + $modSearchNameSplit[1] -replace "'s",''
} else {
$modSearchNameSplit = $modName -split " "
$modSearchName = $modSearchNameSplit[0] + " " + $modSearchNameSplit[1] -replace "'s",''
}
if ($mod -eq $crestaMod) {
$modSearchName = "Functional Weapon Pack"
$modName = "Functional Weapon Pack"
$modDescription = "28 Different Fully Working Weapons"
}
[PSCustomObject]@{
'ModName' = $modName
'ModVersion' = $modVersion
'ModAuthor' = $modAuthor
'ModDescription' = $modDescription
'ModPath' = $mod.Fullname
'ModWebPage' = if ($modWebLink.Length -gt 25) {$modWebLink} else {"NA"}
'ModDownloadLink' = if ($modPackageDownloadLink.Length -gt 25) {$modPackageDownloadLink} else {"NA"}
'modSearchName' = $modSearchName
}
$modInfo = $null
$modName = $null
$modVersion = $null
$modAuthor = $null
$modDescription = $null
}
"End Get-ModDeets function." | Write-Log
Write-Output -InputObject $allModsDeets
}
#############################################
#############################################
#endRegion FUNCTIONS
#############################################
#############################################
#############################################
#############################################
#region XML PREP
#############################################
#############################################
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Teardown Mods Manager v2.1.2 | by Timothy Gruber" Height="540" Width="1000" ScrollViewer.VerticalScrollBarVisibility="Disabled" MinWidth="966" MinHeight="500">
<Grid>
<DockPanel>
<StatusBar DockPanel.Dock="Bottom">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Margin="2,0,0,0">
<TextBlock Name="StatusBarText" Text="Ready..." />
</StatusBarItem>
<Separator Grid.Column="1" />
<StatusBarItem Grid.Column="2" Margin="0,0,0,0" Foreground="Red">
<Button Name="ExportLogsButton" Content="Export Logs" MinWidth="80" />
</StatusBarItem>
<Separator Grid.Column="3" />
<StatusBarItem Grid.Column="4" Margin="0,0,2,0">
<ProgressBar Name="ProgressBar" Value="0" Width="150" Height="16" />
</StatusBarItem>
</StatusBar>
<TabControl>
<TabItem Header="Installed Mods" HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" TextOptions.TextFormattingMode="Display" Width="125">
<DockPanel Margin="0,5,0,0">
<Grid DockPanel.Dock="Bottom" Margin="5,1"/>
<DockPanel DockPanel.Dock="Right" Margin="0">
<DockPanel DockPanel.Dock="Top" Margin="0">
<Button DockPanel.Dock="Right" Name="BackupAllMods" Content="Backup All Mods" VerticalAlignment="Center" Height="30" Width="150" FontSize="14" Padding="10,1" Margin="5,0" HorizontalAlignment="Right" FontWeight="Bold"/>
<Button DockPanel.Dock="Right" Name="ReloadModList" Content="Reload Mod List" VerticalAlignment="Center" Height="30" Width="150" FontSize="14" Padding="10,1" Margin="5,0" HorizontalAlignment="Right" FontWeight="Bold"/>
<Button DockPanel.Dock="Right" Name="DeleteSelectedMod" Content="Delete Selected Mod" VerticalAlignment="Center" Height="30" Width="150" FontSize="12" Padding="10,1" Margin="5,0" HorizontalAlignment="Right" FontWeight="Bold" BorderThickness="2" BorderBrush="#FFAA1F1F" Foreground="#FF8D0000" Background="#FFFFF5B7"/>
<Button DockPanel.Dock="Left" Name="UpdateAllSelectedMods" Content="Update All Selected Mods" VerticalAlignment="Center" Height="30" Width="200" FontSize="14" Padding="10,1" Margin="5,0" HorizontalAlignment="Right" FontWeight="Bold"/>
<StackPanel DockPanel.Dock="Left" HorizontalAlignment="Left" Margin="0,0,5,0">
<Label Content="Teardown mods folder:" VerticalAlignment="Top" Padding="5,0" Margin="5,0" FontWeight="Bold" MinWidth="150" Height="15"/>
<TextBox Name="SelectDefaultModsLocation" VerticalAlignment="Center" Height="18" FontSize="12" Padding="0,0,5,0" Margin="5,0" HorizontalAlignment="Right" IsReadOnlyCaretVisible="True" IsReadOnly="True" ToolTip="Click to select your Teardown mods location if displayed default is incorrect." MinWidth="150"/>
</StackPanel>
</DockPanel>
<GroupBox Name="ModsListBoxGroupBox" Header="Installed Mods List" Margin="0,2,0,0">
<DataGrid DockPanel.Dock="Top" Name="ModsListDataGrid" HorizontalScrollBarVisibility="Visible" HeadersVisibility="None" Visibility="Hidden">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding 'ModName'}" Value="Mod Name">
<Setter Property="Background" Value="#F3F3F3" />
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
<DataTrigger Binding="{Binding 'ModVersion'}" Value="Mod Version">
<Setter Property="Background" Value="#F3F3F3" />
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
<DataTrigger Binding="{Binding 'ModAuthor'}" Value="Mod Author">
<Setter Property="Background" Value="#F3F3F3" />
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
<DataTrigger Binding="{Binding 'ModDescription'}" Value="Mod Description">
<Setter Property="Background" Value="#F3F3F3" />
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
<DataTrigger Binding="{Binding 'ModPath'}" Value="Mod Path">
<Setter Property="Background" Value="#F3F3F3" />
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
<DataTrigger Binding="{Binding 'ModWebpage'}" Value="Mod Webpage">
<Setter Property="Background" Value="#F3F3F3" />
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
<DataTrigger Binding="{Binding 'ModDownloadLink'}" Value="Mod Download Link">
<Setter Property="Background" Value="#F3F3F3" />
<Setter Property="FontWeight" Value="Medium" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
</GroupBox>
</DockPanel>
</DockPanel>
</TabItem>
<TabItem Header="Help" HorizontalAlignment="Left" Height="30" VerticalAlignment="Top" TextOptions.TextFormattingMode="Display" Width="100">
<DockPanel Margin="0,5,0,0">
<GroupBox Header="about" DockPanel.Dock="Bottom" VerticalAlignment="Bottom" FontWeight="Bold">
<ScrollViewer>
<TextBlock TextWrapping="Wrap" FontWeight="Normal"><Run FontWeight="Bold" Text="Created by: "/><Run Text="	Timothy Gruber
"/><Run FontWeight="Bold" Text="Website:	"/><Hyperlink NavigateUri="https://timothygruber.com/"><Run Text="TimothyGruber.com
"/></Hyperlink><Run FontWeight="Bold" Text="GitHub:		"/><Hyperlink NavigateUri="https://github.com/tjgruber/TeardownModsManager"><Run Text="https://github.com/tjgruber/TeardownModsManager
"/></Hyperlink><Run FontWeight="Bold" Text="Version:"/><Run Text="		v2.1.2"/></TextBlock>
</ScrollViewer>
</GroupBox>
<GroupBox Header="Help Menu:" FontWeight="Bold" FontSize="14">
<TabControl TabStripPlacement="Left">
<TabItem Header="General" Height="35" TextOptions.TextFormattingMode="Display" VerticalAlignment="Top" HorizontalContentAlignment="Stretch" FontSize="14">
<GroupBox Header="General..." FontSize="16">
<ScrollViewer>
<RichTextBox IsReadOnlyCaretVisible="True" IsReadOnly="True">
<FlowDocument>
<Paragraph FontWeight="Normal" FontSize="14">
<Run FontWeight="Bold" Text="Teardown Mods Manager"/>
<Run Text=" may be used to update, backup, and remove installed Teardown mods during the wait for Steam Workshop availability in Teardown 0.6, and possibly after."/>
</Paragraph>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Now fully functional, but still a work in progress, at least until Steam Workshop implementation in Teardown 0.6 potentially makes this obsolete."/>
</Paragraph>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="All mods are checked against "/>
<Run FontStyle="Italic" Text="teardownmods.com"/>
<Run Text=". If you have any issues with a specific mod (or the app itself), use the "/>
<Run FontWeight="Bold" Text="Export Logs"/>
<Run Text=" button to examine the logs and include them in your report."/>
</Paragraph>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Foreground="#FF006E8F" FontWeight="Bold" Text="Tip:"/>
<Run FontWeight="Bold" FontSize="16" Text=" "/>
<Run Text="If you delete a mod by mistake, you can reinstall it by selecting it, and clicking the "/>
<Run FontWeight="Bold" Text="Update All Selected Mods"/>
<Run Text=" button. Once you reload the mod list, this is no longer possible, as the mod will no longer be shown in the "/>
<Run FontStyle="Italic" Text="Installed Mods List"/>
<Run Text="."/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</ScrollViewer>
</GroupBox>
</TabItem>
<TabItem Header="Installed Mods Tab" Height="35" VerticalAlignment="Top" TextOptions.TextFormattingMode="Display" FontSize="14">
<GroupBox Header="Installed Mods Tab..." FontSize="16">
<ScrollViewer>
<RichTextBox IsReadOnlyCaretVisible="True" IsReadOnly="True">
<FlowDocument>
<Paragraph FontWeight="Normal" FontSize="14" Padding="0,2,0,0">
<Run Text="Select the mods you wish to update, then click the "/>
<Run FontWeight="Bold" Text="Update All Selected Mods"/>
<Run Text=" button. This can take some time if you select a lot of mods at once. Sometimes the downloads are slow, you can export logs while processing if needed."/>
</Paragraph>
<Paragraph FontWeight="Normal" FontSize="14" Padding="0,2,0,0">
<Run Text="On app load, all mods in the default mods folder should be displayed. The Cresta weapon pack is an exception, which handles them all as a single mod."/>
</Paragraph>
<List>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Changing the default mods location is now supported, and will automatically reload the mods list with validated mods. ** Click the mods folder path textbox to change. **"/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Basic mod validation is used. If 'info.txt' does not exist or include mod name, it is ignored and not included in the list."/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Make sure to back up your mods folder. By default, this is your "/>
<Run FontStyle="Italic" Text="Documents\Teardown\mods"/>
<Run Text=" folder. You may use the "/>
<Run FontWeight="Bold" Text="Backup All Mods"/>
<Run Text=" button to do this for you."/>
</Paragraph>
</ListItem>
</List>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Foreground="#FF006E8F" FontWeight="Bold" Text="Note:"/>
<Run Text=" When a mod developer fixes naming consistency of a mod that was previously inconsistent, you may get an error saying the mod could not be found after extraction. This is expected. Try reloading mod list, and trying again, as the error is correct, but it still likely updated just fine."/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</ScrollViewer>
</GroupBox>
</TabItem>
<TabItem Header="Backup All Mods" Height="35" VerticalAlignment="Top" TextOptions.TextFormattingMode="Display" FontSize="14">
<GroupBox Header="Backup All Mods Button..." FontSize="16">
<ScrollViewer>
<RichTextBox IsReadOnlyCaretVisible="True" IsReadOnly="True">
<FlowDocument>
<Paragraph FontWeight="Normal" FontSize="14" Padding="0,2,0,0">
<Run Text="It should be said that the first thing to be done is backing up your mods. You can do this automatically by clicking the "/>
<Run FontWeight="Bold" Text="Backup All Mods"/>
<Run Text=" button."/>
</Paragraph>
<List>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="This will back up your "/>
<Run FontStyle="Italic" Text="Documents\Teardown\mods"/>
<Run Text=" folder to a zip file: "/>
<Run FontStyle="Italic" Text="Documents\Teardown\mods_backup_132566554489856810.zip"/>
<Run Text="."/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="You can also do it manually and likely faster by copying and pasting a copy of your mods folder to somewhere else."/>
</Paragraph>
</ListItem>
</List>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Foreground="#FF006E8F" FontWeight="Bold" Text="Note:"/>
<Run Text=" "/>
<Run Text="This process can take awhile depending on how big your mods folder is. It can take around 30 seconds per gig. In my test, it took about 30 seconds to back up a mods folder that is 1.4GB."/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</ScrollViewer>
</GroupBox>
</TabItem>
<TabItem Header="Mod Compatibility" Height="35" VerticalAlignment="Top" TextOptions.TextFormattingMode="Display" FontSize="14">
<GroupBox Header="Mod devs: to help ensure mod compatibility with Teardown Mods Manager..." FontSize="16">
<ScrollViewer>
<RichTextBox IsReadOnlyCaretVisible="True" IsReadOnly="True">
<FlowDocument>
<Paragraph FontWeight="Normal" FontSize="14" Padding="0,2,0,0">
<Run Text="Teardown Mods Manager supports updating mods archived with 7-Zip (.7z), WinRAR (.rar), and Zip (.zip)."/>
</Paragraph>
<Paragraph FontWeight="Normal" FontSize="14" Padding="0,2,0,0">
<Run Text="As a mod creator or developer, the following practices can help ensure mod compatibility with Teardown Mods Manager:"/>
</Paragraph>
<List>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Mod name consistency is the biggest factor in your mod working with this app."/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Ensure mod 'name = ' in mod "/>
<Run FontStyle="Italic" Text="info.txt"/>
<Run Text=" matches the name of your mod at "/>
<Run FontStyle="Italic" Text="teardownmods.com"/>
<Run Text="."/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Ensure mod name matches folder name, i.e. "/>
<Run FontStyle="Italic" Text="Documents\Teardown\mods\mod name"/>
<Run Text="."/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Ensure 'version = ' in mod "/>
<Run FontStyle="Italic" Text="info.txt"/>
<Run Text=" is current released version at "/>
<Run FontStyle="Italic" Text="teardownmods.com"/>
<Run Text=". Something meaningful to the most amount of people, such as "/>
<Run FontStyle="Italic" Text="2021.01.31.x"/>
<Run Text=" or preferably "/>
<Run FontStyle="Italic" Text="1.5.2"/>
<Run Text=" for example. See semantic versioning: https://semver.org/"/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Ensure the last file in the downloads list at "/>
<Run FontStyle="Italic" Text="teardownmods.com"/>
<Run Text=" for the mod is the regular default or preferred mod download. This app selects the last file listed to download."/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Ensure name of mod folder is properly archived: so extracting to "/>
<Run FontStyle="Italic" Text="Teardown\mods"/>
<Run Text=" will result in "/>
<Run FontStyle="Italic" Text="Teardown\mods\Mod Name"/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Instead of having multiple mods/maps, use mod options to control lighting, time of day, weather, etc. If that doesn't work for you, create separate mods for them on "/>
<Run FontStyle="Italic" Text="teardownmods.com"/>
</Paragraph>
</ListItem>
<ListItem>
<Paragraph FontWeight="Normal" FontSize="14">
<Run Text="Try to package mods together in the same mod folder that are part of the same mod package. That way I don't have to hard code a workaround."/>
</Paragraph>
</ListItem>
</List>
</FlowDocument>
</RichTextBox>
</ScrollViewer>
</GroupBox>
</TabItem>
</TabControl>
</GroupBox>
</DockPanel>
</TabItem>
</TabControl>
</DockPanel>
</Grid>
</Window>
"@
$xamlReader = (New-Object System.Xml.XmlNodeReader $xaml)
$syncHash.Window = [Windows.Markup.XamlReader]::Load( $xamlReader )
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") |
ForEach-Object {
$syncHash.($_.Name) = $syncHash.Window.FindName($_.Name)
}
#############################################
#############################################
#endRegion XML PREP
#############################################
#############################################
# ██████ ███ ██ ██ ██████ █████ ██████ ██████ ██████ ██████ ███████
# ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██ ██ ██ ██ ██ █████ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ █████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██████ ██ ████ ███████ ██████ ██ ██ ██████ ██████ ██████ ██████ ███████
#region ONLOAD CODE
Update-Window -Control SelectDefaultModsLocation -Property Text -Value "$env:USERPROFILE\Documents\Teardown\Mods"
"Invoking mod table layout and prep" | Write-Log
Invoke-TablePrep
"Getting mod file details" | Write-Log
$syncHash.allModsDeetz = Get-ModDeets
foreach ($modItem in $syncHash.allModsDeetz) {
"Refreshing mod row [$($modItem.ModName)]" | Write-Log
$row = $syncHash.dataTable.NewRow()
$row.ModName = ($modItem.ModName -replace '[^a-zA-Z0-9 .]','')
$row.ModVersion = $modItem.ModVersion
$row.ModAuthor = $modItem.ModAuthor
$row.ModDescription = $modItem.ModDescription
$row.ModPath = $modItem.ModPath
$row.ModWebpage = $modItem.ModWebPage
$row.ModDownloadLink = $modItem.ModDownloadLink
[void]$syncHash.dataTable.Rows.Add($row)
}
"Finished initial loading of mod list" | Write-Log
#############################################
#############################################
#endRegion ONLOAD CODE
#############################################
#############################################
# ██████ ███████ ██ ██████ █████ ██████ ███ ███ ██████ ██████ ██ ██ ███████ ████████ ██████ ██ ██ ████████ ████████ ██████ ███ ██
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██
# ██████ █████ ██ ██ ██ ███████ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ███████ ██ ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██ ██ ███████ ███████ ██████ ██ ██ ██████ ██ ██ ██████ ██████ ███████ ██ ███████ ██ ██████ ██████ ██ ██ ██████ ██ ████
#region RELOAD MOD LIST BUTTON
$syncHash.ReloadModList.Add_Click({
"Clicked 'Reload Mod List' button" | Write-Log
Update-Window -Control ProgressBar -Property "Background" -Value "#FFE6E6E6"
Update-Window -Control ProgressBar -Property "Foreground" -Value "#FF06B025"
"Invoking mod table layout and prep" | Write-Log
Invoke-TablePrep
"Getting mod file details" | Write-Log
if ($syncHash.folderSelectDialog.SelectedPath.Length -gt 2) {
$syncHash.allModsDeetz = Get-ModDeets -ModDir $syncHash.folderSelectDialog.SelectedPath
$statusBarTextFinish = "Finished reloading new mod list [$($syncHash.folderSelectDialog.SelectedPath)]. Ready..."
} else {
$syncHash.allModsDeetz = Get-ModDeets
}
foreach ($modItem in $syncHash.allModsDeetz) {
"Refreshing mod row [$($modItem.ModName)]" | Write-Log
$row = $syncHash.dataTable.NewRow()
$row.ModName = ($modItem.ModName -replace '[^a-zA-Z0-9 .]','')
$row.ModVersion = $modItem.ModVersion
$row.ModAuthor = $modItem.ModAuthor
$row.ModDescription = $modItem.ModDescription
$row.ModPath = $modItem.ModPath
$row.ModWebpage = $modItem.ModWebPage
$row.ModDownloadLink = $modItem.ModDownloadLink
[void]$syncHash.dataTable.Rows.Add($row)
}
if ($statusBarTextFinish) {
Update-Window -Control StatusBarText -Property Text -Value $statusBarTextFinish
} else {Update-Window -Control StatusBarText -Property Text -Value "Finished reloading mod list. Ready..."}
Update-Window -Control ProgressBar -Property "Value" -Value 0
})
#############################################
#############################################
#endRegion RELOAD MOD LIST BUTTON
#############################################
#############################################
# ██ ██ ██████ ██████ █████ ████████ ███████ █████ ██ ██ ███████ ███████ ██ ███████ ██████ ████████ ███████ ██████ ███ ███ ██████ ██████ ███████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██
# ██ ██ ██████ ██ ██ ███████ ██ █████ ███████ ██ ██ ███████ █████ ██ █████ ██ ██ █████ ██ ██ ██ ████ ██ ██ ██ ██ ██ ███████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ██████ ██ ██████ ██ ██ ██ ███████ ██ ██ ███████ ███████ ███████ ███████ ███████ ███████ ██████ ██ ███████ ██████ ██ ██ ██████ ██████ ███████
#region UPDATE ALL MODS BUTTON
$syncHash.UpdateAllSelectedMods.Add_Click({
"Clicked 'Update All Mods' button" | Write-Log
# Defines the Teardown mods folder to use throughout below logic
$modsFolderPath = if ($syncHash.folderSelectDialog.SelectedPath) {$syncHash.folderSelectDialog.SelectedPath} else {"$env:USERPROFILE\Documents\Teardown\mods"}
Update-Window -Control ProgressBar -Property "Value" -Value 0
Update-Window -Control ProgressBar -Property "Background" -Value "#FFE6E6E6"
Update-Window -Control ProgressBar -Property "Foreground" -Value "#FF06B025"
"Building mods list from selected cells" | Write-Log
$selectedCells = foreach ($selectedCellRow in $syncHash.ModsListDataGrid.SelectedCells) {
[PSCustomObject]@{
'ModName' = $selectedCellRow.Item.modName -replace "\|(.*)\| ",''
'ModVersion' = $selectedCellRow.Item.modVersion
'ModAuthor' = $selectedCellRow.Item.modAuthor
'ModDescription' = $selectedCellRow.Item.modDescription
'ModPath' = $selectedCellRow.Item.ModPath
'ModWebPage' = if ($selectedCellRow.Item.modWebLink.Length -gt 25) {$selectedCellRow.Item.modWebLink} else {"NA"}
'ModDownloadLink' = if ($selectedCellRow.Item.modPackageDownloadLink.Length -gt 25) {$selectedCellRow.Item.modPackageDownloadLink} else {"NA"}
}
}
$selectedMods = (($selectedCells | Group-Object -Property ModName).Name) | Where-Object {$_ -cne 'Mod Name'}
"Selected mods are [$($selectedMods -join ', ')]" | Write-Log
if (-not ($selectedMods)) {
Update-Window -Control StatusBarText -Property Text -Value "No mod selected. Please select a mod and try again!"
} else {
$UpdateAllSelectedModsRunspace = [runspacefactory]::CreateRunspace()
$UpdateAllSelectedModsRunspace.Name = "UpdateAllSelectedModsRunspace"
$UpdateAllSelectedModsRunspace.ApartmentState = "STA"
$UpdateAllSelectedModsRunspace.ThreadOptions = "ReuseThread"
$UpdateAllSelectedModsRunspace.Open()
$UpdateAllSelectedModsRunspace.SessionStateProxy.SetVariable("syncHash", $syncHash)
$UpdateAllSelectedModsRunspace.SessionStateProxy.SetVariable("modsFolderPath", $modsFolderPath)
$UpdateAllSelectedModsRunspace.SessionStateProxy.SetVariable("selectedMods", $selectedMods)
$UpdateAllSelectedModsRunspaceScript = [PowerShell]::Create().AddScript({
"Created new runspace for 'Update All Mods'" | Write-Log
#############################################
#region FUNCTIONS
#############################################
function Write-Log {
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline=$true,Mandatory,Position=0)]
[string]$Message,
[switch]$ClearLog,
[switch]$WriteOut
)
begin {
if (($ClearLog) -or ($syncHash.tmmLog -notmatch "Log initialized:")) {
$syncHash.tmmLog = @"
Log initialized: $(Get-Date)
"@
}
}
process {
$timestamp = "$(Get-Date -f 'yyyy-MM-dd HH:mm:ss')"
$logText = "[$timestamp]`t$Message"
$syncHash.tmmLog += "`n$logText"
}
end {
if ($WriteOut) {
Write-Output -InputObject $syncHash.tmmLog
}
}
}
Function Get-InstalledApplication {
<#
.SYNOPSIS
Retrieves information about installed applications.
.DESCRIPTION
Retrieves information about installed applications by querying the registry. You can specify an application name, a product code, or both.
Returns information about application publisher, name & version, product code, uninstall string, install source, location, date, and application architecture.
.PARAMETER Name
The name of the application to retrieve information for. Performs a contains match on the application display name by default.
.PARAMETER Exact
Specifies that the named application must be matched using the exact name.
.PARAMETER WildCard
Specifies that the named application must be matched using a wildcard search.
.PARAMETER RegEx
Specifies that the named application must be matched using a regular expression search.
.PARAMETER ProductCode
The product code of the application to retrieve information for.
.PARAMETER IncludeUpdatesAndHotfixes
Include matches against updates and hotfixes in results.
.EXAMPLE
Get-InstalledApplication -Name 'Adobe Flash'
.EXAMPLE
Get-InstalledApplication -ProductCode '{1AD147D0-BE0E-3D6C-AC11-64F6DC4163F1}'
.NOTES
.LINK
http://psappdeploytoolkit.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$false)]
[ValidateNotNullorEmpty()]
[string[]]$Name,
[Parameter(Mandatory=$false)]
[switch]$Exact = $false,
[Parameter(Mandatory=$false)]
[switch]$WildCard = $false,
[Parameter(Mandatory=$false)]
[switch]$RegEx = $false,
[Parameter(Mandatory=$false)]
[ValidateNotNullorEmpty()]
[string]$ProductCode,
[Parameter(Mandatory=$false)]
[switch]$IncludeUpdatesAndHotfixes
)
Begin {
# Get the OS Architecture
[boolean]$Is64Bit = [boolean]((Get-WmiObject -Class 'Win32_Processor' -ErrorAction 'SilentlyContinue' | Where-Object { $_.DeviceID -eq 'CPU0' } | Select-Object -ExpandProperty 'AddressWidth') -eq 64)
If ($Is64Bit) { [string]$envOSArchitecture = '64-bit' } Else { [string]$envOSArchitecture = '32-bit' }
## Variables: Current Process Architecture
[boolean]$Is64BitProcess = [boolean]([IntPtr]::Size -eq 8)
If ($Is64BitProcess) { [string]$psArchitecture = 'x64' } Else { [string]$psArchitecture = 'x86' }
## Variables: Registry Keys
# Registry keys for native and WOW64 applications
[string[]]$regKeyApplications = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
If ($is64Bit) {
[string]$regKeyLotusNotes = 'HKLM:SOFTWARE\Wow6432Node\Lotus\Notes'
}
Else {
[string]$regKeyLotusNotes = 'HKLM:SOFTWARE\Lotus\Notes'
}
[string]$regKeyAppExecution = 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options'
}
Process {
## Enumerate the installed applications from the registry for applications that have the "DisplayName" property
[psobject[]]$regKeyApplication = @()
ForEach ($regKey in $regKeyApplications) {
If (Test-Path -LiteralPath $regKey -ErrorAction 'SilentlyContinue' -ErrorVariable '+ErrorUninstallKeyPath') {
[psobject[]]$UninstallKeyApps = Get-ChildItem -LiteralPath $regKey -ErrorAction 'SilentlyContinue' -ErrorVariable '+ErrorUninstallKeyPath'
ForEach ($UninstallKeyApp in $UninstallKeyApps) {
Try {
[psobject]$regKeyApplicationProps = Get-ItemProperty -LiteralPath $UninstallKeyApp.PSPath -ErrorAction 'Stop'
If ($regKeyApplicationProps.DisplayName) { [psobject[]]$regKeyApplication += $regKeyApplicationProps }
}
Catch{
Continue
}
}
}
}
## Create a custom object with the desired properties for the installed applications and sanitize property details
[psobject[]]$installedApplication = @()
ForEach ($regKeyApp in $regKeyApplication) {
Try {
[string]$appDisplayName = ''
[string]$appDisplayVersion = ''
[string]$appPublisher = ''
## Bypass any updates or hotfixes
If (-not $IncludeUpdatesAndHotfixes) {
If ($regKeyApp.DisplayName -match '(?i)kb\d+') { Continue }
If ($regKeyApp.DisplayName -match 'Cumulative Update') { Continue }
If ($regKeyApp.DisplayName -match 'Security Update') { Continue }
If ($regKeyApp.DisplayName -match 'Hotfix') { Continue }
}
## Remove any control characters which may interfere with logging and creating file path names from these variables
$illegalChars = [string][System.IO.Path]::GetInvalidFileNameChars()
$appDisplayName = $regKeyApp.DisplayName -replace $illegalChars,''
$appDisplayVersion = $regKeyApp.DisplayVersion -replace $illegalChars,''
$appPublisher = $regKeyApp.Publisher -replace $illegalChars,''
## Determine if application is a 64-bit application
[boolean]$Is64BitApp = If (($is64Bit) -and ($regKeyApp.PSPath -notmatch '^Microsoft\.PowerShell\.Core\\Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node')) { $true } Else { $false }
If ($ProductCode) {
## Verify if there is a match with the product code passed to the script
If ($regKeyApp.PSChildName -match [regex]::Escape($productCode)) {
$installedApplication += New-Object -TypeName 'PSObject' -Property @{
UninstallSubkey = $regKeyApp.PSChildName
ProductCode = If ($regKeyApp.PSChildName -match $MSIProductCodeRegExPattern) { $regKeyApp.PSChildName } Else { [string]::Empty }
DisplayName = $appDisplayName
DisplayVersion = $appDisplayVersion
UninstallString = $regKeyApp.UninstallString
InstallSource = $regKeyApp.InstallSource
InstallLocation = $regKeyApp.InstallLocation
InstallDate = $regKeyApp.InstallDate
Publisher = $appPublisher
Is64BitApplication = $Is64BitApp
}
}
}
If ($name) {
## Verify if there is a match with the application name(s) passed to the script
ForEach ($application in $Name) {
$applicationMatched = $false
If ($exact) {
# Check for an exact application name match
If ($regKeyApp.DisplayName -eq $application) {
$applicationMatched = $true
}
}
ElseIf ($WildCard) {
# Check for wildcard application name match
If ($regKeyApp.DisplayName -like $application) {
$applicationMatched = $true
}
}
ElseIf ($RegEx) {
# Check for a regex application name match
If ($regKeyApp.DisplayName -match $application) {
$applicationMatched = $true
}
}
# Check for a contains application name match
ElseIf ($regKeyApp.DisplayName -match [regex]::Escape($application)) {
$applicationMatched = $true
}
If ($applicationMatched) {
$installedApplication += New-Object -TypeName 'PSObject' -Property @{
UninstallSubkey = $regKeyApp.PSChildName
ProductCode = If ($regKeyApp.PSChildName -match $MSIProductCodeRegExPattern) { $regKeyApp.PSChildName } Else { [string]::Empty }
DisplayName = $appDisplayName
DisplayVersion = $appDisplayVersion
UninstallString = $regKeyApp.UninstallString
InstallSource = $regKeyApp.InstallSource
InstallLocation = $regKeyApp.InstallLocation
InstallDate = $regKeyApp.InstallDate
Publisher = $appPublisher
Is64BitApplication = $Is64BitApp
}
}
}
}
}
Catch {
Continue
}
}
Write-Output -InputObject $installedApplication
}
End {}
}
Function Update-Window {
Param (
$Control,
$Property,
$Value,
[switch]$AppendContent
)
If ($Property -eq "Close") {
$syncHash.Window.Dispatcher.invoke([action]{$syncHash.Window.Close()},"Normal")
Return
}
$syncHash.$Control.Dispatcher.Invoke([action]{
If ($PSBoundParameters['AppendContent']) {
$syncHash.$Control.AppendText($Value)
} Else {
$syncHash.$Control.$Property = $Value
}
}, "Normal")
if ($Control -eq 'StatusBarText' -and $Property -eq 'Text') {
Write-Log -Message $Value
}
}
#############################################
#endRegion FUNCTIONS
#############################################
#############################################
#############################################
#region UPDATE ALL MODS BUTTON LOGIC
#############################################
#############################################
# Check if 7-Zip or WinRAR is installed:
Update-Window -Control StatusBarText -Property Text -Value "Checking if 7-Zip or WinRAR is installed on system..."
$7zApp = Get-InstalledApplication -Name "7-Zip"
$wrarApp = Get-InstalledApplication -Name "WinRAR"
if ((Test-Path -Path "$($7zApp.InstallLocation)7z.exe") -eq $true) {
Update-Window -Control StatusBarText -Property Text -Value "7-Zip installation detected!..."
$7zExePath = "$($7zApp.InstallLocation)7z.exe"
$7zInstalled = $true
$zipOnly = $false
} elseif ((Test-Path -Path "$($wrarApp.InstallLocation)UnRAR.exe") -eq $true) {
Update-Window -Control StatusBarText -Property Text -Value "WinRAR installation detected!..."
$wrarExePath = "$($wrarApp.InstallLocation)UnRAR.exe"
$wrarInstalled = $true
$zipOnly = $false
} else {
Update-Window -Control StatusBarText -Property Text -Value "7-Zip and WinRAR was NOT detected as installed on system..."
$zipOnly = $true
}
$syncHash.selectedModsList = $syncHash.allModsDeetz | Where-Object {$selectedMods -match ($_.ModName -replace '[^a-zA-Z0-9 .]','')}
$syncHash.allModsUpdateTotal = $syncHash.selectedModsList.ModName.Count
$syncHash.allModsUpdateCount = 1
foreach ($modDeetz in $syncHash.selectedModsList) {
if ((Get-Runspace | Where-Object { $_.RunspaceAvailability -eq "Busy" }).Count -gt 4) {
do {
Start-Sleep -Seconds 2
} while ((Get-Runspace | Where-Object { $_.RunspaceAvailability -eq "Busy" }).Count -gt 4)
}
Update-Window -Control ProgressBar -Property "Background" -Value "#FFE6E6E6"
Update-Window -Control ProgressBar -Property "Foreground" -Value "#FF06B025"
$rowSearch = $modDeetz.ModName -replace '[^a-zA-Z0-9 .]',''
$cellOriginal = ($syncHash.dataTable.Rows | Where-Object {$_.ModName -match $rowSearch}).ModName -replace "\|(.*)\| ",''
($syncHash.dataTable.Rows | Where-Object {$_.ModName -match $rowSearch}).ModName = "| Starting update... | $cellOriginal"
"Setting [$($modDeetz.ModName)] 'Mod Name' cell text update process status to [| Starting update... | $cellOriginal]" | Write-Log
$UpdateAllSelectedModsRunspaceSpawn = [runspacefactory]::CreateRunspace()
$UpdateAllSelectedModsRunspaceSpawn.Name = "UpdateAllSelectedModsRunspaceSpawn"
$UpdateAllSelectedModsRunspaceSpawn.ApartmentState = "STA"
$UpdateAllSelectedModsRunspaceSpawn.ThreadOptions = "ReuseThread"
$UpdateAllSelectedModsRunspaceSpawn.Open()
$UpdateAllSelectedModsRunspaceSpawn.SessionStateProxy.SetVariable("syncHash", $syncHash)
$UpdateAllSelectedModsRunspaceSpawn.SessionStateProxy.SetVariable("modDeetz", $modDeetz)
$UpdateAllSelectedModsRunspaceSpawn.SessionStateProxy.SetVariable("cellOriginal", $cellOriginal)
$UpdateAllSelectedModsRunspaceSpawn.SessionStateProxy.SetVariable("7zApp", $7zApp)
$UpdateAllSelectedModsRunspaceSpawn.SessionStateProxy.SetVariable("wrarApp", $wrarApp)
$UpdateAllSelectedModsRunspaceSpawn.SessionStateProxy.SetVariable("7zExePath", $7zExePath)