Use folder files now that we have two new apks
authorChristian Weiske <cweiske@cweiske.de>
Sat, 20 May 2023 22:12:40 +0000 (00:12 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sat, 20 May 2023 22:12:40 +0000 (00:12 +0200)
bin/functions.php
bin/generate-apps-cache.php

index 884f606da38e8eaa9fe2c37c1f332ea2f5c5f2c3..7696648cdb437d544c3d1e7f486791db87ffffdb 100644 (file)
@@ -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'];
index dcdaac916ff86728f8435c584460f9acb3582fa2..69f85ca219b303245f11c94b7f0d5441b5c5c2f7 100755 (executable)
@@ -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"