From db0dc6d9b5fce7d2a7d2495645840da4eba27a02 Mon Sep 17 00:00:00 2001 From: MrKaoS Date: Thu, 5 Jun 2025 12:33:33 -0600 Subject: [PATCH 1/4] Fix title ID parsing regex and add tests --- src/db/localSwitchFilesDB.go | 2 +- src/db/localSwitchFilesDB_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/db/localSwitchFilesDB_test.go diff --git a/src/db/localSwitchFilesDB.go b/src/db/localSwitchFilesDB.go index d3b6719..188bee8 100644 --- a/src/db/localSwitchFilesDB.go +++ b/src/db/localSwitchFilesDB.go @@ -17,7 +17,7 @@ import ( var ( versionRegex = regexp.MustCompile(`\[[vV]?(?P[0-9]{1,10})]`) - titleIdRegex = regexp.MustCompile(`\[(?P[A-Z,a-z0-9]{16})]`) + titleIdRegex = regexp.MustCompile(`\[(?P[A-Za-z0-9]{16})]`) ) const ( diff --git a/src/db/localSwitchFilesDB_test.go b/src/db/localSwitchFilesDB_test.go new file mode 100644 index 0000000..464aa12 --- /dev/null +++ b/src/db/localSwitchFilesDB_test.go @@ -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") + } +} From ab44626db78cdeff228c4a301a420c84085b0634 Mon Sep 17 00:00:00 2001 From: MrKaoS Date: Thu, 5 Jun 2025 13:19:54 -0600 Subject: [PATCH 2/4] Delete duplicates when cleaning old updates --- src/process/organizefolderStructure.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/process/organizefolderStructure.go b/src/process/organizefolderStructure.go index 907d4c7..472387e 100644 --- a/src/process/organizefolderStructure.go +++ b/src/process/organizefolderStructure.go @@ -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 { From a740fd04acd7a026a52bee922f798343c7ba8edb Mon Sep 17 00:00:00 2001 From: MrKaoS Date: Thu, 5 Jun 2025 15:22:51 -0600 Subject: [PATCH 3/4] Reorder deletion step in GUI organize --- src/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui.go b/src/gui.go index f7eb6ad..1816610 100644 --- a/src/gui.go +++ b/src/gui.go @@ -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) { From f45117272cf66b87bdf1172104640458dccd4cf9 Mon Sep 17 00:00:00 2001 From: MrKaoS Date: Tue, 10 Jun 2025 10:48:39 -0600 Subject: [PATCH 4/4] Ignore .DS_Store files on macOS --- src/db/localSwitchFilesDB.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/db/localSwitchFilesDB.go b/src/db/localSwitchFilesDB.go index 188bee8..b01f76f 100644 --- a/src/db/localSwitchFilesDB.go +++ b/src/db/localSwitchFilesDB.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "strconv" "strings" @@ -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 { @@ -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) @@ -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