fix issues with listing and extracting mpq files
This commit is contained in:
parent
ef84ea89ac
commit
11032fec24
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
||||
*.mpq
|
||||
asset
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user