-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathplatforms.go
More file actions
165 lines (151 loc) · 3.94 KB
/
Copy pathplatforms.go
File metadata and controls
165 lines (151 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package cfw
import (
"grout/cfw/allium"
"grout/cfw/batocera"
"grout/cfw/knulli"
"grout/cfw/koriki"
"grout/cfw/minui"
"grout/cfw/muos"
"grout/cfw/nextui"
"grout/cfw/onion"
"grout/cfw/retrodeck"
"grout/cfw/rocknix"
"grout/cfw/spruce"
"grout/cfw/trimui"
"strings"
)
// platformAliasMap is computed from platform mappings - slugs that map to
// overlapping local folders are considered aliases (e.g., sfam/snes both map to "snes")
var platformAliasMap = buildPlatformAliasMap()
func buildPlatformAliasMap() map[string][]string {
// Combine all platform maps to find aliases across all CFWs
allMaps := []map[string][]string{
knulli.Platforms,
muos.Platforms,
nextui.Platforms,
rocknix.Platforms,
spruce.Platforms,
trimui.Platforms,
allium.Platforms,
onion.Platforms,
koriki.Platforms,
batocera.Platforms,
minui.Platforms,
retrodeck.Platforms,
}
// Build reverse map: primary folder -> list of RomM slugs that use it as primary
// Only use the FIRST folder in each list (the primary/default folder)
// This avoids false aliases like arcade/neogeoaes which share "neogeo" as a secondary folder
primaryFolderToSlugs := make(map[string]map[string]bool)
for _, platformMap := range allMaps {
for slug, folders := range platformMap {
if len(folders) == 0 {
continue
}
// Use only the primary (first) folder
primary := strings.ToLower(folders[0])
if primaryFolderToSlugs[primary] == nil {
primaryFolderToSlugs[primary] = make(map[string]bool)
}
primaryFolderToSlugs[primary][slug] = true
}
}
// Find slug groups that share the same primary folder using union-find
parent := make(map[string]string)
var find func(s string) string
find = func(s string) string {
if parent[s] == "" {
parent[s] = s
}
if parent[s] != s {
parent[s] = find(parent[s])
}
return parent[s]
}
union := func(a, b string) {
pa, pb := find(a), find(b)
if pa != pb {
parent[pa] = pb
}
}
// Union slugs that share the same primary folder
for _, slugs := range primaryFolderToSlugs {
var slugList []string
for slug := range slugs {
slugList = append(slugList, slug)
}
for i := 1; i < len(slugList); i++ {
union(slugList[0], slugList[i])
}
}
// Group slugs by their root parent
groups := make(map[string][]string)
for slug := range parent {
root := find(slug)
groups[root] = append(groups[root], slug)
}
// Build final alias map (only for groups with more than one slug)
result := make(map[string][]string)
for _, group := range groups {
if len(group) > 1 {
for _, slug := range group {
result[slug] = group
}
}
}
return result
}
// GetPlatformAliases returns all equivalent platform slugs for the given slug.
// Aliases are RomM slugs that map to overlapping local folders across CFWs.
// Returns a slice containing at least the input slug itself.
func GetPlatformAliases(fsSlug string) []string {
if aliases, ok := platformAliasMap[fsSlug]; ok {
return aliases
}
return []string{fsSlug}
}
// GetPlatformMap returns the platform mapping for the given CFW.
func GetPlatformMap(c CFW) map[string][]string {
switch c {
case MuOS:
return muos.Platforms
case NextUI:
return nextui.Platforms
case Knulli:
return knulli.Platforms
case Spruce:
return spruce.Platforms
case ROCKNIX:
return rocknix.Platforms
case Trimui:
return trimui.Platforms
case Allium:
return allium.Platforms
case Onion:
return onion.Platforms
case Koriki:
return koriki.Platforms
case Batocera:
return batocera.Platforms
case MinUI:
return minui.Platforms
case RetroDECK:
return retrodeck.Platforms
default:
return nil
}
}
// RomMFSSlugToCFW converts a RomM filesystem slug to the CFW-specific folder name.
func RomMFSSlugToCFW(fsSlug string) string {
cfwPlatformMap := GetPlatformMap(GetCFW())
if cfwPlatformMap == nil {
return strings.ToLower(fsSlug)
}
if value, ok := cfwPlatformMap[fsSlug]; ok {
if len(value) > 0 {
return value[0]
}
return ""
}
return strings.ToLower(fsSlug)
}