2021-04-01 13:22:11 +00:00
|
|
|
// +build external
|
|
|
|
|
2021-02-17 14:32:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/fs"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2021-02-18 12:58:30 +00:00
|
|
|
"strings"
|
2021-02-17 14:32:03 +00:00
|
|
|
)
|
|
|
|
|
2021-03-07 15:23:44 +00:00
|
|
|
const binaryType = "external"
|
|
|
|
|
2021-07-16 14:39:22 +00:00
|
|
|
var localFS dirFS
|
|
|
|
var langFS dirFS
|
2021-02-17 14:32:03 +00:00
|
|
|
|
2021-02-18 12:58:30 +00:00
|
|
|
// When using os.DirFS, even on Windows the separator seems to be '/'.
|
|
|
|
// func FSJoin(elem ...string) string { return filepath.Join(elem...) }
|
|
|
|
func FSJoin(elem ...string) string {
|
|
|
|
sep := "/"
|
|
|
|
if strings.Contains(elem[0], "\\") {
|
|
|
|
sep = "\\"
|
|
|
|
}
|
|
|
|
path := ""
|
|
|
|
for _, el := range elem {
|
|
|
|
path += el + sep
|
|
|
|
}
|
|
|
|
return strings.TrimSuffix(path, sep)
|
|
|
|
}
|
2021-02-17 14:32:03 +00:00
|
|
|
|
2021-07-16 14:39:22 +00:00
|
|
|
type dirFS string
|
|
|
|
|
|
|
|
func (dir dirFS) Open(name string) (fs.File, error) {
|
|
|
|
return os.Open(string(dir) + "/" + name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dir dirFS) ReadFile(name string) ([]byte, error) {
|
|
|
|
return os.ReadFile(string(dir) + "/" + name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dir dirFS) ReadDir(name string) ([]fs.DirEntry, error) {
|
|
|
|
return os.ReadDir(string(dir) + "/" + name)
|
|
|
|
}
|
|
|
|
|
2021-02-17 14:32:03 +00:00
|
|
|
func loadFilesystems() {
|
|
|
|
log.Println("Using external storage")
|
|
|
|
executable, _ := os.Executable()
|
2021-07-16 14:39:22 +00:00
|
|
|
localFS = dirFS(filepath.Join(filepath.Dir(executable), "data"))
|
|
|
|
langFS = dirFS(filepath.Join(filepath.Dir(executable), "data", "lang"))
|
2021-02-17 14:32:03 +00:00
|
|
|
}
|