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
/
Copy pathCoreInstallerBeta.ps1
775 lines (715 loc) · 34.2 KB
/
CoreInstallerBeta.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
# ---------------------------------------------------------------------------- #
# Functions #
# ---------------------------------------------------------------------------- #
# 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 ([string] $Text) {
Write-Host "[$Text]>+============================================+<[$Text]" -BackgroundColor "DarkGray"
}
function debug ([string] $Text) {
Write-Verbose "$Text"
}
# -------------------------- Check program installed ------------------------- #
function Check_Program_Installed( $programName ) {
$x86_check = ((Get-ChildItem "HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall") |
Where-Object { $_."Name" -like "*$programName*" } ).Length -gt 0;
if(Test-Path 'HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
{
$x64_check = ((Get-ChildItem "HKLM:Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") |
Where-Object { $_."Name" -like "*$programName*" } ).Length -gt 0;
}
return $x86_check -or $x64_check;
}
# ------------------------------------ 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 = Invoke-WebRequest -useb $link
$section = ';ItIsNotAFuckingSection;'
$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
}
function Wait-ForProcess
{
param
(
$Name = 'notepad',
[Switch]
$IgnoreAlreadyRunningProcesses
)
if ($IgnoreAlreadyRunningProcesses)
{ $NumberOfProcesses = (Get-Process -Name $Name -ErrorAction SilentlyContinue).Count }
else
{ $NumberOfProcesses = 0 }
Write-Host "Waiting for $Name" -NoNewline
while ( (Get-Process -Name $Name -ErrorAction SilentlyContinue).Count -eq $NumberOfProcesses )
{
Write-Host '.' -NoNewline
Start-Sleep -Milliseconds 400
}
Write-Done
}
function DownloadFile($url, $targetFile)
{
$uri = New-Object "System.Uri" "$url"
$request = [System.Net.HttpWebRequest]::Create($uri)
$request.set_Timeout(15000) #15 second timeout
$response = $request.GetResponse()
$totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
$responseStream = $response.GetResponseStream()
$targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
$buffer = new-object byte[] 1000KB
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $count
while ($count -gt 0)
{
$targetStream.Write($buffer, 0, $count)
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $downloadedBytes + $count
Write-Progress -activity "Downloading file '$($url.split('/') | Select -Last 1)'" -status "Downloaded ($([System.Math]::Floor($downloadedBytes/1024))K of $($totalLength)K): " -PercentComplete ((([System.Math]::Floor($downloadedBytes/1024)) / $totalLength) * 100)
}
Write-Progress -activity "Finished downloading file '$($url.split('/') | Select -Last 1)'"
$targetStream.Flush()
$targetStream.Close()
$targetStream.Dispose()
$responseStream.Dispose()
}
# ---------------------------------------------------------------------------- #
# Installation modules #
# ---------------------------------------------------------------------------- #
function Set-DPICompatability {
REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V "$RMEXEloc" /T REG_SZ /D ~HIGHDPIAWARE /F
}
function Download-Rainmeter($params) {
# ----------------------------------- Fetch ---------------------------------- #
Write-Info "Rainmeter is not installed, installing Rainmeter"
$githubRMReleaseAPIObject = Invoke-WebRequest -Uri 'https://api.github.com/repos/rainmeter/rainmeter/releases' -UseBasicParsing | ConvertFrom-Json
$githubRMDownloadURL = $githubRMReleaseAPIObject.assets.browser_download_url[0]
$githubRMDownloadOutpath = "$env:temp\RainmeterInstaller.exe"
# --------------------------------- Download --------------------------------- #
Write-Task "Downloading "; Write-Emphasized $githubRMDownloadURL
Invoke-WebRequest "$githubRMDownloadURL" -outfile "$githubRMDownloadOutpath" -UseBasicParsing
Write-Done
# ------------------------------------ Run ----------------------------------- #
Write-Task "Running installer..."
Start-Process -FilePath (Get-Item -LiteralPath "$env:temp\RainmeterInstaller.exe").FullName -ArgumentList "$params" -Wait
Write-Done
# ---------------------------- Check if installed ---------------------------- #
Write-Task "Checking "; Write-Emphasized "$RMEXEloc"; Write-Task " for Rainmeter.exe"
If (Test-Path -Path "$RMEXEloc") {
Write-Done
Set-DPICompatability
} else {
throw "`nFailed to install Rainmeter! (Did not complete UAC)"
}
# --------------------------------- Generate --------------------------------- #
Write-Task "Generating "; Write-Emphasized "Rainmeter.ini "; Write-Task "for the first time..."
New-Item -Path "$s_RMSettingsFolder" -Name "Rainmeter.ini" -ItemType "file" -Force -Value @"
[Rainmeter]
Logging=0
SkinPath=$s_RMSkinFolder
HardwareAcceleration=1
[illustro\Clock]
Active=0
[illustro\Disk]
Active=0
[illustro\System]
Active=0
"@
Write-Done
If (Test-Path "$env:APPDATA\JaxCore\InstalledComponents\") {
Get-ChildItem -Path "$env:APPDATA\JaxCore\" -Recurse | Remove-Item -Recurse
}
}
# ---------------------------------------------------------------------------- #
# Start of installation #
# ---------------------------------------------------------------------------- #
# ----------------------------------- Info ----------------------------------- #
# $o - Option for installer
# $s - Installer options set by developer
# $o_InstallModule - Module to install
## $o_Version - Version to get (Number ONLY)
# $o_FromCore - If installation is invoked via JaxCore
# $o_FromSHUB - If installation is invoked via S-Hub
# $o_Force - Overwrite existing files
# $o_ExtInstall - Run .rmskin
# $o_PromptBestOption - Prompt for changing to best options
## $o_Location - Where to install Core, or where the Rainmeter folder is
## $o_NoPostActions - Whether to do additional things after installation
# ------------------------------ Default values ------------------------------ #
if (!($o_InstallModule)) {$o_InstallModule = "JaxCore"}
if (!($o_FromCore)) {$o_FromCore = $false}
if (!($o_FromSHUB)) {$o_FromSHUB = $false}
if (!($o_Force)) {$o_Force = $false}
if (!($o_ExtInstall)) {$o_ExtInstall = $false}
if (!($o_PromptBestOption)) {
if ($o_FromCore -or $o_Force -or $o_NoPostActions) {
$o_PromptBestOption = $false
} else {
$o_PromptBestOption = $true
}
}
# ---------------------------- Installer variables --------------------------- #
$s_InstallIsBatch = [bool]($o_InstallModule.Count -gt '1')
$s_rootFolderName = "JaxCoreCache"
$s_root = "C:\$s_rootFolderName"
$s_unpacked = "$s_root\Unpacked"
# Declare global scope installer variables
$s_RMSettingsFolder = ""
$s_RMINIFile = ""
$s_RMSkinFolder = ""
$RMEXEloc = ""
# ----------------------------------- Start ---------------------------------- #
# Enable TLS 1.2 since it is required for connections to GitHub.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ProgressPreference = 'SilentlyContinue'
Write-Info "COREINSTALLER REF: Stable v5.60"
if (!($o_Location)) {
# ---------------------------------------------------------------------------- #
# Standard installation #
# ---------------------------------------------------------------------------- #
# ---------------------------- Installer variables --------------------------- #
$s_RMSettingsFolder = "$env:APPDATA\Rainmeter\"
$s_RMINIFile = "$($s_RMSettingsFolder)Rainmeter.ini"
$s_RMSkinFolder = "$env:APPDATA\JaxCore\InstalledComponents\"
# --------------------------- Check if RM installed -------------------------- #
$RMEXEloc = "$($s_RMSettingsFolder)Rainmeter.exe"
if (Test-Path -LiteralPath "$RMEXEloc") {
# ------------------------------- RM installed ------------------------------- #
debug "Rainmeter is already installed on your device."
$wasRMInstalled = $true
# If (Test-Path "$RMEXE32bitloc") {$RMEXEloc = "$RMEXE32bitloc"}
If (Test-Path $s_RMINIFile) {
$Ini = Get-IniContent $s_RMINIFile
$s_RMSkinFolder = $Ini["Rainmeter"]["SkinPath"]
$hwa = $Ini["Rainmeter"]["HardwareAcceleration"]
if (($hwa -eq $null) -and ($o_PromptBestOption -eq $true)) {
Write-Info "JaxCore recommends that the HardwareAcceleration option for Rainmeter to be turned on. "
$confirmation = Read-Host "Turn on? (y/n)"
if ($confirmation -match '^y$') {
$Ini["Rainmeter"]["HardwareAcceleration"] = "1"
Set-IniContent $Ini $s_RMINIFile
}
}
} else {
Write-Fail "Seems like you have Rainmeter installed but haven't ran it once on this account. Please do so and try again."
Read-Host
Exit
}
} else {
$wasRMInstalled = $false
$RMEXEloc = "$Env:Programfiles\Rainmeter\Rainmeter.exe"
Download-Rainmeter "/S /AUTOSTARTUP=1 /RESTART=0"
}
} else {
# ---------------------------------------------------------------------------- #
# Portable installation #
# ---------------------------------------------------------------------------- #
# ---------------------------- Installer variables --------------------------- #
$s_RMSettingsFolder = "$o_Location\Rainmeter\"
$s_RMINIFile = "$($s_RMSettingsFolder)Rainmeter.ini"
$s_RMSkinFolder = "$o_Location\JaxCore\InstalledComponents\"
$RMEXEloc = "$s_RMSettingsFolder\Rainmeter.exe"
# ------- Check if Rainmeter is already installed at provided location ------- #
If (Test-Path "$o_Location\Rainmeter\Rainmeter.exe") {
debug "Rainmeter is already installed under $o_Location\Rainmeter";
$wasRMInstalled = $true
If (Test-Path $s_RMINIFile) {
$Ini = Get-IniContent $s_RMINIFile
$s_RMSkinFolder = $Ini["Rainmeter"]["SkinPath"]
If ($s_RMSkinFolder -eq $null) {
$s_RMSkinFolder = "$($s_RMSettingsFolder)Skins\"
$Ini["Rainmeter"]["SkinPath"] = $s_RMSkinFolder
Set-IniContent $Ini $s_RMINIFile
}
$hwa = $Ini["Rainmeter"]["HardwareAcceleration"]
if (($hwa -eq $null) -and ($o_PromptBestOption -eq $true)) {
Write-Info "JaxCore recommends that the HardwareAcceleration option for Rainmeter to be turned on. "
$confirmation = Read-Host "Turn on? (y/n)"
if ($confirmation -match '^y$') {
$Ini["Rainmeter"]["HardwareAcceleration"] = "1"
Set-IniContent $Ini $s_RMINIFile
}
}
}
} else {
Write-Host "Are you sure you want to install JaxCore at " -NoNewLine; Write-Emphasized $o_Location
$confirmation = Read-Host "? (y/n)"
if ($confirmation -match '^y$') {
$wasRMInstalled = $false
Download-Rainmeter "/S /RESTART=0 /PORTABLE=1 /D=$s_RMSettingsFolder"
} else {
Write-Fail "Action cancelled. Installation terminated."
Return
}
}
}
# ---------------------------------------------------------------------------- #
# Getting info from Rainmeter process #
# ---------------------------------------------------------------------------- #
If (!$bit) {
If (!(Get-Process 'Rainmeter' -ErrorAction SilentlyContinue)) {
& "$RMEXEloc"
Wait-ForProcess 'Rainmeter'
}
$rmprocess_object = Get-Process Rainmeter
$rmprocess_id = $rmprocess_object.id
# ------------------------------------ Bit ----------------------------------- #
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
# -------------------------- Stop running instances -------------------------- #
If (!(Test-Path $s_RMSkinFolder)) {New-Item -Path $s_RMSkinFolder -Type "Directory" > $null}
[System.IO.Directory]::SetCurrentDirectory($s_RMSkinFolder)
If (Get-Process 'Rainmeter' -ErrorAction SilentlyContinue) {
Write-Task "Ending Rainmeter & potential AHKv1 process"
Stop-Process -Name 'Rainmeter'
If (Get-Process 'AHKv1' -ErrorAction SilentlyContinue) {
Stop-Process -Name 'AHKv1'
}
Write-Done
}
}
# ---------------------------------------------------------------------------- #
# Download #
# ---------------------------------------------------------------------------- #
New-Item -Path $s_root -Type "Directory" -Force > $null
Get-Item $s_root -Force | foreach { $_.Attributes = $_.Attributes -bor "Hidden" }
Get-ChildItem "$s_root" | ForEach-Object {
Remove-Item $_.FullName -Force -Recurse
}
# ------------------------------ Download files ------------------------------ #
Write-Task "Getting ModuleDetails from JaxCore repository"
$moduleDetails = Get-RemoteIniContent 'https://raw.githubusercontent.com/Jax-Core/JaxCore/main/S-Hub/ModuleDetails.ini'
Write-Done
foreach ($m in $o_InstallModule) {
debug "Processing module $m"
If ($moduleDetails.ExternalWidgets.Keys -contains $m) {
$org = $moduleDetails.ExternalWidgets[$m]
} else {
$org = 'Jax-Core'
}
debug "Organization: $org"
if (-not $o_Version) {
$release_api_url = "https://api.github.com/repos/$org/$m/releases/latest"
} else {
$release_api_url = "https://api.github.com/repos/$org/$m/releases/tags/v$o_Version"
}
# 22H2 media player patch
if (($moduleDetails[$m].Values -contains 'WindowsNowPlaying') -and ($22h2_downloaded -ne $true) -and ($([System.Environment]::OSVersion.Version.Build) -gt 22533)) {
$22h2_downloaded = $true
$outpath = "$s_root\zzzzzz.rmskin"
Write-Task "Downloading 22H2 media player patch from "; Write-Emphasized "https://github.com/Jax-Core/22H2-MediaPatch/releases/download/v1/zzzzzz.rmskin"
Invoke-WebRequest "https://github.com/Jax-Core/22H2-MediaPatch/releases/download/v1/zzzzzz.rmskin" -outfile "$outpath" -UseBasicParsing
Write-Done
}
# End End End End
Write-Task "Downloading "; Write-Emphasized $release_api_url; Write-Task " to get download URL"
$api_object = Invoke-WebRequest -Uri $release_api_url -UseBasicParsing | ConvertFrom-Json
Write-Done
$dl_url = $api_object.assets.browser_download_url
$outpath = "$s_root\$($m)_$($api_object.tag_name).rmskin"
Write-Task "Downloading "; Write-Emphasized $dl_url
Invoke-WebRequest "$dl_url" -outfile "$outpath" -UseBasicParsing
Write-Done
}
# ---------------------------------------------------------------------------- #
# Installation #
# ---------------------------------------------------------------------------- #
If (($o_ExtInstall -eq $true) -and ($s_InstallIsBatch -eq $false)) {
# ---------------------------------------------------------------------------- #
# RMSKIN legacy installation #
# ---------------------------------------------------------------------------- #
# ---------------------------------- RMSKIN ---------------------------------- #
Write-Task "Running .rmskin to install (specified)"
If (Test-Path -Path "$s_root\*") {
Get-ChildItem $s_root -File | ForEach-Object {
Invoke-Item $_.FullName
}
} else {
throw 'Unable to find downloaded file. Try running installer as adminstrator, or if you are installing a module within JaxCore, run Rainmeter as administrator and try again. Make sure you have no programs running that would potentially delete the downloaded file'
}
Write-Done
Write-Task "Interacting with installer UI"
If ($Null -NotMatch (get-process "SkinInstaller" -ea SilentlyContinue)) {
$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate('Rainmeter Skin Installer')
Start-Sleep -s 1.5
$wshell.SendKeys('{ENTER}')
}
Write-Done
Write-Task "Waiting for SkinInstaller to quit"
Wait-Process "SkinInstaller"
Write-Done
Wait-ForProcess 'Rainmeter'
} else {
# ---------------------------------------------------------------------------- #
# Standard extraction installation #
# ---------------------------------------------------------------------------- #
# ------------------------------- Extract file ------------------------------- #
If (Test-Path -Path "$s_root\*") {
Get-ChildItem $s_root -File | ForEach-Object {
$i_name = $($_.Name -replace '\.rmskin', '')
Rename-Item -LiteralPath (Get-Item -LiteralPath "$s_root\$($_.Name)").FullName -NewName "$i_name.zip"
Write-Task "Exapnding downloaded archive "; Write-Emphasized "$i_name"; Write-Task " -> "; Write-Emphasized "$s_root\Unpacked\$i_name\"
Expand-Archive -LiteralPath (Get-Item -LiteralPath "$s_root\$i_name.zip").FullName -DestinationPath "$s_unpacked\$i_name\" -Force
Write-Done
}
} else {
throw 'Unable to find downloaded file. Try running installer as adminstrator, or if you are installing a module within JaxCore, run Rainmeter as administrator and try again. Make sure you have no programs running that would potentially delete the downloaded file'
}
# ---------------------------- Start installation ---------------------------- #
Write-Info "Starting installation..."
debug "-----------------"
debug "RainmeterPluginsBit: $bit"
debug "RainmeterPath: $s_RMSettingsFolder"
debug "RainmeterExePath: $RMEXEloc"
debug "SkinsPath: $s_RMSkinFolder"
debug "InstallIsBatch: $s_InstallIsBatch"
debug "-----------------"
$isInstallingCore = $false
[System.Collections.ArrayList]$list_of_installations = @()
Get-ChildItem "$s_unpacked\" -Directory | Sort-Object | ForEach-Object {
$i_root = "$s_unpacked\$($_.Name)"
If (!(Test-Path "$i_root\RMSKIN.ini")) {
Write-Fail "ERROR: Unable to find RMSKIN.ini in extracted package. Please report this issue to the developer."
debug "Press ENTER to close this prompt"
Read-Host
Exit
}
# ------------------------------ Read RMSKIN.ini ----------------------------- #
$Ini = Get-IniContent "$i_root\RMSKIN.ini"
if (Test-Path "$i_root\Skins\") {
$skin_name = (Get-ChildItem -Path "$i_root\Skins\" | Select-Object -First 1).Name
$skin_auth = $Ini["rmskin"]["Author"]
$skin_ver = $Ini["rmskin"]["Version"]
$skin_varf = $Ini["rmskin"]["VariableFiles"]
$skin_load = $Ini["rmskin"]["Load"]
$skin_load_path = Split-Path $skin_load
if ($skin_name -contains '#JaxCore') {$isInstallingCore = $true}
$list_of_installations.Add("$skin_name") > $null
debug "$skin_name $skin_ver - by $skin_auth"
debug "Variable files: $skin_varf"
debug "Load: $skin_load_path ($isInstallingCore)"
debug "-----------------"
# ------------------------------ Variable files ------------------------------ #
If (Test-Path "$s_RMSkinFolder\$skin_name") {
$new_install = $false
debug "This is an update"
$confirmation = 'y'
If ($o_Force) {$confirmation = 'n'}
If ($o_PromptBestOption) {
$confirmation = Read-Host "Do you want to save variables for this installation? (y/n)"
}
if ($confirmation -match '^y$') {
debug "> Saving variable files"
$skin_varf = $skin_varf -split '\s\|\s'
If (Test-Path "$i_root\Unpacked\$i_name\") { Remove-Item -Path "$i_root\SavedVarFiles" -Force -Recurse > $null }
New-Item -Path "$i_root\SavedVarFiles" -Type "Directory" > $null
foreach ($varf in $skin_varf) {
if (Test-Path -Path "$s_RMSkinFolder\$varf") {
$i_savedir = "$i_root\SavedVarFiles\$(Split-Path $varf)"
$i_savelocation = "$i_root\SavedVarFiles\$varf"
debug "Saving #$i $($varf) -> $i_savelocation"
If (!(Test-Path "$i_savedir")) { New-Item -Path "$i_savedir" -Type "Directory" > $null }
Copy-Item -Path "$s_RMSkinFolder\$varf" -Destination "$i_savelocation" -Force > $null
}
}
} else {
debug "> Not saving variable files"
}
} else {
$new_install = $true
debug "This is a new installation"
}
# ---------------------------------- Process --------------------------------- #
debug "> Moving skin files"
Get-ChildItem -Path "$i_root\Skins\" | ForEach-Object {
If ($new_install) {
New-Item -Path "$s_RMSkinFolder\$($_.Name)\" -Type "Directory" -Force > $null
} else {
Get-ChildItem -Path "$s_RMSkinFolder\$($_.Name)\" -Recurse | Remove-Item -Recurse
}
Move-Item -Path "$i_root\Skins\$($_.Name)\*" -Destination "$s_RMSkinFolder\$($_.Name)\" -Force
}
# ------------------------------ Variable files ------------------------------ #
If ((-not $new_install) -and ($confirmation -match '^y$')) {
debug "> Writing saved variables files back to skin"
foreach ($varf in $skin_varf) {
$i_savelocation = "$i_root\SavedVarFiles\$varf"
$i_targetlocation = "$s_RMSkinFolder\$varf"
If (Test-Path "$i_savelocation") {
debug "Writing keys and values from saved variables to local"
$Ini = Get-IniContent $i_savelocation;$oldvars = $Ini
$Ini = Get-IniContent $i_targetlocation;$newvars = $Ini
$oldvars.Keys | Foreach-Object {
$i_section = $_
$oldvars[$i_section].Keys | ForEach-Object {
$i_value = $_
# debug "[$i_section] $i_value"
If ([bool]$newvars[$i_section][$i_value]) {
$newvars[$i_section][$i_value] = $oldvars[$i_section][$i_value]
# debug "$($newvars[$i_section][$i_value]) replaced by $($oldvars[$i_section][$i_value])"
}
}
}
Set-IniContent $newvars $i_targetlocation
}
}
} elseif (($skin_name -notcontains '#JaxCore') -and !$o_FromSHUB -and $o_NoPostActions) {
debug "> Automatically changing scale variables (new installation)"
$vc = Get-WmiObject -class "Win32_VideoController"
$saw = $vc.CurrentHorizontalResolution
$sah = $vc.CurrentVerticalResolution
# ((#SCREENAREAWIDTH#/1920) < (#SCREENAREAHEIGHT#/1080) ? (#SCREENAREAWIDTH#/1920) : (#SCREENAREAHEIGHT#/1080))
$scale = 1
Write-Task "Getting scale"
If (($saw/1920) -lt ($sah/1080)) {
$scale = $saw / 1920
} else {
$scale = $sah / 1080
}
Write-Done
$scale = [math]::Round($scale,2)
debug "Scale is $scale"
if ($scale -eq 1) {
debug "Scale unchanged."
} elseif ($scale -eq 0) {
Write-Fail "Seems like the installer is unable to identify the correct screen sizes. Skipping scaling writing."
} else {
Write-Task "Applying scaling to config files"
$varsfile = "$s_RMSkinFolder\$skin_name\@Resources\Vars.inc"
If (Test-Path $varsfile) {
debug "Vars.inc found."
$Ini = Get-IniContent $varsfile
If ([bool]$Ini["Variables"]["Scale"]) {
$Ini["Variables"]["Scale"] = $scale
Set-IniContent $Ini $varsfile
}
}
$othervarfiles = "$s_RMSkinFolder\$skin_name\Main\Vars\"
If (Test-Path "$othervarfiles") {
debug "Found other variable files"
Get-ChildItem "$othervarfiles" -File | ForEach-Object {
$i_file = "$othervarfiles\$($_.Name)"
$Ini = Get-IniContent $i_file
If ([bool]$Ini["Variables"]["Scale"]) {
debug "Found scale variable in $i_file"
$Ini["Variables"]["Scale"] = $scale
Set-IniContent $Ini $i_file
}
}
}
Write-Done
}
}
# ------------------------------ Hotkey variable ----------------------------- #
If ($($ModuleDetails[$skin_name].VarFiles -split '\s\|\s') -contains "$skin_name\@Resources\Actions\Hotkeys.ini") {
If (!((join-path "$Env:APPDATA\Rainmeter\" "") -eq ($RMEXEloc))) {
Write-Task "Setting Rainmeter path for AutoHotkey to use in modules."
$i_file = "$s_RMSkinFolder\$skin_name\@Resources\Actions\Hotkeys.ini"
$Ini = Get-IniContent $i_file
$Ini["Variables"]["RMPATH"] = $RMEXEloc
Set-IniContent $Ini $i_file
Write-Done
}
}
} else {
debug "> Skipping skin installation (none)"
}
# ---------------------------------- Plugins --------------------------------- #
If (Test-Path "$i_root\Plugins\") {
debug "> Moving / replacing plugins"
$i_targetlocation = "$($s_RMSettingsFolder)\Plugins\"
If (!(Test-Path "$i_targetlocation\")) { New-Item -Path "$i_targetlocation" -Type "Directory" -Force }
Get-ChildItem "$i_root\Plugins\$bit" | ForEach-Object {
$i_plugin = $_.Name
$i_pluginlocation = "$i_root\Plugins\$bit\$i_plugin"
debug "Moving `"$i_plugin`" -> `"$i_pluginlocation`""
If (Test-Path "$i_targetlocation\$i_plugin") { Remove-Item "$i_targetlocation\$i_plugin" -Force }
Copy-Item -Path "$i_pluginlocation" -Destination "$i_targetlocation" -Force > $null
}
} else {
debug "> Skipping plugin installation (none)"
}
Write-Info "Finished installation of $skin_name! :D "
}
If (!($o_FromSHUB) -or $o_NoPostActions) {
Start-Process "$RMEXEloc"
Wait-ForProcess 'Rainmeter'
}
}
Start-Sleep -Milliseconds 500
If (!$wasRMInstalled) {
Stop-Process -Name 'Rainmeter'
Remove-Item -Path "$($s_RMSettingsFolder)Rainmeter.ini"
New-Item -Path "$s_RMSettingsFolder" -Name "Rainmeter.ini" -ItemType "file" -Force -Value @"
[Rainmeter]
Logging=0
SkinPath=$s_RMSkinFolder
HardwareAcceleration=1
[illustro\Clock]
Active=0
[illustro\Disk]
Active=0
[illustro\System]
Active=0
[$skin_load_path]
Active=1
"@
Start-Process "$RMEXEloc"
Wait-ForProcess 'Rainmeter'
Start-Sleep -Milliseconds 500
} elseif ($isInstallingCore -or $o_NoPostActions) {
if ($o_ExtInstall -eq $false) {
& "$RMEXEloc" [!ActivateConfig $skin_load_path]
}
} else {
If ($o_ExtInstall) {
& "$RMEXEloc" [!DeactivateConfig $skin_load_path]
}
$dlcINCFile = "$s_RMSkinFolder\..\CoreData\@DLCs\InstalledDLCs.inc"
If (!($o_FromSHUB)) {
If (!(Test-Path $dlcINCFile)) {
debug "No DLCs installed."
} else {
If ([String]::IsNullOrWhiteSpace((Get-content $dlcINCFile))) {
debug "No DLCs installed."
} else {
# --------------------- Check if skin has a DLC installed -------------------- #
$Ini = Get-IniContent -filePath $dlcINCFile
for ($i = 0;$i -lt $list_of_installations.Count;$i++) {
$i_name = $list_of_installations[$i]
debug "> Matching $i_name with installed DLCs"
for ($j = 0; $j -lt $Ini['Variables'].Keys.Count; $j++) {
if ($Ini['Variables'].Keys[$j] -match $i_name) {
debug "Found $i_name in installed DLCs"
& "$RMEXEloc" [!WriteKeyValue Variables Sec.Page "2" "$s_RMSkinFolder\#JaxCore\Main\Home.ini"][!WriteKeyValue Variables Page.SubPage "1" "$s_RMSkinFolder\#JaxCore\CoreShell\Home\Page2.inc"][!WriteKeyValue Variables Page.Complete_Reinstallation "1" "$s_RMSkinFolder\#JaxCore\CoreShell\Home\Page2.inc"][!WriteKeyValue Variables Page.Reinstallation_isSingle "$([Bool]($list_of_installations.Count -eq 1))" "$s_RMSkinFolder\#JaxCore\CoreShell\Home\Page2.inc"][!ActivateConfig "#JaxCore\Main" "Home.Ini"]
Return
}
}
}
debug "No matching DLCs found"
}
}
If ($s_InstallIsBatch) {
& "$RMEXEloc" [!WriteKeyValue Variables Sec.Page "1" "$s_RMSkinFolder\#JaxCore\Main\Home.ini"][!ActivateConfig "#JaxCore\Main" "Home.Ini"]
} else {
& "$RMEXEloc" [!WriteKeyvalue Variables Skin.Name "$skin_name" "$s_RMSkinFolder\#JaxCore\@Resources\CacheVars\Configurator.inc"][!WriteKeyvalue Variables Skin.Set_Page Info "$s_RMSkinFolder\#JaxCore\@Resources\CacheVars\Configurator.inc"][!ActivateConfig "#JaxCore\Main" "Settings.Ini"]
}
}
}
Write-Task "Clearing cache"
Get-ChildItem -Path "$s_root\" -Recurse | Remove-Item -Recurse
Remove-Item -Path "$s_root" -Force
Write-Done
If (!($o_FromSHUB)) {Exit}