This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
shp-packager.ps1
904 lines (816 loc) · 35.9 KB
/
shp-packager.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
using namespace System.Collections.Generic; using namespace System.Text
<#
>>==SCRIPT PARAMETERS==<<
$o_name - Name of package
$o_noDiscord - don't package BetterDiscord?
$o_noSpotify - don't package Spicetify theme?
$o_noFirefox - don't package Firefox profile?
$o_noWinVS - don't package Windows visual style?
$o_noRainmeter - don't package Rainmeter skins?
$o_noCore - don't package JaxCore modules?
$o_saveLocation - location to save generated folder structure [==Default set when running==]
$o_saveLocationSHP - location to export the package [==Default set when running==]
$o_keepGenerated - keep generated folder structure?
$o_noCopy - copy files to structure?
$o_noCompile - compile SHP package? (debug only)
#>
param(
[Parameter(Mandatory=$true)][Alias("n")][ValidateNotNullOrEmpty()][string]$o_name,
[Alias("D")][switch]$o_noDiscord,
[Alias("S")][switch]$o_noSpotify,
[Alias("F")][switch]$o_noFirefox,
[Alias("W")][switch]$o_noWinVS,
[Alias("R")][switch]$o_noRainmeter,
[Alias("C")][switch]$o_noCore,
[Alias("locsave")][string]$o_saveLocation,
[Alias("locexport")][string]$o_saveLocationSHP,
[Alias("keep")][switch]$o_keepGenerated,
[Alias("nocopy")][switch]$o_noCopy,
[Alias("nocompile")][switch]$o_noCompile
)
$ErrorActionPreference = 'SilentlyContinue'
Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
using System.Text;
public class WindowTools
{
public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam);
[DllImport("user32.dll")]
public static extern bool EnumWindows(EnumWindowsProc enumFunc, int lParam);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr GetShellWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
[DllImport("user32.dll")]
public static extern bool CloseWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
}
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
'
class OpenWindow {
[string] $Title
[IntPtr] $Handle
[UInt32] $ProcessID
}
# ---------------------------------------------------------------------------- #
# Functions #
# ---------------------------------------------------------------------------- #
# -------------------------------- Window size ------------------------------- #
function Get-OpenWindow {
[CmdletBinding()]
param (
[String]$Name = '*'
)
$handles = [List[IntPtr]]::new()
$shellWindowhWnd = [WindowTools]::GetShellWindow()
$null = [WindowTools]::EnumWindows(
{
param (
[IntPtr] $handle,
[int] $lParam
)
if ($handle -eq $shellWindowhWnd) {
return $true
}
if (-not [WindowTools]::IsWindowVisible($handle)) {
return $true
}
$handles.Add($handle)
return $true
},
0
)
foreach ($handle in $handles) {
$titleLength = [WindowTools]::GetWindowTextLength($handle)
if ($titleLength -gt 0) {
$titleBuilder = [StringBuilder]::new($titleLength)
$null = [WindowTools]::GetWindowText(
$handle,
$titleBuilder,
$titleLength + 1
)
$title = $titleBuilder.ToString()
if ($title -like $Name) {
$processID = 0
$null = [WindowTools]::GetWindowThreadProcessId(
$handle,
[ref]$ProcessID
)
[OpenWindow]@{
Title = $title
Handle = $handle
ProcessId = $ProcessID
}
}
}
}
}
function Get-WindowPosition {
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'FromInputObject')]
[OpenWindow]$InputObject
)
process {
$rect = [RECT]::new()
$null = [WindowTools]::GetWindowRect(
$InputObject.Handle,
[ref]$rect
)
[PSCustomObject]@{
Title = $InputObject.Title
Handle = $InputObject.Handle
ProcessID = $InputObject.ProcessID
Left = $rect.Left
Top = $rect.Top
Right = $rect.Right
Bottom = $rect.Bottom
}
}
}
# -------------------------------- Write-Host -------------------------------- #
function Write-Task ([string] $Text) {
Write-Host $Text -NoNewLine
}
function Write-Done {
Write-Host " > " -NoNewline
Write-Host "OK" -ForegroundColor "Green"
}
function Write-Emphasized ([string] $Text) {
Write-Host $Text -NoNewLine -ForegroundColor "Cyan"
}
function Write-Info ([string] $Text) {
Write-Host $Text -ForegroundColor "Yellow"
}
function Write-Fail ([string] $Text) {
Write-Host $Text -ForegroundColor "Red"
}
function Write-Divider {
Write-Host "============================================" -BackgroundColor "Gray"
}
function debug ([string] $Text) {
Write-Verbose "$Text"
}
# ------------------------------------ Ini ----------------------------------- #
function Get-IniContent ($filePath) {
$ini = [ordered]@{}
if (![System.IO.File]::Exists($filePath)) {
throw "$filePath invalid"
}
# $section = ';ItIsNotAFuckingSection;'
# $ini.Add($section, [ordered]@{})
foreach ($line in [System.IO.File]::ReadLines($filePath)) {
if ($line -match "^\s*\[(.+?)\]\s*$") {
$section = $matches[1]
$secDup = 1
while ($ini.Keys -contains $section) {
$section = $section + '||ps' + $secDup
}
$ini.Add($section, [ordered]@{})
}
elseif ($line -match "^\s*;.*$") {
$notSectionCount = 0
while ($ini[$section].Keys -contains ';NotSection' + $notSectionCount) {
$notSectionCount++
}
$ini[$section][';NotSection' + $notSectionCount] = $matches[1]
}
elseif ($line -match "^\s*(.+?)\s*=\s*(.+?)$") {
$key, $value = $matches[1..2]
$ini[$section][$key] = $value
}
else {
$notSectionCount = 0
while ($ini[$section].Keys -contains ';NotSection' + $notSectionCount) {
$notSectionCount++
}
$ini[$section][';NotSection' + $notSectionCount] = $line
}
}
return $ini
}
function Get-RemoteIniContent ($link) {
$ini = [ordered]@{}
$result = iwr -useb $link
$ini.Add($section, [ordered]@{})
foreach ($line in $($result.Content -split "`n")) {
if ($line -match "^\s*\[(.+?)\]\s*$") {
$section = $matches[1]
$secDup = 1
while ($ini.Keys -contains $section) {
$section = $section + '||ps' + $secDup
}
$ini.Add($section, [ordered]@{})
}
elseif ($line -match "^\s*;.*$") {
$notSectionCount = 0
while ($ini[$section].Keys -contains ';NotSection' + $notSectionCount) {
$notSectionCount++
}
$ini[$section][';NotSection' + $notSectionCount] = $matches[1]
}
elseif ($line -match "^\s*(.+?)\s*=\s*(.+?)$") {
$key, $value = $matches[1..2]
$ini[$section][$key] = $value
}
else {
$notSectionCount = 0
while ($ini[$section].Keys -contains ';NotSection' + $notSectionCount) {
$notSectionCount++
}
$ini[$section][';NotSection' + $notSectionCount] = $line
}
}
return $ini
}
function Set-IniContent($ini, $filePath) {
$str = @()
foreach ($section in $ini.GetEnumerator()) {
if ($section -ne ';ItIsNotAFuckingSection;') {
$str += "[" + ($section.Key -replace '\|\|ps\d+$', '') + "]"
}
foreach ($keyvaluepair in $section.Value.GetEnumerator()) {
if ($keyvaluepair.Key -match "^;NotSection\d+$") {
$str += $keyvaluepair.Value
}
else {
$str += $keyvaluepair.Key + "=" + $keyvaluepair.Value
}
}
}
$finalStr = $str -join [System.Environment]::NewLine
$finalStr | Out-File -filePath $filePath -Force -Encoding unicode
}
# ----------------------------------- Copy ----------------------------------- #
function Copy-Path {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[ValidateScript({Test-Path -Path $_ -PathType Container})]
[string]$Source,
[Parameter(Position = 1)]
[string]$Destination,
[string[]]$ExcludeFolders = $null,
[switch]$IncludeEmptyFolders
)
$Source = $Source.TrimEnd("\")
$Destination = $Destination.TrimEnd("\")
Get-ChildItem -Path $Source -Recurse | ForEach-Object {
if ($_.PSIsContainer) {
# it's a folder
if ($ExcludeFolders.Count) {
if ($ExcludeFolders -notcontains $_.Name -and $IncludeEmptyFolders) {
# create the destination folder, even if it is empty
$target = Join-Path -Path $Destination -ChildPath $_.FullName.Substring($Source.Length)
if (!(Test-Path $target -PathType Container)) {
# Write-Verbose "Create folder $target"
New-Item -ItemType Directory -Path $target | Out-Null
}
}
}
}
else {
# it's a file
$copy = $true
if ($ExcludeFolders.Count) {
# get all subdirectories in the current file path as array
$subs = $_.DirectoryName.Replace($Source,"").Trim("\").Split("\")
# check each sub folder name against the $ExcludeFolders array
foreach ($folderName in $subs) {
if ($ExcludeFolders -contains $folderName) { $copy; break }
}
}
if ($copy) {
# create the destination folder if it does not exist yet
$target = Join-Path -Path $Destination -ChildPath $_.DirectoryName.Substring($Source.Length)
if (!(Test-Path $target -PathType Container)) {
# Write-Verbose "Create folder $target"
New-Item -ItemType Directory -Path $target | Out-Null
}
# Write-Verbose "Copy file $($_.FullName) to $target"
$_ | Copy-Item -Destination $target -Force
}
}
}
}
# ---------------------------------------------------------------------------- #
# Start #
# ---------------------------------------------------------------------------- #
<#
Standard compiling
.\S-Hub\shp-packager.ps1 -n "Test" -S -F
Test flow
.\S-Hub\shp-packager.ps1 -n "Test" -keep -nocompile
#>
Write-Info "SHPPACKAGER REF: Experimental v1.9"
# ---------------------------- Installer variables --------------------------- #
$user = [EnvironmentVariableTarget]::User
$path = [Environment]::GetEnvironmentVariable("PATH", $user)
$paths = $path -split ";"
$s_RMSettingsFolder = $paths -match 'Rainmeter'
$s_RMINIFile = "$s_RMSettingsFolder\Rainmeter.ini"
$RMEXEloc = "$s_RMSettingsFolder\Rainmeter.exe"
# Get the set skin path
if (Test-Path $s_RMINIFile) {
$Ini = Get-IniContent $s_RMINIFile
$s_RMSkinFolder = $Ini["Rainmeter"]["SkinPath"].TrimEnd('\')
$s_RMVault = "$s_RMSkinFolder\@Vault\Plugins"
$Ini = $null
} else {
Write-Fail "Unable to locate $s_RMINIFile."
Write-Info "Make sure you've registered the paths with S-Hub packager tool in JaxCore."
Return
}
# ----------------------------- Default locations ---------------------------- #
if (!$o_saveLocation) {$o_saveLocation = "$s_RMSkinFolder\..\CoreData\S-Hub\Generated"}
if (!$o_saveLocationSHP) {$o_saveLocationSHP = "$s_RMSkinFolder\..\CoreData\S-Hub\Exports"}
# Set running directory
[System.IO.Directory]::SetCurrentDirectory($o_saveLocationSHP)
Write-Info "Getting required information..."
# -------------------------------- Get rm bit -------------------------------- #
$rmprocess_object = Get-Process Rainmeter
$rmprocess_id = $rmprocess_object.id
Write-Task "Getting Rainmeter bitness..."
$bit = '32bit'
Get-Process -Id $rmprocess_id | Foreach {
$modules = $_.modules
foreach($module in $modules) {
$file = [System.IO.Path]::GetFileName($module.FileName).ToLower()
if($file -eq "wow64.dll") {
$bit = "32bit"
Break
} else {
$bit = "64bit"
}
}
}
Write-Done
# ---------------------------------- Screen ---------------------------------- #
Write-Task "Getting screen sizes"
Add-Type -AssemblyName System.Windows.Forms
$sa_Top = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Top
$sa_Left = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Left
$sa_Bottom = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Bottom
$sa_Right = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Right
$saw = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width
$sah = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height
Write-Done
debug "SCREEN TLBR: $sa_Top, $sa_Left, $sa_Bottom, $sa_Right"
if ($saw -eq $null) {
while ($true) {
$saw = Read-Host 'Unable to detect monitor width. Please enter the width of the primary monitor in pixels as a whole number'
if ($saw -gt 0) {
while ($true) {
$sah = Read-Host 'Unable to detect monitor height. Please enter height width of the primary monitor in pixels as a whole number'
if ($sah -gt 0) {
Break
} else {
Continue
}
}
Break
} else {
Continue
}
}
}
$WinVer = [int]((Get-WmiObject -class Win32_OperatingSystem).Caption -replace "[^0-9]" , '')
if ($WinVer -eq $null) {
$WinVer = [int]((Get-ComputerInfo).WindowsProductName -replace "[^0-9]" , '')
}
# ----------------------------- Get display scale ---------------------------- #
Add-Type @'
using System;
using System.Runtime.InteropServices;
using System.Drawing;
public class DPI {
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
public enum DeviceCap {
VERTRES = 10,
DESKTOPVERTRES = 117
}
public static float scaling() {
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
return (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
}
}
'@ -ReferencedAssemblies 'System.Drawing.dll'
$WinScale = [Math]::round([DPI]::scaling(), 2)
# ------------------------------- Start package ------------------------------ #
debug "SetupName: $o_name"
debug "RainmeterPluginsBit: $bit"
debug "RainmeterPath: $s_RMSettingsFolder"
debug "RainmeterExePath: $RMEXEloc"
debug "RainmeterSkinsPath: $s_RMSkinFolder"
debug "SavingDirectory_Generated: $o_saveLocation"
debug "SavingDirectory_SHP: $o_saveLocationSHP"
debug "PrimaryScreenAreaSizes: $saw x $sah"
# ------------------------- Create SHPData structure ------------------------- #
$SHPInfo = @{'SetupName'=$o_name;'ScreenSizeW'=$saw;'ScreenSizeH'=$sah;'CoreModules'='';'DLCs'=@();'WinBuild'=$([System.Environment]::OSVersion.Version.Build);'WinVer'=$WinVer;'WinScale'=$WinScale;'WinVS'=''}
$SHPRainmeter = @{'Skins'='';'Droptop'=$false}
$SHPBetterDiscord = @{'themelist'=@()}
$SHPSpicetify = @{'current_theme'='';'color_scheme'='';'extensions'=''}
$SHPFirefox = @{}
$SHPData = @{'Data'=$SHPInfo;'Rainmeter'=$SHPRainmeter;'BetterDiscord'=$SHPBetterDiscord;'Spicetify'=$SHPSpicetify;'Firefox'=$SHPFirefox;'Tags'=@()}
# -------------------------------- Name to id -------------------------------- #
$s_NameToID = @{
"YourFlyouts"="0";
"YourMixer"="1";
"ValliStart"="2";
"Rainmeter"="R";
"Firefox"="F";
"Spicetify"="S";
"BetterDiscord"="D";
"Droptop"="T";
"WinVS"="W"
}
# ------------------------------ Wipe directory ------------------------------ #
Write-Task "Wiping generation directory"
if (Test-Path -Path "$o_saveLocation") {Remove-Item "$o_saveLocation" -Recurse -Force > $null}
Write-Done
# ----------------------------- Create directory ----------------------------- #
Write-Task "Creating new directory"
New-Item -Path "$o_saveLocation" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\Rainmeter" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\Rainmeter\Skins" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\Rainmeter\Plugins" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\Wallpaper" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\AppSkins" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\AppSkins\Spicetify" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\AppSkins\Spicetify\Themes" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\AppSkins\Spicetify\Extensions" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\AppSkins\BetterDiscord" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\AppSkins\Firefox" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocation\WinVS" -ItemType "Directory" > $null
New-Item -Path "$o_saveLocationSHP" -ItemType "Directory" > $null
Write-Done
# ---------------------------------------------------------------------------- #
# Rainmeter and JaxCore #
# ---------------------------------------------------------------------------- #
# ------------------------ Get JaxCore module details ------------------------ #
Write-Task "Reading remote ModuleDetails.ini"
$ModuleDetails = Get-RemoteIniContent 'https://raw.githubusercontent.com/Jax-Core/JaxCore/main/S-Hub/ModuleDetails.ini'
$tagged_modules = $ModuleDetails.SHubPreferences.TaggedModules
$custom_userimages = @{}
foreach ($k in $ModuleDetails.CustomUserImages.Keys) {
$a = $($ModuleDetails.CustomUserImages[$k]).Split('|')
$ha = @{}
foreach($v in $a) {
$ha += ConvertFrom-StringData $v
}
$custom_userimages[$k] = $ha
}
$jaxcore_modules = $ModuleDetails.Keys | Where-Object {$_ -notmatch "Setup|Version|JaxCore|JaxCoreDLCs|CustomUserImages|SHubPreferences"}
$exclude_plugins = $ModuleDetails.Version.Keys
$s_RMINIFile_filterpattern = $ModuleDetails.SHubPreferences.SectionFilterPattern
Write-Done
# ---------------------------- Read Rainmeter.ini ---------------------------- #
Write-Task "Getting Rainmeter layout..."
$Ini = Get-IniContent $s_RMINIFile
Write-Done
debug "Found $($Ini.Count) sections in $s_RMINIFile"
# -------------------------- Filter through sections ------------------------- #
Write-Task "Filtering through Rainmeter sections"
[string[]]$Ini.Keys | Where-Object { $Ini[$_].Active -contains "0" -or $_ -match $s_RMINIFile_filterpattern } | ForEach-Object {
$Ini.Remove($_)
}
# ----------------------------- Tag modules & WH ----------------------------- #
function isOffscreen($st, $sl, $sb, $sr) {
debug "TLBR: $st, $sl, $sb, $sr"
# If rectangle has area 0, no overlap
if ($sl -eq $sr -or $st -eq $sb) {
return $true
}
# If one rectangle is on left side of other
if ($sl -gt $sa_Right -or $sa_Left -gt $sr) {
return $true
}
# If one rectangle is above other
if ($sb -lt $sa_Top -or $sa_Bottom -lt $st) {
return $true
}
return $false
}
[string[]]$Ini.Keys | ForEach-Object {
$currentSection = $_
if ($_ -notmatch "$tagged_modules") {
Get-ChildItem -Path "$s_RMSkinFolder\$currentSection" -File | ForEach-Object {
debug "Getting window property of $s_RMSkinFolder\$currentSection\$($_.Name)"
$currentSWH = Get-OpenWindow "$s_RMSkinFolder\$currentSection\$($_.Name)" | Get-WindowPosition
if ($currentSWH -ne $null) {
if (isOffscreen $currentSWH.Top $currentSWH.Left $currentSWH.Bottom $currentSWH.Right) {
debug "$currentSection is off screen"
$Ini.Remove($currentSection)
} else {
debug "$currentSection is on screen"
}
}
}
} elseif ($currentSection -match "^($tagged_modules)\\Main$") {
if (!$o_noCore) {
$currentSection = $currentSection -replace '\\.*$', ''
debug "Valid SHP Tag: $currentSection"
$SHPData.Tags += $currentSection
} else {
$Ini.Remove($currentSection)
}
} elseif ($currentSection -match "^($tagged_modules)?\\.*$") {
$Ini.Remove($currentSection)
} else {
$Ini[$currentSection].WindowW = $currentSWH.Right - $currentSWH.Left
$Ini[$currentSection].WindowH = $currentSWH.Bottom - $currentSWH.Top
}
}
Write-Done
# ----------------------- Convert sections to skin name ---------------------- #
$valid_skins = [string[]]$Ini.Keys | ForEach-Object { $_ -replace '\\.*$', '' }
# --------------------------- Work with valid skins -------------------------- #
Write-Task "Copying Rainmeter and JaxCore items"
$i = 0
$ii = 0
$skins = @()
$valid_jaxcore_modules = @()
$valid_skins | select-object -unique | ForEach-Object {
if ($jaxcore_modules -contains $_) {
if (!$o_noCore) {
$ii++
$valid_jaxcore_modules += $_
$skin_varf = $ModuleDetails["$_"].VarFiles -split '\s\|\s' | Where-Object {$_ -notmatch "WelcomeVars|Hotkeys"}
if (!$o_noCopy) {
foreach ($varf in $skin_varf) {
if (Test-Path -path "$s_RMSkinFolder\$varf") {
# ----------------------------------- Copy ----------------------------------- #
$i_savedir = "$o_saveLocation\Rainmeter\JaxCore\$(Split-Path $varf)"
$i_savelocation = "$o_saveLocation\Rainmeter\JaxCore\$varf"
if (!(Test-Path "$i_savedir")) { New-Item -Path "$i_savedir" -Type "Directory" > $null }
Copy-Item -Path "$s_RMSkinFolder\$varf" -Destination "$i_savelocation" -Force > $null
# --------------------------------- Check DLC -------------------------------- #
if ($($ModuleDetails.JaxCoreDLCs.ModuleList -Split "\|") -contains $_) {
foreach($dlc in $ModuleDetails.JaxCoreDLCs.DLCList -Split "\|") {
$dlcFound = Select-String -Path "$s_RMSkinFolder\$varf" -Pattern "$dlc"
if ($dlcFound -ne $null) {
debug "Found $dlc in $_ as an active DLC."
$SHPData.Data.DLCs += $_+'_'+$dlc
Break
}
}
}
}
}
}
foreach ($module in $custom_userimages.Keys) {
if ($_ -eq $module) {
foreach ($varf in $custom_userimages[$module].Keys) {
$moduleIni = Get-IniContent "$s_RMSkinFolder\$module\$varf"
$current_userimage = $moduleIni.Variables[$custom_userimages[$module][$varf]]
if (($current_userimage -notmatch "#SKINSPATH#") -and (Test-Path -Path $current_userimage)) {
debug "Copying $varf from $module to root of module (user content)"
if (!$o_noCopy) {
Copy-Item -Path $current_userimage -Destination "$o_saveLocation\Rainmeter\JaxCore\$module\"
$moduleIni.Variables[$custom_userimages[$module][$varf]] = '#ROOTCONFIGPATH#' + $(Split-Path $current_userimage -Leaf)
Set-IniContent $moduleIni "$o_saveLocation\Rainmeter\JaxCore\$module\$varf"
}
}
}
}
}
if ($_ -eq 'ModularVisualizer') {
New-Item -Path "$o_saveLocation\Rainmeter\CoreData\ModularVisualizer" -ItemType Directory > $null
if (!$o_noCopy) {
Get-ChildItem "$s_RMSkinFolder\..\CoreData\ModularVisualizer\" -Directory | ForEach-Object {
Copy-Item -Path $_.FullName -Destination "$o_saveLocation\Rainmeter\CoreData\ModularVisualizer\" -Recurse
}
}
}
}
} else {
if (!$o_noRainmeter -and (Test-Path -Path "$s_RMSkinFolder\$_")) {
$i++
$skins += $_
if (!$o_noCopy) {Copy-Path -Source "$s_RMSkinFolder\$_" -Destination "$o_saveLocation\Rainmeter\Skins\$_\" -ExcludeFolders '.git'}
}
}
}
$SHPData.Data.CoreModules = $valid_jaxcore_modules
$SHPData.Rainmeter.Skins = $skins
if ($skins.count -ne 0) {
$SHPData.Tags += "Rainmeter"
}
debug "$ii valid JaxCore modules configurations saved: $valid_jaxcore_modules"
debug "$i valid Rainmeter skins copied: $skins"
Write-Done
# ------------------------------- Copy plugins ------------------------------- #
Write-Task "Copying Rainmeter plugins"
if (!$o_noRainmeter) {
$i = 0
Get-ChildItem -Path $s_RMVault | Where-Object {$_.Name -notmatch ($exclude_plugins -join '|')} | ForEach-Object {
$i++
$i_Plugin = $_.Name
Get-ChildItem -Path $_.FullName | Sort-Object Name -Descending | Select-Object -First 1 | ForEach-Object {
if (!$o_noCopy) {Copy-Path -Source $_.FullName -Destination "$o_saveLocation\Rainmeter\Plugins\$i_Plugin\"}
}
}
debug "$i valid plugins copied."
}
Write-Done
# ----------------------------- Export Rainmeter.ini ---------------------------- #
if (!$o_noRainmeter -or !$o_noCore) {
Set-IniContent -ini $Ini -filePath "$o_saveLocation\Rainmeter.ini" -Encoding unicode -Force
}
# ---------------------------------------------------------------------------- #
# Spicetify #
# ---------------------------------------------------------------------------- #
if (!$o_noSpotify) {
$spicetify_detected = Get-Command spicetify -ErrorAction Silent
if ($spicetify_detected -ne $null) {
Write-Task 'Getting spicetify paths'
$spicetifyconfig_path = spicetify.exe -c
$spicetify_path = "$spicetifyconfig_path\..\"
Write-Done
if (Test-Path -Path "$spicetifyconfig_path") {
$Ini = Get-IniContent $spicetifyconfig_path
$spicetify_current_theme = $Ini['Setting']["current_theme"]
$spicetify_color_scheme = $Ini['Setting']["color_scheme"]
$spicetify_extensions = $Ini['AdditionalOptions']["extensions"].Split("|")
# Copy spicetify theme
Write-Task "Exporting Theme: $spicetify_current_theme, ColorScheme: $spicetify_color_scheme"
if (!$o_noCopy) {
Copy-Item -Path "$spicetify_path\Themes\$spicetify_current_theme\*" -Destination "$o_saveLocation\AppSkins\Spicetify\Themes" -Exclude @("*.png", "*.jpeg") -Recurse -Force
}
$SHPData.Spicetify.current_theme = $spicetify_current_theme
$SHPData.Spicetify.color_scheme = $spicetify_color_scheme
Write-Done
foreach ($extension in $spicetify_extensions) {
if ($extension -match $spicetify_current_theme) {
Write-Task "Found corresponding plugin matching theme name $spicetify_current_theme, copying"
$spicetify_themeext = $extension.TrimEnd('.js')+'.js'
$SHPData.Spicetify.extensions = $spicetify_themeext
if (!$o_noCopy) { Copy-Item -Path "$spicetify_path\Extensions\$spicetify_themeext" -Destination "$o_saveLocation\AppSkins\Spicetify\Extensions" -Force }
Write-Done
Break
}
}
$SHPData.Tags += 'Spicetify'
} else {
Write-Fail "Unable to locate $spicetifyconfig_path"
}
} else {
Write-Fail 'Spicetify is not found on your device. '
}
}
# ---------------------------------------------------------------------------- #
# BetterDiscord #
# ---------------------------------------------------------------------------- #
if (!$o_noDiscord) {
$bd_path = "$env:APPDATA\BetterDiscord"
if (Test-Path -Path $bd_path) {
Write-Task 'Getting BetterDiscord assets...'
$bd_data_folders = Get-ChildItem -Path "$bd_path\data" -Directory
if ($bd_data_folders.Count -eq 1) {
$bd_selected_folder = $bd_data_folders
} else {
$bd_selected_folder = $bd_data_folders[0]
}
Write-Done
Write-Task "Extracting themes from discord:data\$($bd_selected_folder)\themes.json"
$bd_themes = Get-Content -Path "$bd_path\data\$($bd_selected_folder)\themes.json" | ConvertFrom-Json
$i_found = $False
$bd_themes | Get-Member | Where-Object -Property MemberType -match "NoteProperty" | Select-Object "Name" | ForEach-Object {
$i_bd_themename = "$([string]$_.Name)"
if ($($bd_themes.$i_bd_themename) -match "True") {
debug "Theme `"$i_bd_themename`" applied, trying to find css file"
Get-ChildItem -Path "$bd_path\themes\*" -Filter *.theme.css | ForEach-Object {
$a = Get-Content $_ -First 2
$a = [regex]::match($a,'/\*\*\s\s\*\s@name\s(.*)').Groups[1].Value
if ($i_bd_themename -contains $a.trim()) {
debug "Found theme in $_"
Copy-Item -Path "$_" -Destination "$o_saveLocation\AppSkins\BetterDiscord\" -Force
$SHPData.BetterDiscord.themelist += $i_bd_themename
}
}
$i_found = $True
}
}
if ($i_found) {
$SHPData.Tags += "BetterDiscord"
Write-Done
} else {
Write-Fail "No active themes detected"
}
} else {
Write-Fail 'BetterDiscord is not found on your device. '
}
}
# ---------------------------------------------------------------------------- #
# Firefox #
# ---------------------------------------------------------------------------- #
if (!$o_noFirefox) {
$ff_path = "$env:APPDATA\Mozilla\Firefox\"
$ffconfig_path = "$($ff_path)profiles.ini"
if (Test-Path -Path "$ffconfig_path") {
Write-Task 'Getting Firefox paths'
$Ini = Get-IniContent $ffconfig_path
$ff_defaultprofile_path = $Ini[0]["Default"]
Write-Done
$ff_userchrome_path = "$($ff_path)$ff_defaultprofile_path\chrome\*"
if (Test-Path -Path "$ff_userchrome_path") {
# Copy firefox theme
Write-Task "Exporting user css files $ff_userchrome_path"
if (!$o_noCopy) {Copy-Item -Path "$ff_userchrome_path" -Destination "$o_saveLocation\AppSkins\Firefox\" -Force}
$SHPData.Tags += "Firefox"
Write-Done
} else {
Write-Fail "Nothing is located at $ff_userchrome_path"
}
} else {
Write-Fail 'Firefox custom css is not found on your device. '
}
}
# ---------------------------------------------------------------------------- #
# Windows VS #
# ---------------------------------------------------------------------------- #
if (!$o_noWinVS) {
$currentTheme = (Get-ItemProperty "HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Themes").CurrentTheme
Write-Task "Exporting visual style $(Split-Path $currentTheme -leaf)"
Copy-Item -Path $currentTheme -Destination "$o_saveLocation\WinVS\"
Write-Done
Write-Task "Reading $(Split-Path $currentTheme -Leaf -Resolve)"
$WinVSdotTheme = Get-IniContent $currentTheme
$currentThemeVSPath = ($WinVSdotTheme.VisualStyles.Path).Replace('%ResourceDir%\', 'C:\Windows\Resources\').Replace('%SystemRoot%\', 'C:\Windows\')
$currentThemeVSPathFolder = $currentThemeVSPath | Split-Path
$currentThemeVSPathFolderName = $currentThemeVSPathFolder | Split-Path -Leaf
Write-Done
If ($currentThemeVSPath -ne $null) {
Write-Task "Copying $currentThemeVSPath"
New-Item -Path "$o_saveLocation\WinVS\$currentThemeVSPathFolderName\" -ItemType Directory > $Null
Copy-Item -Path "$currentThemeVSPath" -Destination "$o_saveLocation\WinVS\$currentThemeVSPathFolderName\"
Write-Done
If ((Get-ChildItem -Path $currentThemeVSPathFolder -Directory) -ne $null) {
Write-Task "Copying additional files in msstyles directory"
Get-ChildItem -Path $currentThemeVSPathFolder -Directory | ForEach-Object {
debug $_.FullName
Copy-Item -Path $_.FullName -Destination "$o_saveLocation\WinVS\$currentThemeVSPathFolderName\" -Recurse
}
Write-Done
}
} else {
Write-Fail "Unable to locate $(Split-Path $currentTheme -leaf)'s msstyle directory."
}
$SHPData.Data.WinVS = $currentTheme
$SHPData.Tags += "WinVS"
}
# ---------------------------------------------------------------------------- #
# Wallpaper #
# ---------------------------------------------------------------------------- #
Write-Task 'Getting Wallpaper...'
$wallpaper_path = Get-ItemProperty 'HKCU:\Control Panel\Desktop' | Select -exp 'Wallpaper'
Write-Done
Write-Task "Copying wallpaper from $wallpaper_path"
$wallpaper_ext = $wallpaper_path -replace '^.*\.', ''
Copy-Item -Path $wallpaper_path -Destination "$o_saveLocation\Wallpaper\Wallpaper.$wallpaper_ext" -Force
Write-Done
# ---------------------------------- Export ---------------------------------- #
Write-Task "Exporting SHP-data.ini"
$o_name += "{"
$SHPData.Tags | ForEach-Object {
$o_name += $s_NameToID[$_]
}
$o_name += "}"
$SHPData | ConvertTo-Json -depth 10 | Out-File -FilePath "$o_saveLocation\SHP-data.json" -Encoding unicode -Force
Write-Done
Write-Task "Compiling SHP package"
if (!$o_noCompile) {
$ProgressPreference = 'SilentlyContinue'
Compress-Archive -Path "$o_saveLocation\*" -DestinationPath "$o_saveLocationSHP\$o_name.zip" -Force -CompressionLevel "Fastest"
Rename-Item -Path "$o_saveLocationSHP\$o_name.zip" -NewName "$o_name.shp"
}
if (!$o_keepGenerated) {Remove-Item -Path "$o_saveLocation\*" -Recurse}
Write-Done
# Open folder
if (!$o_noCompile) {Invoke-Item $o_saveLocationSHP}
Write-Host ">>> Export success! (^ ᴗ ^) <<<" -ForegroundColor "Green"