diff --git a/.gitignore b/.gitignore index 71bfb3c..3be4e1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .stfolder +*.log diff --git a/updater/main.go b/updater/main.go index 572f8c8..8e7bc9f 100644 --- a/updater/main.go +++ b/updater/main.go @@ -23,10 +23,14 @@ var Warning *log.Logger func init() { log.SetFlags(log.Lmicroseconds | log.Lshortfile) - Error = log.New(io.MultiWriter(os.Stderr, os.Stdout), + logFile, err := os.OpenFile("updater.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + if err != nil { + log.Fatalf("error opening log file: %v", err) + } + Error = log.New(io.MultiWriter(os.Stderr, logFile), fmt.Sprintf("%sERROR:%s ", "\033[0;101m", "\033[0m"), log.Lmicroseconds|log.Lshortfile) - Warning = log.New(io.MultiWriter(os.Stdout), + Warning = log.New(io.MultiWriter(os.Stdout, logFile), fmt.Sprintf("%sWarning:%s ", "\033[0;93m", "\033[0m"), log.Lmicroseconds|log.Lshortfile) } @@ -36,6 +40,7 @@ const remoteUrl = "https://git.site.quack-lab.dev/dave/barotrauma-gamefiles/raw/ func main() { nodl := flag.Bool("nodl", false, "nodl") hashfile := flag.String("hashfile", "hashes.txt", "hashfile") + root := flag.String("root", ".", "root") flag.Parse() cwd, err := os.Getwd() @@ -43,10 +48,13 @@ func main() { Error.Printf("error getting cwd: %v", err) return } + log.Printf("cwd: %s", cwd) + log.Printf("root: %s", *root) - root := filepath.Join(cwd, "Content") + *root = filepath.Join(cwd, *root, "Content") + log.Printf("root: %s", *root) - *hashfile = filepath.Join(root, *hashfile) + *hashfile = filepath.Join(*root, *hashfile) hashes, err := LoadLocalHashes(*hashfile) if err != nil { Error.Printf("error loading hashes: %v", err) @@ -61,7 +69,7 @@ func main() { } log.Printf("loaded remote hashes") - files, err := doublestar.Glob(os.DirFS(root), "**/*.xml") + files, err := doublestar.Glob(os.DirFS(*root), "**/*.xml") if err != nil { Error.Printf("error globbing files: %v", err) return @@ -73,14 +81,14 @@ func main() { go func(file string) { 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) if err != nil { Error.Printf("error getting hash: %v", err) return } - relativepath, err := filepath.Rel(root, path) + relativepath, err := filepath.Rel(*root, path) if err != nil { Error.Printf("error getting relative path: %v", err) return @@ -125,7 +133,7 @@ func main() { go func(file string) { defer wg.Done() file = strings.ReplaceAll(file, "\\", "/") - path := filepath.Join(root, file) + path := filepath.Join(*root, file) log.Printf("Downloading %s", file) if *nodl { log.Printf("Skipping download for %s", file) diff --git a/updater/updater.exe b/updater/updater.exe index f91d4d1..3f8c4c2 100644 --- a/updater/updater.exe +++ b/updater/updater.exe @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:69386b5242582f791cf9db8fa9401738247982c2b0632ecb73ba2965dc7a42cd +oid sha256:f59f1d0f614e46914b160609100fa0639a1f505267de4b263e096a98bc63660d size 8627712