fix issues with listing and extracting mpq files

This commit is contained in:
Alex Yatskov 2018-12-15 17:56:42 -08:00
parent ef84ea89ac
commit 11032fec24
3 changed files with 7 additions and 5 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
*.mpq
asset

View File

@ -22,6 +22,7 @@ import (
"fmt"
"io"
"math"
"os"
"strings"
"unsafe"
)
@ -124,7 +125,7 @@ func (a *archive) Close() error {
}
func (a *archive) OpenFile(path string) (File, error) {
cs := C.CString(path)
cs := C.CString(strings.Replace(path, string(os.PathSeparator), "\\", -1))
defer C.free(unsafe.Pointer(cs))
file := &file{size: math.MaxUint32}
@ -153,6 +154,7 @@ func (a *archive) GetPaths() ([]string, error) {
for _, line := range strings.Split(string(buff.Bytes()), "\r\n") {
line = strings.TrimSpace(line)
line = strings.Replace(line, "\\", string(os.PathSeparator), -1)
if len(line) > 0 {
a.paths = append(a.paths, line)
}

View File

@ -86,7 +86,7 @@ func extract(mpqPath, filter, targetDir string) error {
func main() {
var (
filter = flag.String("filter", "*.*", "wildcard file filter")
filter = flag.String("filter", "**", "wildcard file filter")
targetDir = flag.String("target", ".", "target directory")
)
@ -107,14 +107,14 @@ func main() {
case "list":
for i := 1; i < flag.NArg(); i++ {
if err := list(flag.Arg(i), *filter); err != nil {
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
case "extract":
for i := 1; i < flag.NArg(); i++ {
if err := extract(flag.Arg(i), *filter, *targetDir); err != nil {
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}