diff --git a/menu/menu_test.go b/menu/menu_test.go index 734796cd..a6e65796 100644 --- a/menu/menu_test.go +++ b/menu/menu_test.go @@ -120,7 +120,14 @@ func Test_buildExplorer(t *testing.T) { os.Create(tmp + "File 7.txt") os.Mkdir(tmp+"Folder 1", 0777) - scene := buildExplorer(os.TempDir()+"/Test_buildExplorer/", []string{".img"}, cbMock, dirActionMock) + prettify := func(in string) string { + if in == "File 4" { + return "IMAGE 4" + } + return in + } + + scene := buildExplorer(os.TempDir()+"/Test_buildExplorer/", []string{".img"}, cbMock, dirActionMock, prettify) menu.Push(scene) children := scene.Entry().children @@ -146,7 +153,7 @@ func Test_buildExplorer(t *testing.T) { t.Run("Files have file icon", func(t *testing.T) { if children[2].icon != "file" { - t.Errorf("buildExplorer = %v, want %v", children[1].icon, "file") + t.Errorf("buildExplorer = %v, want %v", children[2].icon, "file") } }) @@ -159,7 +166,7 @@ func Test_buildExplorer(t *testing.T) { t.Run("Folders have folder icon", func(t *testing.T) { if children[4].icon != "folder" { - t.Errorf("buildExplorer = %v, want %v", children[1].icon, "folder") + t.Errorf("buildExplorer = %v, want %v", children[4].icon, "folder") } }) @@ -172,6 +179,13 @@ func Test_buildExplorer(t *testing.T) { t.Errorf("buildExplorer = %v, want %v", len(menu.stack), 2) } }) + + t.Run("Prettifier should work", func(t *testing.T) { + want := "IMAGE 4" + if children[3].label != want { + t.Errorf("buildExplorer = %v, want %v", children[3].label, want) + } + }) } func TestExtractTags(t *testing.T) { diff --git a/menu/scene_explorer.go b/menu/scene_explorer.go index 05208cd6..fe1f3f1e 100644 --- a/menu/scene_explorer.go +++ b/menu/scene_explorer.go @@ -17,6 +17,9 @@ type sceneExplorer struct { entry } +// Prettifier processes a file name +type Prettifier func(string) string + func matchesExtensions(f os.FileInfo, exts []string) bool { if len(exts) > 0 { var fileExtension = filepath.Ext(f.Name()) @@ -46,7 +49,7 @@ func getWindowsDrives() (drives []string) { return drives } -func appendFolder(list *sceneExplorer, label, newPath string, exts []string, cb func(string), dirAction *entry) { +func appendFolder(list *sceneExplorer, label, newPath string, exts []string, cb func(string), dirAction *entry, prettifier Prettifier) { list.children = append(list.children, entry{ label: label, icon: "folder", @@ -56,7 +59,7 @@ func appendFolder(list *sceneExplorer, label, newPath string, exts []string, cb if dirAction != nil { dirAction.callbackOK = func() { cb(newPath) } } - menu.Push(buildExplorer(newPath, exts, cb, dirAction)) + menu.Push(buildExplorer(newPath, exts, cb, dirAction, prettifier)) }, }) } @@ -69,7 +72,7 @@ func explorerIcon(f os.FileInfo) string { return icon } -func appendNode(list *sceneExplorer, fullPath string, name string, f os.FileInfo, exts []string, cb func(string), dirAction *entry) { +func appendNode(list *sceneExplorer, fullPath string, name string, f os.FileInfo, exts []string, cb func(string), dirAction *entry, prettifier Prettifier) { // Check whether or not we are to display hidden files. if name[:1] == "." && !settings.Current.ShowHiddenFiles { return @@ -80,8 +83,14 @@ func appendNode(list *sceneExplorer, fullPath string, name string, f os.FileInfo return } + // Process file name if needed, used for user friendly file names + displayName := name + if prettifier != nil { + displayName = prettifier(utils.FileName(name)) + } + list.children = append(list.children, entry{ - label: name, + label: displayName, icon: explorerIcon(f), callbackOK: func() { if f.IsDir() { @@ -90,7 +99,7 @@ func appendNode(list *sceneExplorer, fullPath string, name string, f os.FileInfo if dirAction != nil { dirAction.callbackOK = func() { cb(newPath) } } - menu.Push(buildExplorer(newPath, exts, cb, dirAction)) + menu.Push(buildExplorer(newPath, exts, cb, dirAction, prettifier)) } else if cb != nil && (exts == nil || utils.StringInSlice(filepath.Ext(name), exts)) { cb(filepath.Clean(fullPath)) } @@ -98,7 +107,7 @@ func appendNode(list *sceneExplorer, fullPath string, name string, f os.FileInfo }) } -func buildExplorer(path string, exts []string, cb func(string), dirAction *entry) Scene { +func buildExplorer(path string, exts []string, cb func(string), dirAction *entry, prettifier Prettifier) Scene { var list sceneExplorer list.label = "Explorer" @@ -113,17 +122,17 @@ func buildExplorer(path string, exts []string, cb func(string), dirAction *entry if runtime.GOOS == "windows" { drives := getWindowsDrives() for _, drive := range drives { - appendFolder(&list, drive+":\\", drive+":\\", exts, cb, dirAction) + appendFolder(&list, drive+":\\", drive+":\\", exts, cb, dirAction, prettifier) } list.segueMount() return &list } } else if isWindowsDrive(path) { // Special .. entry pointing to the list of drives on Windows - appendFolder(&list, "..", "/", exts, cb, dirAction) + appendFolder(&list, "..", "/", exts, cb, dirAction, prettifier) } else { // Add a first entry for the parent directory. - appendFolder(&list, "..", filepath.Clean(path+"/.."), exts, cb, dirAction) + appendFolder(&list, "..", filepath.Clean(path+"/.."), exts, cb, dirAction, prettifier) } files, err := ioutil.ReadDir(path) @@ -144,7 +153,7 @@ func buildExplorer(path string, exts []string, cb func(string), dirAction *entry log.Println(err) continue } - appendNode(&list, fullPath, f.Name(), fi, exts, cb, dirAction) + appendNode(&list, fullPath, f.Name(), fi, exts, cb, dirAction, prettifier) } buildIndexes(&list.entry) diff --git a/menu/scene_main.go b/menu/scene_main.go index 545174a0..78a106d5 100644 --- a/menu/scene_main.go +++ b/menu/scene_main.go @@ -17,6 +17,48 @@ type sceneMain struct { entry } +var prettyCoreNames = map[string]string{ + "atari800_libretro": "Atari 800 (Atari 5200)", + "bluemsx_libretro": "BlueMSX (MSX)", + "fbneo_libretro": "FBNeo (Arcade)", + "fceumm_libretro": "Fceumm (NES)", + "gambatte_libretro": "Gambatte (Game Boy)", + "genesis_plus_gx_libretro": "Genesis Plus GX (Genesis, Master System, Sega CD)", + "handy_libretro": "Handy (Atari Lynx)", + "lutro_libretro": "Lutro (LÖVE)", + "mednafen_ngp_libretro": "Beetle NeoGeo Pocket", + "mednafen_pce_fast_libretro": "Beetle PC-Engine Fast", + "mednafen_pce_libretro": "Beetle PC-Engine", + "mednafen_pcfx_libretro": "Beetle PC-FX", + "mednafen_psx_libretro": "Beetle PlayStation", + "mednafen_saturn_libretro": "Beetle Saturn", + "mednafen_supergrafx_libretro": "Beetle SuperGrafx", + "mednafen_vb_libretro": "Beetle VirtualBoy", + "mednafen_wswan_libretro": "Beetle WonderSwan", + "melonds_libretro": "MelonDS (Nintendo DS)", + "mgba_libretro": "mGBA (Game Boy Advance)", + "np2kai_libretro": "NP2Kai (PC-98)", + "o2em_libretro": "O2EM (Odyssey²)", + "pcsx_rearmed_libretro": "PCSX Rearmed (PLayStation)", + "picodrive_libretro": "PicoDrive (Genesis, 32X)", + "pokemini_libretro": "PokeMini (Pokemon Mini)", + "prosystem_libretro": "Prosystem (Atari 7800)", + "sameboy_libretro": "SameBoy (Game Boy)", + "snes9x_libretro": "Snes9x (SNES)", + "stella2014_libretro": "Stella 2014 (Atari 2600)", + "swanstation_libretro": "SwanStation (PlayStation)", + "vecx_libretro": "VecX (Vectrex)", + "virtualjaguar_libretro": "Virtual Jaguar (Atari Jaguar)", +} + +func prettifyCoreName(in string) string { + name, ok := prettyCoreNames[in] + if ok { + return name + } + return in +} + func buildMainMenu() Scene { var list sceneMain list.label = "Main Menu" @@ -44,6 +86,7 @@ func buildMainMenu() Scene { []string{".dll", ".dylib", ".so"}, coreExplorerCb, nil, + prettifyCoreName, )) }, }) @@ -59,6 +102,7 @@ func buildMainMenu() Scene { nil, gameExplorerCb, nil, + nil, )) } else { ntf.DisplayAndLog(ntf.Warning, "Menu", "Please load a core first.") diff --git a/menu/scene_settings.go b/menu/scene_settings.go index 48df57b1..c5e93bf1 100644 --- a/menu/scene_settings.go +++ b/menu/scene_settings.go @@ -72,8 +72,9 @@ func buildSettings() Scene { &entry{ label: "<Select this directory>", icon: "scan", - }), - ) + }, + nil, + )) }, }) } else { diff --git a/menu/scene_tabs.go b/menu/scene_tabs.go index c23b334b..630d4a1a 100644 --- a/menu/scene_tabs.go +++ b/menu/scene_tabs.go @@ -71,7 +71,9 @@ func buildTabs() Scene { &entry{ label: "<Scan this directory>", icon: "scan", - })) + }, + nil, + )) }, })