Fix the god damn disgusting windows path
This commit is contained in:
@@ -34,7 +34,6 @@ func init() {
|
||||
const remoteUrl = "https://git.site.quack-lab.dev/dave/barotrauma-gamefiles/raw/branch/cooked/Content"
|
||||
|
||||
func main() {
|
||||
savehash := flag.Bool("savehash", false, "save hash")
|
||||
hashfile := flag.String("hashfile", "hashes.txt", "hashfile")
|
||||
flag.Parse()
|
||||
|
||||
@@ -72,7 +71,9 @@ func main() {
|
||||
wg.Add(1)
|
||||
go func(file string) {
|
||||
defer wg.Done()
|
||||
file = strings.ReplaceAll(file, "\\", "/")
|
||||
path := filepath.Join(root, file)
|
||||
path = strings.ReplaceAll(path, "\\", "/")
|
||||
hash, err := GetLocalHash(path)
|
||||
if err != nil {
|
||||
Error.Printf("error getting hash: %v", err)
|
||||
@@ -83,6 +84,7 @@ func main() {
|
||||
Error.Printf("error getting relative path: %v", err)
|
||||
return
|
||||
}
|
||||
relativepath = strings.ReplaceAll(relativepath, "\\", "/")
|
||||
hashes.Store(relativepath, hash)
|
||||
}(file)
|
||||
}
|
||||
@@ -128,17 +130,22 @@ func main() {
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
if *savehash {
|
||||
err := SaveLocalHashes(*hashfile, hashes)
|
||||
// We want to update the newly downloaded files, if any
|
||||
err = SaveLocalHashes(*hashfile, hashes)
|
||||
if err != nil {
|
||||
Error.Printf("error saving hashes: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetLocalHash(path string) (string, error) {
|
||||
hash := sha256.New()
|
||||
@@ -183,6 +190,7 @@ type FileHash struct {
|
||||
Path string
|
||||
Hash string
|
||||
}
|
||||
|
||||
func SaveLocalHashes(path string, hashes *sync.Map) error {
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user