func extractMpq(flags zamaraFlags) { err := os.MkdirAll(flags.output, 0755) if err != nil { fmt.Printf("Could not access output location: %v\n", err.Error()) os.Exit(1) } reader, err := os.Open(flags.input) if err != nil { log.Printf("Error opening MPQ: %v\n", err.Error()) os.Exit(1) } mpq, err := pmpq.NewMpq(reader) if err != nil { log.Printf("Error reading MPQ: %v\n", err.Error()) os.Exit(1) } for _, file := range mpq.Files() { cleanPath := cleanDirectory(flags.output) + cleanFilename(file.Filename) if flags.verbose { fmt.Printf("Extracting %v to %v\n", file.Filename, cleanPath) } _, err = mpq.File(file.Filename) if err != nil { fmt.Printf("Error extracting file %v\n%v\n", file.Filename, err.Error()) continue } osFile, err := os.Create(cleanPath) defer osFile.Close() if err != nil { fmt.Printf("Error creating file %v\n%v\n", cleanPath, err.Error()) continue } buffer := make([]byte, file.FileSize) _, err = mpq.Read(buffer) if err != nil && err != pmpq.EOF { fmt.Printf("Error reading file %v from MPQ\n%v\n", file.Filename, err.Error()) continue } _, err = osFile.Write(buffer) if err != nil { fmt.Printf("Error writing file %v to %v\n%v\n", file.Filename, cleanPath, err.Error()) continue } } os.Exit(0) }
func mpqXml(flags zamaraFlags) { if len(flags.outputAbs) <= 0 { fmt.Printf("An output file must be specified.") usage() } reader, err := os.Open(flags.inputAbs) if err != nil { fmt.Fprintf(os.Stderr, "Unable to open MPQ (%v): %v", flags.input, err.Error()) os.Exit(1) } mpq, err := mpq.NewMpq(reader) if err != nil { fmt.Fprintf(os.Stderr, "Unable to read MPQ: %v", err.Error()) os.Exit(1) } if flags.verbose { fmt.Printf("Reading MPQ: %v\n", flags.input) } xmlOutput, err := xml.MarshalIndent(mpq, "", " ") if err != nil { fmt.Printf("Error: %v\n", err.Error()) } writer, err := os.Create(flags.outputAbs) if err != nil { fmt.Fprintf(os.Stderr, "Unable to open output file: %v", flags.outputAbs) os.Exit(1) } _, err = writer.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\" ?>") if err != nil { fmt.Printf("There was a problem writing the XML file.\n%v", err.Error()) os.Exit(1) } _, err = writer.Write(xmlOutput) if err != nil { fmt.Printf("There was a problem writing the XML file.\n%v", err.Error()) os.Exit(1) } _, err = writer.WriteString("\n") if err != nil { fmt.Printf("There was a problem writing the XML file.\n%v", err.Error()) os.Exit(1) } if flags.verbose { fmt.Printf("The MPQ's XML was written to %v", flags.output) } os.Exit(0) }
func (replay *Replay) load(reader io.ReadSeeker) (err error) { replay.Players = make([]*Player, 0) replay.mpq, err = mpq.NewMpq(reader) if err != nil { return } err = replay.loadDetails() if err != nil { return } replay.loadAttributes() if err != nil { return } return }
func mpqStdout(flags zamaraFlags) { reader, err := os.Open(flags.inputAbs) if err != nil { fmt.Fprintf(os.Stderr, "Unable to open MPQ (%v): %v", flags.input, err.Error()) os.Exit(1) } mpq, err := mpq.NewMpq(reader) if err != nil { fmt.Fprintf(os.Stderr, "Unable to read MPQ: %v", err.Error()) os.Exit(1) } fmt.Printf("Reading MPQ: %v\n", flags.input) mpqStdoutHeader(flags, mpq) mpqStdoutUserData(flags, mpq) mpqStdoutHashTable(flags, mpq) mpqStdoutBlockTable(flags, mpq) }