Files
navi/internal/update/store_windows.go
T
2026-08-01 14:12:30 +03:00

50 lines
963 B
Go

//go:build windows
package update
import (
"sync"
"unsafe"
"golang.org/x/sys/windows"
)
const (
appModelErrorNoPackage = 15700 // APPMODEL_ERROR_NO_PACKAGE
errorInsufficientBuffer = 122 // ERROR_INSUFFICIENT_BUFFER
)
var (
storeOnce sync.Once
storePackaged bool
)
// IsStorePackaged reports whether this process has an MSIX / Store package identity.
// Store builds must not self-update (Store owns updates).
func IsStorePackaged() bool {
storeOnce.Do(func() {
storePackaged = detectStorePackage()
})
return storePackaged
}
func detectStorePackage() bool {
mod := windows.NewLazySystemDLL("kernel32.dll")
proc := mod.NewProc("GetCurrentPackageFullName")
if err := proc.Find(); err != nil {
return false
}
var n uint32
r, _, _ := proc.Call(uintptr(unsafe.Pointer(&n)), 0)
switch r {
case appModelErrorNoPackage:
return false
case errorInsufficientBuffer:
return true
case 0:
return n > 0
default:
return false
}
}