[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:
parent
bf2afab07d
commit
6f14cd7c06
|
|
@ -20,6 +20,8 @@ type Arguments struct {
|
||||||
|
|
||||||
FileNum int `arg:"--file-num" default:"-1"`
|
FileNum int `arg:"--file-num" default:"-1"`
|
||||||
Range string `arg:"--range"`
|
Range string `arg:"--range"`
|
||||||
|
|
||||||
|
Output string `arg:"--output"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -39,11 +41,20 @@ func run(args *Arguments) error {
|
||||||
return err
|
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)
|
err = os.MkdirAll(outdir, 0775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if args.Side >= 0 && args.FileNum == -1 {
|
if args.Side >= 0 && args.FileNum == -1 {
|
||||||
if args.Side >= len(rom.Sides) {
|
if args.Side >= len(rom.Sides) {
|
||||||
|
|
@ -100,7 +111,11 @@ func run(args *Arguments) error {
|
||||||
end = file.Size
|
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)
|
fmt.Println("fileName:", fileName)
|
||||||
err := os.WriteFile(fileName, file.Data[start:end], 0664)
|
err := os.WriteFile(fileName, file.Data[start:end], 0664)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue