0) { $_SESSION['current_profile'] = $profiles[0]['id']; } else { // Create default profile if none exists $defaultProfileId = createProfile("Player 1", "avatar1.png"); $_SESSION['current_profile'] = $defaultProfileId; } } // Get RetroAchievements settings $raSettings = getRetroAchievementsSettings(); // Get general settings $generalSettingsPath = 'config/general.json'; $generalSettings = []; if (file_exists($generalSettingsPath)) { $generalSettings = json_decode(file_get_contents($generalSettingsPath), true); } $siteName = $generalSettings['site_name'] ?? 'RetroHub'; // Get list of all ROMs $games = []; $files = scandir("./roms/"); foreach($files as $file) { if(!in_array($file, array('.', '..'))) { $name = pathinfo($file, PATHINFO_FILENAME); $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); // Determine console type based on extension $console = getConsoleByExtension($ext); // Default thumbnail path $thumbnail = null; // First check for a local thumbnail if (file_exists("./img/$file.png")) { $thumbnail = "img/$file.png"; } // Check RetroAchievements for thumbnail if enabled and no local thumbnail $metadata = null; if ($raSettings['enabled'] && (!$thumbnail || $raSettings['override_local_images'])) { // Fetch game metadata (this will also cache the images) $metadata = getGameMetadata($name, $console); // Use screenshot as thumbnail if available if ($metadata) { if ($metadata['screenshot_title']) { $thumbnail = $metadata['screenshot_title']; } elseif ($metadata['screenshot_ingame']) { $thumbnail = $metadata['screenshot_ingame']; } elseif ($metadata['icon']) { $thumbnail = $metadata['icon']; } } } // If still no thumbnail, use default placeholder if (!$thumbnail) { $thumbnail = "img/placeholder_" . $console . ".png"; // If console-specific placeholder doesn't exist, use generic one if (!file_exists($thumbnail)) { $thumbnail = "img/placeholder_game.png"; } } $games[] = [ 'file' => $file, 'name' => $name, 'console' => $console, 'thumbnail' => $thumbnail, 'play_url' => 'play.php?game=' . urlencode($file), 'metadata' => $metadata ]; } } // Sort games alphabetically usort($games, function($a, $b) { return strcasecmp($a['name'], $b['name']); }); // Get current profile data $currentProfile = getProfileById($_SESSION['current_profile']); $allProfiles = getProfiles(); ?> <?php echo htmlspecialchars($siteName); ?> - Game Library