Skip to content

chore: improve dump flag #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading