diff --git a/gui.go b/gui.go index 8139700..43e5445 100644 --- a/gui.go +++ b/gui.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "github.com/asticode/go-astikit" "github.com/asticode/go-astilectron" @@ -29,16 +30,16 @@ type LocalLibraryData struct { } type LibraryTemplateData struct { - Id int `json:"id"` - Name string `json:"name"` - Version string `json:"version"` - Dlc string `json:"dlc"` - TitleId string `json:"titleId"` - Path string `json:"path"` - Icon string `json:"icon"` - Update int `json:"update"` - MultiContent bool `json:"multi_content"` - Split bool `json:"split"` + Id int `json:"id"` + Name string `json:"name"` + Version string `json:"version"` + Dlc string `json:"dlc"` + TitleId string `json:"titleId"` + Path string `json:"path"` + Icon string `json:"icon"` + Update int `json:"update"` + Region string `json:"region"` + Type string `json:"type"` } type ProgressUpdate struct { @@ -221,17 +222,19 @@ func (g *GUI) handleMessage(m *astilectron.EventMessage) interface{} { } } if title, ok := g.state.switchDB.TitlesMap[k]; ok { - + if title.Attributes.Name != "" { + name = title.Attributes.Name + } libraryData = append(libraryData, LibraryTemplateData{ - Icon: title.Attributes.IconUrl, - Name: title.Attributes.Name, - TitleId: v.File.Metadata.TitleId, - Update: v.LatestUpdate, - Version: version, - MultiContent: v.MultiContent, - Split: v.IsSplit, - Path: filepath.Join(v.File.ExtendedInfo.BaseFolder, v.File.ExtendedInfo.Info.Name()), + Icon: title.Attributes.IconUrl, + Name: name, + TitleId: v.File.Metadata.TitleId, + Update: v.LatestUpdate, + Version: version, + Region: title.Attributes.Region, + Type: getType(v), + Path: filepath.Join(v.File.ExtendedInfo.BaseFolder, v.File.ExtendedInfo.Info.Name()), }) } else { if name == "" { @@ -239,12 +242,12 @@ func (g *GUI) handleMessage(m *astilectron.EventMessage) interface{} { } libraryData = append(libraryData, LibraryTemplateData{ - Name: name, - Update: v.LatestUpdate, - Version: version, - MultiContent: v.MultiContent, - TitleId: v.File.Metadata.TitleId, - Path: v.File.ExtendedInfo.Info.Name(), + Name: name, + Update: v.LatestUpdate, + Version: version, + Type: getType(v), + TitleId: v.File.Metadata.TitleId, + Path: v.File.ExtendedInfo.Info.Name(), }) } @@ -258,7 +261,7 @@ func (g *GUI) handleMessage(m *astilectron.EventMessage) interface{} { } } for k, v := range localDB.Skipped { - issues = append(issues, Pair{Key: filepath.Join(k.BaseFolder, k.Info.Name()), Value: v}) + issues = append(issues, Pair{Key: filepath.Join(k.BaseFolder, k.Info.Name()), Value: v.ReasonText}) } response.LibraryData = libraryData @@ -295,6 +298,20 @@ func (g *GUI) handleMessage(m *astilectron.EventMessage) interface{} { return retValue } +func getType(gameFile *db.SwitchGameFiles) string { + if gameFile.IsSplit { + return "split" + } + if gameFile.MultiContent { + return "multi-content" + } + ext := filepath.Ext(gameFile.File.ExtendedInfo.Info.Name()) + if len(ext) > 1 { + return ext[1:] + } + return "" +} + func (g *GUI) saveSettings(settingsJson string) error { s := settings.AppSettings{} err := json.Unmarshal([]byte(settingsJson), &s) @@ -342,7 +359,7 @@ func (g *GUI) buildSwitchDb() (*db.SwitchTitlesDB, error) { filename := filepath.Join(g.baseFolder, settings.TITLE_JSON_FILENAME) titleFile, titlesEtag, err := db.LoadAndUpdateFile(settings.TITLES_JSON_URL, filename, settingsObj.TitlesEtag) if err != nil { - return nil, err + return nil, errors.New("failed to download switch titles [reason:" + err.Error() + "]") } settingsObj.TitlesEtag = titlesEtag @@ -350,7 +367,7 @@ func (g *GUI) buildSwitchDb() (*db.SwitchTitlesDB, error) { filename = filepath.Join(g.baseFolder, settings.VERSIONS_JSON_FILENAME) versionsFile, versionsEtag, err := db.LoadAndUpdateFile(settings.VERSIONS_JSON_URL, filename, settingsObj.VersionsEtag) if err != nil { - return nil, err + return nil, errors.New("failed to download switch updates [reason:" + err.Error() + "]") } settingsObj.VersionsEtag = versionsEtag @@ -377,13 +394,13 @@ func (g *GUI) organizeLibrary() { folderToScan := settings.ReadSettings(g.baseFolder).Folder process.OrganizeByFolders(folderToScan, g.state.localDB, g.state.switchDB, g) if settings.ReadSettings(g.baseFolder).OrganizeOptions.DeleteOldUpdateFiles { - process.DeleteOldUpdates(g.state.localDB, g) + process.DeleteOldUpdates(g.baseFolder, g.state.localDB, g) } } func (g *GUI) UpdateProgress(curr int, total int, message string) { progressMessage := ProgressUpdate{curr, total, message} - g.sugarLogger.Debugf("process %v (%v/%v)", message, curr, total) + g.sugarLogger.Debugf("%v (%v/%v)", message, curr, total) msg, err := json.Marshal(progressMessage) if err != nil { g.sugarLogger.Error(err) diff --git a/resources/app/app.js b/resources/app/app.js index 65694b2..6552d3f 100644 --- a/resources/app/app.js +++ b/resources/app/app.js @@ -200,7 +200,7 @@ $(function () { let table = new Tabulator("#dlc-table", { layout:"fitDataStretch", initialSort:[ - {column:"name", dir:"desc"}, //sort by this first + {column:"Attributes.name", dir:"asc"}, //sort by this first ], pagination: "local", paginationSize: state.settings.gui_page_size, @@ -262,7 +262,7 @@ $(function () { if (state.library && state.library.library_data.length) { var table = new Tabulator("#library-table", { initialSort:[ - {column:"name", dir:"desc"}, //sort by this first + {column:"name", dir:"asc"}, //sort by this first ], layout:"fitDataStretch", pagination: "local", @@ -273,8 +273,8 @@ $(function () { {field: "icon",formatter:"image", headerSort:false,formatterParams:{height:"60px", width:"60px"}}, {title: "Title", field: "name", headerFilter:"input",formatter:"textarea",width:350}, {title: "Title id", headerSort:false, field: "titleId"}, - {title: "Multi content", headerSort:false, field: "multi_content"}, - {title: "Split", headerSort:false, field: "split"}, + {title: "Region", headerSort:true, field: "region"}, + {title: "Type", headerSort:true, field: "type"}, {title: "Update", headerSort:false, field: "update"}, {title: "Version", headerSort:false, field: "version"}, {title: "File name", headerSort:false, field: "path",formatter:"textarea",cellClick:function(e, cell){ @@ -326,7 +326,11 @@ $(function () { sendMessage("organize", "", (r => { $(".progress-container").hide(); - loadTab("#organize"); + state.library = undefined; + state.updates = undefined; + state.dlc = undefined; + loadTab("#library"); + scanLocalFolder() dialog.showMessageBox(null, { type: 'info', buttons: ['Ok'], diff --git a/settings/settings.go b/settings/settings.go index fba94cb..82abcf1 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -19,10 +19,12 @@ const ( SETTINGS_FILENAME = "settings.json" TITLE_JSON_FILENAME = "titles.json" VERSIONS_JSON_FILENAME = "versions.json" - SLM_VERSION = "1.3.5" + SLM_VERSION = "1.3.7" TITLES_JSON_URL = "https://tinfoil.media/repo/db/titles.json" - VERSIONS_JSON_URL = "https://tinfoil.media/repo/db/versions.json" - SLM_VERSION_URL = "https://raw.githubusercontent.com/giwty/switch-library-manager/master/slm.json" + //TITLES_JSON_URL = "https://raw.githubusercontent.com/blawar/titledb/master/titles.US.en.json" + VERSIONS_JSON_URL = "https://tinfoil.media/repo/db/versions.json" + //VERSIONS_JSON_URL = "https://raw.githubusercontent.com/blawar/titledb/master/versions.json" + SLM_VERSION_URL = "https://raw.githubusercontent.com/giwty/switch-library-manager/master/slm.json" ) const ( @@ -30,6 +32,7 @@ const ( TEMPLATE_TITLE_NAME = "TITLE_NAME" TEMPLATE_DLC_NAME = "DLC_NAME" TEMPLATE_VERSION = "VERSION" + TEMPLATE_REGION = "REGION" TEMPLATE_VERSION_TXT = "VERSION_TXT" TEMPLATE_TYPE = "TYPE" )