Skip to content

Commit

Permalink
Merge pull request #106 from redraskal/chore/dump
Browse files Browse the repository at this point in the history
chore: improve dump flag
  • Loading branch information
redraskal authored Aug 18, 2024
2 parents 9c0844d + 439b1c1 commit d530396
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 132 deletions.
116 changes: 0 additions & 116 deletions dissect/dump.go

This file was deleted.

23 changes: 7 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"encoding/json"
"github.com/redraskal/r6-dissect/dissect"
"io"
"os"
"strings"

"github.com/redraskal/r6-dissect/dissect"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -50,12 +51,7 @@ func main() {
log.Fatal().Msg("dump requires a replay file input.")
}
if viper.GetBool("dump") {
outBin, err := os.OpenFile(out.Name()+".bin", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.ModePerm)
if err != nil {
log.Fatal().Err(err).Send()
}
defer outBin.Close()
if err := writeRoundDump(in, out, outBin); err != nil {
if err := writeRoundDump(in, out); err != nil {
log.Fatal().Err(err).Send()
}
return
Expand All @@ -79,7 +75,7 @@ func setup() {
pflag.StringP("format", "f", "", "specifies the output format (json, excel)")
pflag.StringP("output", "o", "", "specifies the output path")
pflag.BoolP("debug", "d", false, "sets log level to debug")
pflag.BoolP("dump", "p", false, "dumps packets to the output")
pflag.BoolP("dump", "p", false, "dumps decompressed replay to the output")
pflag.Bool("info", false, "prints the replay header")
pflag.BoolP("version", "v", false, "prints the version")
pflag.Parse()
Expand Down Expand Up @@ -182,18 +178,13 @@ func writeRound(in io.Reader, out io.Writer) error {
})
}

func writeRoundDump(in io.Reader, out *os.File, outBin *os.File) error {
func writeRoundDump(in io.Reader, out *os.File) error {
r, err := dissect.NewReader(in)
if err != nil {
return err
}
if _, err := r.Write(outBin); err != nil {
return err
}
if err := r.Dump(out); !dissect.Ok(err) {
return err
}
return nil
_, err = r.Write(out)
return err
}

func piped(f *os.File) bool {
Expand Down

0 comments on commit d530396

Please sign in to comment.