lazarus/platform/file.go

77 lines
1.4 KiB
Go
Raw Normal View History

2019-01-09 02:34:51 +00:00
package platform
2019-01-11 04:00:54 +00:00
import (
"errors"
"path/filepath"
"github.com/FooSoft/lazarus/formats/mpq"
)
2019-01-09 02:34:51 +00:00
var fileState struct {
2019-01-09 02:45:19 +00:00
mountPoints map[string]*mpq.Archive
2019-01-11 04:00:54 +00:00
mountPaths map[string]*mpq.Archive
2019-01-09 02:34:51 +00:00
}
2019-01-11 04:00:54 +00:00
type File struct{}
2019-01-09 02:34:51 +00:00
func FileMountArchive(mountPath, archivePath string) error {
2019-01-11 04:00:54 +00:00
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")
}
2019-01-09 02:34:51 +00:00
return nil
}
func FileUnmountArchive(mountPath string) error {
2019-01-11 04:00:54 +00:00
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)
}
2019-01-09 02:34:51 +00:00
return nil
}
func FileUnmountAll() error {
for _, archive := range fileState.mountPoints {
if err := archive.Close(); err != nil {
return err
}
}
return nil
}
2019-01-09 02:34:51 +00:00
func FileOpen(path string) (*File, error) {
return nil, nil
}