Skip to content

Commit

Permalink
add support for region
Browse files Browse the repository at this point in the history
  • Loading branch information
giwty authored and giwty committed Oct 6, 2020
1 parent ec7020e commit ba2a8b8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 38 deletions.
77 changes: 47 additions & 30 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"github.com/asticode/go-astikit"
"github.com/asticode/go-astilectron"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -221,30 +222,32 @@ 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 == "" {
name = db.ParseTitleNameFromFileName(v.File.ExtendedInfo.Info.Name())
}
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(),
})
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -342,15 +359,15 @@ 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

g.UpdateProgress(2, 4, "Downloading versions.json")
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

Expand All @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions resources/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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){
Expand Down Expand Up @@ -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'],
Expand Down
9 changes: 6 additions & 3 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ 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 (
TEMPLATE_TITLE_ID = "TITLE_ID"
TEMPLATE_TITLE_NAME = "TITLE_NAME"
TEMPLATE_DLC_NAME = "DLC_NAME"
TEMPLATE_VERSION = "VERSION"
TEMPLATE_REGION = "REGION"
TEMPLATE_VERSION_TXT = "VERSION_TXT"
TEMPLATE_TYPE = "TYPE"
)
Expand Down

0 comments on commit ba2a8b8

Please sign in to comment.