Fixup
This commit is contained in:
parent
52e7626a3e
commit
d9fde32e34
|
@ -0,0 +1,4 @@
|
||||||
|
build_logs
|
||||||
|
go.mod
|
||||||
|
go.sum
|
||||||
|
.DS_store
|
|
@ -1,66 +0,0 @@
|
||||||
//go:build windows
|
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"golang.org/x/sys/windows/registry"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Ensure we install and configure on first run
|
|
||||||
ensureInstallation()
|
|
||||||
ensureStartup()
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureInstallation() {
|
|
||||||
targetPath := filepath.Join(os.Getenv("ProgramFiles"), "AE-Send", "ae-send.exe")
|
|
||||||
currentPath, _ := os.Executable()
|
|
||||||
|
|
||||||
if currentPath != targetPath {
|
|
||||||
if err := os.MkdirAll(filepath.Dir(targetPath), 0755); err != nil {
|
|
||||||
return // handle error
|
|
||||||
}
|
|
||||||
if err := copyFile(currentPath, targetPath); err != nil {
|
|
||||||
return // handle error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch new instance
|
|
||||||
cmd := exec.Command(targetPath)
|
|
||||||
cmd.Start()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureStartup() {
|
|
||||||
key, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Run`, registry.SET_VALUE)
|
|
||||||
if err != nil {
|
|
||||||
return // handle error
|
|
||||||
}
|
|
||||||
defer key.Close()
|
|
||||||
|
|
||||||
currentPath, _ := os.Executable()
|
|
||||||
key.SetStringValue("AE-Send", currentPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyFile(src, dst string) error {
|
|
||||||
in, err := os.Open(src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
out, err := os.Create(dst)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
_, err = io.Copy(out, in)
|
|
||||||
return err
|
|
||||||
}
|
|
Loading…
Reference in New Issue