Reimplement dependency list builder in tools instead of cli

This commit is contained in:
rainyuu 2021-01-31 11:25:17 +01:00
parent 91a865467b
commit 3a420c4a41
2 changed files with 20 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package cli
import ( import (
"fmt" "fmt"
"r2go/api"
"r2go/tools" "r2go/tools"
"github.com/fatih/color" "github.com/fatih/color"
@ -15,10 +14,10 @@ func InstallMod(pkg string) []string {
red := color.New(color.FgRed).SprintFunc() red := color.New(color.FgRed).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc() blue := color.New(color.FgBlue).SprintFunc()
cyan := color.New(color.FgCyan).SprintFunc() cyan := color.New(color.FgCyan).SprintFunc()
deps := []string{} // deps := []string{}
buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... ")) buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... "))
stat, ov := tools.DownloadMod(tools.ExposeModString(pkg)) stat, ov, deps := tools.DownloadMod(tools.ExposeModString(pkg))
if stat == 1 { if stat == 1 {
buffer += green("up to date!") buffer += green("up to date!")
@ -30,15 +29,15 @@ func InstallMod(pkg string) []string {
buffer += blue("downloaded") buffer += blue("downloaded")
} }
if stat != 3 { // if stat != 3 {
_, mod := api.GetModData(tools.ExposeModString(pkg)) // _, mod := api.GetModData(tools.ExposeModString(pkg))
for _, dep := range mod.Versions[0].Dependencies { // for _, dep := range mod.Versions[0].Dependencies {
depString := tools.ExposeModString(dep) // depString := tools.ExposeModString(dep)
if depString != "tristanmcpherson-R2API" && depString != "bbepis-BepInExPack" { // if depString != "tristanmcpherson-R2API" && depString != "bbepis-BepInExPack" {
deps = append(deps, depString) // deps = append(deps, depString)
} // }
} // }
} // }
fmt.Println(buffer) fmt.Println(buffer)
return deps return deps

View File

@ -21,9 +21,10 @@ func ExposeModString(input string) string {
// DownloadMod gets the download URL and installs the mod in the correct folder // DownloadMod gets the download URL and installs the mod in the correct folder
// DownloadMod returns 0 if the download is sucessful, and 1 if it is already installed // DownloadMod returns 0 if the download is sucessful, and 1 if it is already installed
// DownlaodMod returns 2 if the mod updated, and 3 if the mod could not be found. // DownlaodMod returns 2 if the mod updated, and 3 if the mod could not be found.
func DownloadMod(depString string) (int, string) { func DownloadMod(depString string) (int, string, []string) {
var status int var status int
var modver string var modver string
var deps []string
if depString == "R2API" { if depString == "R2API" {
depString = "tristanmcpherson-R2API" depString = "tristanmcpherson-R2API"
@ -32,7 +33,7 @@ func DownloadMod(depString string) (int, string) {
sysinfo := utils.GetSysInfo() sysinfo := utils.GetSysInfo()
status, mod := api.GetModData(depString) status, mod := api.GetModData(depString)
if status != 0 { if status != 0 {
return 3, "not_found" return 3, "not_found", deps
} }
downloadURL := mod.Versions[0].DownloadURL downloadURL := mod.Versions[0].DownloadURL
@ -43,7 +44,7 @@ func DownloadMod(depString string) (int, string) {
if utils.PathExists(modFolder) { if utils.PathExists(modFolder) {
return 1, modver return 1, modver, deps
} }
status, mod = api.GetModData(depString) status, mod = api.GetModData(depString)
@ -67,13 +68,17 @@ func DownloadMod(depString string) (int, string) {
log.Println(unzip) log.Println(unzip)
utils.CheckErr(err) utils.CheckErr(err)
for _, dep := range mod.Versions[0].Dependencies {
deps = append(deps, dep)
}
// TODO: Dependencies! // TODO: Dependencies!
// fmt.Println("pog") // fmt.Println("pog")
// for _, dep := range mod.Versions[0].Dependencies { // for _, dep := range mod.Versions[0].Dependencies {
// DownloadMod(dep) // DownloadMod(dep)
// } // }
return status, modver return status, modver, deps
} }
// RemoveMod uninstalls a mod // RemoveMod uninstalls a mod