Skip to content

Commit 2822812

Browse files
giwtygiwty
authored andcommitted
fix nil pointer panic
1 parent 97f41cc commit 2822812

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

process/organizefolderStructure.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path"
1010
"path/filepath"
1111
"regexp"
12+
"robpike.io/nihongo"
1213
"sort"
1314
"strconv"
1415
"strings"
@@ -18,9 +19,12 @@ var (
1819
folderIllegalCharsRegex = regexp.MustCompile(`[/\\?%*:|"<>]`)
1920
)
2021

21-
func DeleteOldUpdates(localDB *db.LocalSwitchFilesDB) {
22+
func DeleteOldUpdates(localDB *db.LocalSwitchFilesDB, updateProgress db.ProgressUpdater) {
23+
i := 0
2224
for _, v := range localDB.TitlesMap {
23-
25+
if updateProgress != nil {
26+
updateProgress.UpdateProgress(i, len(localDB.TitlesMap), v.File.Info.Name())
27+
}
2428
if len(v.Updates) > 1 {
2529
//sort the available local versions
2630
localVersions := make([]int, len(v.Updates))
@@ -53,13 +57,14 @@ func OrganizeByFolders(baseFolder string, localDB *db.LocalSwitchFilesDB, titles
5357

5458
options := settings.ReadSettings(baseFolder).OrganizeOptions
5559
i := 0
60+
tasksSize := len(localDB.TitlesMap) + 2
5661
for k, v := range localDB.TitlesMap {
5762
i++
5863
if v.BaseExist == false {
5964
continue
6065
}
6166
if updateProgress != nil {
62-
updateProgress.UpdateProgress(i, len(localDB.TitlesMap), v.File.Info.Name())
67+
updateProgress.UpdateProgress(i, tasksSize, v.File.Info.Name())
6368
}
6469

6570
titleName := getTitleName(titlesDB.TitlesMap[k], v)
@@ -138,10 +143,23 @@ func OrganizeByFolders(baseFolder string, localDB *db.LocalSwitchFilesDB, titles
138143
}
139144

140145
if options.DeleteEmptyFolders {
146+
if updateProgress != nil {
147+
i += 1
148+
updateProgress.UpdateProgress(i, tasksSize, "deleting empty folders... (can take 1-2min)")
149+
}
141150
err := deleteEmptyFolders(baseFolder)
142151
if err != nil {
143152
zap.S().Errorf("Failed to delete empty folders [%v]\n", err)
144153
}
154+
if updateProgress != nil {
155+
i += 1
156+
updateProgress.UpdateProgress(i, tasksSize, "done")
157+
}
158+
} else {
159+
if updateProgress != nil {
160+
i += 2
161+
updateProgress.UpdateProgress(i, tasksSize, "done")
162+
}
145163
}
146164
}
147165

@@ -203,7 +221,7 @@ func applyTemplate(templateData map[string]string, template string) string {
203221
if strings.HasSuffix(result, ".") {
204222
result = result[:len(result)-1]
205223
}
206-
return result
224+
return nihongo.RomajiString(result)
207225
}
208226

209227
func deleteEmptyFolders(path string) error {

0 commit comments

Comments
 (0)