Initial commit
This commit is contained in:
19
cmd/win/root.go
Normal file
19
cmd/win/root.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package win
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "wingoutil",
|
||||||
|
Short: "DeveloperDurp's Windows Utility - Install Programs, Tweaks, Fixes, and Updates",
|
||||||
|
Long: `DeveloperDurp's Windows Utility - Install Programs, Tweaks, Fixes, and Updates (Inspired by Chris Titus Tech's winutil)`,
|
||||||
|
}
|
||||||
|
|
||||||
|
func Execute() error {
|
||||||
|
err := rootCmd.Execute()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
24
main.go
Normal file
24
main.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"gitlab.com/developerdurp/wingotil/pkg/ostype"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
os, err := ostype.GetOsType()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch os.(type) {
|
||||||
|
case *ostype.WinVer:
|
||||||
|
fmt.Println("Windows")
|
||||||
|
case *ostype.LinVer:
|
||||||
|
fmt.Println("Linux")
|
||||||
|
default:
|
||||||
|
fmt.Println("unable to detect OS version")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
pkg/ostype/os.go
Normal file
63
pkg/ostype/os.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package ostype
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"golang.org/x/sys/windows/registry"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WinVer struct {
|
||||||
|
CurrentVersion string
|
||||||
|
ProductName string
|
||||||
|
}
|
||||||
|
type LinVer struct {
|
||||||
|
Distro string
|
||||||
|
LinuxVersion string
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetOsType() (interface{}, error) {
|
||||||
|
|
||||||
|
os := runtime.GOOS
|
||||||
|
switch os {
|
||||||
|
case "windows":
|
||||||
|
|
||||||
|
winVer, err := GetWinVersion()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("Unable to detect Windows Version")
|
||||||
|
}
|
||||||
|
|
||||||
|
return winVer, nil
|
||||||
|
|
||||||
|
case "darwin":
|
||||||
|
return nil, nil
|
||||||
|
case "linux":
|
||||||
|
return nil, nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("Unable to detect OS")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWinVersion() (*WinVer, error) {
|
||||||
|
|
||||||
|
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer k.Close()
|
||||||
|
|
||||||
|
currentVersion, _, err := k.GetStringValue("CurrentVersion")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
productName, _, err := k.GetStringValue("ProductName")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
version := &WinVer{
|
||||||
|
CurrentVersion: currentVersion,
|
||||||
|
ProductName: productName,
|
||||||
|
}
|
||||||
|
return version, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user