diff --git a/lib/game_launcher.cpp b/lib/game_launcher.cpp index 646a258..b203e0a 100644 --- a/lib/game_launcher.cpp +++ b/lib/game_launcher.cpp @@ -9,6 +9,7 @@ #include "display/low_level_gui.h" #include #include +#include GameLauncher::GameLauncher(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager) @@ -235,9 +236,9 @@ bool GameLauncher::select_game_by_name(const char* name) { 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++) { - if (strcmp(games[i].name, name) == 0) { + if (strcasecmp(games[i].name, name) == 0) { printf("Found exact match: %s\n", games[i].name); // 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--) { - 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); // Create and initialize the game