Compare commits
2 Commits
65ee980827
...
4f99e500c0
Author | SHA1 | Date | |
---|---|---|---|
4f99e500c0 | |||
2e8c0790a5 |
10
helpers.go
10
helpers.go
@ -17,7 +17,7 @@ func DownloadCache() error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := os.MkdirAll(TMPDIR, os.ModePerm); err != nil {
|
||||
if err = os.MkdirAll(TMPDIR, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("couldn't create tmpdir: %w", err)
|
||||
}
|
||||
out, err := os.Create(PAYLOAD)
|
||||
@ -26,7 +26,7 @@ func DownloadCache() error {
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
if _, err := io.Copy(out, resp.Body); err != nil {
|
||||
if _, err = io.Copy(out, resp.Body); err != nil {
|
||||
return fmt.Errorf("couldn't write to file: %w", err)
|
||||
}
|
||||
|
||||
@ -35,6 +35,9 @@ func DownloadCache() error {
|
||||
|
||||
func DownloadBepinex() error {
|
||||
tmpPath := TMPDIR + "/bepinex.zip"
|
||||
|
||||
// download only if it doesnt exist
|
||||
if _, err := os.Stat(tmpPath); err != nil {
|
||||
resp, err := http.Get("https://github.com/BepInEx/BepInEx/releases/download/v5.4.23.2/BepInEx_win_x64_5.4.23.2.zip")
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not download bepinex: %w", err)
|
||||
@ -51,8 +54,9 @@ func DownloadBepinex() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not save file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = unzip(tmpPath, GAME_PATH)
|
||||
err := unzip(tmpPath, GAME_PATH)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not extract BepInEx: %w", err)
|
||||
}
|
||||
|
9
spire.go
9
spire.go
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
@ -26,14 +25,13 @@ func getCache() error {
|
||||
info, err := os.Stat(PAYLOAD)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("payload isn't accessible, requesting")
|
||||
// payload isn't accessible, requesting
|
||||
DownloadCache()
|
||||
} else if !(info.ModTime().After(time.Now().Add(-2 * time.Hour))) {
|
||||
// download again if payload is older than 2 hours
|
||||
DownloadCache()
|
||||
} else {
|
||||
fmt.Println("payload was updated recently, won't update")
|
||||
}
|
||||
// else payload was updated recently, won't update
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -44,7 +42,6 @@ func installBepinex() {
|
||||
if err != nil {
|
||||
// install bepinex
|
||||
DownloadBepinex()
|
||||
} else {
|
||||
fmt.Println("bepinex already installed")
|
||||
}
|
||||
// else bepinex already installed
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user