Skip to content

Commit 939403a

Browse files
committed
The code has been completely rewritten to migrate from Batch to PowerShell, with the aim of taking advantage of modern features and ensuring greater longevity.
New messages have been added to the translation files and theme customization settings have been removed from the configuration. The README.md and LICENSE.md files have been modified to improve readability.
1 parent 476b8cf commit 939403a

File tree

7 files changed

+214
-254
lines changed

7 files changed

+214
-254
lines changed

LICENSE renamed to LICENSE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
# MIT License
22

3-
Copyright (c) 2024 Christopher
3+
## Copyright (c) 2024 Christopher
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

auto-repair.cmd

Lines changed: 0 additions & 193 deletions
This file was deleted.

auto-repair.ps1

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Switch to UTF-8
2+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
3+
4+
# Function to import .properties files as variables
5+
function Import-PropertiesFile {
6+
param (
7+
[string]$Path
8+
)
9+
Get-Content $Path | ForEach-Object {
10+
if ($_ -notmatch '^\s*#' -and $_ -match '^(.*?)=(.*)$') {
11+
Set-Variable -Name $matches[1].Trim() -Value $matches[2].Trim() -Scope Script
12+
}
13+
}
14+
}
15+
16+
# Load general settings
17+
Import-PropertiesFile "$PSScriptRoot\config.properties"
18+
19+
# Load language file according to the ‘lang’ variable in config.properties
20+
Import-PropertiesFile "$PSScriptRoot\languages\$lang.properties"
21+
22+
# Declare Pause function
23+
function Pause {
24+
Write-Host ""
25+
Write-Host "$pauseMessage"
26+
[void][System.Console]::ReadKey($true)
27+
}
28+
29+
Clear-Host
30+
31+
# Check administrator permissions
32+
function Test-Admin {
33+
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
34+
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
35+
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
36+
}
37+
38+
if (-not (Test-Admin)) {
39+
Clear-Host
40+
Write-Host $separatorLarge
41+
Write-Host ""
42+
Write-Host $permissionWarning0
43+
Write-Host $permissionWarning1
44+
Write-Host $separatorLarge
45+
Write-Host ""
46+
Pause
47+
Start-Process powershell "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
48+
exit
49+
}
50+
51+
function Show-Menu {
52+
Clear-Host
53+
Write-Host $separatorLarge
54+
Write-Host ""
55+
Write-Host $mainMenuTitle
56+
Write-Host ""
57+
Write-Host "[1] $option1"
58+
Write-Host "[2] $option2"
59+
Write-Host "[3] $option3 ($partition)"
60+
Write-Host $separatorSmall
61+
Write-Host ""
62+
Write-Host "[4] $option4"
63+
Write-Host "[5] $option5"
64+
Write-Host "[6] $option6 ($partition)"
65+
Write-Host "[7] $option7 ($partition)"
66+
Write-Host $separatorSmall
67+
Write-Host ""
68+
Write-Host "[8] $option8"
69+
Write-Host "[9] $option9"
70+
Write-Host "[0] $option0"
71+
Write-Host "[Q] $optionQ"
72+
Write-Host $separatorLarge
73+
Write-Host ""
74+
}
75+
76+
do {
77+
Show-Menu
78+
Write-Host $prompt
79+
$key = [System.Console]::ReadKey($true).KeyChar
80+
$choice = $key.ToString().ToUpper()
81+
82+
switch ($choice) {
83+
'1' {
84+
Clear-Host
85+
Write-Host "sfc /scannow" -ForegroundColor Green
86+
Start-Process -Wait -NoNewWindow cmd "/c sfc /scannow"
87+
Pause
88+
}
89+
'2' {
90+
Clear-Host
91+
Write-Host "DISM /online /cleanup-image /restorehealth" -ForegroundColor Green
92+
Start-Process -Wait -NoNewWindow cmd "/c DISM /online /cleanup-image /restorehealth"
93+
Pause
94+
}
95+
'3' {
96+
Clear-Host
97+
Write-Host "chkdsk $partition /f /r /x" -ForegroundColor Green
98+
Start-Process -Wait -NoNewWindow cmd "/c chkdsk $partition /f /r /x"
99+
Pause
100+
}
101+
'4' {
102+
Clear-Host
103+
Write-Host "DISM /Online /Cleanup-Image /CheckHealth" -ForegroundColor Green
104+
Start-Process -Wait -NoNewWindow cmd "/c DISM /Online /Cleanup-Image /CheckHealth"
105+
Write-Host ""
106+
Write-Host "DISM /Online /Cleanup-Image /ScanHealth" -ForegroundColor Green
107+
Start-Process -Wait -NoNewWindow cmd "/c DISM /Online /Cleanup-Image /ScanHealth"
108+
Pause
109+
}
110+
'5' {
111+
Clear-Host
112+
Write-Host "DISM /online /cleanup-image /startcomponentcleanup /resetbase" -ForegroundColor Green
113+
Start-Process -Wait -NoNewWindow cmd "/c DISM /online /cleanup-image /startcomponentcleanup /resetbase"
114+
Write-Host ""
115+
Write-Host "DISM /Online /Cleanup-Image /startComponentCleanup" -ForegroundColor Green
116+
Start-Process -Wait -NoNewWindow cmd "/c DISM /Online /Cleanup-Image /startComponentCleanup"
117+
Pause
118+
}
119+
'6' {
120+
Clear-Host
121+
Write-Host "chkdsk $partition /F /R" -ForegroundColor Green
122+
Start-Process -Wait -NoNewWindow cmd "/c chkdsk $partition /F /R"
123+
Pause
124+
}
125+
'7' {
126+
Clear-Host
127+
Write-Host "defrag $partition /U /V" -ForegroundColor Green
128+
Start-Process -Wait -NoNewWindow cmd "/c defrag $partition /U /V"
129+
Pause
130+
}
131+
'8' {
132+
Clear-Host
133+
Write-Host $separatorSmall
134+
Write-Host ""
135+
Write-Host $instructiveMessage
136+
Write-Host ""
137+
Write-Host $instructiveLink
138+
Write-Host $separatorSmall
139+
Pause
140+
}
141+
'9' {
142+
Clear-Host
143+
Write-Host $separatorSmall
144+
Write-Host ""
145+
Write-Host $sourcesMessage
146+
Write-Host ""
147+
Write-Host $sourcesLink
148+
Write-Host $separatorSmall
149+
Pause
150+
}
151+
'0' {
152+
Clear-Host
153+
Write-Host $separatorLarge
154+
Write-Host ""
155+
Write-Host "$aboutMessageVersion $scriptVersion"
156+
Write-Host "$aboutMessageFirstDate $scriptFirstDate"
157+
Write-Host "$aboutMessageReleaseDate $scriptReleaseDate"
158+
Write-Host $separatorSmall
159+
Write-Host ""
160+
Write-Host "$aboutMessageContact $scriptAuthor"
161+
Write-Host $separatorLarge
162+
Pause
163+
}
164+
'Q' {
165+
Clear-Host
166+
Write-Host $separatorSmall
167+
Write-Host ""
168+
Write-Host $exitingMessage
169+
Write-Host $separatorSmall
170+
Pause
171+
exit
172+
}
173+
default {
174+
Write-Host ""
175+
Write-Host "$InvalidOption" -ForegroundColor Red
176+
Write-Host ""
177+
Start-Sleep -Seconds 5
178+
}
179+
}
180+
} while ($true)

0 commit comments

Comments
 (0)