Skip to content

Commit

Permalink
pl2-to-png: Make path optional and report errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziemas committed Aug 29, 2021
1 parent a8c205d commit c541f30
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions cmd/pl2-to-png/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"image/png"
"io/ioutil"
"os"
"path"

"github.com/OpenDiablo2/pl2/pkg"
)
Expand All @@ -18,7 +19,7 @@ type options struct {
}

func parseOptions(o *options) (terminate bool) {
o.pl2 = flag.String("pl2", "", "input pkg file (required)")
o.pl2 = flag.String("pl2", "", "input pl2 file (required)")
o.pngPath = flag.String("png", "", "path to output png file (optional)")

flag.Parse()
Expand All @@ -43,16 +44,22 @@ func main() {

pl2, err := pkg.FromBytes(data)
if err != nil {
fmt.Print(fmt.Errorf("Error decoding pl2: %w\n", err))
return
}

if *o.pngPath != "" {
img := makeImage(pl2)
pngPath := *o.pngPath

err = writeImage(*o.pngPath, img)
if err != nil {
fmt.Errorf("problem writing image, %w", err)
}
if pngPath == "" {
pngPath, _ = os.Getwd()
pngPath = path.Join(pngPath, "output.png")
}

img := makeImage(pl2)

err = writeImage(pngPath, img)
if err != nil {
fmt.Print(fmt.Errorf("problem writing image, %w", err))
}
}

Expand Down Expand Up @@ -188,4 +195,4 @@ func writeImage(outPath string, img image.Image) error {
}

return nil
}
}

0 comments on commit c541f30

Please sign in to comment.