Make game name search case-insensitive

Serial uploader searches for games by filename (e.g., "tetris") but
games are registered by their metadata NAME field (e.g., "Tetris").
This caused launch failures when case didn't match.

Changed select_game_by_name() to use case-insensitive matching:
- strcasecmp() for exact match
- tolower() both strings before strstr() for partial match

Now uploading "tetris.lua" will successfully match and launch "Tetris".

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Adolfo Reyna
2026-02-12 23:27:48 -05:00
parent 518bc054c4
commit 76e3d2435e

View File

@@ -9,6 +9,7 @@
#include "display/low_level_gui.h" #include "display/low_level_gui.h"
#include <stdio.h> #include <stdio.h>
#include <cstring> #include <cstring>
#include <cctype>
GameLauncher::GameLauncher(uint16_t width, uint16_t height, GameLauncher::GameLauncher(uint16_t width, uint16_t height,
LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager) LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager)
@@ -235,9 +236,9 @@ bool GameLauncher::select_game_by_name(const char* name) {
selected_game = nullptr; selected_game = nullptr;
} }
// First pass: search for exact match (prefer exact matches) // First pass: search for exact match (case-insensitive)
for (size_t i = 0; i < games.size(); i++) { for (size_t i = 0; i < games.size(); i++) {
if (strcmp(games[i].name, name) == 0) { if (strcasecmp(games[i].name, name) == 0) {
printf("Found exact match: %s\n", games[i].name); printf("Found exact match: %s\n", games[i].name);
// Create and initialize the game // Create and initialize the game
@@ -255,9 +256,27 @@ bool GameLauncher::select_game_by_name(const char* name) {
} }
} }
// Second pass: search in reverse order for partial match (newest files first) // Second pass: search in reverse order for partial match (case-insensitive, newest files first)
for (int i = games.size() - 1; i >= 0; i--) { for (int i = games.size() - 1; i >= 0; i--) {
if (strstr(games[i].name, name) != nullptr) { // Convert both strings to lowercase for comparison
char game_name_lower[256];
char search_name_lower[256];
strncpy(game_name_lower, games[i].name, sizeof(game_name_lower) - 1);
game_name_lower[sizeof(game_name_lower) - 1] = '\0';
strncpy(search_name_lower, name, sizeof(search_name_lower) - 1);
search_name_lower[sizeof(search_name_lower) - 1] = '\0';
// Convert to lowercase
for (size_t j = 0; game_name_lower[j]; j++) {
game_name_lower[j] = tolower(game_name_lower[j]);
}
for (size_t j = 0; search_name_lower[j]; j++) {
search_name_lower[j] = tolower(search_name_lower[j]);
}
if (strstr(game_name_lower, search_name_lower) != nullptr) {
printf("Found partial match: %s (searching for: %s)\n", games[i].name, name); printf("Found partial match: %s (searching for: %s)\n", games[i].name, name);
// Create and initialize the game // Create and initialize the game