From bb74c4f4aa682906017f66af292cce94ad673b66 Mon Sep 17 00:00:00 2001 From: giwty <0b@LonXm#fkv> Date: Tue, 28 Jul 2020 15:17:03 -0700 Subject: [PATCH] Rename to switch library manager More fixes --- README.md | 12 ++++++------ db/localSwitchFilesDB.go | 4 ++-- go.mod | 2 +- main.go | 4 ++-- process/incompleteTitleProcessor.go | 4 ++-- process/organizefolderStructure.go | 4 ++-- settings/settings.go | 22 +++++++++++----------- switchfs/nca.go | 4 ++-- switchfs/ncaHeader.go | 2 +- ui/console.go | 8 ++++---- ui/gui.go | 28 +++++++++++----------------- 11 files changed, 44 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 9486ff6..cb77234 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ The following template elements are supported: - Double click the Exe file - If you want to use command line mode, update the settings.json with `'GUI':false` - Open `cmd` - - Run `switch-backup-manager.exe` + - Run `switch-library-manager.exe` - Optionally -f `X:\folder\containing\nsp\files"` - Optionally add `-r` to recursively scan for nested folders - Edit the settings.json file for additional options @@ -75,18 +75,18 @@ The following template elements are supported: - Double click the App file - If you want to use command line mode, update the settings.json with `'GUI':false` - Open your Terminal - - `cd` to the folder containing `switch-backup-manager` - - `chmod +x switch-backup-manager` to make it executable - - Run `./switch-backup-manager' + - `cd` to the folder containing `switch-library-manager` + - `chmod +x switch-library-manager` to make it executable + - Run `./switch-library-manager' - Optionally -f `X:\folder\containing\nsp\files"` - Optionally add `-r` to recursively scan for nested folders - Edit the settings.json file for additional options ## Building - Install and setup latest Go -- Get the module and its dependencies: `go get -u github.com/giwty/switch-backup-manager` +- Get the module and its dependencies: `go get -u github.com/giwty/switch-library-manager` - Build it for the OS you need, and make sure to choose `amd64` architecture: - - `env GOOS=target-OS GOARCH=amd64 go build github.com/giwty/switch-backup-manager` + - `env GOOS=target-OS GOARCH=amd64 go build github.com/giwty/switch-library-manager` - `target-OS` can be `windows`, `darwin` (mac OS), `linux`, or any other (check the Go documentation for a complete list). #### Thanks diff --git a/db/localSwitchFilesDB.go b/db/localSwitchFilesDB.go index 30fb49a..79007d7 100644 --- a/db/localSwitchFilesDB.go +++ b/db/localSwitchFilesDB.go @@ -2,8 +2,8 @@ package db import ( "errors" - "github.com/giwty/switch-backup-manager/settings" - "github.com/giwty/switch-backup-manager/switchfs" + "github.com/giwty/switch-library-manager/settings" + "github.com/giwty/switch-library-manager/switchfs" "go.uber.org/zap" "io/ioutil" "os" diff --git a/go.mod b/go.mod index 7cded0d..1591b25 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/giwty/switch-backup-manager +module github.com/giwty/switch-library-manager go 1.12 diff --git a/main.go b/main.go index f4ead00..d1dccb2 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "github.com/giwty/switch-backup-manager/settings" - "github.com/giwty/switch-backup-manager/ui" + "github.com/giwty/switch-library-manager/settings" + "github.com/giwty/switch-library-manager/ui" "go.uber.org/zap" "os" "path" diff --git a/process/incompleteTitleProcessor.go b/process/incompleteTitleProcessor.go index 5bb0e3c..943dd4e 100644 --- a/process/incompleteTitleProcessor.go +++ b/process/incompleteTitleProcessor.go @@ -2,8 +2,8 @@ package process import ( "fmt" - "github.com/giwty/switch-backup-manager/db" - "github.com/giwty/switch-backup-manager/switchfs" + "github.com/giwty/switch-library-manager/db" + "github.com/giwty/switch-library-manager/switchfs" "go.uber.org/zap" "sort" "strconv" diff --git a/process/organizefolderStructure.go b/process/organizefolderStructure.go index cf22dbd..2be52e7 100644 --- a/process/organizefolderStructure.go +++ b/process/organizefolderStructure.go @@ -1,8 +1,8 @@ package process import ( - "github.com/giwty/switch-backup-manager/db" - "github.com/giwty/switch-backup-manager/settings" + "github.com/giwty/switch-library-manager/db" + "github.com/giwty/switch-library-manager/settings" "go.uber.org/zap" "io/ioutil" "os" diff --git a/settings/settings.go b/settings/settings.go index 1cb1346..ca4f64f 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -55,11 +55,11 @@ type AppSettings struct { GuiPagingSize int `json:"gui_page_size"` } -func ReadSettingsAsJSON() string { - if _, err := os.Stat(SETTINGS_FILENAME); err != nil { - saveDefaultSettings() +func ReadSettingsAsJSON(baseFolder string) string { + if _, err := os.Stat(path.Join(baseFolder, SETTINGS_FILENAME)); err != nil { + saveDefaultSettings(baseFolder) } - file, _ := os.Open("./" + SETTINGS_FILENAME) + file, _ := os.Open(path.Join(baseFolder, SETTINGS_FILENAME)) bytes, _ := ioutil.ReadAll(file) return string(bytes) } @@ -69,21 +69,21 @@ func ReadSettings(baseFolder string) *AppSettings { return settingsInstance } settingsInstance = &AppSettings{Debug: false, GuiPagingSize: 100} - if _, err := os.Stat(SETTINGS_FILENAME); err == nil { + if _, err := os.Stat(path.Join(baseFolder, SETTINGS_FILENAME)); err == nil { file, err := os.Open(path.Join(baseFolder, SETTINGS_FILENAME)) if err != nil { zap.S().Warnf("Missing or corrupted config file, creating a new one") - return saveDefaultSettings() + return saveDefaultSettings(baseFolder) } else { _ = json.NewDecoder(file).Decode(&settingsInstance) return settingsInstance } } else { - return saveDefaultSettings() + return saveDefaultSettings(baseFolder) } } -func saveDefaultSettings() *AppSettings { +func saveDefaultSettings(baseFolder string) *AppSettings { settingsInstance = &AppSettings{ TitlesEtag: "W/\"7cda5dea264d61:0\"", VersionsEtag: "W/\"413d981bf65ed61:0\"", @@ -104,12 +104,12 @@ func saveDefaultSettings() *AppSettings { DeleteOldUpdateFiles: false, }, } - return SaveSettings(settingsInstance) + return SaveSettings(settingsInstance, baseFolder) } -func SaveSettings(settings *AppSettings) *AppSettings { +func SaveSettings(settings *AppSettings, baseFolder string) *AppSettings { file, _ := json.MarshalIndent(settings, "", " ") - _ = ioutil.WriteFile(SETTINGS_FILENAME, file, 0644) + _ = ioutil.WriteFile(path.Join(baseFolder, SETTINGS_FILENAME), file, 0644) settingsInstance = settings return settings } diff --git a/switchfs/nca.go b/switchfs/nca.go index e64d82e..3b4d304 100644 --- a/switchfs/nca.go +++ b/switchfs/nca.go @@ -7,8 +7,8 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/giwty/switch-backup-manager/settings" - "github.com/giwty/switch-backup-manager/switchfs/_crypto" + "github.com/giwty/switch-library-manager/settings" + "github.com/giwty/switch-library-manager/switchfs/_crypto" "io" ) diff --git a/switchfs/ncaHeader.go b/switchfs/ncaHeader.go index 8bcf5a2..7754fbd 100644 --- a/switchfs/ncaHeader.go +++ b/switchfs/ncaHeader.go @@ -4,7 +4,7 @@ import ( "crypto/aes" "encoding/binary" "encoding/hex" - "github.com/giwty/switch-backup-manager/switchfs/_crypto" + "github.com/giwty/switch-library-manager/switchfs/_crypto" "strconv" ) diff --git a/ui/console.go b/ui/console.go index d02588b..3ede946 100644 --- a/ui/console.go +++ b/ui/console.go @@ -4,9 +4,9 @@ import ( "flag" "fmt" "github.com/briandowns/spinner" - "github.com/giwty/switch-backup-manager/db" - "github.com/giwty/switch-backup-manager/process" - "github.com/giwty/switch-backup-manager/settings" + "github.com/giwty/switch-library-manager/db" + "github.com/giwty/switch-library-manager/process" + "github.com/giwty/switch-library-manager/settings" "github.com/jedib0t/go-pretty/table" "go.uber.org/zap" "io/ioutil" @@ -64,7 +64,7 @@ func (c *Console) Start() { } //3. update the config file with new etag - settings.SaveSettings(settingsObj) + settings.SaveSettings(settingsObj, c.baseFolder) //4. create switch title db titlesDB, err := db.CreateSwitchTitleDB(titleFile, versionsFile) diff --git a/ui/gui.go b/ui/gui.go index 0f8d696..f935889 100644 --- a/ui/gui.go +++ b/ui/gui.go @@ -4,9 +4,9 @@ import ( "encoding/json" "fmt" "github.com/asticode/go-astilog" - "github.com/giwty/switch-backup-manager/db" - "github.com/giwty/switch-backup-manager/process" - "github.com/giwty/switch-backup-manager/settings" + "github.com/giwty/switch-library-manager/db" + "github.com/giwty/switch-library-manager/process" + "github.com/giwty/switch-library-manager/settings" "go.uber.org/zap" "io/ioutil" "os" @@ -63,17 +63,9 @@ func (g *GUI) Start() { return } - logFilePath := path.Join(g.baseFolder, "slm-gui.log") - file, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - g.sugarLogger.Error("Failed to create log file", err) - } - defer file.Close() - //l := log.New(file, log.Prefix(), log.Flags()) logger := astilog.New(astilog.Configuration{ - Filename: logFilePath, - Level: astilog.LevelWarn, + Level: astilog.LevelInfo, }) // Create astilectron @@ -242,33 +234,35 @@ func (g *GUI) getMissingUpdates() string { } func (g *GUI) loadSettings() string { - return settings.ReadSettingsAsJSON() + return settings.ReadSettingsAsJSON(g.baseFolder) } func (g *GUI) saveSettings(settingsJson string) { s := settings.AppSettings{} json.Unmarshal([]byte(settingsJson), &s) - settings.SaveSettings(&s) + settings.SaveSettings(&s, g.baseFolder) } func (g *GUI) buildSwitchDb() (*db.SwitchTitlesDB, error) { settingsObj := settings.ReadSettings(g.baseFolder) //1. load the titles JSON object g.UpdateProgress(1, 4, "Downloading titles.json") - titleFile, titlesEtag, err := db.LoadAndUpdateFile(settings.TITLES_JSON_URL, settings.TITLE_JSON_FILENAME, settingsObj.TitlesEtag) + filename := path.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 } settingsObj.TitlesEtag = titlesEtag g.UpdateProgress(2, 4, "Downloading versions.json") - versionsFile, versionsEtag, err := db.LoadAndUpdateFile(settings.VERSIONS_JSON_URL, settings.VERSIONS_JSON_FILENAME, settingsObj.VersionsEtag) + filename = path.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 } settingsObj.VersionsEtag = versionsEtag - settings.SaveSettings(settingsObj) + settings.SaveSettings(settingsObj, g.baseFolder) g.UpdateProgress(3, 4, "Building titles DB ...") switchTitleDB, err := db.CreateSwitchTitleDB(titleFile, versionsFile)