Skip to content

Commit

Permalink
enhance GUI to accept filename for file processing and display content
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrust committed Dec 27, 2024
1 parent eb1c7d4 commit 2c5f017
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/iffmaster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
)

func main() {
var filename string

showVersion := flag.Bool("version", false, "Display the version of iffmaster")
flag.Parse()

Expand All @@ -30,10 +32,8 @@ func main() {
}

if flag.NArg() > 0 {
//filename := flag.Arg(0)
//fmt.Println("Filename provided:", filename)
// You can add code here to handle the filename, e.g., open the file
} else {
gui.OpenGUI(Version)
filename = flag.Arg(0)
}

gui.OpenGUI(filename, Version)
}
33 changes: 31 additions & 2 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package gui
import (
"bytes"
"io"
"log"
"os"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
Expand Down Expand Up @@ -36,8 +38,10 @@ type AppData struct {
structTableView *widget.Table
}

// OpenGUI layouts the main window and opens it
func OpenGUI(version string) {
// OpenGUI layouts the main window and opens it.
// If a filename is given, it reads the file and displays its content.
// The version string is used to display the version of the application.
func OpenGUI(filename string, version string) {
var appData AppData
var fileDlg *dialog.FileDialog

Expand Down Expand Up @@ -110,5 +114,30 @@ func OpenGUI(version string) {
appData.win.SetContent(appData.topContainer)

appData.win.Resize(fyne.NewSize(800, 600))

readFileName(&appData, filename)

appData.win.ShowAndRun()
}

// readFileName reads the file with the given filename and displays its content.
// If the filename is empty, it does nothing.
func readFileName(appData *AppData, filename string) {
log.Print("readFileName: ", filename)
if filename != "" {
data, err := os.ReadFile(filename)
if err != nil {
dialog.ShowError(err, appData.win)
return
}

appData.chunks, err = chunks.ReadIFFFile(bytes.NewReader(data), int64(len(data)))
if err != nil {
dialog.ShowError(err, appData.win)
return
}

appData.nodeList = ConvertIFFChunkToListNode(appData.chunks)
appData.topContainer.Refresh()
}
}

0 comments on commit 2c5f017

Please sign in to comment.