-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
204 lines (190 loc) · 5.5 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package main
import (
"context"
"fmt"
"github.com/wailsapp/wails/v2/pkg/runtime"
"golang.org/x/sys/windows/registry"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
"syscall"
)
// App struct
type App struct {
ctx context.Context
}
type DeviceOverviewData struct {
Model string
Arch int
DeviceName string
CPUName string
GPUList []Device
RamSize int64
RamType int
SystemPartition []DrivePartition
}
type DrivePartition struct {
Label string
Letter string
Size int64
FreeSpace int64
Type int
isBootable bool
isPageFile bool
isCrashDump bool
isRecovery bool
isEFI bool
FSType int
}
type AllDeviceTypes struct {
Audio []Device `json:"audio"`
Apos []Device `json:"apos"`
Battery []Device `json:"battery"`
Biometric []Device `json:"biometric"`
Bluetooth []Device `json:"bluetooth"`
Camera []Device `json:"camera"`
Pc []Device `json:"pc"`
Drive []Device `json:"drive"`
Gpu []Device `json:"gpu"`
Firmware []Device `json:"firmware"`
Hid []Device `json:"hid"`
Keyboard []Device `json:"keyboard"`
Mouse []Device `json:"mouse"`
Display []Device `json:"display"`
Network []Device `json:"network"`
Printq []Device `json:"printq"`
Cpu []Device `json:"cpu"`
Secure []Device `json:"secure"`
Softwarecomponents []Device `json:"softwarecomponents"`
Softwaredevices []Device `json:"softwaredevices"`
Sound []Device `json:"sound"`
Memoryc []Device `json:"memoryc"`
Sysdev []Device `json:"sysdev"`
Usbc []Device `json:"usbc"`
Usbmgr []Device `json:"usbmgr"`
}
type Device struct {
Name string
Size int64
SerialNumber string
Manufacturer string
MediaType string
ConfigManagerErrorCode uint32
Model string
Status string
Description string
DeviceID string
MPU401Address uint32
PNPDeviceID string
TimeOnBattery uint32
TimeToFullCharge uint32
SmartBatteryVersion string
EstimatedChargeRemaining uint16
EstimatedRunTime uint32
ExpectedBatteryLife uint32
ExpectedLife uint32
FullChargeCapacity uint32
MaxRechargeTime uint32
DesignCapacity uint32
DesignVoltage uint64
BatteryRechargeTime uint32
BatteryStatus uint16
Chemistry uint16
}
type Win32_PNPDevice struct {
Description string
Name string
Status string
ConfigManagerErrorCode uint32
DeviceID string
PNPDeviceID string
Manufacturer string
PNPClass string
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
log.Fatal(err)
}
defer k.Close()
cb, _, err := k.GetStringValue("CurrentBuild")
if err != nil {
log.Fatal(err)
}
cbi, err := strconv.Atoi(cb)
if err != nil {
// ... handle error
panic(err)
}
if cbi < 22000 {
runtime.Quit(ctx)
vbscript := `
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Set colOS = objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objOS in colOS
If CInt(objOS.BuildNumber) < 22000 Then
MsgBox "Oops... This app can be run only on Windows 11. Update your system and try again.", vbCritical, "Device Manager"
End If
Next
`
vbsFile, err := ioutil.TempFile("", "dvmgrosbt*.vbs")
if err != nil {
fmt.Println("error when creation temporarily script file:", err)
return
}
defer os.Remove(vbsFile.Name())
_, err = vbsFile.Write([]byte(vbscript))
if err != nil {
fmt.Println("write err", err)
return
}
vbsFile.Close()
cmd := exec.Command("wscript", vbsFile.Name())
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
err = cmd.Run()
if err != nil {
fmt.Println("error message exec", err)
return
}
}
}
func (a *App) GetAllDevicesList() AllDeviceTypes {
var devices AllDeviceTypes
devices.Audio = GetAudioDevices()
devices.Apos = GetAPODevices()
devices.Battery = GetBatteriesDevices()
devices.Biometric = GetBiometricDevices()
devices.Bluetooth = GetBluetoothDevices()
devices.Camera = GetCameraDevices()
devices.Pc = GetPCDevices()
devices.Drive = GetDriveDevices()
devices.Gpu = GetGPUDevices()
devices.Firmware = GetFirmwareDevices()
devices.Hid = GetHIDDevices()
devices.Keyboard = GetKeyboardsDevices()
devices.Mouse = GetMiceDevices()
devices.Display = GetDisplayDevices()
devices.Network = GetNetworkDevices()
devices.Printq = GetPrintQDevices()
devices.Cpu = GetCPUDevices()
devices.Secure = GetSecureDevices()
devices.Softwarecomponents = GetSoftwareComponentsDevices()
devices.Softwaredevices = GetSoftwareDevices()
devices.Sound = GetSVGCDevices()
devices.Memoryc = GetStorageControllersDevices()
devices.Sysdev = GetSystemDevices()
devices.Usbc = GetUSBControllersDevices()
devices.Usbmgr = GetUSBManagersDevices()
return devices
}