-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk_info.go
102 lines (86 loc) · 2.06 KB
/
disk_info.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
package main
import (
"fmt"
"strings"
"github.com/jaypipes/ghw"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
type DiskInfo struct {
Label string
Model string
Size uint64
MountPoint string
}
func (a *App) GetDiskInfo() []DiskInfo {
env := runtime.Environment(a.ctx)
block, err := ghw.Block()
if err != nil {
fmt.Printf("Error getting block storage info: %v", err)
return nil
}
var diskInfos []DiskInfo
for _, disk := range block.Disks {
if disk.IsRemovable {
for _, partition := range disk.Partitions {
var label string
var model string
if partition.FilesystemLabel != "" {
label = strings.TrimSpace(partition.FilesystemLabel)
}
if label == "" && partition.Label != "" {
label = strings.TrimSpace(partition.Label)
}
if label == "" && disk.Model != "" {
label = strings.TrimSpace(disk.Model)
}
if label == "" {
label = "Untitled"
}
if disk.Model != "" {
model = disk.Model
}
if model == "" {
model = "Unknown"
}
diskInfos = append(diskInfos, DiskInfo{
Label: label,
Model: model,
Size: partition.SizeBytes,
MountPoint: partition.MountPoint,
})
}
}
if env.BuildType == "dev" {
// In development mode, also add the test disk
for _, partition := range disk.Partitions {
var label string
var model string
if partition.FilesystemLabel != "" {
label = strings.TrimSpace(partition.FilesystemLabel)
}
if label == "" && partition.Label != "" {
label = strings.TrimSpace(partition.Label)
}
if label == "" && disk.Model != "" {
label = strings.TrimSpace(disk.Model)
}
if label != "FakeExternalDisk" {
continue // Skip non-Test disks in this section
}
if disk.Model != "" {
model = disk.Model
}
if model == "" {
model = "Unknown"
}
diskInfos = append(diskInfos, DiskInfo{
Label: label,
Model: model,
Size: partition.SizeBytes,
MountPoint: partition.MountPoint,
})
}
}
}
return diskInfos
}