@@ -130,6 +130,86 @@ else {
130130$exe = Join-Path $InstallDir ' bin\xpplens.exe'
131131Say " done: $exe "
132132
133+ # The program folder on the user's PATH, as the setup program does: "xpplens" then works in any new terminal.
134+ # Read and written raw (REG_EXPAND_SZ), so entries such as %USERPROFILE%\... keep expanding.
135+ $binFull = (Resolve-Path $binDst ).Path.TrimEnd(' \' )
136+ $envKey = [Microsoft.Win32.Registry ]::CurrentUser.OpenSubKey(' Environment' , $true )
137+ try {
138+ $rawPath = [string ]$envKey.GetValue (' Path' , ' ' , [Microsoft.Win32.RegistryValueOptions ]::DoNotExpandEnvironmentNames)
139+ $items = @ ($rawPath -split ' ;' | Where-Object { $_ })
140+ if ($items | Where-Object { [Environment ]::ExpandEnvironmentVariables($_ ).TrimEnd(' \' ) -ieq $binFull }) {
141+ Say " already on your PATH: $binFull "
142+ }
143+ else {
144+ $envKey.SetValue (' Path' , (@ ($items ) + $binFull ) -join ' ;' , [Microsoft.Win32.RegistryValueKind ]::ExpandString)
145+ # Tell Explorer, so terminals opened from now on see it (WM_SETTINGCHANGE "Environment").
146+ Add-Type - Namespace XppLensSetup - Name Native - MemberDefinition @'
147+ [DllImport("user32.dll", CharSet = CharSet.Unicode)]
148+ public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint msg, UIntPtr wParam, string lParam, uint flags, uint timeout, out UIntPtr result);
149+ '@
150+ $ignored = [UIntPtr ]::Zero
151+ [void ][XppLensSetup.Native ]::SendMessageTimeout([IntPtr ]0xffff , 0x1A , [UIntPtr ]::Zero, ' Environment' , 2 , 5000 , [ref ]$ignored )
152+ $env: Path = " $env: Path ;$binFull "
153+ Say " added to your PATH: $binFull (open a new terminal to use 'xpplens')"
154+ }
155+ }
156+ finally {
157+ $envKey.Close ()
158+ }
159+
160+ # Start menu entries and an entry in Windows' installed apps, as the setup program makes them. When the setup
161+ # program installed xpp-lens for this user, its own entries stay (they are the same, and its uninstaller owns
162+ # them); the setup program removes these when it takes over a folder installed by this script.
163+ $setupKey = ' HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{B3C9E031-73CD-4356-AC30-B8EC91C3C528}_is1'
164+ if (Test-Path $setupKey ) {
165+ Say " Start menu and installed apps: kept from the setup program ($ ( (Get-ItemProperty $setupKey ).InstallLocation) )"
166+ }
167+ else {
168+ $pl = if ($SkillsLanguage ) { $SkillsLanguage -eq ' pl' } else { (Get-UICulture ).TwoLetterISOLanguageName -eq ' pl' }
169+ # The setup program's names (Polish without diacritics in this ASCII script: "sprawdz" gets its z-acute here).
170+ $names = if ($pl ) {
171+ @ { status = ' xpp-lens - status' ; build = ' xpp-lens - aktualizacja indeksu' ; update = " xpp-lens - sprawd$ ( [char ]0x17A ) aktualizacje"
172+ uninstall = ' Odinstaluj xpp-lens' ; console = ' Konsola z poleceniami xpplens' }
173+ }
174+ else {
175+ @ { status = ' xpp-lens - status' ; build = ' xpp-lens - update the index' ; update = ' xpp-lens - check for updates'
176+ uninstall = ' Uninstall xpp-lens' ; console = ' Console with the xpplens commands' }
177+ }
178+ $group = Join-Path ([Environment ]::GetFolderPath(' Programs' )) ' xpp-lens'
179+ if (Test-Path $group ) { Remove-Item $group - Recurse - Force }
180+ New-Item - ItemType Directory - Force - Path $group | Out-Null
181+ $shell = New-Object - ComObject WScript.Shell
182+ function New-Shortcut ($name , $target , $arguments , $workDir , $description ) {
183+ $lnk = $shell.CreateShortcut ((Join-Path $group " $name .lnk" ))
184+ $lnk.TargetPath = $target
185+ $lnk.Arguments = $arguments
186+ $lnk.WorkingDirectory = $workDir
187+ $lnk.IconLocation = " $exe ,0"
188+ if ($description ) { $lnk.Description = $description }
189+ $lnk.Save ()
190+ }
191+ New-Shortcut ' xpp-lens' $env: ComSpec " /k `" title xpp-lens & set `" PATH=$binFull ;%PATH%`" & xpplens help`" " $env: USERPROFILE $names.console
192+ foreach ($c in ' status' , ' build' , ' update' ) {
193+ New-Shortcut $names [$c ] $env: ComSpec " /k `"`" $exe `" $c `" " $InstallDir $null
194+ }
195+ $uninstallCmd = " -NoProfile -ExecutionPolicy Bypass -File `" $ ( Join-Path $InstallDir ' uninstall.ps1' ) `" "
196+ New-Shortcut $names.uninstall ' powershell.exe' $uninstallCmd $InstallDir $null
197+
198+ $appKey = ' HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\xpp-lens'
199+ New-Item - Path $appKey - Force | Out-Null
200+ $appVersion = ([string ](& $exe version)).Split(' ' )[1 ]
201+ $sizeKb = [int ]((Get-ChildItem $InstallDir - Recurse - File | Measure-Object Length - Sum).Sum / 1 KB )
202+ $values = @ {
203+ DisplayName = ' xpp-lens' ; DisplayVersion = $appVersion ; Publisher = ' WillowDev' ; DisplayIcon = $exe
204+ InstallLocation = $dstFull ; URLInfoAbout = ' https://github.com/willowdev-code/xpp-lens'
205+ UninstallString = " powershell.exe $uninstallCmd "
206+ }
207+ foreach ($v in $values.GetEnumerator ()) { Set-ItemProperty $appKey - Name $v.Key - Value $v.Value }
208+ foreach ($v in ' NoModify' , ' NoRepair' ) { New-ItemProperty $appKey - Name $v - Value 1 - PropertyType DWord - Force | Out-Null }
209+ New-ItemProperty $appKey - Name EstimatedSize - Value $sizeKb - PropertyType DWord - Force | Out-Null
210+ Say " Start menu entries and an entry in installed apps (xpp-lens $appVersion )"
211+ }
212+
133213Head " 2/5 PackagesLocalDirectory folder"
134214if (-not $PackagesDir ) {
135215 $found = @ (& $exe detect | Where-Object { $_ -match " `t " })
0 commit comments