Skip to content
14 changes: 13 additions & 1 deletion src/db/localSwitchFilesDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"

Expand All @@ -17,7 +18,7 @@ import (

var (
versionRegex = regexp.MustCompile(`\[[vV]?(?P<version>[0-9]{1,10})]`)
titleIdRegex = regexp.MustCompile(`\[(?P<titleId>[A-Z,a-z0-9]{16})]`)
titleIdRegex = regexp.MustCompile(`\[(?P<titleId>[A-Za-z0-9]{16})]`)
)

const (
Expand Down Expand Up @@ -134,6 +135,10 @@ func scanFolder(folder string, recursive bool, files *[]ExtendedFileInfo, progre
return nil
}

if runtime.GOOS == "darwin" && strings.EqualFold(info.Name(), ".ds_store") {
return nil
}

base := path[0 : len(path)-len(info.Name())]
if strings.TrimSuffix(base, string(os.PathSeparator)) != strings.TrimSuffix(folder, string(os.PathSeparator)) &&
!recursive {
Expand Down Expand Up @@ -167,6 +172,9 @@ func (ldb *LocalSwitchDBManager) processLocalFiles(files []ExtendedFileInfo,
ignoreFileTypes["."+strings.ToLower(ext)] = struct{}{}
}
}
if runtime.GOOS == "darwin" {
ignoreFileTypes[".ds_store"] = struct{}{}
}

ind := 0
total := len(files)
Expand All @@ -182,6 +190,10 @@ func (ldb *LocalSwitchDBManager) processLocalFiles(files []ExtendedFileInfo,
continue
}

if runtime.GOOS == "darwin" && strings.EqualFold(file.FileName, ".ds_store") {
continue
}

fileName := strings.ToLower(file.FileName)
isSplit := false

Expand Down
25 changes: 25 additions & 0 deletions src/db/localSwitchFilesDB_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package db

import "testing"

func TestParseTitleIdFromFileName(t *testing.T) {
fileName := "Super Mario [0100000000010000][v0].nsp"
titleId, err := parseTitleIdFromFileName(fileName)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if titleId == nil || *titleId != "0100000000010000" {
if titleId == nil {
t.Fatalf("expected title ID not nil")
}
t.Fatalf("expected 0100000000010000 got %v", *titleId)
}
}

func TestParseTitleIdFromFileNameInvalid(t *testing.T) {
fileName := "Invalid [01000000000100,0][v0].nsp"
_, err := parseTitleIdFromFileName(fileName)
if err == nil {
t.Fatalf("expected error for invalid title id")
}
}
2 changes: 1 addition & 1 deletion src/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ func (g *GUI) organizeLibrary() {
g.state.window.SendMessage(Message{Name: "error", Payload: "the organize options in settings.json are not valid, please check that the template contains file/folder name"}, func(m *astilectron.EventMessage) {})
return
}
process.OrganizeByFolders(folderToScan, g.state.localDB, g.state.switchDB, g)
if settings.ReadSettings(g.baseFolder).OrganizeOptions.DeleteOldUpdateFiles {
process.DeleteOldUpdates(g.baseFolder, g.state.localDB, g)
}
process.OrganizeByFolders(folderToScan, g.state.localDB, g.state.switchDB, g)
}

func (g *GUI) UpdateProgress(curr int, total int, message string) {
Expand Down
13 changes: 12 additions & 1 deletion src/process/organizefolderStructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ func DeleteOldUpdates(baseFolder string, localDB *db.LocalSwitchFilesDB, updateP
i := 0
for k, v := range localDB.Skipped {
switch v.ReasonCode {
//case db.REASON_DUPLICATE:
case db.REASON_DUPLICATE:
fileToRemove := filepath.Join(k.BaseFolder, k.FileName)
if updateProgress != nil {
updateProgress.UpdateProgress(0, 0, "deleting "+fileToRemove)
}
zap.S().Infof("Deleting file: %v \n", fileToRemove)
err := os.Remove(fileToRemove)
if err != nil {
zap.S().Errorf("Failed to delete file %v [%v]\n", fileToRemove, err)
continue
}
i++
case db.REASON_OLD_UPDATE:
fileToRemove := filepath.Join(k.BaseFolder, k.FileName)
if updateProgress != nil {
Expand Down
Loading