windows.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package ncwindows
  2. import (
  3. "io/ioutil"
  4. "log"
  5. "os"
  6. "github.com/gravitl/netmaker/netclient/ncutils"
  7. )
  8. // InitWindows - Initialize windows directory & files and such
  9. func InitWindows() {
  10. _, directoryErr := os.Stat(ncutils.GetNetclientPath()) // Check if data directory exists or not
  11. if os.IsNotExist(directoryErr) { // create a data directory
  12. os.Mkdir(ncutils.GetNetclientPath(), 0755)
  13. }
  14. wdPath, wdErr := os.Getwd() // get the current working directory
  15. if wdErr != nil {
  16. log.Fatal("failed to get current directory..")
  17. }
  18. _, dataNetclientErr := os.Stat(ncutils.GetNetclientPathSpecific() + "netclient.exe")
  19. _, currentNetclientErr := os.Stat(wdPath + "\\netclient.exe")
  20. if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata
  21. if currentNetclientErr == nil { // copy it if it exists locally
  22. input, err := ioutil.ReadFile(wdPath + "\\netclient.exe")
  23. if err != nil {
  24. log.Println("failed to find netclient.exe")
  25. return
  26. }
  27. if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"netclient.exe", input, 0644); err != nil {
  28. log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath())
  29. return
  30. }
  31. }
  32. }
  33. log.Println("Gravitl Netclient on Windows started")
  34. }