|
6 | 6 | "net/http" |
7 | 7 | "os" |
8 | 8 | "os/user" |
| 9 | + "strings" |
9 | 10 |
|
10 | 11 | "github.com/libretro/ludo/video" |
11 | 12 | ) |
@@ -42,11 +43,27 @@ func downloadThumbnail(list *entry, i int, url, folderPath, path string) { |
42 | 43 | io.Copy(out, resp.Body) |
43 | 44 | } |
44 | 45 |
|
| 46 | +// Scrub characters that are not cross-platform and/or violate the |
| 47 | +// No-Intro filename standard. |
| 48 | +func scrubIllegalChars(str string) string { |
| 49 | + str = strings.Replace(str, "&", "_", -1) |
| 50 | + str = strings.Replace(str, "*", "_", -1) |
| 51 | + str = strings.Replace(str, "/", "_", -1) |
| 52 | + str = strings.Replace(str, ":", "_", -1) |
| 53 | + str = strings.Replace(str, "`", "_", -1) |
| 54 | + str = strings.Replace(str, "<", "_", -1) |
| 55 | + str = strings.Replace(str, ">", "_", -1) |
| 56 | + str = strings.Replace(str, "?", "_", -1) |
| 57 | + str = strings.Replace(str, "|", "_", -1) |
| 58 | + return str |
| 59 | +} |
| 60 | + |
45 | 61 | func drawThumbnail(list *entry, i int, system, gameName string, x, y, w, h, scale float32) { |
46 | 62 | usr, _ := user.Current() |
47 | 63 | folderPath := usr.HomeDir + "/.ludo/thumbnails/" + system + "/Named_Snaps/" |
48 | 64 | path := folderPath + gameName + ".png" |
49 | | - url := "http://thumbnails.libretro.com/" + system + "/Named_Snaps/" + gameName + ".png" |
| 65 | + legalName := scrubIllegalChars(gameName) |
| 66 | + url := "http://thumbnails.libretro.com/" + system + "/Named_Snaps/" + legalName + ".png" |
50 | 67 |
|
51 | 68 | if list.children[i].thumbnail == 0 || list.children[i].thumbnail == menu.icons["img-dl"] { |
52 | 69 | if _, err := os.Stat(path); !os.IsNotExist(err) { |
|
0 commit comments