Scan a single root (e.g. "/.fonts") and append its families to `out`. Skips families whose names already exist in `out` (de-duplicates between the hidden and visible roots — first scan wins).
| 180 | // Skips families whose names already exist in `out` (de-duplicates between |
| 181 | // the hidden and visible roots — first scan wins). |
| 182 | void SdCardFontRegistry::scanRoot(const char* rootPath, std::vector<SdCardFontFamilyInfo>& out) { |
| 183 | HalFile root = Storage.open(rootPath); |
| 184 | if (!root) { |
| 185 | LOG_DBG("SDREG", "Fonts directory not found: %s", rootPath); |
| 186 | return; |
| 187 | } |
| 188 | if (!root.isDirectory()) { |
| 189 | LOG_ERR("SDREG", "Fonts path is not a directory: %s", rootPath); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | char nameBuffer[128]; |
| 194 | while (true) { |
| 195 | HalFile entry = root.openNextFile(); |
| 196 | if (!entry) break; |
| 197 | if (entry.isDirectory()) { |
| 198 | entry.getName(nameBuffer, sizeof(nameBuffer)); |
| 199 | entry.close(); |
| 200 | |
| 201 | // Skip hidden/system directories inside the root (macOS ._*, .Trashes, etc.) |
| 202 | if (nameBuffer[0] == '.' || nameBuffer[0] == '_') continue; |
| 203 | |
| 204 | // De-dup by family name across roots. |
| 205 | bool exists = false; |
| 206 | for (const auto& fam : out) { |
| 207 | if (fam.name == nameBuffer) { |
| 208 | exists = true; |
| 209 | break; |
| 210 | } |
| 211 | } |
| 212 | if (exists) continue; |
| 213 | |
| 214 | SdCardFontFamilyInfo family; |
| 215 | family.name = nameBuffer; |
| 216 | std::string subDirPath = std::string(rootPath) + "/" + nameBuffer; |
| 217 | SdCardFontRegistry::scanDirectory(subDirPath.c_str(), family); |
| 218 | |
| 219 | if (!family.files.empty()) { |
| 220 | out.push_back(std::move(family)); |
| 221 | LOG_DBG("SDREG", "Found family: %s (%d files) in %s", out.back().name.c_str(), |
| 222 | static_cast<int>(out.back().files.size()), rootPath); |
| 223 | } |
| 224 | } else { |
| 225 | entry.close(); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | bool SdCardFontRegistry::discover() { |
| 231 | families_.clear(); |
nothing calls this directly
no test coverage detected