Skip to content

Commit

Permalink
Replaced opts.InputFiles array with opts.InputFile string option
Browse files Browse the repository at this point in the history
  • Loading branch information
SamusAranX committed May 11, 2023
1 parent 632efba commit 5468255
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
4 changes: 1 addition & 3 deletions gbs/makegb.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,10 @@ func MakeGB(gbsBytes []byte, outFile string) error {
binary.BigEndian.PutUint16(gcs, globalChecksum(gbBytes))
copy(gbBytes[0x14E:0x150], gcs)

written, err := utils.WriteAllBytes(outFile, gbBytes)
_, err = utils.WriteAllBytes(outFile, gbBytes)
if err != nil {
return err
}

log.Printf("gbBytes written to file: %d/%d", written, romSizeBytes)

return nil
}
33 changes: 14 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,23 @@ func main() {
log.Fatalf("Can't create output directory: %v", err)
}

for i, inputFile := range opts.InputFiles {
if i > 0 {
log.Println("################")
}

_, inputBase := path.Split(inputFile)
inputNoext := strings.TrimSuffix(inputBase, path.Ext(inputBase))
outputFile := path.Join(opts.OutDir, fmt.Sprintf("%s.gb", inputNoext))
_, inputBase := path.Split(opts.InputFile)
inputNoext := strings.TrimSuffix(inputBase, path.Ext(inputBase))
outputFile := path.Join(opts.OutDir, fmt.Sprintf("%s.gb", inputNoext))

log.Println(inputBase)
log.Printf("→ %s", inputBase)

gbsBytes, err := utils.ReadAllBytes(inputFile)
if err != nil {
log.Println(err)
continue
}
gbsBytes, err := utils.ReadAllBytes(opts.InputFile)
if err != nil {
log.Println(err)
return
}

err = gbs.MakeGB(gbsBytes, outputFile)
if err != nil {
log.Printf("Couldn't create GB file:")
log.Println(err)
}
err = gbs.MakeGB(gbsBytes, outputFile)
if err != nil {
log.Printf("Couldn't create GB file:")
log.Println(err)
}

log.Printf("Successfully created %s", outputFile)
}
6 changes: 3 additions & 3 deletions opts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

type CommandLineOpts struct {
InputFiles []string `short:"i" long:"input" description:"Input GBS files"`
OutDir string `short:"o" long:"outdir" description:"Output directory" default:"./"`
Version bool `short:"v" long:"version" description:"Show version and exit"`
InputFile string `short:"i" long:"input" description:"Input GBS file"`
OutDir string `short:"o" long:"outdir" description:"Output directory" default:"./"`
Version bool `short:"v" long:"version" description:"Show version and exit"`
}

0 comments on commit 5468255

Please sign in to comment.