Skip to content

Commit

Permalink
read titles/versions urls from settings.json #23
Browse files Browse the repository at this point in the history
  • Loading branch information
trembon committed Apr 9, 2024
1 parent 743c35b commit 0aa7eff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Console) Start() {
progressBar = progressbar.New(2)

filename := filepath.Join(c.baseFolder, settings.TITLE_JSON_FILENAME)
titleFile, titlesEtag, err := db.LoadAndUpdateFile(settings.TITLES_JSON_URL, filename, settingsObj.TitlesEtag)
titleFile, titlesEtag, err := db.LoadAndUpdateFile(settingsObj.TitlesJsonUrl, filename, settingsObj.TitlesEtag)
if err != nil {
fmt.Printf("title json file doesn't exist\n")
return
Expand All @@ -63,7 +63,7 @@ func (c *Console) Start() {
progressBar.Add(1)
//2. load the versions JSON object
filename = filepath.Join(c.baseFolder, settings.VERSIONS_JSON_FILENAME)
versionsFile, versionsEtag, err := db.LoadAndUpdateFile(settings.VERSIONS_JSON_URL, filename, settingsObj.VersionsEtag)
versionsFile, versionsEtag, err := db.LoadAndUpdateFile(settingsObj.VersionsJsonUrl, filename, settingsObj.VersionsEtag)
if err != nil {
fmt.Printf("version json file doesn't exist\n")
return
Expand Down
4 changes: 2 additions & 2 deletions src/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ func (g *GUI) buildSwitchDb() (*db.SwitchTitlesDB, error) {
//1. load the titles JSON object
g.UpdateProgress(1, 4, "Downloading titles.json")
filename := filepath.Join(g.baseFolder, settings.TITLE_JSON_FILENAME)
titleFile, titlesEtag, err := db.LoadAndUpdateFile(settings.TITLES_JSON_URL, filename, settingsObj.TitlesEtag)
titleFile, titlesEtag, err := db.LoadAndUpdateFile(settingsObj.TitlesJsonUrl, filename, settingsObj.TitlesEtag)
if err != nil {
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)
versionsFile, versionsEtag, err := db.LoadAndUpdateFile(settingsObj.VersionsJsonUrl, filename, settingsObj.VersionsEtag)
if err != nil {
return nil, errors.New("failed to download switch updates [reason:" + err.Error() + "]")
}
Expand Down
18 changes: 11 additions & 7 deletions src/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ var (
)

const (
SETTINGS_FILENAME = "settings.json"
TITLE_JSON_FILENAME = "titles.json"
VERSIONS_JSON_FILENAME = "versions.json"
SLM_VERSION = "1.5.0"
TITLES_JSON_URL = "https://tinfoil.media/repo/db/titles.json"
VERSIONS_JSON_URL = "https://raw.githubusercontent.com/blawar/titledb/master/versions.json"
SLM_VERSION_URL = "https://raw.githubusercontent.com/trembon/switch-library-manager/master/version.json"
SETTINGS_FILENAME = "settings.json"
TITLE_JSON_FILENAME = "titles.json"
VERSIONS_JSON_FILENAME = "versions.json"
SLM_VERSION = "1.5.0"
DEFAULT_TITLES_JSON_URL = "https://tinfoil.media/repo/db/titles.json"
DEFAULT_VERSIONS_JSON_URL = "https://raw.githubusercontent.com/blawar/titledb/master/versions.json"
SLM_VERSION_URL = "https://raw.githubusercontent.com/trembon/switch-library-manager/master/version.json"
)

const (
Expand All @@ -47,7 +47,9 @@ type OrganizeOptions struct {
}

type AppSettings struct {
VersionsJsonUrl string `json:"versions_json_url"`
VersionsEtag string `json:"versions_etag"`
TitlesJsonUrl string `json:"titles_json_url"`
TitlesEtag string `json:"titles_etag"`
Prodkeys string `json:"prod_keys"`
Folder string `json:"folder"`
Expand Down Expand Up @@ -95,7 +97,9 @@ func ReadSettings(baseFolder string) *AppSettings {

func saveDefaultSettings(baseFolder string) *AppSettings {
settingsInstance = &AppSettings{
TitlesJsonUrl: DEFAULT_TITLES_JSON_URL,
TitlesEtag: "W/\"a5b02845cf6bd61:0\"",
VersionsJsonUrl: DEFAULT_VERSIONS_JSON_URL,
VersionsEtag: "W/\"2ef50d1cb6bd61:0\"",
Folder: "",
ScanFolders: []string{},
Expand Down

0 comments on commit 0aa7eff

Please sign in to comment.