-
-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathuninstall.ps1
More file actions
341 lines (302 loc) · 12.4 KB
/
Copy pathuninstall.ps1
File metadata and controls
341 lines (302 loc) · 12.4 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
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
# Islands Dark Theme Uninstaller for Windows
param(
[ValidateSet("auto", "vscode", "vscodium")]
[string]$Editor = "auto"
)
$ErrorActionPreference = "Stop"
Write-Host "Islands Dark Theme Uninstaller for Windows" -ForegroundColor Cyan
Write-Host "===========================================" -ForegroundColor Cyan
Write-Host ""
# Pick editor target
if ($env:ISLANDS_DARK_EDITOR -and $Editor -eq "auto") {
$Editor = $env:ISLANDS_DARK_EDITOR
}
$Editor = $Editor.ToLowerInvariant()
if ($Editor -eq "codium") {
$Editor = "vscodium"
} elseif ($Editor -eq "code") {
$Editor = "vscode"
}
if ($Editor -eq "auto") {
if (Get-Command "code" -ErrorAction SilentlyContinue) {
$Editor = "vscode"
} elseif (Get-Command "codium" -ErrorAction SilentlyContinue) {
$Editor = "vscodium"
} else {
$Editor = "vscode"
}
}
if ($Editor -eq "vscodium") {
$editorName = "VSCodium"
$cliName = "codium"
$extRoot = "$env:USERPROFILE\.vscode-oss\extensions"
$settingsDir = "$env:APPDATA\VSCodium\User"
$processName = "VSCodium"
$editorDirs = @(
"$env:LOCALAPPDATA\Programs\VSCodium",
"$env:ProgramFiles\VSCodium",
"${env:ProgramFiles(x86)}\VSCodium"
)
$possiblePaths = @(
"$env:LOCALAPPDATA\Programs\VSCodium\bin\codium.cmd",
"$env:ProgramFiles\VSCodium\bin\codium.cmd",
"${env:ProgramFiles(x86)}\VSCodium\bin\codium.cmd"
)
} else {
$editorName = "VS Code"
$cliName = "code"
$extRoot = "$env:USERPROFILE\.vscode\extensions"
$settingsDir = "$env:APPDATA\Code\User"
$processName = "Code"
$editorDirs = @(
"$env:LOCALAPPDATA\Programs\Microsoft VS Code",
"$env:ProgramFiles\Microsoft VS Code",
"${env:ProgramFiles(x86)}\Microsoft VS Code"
)
$possiblePaths = @(
"$env:LOCALAPPDATA\Programs\Microsoft VS Code\bin\code.cmd",
"$env:ProgramFiles\Microsoft VS Code\bin\code.cmd",
"${env:ProgramFiles(x86)}\Microsoft VS Code\bin\code.cmd"
)
}
# Locate editor CLI
$codePath = Get-Command $cliName -ErrorAction SilentlyContinue
if (-not $codePath) {
foreach ($path in $possiblePaths) {
if (Test-Path $path) {
$env:Path += ";$(Split-Path $path)"
$codePath = $true
break
}
}
}
if ($codePath) {
Write-Host "$editorName CLI found" -ForegroundColor Green
} else {
Write-Host "$editorName CLI not found - will skip CLI operations" -ForegroundColor Yellow
}
Write-Host ""
# Load pre-install state if available
$settingsFile = Join-Path $settingsDir "settings.json"
$stateFile = Join-Path $settingsDir ".islands-dark-state.json"
$state = $null
if (Test-Path $stateFile) {
try {
$state = Get-Content $stateFile -Raw | ConvertFrom-Json
Write-Host "Found pre-install state file" -ForegroundColor Green
} catch {
Write-Host "Could not read state file" -ForegroundColor Yellow
}
}
# Step 1: Restore editor settings
Write-Host "Step 1: Restoring $editorName settings..."
$restored = $false
# Try to restore from the exact backup recorded in state file
if ($state -and $state.settingsBackupPath -and (Test-Path $state.settingsBackupPath)) {
Copy-Item $state.settingsBackupPath $settingsFile -Force
Write-Host "Settings restored from original backup" -ForegroundColor Green
Write-Host " Source: $($state.settingsBackupPath)" -ForegroundColor DarkGray
$restored = $true
}
# Fall back to latest timestamped backup
if (-not $restored -and (Test-Path $settingsDir)) {
$backups = Get-ChildItem "$settingsDir\settings.json.pre-islands-dark*" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending
if ($backups.Count -gt 0) {
Copy-Item $backups[0].FullName $settingsFile -Force
Write-Host "Settings restored from backup" -ForegroundColor Green
Write-Host " Source: $($backups[0].FullName)" -ForegroundColor DarkGray
$restored = $true
}
}
# If no backup exists, surgically remove Islands Dark keys from settings
if (-not $restored -and (Test-Path $settingsFile)) {
Write-Host "No backup found - surgically removing Islands Dark settings..." -ForegroundColor Yellow
try {
$raw = Get-Content $settingsFile -Raw
try { $settings = $raw | ConvertFrom-Json }
catch { $settings = $null }
if ($settings) {
# Keys that Islands Dark adds
$islandsKeys = @(
'// Islands Dark Settings v0.0.3',
'// Islands Dark Settings v0.0.2',
'custom-ui-style.stylesheet',
'custom-ui-style.font',
'chat.viewSessions.orientation'
)
$cleaned = [ordered]@{}
$settings.PSObject.Properties | ForEach-Object {
if ($_.Name -notin $islandsKeys) {
$cleaned[$_.Name] = $_.Value
}
}
# Restore previous theme if we have state
if ($state) {
if ($state.previousColorTheme) {
$cleaned['workbench.colorTheme'] = $state.previousColorTheme
}
if ($state.previousIconTheme) {
$cleaned['workbench.iconTheme'] = $state.previousIconTheme
}
} else {
# Reset to editor defaults
$cleaned['workbench.colorTheme'] = 'Default Dark+'
$cleaned.Remove('workbench.iconTheme')
}
[PSCustomObject]$cleaned | ConvertTo-Json -Depth 100 | Set-Content $settingsFile
Write-Host "Islands Dark settings removed, previous theme restored" -ForegroundColor Green
}
} catch {
Write-Host "Could not modify settings.json - please update manually" -ForegroundColor Yellow
}
} elseif (-not $restored) {
Write-Host "No settings.json found" -ForegroundColor Yellow
}
# Step 2: Remove Islands Dark theme extension
Write-Host ""
Write-Host "Step 2: Removing Islands Dark theme extension..."
$extDir = Join-Path $extRoot "bwya77.islands-dark-1.0.0"
if (Test-Path $extDir) {
Remove-Item -Recurse -Force $extDir
Write-Host "Theme extension directory removed" -ForegroundColor Green
} else {
Write-Host "Extension directory not found (may already be removed)" -ForegroundColor Yellow
}
if ($codePath) {
try {
$null = & $cliName --uninstall-extension bwya77.islands-dark --force 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Extension uninstalled via $editorName CLI" -ForegroundColor Green
}
} catch {}
}
# Step 3: Handle Custom UI Style extension
Write-Host ""
Write-Host "Step 2b: Clearing extensions.json..."
# Remove extensions.json so the editor rebuilds it from the extensions
# actually on disk. Restoring the pre-install backup would lose any
# extensions the user installed after Islands Dark.
$extJson = Join-Path $extRoot "extensions.json"
if (Test-Path $extJson) {
Remove-Item $extJson -Force
Write-Host "extensions.json removed ($editorName will rebuild it on next launch)" -ForegroundColor Green
} else {
Write-Host "extensions.json not present (already clean)" -ForegroundColor DarkGray
}
Write-Host ""
Write-Host "Step 3: Handling Custom UI Style extension..."
if ($state -and $state.customUiStyleWasInstalled -eq $true) {
# Custom UI Style was already installed before Islands Dark - leave it but disable CSS
Write-Host "Custom UI Style was installed before Islands Dark - leaving it installed" -ForegroundColor Green
Write-Host " The Islands Dark CSS rules have been removed from your settings." -ForegroundColor DarkGray
} else {
# We installed it, so uninstall it
if ($codePath) {
try {
$null = & $cliName --uninstall-extension subframe7536.custom-ui-style --force 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Custom UI Style extension uninstalled" -ForegroundColor Green
} else {
Write-Host "Custom UI Style may already be removed" -ForegroundColor Yellow
}
} catch {
Write-Host "Could not uninstall Custom UI Style automatically" -ForegroundColor Yellow
}
} else {
Write-Host "Please uninstall Custom UI Style manually from $editorName Extensions" -ForegroundColor Yellow
}
}
# Step 3b: Restore editor workbench files patched by Custom UI Style
Write-Host ""
Write-Host "Step 3b: Removing Custom UI Style CSS patches..."
$cuiRestoredCount = 0
foreach ($vscodeBase in $editorDirs) {
if (-not (Test-Path $vscodeBase)) { continue }
# Custom UI Style saves originals as *.custom-ui-style.{ext}
# Find all backup files and restore them
$backupFiles = Get-ChildItem $vscodeBase -Recurse -Filter "*.custom-ui-style.*" -ErrorAction SilentlyContinue
foreach ($backup in $backupFiles) {
# Derive the original filename: workbench.custom-ui-style.html -> workbench.html
# workbench.desktop.main.custom-ui-style.css -> workbench.desktop.main.css
$originalName = $backup.Name -replace '\.custom-ui-style\.', '.'
$originalPath = Join-Path $backup.DirectoryName $originalName
if (Test-Path $originalPath) {
try {
Copy-Item $backup.FullName $originalPath -Force
Remove-Item $backup.FullName -Force
$cuiRestoredCount++
} catch {
Write-Host " Could not restore: $originalName" -ForegroundColor Yellow
}
}
}
break
}
if ($cuiRestoredCount -gt 0) {
Write-Host "$cuiRestoredCount $editorName file(s) restored to original state" -ForegroundColor Green
} else {
Write-Host "No Custom UI Style patches found (already clean)" -ForegroundColor DarkGray
}
# Step 4: Remove fonts that we installed
Write-Host ""
Write-Host "Step 4: Removing installed fonts..."
if ($state -and $state.fonts) {
$removedCount = 0
$state.fonts.PSObject.Properties | ForEach-Object {
$fontInfo = $_.Value
if ($fontInfo.wasPresentBeforeInstall -eq $false -and $fontInfo.installedPath -and (Test-Path $fontInfo.installedPath)) {
Remove-Item $fontInfo.installedPath -Force -ErrorAction SilentlyContinue
$removedCount++
}
}
if ($removedCount -gt 0) {
Write-Host "$removedCount font(s) removed" -ForegroundColor Green
} else {
Write-Host "No fonts to remove (all were pre-existing)" -ForegroundColor DarkGray
}
} else {
Write-Host "No font state found - skipping font removal" -ForegroundColor Yellow
Write-Host " You can manually remove Bear Sans UI fonts from: $env:LOCALAPPDATA\Microsoft\Windows\Fonts" -ForegroundColor DarkGray
}
# Step 5: Clean up state and backup files
Write-Host ""
Write-Host "Step 5: Cleaning up..."
if (Test-Path $stateFile) {
Remove-Item $stateFile -Force
Write-Host "State file removed" -ForegroundColor DarkGray
}
# Clean up backup files
if (Test-Path $settingsDir) {
$backupFiles = Get-ChildItem "$settingsDir\settings.json.pre-islands-dark*" -ErrorAction SilentlyContinue
if ($backupFiles.Count -gt 0) {
$backupFiles | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Host "$($backupFiles.Count) settings backup file(s) removed" -ForegroundColor DarkGray
}
}
# Clean up extensions.json backup files
if (Test-Path $extRoot) {
$extJsonBackups = Get-ChildItem "$extRoot\extensions.json.pre-islands-dark*" -ErrorAction SilentlyContinue
if ($extJsonBackups.Count -gt 0) {
$extJsonBackups | Remove-Item -Force -ErrorAction SilentlyContinue
Write-Host "$($extJsonBackups.Count) extensions.json backup file(s) removed" -ForegroundColor DarkGray
}
}
# Step 6: Reload editor
Write-Host ""
Write-Host "Step 6: Reloading $editorName..."
if ($codePath) {
Write-Host " Closing $editorName..." -ForegroundColor Cyan
Stop-Process -Name $processName -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 3
Write-Host " Relaunching $editorName..." -ForegroundColor Cyan
Start-Process $cliName -ErrorAction SilentlyContinue
} else {
Write-Host " Please restart $editorName manually to complete the uninstall." -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Islands Dark has been uninstalled!" -ForegroundColor Green
Write-Host ""
Write-Host "Note: If you see CSS artifacts, open Command Palette (Ctrl+Shift+P)" -ForegroundColor Yellow
Write-Host "and run 'Custom UI Style: Disable' to clean up injected styles." -ForegroundColor Yellow
Write-Host ""
Start-Sleep -Seconds 3