Fix filepath separator and external files on windows

For some reason, '/' is used instead of '\' on windows when loading
lang. FSJoin will now use whatever already exists in the path.
app.GetPath now creates a DirFS from the containing directory instead of
app.systemFS, which fixes loading on windows.
This commit is contained in:
Harvey Tindall
2021-02-18 12:58:30 +00:00
parent cdc837e781
commit adbb5b9d38
5 changed files with 21 additions and 8 deletions
+14 -1
View File
@@ -5,12 +5,25 @@ import (
"log"
"os"
"path/filepath"
"strings"
)
var localFS fs.FS
var langFS fs.FS
func FSJoin(elem ...string) string { return filepath.Join(elem...) }
// 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)
}
func loadFilesystems() {
log.Println("Using external storage")