work in progress on filesystem and mpq extract

This commit is contained in:
Alex Yatskov 2018-12-14 18:13:19 -08:00
parent a06a3c3a85
commit 1df993dbd3
3 changed files with 84 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.mpq

50
filesystem/filesystem.go Normal file
View File

@ -0,0 +1,50 @@
package filesystem
import (
"bytes"
"io"
"github.com/icza/mpq"
)
type FileSystem interface {
Mount(root, path string) error
List() ([]string, error)
Open(path string) (io.ReadSeeker, error)
}
func New() FileSystem {
return new(filesystem)
}
type filesystem struct {
db *mpq.MPQ
}
func (fs *filesystem) Mount(root, path string) error {
db, err := mpq.NewFromFile(path)
if err != nil {
return err
}
fs.db = db
return nil
}
func (fs *filesystem) List() ([]string, error) {
data, err := fs.db.FileByName("(listfile)")
if err != nil {
return nil, err
}
return []string{string(data)}, nil
}
func (fs *filesystem) Open(path string) (io.ReadSeeker, error) {
data, err := fs.db.FileByName(path)
if err != nil {
return nil, err
}
return bytes.NewReader(data), nil
}

33
tools/mpq/mpq.go Normal file
View File

@ -0,0 +1,33 @@
package main
import (
"flag"
"log"
"os"
"github.com/FooSoft/lazarus/filesystem"
)
func main() {
// var (
// wildcard = flag.String("wildcard", "*.*", "wildcard filter")
// )
flag.Parse()
if flag.NArg() == 0 {
flag.PrintDefaults()
os.Exit(2)
}
fs := filesystem.New()
if err := fs.Mount("", flag.Arg(0)); err != nil {
log.Fatal(err)
}
paths, err := fs.List()
if err != nil {
log.Fatal(err)
}
log.Print(paths)
}