From: Christian Weiske Date: Sat, 20 May 2023 22:12:40 +0000 (+0200) Subject: Use folder files now that we have two new apks X-Git-Url: https://git.cweiske.de/gamestick-pjgsapi.git/commitdiff_plain/9dd70aab7916396eeeb7b9f00b48c0897c74e0d2 Use folder files now that we have two new apks --- diff --git a/bin/functions.php b/bin/functions.php index 884f606..7696648 100644 --- a/bin/functions.php +++ b/bin/functions.php @@ -37,12 +37,10 @@ function loadConfigFeaturedFile() /** * Load game data files and return them */ -function loadGames(string $gamesDir): array +function loadGames(array $gameFiles): array { - $gamesDir = str_replace('//', '/', $gamesDir . '/'); - $games = []; - foreach (glob($gamesDir . '*.json') as $gameFile) { + foreach ($gameFiles as $gameFile) { $gameData = json_decode(file_get_contents($gameFile)); if ($gameData === null) { throw new \Exception('Cannot load game file: ' . $gameFile); @@ -133,6 +131,7 @@ function convertGameDataForConnect(object $gameData, array $popular): array continue; } if ($release->versionCode > $highestVersionCode) { + $highestVersionCode = $release->versionCode; $highestVersionKey = $releaseKey; } } @@ -143,7 +142,7 @@ function convertGameDataForConnect(object $gameData, array $popular): array $connectData['size'] = round($release->size / 1024 / 1024 * 1000); $connectData['download'] = [ 'url' => $release->url, - 'version' => $release->gsVersion, + 'version' => $release->versionCode, ]; } else { $connectData['name'] = '!! ' . $connectData['name']; diff --git a/bin/generate-apps-cache.php b/bin/generate-apps-cache.php index dcdaac9..69f85ca 100755 --- a/bin/generate-apps-cache.php +++ b/bin/generate-apps-cache.php @@ -18,20 +18,37 @@ if (!is_dir($cacheDir)) { } if (!isset($argv[1])) { - fwrite(STDERR, "Pass the path to a directory with game data json files\n"); + fwrite(STDERR, "Pass the path to a \"folders\" file with game data json files folder names\n"); exit(1); } -$gamesDir = $argv[1]; -if (!is_dir($gamesDir)) { - fwrite(STDERR, 'Given path is not a directory: ' . $gamesDir . "\n"); + +$foldersFile = $argv[1]; +if (!is_file($foldersFile)) { + fwrite(STDERR, 'Given path is not a file: ' . $foldersFile . "\n"); exit(1); } +$baseDir = dirname($foldersFile); +$gameFiles = []; +foreach (file($foldersFile) as $line) { + $line = trim($line); + if (strlen($line)) { + if (strpos($line, '..') !== false) { + fwrite(STDERR, 'Path attack in ' . $folder . "\n"); + } + $folder = $baseDir . '/' . $line; + if (!is_dir($folder)) { + fwrite(STDERR, 'Folder does not exist: ' . $folder . "\n"); + } + $gameFiles = array_merge($gameFiles, glob($folder . '/*.json')); + } +} + $appsCacheFile = $cacheDir . 'connect-apps.min.json'; $featuredAgesCacheFile = $cacheDir . 'connect-featured-ages.min.json'; -$games = loadGames($gamesDir); +$games = loadGames($gameFiles); loadConfigFeaturedFile(); loadConfigPopularTxtFile(); //make it "package name => number"