Show update file names when selected in itgui

This commit is contained in:
Elara 2021-10-07 13:38:13 -07:00
parent 843e369bab
commit b15cbb6349
2 changed files with 17 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net" "net"
"path/filepath"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
@ -18,11 +19,12 @@ import (
func upgradeTab(parent fyne.Window) *fyne.Container { func upgradeTab(parent fyne.Window) *fyne.Container {
var ( var (
archivePath string archivePath string
fiwmarePath string firmwarePath string
initPktPath string initPktPath string
) )
var archiveBtn *widget.Button
// Create archive selection dialog // Create archive selection dialog
archiveDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { archiveDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
if e != nil || uc == nil { if e != nil || uc == nil {
@ -30,25 +32,29 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
} }
uc.Close() uc.Close()
archivePath = uc.URI().Path() archivePath = uc.URI().Path()
archiveBtn.SetText(fmt.Sprintf("Select archive (.zip) [%s]", filepath.Base(archivePath)))
}, parent) }, parent)
// Limit dialog to .zip files // Limit dialog to .zip files
archiveDialog.SetFilter(storage.NewExtensionFileFilter([]string{".zip"})) archiveDialog.SetFilter(storage.NewExtensionFileFilter([]string{".zip"}))
// Create button to show dialog // Create button to show dialog
archiveBtn := widget.NewButton("Select archive (.zip)", archiveDialog.Show) archiveBtn = widget.NewButton("Select archive (.zip)", archiveDialog.Show)
var firmwareBtn *widget.Button
// Create firmware selection dialog // Create firmware selection dialog
firmwareDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { firmwareDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
if e != nil || uc == nil { if e != nil || uc == nil {
return return
} }
uc.Close() uc.Close()
fiwmarePath = uc.URI().Path() firmwarePath = uc.URI().Path()
firmwareBtn.SetText(fmt.Sprintf("Select firmware (.bin) [%s]", filepath.Base(firmwarePath)))
}, parent) }, parent)
// Limit dialog to .bin files // Limit dialog to .bin files
firmwareDialog.SetFilter(storage.NewExtensionFileFilter([]string{".bin"})) firmwareDialog.SetFilter(storage.NewExtensionFileFilter([]string{".bin"}))
// Create button to show dialog // Create button to show dialog
firmwareBtn := widget.NewButton("Select init packet (.bin)", firmwareDialog.Show) firmwareBtn = widget.NewButton("Select firmware (.bin)", firmwareDialog.Show)
var initPktBtn *widget.Button
// Create init packet selection dialog // Create init packet selection dialog
initPktDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { initPktDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) {
if e != nil || uc == nil { if e != nil || uc == nil {
@ -56,11 +62,12 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
} }
uc.Close() uc.Close()
initPktPath = uc.URI().Path() initPktPath = uc.URI().Path()
initPktBtn.SetText(fmt.Sprintf("Select init packet (.dat) [%s]", filepath.Base(initPktPath)))
}, parent) }, parent)
// Limit dialog to .dat files // Limit dialog to .dat files
initPktDialog.SetFilter(storage.NewExtensionFileFilter([]string{".dat"})) initPktDialog.SetFilter(storage.NewExtensionFileFilter([]string{".dat"}))
// Create button to show dialog // Create button to show dialog
initPktBtn := widget.NewButton("Select init packet (.dat)", initPktDialog.Show) initPktBtn = widget.NewButton("Select init packet (.dat)", initPktDialog.Show)
// Hide init packet and firmware buttons // Hide init packet and firmware buttons
initPktBtn.Hide() initPktBtn.Hide()
@ -91,7 +98,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
startBtn := widget.NewButton("Start", func() { startBtn := widget.NewButton("Start", func() {
// If archive path does not exist and both init packet and firmware paths // If archive path does not exist and both init packet and firmware paths
// also do not exist, return error // also do not exist, return error
if archivePath == "" && (initPktPath == "" && fiwmarePath == "") { if archivePath == "" && (initPktPath == "" && firmwarePath == "") {
guiErr(nil, "Upgrade requires archive or files selected", false, parent) guiErr(nil, "Upgrade requires archive or files selected", false, parent)
return return
} }
@ -119,7 +126,7 @@ func upgradeTab(parent fyne.Window) *fyne.Container {
files = append(files, archivePath) files = append(files, archivePath)
case "Files": case "Files":
fwUpgType = types.UpgradeTypeFiles fwUpgType = types.UpgradeTypeFiles
files = append(files, initPktPath, fiwmarePath) files = append(files, initPktPath, firmwarePath)
} }
// Dial itd UNIX socket // Dial itd UNIX socket

View File

@ -36,7 +36,7 @@ import (
) )
func startSocket(dev *infinitime.Device) error { func startSocket(dev *infinitime.Device) error {
// Make socket directory if non-existent // Make socket directory if non-existant
err := os.MkdirAll(filepath.Dir(viper.GetString("socket.path")), 0755) err := os.MkdirAll(filepath.Dir(viper.GetString("socket.path")), 0755)
if err != nil { if err != nil {
return err return err