Use folder files now that we have two new apks
[gamestick-pjgsapi.git] / bin / generate-apps-cache.php
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"