From ecb4650423cd6edd6c1dce58b17c248809cfce37 Mon Sep 17 00:00:00 2001 From: jabuxas Date: Sat, 28 Sep 2024 09:55:08 -0300 Subject: [PATCH] refactor: demodularize bepinex install --- helpers.go | 50 ++++++++++++++++++++++++++------------------------ spire.go | 10 +--------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/helpers.go b/helpers.go index fe240c5..06fdee5 100644 --- a/helpers.go +++ b/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 } diff --git a/spire.go b/spire.go index 5948a4b..a7c079e 100644 --- a/spire.go +++ b/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 -}