/**
* 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);
continue;
}
if ($release->versionCode > $highestVersionCode) {
+ $highestVersionCode = $release->versionCode;
$highestVersionKey = $releaseKey;
}
}
$connectData['size'] = round($release->size / 1024 / 1024 * 1000);
$connectData['download'] = [
'url' => $release->url,
- 'version' => $release->gsVersion,
+ 'version' => $release->versionCode,
];
} else {
$connectData['name'] = '!! ' . $connectData['name'];
}
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"