[fdsextract] Add --output option

Currently only available when extracting single files.  Will use the
given filename as the output name instead of constructing one.

TODO: Make this value a template that can be used with multiple files.
This commit is contained in:
Zorchenhimer 2025-12-18 21:38:02 -05:00
parent bf2afab07d
commit 6f14cd7c06
Signed by: Zorchenhimer
GPG Key ID: 70A1AB767AAB9C20
1 changed files with 20 additions and 5 deletions

View File

@ -20,6 +20,8 @@ type Arguments struct {
FileNum int `arg:"--file-num" default:"-1"`
Range string `arg:"--range"`
Output string `arg:"--output"`
}
func main() {
@ -39,11 +41,20 @@ func run(args *Arguments) error {
return err
}
outdir := strings.TrimSuffix(args.Input, filepath.Ext(args.Input))
if args.Output != "" && args.FileNum == -1 {
return fmt.Errorf("--output can only be used when exporting a single file")
}
outdir := "./"
if args.Output == "" {
outdir = strings.TrimSuffix(args.Input, filepath.Ext(args.Input))
}
if args.Output != "" {
err = os.MkdirAll(outdir, 0775)
if err != nil {
return err
}
}
if args.Side >= 0 && args.FileNum == -1 {
if args.Side >= len(rom.Sides) {
@ -100,7 +111,11 @@ func run(args *Arguments) error {
end = file.Size
}
fileName := filepath.Join(outdir, fmt.Sprintf("%03d_%s_%02d_%02X", args.FileNum, sideName, file.Number, file.Id))
fileName := args.Output
if fileName == "" {
fileName = filepath.Join(outdir, fmt.Sprintf("%03d_%s_%02d_%02X", args.FileNum, sideName, file.Number, file.Id))
}
fmt.Println("fileName:", fileName)
err := os.WriteFile(fileName, file.Data[start:end], 0664)
if err != nil {