[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"`
|
||||
Range string `arg:"--range"`
|
||||
|
||||
Output string `arg:"--output"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
@ -39,10 +41,19 @@ func run(args *Arguments) error {
|
|||
return err
|
||||
}
|
||||
|
||||
outdir := strings.TrimSuffix(args.Input, filepath.Ext(args.Input))
|
||||
err = os.MkdirAll(outdir, 0775)
|
||||
if err != nil {
|
||||
return err
|
||||
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 {
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue