cartridge names have file extensions clipped only if the extension is in

the list of known/supported file extensions
This commit is contained in:
JetSetIlly 2024-04-17 10:16:06 +01:00
parent e47c37bd98
commit 37ce7bc244
2 changed files with 11 additions and 5 deletions

View file

@ -17,6 +17,7 @@ package cartridgeloader
import (
"path/filepath"
"slices"
"strings"
)
@ -40,6 +41,9 @@ func decideOnName(ld Loader) string {
// is inconvenient.
func NameFromFilename(filename string) string {
name := filepath.Base(filename)
name = strings.TrimSuffix(name, filepath.Ext(filename))
ext := filepath.Ext(filename)
if slices.Contains(FileExtensions, ext) {
name = strings.TrimSuffix(name, filepath.Ext(filename))
}
return name
}

View file

@ -258,7 +258,7 @@ func (win *winSelectROM) draw() {
win.selectedName = win.selectedProperties.Name
if win.selectedName == "" {
win.selectedName = win.path.Base()
win.selectedName = strings.TrimSuffix(win.selectedName, filepath.Ext(win.selectedName))
win.selectedName = cartridgeloader.NameFromFilename(win.selectedName)
}
// normalise ROM name for presentation
@ -588,6 +588,11 @@ func (win *winSelectROM) draw() {
}
}
}
imgui.Spacing()
imgui.Checkbox("Show All", &win.showAllFiles)
imgui.SameLine()
imgui.Checkbox("Show Hidden", &win.showHidden)
})
}
@ -622,9 +627,6 @@ func (win *winSelectROM) setPath(path string) error {
}
func (win *winSelectROM) setSelectedFile(filename string) {
// selected name will be
win.selectedName = ""
// return immediately if the filename is empty
if filename == "" {
return