some work on platform file
This commit is contained in:
parent
c51f380d59
commit
a7b14cc12c
@ -1,19 +1,63 @@
|
|||||||
package platform
|
package platform
|
||||||
|
|
||||||
import "github.com/FooSoft/lazarus/formats/mpq"
|
import (
|
||||||
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/FooSoft/lazarus/formats/mpq"
|
||||||
|
)
|
||||||
|
|
||||||
var fileState struct {
|
var fileState struct {
|
||||||
mountPoints map[string]*mpq.Archive
|
mountPoints map[string]*mpq.Archive
|
||||||
|
mountPaths map[string]*mpq.Archive
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct{}
|
||||||
}
|
|
||||||
|
|
||||||
func FileMountArchive(mountPath, archivePath string) error {
|
func FileMountArchive(mountPath, archivePath string) error {
|
||||||
|
archive, err := mpq.NewFromFile(archivePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if fileState.mountPoints == nil {
|
||||||
|
fileState.mountPoints = make(map[string]*mpq.Archive)
|
||||||
|
}
|
||||||
|
|
||||||
|
var count int
|
||||||
|
for _, path := range archive.GetPaths() {
|
||||||
|
resourcePath := filepath.Join(mountPath, path)
|
||||||
|
if _, ok := fileState.mountPoints[resourcePath]; !ok {
|
||||||
|
fileState.mountPoints[resourcePath] = archive
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if count == 0 {
|
||||||
|
archive.Close()
|
||||||
|
return errors.New("file archive could not be mounted")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileUnmountArchive(mountPath string) error {
|
func FileUnmountArchive(mountPath string) error {
|
||||||
|
archive, ok := fileState.mountPoints[mountPath]
|
||||||
|
if !ok {
|
||||||
|
return errors.New("file archive is nout mounted")
|
||||||
|
}
|
||||||
|
|
||||||
|
var paths []string
|
||||||
|
for p, a := range fileState.mountPaths {
|
||||||
|
if archive == a {
|
||||||
|
paths = append(paths, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range paths {
|
||||||
|
delete(fileState.mountPaths, p)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user