Fix the god damn disgusting windows path

This commit is contained in:
2025-03-26 21:06:19 +01:00
parent 85fc955a1b
commit 5945f8cc25

View File

@@ -34,7 +34,6 @@ func init() {
const remoteUrl = "https://git.site.quack-lab.dev/dave/barotrauma-gamefiles/raw/branch/cooked/Content" const remoteUrl = "https://git.site.quack-lab.dev/dave/barotrauma-gamefiles/raw/branch/cooked/Content"
func main() { func main() {
savehash := flag.Bool("savehash", false, "save hash")
hashfile := flag.String("hashfile", "hashes.txt", "hashfile") hashfile := flag.String("hashfile", "hashes.txt", "hashfile")
flag.Parse() flag.Parse()
@@ -72,7 +71,9 @@ func main() {
wg.Add(1) wg.Add(1)
go func(file string) { go func(file string) {
defer wg.Done() defer wg.Done()
file = strings.ReplaceAll(file, "\\", "/")
path := filepath.Join(root, file) path := filepath.Join(root, file)
path = strings.ReplaceAll(path, "\\", "/")
hash, err := GetLocalHash(path) hash, err := GetLocalHash(path)
if err != nil { if err != nil {
Error.Printf("error getting hash: %v", err) Error.Printf("error getting hash: %v", err)
@@ -83,6 +84,7 @@ func main() {
Error.Printf("error getting relative path: %v", err) Error.Printf("error getting relative path: %v", err)
return return
} }
relativepath = strings.ReplaceAll(relativepath, "\\", "/")
hashes.Store(relativepath, hash) hashes.Store(relativepath, hash)
}(file) }(file)
} }
@@ -128,15 +130,20 @@ func main() {
if err != nil { if err != nil {
Error.Printf("error updating local file: %v", err) Error.Printf("error updating local file: %v", err)
} }
newhash, err := GetLocalHash(path)
if err != nil {
Error.Printf("error getting local hash: %v", err)
return
}
hashes.Store(file, newhash)
}(file) }(file)
} }
wg.Wait() wg.Wait()
} }
if *savehash { // We want to update the newly downloaded files, if any
err := SaveLocalHashes(*hashfile, hashes) err = SaveLocalHashes(*hashfile, hashes)
if err != nil { if err != nil {
Error.Printf("error saving hashes: %v", err) Error.Printf("error saving hashes: %v", err)
}
} }
} }
@@ -183,6 +190,7 @@ type FileHash struct {
Path string Path string
Hash string Hash string
} }
func SaveLocalHashes(path string, hashes *sync.Map) error { func SaveLocalHashes(path string, hashes *sync.Map) error {
file, err := os.Create(path) file, err := os.Create(path)
if err != nil { if err != nil {