Skip to content

Commit 937e8d4

Browse files
author
Timabliss
committed
vscode: Use official startup script for version detection & clean registry on update
Refactored the post_install logic to be deterministic and robust: 1. Source of Truth: Instead of guessing/sniffing directory names (which is error-prone), we now parse the `bin/code` shell script. This script contains the hardcoded `VERSIONFOLDER` variable, providing the exact path hash used by VS Code itself. 2. Registry Injection: Dynamically injects the detected path into .reg templates. 3. Update Cleanup: Detects if older versions exist and automatically runs `uninstall-*.reg` to prevent dead context menu links, ensuring a clean slate for the new version.
1 parent 780bc78 commit 937e8d4

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

bucket/vscode.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@
3434
"post_install": [
3535
"$dirpath = \"$dir\".Replace('\\', '\\\\')",
3636
"$exepath = \"$dir\\Code.exe\".Replace('\\', '\\\\')",
37+
"$binFile = \"$dir\\bin\\code\"",
38+
"$targetDir = $dirpath",
39+
"if (Test-Path $binFile) {",
40+
" if ((Get-Content $binFile -Raw) -match 'VERSIONFOLDER=\"([^\"]+)\"') {",
41+
" $targetDir = \"$dir\\$($matches[1])\".Replace('\\', '\\\\')",
42+
" }",
43+
"}",
3744
"'install-associations', 'uninstall-associations', 'install-context', 'uninstall-context', 'install-github-integration', 'uninstall-github-integration' | ForEach-Object {",
3845
" if (Test-Path \"$bucketsdir\\extras\\scripts\\vscode\\$_.reg\") {",
3946
" $content = Get-Content \"$bucketsdir\\extras\\scripts\\vscode\\$_.reg\"",
40-
" $content = $content.Replace('$codedir', $dirpath)",
47+
" if ($_ -match 'github') {$targetDir = $dirpath,} else {$targetDir = $hashPath}",
48+
" $content = $content.Replace('$codedir', $targetDir)",
4149
" $content = $content.Replace('$code', $exepath)",
4250
" if ($global) {",
4351
" $content = $content.Replace('HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE')",
@@ -57,12 +65,23 @@
5765
"if ((Test-Path \"$extensions_file\")) {",
5866
" info 'Adjusting path in extensions file...'",
5967
" (Get-Content \"$extensions_file\") -replace '(?<=vscode(/|\\\\\\\\)).*?(?=(/|\\\\\\\\)data(/|\\\\\\\\)extensions)', $version | Set-Content \"$extensions_file\"",
68+
"}",
69+
"$appRoot = Split-Path $dir -Parent",
70+
"$otherVersions = Get-ChildItem $appRoot -Directory | Where-Object { $_.FullName -ne $dir -and $_.Name -ne 'current' }",
71+
"if ($otherVersions.Count -gt 0) {",
72+
" 'uninstall-associations', 'uninstall-context', 'uninstall-github-integration' | ForEach-Object {",
73+
" $regFile = \"$dir\\$_.reg\"",
74+
" if (Test-Path $regFile) {",
75+
" regedit /s \"$regFile\"",
76+
" }",
77+
" }",
6078
"}"
6179
],
6280
"uninstaller": {
6381
"script": [
6482
"if ($cmd -eq 'uninstall')",
6583
"{",
84+
" reg import \"$dir\\uninstall-associations.reg\" ",
6685
" reg import \"$dir\\uninstall-context.reg\" ",
6786
" reg import \"$dir\\uninstall-github-integration.reg\" ",
6887
"}"

0 commit comments

Comments
 (0)