diff --git a/fetchupd.php b/fetchupd.php index a1ece3f..a3dc648 100644 --- a/fetchupd.php +++ b/fetchupd.php @@ -1,6 +1,6 @@ 'NO_FILEINFO_DIR'); @@ -27,8 +27,24 @@ function uupListIds($search = null) { consoleLogger('Parsing database info...'); - $database = @file_get_contents('cache/fileinfo.json'); + $cacheFile = 'cache/fileinfo_v2.json'; + $cacheV2Version = 1; + + $database = @file_get_contents($cacheFile); $database = json_decode($database, true); + + if(isset($database['version'])) { + $version = $database['version']; + } else { + $version = 0; + } + + if($version == $cacheV2Version && isset($database['database'])) { + $database = $database['database']; + } else { + $database = array(); + } + if(empty($database)) $database = array(); $newDb = array(); @@ -44,11 +60,13 @@ function uupListIds($search = null) { $title = isset($info['title']) ? $info['title'] : 'UNKNOWN'; $build = isset($info['build']) ? $info['build'] : 'UNKNOWN'; $arch = isset($info['arch']) ? $info['arch'] : 'UNKNOWN'; + $created = isset($info['created']) ? $info['created'] : null; $temp = array( 'title' => $title, 'build' => $build, 'arch' => $arch, + 'created' => $created, ); $newDb[$uuid] = $temp; @@ -56,6 +74,7 @@ function uupListIds($search = null) { $title = $database[$uuid]['title']; $build = $database[$uuid]['build']; $arch = $database[$uuid]['arch']; + $created = $database[$uuid]['created']; $newDb[$uuid] = $database[$uuid]; } @@ -64,6 +83,7 @@ function uupListIds($search = null) { 'title' => $title, 'build' => $build, 'arch' => $arch, + 'created' => $created, 'uuid' => $uuid, ); @@ -77,6 +97,10 @@ function uupListIds($search = null) { $tmp = 0; } + if($sortByDate) { + $tmp = $created.$tmp; + } + $buildAssoc[$tmp][] = $arch.$title.$uuid; $builds[$tmp.$arch.$title.$uuid] = $temp; } @@ -104,9 +128,14 @@ function uupListIds($search = null) { if($newDb != $database) { if(!file_exists('cache')) mkdir('cache'); + $cacheData = array( + 'version' => $cacheV2Version, + 'database' => $newDb, + ); + $success = @file_put_contents( - 'cache/fileinfo.json', - json_encode($newDb)."\n" + $cacheFile, + json_encode($cacheData)."\n" ); if(!$success) consoleLogger('Failed to update database cache.'); diff --git a/shared/main.php b/shared/main.php index 1c6371b..66c05f6 100644 --- a/shared/main.php +++ b/shared/main.php @@ -16,7 +16,7 @@ limitations under the License. */ function uupApiVersion() { - return '1.19.3'; + return '1.20.0'; } require_once dirname(__FILE__).'/auths.php';