100 lines
2.8 KiB
Go
100 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/app"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/dialog"
|
|
"fyne.io/fyne/v2/widget"
|
|
"fyne.io/fyne/v2/layout"
|
|
)
|
|
|
|
func main() {
|
|
a := app.New()
|
|
w := a.NewWindow("Upload 3 Files")
|
|
w.Resize(fyne.NewSize(800, 400))
|
|
|
|
var file1Path, file2Path, file3Path string
|
|
|
|
// Labels to show selected filenames
|
|
fileLabel1 := widget.NewLabel("No file selected")
|
|
fileLabel2 := widget.NewLabel("No file selected")
|
|
fileLabel3 := widget.NewLabel("No file selected")
|
|
|
|
// Button 1
|
|
btn1 := widget.NewButton("Upload Certificate Private Key File", func() {
|
|
dialog.ShowFileOpen(func(r fyne.URIReadCloser, err error) {
|
|
if r != nil {
|
|
fileLabel1.SetText(r.URI().Name())
|
|
file1Path = r.URI().Path()
|
|
}
|
|
}, w)
|
|
})
|
|
|
|
// Button 2
|
|
btn2 := widget.NewButton("Upload Certificate File", func() {
|
|
dialog.ShowFileOpen(func(r fyne.URIReadCloser, err error) {
|
|
if r != nil {
|
|
fileLabel2.SetText(r.URI().Name())
|
|
file2Path = r.URI().Path()
|
|
}
|
|
}, w)
|
|
})
|
|
|
|
// Button 3
|
|
btn3 := widget.NewButton("Upload Certificate Intermediate File", func() {
|
|
dialog.ShowFileOpen(func(r fyne.URIReadCloser, err error) {
|
|
if r != nil {
|
|
fileLabel3.SetText(r.URI().Name())
|
|
file3Path = r.URI().Path()
|
|
}
|
|
}, w)
|
|
})
|
|
|
|
goBtn := widget.NewButton("Go", func() {
|
|
fmt.Println("Go button clicked")
|
|
files := []string{file1Path, file2Path, file3Path}
|
|
|
|
allPresent := true
|
|
for _, f := range files {
|
|
if f == "" {
|
|
allPresent = false
|
|
break
|
|
}
|
|
}
|
|
|
|
if !allPresent {
|
|
fmt.Println("One or more files missing!")
|
|
return
|
|
}
|
|
|
|
for i, f := range files {
|
|
data, err := os.ReadFile(f)
|
|
if err != nil {
|
|
fmt.Printf("Error reading file %d (%s): %v\n", i+1, f, err)
|
|
continue
|
|
}
|
|
|
|
fmt.Printf("Contents of file %d (%s):\n%s\n\n", i+1, f, string(data))
|
|
}
|
|
})
|
|
|
|
content := container.NewBorder(
|
|
nil, // top
|
|
goBtn, // bottom
|
|
nil, nil, // left, right
|
|
container.NewVBox( // center content
|
|
widget.NewLabel("Select 3 files:"),
|
|
container.NewHBox(btn1, fileLabel1),
|
|
container.NewHBox(btn2, fileLabel2),
|
|
container.NewHBox(btn3, fileLabel3),
|
|
layout.NewSpacer(), // adds flexible space
|
|
),
|
|
)
|
|
|
|
w.SetContent(content)
|
|
w.ShowAndRun()
|
|
}
|