Added check if mod exists
This commit is contained in:
parent
2b19b57541
commit
3933f84535
@ -113,16 +113,16 @@ func SearchMods(inp string) fuzzy.Ranks {
|
||||
}
|
||||
|
||||
// GetModData gets object of mod by depString
|
||||
func GetModData(depString string) Mod {
|
||||
func GetModData(depString string) (int, Mod) {
|
||||
if depString == "R2API" {
|
||||
depString = "tristanmcpherson-R2API"
|
||||
}
|
||||
|
||||
for i := 0; i < len(PkgList); i++ {
|
||||
if PkgList[i].FullName == depString {
|
||||
return PkgList[i]
|
||||
return 0, PkgList[i]
|
||||
}
|
||||
}
|
||||
|
||||
panic("Mod not found")
|
||||
return 1, Mod{}
|
||||
}
|
||||
|
@ -15,17 +15,21 @@ func InstallMod(pkg string) {
|
||||
|
||||
green := color.New(color.FgGreen).SprintFunc()
|
||||
magenta := color.New(color.FgMagenta).SprintFunc()
|
||||
red := color.New(color.FgRed).SprintFunc()
|
||||
blue := color.New(color.FgBlue).SprintFunc()
|
||||
|
||||
if stat == 1 {
|
||||
buffer += green("up to date!")
|
||||
} else if stat == 2 {
|
||||
buffer += fmt.Sprintf("%s %s", magenta("updating to version"), ov)
|
||||
} else if stat == 3 {
|
||||
buffer += fmt.Sprintf("%s", red("could not find the mod specified."))
|
||||
} else {
|
||||
buffer += blue("downloaded")
|
||||
}
|
||||
|
||||
mod := api.GetModData(tools.ExposeModString(pkg))
|
||||
if stat != 3 {
|
||||
_, mod := api.GetModData(tools.ExposeModString(pkg))
|
||||
for _, dep := range mod.Versions[0].Dependencies {
|
||||
depString := tools.ExposeModString(dep)
|
||||
if depString != "tristanmcpherson-R2API" && depString != "bbepis-BepInExPack" {
|
||||
@ -33,6 +37,8 @@ func InstallMod(pkg string) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fmt.Println(buffer)
|
||||
}
|
||||
|
||||
|
21
main.go
21
main.go
@ -55,9 +55,12 @@ func main() {
|
||||
case "info":
|
||||
api.InitAPI()
|
||||
if len(os.Args) <= 2 {
|
||||
fmt.Printf("Usage: %s info <dependency string>\n", os.Args[0])
|
||||
fmt.Println("Usage: r2go info <dependency string>")
|
||||
} else {
|
||||
var selectedmod api.Mod = api.GetModData(os.Args[2])
|
||||
status, selectedmod := api.GetModData(os.Args[2])
|
||||
if status != 0 {
|
||||
fmt.Println("> Could not find the mod specified.")
|
||||
}
|
||||
color.Cyan("Mod Info: %s", os.Args[2])
|
||||
fmt.Println(" Name: " + selectedmod.Versions[0].FullName)
|
||||
fmt.Println(" Desc: " + selectedmod.Versions[0].Description)
|
||||
@ -106,9 +109,14 @@ func main() {
|
||||
|
||||
color.Green("> Complete!")
|
||||
case "pull":
|
||||
color.Red("> Forcefully updating API Cache")
|
||||
api.InitAPI()
|
||||
color.Cyan("> Checking API Cache")
|
||||
if api.CheckAPICache() == 0 {
|
||||
color.Green("> API Cache is up to date!")
|
||||
} else {
|
||||
color.Red("> API Cache out of date!")
|
||||
api.UpdateAPICache()
|
||||
}
|
||||
case "toggle", "tm", "togglemods":
|
||||
if tools.ToggleMods() {
|
||||
color.Cyan("> Mods Enabled")
|
||||
@ -118,9 +126,8 @@ func main() {
|
||||
case "filter":
|
||||
fmt.Println(tools.ExposeModString(os.Args[2]))
|
||||
case "version", "ver", "v":
|
||||
color.Magenta("> r2go")
|
||||
fmt.Println(">", version)
|
||||
fmt.Println("> git.cya.cx/endigma/r2mod-go")
|
||||
color.Magenta("> r2go", version)
|
||||
fmt.Println(" > github.com/endigma442")
|
||||
case "search", "s", "find":
|
||||
api.InitAPI()
|
||||
|
||||
@ -134,6 +141,6 @@ func main() {
|
||||
fmt.Println(" -", mod.Target)
|
||||
}
|
||||
default:
|
||||
fmt.Printf("Unknown command, use '%s help' for a list of commands.\n", os.Args[0])
|
||||
fmt.Println("Unknown command, use 'r2go help' for a list of commands.")
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ func ExposeModString(input string) string {
|
||||
}
|
||||
|
||||
// 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
|
||||
// DownlaodMod returns 2 if the mod updated, and 3 if the mod could not be found.
|
||||
func DownloadMod(depString string) (int, string) {
|
||||
var status int
|
||||
var modver string
|
||||
@ -28,7 +30,10 @@ func DownloadMod(depString string) (int, string) {
|
||||
}
|
||||
|
||||
sysinfo := utils.GetSysInfo()
|
||||
mod := api.GetModData(depString)
|
||||
status, mod := api.GetModData(depString)
|
||||
if status != 0 {
|
||||
return 3, "not_found"
|
||||
}
|
||||
downloadURL := mod.Versions[0].DownloadURL
|
||||
|
||||
modName := sysinfo.ProgDir + "/dl/" + depString + ".zip"
|
||||
@ -37,10 +42,12 @@ func DownloadMod(depString string) (int, string) {
|
||||
modFolder := sysinfo.PluginDir + "/" + depString + "-" + modVersion
|
||||
|
||||
if utils.PathExists(modFolder) {
|
||||
|
||||
return 1, modver
|
||||
}
|
||||
|
||||
if len(api.GetModData(depString).Versions) >= 2 {
|
||||
status, mod = api.GetModData(depString)
|
||||
if len(mod.Versions) >= 2 {
|
||||
modVersionOld := mod.Versions[1].VersionNumber
|
||||
modFolderOld := sysinfo.PluginDir + "/" + depString + "-" + modVersionOld
|
||||
|
||||
@ -49,7 +56,7 @@ func DownloadMod(depString string) (int, string) {
|
||||
status = 2
|
||||
modver = modVersion
|
||||
} else {
|
||||
status = 3
|
||||
status = 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,8 +78,11 @@ func DownloadMod(depString string) (int, string) {
|
||||
|
||||
// RemoveMod uninstalls a mod
|
||||
func RemoveMod(depString string) int {
|
||||
modVersion := api.GetModData(depString).Versions[0].VersionNumber
|
||||
modFolder := utils.SystemInfo.PluginDir + "/" + depString + "-" + modVersion
|
||||
status, mod := api.GetModData(depString)
|
||||
if status != 0 {
|
||||
fmt.Println("> Could not find the mod specified.")
|
||||
}
|
||||
modFolder := utils.SystemInfo.PluginDir + "/" + depString + "-" + mod.Versions[0].VersionNumber
|
||||
|
||||
if !utils.PathExists(modFolder) {
|
||||
return 1
|
||||
|
Loading…
Reference in New Issue
Block a user