refactor: demodularize bepinex install
This commit is contained in:
parent
464b8ef778
commit
ecb4650423
50
helpers.go
50
helpers.go
@ -34,35 +34,37 @@ func DownloadCache() error {
|
||||
}
|
||||
|
||||
func DownloadBepinex() error {
|
||||
tmpPath := TMPDIR + "/bepinex.zip"
|
||||
if _, err := os.Stat(GAME_PATH + "/BepInEx"); err != nil {
|
||||
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)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
// 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)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
out, err := os.Create(tmpPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create file: %w", err)
|
||||
}
|
||||
defer out.Close()
|
||||
out, err := os.Create(tmpPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create 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 = io.Copy(out, resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not save file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
err := unzip(tmpPath, GAME_PATH)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not extract BepInEx: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
err := unzip(tmpPath, GAME_PATH)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not extract BepInEx: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
10
spire.go
10
spire.go
@ -18,7 +18,7 @@ func main() {
|
||||
if err := SanitizeInput(&GAME_PATH); err != nil {
|
||||
log.Fatal("GAME_PATH is not set")
|
||||
}
|
||||
installBepinex()
|
||||
DownloadBepinex()
|
||||
}
|
||||
|
||||
func getCache() error {
|
||||
@ -35,11 +35,3 @@ func getCache() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func installBepinex() {
|
||||
if _, err := os.Stat(GAME_PATH + "/BepInEx"); err != nil {
|
||||
// install bepinex
|
||||
DownloadBepinex()
|
||||
}
|
||||
// else bepinex already installed
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user