Skip to content

Commit

Permalink
Rename to switch library manager
Browse files Browse the repository at this point in the history
More fixes
  • Loading branch information
giwty authored and giwty committed Jul 28, 2020
1 parent d40c1d7 commit bb74c4f
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 50 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions db/localSwitchFilesDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/giwty/switch-backup-manager
module github.com/giwty/switch-library-manager

go 1.12

Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions process/incompleteTitleProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions process/organizefolderStructure.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
22 changes: 11 additions & 11 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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\"",
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions switchfs/nca.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion switchfs/ncaHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
8 changes: 4 additions & 4 deletions ui/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 11 additions & 17 deletions ui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bb74c4f

Please sign in to comment.