-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
113 lines (97 loc) · 2.98 KB
/
main.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
package main
import (
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"
flag "github.com/spf13/pflag"
"github.com/JoshuaDoes/menuify"
"github.com/JoshuaDoes/menuify/screens/ncurses"
)
var (
workingDir string //where the menu should treat as its working directory
configFile string //path to menu configuration
keyCalibrationFile string //path to keyboard calibration, can be written for embedded devices or generated by first run calibrator
menu *menuify.Menu //holds the context of the text menu engine
screen *ncurses.MenuScreen_Ncurses //interfaces with the actual terminal window
SOURCEIMG *WIM
SOURCEIDX int
SOURCES []*WIM
)
func init() {
//Apply all command-line flags
flag.StringVar(&workingDir, "workingDir", "", "path to treat as working directory")
flag.StringVar(&configFile, "menu", "", "path to menu configuration")
flag.StringVar(&keyCalibrationFile, "keyCalibration", "", "path to keyboard calibration, generated by calibrator if not present")
flag.Parse()
if workingDir == "" {
workingDir, _ = os.Getwd()
}
if configFile == "" {
configFile = workingDir + "/menu.json"
}
if keyCalibrationFile == "" {
keyCalibrationFile = workingDir + "/keyCalibration.json"
}
menu = menuify.NewMenu()
if err := menu.Load(configFile); err != nil {
panic(fmt.Sprintf("error loading menu config: %v", err))
}
screen = ncurses.NewMenuScreenNcurses(menu)
if screen == nil {
panic(fmt.Sprintf("error initializing screen, is nil?"))
}
menu.SetScreen(screen)
SOURCES = make([]*WIM, 0)
}
func main() {
if err := menu.Engine.Calibrate(keyCalibrationFile); err != nil {
menuify.ScreenPrintf(screen, "Error calibrating: %v\n", err)
return //Allows ncurses to gracefully exit
}
screen.Clear()
wims, _ := WalkMatch("sources", "*.*")
if len(wims) > 0 {
for i := 0; i < len(wims); i++ {
wiminfo, err := WIMInfo(wims[i])
if err == nil { //We only want valid WIM and ESD files that don't fail to parse
SOURCES = append(SOURCES, wiminfo)
}
}
} else {
menu.Engine.ErrorText("No install sources are available!", "")
return
}
menu.Engine.Hook("install-select_wim", hookInstallSelectWim)
menu.Engine.Hook("install-select_edition", hookInstallSelectEdition)
menu.Engine.Hook("install-select_disk", hookInstallSelectDisk)
menu.Engine.Hook("install-windows-confirmation", hookInstallWindowsConfirmation)
menu.Engine.Hook("install-windows", hookInstallWindows)
menu.Engine.Home()
menu.Engine.BindKeys()
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT)
<-sc
}
func WalkMatch(root, pattern string) ([]string, error) {
var matches []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
if matched, err := filepath.Match(pattern, filepath.Base(path)); err != nil {
return err
} else if matched {
matches = append(matches, path)
}
return nil
})
if err != nil {
return nil, err
}
return matches, nil
}