Rework listid.php, move low priority updates to the bottom
This commit is contained in:
147
listid.php
147
listid.php
@@ -27,19 +27,8 @@ function uupApiPrivateInvalidateFileinfoCache() {
|
|||||||
$cache2->delete();
|
$cache2->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
function uupApiPrivateGetFromFileinfo($sortByDate = 0) {
|
function uupApiGetFileInfoCache($cacheFile) {
|
||||||
$dirs = uupApiGetFileinfoDirs();
|
|
||||||
$fileinfo = $dirs['fileinfoData'];
|
|
||||||
$fileinfoRoot = $dirs['fileinfo'];
|
|
||||||
|
|
||||||
$files = scandir($fileinfo);
|
|
||||||
$files = preg_grep('/\.json$/', $files);
|
|
||||||
|
|
||||||
consoleLogger('Parsing database info...');
|
|
||||||
|
|
||||||
$cacheFile = $fileinfoRoot.'/cache.json';
|
|
||||||
$cacheV2Version = 1;
|
$cacheV2Version = 1;
|
||||||
|
|
||||||
$database = uupApiReadJson($cacheFile);
|
$database = uupApiReadJson($cacheFile);
|
||||||
|
|
||||||
if(isset($database['version'])) {
|
if(isset($database['version'])) {
|
||||||
@@ -54,88 +43,98 @@ function uupApiPrivateGetFromFileinfo($sortByDate = 0) {
|
|||||||
$database = array();
|
$database = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($database)) $database = array();
|
if(empty($database))
|
||||||
|
$database = [];
|
||||||
|
|
||||||
|
return $database;
|
||||||
|
}
|
||||||
|
|
||||||
|
function uupApiPrivateGetCachedBuild(&$cache, $uuid) {
|
||||||
|
if(!isset($cache[$uuid])) {
|
||||||
|
$info = uupApiReadFileinfoMeta($uuid);
|
||||||
|
$data = [
|
||||||
|
'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,
|
||||||
|
];
|
||||||
|
|
||||||
|
$cache[$uuid] = $data;
|
||||||
|
} else {
|
||||||
|
$data = $cache[$uuid];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['uuid'] = $uuid;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function uupApiPrivateGetSortTag($data, $sortByDate) {
|
||||||
|
$tmp = explode('.', $data['build']);
|
||||||
|
|
||||||
|
if($sortByDate) {
|
||||||
|
$tag = PHP_INT_MAX - intval($data['created']);
|
||||||
|
} else {
|
||||||
|
$tag = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag .= intval(uupApiIsUpdateLowPriority($data['title']));
|
||||||
|
|
||||||
|
if(isset($tmp[1])) {
|
||||||
|
$tag .= str_pad(999999999 - $tmp[0], 10, '0', STR_PAD_LEFT);
|
||||||
|
$tag .= str_pad(999999999 - $tmp[1], 10, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag .= $data['arch'] . $data['title'] . $data['uuid'];
|
||||||
|
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
function uupApiPrivateGetFromFileinfo($sortByDate = 0) {
|
||||||
|
$dirs = uupApiGetFileinfoDirs();
|
||||||
|
$fileinfo = $dirs['fileinfoData'];
|
||||||
|
$fileinfoRoot = $dirs['fileinfo'];
|
||||||
|
|
||||||
|
$files = scandir($fileinfo);
|
||||||
|
$files = preg_grep('/\.json$/', $files);
|
||||||
|
|
||||||
|
consoleLogger('Parsing database info...');
|
||||||
|
|
||||||
|
$cacheFile = $fileinfoRoot.'/cache.json';
|
||||||
|
$cacheV2Version = 1;
|
||||||
|
|
||||||
|
$database = uupApiGetFileInfoCache($cacheFile);
|
||||||
|
$oldDb = $database;
|
||||||
|
|
||||||
$newDb = array();
|
|
||||||
$builds = array();
|
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
if($file == '.' || $file == '..')
|
if($file == '.' || $file == '..')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$uuid = preg_replace('/\.json$/', '', $file);
|
$uuid = preg_replace('/\.json$/', '', $file);
|
||||||
|
|
||||||
if(!isset($database[$uuid])) {
|
$data = uupApiPrivateGetCachedBuild($database, $uuid);
|
||||||
$info = uupApiReadFileinfoMeta($uuid);
|
$tag = uupApiPrivateGetSortTag($data, $sortByDate);
|
||||||
|
|
||||||
$title = isset($info['title']) ? $info['title'] : 'UNKNOWN';
|
$buildAssoc[$tag] = $uuid;
|
||||||
$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;
|
|
||||||
} else {
|
|
||||||
$title = $database[$uuid]['title'];
|
|
||||||
$build = $database[$uuid]['build'];
|
|
||||||
$arch = $database[$uuid]['arch'];
|
|
||||||
$created = $database[$uuid]['created'];
|
|
||||||
|
|
||||||
$newDb[$uuid] = $database[$uuid];
|
|
||||||
}
|
|
||||||
|
|
||||||
$temp = array(
|
|
||||||
'title' => $title,
|
|
||||||
'build' => $build,
|
|
||||||
'arch' => $arch,
|
|
||||||
'created' => $created,
|
|
||||||
'uuid' => $uuid,
|
|
||||||
);
|
|
||||||
|
|
||||||
$tmp = explode('.', $build);
|
|
||||||
if(isset($tmp[1])) {
|
|
||||||
$tmp[0] = str_pad($tmp[0], 10, '0', STR_PAD_LEFT);
|
|
||||||
$tmp[1] = str_pad($tmp[1], 10, '0', STR_PAD_LEFT);
|
|
||||||
$tmp = $tmp[0].$tmp[1];
|
|
||||||
} else {
|
|
||||||
consoleLogger($uuid.'.json appears to be broken and may be useless.');
|
|
||||||
$tmp = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($sortByDate) {
|
|
||||||
$tmp = $created.$tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
$buildAssoc[$tmp][] = $arch.$title.$uuid;
|
|
||||||
$builds[$tmp.$arch.$title.$uuid] = $temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($buildAssoc)) return [];
|
if(empty($buildAssoc))
|
||||||
|
return [];
|
||||||
|
|
||||||
krsort($buildAssoc);
|
ksort($buildAssoc);
|
||||||
$buildsNew = array();
|
|
||||||
|
|
||||||
foreach($buildAssoc as $key => $val) {
|
$builds = [];
|
||||||
sort($val);
|
foreach($buildAssoc as $val) {
|
||||||
foreach($val as $id) {
|
$builds[] = uupApiPrivateGetCachedBuild($database, $val);
|
||||||
$buildsNew[] = $builds[$key.$id];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$builds = $buildsNew;
|
|
||||||
consoleLogger('Done parsing database info.');
|
consoleLogger('Done parsing database info.');
|
||||||
|
|
||||||
if($newDb != $database) {
|
if($database != $oldDb) {
|
||||||
if(!file_exists('cache')) mkdir('cache');
|
if(!file_exists('cache')) mkdir('cache');
|
||||||
|
|
||||||
$cacheData = array(
|
$cacheData = array(
|
||||||
'version' => $cacheV2Version,
|
'version' => $cacheV2Version,
|
||||||
'database' => $newDb,
|
'database' => $database,
|
||||||
);
|
);
|
||||||
|
|
||||||
$success = @file_put_contents(
|
$success = @file_put_contents(
|
||||||
|
|||||||
@@ -207,3 +207,18 @@ function getAllowedFlags() {
|
|||||||
function uupAreAppxPresent($genPack) {
|
function uupAreAppxPresent($genPack) {
|
||||||
return isset($genPack['neutral']['APP']);
|
return isset($genPack['neutral']['APP']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function uupApiIsUpdateLowPriority($title) {
|
||||||
|
$titles = [
|
||||||
|
'Update Stack Package',
|
||||||
|
'.NET Framework',
|
||||||
|
'OOBE'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach($titles as $val) {
|
||||||
|
if(str_contains($title, $val) == true)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user