Ignore cached file data, re-request it

This commit is contained in:
comp500 2019-09-19 18:12:21 +01:00
parent fd9ecbe6d4
commit 47a2dccffe

View File

@ -24,8 +24,8 @@ type importPackMetadata interface {
Name() string Name() string
Versions() map[string]string Versions() map[string]string
Mods() []struct { Mods() []struct {
ID int ModID int
File modFileInfo FileID int
} }
GetFiles() ([]importPackFile, error) GetFiles() ([]importPackFile, error)
} }
@ -111,7 +111,7 @@ var importCmd = &cobra.Command{
modsList := packImport.Mods() modsList := packImport.Mods()
modIDs := make([]int, len(modsList)) modIDs := make([]int, len(modsList))
for i, v := range modsList { for i, v := range modsList {
modIDs[i] = v.ID modIDs[i] = v.ModID
} }
fmt.Println("Querying Curse API for mod info...") fmt.Println("Querying Curse API for mod info...")
@ -128,26 +128,42 @@ var importCmd = &cobra.Command{
} }
// TODO: multithreading???? // TODO: multithreading????
successes := 0
for _, v := range modsList { for _, v := range modsList {
modInfoValue, ok := modInfosMap[v.ID] modInfoValue, ok := modInfosMap[v.ModID]
if !ok { if !ok {
if len(v.File.FriendlyName) > 0 { fmt.Printf("Failed to obtain mod information for ID %d\n", v.ModID)
fmt.Printf("Failed to obtain mod information for \"%s\"\n", v.File.FriendlyName)
} else {
fmt.Printf("Failed to obtain mod information for \"%s\"\n", v.File.FileName)
}
continue continue
} }
fmt.Printf("Imported mod \"%s\" successfully!\n", modInfoValue.Name) found := false
var fileInfo modFileInfo
for _, fileInfo = range modInfoValue.LatestFiles {
if fileInfo.ID == v.FileID {
found = true
break
}
}
if !found {
fileInfo, err = getFileInfo(v.ModID, v.FileID)
if !ok {
fmt.Printf("Failed to obtain file information for Mod / File %d / %d: %s\n", v.ModID, v.FileID, err)
continue
}
}
err = createModFile(modInfoValue, v.File, &index) err = createModFile(modInfoValue, fileInfo, &index)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
fmt.Printf("Imported mod \"%s\" successfully!\n", modInfoValue.Name)
successes++
} }
fmt.Printf("Successfully imported %d/%d mods!\n", successes, len(modsList))
// TODO: import existing files (config etc.) // TODO: import existing files (config etc.)
err = index.Write() err = index.Write()
@ -212,8 +228,11 @@ type twitchInstalledPackMeta struct {
} `json:"baseModLoader"` } `json:"baseModLoader"`
ModpackOverrides []string `json:"modpackOverrides"` ModpackOverrides []string `json:"modpackOverrides"`
ModsInternal []struct { ModsInternal []struct {
ID int `json:"addonID"` ID int `json:"addonID"`
File modFileInfo `json:"installedFile"` File struct {
// I've given up on using this cached data, just going to re-request it
ID int `json:"id"`
} `json:"installedFile"`
} `json:"installedAddons"` } `json:"installedAddons"`
// Used to determine if modpackOverrides should be used or not // Used to determine if modpackOverrides should be used or not
IsUnlocked bool `json:"isUnlocked"` IsUnlocked bool `json:"isUnlocked"`
@ -237,13 +256,23 @@ func (m twitchInstalledPackMeta) Versions() map[string]string {
} }
func (m twitchInstalledPackMeta) Mods() []struct { func (m twitchInstalledPackMeta) Mods() []struct {
ID int ModID int
File modFileInfo FileID int
} { } {
return []struct { list := make([]struct {
ID int ModID int
File modFileInfo FileID int
}(m.ModsInternal) }, len(m.ModsInternal))
for i, v := range m.ModsInternal {
list[i] = struct {
ModID int
FileID int
}{
ModID: v.ID,
FileID: v.File.ID,
}
}
return list
} }
func (m twitchInstalledPackMeta) GetFiles() ([]importPackFile, error) { func (m twitchInstalledPackMeta) GetFiles() ([]importPackFile, error) {