@@ -33,11 +33,13 @@ func RemoveExisting(gridDir string, gameId string, artStyleExtensions []string)
33
33
if err != nil {
34
34
return err
35
35
}
36
+ images = filterForImages (images )
36
37
37
38
backups , err := filepath .Glob (filepath .Join (gridDir , "originals" , gameId + artStyleExtensions [0 ] + " *.*" ))
38
39
if err != nil {
39
40
return err
40
41
}
42
+ backups = filterForImages (backups )
41
43
42
44
all := append (images , backups ... )
43
45
for _ , path := range all {
@@ -77,12 +79,29 @@ func InsensitiveFilepath(path string) string {
77
79
return p
78
80
}
79
81
82
+ func filterForImages (paths []string ) []string {
83
+ var matchedPaths []string
84
+ for _ , path := range paths {
85
+ ext := filepath .Ext (path )
86
+ switch ext {
87
+ case ".png" :
88
+ matchedPaths = append (matchedPaths , path )
89
+ case ".jpg" :
90
+ matchedPaths = append (matchedPaths , path )
91
+ case ".jpeg" :
92
+ matchedPaths = append (matchedPaths , path )
93
+ }
94
+ }
95
+ return matchedPaths
96
+ }
97
+
80
98
func LoadExisting (overridePath string , gridDir string , game * Game , artStyleExtensions []string ) {
81
99
overridenIDs , _ := filepath .Glob (filepath .Join (overridePath , game .ID + artStyleExtensions [0 ] + ".*" ))
82
100
if overridenIDs != nil && len (overridenIDs ) > 0 {
83
101
loadImage (game , "local file in directory 'games'" , overridenIDs [0 ])
84
102
return
85
103
}
104
+ overridenIDs = filterForImages (overridenIDs )
86
105
87
106
if game .Name != "" {
88
107
re := regexp .MustCompile (`\W+` )
@@ -105,6 +124,7 @@ func LoadExisting(overridePath string, gridDir string, game *Game, artStyleExten
105
124
}
106
125
107
126
files , err := filepath .Glob (filepath .Join (gridDir , game .ID + artStyleExtensions [0 ] + ".*" ))
127
+ files = filterForImages (files )
108
128
if err == nil && len (files ) > 0 {
109
129
err = loadImage (game , "manual customization" , files [0 ])
110
130
if err == nil {
0 commit comments