From b1247d2d0d51108c910a73891ff3116e5f032ab1 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Sat, 12 Jan 2019 18:39:45 +0100 Subject: [pkg] all your deps are vendored to us --- .../ProtonMail/go-autostart/autostart_windows.go | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 vendor/github.com/ProtonMail/go-autostart/autostart_windows.go (limited to 'vendor/github.com/ProtonMail/go-autostart/autostart_windows.go') diff --git a/vendor/github.com/ProtonMail/go-autostart/autostart_windows.go b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.go new file mode 100644 index 0000000..3c14609 --- /dev/null +++ b/vendor/github.com/ProtonMail/go-autostart/autostart_windows.go @@ -0,0 +1,52 @@ +package autostart + +// #cgo LDFLAGS: -lole32 -luuid +/* +#define WIN32_LEAN_AND_MEAN +#include +#include + +uint64_t CreateShortcut(char *shortcutA, char *path, char *args); +*/ +import "C" + +import ( + "errors" + "fmt" + "os" + "path/filepath" + "strings" +) + +var startupDir string + +func init() { + startupDir = filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Startup") +} + +func (a *App) path() string { + return filepath.Join(startupDir, a.Name+".lnk") +} + +func (a *App) IsEnabled() bool { + _, err := os.Stat(a.path()) + return err == nil +} + +func (a *App) Enable() error { + path := a.Exec[0] + args := strings.Join(a.Exec[1:], " ") + + if err := os.MkdirAll(startupDir, 0777); err != nil { + return err + } + res := C.CreateShortcut(C.CString(a.path()), C.CString(path), C.CString(args)) + if res != 0 { + return errors.New(fmt.Sprintf("autostart: cannot create shortcut '%s' error code: 0x%.8x", a.path(), res)) + } + return nil +} + +func (a *App) Disable() error { + return os.Remove(a.path()) +} -- cgit v1.2.3