mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 20:09:39 -08:00
fix(windows): build with app exe compatible fork
This commit is contained in:
parent
3cba6f74ea
commit
5047390bc4
|
@ -531,12 +531,6 @@ func (env *Shell) CommandPath(command string) string {
|
|||
env.Debug("CommandPath", path)
|
||||
return path
|
||||
}
|
||||
path, err = env.LookWinAppPath(command)
|
||||
if err == nil {
|
||||
env.cmdCache.set(command, path)
|
||||
env.Debug("CommandPath", path)
|
||||
return path
|
||||
}
|
||||
env.Error("CommandPath", err)
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
@ -118,26 +117,6 @@ func (env *Shell) CachePath() string {
|
|||
return env.Home()
|
||||
}
|
||||
|
||||
func (env *Shell) LookWinAppPath(file string) (string, error) {
|
||||
winAppPath := filepath.Join(env.Getenv("LOCALAPPDATA"), `\Microsoft\WindowsApps\`)
|
||||
if !strings.HasSuffix(file, ".exe") {
|
||||
file += ".exe"
|
||||
}
|
||||
isWinStoreApp := func() bool {
|
||||
pattern := winAppPath + env.PathSeparator() + file
|
||||
matches, err := filepath.Glob(pattern)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return len(matches) != 0
|
||||
}
|
||||
if isWinStoreApp() {
|
||||
commandFile := filepath.Join(winAppPath, file)
|
||||
return readWinAppLink(commandFile)
|
||||
}
|
||||
return "", errors.New("no Windows Store App")
|
||||
}
|
||||
|
||||
// Takes a registry path to a key like
|
||||
//
|
||||
// "HKLM\Software\Microsoft\Windows NT\CurrentVersion\EditionID"
|
||||
|
|
|
@ -155,48 +155,6 @@ func (rb *AppExecLinkReparseBuffer) Path() (string, error) {
|
|||
return link, nil
|
||||
}
|
||||
|
||||
// openSymlink calls CreateFile Windows API with FILE_FLAG_OPEN_REPARSE_POINT
|
||||
// parameter, so that Windows does not follow symlink, if path is a symlink.
|
||||
// openSymlink returns opened file handle.
|
||||
func openSymlink(path string) (syscall.Handle, error) {
|
||||
p, err := syscall.UTF16PtrFromString(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
attrs := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS)
|
||||
// Use FILE_FLAG_OPEN_REPARSE_POINT, otherwise CreateFile will follow symlink.
|
||||
// See https://docs.microsoft.com/en-us/windows/desktop/FileIO/symbolic-link-effects-on-file-systems-functions#createfile-and-createfiletransacted
|
||||
attrs |= syscall.FILE_FLAG_OPEN_REPARSE_POINT
|
||||
h, err := syscall.CreateFile(p, 0, 0, nil, syscall.OPEN_EXISTING, attrs, 0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func readWinAppLink(path string) (string, error) {
|
||||
h, err := openSymlink(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer syscall.CloseHandle(h) //nolint: errcheck
|
||||
|
||||
rdbbuf := make([]byte, syscall.MAXIMUM_REPARSE_DATA_BUFFER_SIZE)
|
||||
var bytesReturned uint32
|
||||
err = syscall.DeviceIoControl(h, syscall.FSCTL_GET_REPARSE_POINT, nil, 0, &rdbbuf[0], uint32(len(rdbbuf)), &bytesReturned, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
rdb := (*REPARSE_DATA_BUFFER)(unsafe.Pointer(&rdbbuf[0]))
|
||||
rb := (*GenericDataBuffer)(unsafe.Pointer(&rdb.DUMMYUNIONNAME))
|
||||
appExecLink := (*AppExecLinkReparseBuffer)(unsafe.Pointer(&rb.DataBuffer))
|
||||
if appExecLink.Version != 3 {
|
||||
return "", errors.New("unknown AppExecLink version")
|
||||
}
|
||||
return appExecLink.Path()
|
||||
}
|
||||
|
||||
var (
|
||||
advapi = syscall.NewLazyDLL("advapi32.dll")
|
||||
procGetAce = advapi.NewProc("GetAce")
|
||||
|
|
Loading…
Reference in a new issue