/
main.go
157 lines (137 loc) · 4.13 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
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
package main
import (
"engineSync/buttons"
"engineSync/internal"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"image/color"
_ "modernc.org/sqlite"
"strings"
)
var engineLibraryDir string
var engineDbFiles []string
var soundSwitchProject string
var targetDevicePath string
var ignoreNonExistentTracks bool
var keepDirectoryStructure bool
var libraryButton *widget.Button
var soundSwitchButton *widget.Button
var targetDriveButton *widget.Button
var startSyncButton *widget.Button
var statusText *canvas.Text
var ignoreNonExistentTracksCheck *widget.Check
var keepDirectoryStructureCheck *widget.Check
var progress *widget.ProgressBar
var loader *widget.ProgressBarInfinite
func main() {
a := app.New()
w := a.NewWindow("engineSync")
w.Resize(fyne.NewSize(255, 280))
w.SetFixedSize(true)
statusText = canvas.NewText("Select Engine Library to start!", color.White)
statusText.Alignment = fyne.TextAlignCenter
progress = widget.NewProgressBar()
progress.Hide()
progress.Refresh()
loader = widget.NewProgressBarInfinite()
loader.Hide()
loader.Refresh()
startSyncButton = widget.NewButton("Start Sync!", func() {
buttons.OnSyncButtonClick(setLoading, func(current int) {
progress.Value = float64(current)
progress.Refresh()
}, setStatus, soundSwitchProject, targetDevicePath, engineLibraryDir, engineDbFiles, ignoreNonExistentTracks, keepDirectoryStructure)
})
startSyncButton.Disable()
targetDriveButton = widget.NewButton("Select Target Drive", func() {
buttons.OnTargetDriveButtonClick(setLoading, setStatus, func(path string) {
targetDevicePath = path
}, targetDriveButton)
})
targetDriveButton.Disable()
soundSwitchButton = widget.NewButton("Select SoundSwitch Project (Optional)", func() {
buttons.OnSoundSwitchButtonClick(setLoading, setStatus, func(path string) {
soundSwitchProject = path
}, soundSwitchButton)
})
soundSwitchButton.Disable()
libraryButton = widget.NewButton("Select Engine Library Backup", func() {
buttons.OnLibraryButtonClick(setLoading, setStatus, func(files []string) {
engineDbFiles = files
}, func(path string) {
engineLibraryDir = path
}, libraryButton)
})
ignoreNonExistentTracksCheck = widget.NewCheck("Ignore Missing Tracks", func(value bool) {
ignoreNonExistentTracks = value
})
keepDirectoryStructureCheck = widget.NewCheck("Keep directory structure", func(value bool) {
keepDirectoryStructure = value
})
w.SetContent(container.NewVBox(
layout.NewSpacer(),
statusText,
layout.NewSpacer(),
libraryButton,
soundSwitchButton,
targetDriveButton,
container.New(layout.NewCenterLayout(), container.NewVBox(
ignoreNonExistentTracksCheck,
keepDirectoryStructureCheck,
)),
layout.NewSpacer(),
startSyncButton,
layout.NewSpacer(),
container.NewVBox(
progress,
loader,
),
layout.NewSpacer(),
))
w.ShowAndRun()
}
func setStatus(status string, color color.RGBA) {
statusText.Color = color
statusText.Text = status
statusText.Refresh()
}
func setLoading(loading bool, infinite bool, current int, total int) {
if loading {
if infinite {
internal.HideProgressBar(progress)
internal.ShowLoader(loader)
} else {
internal.HideLoader(loader)
internal.ShowProgressBar(progress, total, current)
}
setStatus("Loading...", color.RGBA{R: 255, G: 255, B: 255, A: 255})
libraryButton.Disable()
soundSwitchButton.Disable()
targetDriveButton.Disable()
ignoreNonExistentTracksCheck.Disable()
keepDirectoryStructureCheck.Disable()
startSyncButton.Disable()
} else {
internal.HideProgressBar(progress)
internal.HideLoader(loader)
setStatus("Ready!", color.RGBA{R: 255, G: 255, B: 255, A: 255})
ignoreNonExistentTracksCheck.Enable()
keepDirectoryStructureCheck.Enable()
if !(engineDbFiles != nil && !(len(engineDbFiles) <= 0) || len(engineLibraryDir) <= 0) {
libraryButton.Enable()
} else {
if len(soundSwitchProject) <= 0 && !strings.HasSuffix(soundSwitchProject, ".ssproj") {
soundSwitchButton.Enable()
}
if len(targetDevicePath) <= 0 {
targetDriveButton.Enable()
} else {
startSyncButton.Enable()
}
}
}
}