mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-29 23:22:45 +00:00
0884f89431
* start pulling out + replacing urfave and config * replace many many instances of config * move more stuff => viper * properly remove urfave * move some flags to root command * add testrig commands to root * alias config file keys * start adding cli parsing tests * reorder viper init * remove config path alias * fmt * change config file keys to non-nested * we're more or less in business now * tidy up the common func * go fmt * get tests passing again * add note about the cliparsing tests * reorganize * update docs with changes * structure cmd dir better * rename + move some files around * fix dangling comma
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
// +build windows
|
|
// +build go1.4
|
|
|
|
package mousetrap
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) {
|
|
snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer syscall.CloseHandle(snapshot)
|
|
var procEntry syscall.ProcessEntry32
|
|
procEntry.Size = uint32(unsafe.Sizeof(procEntry))
|
|
if err = syscall.Process32First(snapshot, &procEntry); err != nil {
|
|
return nil, err
|
|
}
|
|
for {
|
|
if procEntry.ProcessID == uint32(pid) {
|
|
return &procEntry, nil
|
|
}
|
|
err = syscall.Process32Next(snapshot, &procEntry)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
|
|
// StartedByExplorer returns true if the program was invoked by the user double-clicking
|
|
// on the executable from explorer.exe
|
|
//
|
|
// It is conservative and returns false if any of the internal calls fail.
|
|
// It does not guarantee that the program was run from a terminal. It only can tell you
|
|
// whether it was launched from explorer.exe
|
|
func StartedByExplorer() bool {
|
|
pe, err := getProcessEntry(os.Getppid())
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:])
|
|
}
|