Merge pull request #20 from eraseyourknees/master

1.33.0
This commit is contained in:
eraseyourknees 2022-08-25 22:15:46 +02:00 committed by GitHub
commit 2dbb52dc7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
473 changed files with 157 additions and 235 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
require_once dirname(__FILE__).'/shared/main.php'; require_once dirname(__FILE__).'/shared/main.php';
require_once dirname(__FILE__).'/shared/requests.php'; require_once dirname(__FILE__).'/shared/requests.php';
require_once dirname(__FILE__).'/shared/cache.php';
require_once dirname(__FILE__).'/listid.php'; require_once dirname(__FILE__).'/listid.php';
function uupFetchUpd( function uupFetchUpd(
@ -90,23 +91,10 @@ function uupFetchUpd(
$type = 'Production'; $type = 'Production';
} }
$cacheHash = hash('sha256', strtolower("api-fetch-$arch-$ring-$flight-$build-$minor-$sku-$type")); $res = "api-fetch-$arch-$ring-$flight-$build-$minor-$sku-$type";
$cached = 0; $cache = new UupDumpCache($res);
$out = $cache->get();
if(file_exists('cache/'.$cacheHash.'.json.gz') && $cacheRequests == 1) { $cached = ($out !== false);
$cache = @gzdecode(@file_get_contents('cache/'.$cacheHash.'.json.gz'));
$cache = json_decode($cache, 1);
if(!empty($cache['content']) && ($cache['expires'] > time())) {
consoleLogger('Using cached response...');
$out = $cache['content'];
$cached = 1;
} else {
$cached = 0;
}
unset($cache);
}
if(!$cached) { if(!$cached) {
consoleLogger('Fetching information from the server...'); consoleLogger('Fetching information from the server...');
@ -117,15 +105,7 @@ function uupFetchUpd(
consoleLogger('Information has been successfully fetched.'); consoleLogger('Information has been successfully fetched.');
if($cacheRequests == 1) { if($cacheRequests == 1) {
$cache = array( $cache->put($out, 120);
'expires' => time()+120,
'content' => $out,
);
if(!file_exists('cache')) mkdir('cache');
@file_put_contents('cache/'.$cacheHash.'.json.gz', gzencode(json_encode($cache)."\n"));
unset($cache);
} }
} }

56
get.php
View File

@ -18,6 +18,7 @@ limitations under the License.
require_once dirname(__FILE__).'/shared/main.php'; require_once dirname(__FILE__).'/shared/main.php';
require_once dirname(__FILE__).'/shared/requests.php'; require_once dirname(__FILE__).'/shared/requests.php';
require_once dirname(__FILE__).'/shared/packs.php'; require_once dirname(__FILE__).'/shared/packs.php';
require_once dirname(__FILE__).'/shared/cache.php';
/* /*
$updateId = Update Identifier $updateId = Update Identifier
@ -142,6 +143,7 @@ function uupGetFiles(
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN'; $updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN';
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId; $updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
$sha256capable = isset($info['sha256ready']); $sha256capable = isset($info['sha256ready']);
$hasUpdates = false;
if(isset($info['releasetype'])) { if(isset($info['releasetype'])) {
$type = $info['releasetype']; $type = $info['releasetype'];
@ -215,6 +217,7 @@ function uupGetFiles(
unset($index, $name, $msu); unset($index, $name, $msu);
$filesInfoKeys = array_keys($filesInfoList); $filesInfoKeys = array_keys($filesInfoList);
$updatesRegex = '/Windows(10|11)\.0-KB|SSU-.*?\....$/i';
switch($fileListSource) { switch($fileListSource) {
case 'UPDATEONLY': case 'UPDATEONLY':
@ -227,8 +230,8 @@ function uupGetFiles(
unset($removeFiles); unset($removeFiles);
foreach($removeMSUs as $val) { foreach($removeMSUs as $val) {
if(isset($filesInfoList[$val.'.cab'])) { if(isset($filesInfoList[$val.'.cab']) && isset($filesInfoList[$val.'.msu'])) {
if(isset($filesInfoList[$val.'.msu'])) unset($filesInfoList[$val.'.msu']); unset($filesInfoList[$val.'.msu']);
} }
} }
unset($removeMSUs); unset($removeMSUs);
@ -236,13 +239,14 @@ function uupGetFiles(
$filesInfoKeys = array_keys($filesInfoList); $filesInfoKeys = array_keys($filesInfoList);
$temp = preg_grep('/.*?AggregatedMetadata.*?\.cab|.*?DesktopDeployment.*?\.cab/i', $filesInfoKeys); $temp = preg_grep('/.*?AggregatedMetadata.*?\.cab|.*?DesktopDeployment.*?\.cab/i', $filesInfoKeys);
$filesInfoKeys = preg_grep('/Windows(10|11)\.0-KB|SSU-.*?\....$/i', $filesInfoKeys); $filesInfoKeys = preg_grep($updatesRegex, $filesInfoKeys);
if(count($filesInfoKeys) == 0) { if(count($filesInfoKeys) == 0) {
return array('error' => 'NOT_CUMULATIVE_UPDATE'); return array('error' => 'NOT_CUMULATIVE_UPDATE');
} }
if($build > 21380) $filesInfoKeys = array_merge($filesInfoKeys, $temp); if($build > 21380) $filesInfoKeys = array_merge($filesInfoKeys, $temp);
unset($temp); unset($temp);
$hasUpdates = true;
break; break;
case 'WUBFILE': case 'WUBFILE':
@ -257,8 +261,8 @@ function uupGetFiles(
if($fileListSource == 'GENERATEDPACKS') { if($fileListSource == 'GENERATEDPACKS') {
foreach($removeMSUs as $val) { foreach($removeMSUs as $val) {
if(isset($filesInfoList[$val.'.cab'])) { if(isset($filesInfoList[$val.'.cab']) && isset($filesInfoList[$val.'.msu'])) {
if(isset($filesInfoList[$val.'.msu'])) unset($filesInfoList[$val.'.msu']); unset($filesInfoList[$val.'.msu']);
} }
} }
unset($removeMSUs); unset($removeMSUs);
@ -270,8 +274,10 @@ function uupGetFiles(
} else if($build > 21380) { } else if($build > 21380) {
$temp = preg_grep('/Windows(10|11)\.0-KB|SSU-.*?\....$|.*?AggregatedMetadata.*?\.cab|.*?DesktopDeployment.*?\.cab/i', $temp); $temp = preg_grep('/Windows(10|11)\.0-KB|SSU-.*?\....$|.*?AggregatedMetadata.*?\.cab|.*?DesktopDeployment.*?\.cab/i', $temp);
} else { } else {
$temp = preg_grep('/Windows(10|11)\.0-KB|SSU-.*?\....$/i', $temp); $temp = preg_grep($updatesRegex, $temp);
} }
$hasUpdates = !empty(preg_grep($updatesRegex, $temp));
$filesPacksList = array_merge($filesPacksList, $temp); $filesPacksList = array_merge($filesPacksList, $temp);
$newFiles = array(); $newFiles = array();
@ -337,31 +343,21 @@ function uupGetFiles(
'arch' => $updateArch, 'arch' => $updateArch,
'build' => $updateBuild, 'build' => $updateBuild,
'sku' => $updateSku, 'sku' => $updateSku,
'hasUpdates' => $hasUpdates,
'files' => $files, 'files' => $files,
); );
} }
function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) { function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) {
$cacheHash = hash('sha256', strtolower("api-get-${updateId}_rev.$rev")); $res = "api-get-${updateId}_rev.$rev";
$cached = 0; $cache = new UupDumpCache($res);
$fromCache = $cache->get();
$cached = ($fromCache !== false);
if(file_exists('cache/'.$cacheHash.'.json.gz') && $cacheRequests == 1) { if($cached) {
$cache = @gzdecode(@file_get_contents('cache/'.$cacheHash.'.json.gz')); $out = $fromCache['out'];
$cache = json_decode($cache, 1); $fetchTime = $fromCache['fetchTime'];
if(!empty($cache['content']) && ($cache['expires'] > time())) {
consoleLogger('Using cached response...');
$out = $cache['content'];
$fetchTime = $cache['fetchTime'];
$cached = 1;
} else { } else {
$cached = 0;
}
unset($cache);
}
if(!$cached) {
$fetchTime = time(); $fetchTime = time();
consoleLogger('Fetching information from the server...'); consoleLogger('Fetching information from the server...');
$postData = composeFileGetRequest($updateId, uupDevice(), $info, $rev, $type); $postData = composeFileGetRequest($updateId, uupDevice(), $info, $rev, $type);
@ -372,7 +368,7 @@ function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) {
consoleLogger('Parsing information...'); consoleLogger('Parsing information...');
$xmlOut = @simplexml_load_string($out); $xmlOut = @simplexml_load_string($out);
if($xmlOut === false) { if($xmlOut === false) {
@unlink('cache/'.$cacheHash.'.json.gz'); $cache->delete();
return array('error' => 'XML_PARSE_ERROR'); return array('error' => 'XML_PARSE_ERROR');
} }
@ -468,14 +464,12 @@ function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) {
} }
if($cacheRequests == 1 && $cached == 0) { if($cacheRequests == 1 && $cached == 0) {
$cache = array( $cacheData = [
'expires' => time()+90, 'out' => $out,
'content' => $out,
'fetchTime' => $fetchTime, 'fetchTime' => $fetchTime,
); ];
if(!file_exists('cache')) mkdir('cache'); $cache->put($cacheData, 90);
@file_put_contents('cache/'.$cacheHash.'.json.gz', gzencode(json_encode($cache)."\n"));
} }
return $files; return $files;

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2019 UUP dump API authors Copyright 2022 UUP dump API authors
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -21,7 +21,7 @@ require_once dirname(__FILE__).'/updateinfo.php';
function uupListEditions($lang = 'en-us', $updateId = 0) { function uupListEditions($lang = 'en-us', $updateId = 0) {
if($updateId) { if($updateId) {
$info = uupUpdateInfo($updateId); $info = uupUpdateInfo($updateId, false, true);
} }
if(!$lang) { if(!$lang) {

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2019 UUP dump API authors Copyright 2022 UUP dump API authors
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -21,7 +21,7 @@ require_once dirname(__FILE__).'/updateinfo.php';
function uupListLangs($updateId = 0) { function uupListLangs($updateId = 0) {
if($updateId) { if($updateId) {
$info = uupUpdateInfo($updateId); $info = uupUpdateInfo($updateId, false, true);
} }
if(isset($info['info'])) { if(isset($info['info'])) {

78
shared/cache.php Normal file
View File

@ -0,0 +1,78 @@
<?php
/*
Copyright 2022 eraseyourknees
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
class UupDumpCache {
private $cacheFile;
private $isCompressed;
private $newCacheVersion = 1;
public function __construct($resource, $compressed = true) {
$res = $resource."+cache_v".$this->newCacheVersion;
$cacheHash = hash('sha256', strtolower($res));
$ext = $compressed ? '.json.gz' : '.json';
$this->cacheFile = 'cache/'.$cacheHash.$ext;
$this->isCompressed = $compressed;
}
public function getFileName() {
return $this->cacheFile;
}
public function delete() {
@unlink($this->cacheFile);
}
public function get() {
$cacheFile = $this->cacheFile;
if(!file_exists($cacheFile)) {
return false;
}
$cache = @file_get_contents($cacheFile);
if($this->isCompressed) $cache = @gzdecode($cache);
$cache = json_decode($cache, 1);
$expires = $cache['expires'];
$isExpired = ($expires !== false) && (time() > $expires);
if(empty($cache['content']) || $isExpired) {
$this->delete();
return false;
}
return $cache['content'];
}
public function put($content, $validity) {
$cacheFile = $this->cacheFile;
$expires = $validity ? time() + $validity : false;
$cache = array(
'expires' => $expires,
'content' => $content,
);
if(!file_exists('cache')) mkdir('cache');
$cacheContent = json_encode($cache)."\n";
if($this->isCompressed) $cacheContent = @gzencode($cacheContent);
@file_put_contents($cacheFile, $cacheContent);
}
}

View File

@ -16,7 +16,7 @@ limitations under the License.
*/ */
function uupApiVersion() { function uupApiVersion() {
return '1.32.2'; return '1.33.0';
} }
require_once dirname(__FILE__).'/auths.php'; require_once dirname(__FILE__).'/auths.php';

View File

@ -202,165 +202,12 @@ function uupGetInfoTexts() {
} }
function uupGetGenPacks($build = 15063, $arch = null, $updateId = null) { function uupGetGenPacks($build = 15063, $arch = null, $updateId = null) {
$internalPacks = dirname(__FILE__).'/packs'; if(empty($updateId)) return [];
if(!file_exists('packs/'.$updateId.'.json.gz')) return [];
if(!file_exists($internalPacks.'/metadata.json')) {
if(!uupCreateInternalPacksMetadata($internalPacks)) {
return array();
}
}
if(!empty($updateId)) {
if(file_exists('packs/'.$updateId.'.json.gz')) {
$genPack = @gzdecode(@file_get_contents('packs/'.$updateId.'.json.gz')); $genPack = @gzdecode(@file_get_contents('packs/'.$updateId.'.json.gz'));
if(empty($genPack)) return array(); if(empty($genPack)) return [];
$genPack = json_decode($genPack, 1); $genPack = json_decode($genPack, 1);
return $genPack; return $genPack;
} }
}
$metadata = @file_get_contents($internalPacks.'/metadata.json');
if(empty($metadata)) {
return array();
} else {
$metadata = json_decode($metadata, 1);
}
$hashDetermined = 0;
$useAllHashesForBuild = 0;
if($updateId) {
if(isset($metadata['knownIds'][$updateId])) {
$hash = $metadata['knownIds'][$updateId];
$hashDetermined = 1;
}
}
if(!$hashDetermined) {
foreach($metadata['knownBuilds'] as $buildNum => $val) {
if($build < $buildNum) continue;
$useBuild = $buildNum;
break;
}
if(!isset($useBuild)) {
return array();
}
if(!$arch && !isset($metadata['knownBuilds'][$useBuild][$arch])) {
$genPack = array();
foreach($metadata['knownBuilds'][$useBuild] as $hash) {
$temp = @gzdecode(@file_get_contents($internalPacks.'/'.$hash.'.json.gz'));
if(!empty($temp)) {
$temp = json_decode($temp, 1);
$genPack = array_merge_recursive($genPack, $temp);
unset($temp);
}
}
} elseif(!isset($metadata['knownBuilds'][$useBuild][$arch])) {
return array();
} else {
$hash = $metadata['knownBuilds'][$useBuild][$arch];
}
}
if(!isset($genPack)) {
$genPack = @gzdecode(@file_get_contents($internalPacks.'/'.$hash.'.json.gz'));
if(!empty($genPack)) {
$genPack = json_decode($genPack, 1);
} else {
$genPack = array();
}
}
return $genPack;
}
//Function to regenerate internal packs. Should not be used when not needed.
function uupCreateInternalPacksMetadata($internalPacks) {
$metadataCreationAllowed = 0;
if(!$metadataCreationAllowed) return false;
$builds = uupListIds();
if(isset($ids['error'])) {
return false;
}
$builds = $builds['builds'];
if(!file_exists('packs')) return false;
if(!file_exists($internalPacks)) {
if(!mkdir($internalPacks)) {
return false;
}
} else {
rmdir($internalPacks);
mkdir($internalPacks);
}
$files = scandir('packs');
$files = preg_grep('/\.json.gz$/', $files);
$packs = array();
foreach($builds as $build) {
$uuid = $build['uuid'];
$file = $uuid.'.json.gz';
if(!file_exists('packs/'.$file)) continue;
$genPack = @gzdecode(@file_get_contents('packs/'.$file));
$hash = hash('sha1', $genPack);
if(!file_exists($internalPacks.'/'.$hash.'.json.gz')) {
if(!copy('packs/'.$file, $internalPacks.'/'.$hash.'.json.gz')) {
return false;
}
}
$packs['knownIds'][$uuid] = $hash;
$buildNum = explode('.', $build['build']);
$buildNum = $buildNum[0];
$packs['knownBuilds'][$buildNum][$build['arch']] = $hash;
}
file_put_contents($internalPacks.'/metadata.json', json_encode($packs)."\n");
return true;
}
//Emulation of legacy packs. Do not use in new scripts due to extremely slow process.
function uupGetPacks($build = 15063) {
$returnArray = uupGetInfoTexts();
$genPack = uupGetGenPacks($build);
foreach($genPack as $lang => $editions) {
$packsForLangs[$lang] = array_keys($editions);
$packsForLangs[$lang][] = $lang;
foreach(array_keys($editions) as $edition) {
foreach($editions[$edition] as $name) {
$newName = preg_replace('/^cabs_|^metadataesd_|~31bf3856ad364e35/i', '', $name);
$newName = preg_replace('/~~\.|~\./', '.', $newName);
$newName = preg_replace('/~/', '-', $newName);
$newName = strtolower($newName);
$packs[$lang][$edition][] = $newName;
}
$editionPacks[$edition] = $edition;
$packs[$edition][$edition] = array();
$skipNeutral[$edition] = 1;
$skipLangPack[$edition] = 1;
}
}
$returnArray['packs'] = $packs;
$returnArray['packsForLangs'] = $packsForLangs;
$returnArray['editionPacks'] = $editionPacks;
$returnArray['skipNeutral'] = $skipNeutral;
$returnArray['skipLangPack'] = $skipLangPack;
return $returnArray;
}

Some files were not shown because too many files have changed in this diff Show More