Skip to content

Commit

Permalink
added option to ignore dlc updates (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
trembon authored Feb 19, 2024
1 parent 100c783 commit 1179d59
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
6 changes: 3 additions & 3 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (c *Console) Start() {

if settingsObj.CheckForMissingUpdates {
fmt.Printf("\nChecking for missing updates\n")
c.processMissingUpdates(localDB, titlesDB)
c.processMissingUpdates(localDB, titlesDB, settingsObj)
}

if settingsObj.CheckForMissingDLC {
Expand Down Expand Up @@ -166,8 +166,8 @@ func (c *Console) processIssues(localDB *db.LocalSwitchFilesDB) {
t.Render()
}

func (c *Console) processMissingUpdates(localDB *db.LocalSwitchFilesDB, titlesDB *db.SwitchTitlesDB) {
incompleteTitles := process.ScanForMissingUpdates(localDB.TitlesMap, titlesDB.TitlesMap)
func (c *Console) processMissingUpdates(localDB *db.LocalSwitchFilesDB, titlesDB *db.SwitchTitlesDB, settingsObj *settings.AppSettings) {
incompleteTitles := process.ScanForMissingUpdates(localDB.TitlesMap, titlesDB.TitlesMap, settingsObj.IgnoreDLCUpdates)
if len(incompleteTitles) != 0 {
fmt.Print("\nFound available updates:\n\n")
} else {
Expand Down
3 changes: 2 additions & 1 deletion gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ func (g *GUI) getMissingDLC() string {
}

func (g *GUI) getMissingUpdates() string {
missingUpdates := process.ScanForMissingUpdates(g.state.localDB.TitlesMap, g.state.switchDB.TitlesMap)
settingsObj := settings.ReadSettings(g.baseFolder)
missingUpdates := process.ScanForMissingUpdates(g.state.localDB.TitlesMap, g.state.switchDB.TitlesMap, settingsObj.IgnoreDLCUpdates)
values := make([]process.IncompleteTitle, len(missingUpdates))
i := 0
for _, missingUpdate := range missingUpdates {
Expand Down
60 changes: 32 additions & 28 deletions process/incompleteTitleProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package process

import (
"fmt"
"sort"
"strconv"

"github.com/giwty/switch-library-manager/db"
"github.com/giwty/switch-library-manager/switchfs"
"go.uber.org/zap"
"sort"
"strconv"
)

type IncompleteTitle struct {
Expand All @@ -19,14 +20,14 @@ type IncompleteTitle struct {
}

func ScanForMissingUpdates(localDB map[string]*db.SwitchGameFiles,
switchDB map[string]*db.SwitchTitle) map[string]IncompleteTitle {
switchDB map[string]*db.SwitchTitle, ignoreDLCupdates bool) map[string]IncompleteTitle {

result := map[string]IncompleteTitle{}

//iterate over local files, and compare to remote versions
for idPrefix, switchFile := range localDB {

if switchFile.BaseExist == false {
if !switchFile.BaseExist {
zap.S().Infof("missing base for game %v", idPrefix)
continue
}
Expand All @@ -36,6 +37,7 @@ func ScanForMissingUpdates(localDB map[string]*db.SwitchGameFiles,
}

switchTitle := IncompleteTitle{Attributes: switchDB[idPrefix].Attributes, Meta: switchFile.File.Metadata}

//sort the available local versions
localVersions := make([]int, len(switchFile.Updates))
i := 0
Expand Down Expand Up @@ -73,32 +75,34 @@ func ScanForMissingUpdates(localDB map[string]*db.SwitchGameFiles,
}

//process dlc
for k, availableDlc := range switchDB[idPrefix].Dlc {
if !ignoreDLCupdates {
for k, availableDlc := range switchDB[idPrefix].Dlc {

if localDlc, ok := switchFile.Dlc[k]; ok {
latestDlcVersion, err := availableDlc.Version.Int64()
if err != nil {
continue
}
if localDlc, ok := switchFile.Dlc[k]; ok {
latestDlcVersion, err := availableDlc.Version.Int64()
if err != nil {
continue
}

if localDlc.Metadata == nil {
continue
}
if localDlc.Metadata.Version < int(latestDlcVersion) {
updateDate := "-"
if availableDlc.ReleaseDate != 0 {
updateDate = strconv.Itoa(availableDlc.ReleaseDate)
if len(updateDate) > 7 {
updateDate = updateDate[0:4] + "-" + updateDate[4:6] + "-" + updateDate[6:]
}
if localDlc.Metadata == nil {
continue
}
if localDlc.Metadata.Version < int(latestDlcVersion) {
updateDate := "-"
if availableDlc.ReleaseDate != 0 {
updateDate = strconv.Itoa(availableDlc.ReleaseDate)
if len(updateDate) > 7 {
updateDate = updateDate[0:4] + "-" + updateDate[4:6] + "-" + updateDate[6:]
}
}

result[availableDlc.Id] = IncompleteTitle{
Attributes: availableDlc,
LatestUpdate: int(latestDlcVersion),
LocalUpdate: localDlc.Metadata.Version,
LatestUpdateDate: updateDate,
Meta: localDlc.Metadata}
result[availableDlc.Id] = IncompleteTitle{
Attributes: availableDlc,
LatestUpdate: int(latestDlcVersion),
LocalUpdate: localDlc.Metadata.Version,
LatestUpdateDate: updateDate,
Meta: localDlc.Metadata}
}
}
}
}
Expand All @@ -114,7 +118,7 @@ func ScanForMissingDLC(localDB map[string]*db.SwitchGameFiles,
//iterate over local files, and compare to remote versions
for idPrefix, switchFile := range localDB {

if switchFile.BaseExist == false {
if !switchFile.BaseExist {
continue
}

Expand Down Expand Up @@ -148,7 +152,7 @@ func ScanForBrokenFiles(localDB map[string]*db.SwitchGameFiles) []db.SwitchFileI
//iterate over local files, and compare to remote versions
for _, switchFile := range localDB {

if switchFile.BaseExist == false {
if !switchFile.BaseExist {
for _, f := range switchFile.Dlc {
result = append(result, f)
}
Expand Down
2 changes: 2 additions & 0 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type AppSettings struct {
OrganizeOptions OrganizeOptions `json:"organize_options"`
ScanRecursively bool `json:"scan_recursively"`
GuiPagingSize int `json:"gui_page_size"`
IgnoreDLCUpdates bool `json:"ignore_dlc_updates"`
IgnoreDLCTitleIds []string `json:"ignore_dlc_title_ids"`
}

Expand Down Expand Up @@ -99,6 +100,7 @@ func saveDefaultSettings(baseFolder string) *AppSettings {
Folder: "",
ScanFolders: []string{},
IgnoreDLCTitleIds: []string{},
IgnoreDLCUpdates: false,
GUI: true,
GuiPagingSize: 100,
CheckForMissingUpdates: true,
Expand Down

0 comments on commit 1179d59

Please sign in to comment.