-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSASPClean.ps1
230 lines (213 loc) · 10.7 KB
/
SASPClean.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
$localePath = "language\locales"
$language = "en"
$envLang = [System.Globalization.CultureInfo]::CurrentCulture.Name
if ($envLang -like "de*") {
$language = "de"
} elseif ($envLang -like "en*") {
$language = "en"
} elseif ($envLang -like "tr*") {
$language = "tr"
} elseif ($envLang -like "ar*") {
$language = "ar"
} elseif ($envLang -like "es*") {
$language = "es"
} elseif ($envLang -like "ru*") {
$language = "ru"
} elseif ($envLang -like "zh*") {
$language = "zh"
}
$localeFilePath = Join-Path -Path $localePath -ChildPath "$language.json"
if (Test-Path $localeFilePath) {
$localeData = Get-Content -Path $localeFilePath -Encoding UTF8 | ConvertFrom-Json
} else {
Write-Host "Language file not found. Default English language file will be used."
$localeData = Get-Content -Path (Join-Path -Path $localePath -ChildPath "en.json") -Encoding UTF8 | ConvertFrom-Json
}
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDirectory = Split-Path $scriptPath -Parent
$packageJsonPath = Join-Path $scriptDirectory "package.json"
$packageJsonExists = Test-Path $packageJsonPath
$iconFileName = "icon\SASPClean.png"
$iconPath = Join-Path $scriptDirectory $iconFileName
$loadingForm = New-Object System.Windows.Forms.Form
$loadingForm.Text = $localeData.formTitle
$loadingForm.Size = New-Object System.Drawing.Size(400, 150)
$loadingForm.StartPosition = "CenterScreen"
$loadingForm.BackColor = [System.Drawing.Color]::FromArgb(255, 245, 245, 245)
$loadingLabelPackageJson = New-Object System.Windows.Forms.Label
$loadingLabelPackageJson.Text = $localeData.loadingScreen.checkingUpdates
$loadingLabelPackageJson.Font = New-Object System.Drawing.Font("Arial", 12, [System.Drawing.FontStyle]::Bold)
$loadingLabelPackageJson.AutoSize = $true
$loadingLabelPackageJson.Location = New-Object System.Drawing.Point(20, 45)
$loadingForm.Controls.Add($loadingLabelPackageJson)
$loadingForm.add_Shown({
$iconFolder = Join-Path $scriptDirectory "icon"
if (-not (Test-Path $iconFolder -PathType Container)) {
[System.Windows.Forms.MessageBox]::Show($localeData.errorMessages.folderNotFound, "Folder Not Found", "OK", "Error")
$loadingForm.Close()
return
}
$iconPath = Join-Path $scriptDirectory "icon\SASPClean.png"
if (-not (Test-Path $iconPath -PathType Leaf)) {
[System.Windows.Forms.MessageBox]::Show($localeData.errorMessages.fileNotFound, "File Not Found", "OK", "Error")
$loadingForm.Close()
return
}
$packageJsonPath = Join-Path $scriptDirectory "package.json"
if (-not (Test-Path $packageJsonPath -PathType Leaf)) {
[System.Windows.Forms.MessageBox]::Show($localeData.errorMessages.packageJsonNotFound, "File Not Found", "OK", "Error")
$loadingForm.Close()
return
}
$latestRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/sasprosko590/SASPClean/releases/latest"
if ($packageJsonExists) {
$packageJson = Get-Content -Path $packageJsonPath | ConvertFrom-Json
$currentVersion = "V" + $packageJson.version
if ($latestRelease.tag_name -ne $currentVersion) {
$updateMessage = $localeData.updateMessages.newVersionAvailable
$userChoice = [System.Windows.Forms.MessageBox]::Show($updateMessage, $localeData.updateMessages.updateAvailable, "YesNo", "Information")
if ($userChoice -eq "Yes") {
Start-Process $latestRelease.html_url
}
}
}
$loadingForm.Close()
})
$form = New-Object System.Windows.Forms.Form
$form.Text = "SASPClean"
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDirectory = Split-Path $scriptPath -Parent
$image = [System.Drawing.Image]::FromFile($iconPath)
$icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap($image)).GetHicon())
$form.Icon = $icon
$form.Size = New-Object System.Drawing.Size(1225, 600)
$form.StartPosition = "CenterScreen"
$form.AutoScroll = $true
$backgroundColor = [System.Drawing.Color]::FromArgb(255, 245, 245, 245)
$buttonColor = [System.Drawing.Color]::FromArgb(255, 0, 102, 204)
$buttonForeColor = [System.Drawing.Color]::White
$form.BackColor = $backgroundColor
$checkboxOptions = @(
$localeData.checkDisk,
$localeData.clearWindowsUpdate,
$localeData.diskCleaner,
$localeData.diskCleanerSagerun,
$localeData.dismTools,
$localeData.mdtTool,
$localeData.mrtTool,
$localeData.fileSystemCheck,
$localeData.windowsExperienceIndex,
$localeData.upgradePackages,
$localeData.checkWinUpdate,
$localeData.checkHacked,
$localeData.performanceHigh,
$localeData.gameMode,
$localeData.performanceOptions,
$localeData.systemInfo,
$localeData.initiateFileCleanup
)
$checkboxes = @{}
$yPosition = 20
foreach ($option in $checkboxOptions) {
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Text = $option
$checkbox.Location = New-Object System.Drawing.Point(20, $yPosition)
$checkbox.AutoSize = $true
$checkbox.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$checkbox.ForeColor = [System.Drawing.Color]::FromArgb(255, 33, 33, 33)
$form.Controls.Add($checkbox)
$checkboxes[$option] = $checkbox
$yPosition += 25
}
$runButton = New-Object System.Windows.Forms.Button
$runButton.Text = $localeData.runButton
$runButton.Location = New-Object System.Drawing.Point(20, $yPosition)
$runButton.BackColor = $buttonColor
$runButton.ForeColor = $buttonForeColor
$runButton.Width = 100
$runButton.Add_Click({
foreach ($option in $checkboxOptions) {
if ($checkboxes[$option].Checked) {
switch -wildcard ($option) {
$localeData.checkDisk {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "chkdsk /f" -Wait
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "chkdsk /x" -Wait
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "chkdsk /r" -Wait
}
$localeData.clearWindowsUpdate {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "dism /online /cleanup-image /startcomponentcleanup" -Wait
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "dism /online /cleanup-image /spsuperseded" -Wait
}
$localeData.diskCleaner {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "cleanmgr.exe" -Wait
}
$localeData.diskCleanerSagerun {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "cleanmgr /sagerun:1" -Wait
}
$localeData.dismTools {
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "/c", "dism /online /add-package /packagepath:C:\path\to\update.cab" -Wait
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "/c", "dism /online /cleanup-image /checkhealth" -Wait
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "/c", "dism /online /get-packages"-Wait
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "/c", "dism /online /cleanup-image /restorehealth /source:C:\path\to\source /limitaccess"-Wait
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "/c", "dism /online /cleanup-image /restorehealth /source:C:\path\to\repairsource\install.wim" -Wait
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "/c", "dism /online /cleanup-image /restorehealth /source:C:\RepairSource\Windows /limitaccess" -Wait
Start-Process -FilePath "cmd.exe" -Verb RunAs -ArgumentList "/c", "dism /online /cleanup-image /restorehealth" -Wait
}
$localeData.mdtTool {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "mdsched.exe" -Wait
}
$localeData.mrtTool {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "mrt.exe" -Wait
}
$localeData.fileSystemCheck {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "sfc /scannow" -Wait
}
$localeData.windowsExperienceIndex {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "winsat formal" -Wait
}
$localeData.upgradePackages {
$chocoInstalled = Get-Command choco -ErrorAction SilentlyContinue
if ($null -eq $chocoInstalled) {
Write-Host "$localeData.chocolateyNotFound"
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" -Wait
} else {
Write-Host "$localeData.chocolateyInstalled"
}
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "choco upgrade all -y && winget upgrade --all" -Wait
}
$localeData.checkWinUpdate {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "wuauclt.exe /detectnow" -Wait
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/c", "wuauclt.exe /updatenow" -Wait
}
$localeData.checkHacked {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "quser" -Wait
}
$localeData.performanceHigh {
Start-Process "powercfg.cpl" -Verb RunAs
}
$localeData.gameMode {
Start-Process 'ms-settings:gaming-gamemode' -Wait
}
$localeData.performanceOptions {
SystemPropertiesPerformance
}
$localeData.systemInfo {
Start-Process 'cmd.exe' -Verb RunAs -ArgumentList "/k", "systeminfo" -Wait
}
$localeData.initiateFileCleanup {
Start-Process 'cmd.exe' -ArgumentList "/k", "npm install && node test\index.test.js && pause" -Wait
}
}
}
}
})
$form.Controls.Add($runButton)
$form.add_Closing({
if (-not $RanScript -and [Windows.Forms.MessageBox]::Show($localeData.exitMessage, $localeData.exitTitle, 'YesNo', 'Question') -eq 'No') {
$_.Cancel = $true
}
})
$loadingForm.ShowDialog()
$form.ShowDialog()