-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.go
More file actions
66 lines (57 loc) · 1.02 KB
/
models.go
File metadata and controls
66 lines (57 loc) · 1.02 KB
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
package main
import (
"fmt"
"golang.org/x/sys/windows/registry"
"strings"
)
type RegistryType int
const (
RegString RegistryType = iota
RegDWord
)
type Setting struct {
Name string
DefaultValue interface{}
CurrentValue interface{}
Type RegistryType
IsChecked bool
IsDifferent bool
}
type Session struct {
EncodedName string
DisplayName string
}
func (s *Setting) GetDefaultValueString() string {
switch v := s.DefaultValue.(type) {
case string:
return sanitizeString(v)
case uint32:
return fmt.Sprintf("%d", v)
default:
return ""
}
}
func (s *Setting) GetCurrentValueString() string {
switch v := s.CurrentValue.(type) {
case string:
return sanitizeString(v)
case uint32:
return fmt.Sprintf("%d", v)
default:
return ""
}
}
func sanitizeString(s string) string {
return strings.Map(func(r rune) rune {
if r == 0 {
return -1
}
return r
}, s)
}
func regTypeToRegistryType(regType uint32) RegistryType {
if regType == registry.DWORD {
return RegDWord
}
return RegString
}