Repository navigation
Expand file tree
/
Copy pathStart-CatSystem.ps1
More file actions
144 lines (121 loc) · 4.15 KB
/
Copy pathStart-CatSystem.ps1
File metadata and controls
144 lines (121 loc) · 4.15 KB
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
#Requires -RunAsAdministrator
#Requires -Version 5.1
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$script:Root = $PSScriptRoot
$moduleOrder = @(
'Helpers\SystemAnalyzer.psm1'
'Helpers\Benchmark.psm1'
'Helpers\UIRenderer.psm1'
'Core\Logger.psm1'
'Core\RollbackManager.psm1'
'Core\RegistryHandler.psm1'
'Modules\GhostProtocol.psm1'
'Modules\SculptorEngine.psm1'
'Modules\NetBooster.psm1'
'Modules\BrowserCleaner.psm1'
'Modules\StartupManager.psm1'
'Modules\SystemCleaner.psm1'
)
foreach ($relative in $moduleOrder) {
$full = Join-Path -Path $script:Root -ChildPath $relative
if (-not (Test-Path -LiteralPath $full)) {
throw "Required module missing: $full"
}
Import-Module $full -DisableNameChecking -ErrorAction Stop
}
try {
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
}
catch {
Write-Verbose "UTF8 encoding unavailable: $($_.Exception.Message)"
}
function Invoke-RollbackChanges {
[CmdletBinding()]
[OutputType([pscustomobject])]
param()
$before = Get-SystemBenchmark
Write-CatHeader -Title 'Rollback Changes' -Tag '[<]'
$answer = [string](Read-Host 'Rollback all changes made by Cat-System? (y/n)')
if ($answer.Trim() -notmatch '^[Yy]') {
Write-CatLog -Message 'Rollback cancelled.' -Type Info
return [pscustomobject]@{
Module = 'Rollback Changes'
Before = $before
After = $before
Success = $false
}
}
$result = Restore-AllChanges
if ($result) {
Clear-Backup
}
$after = Get-SystemBenchmark
return [pscustomobject]@{
Module = 'Rollback Changes'
Before = $before
After = $after
Success = $result
}
}
$script:Actions = [ordered]@{
'1' = @{ Name = 'Ghost Protocol'; Handler = { Invoke-GhostProtocol } }
'2' = @{ Name = 'Sculptor Engine'; Handler = { Invoke-SculptorEngine } }
'3' = @{ Name = 'Net Booster'; Handler = { Invoke-NetBooster } }
'4' = @{ Name = 'Browser Cleaner'; Handler = { Invoke-BrowserCleaner } }
'5' = @{ Name = 'Startup Manager'; Handler = { Invoke-StartupManager } }
'6' = @{ Name = 'System Cleaner'; Handler = { Invoke-SystemCleaner } }
'7' = @{ Name = 'Rollback Changes'; Handler = { Invoke-RollbackChanges } }
}
function Start-CatMainLoop {
[CmdletBinding()]
[OutputType([void])]
param()
while ($true) {
try {
Clear-Host
Show-Banner
$raw = Read-Host 'Awaiting Command'
if ($null -eq $raw) { continue }
$selection = ([string]$raw).Trim()
if ($selection.Length -eq 0) { continue }
if ($selection -eq '0') {
Show-ExitAnimation
return
}
if (-not $script:Actions.Contains($selection)) {
Write-CatLog -Message 'Invalid selection.' -Type Warning -Tag '[!]'
Start-Sleep -Milliseconds 1200
continue
}
$action = $script:Actions[$selection]
Clear-Host
$result = & $action.Handler
if ($null -ne $result -and -not $result.Success) {
Write-CatLog -Message 'Module completed with warnings or no changes.' -Type Warning
}
Write-Host ''
Write-Host '======================================================' -ForegroundColor DarkCyan
Write-Host ' Press ANY KEY to return to Main Menu' -ForegroundColor DarkCyan
Write-Host '======================================================' -ForegroundColor DarkCyan
[void][System.Console]::ReadKey($true)
}
catch {
Write-CatLog -Message "System error: $($_.Exception.Message)" -Type Critical
Start-Sleep -Seconds 2
}
}
}
try {
Start-CatMainLoop
}
finally {
$loaded = Get-Module | Where-Object {
$_.Path -and $_.Path.StartsWith($script:Root, [System.StringComparison]::OrdinalIgnoreCase)
}
foreach ($mod in $loaded) {
Remove-Module -Name $mod.Name -Force -ErrorAction SilentlyContinue
}
}