forked from emadadel4/itt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newTweak.ps1
277 lines (222 loc) · 8.57 KB
/
newTweak.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
Write-Host "
+-------------------------------------------------------------------------+
| ___ _____ _____ ____ _ _____ _ ____ _ ____ _____ |
| |_ _|_ _|_ _| | _ \ / \|_ _|/ \ | __ ) / \ / ___|| ____| |
| | | | | | | | | | |/ _ \ | | / _ \ | _ \ / _ \ \___ \| _| |
| | | | | | | | |_| / ___ \| |/ ___ \| |_) / ___ \ ___) | |___ |
| |___| |_| |_| |____/_/ \_\_/_/ \_\____/_/ \_\____/|_____| |
| Made with ♥ By Emad Adel |
+-------------------------------------------------------------------------+
"
# Function to create JSON structure
function Create-JsonObject {
$Name = Read-Host "Tweak name"
$Description = Read-Host "Description"
$jsonObject = @{
Name = $Name
Description = $Description
Check = "false"
Category = ""
Refresh = "false"
Registry = @()
AppxPackage = @()
ScheduledTask = @()
Script = @()
UndoScript = @()
Services = @()
}
$jsonObject.Category += Category
$addRemoveCommands = Read-Host "Do you want to add 'Command' in this tweak? (y/n)"
if ($addRemoveCommands -eq "y") {
$jsonObject.Script += Add-Commands
}
# Prompt user to add items to specific properties
$addRemoveTasks = (Read-Host "Do you want to add 'Remove ScheduledTask' in this tweak? (y/n)").ToLower()
if ($addRemoveTasks -eq "y") {
$jsonObject.ScheduledTask += Add-RemoveTasks
}
$addRegistry = Read-Host "Do you want to Modify 'Registry' in this tweak? (y/n)"
if ($addRegistry -eq "y") {
$jsonObject.Registry += Add-Registry
}
# Prompt user to add Appx packages
$addRemoveAppxPackage = Read-Host "Do you want to Remove 'AppxPackage' in this tweak? (y/n)"
if ($addRemoveAppxPackage -eq "y") {
$jsonObject.AppxPackage += Add-AppxPackage
}
$addServices = Read-Host "Do you want to add 'Services' in this tweak? (y/n)"
if ($addServices -eq "y") {
$jsonObject.Services += Add-Services
}
return $jsonObject
}
function Category {
# category
$ActionType = @{
1 = "Privacy"
2 = "Fixer"
3 = "Performance"
4 = "Personalization"
5 = "Power"
6 = "Protection"
7 = "Classic"
}
do {
Write-Host "Which category will this tweak belong to?"
foreach ($key in $ActionType.Keys | Sort-Object) {
Write-Host "$key - $($ActionType[$key])"
}
$choice = Read-Host "Enter the number corresponding to the Tweak Type"
if ([int]$choice -in $ActionType.Keys) {
$category = $ActionType[[int]$choice]
} else {
Write-Host "Invalid choice. Please select a valid option."
}
} until ([int]$choice -in $ActionType.Keys)
# category
return $category
}
# Function to add Command
function Add-Commands {
$Commands = @() # Initialize an array for tasks
do {
$cmd = Read-Host "Enter a command"
$Commands += $cmd
# Ask if the user wants to add another task
$addAnotherCommand = Read-Host "Do you want to add another command? (y/n)"
} while ($addAnotherCommand -eq "y")
return $Commands
}
# Function to add tasks to RemoveTasks
function Add-RemoveTasks {
$tasks = @() # Initialize an array for tasks
do {
$task = Read-Host "Enter ScheduledTask name"
$tasks += $task
# Ask if the user wants to add another task
$addAnotherTask = Read-Host "Do you want to add another task? (yes/no)"
} while ($addAnotherTask -eq "yes")
return $tasks
}
# Function to add Services
function Add-Services {
$ServicesEntries = @() # Initialize an array
do {
# StartupType
$StartupType = @{
1 = "Disabled"
2 = "Automatic"
4 = "Manual "
}
do {
Write-Host "Which category will this tweak belong to?"
foreach ($key in $StartupType.Keys | Sort-Object) {
Write-Host "$key - $($StartupType[$key])"
}
$choice = Read-Host "Enter the number corresponding to the Tweak Type"
if ([int]$choice -in $StartupType.Keys) {
$type = $StartupType[[int]$choice]
} else {
Write-Host "Invalid choice. Please select a valid option."
}
} until ([int]$choice -in $StartupType.Keys)
# StartupType
# Create a new entry for Modify
$Services = @{
Name = Read-Host "Enter Service name"
StartupType = $type
DefaultType = "Manual"
}
$ServicesEntries += $Services # Add the entry to the array
# Ask if the user wants to add another Modify entry
$continue = Read-Host "Do you want to add another Service entry? (y/n)"
} while ($continue -eq "y")
return $ServicesEntries
}
# Function to add modify entries to Registry
function Add-Registry {
$modifyEntries = @() # Initialize an array
do {
# ValueType
$ValueType = @{
1 = "DWord"
2 = "Qword"
3 = "Binary"
4 = "String"
5 = "MultiString"
6 = "ExpandString"
7 = "LINK"
8 = "NONE"
9 = "QWORD_LITTLE_ENDIAN"
}
do {
Write-Host "What is the value type"
foreach ($key in $ValueType.Keys | Sort-Object) {
Write-Host "$key - $($ValueType[$key])"
}
$choice = Read-Host "Enter the number corresponding to the Tweak Type"
if ([int]$choice -in $ValueType.Keys) {
$type = $ValueType[[int]$choice]
} else {
Write-Host "Invalid choice. Please select a valid option."
}
} until ([int]$choice -in $ValueType.Keys)
# ValueType
# Create a new entry for Registry
$modifyEntry = @{
Path = Read-Host "Enter Path"
Name = Read-Host "Enter value Name"
Type = $type
Value = Read-Host "Enter Value"
DefaultValue = Read-Host "Enter Default Value"
}
$modifyEntries += $modifyEntry # Add the entry to the Modify array
# Ask if the user wants to add another Modify entry
$continue = Read-Host "Do you want to add another Modify entry? (y/n)"
} while ($continue -eq "y")
return $modifyEntries
}
# Function to add Appx packages
function Add-AppxPackage {
$appxPackages = @() # Initialize an array for Appx packages
do {
$packageName = Read-Host "Enter Appx package name'"
$appxPackages += $packageName
# Ask if the user wants to add another Appx package
$addAnotherAppx = Read-Host "Do you want to add another Appx package? (y/n)"
} while ($addAnotherAppx -eq "y")
return $appxPackages
}
# Main script execution
$outputFilePath = "./static/Database/Tweaks.json"
# Check if the JSON file exists
if (Test-Path $outputFilePath) {
# Read existing JSON file
$existingJson = Get-Content -Path $outputFilePath -Raw | ConvertFrom-Json
# Create a new JSON object to add
$newJsonObject = Create-JsonObject
# Append the new object to the existing JSON structure
$existingJson += $newJsonObject
# Convert back to JSON format while maintaining the property order
$jsonOutput = @()
foreach ($item in $existingJson) {
$jsonOutput += [PSCustomObject]@{
Name = $item.Name
Description = $item.Description
Category = $item.Category
Check = $item.Check
Refresh = $item.Refresh
Script = $item.Script
UndoScript = $item.UndoScript
ScheduledTask = $item.ScheduledTask
AppxPackage = $item.AppxPackage
Services = $item.Services
Registry = $item.Registry
}
}
# Write the ordered JSON to the file
$jsonOutput | ConvertTo-Json -Depth 20 | Out-File -FilePath $outputFilePath -Encoding utf8
Write-Host "Added successfully to existing JSON file. Don't forget to build and test it before commit" -ForegroundColor Green
} else {
Write-Host "The file $outputFilePath does not exist!" -ForegroundColor Red
}