Compare commits
No commits in common. "4f99e500c0a6adf650fb16f2492b4945671af76b" and "65ee9808279724472cfbca19f1244b0dbe48d436" have entirely different histories.
4f99e500c0
...
65ee980827
36
helpers.go
36
helpers.go
@ -17,7 +17,7 @@ func DownloadCache() error {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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)
|
return fmt.Errorf("couldn't create tmpdir: %w", err)
|
||||||
}
|
}
|
||||||
out, err := os.Create(PAYLOAD)
|
out, err := os.Create(PAYLOAD)
|
||||||
@ -26,7 +26,7 @@ func DownloadCache() error {
|
|||||||
}
|
}
|
||||||
defer out.Close()
|
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)
|
return fmt.Errorf("couldn't write to file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,28 +35,24 @@ func DownloadCache() error {
|
|||||||
|
|
||||||
func DownloadBepinex() error {
|
func DownloadBepinex() error {
|
||||||
tmpPath := TMPDIR + "/bepinex.zip"
|
tmpPath := TMPDIR + "/bepinex.zip"
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// download only if it doesnt exist
|
out, err := os.Create(tmpPath)
|
||||||
if _, err := os.Stat(tmpPath); err != nil {
|
if 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")
|
return fmt.Errorf("could not create file: %w", err)
|
||||||
if err != nil {
|
}
|
||||||
return fmt.Errorf("could not download bepinex: %w", err)
|
defer out.Close()
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
out, err := os.Create(tmpPath)
|
_, err = io.Copy(out, resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create file: %w", err)
|
return fmt.Errorf("could not save file: %w", err)
|
||||||
}
|
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
_, err = io.Copy(out, resp.Body)
|
|
||||||
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("could not extract BepInEx: %w", err)
|
return fmt.Errorf("could not extract BepInEx: %w", err)
|
||||||
}
|
}
|
||||||
|
9
spire.go
9
spire.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -25,13 +26,14 @@ func getCache() error {
|
|||||||
info, err := os.Stat(PAYLOAD)
|
info, err := os.Stat(PAYLOAD)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// payload isn't accessible, requesting
|
fmt.Println("payload isn't accessible, requesting")
|
||||||
DownloadCache()
|
DownloadCache()
|
||||||
} else if !(info.ModTime().After(time.Now().Add(-2 * time.Hour))) {
|
} else if !(info.ModTime().After(time.Now().Add(-2 * time.Hour))) {
|
||||||
// download again if payload is older than 2 hours
|
// download again if payload is older than 2 hours
|
||||||
DownloadCache()
|
DownloadCache()
|
||||||
|
} else {
|
||||||
|
fmt.Println("payload was updated recently, won't update")
|
||||||
}
|
}
|
||||||
// else payload was updated recently, won't update
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -42,6 +44,7 @@ func installBepinex() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// install bepinex
|
// install bepinex
|
||||||
DownloadBepinex()
|
DownloadBepinex()
|
||||||
|
} else {
|
||||||
|
fmt.Println("bepinex already installed")
|
||||||
}
|
}
|
||||||
// else bepinex already installed
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user