Add --extract
Extract all files in the rom to the given directory. Filename structure is ###_Side_FileNumber_FileId.
This commit is contained in:
parent
4ab973c6b2
commit
cc0e79c72b
|
|
@ -16,6 +16,7 @@ import (
|
||||||
|
|
||||||
type Arguments struct {
|
type Arguments struct {
|
||||||
Input string `arg:"positional,required"`
|
Input string `arg:"positional,required"`
|
||||||
|
Extract string `arg:"--extract" help:"Extract files to the given directory"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,6 +50,26 @@ func run(args *Arguments) error {
|
||||||
|
|
||||||
fmt.Println(rom.Info())
|
fmt.Println(rom.Info())
|
||||||
|
|
||||||
|
if args.Extract != "" {
|
||||||
|
err = os.MkdirAll(args.Extract, 0775)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
num := 0
|
||||||
|
for _, side := range rom.Sides {
|
||||||
|
sideName := fmt.Sprintf("Side%d", side.Header.PhysicalSide)
|
||||||
|
for _, file := range side.Files {
|
||||||
|
fileName := filepath.Join(args.Extract, fmt.Sprintf("%03d_%s_%02d_%02X", num, sideName, file.Number, file.Id))
|
||||||
|
err := os.WriteFile(fileName, file.Data, 0664)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
num++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue