netmaker/netclient/ncwindows/windows.go

39 lines
1.2 KiB
Go
Raw Normal View History

2021-08-31 03:58:23 +08:00
package ncwindows
import (
"io/ioutil"
"log"
"os"
2021-09-20 02:03:47 +08:00
"github.com/gravitl/netmaker/netclient/ncutils"
2021-08-31 03:58:23 +08:00
)
2021-10-09 03:07:12 +08:00
// InitWindows - Initialize windows directory & files and such
2021-08-31 03:58:23 +08:00
func InitWindows() {
2021-09-20 02:03:47 +08:00
_, directoryErr := os.Stat(ncutils.GetNetclientPath()) // Check if data directory exists or not
if os.IsNotExist(directoryErr) { // create a data directory
os.Mkdir(ncutils.GetNetclientPath(), 0755)
2021-08-31 03:58:23 +08:00
}
wdPath, wdErr := os.Getwd() // get the current working directory
if wdErr != nil {
log.Fatal("failed to get current directory..")
}
2021-09-20 02:03:47 +08:00
_, dataNetclientErr := os.Stat(ncutils.GetNetclientPathSpecific() + "netclient.exe")
2021-08-31 03:58:23 +08:00
_, currentNetclientErr := os.Stat(wdPath + "\\netclient.exe")
if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata
if currentNetclientErr == nil { // copy it if it exists locally
input, err := ioutil.ReadFile(wdPath + "\\netclient.exe")
if err != nil {
log.Println("failed to find netclient.exe")
return
}
2021-09-20 02:03:47 +08:00
if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"netclient.exe", input, 0644); err != nil {
log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath())
2021-08-31 03:58:23 +08:00
return
}
}
}
log.Println("Gravitl Netclient on Windows started")
}