Skip to content

Commit

Permalink
feat: support updating package list after build
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
  • Loading branch information
Ryex committed Sep 29, 2024
1 parent f22a60f commit 4ae2473
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 299 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/schollz/progressbar/v3 v3.16.0
github.com/sirupsen/logrus v1.9.3
github.com/snowzach/rotatefilehook v0.0.0-20220211133110-53752135082d
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef
github.com/sunshineplan/imgconv v1.1.11
Expand Down Expand Up @@ -43,7 +44,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rymdport/portal v0.2.6 // indirect
github.com/snowzach/rotatefilehook v0.0.0-20220211133110-53752135082d // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/sunshineplan/pdf v1.0.7 // indirect
github.com/yuin/goldmark v1.7.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (ctx *Context) LoadPkg(path string) error {
return err
}
} else {
err := ctx.Pkg.LoadFromPackedPath(ctx.InputPath)
err := ctx.Pkg.LoadFromPackedPath(ctx.InputPath, nil)
if err != nil {
ctx.Log.WithError(err).Error("failed to load package")
return err
Expand Down
10 changes: 6 additions & 4 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ func (gtc *GenTumbCmd) Run(ctx *Context) error {
return err
}

err = pkg.BuildFileList()
if err != nil {
l.WithError(err).Error("could not build file list")
return err
errs := pkg.BuildFileList()
if len(errs) != 0 {
for _, err := range errs {
l.WithField("task", "build file list").Errorf("error: %s", err.Error())
}
return errors.New("Failed to build file list")
}

err = pkg.GenerateThumbnails()
Expand Down
19 changes: 9 additions & 10 deletions internal/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,25 @@ func (lsf *ListFilesCmd) printTree(l logrus.FieldLogger, pkg *ddpackage.Package)
}
}
fileList := pkg.FileList()
for i := 0; i < len(fileList); i++ {
info := &fileList[i]
if info.IsMetadata() && !lsf.All {
for i, fi := range fileList {
if fi.IsMetadata() && !lsf.All {
continue
}
if info.IsTexture() && (!lsf.Textures && !lsf.All) {
if fi.IsTexture() && (!lsf.Textures && !lsf.All) {
continue
}
if info.IsThumbnail() && (!lsf.Thumbnails && !lsf.All) {
if fi.IsThumbnail() && (!lsf.Thumbnails && !lsf.All) {
continue
}
if info.IsData() && (!lsf.Data && !lsf.All) {
if fi.IsData() && (!lsf.Data && !lsf.All) {
continue
}
path := pkg.NormalizeResourcePath(info.ResPath)
l.WithField("res", info.ResPath).
WithField("size", info.Size).
path := pkg.NormalizeResourcePath(fi.ResPath)
l.WithField("res", fi.ResPath).
WithField("size", fi.Size).
WithField("index", i).
Trace("building tree node")
nodeForPath(path, info)
nodeForPath(path, fi)
}

fmt.Println(tree.String())
Expand Down
10 changes: 6 additions & 4 deletions internal/cmd/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ func (pc *PackCmd) Run(ctx *Context) error {
return err
}

err = pkg.BuildFileList()
if err != nil {
l.WithError(err).Error("could not build file list")
return err
errs := pkg.BuildFileList()
if len(errs) != 0 {
for _, err := range errs {
l.WithField("task", "build file list").Errorf("err: %s", err.Error())
}
return errors.New("Failed to build file list")
}

bar := progressbar.Default(100, "Packing ...")
Expand Down
6 changes: 3 additions & 3 deletions internal/gui/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewPackJSONDialogPkg(
if dlg.Version == "" {
dlg.Version = "1"
}
dlg.buildUi()
dlg.buildUI()
return dlg
}

Expand All @@ -97,11 +97,11 @@ func NewPackJSONDialog(
ColorOverrides: structures.DefaultCustomColorOverrides(),
editable: true,
}
dlg.buildUi()
dlg.buildUI()
return dlg
}

func (dlg *PackJSONDialog) buildUi() {
func (dlg *PackJSONDialog) buildUI() {
IDLbl := widget.NewLabel(lang.X("packJson.id.label", "ID"))
IDEntry := widget.NewEntryWithData(binding.BindString(&dlg.ID))

Expand Down
35 changes: 20 additions & 15 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ func (a *App) setupPathHandler() {
if err != nil {
log.WithError(err).Errorf("can not stat path %s", path)
a.setErrContent(
err,
lang.X(
"err.badPath",
"Can not open \"{{.Path}}\"",
map[string]any{
"Path": path,
},
),
err,
)
return
}
Expand All @@ -258,24 +258,26 @@ func (a *App) setupPathHandler() {
})
}

func (a *App) setErrContent(err error, msg string) {
func (a *App) setErrContent(msg string, errs ...error) {
msgText := canvas.NewText(msg, theme.Color(theme.ColorNameForeground))
msgText.TextSize = 16
msgText.Alignment = fyne.TextAlignCenter

errText := multilineCanvasText(
err.Error(),
14,
fyne.TextStyle{Italic: true},
fyne.TextAlignCenter,
theme.Color(theme.ColorNameError),
)
errContainer := container.NewVBox()
for i, err := range errs {
errText := multilineCanvasText(
fmt.Sprintf("%d) ", i)+err.Error(),
12,
fyne.TextStyle{Italic: true},
fyne.TextAlignLeading,
theme.Color(theme.ColorNameError),
)
errContainer.Add(errText)
}

msgContent := container.NewVBox(
layout.NewSpacer(),
msgContent := container.NewCenter(
msgText,
errText,
layout.NewSpacer(),
container.NewScroll(errContainer),
)

a.setMainContent(msgContent)
Expand All @@ -302,7 +304,7 @@ func multilineCanvasText(
return content
}

func (a *App) setWaitContent(msg string) binding.String {
func (a *App) setWaitContent(msg string) (binding.Float, binding.String) {
activity := widget.NewActivity()
activity.Start()
msgText := canvas.NewText(msg, theme.Color(theme.ColorNameForeground))
Expand All @@ -316,6 +318,9 @@ func (a *App) setWaitContent(msg string) binding.String {
activityText.Text = str
activityText.Refresh()
})
progressBar := widget.NewProgressBar()
activityProgress := binding.NewFloat()
progressBar.Bind(activityProgress)

activityContent := container.NewVBox(
layout.NewSpacer(),
Expand All @@ -325,7 +330,7 @@ func (a *App) setWaitContent(msg string) binding.String {
layout.NewSpacer(),
)
a.setMainContent(activityContent)
return activityStr
return activityProgress, activityStr
}

func (a *App) showErrorDialog(err error) {
Expand Down
21 changes: 13 additions & 8 deletions internal/gui/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (a *App) loadUnpackedPath(path string) {
return
}

activity := a.setWaitContent(lang.X(
activityProgress, activityStr := a.setWaitContent(lang.X(
"pack.wait",
"Loading unpacked resources from {{.Path}} (building index) ...",
map[string]any{
Expand All @@ -54,42 +54,47 @@ func (a *App) loadUnpackedPath(path string) {
if err != nil {
l.WithError(err).Error("could not load directory")
a.setErrContent(
err,
lang.X(
"err.badResources",
"Failed to load unpacked resources from {{.Path}}",
map[string]any{"Path": path}),

err,
)
return
}

err = pkg.BuildFileList(func(path string) {
activity.Set(lang.X(
errs := pkg.BuildFileListProgress(func(p float64, path string) {
activityProgress.Set(p)
activityStr.Set(lang.X(
"pack.buildList.activity",
"Loading {{.Path}} ...",
map[string]any{
"Path": utils.TruncatePathHumanFriendly(path, 80),
},
))
})
if err != nil {
l.WithError(err).Error("could not build file list")
if len(errs) != 0 {
for _, err := range errs {
l.WithField("task", "build file list").Errorf("error: %s", err)
}
a.setErrContent(
err,
lang.X(
"err.fileList",
"Failed to build file list from {{.Path}}",
map[string]any{
"Path": path,
},
),
err,
)
return
}

err = pkg.LoadTags()
if err != nil {
a.showErrorDialog(errors.Join(err, fmt.Errorf(lang.X("package.tags.error", "Failed to read tags"))))
a.showErrorDialog(
errors.Join(err, fmt.Errorf(lang.X("package.tags.error", "Failed to read tags"))))
err = nil
}
err = pkg.LoadResourceMetadata()
Expand Down
Loading

0 comments on commit 4ae2473

Please sign in to comment.