Add --extract

Extract all files in the rom to the given directory.  Filename structure
is ###_Side_FileNumber_FileId.
This commit is contained in:
Zorchenhimer 2025-12-07 20:28:11 -05:00
parent 4ab973c6b2
commit cc0e79c72b
Signed by: Zorchenhimer
GPG Key ID: 70A1AB767AAB9C20
1 changed files with 21 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import (
type Arguments struct {
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())
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
}