Deprecate old packs system and replace it with internal generated packs

This commit is contained in:
mkuba50 2019-01-05 01:25:25 +01:00
parent 888cc470cb
commit d1911c2424
54 changed files with 224 additions and 254 deletions

173
get.php
View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2018 UUP dump API authors Copyright 2019 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.
@ -52,49 +52,22 @@ function uupGetFiles(
$info['sku'] = 48; $info['sku'] = 48;
} }
$packs = uupGetPacks($build); if($usePack) {
$packsForLangs = $packs['packsForLangs']; $genPack = uupGetGenPacks($build, $info['arch'], $updateId);
$editionPacks = $packs['editionPacks']; if(empty($genPack)) return array('error' => 'UNSUPPORTED_COMBINATION');
$checkEditions = $packs['allEditions'];
$skipNeutral = $packs['skipNeutral'];
$skipLangPack = $packs['skipLangPack'];
$packs = $packs['packs'];
$noLangPack = 0;
$noNeutral = 0;
$useGeneratedPacks = 0;
if(file_exists('packs/'.$updateId.'.json.gz') && $usePack) {
$genPack = @gzdecode(@file_get_contents('packs/'.$updateId.'.json.gz'));
if(!empty($genPack)) {
$genPack = json_decode($genPack, 1);
if(!isset($genPack[$usePack])) { if(!isset($genPack[$usePack])) {
return array('error' => 'UNSUPPORTED_LANG'); return array('error' => 'UNSUPPORTED_LANG');
} }
$packsForLangs = array();
$packsForLangs[$usePack] = array(0);
$useGeneratedPacks = 1;
}
}
if($usePack) {
$usePack = strtolower($usePack);
if(!isset($packsForLangs[$usePack])) {
return array('error' => 'UNSUPPORTED_LANG');
}
} }
$desiredEdition = strtoupper($desiredEdition); $desiredEdition = strtoupper($desiredEdition);
$fileListSource = $desiredEdition;
switch($desiredEdition) { switch($desiredEdition) {
case '0': case '0':
if($useGeneratedPacks) { if($usePack) {
$desiredEdition = 'GENERATEDPACKS'; $fileListSource = 'GENERATEDPACKS';
$filesList = array(); $filesList = array();
foreach($genPack[$usePack] as $val) { foreach($genPack[$usePack] as $val) {
@ -113,58 +86,15 @@ function uupGetFiles(
case 'UPDATEONLY': break; case 'UPDATEONLY': break;
default: default:
if($useGeneratedPacks) {
if(!isset($genPack[$usePack][$desiredEdition])) { if(!isset($genPack[$usePack][$desiredEdition])) {
return array('error' => 'UNSUPPORTED_COMBINATION'); return array('error' => 'UNSUPPORTED_COMBINATION');
} }
$filesList = $genPack[$usePack][$desiredEdition]; $filesList = $genPack[$usePack][$desiredEdition];
$desiredEdition = 'GENERATEDPACKS'; $fileListSource = 'GENERATEDPACKS';
break; break;
} }
if(!$usePack) {
return array('error' => 'UNSPECIFIED_LANG');
}
if(!isset($editionPacks[$desiredEdition])) {
return array('error' => 'UNSUPPORTED_EDITION');
}
$supported = 0;
foreach($packsForLangs[$usePack] as $val) {
if($editionPacks[$desiredEdition] == $val) $supported = 1;
}
if(!$supported) {
return array('error' => 'UNSUPPORTED_COMBINATION');
}
unset($supported);
if(isset($skipLangPack[$desiredEdition])) {
if($skipLangPack[$desiredEdition]) {
$noLangPack = 1;
}
}
if(isset($skipNeutral[$desiredEdition])) {
if($skipNeutral[$desiredEdition]) {
$noNeutral = 1;
}
}
$checkEditions = array($desiredEdition);
break;
}
if($noNeutral) {
foreach($packsForLangs[$usePack] as $num) {
if(isset($packs[$num]['editionNeutral'])) {
unset($packs[$num]['editionNeutral']);
}
}
}
$cacheHash = hash('sha1', strtolower("api-get-$updateId")); $cacheHash = hash('sha1', strtolower("api-get-$updateId"));
$cached = 0; $cached = 0;
@ -328,7 +258,7 @@ function uupGetFiles(
$filesKeys = array_keys($files); $filesKeys = array_keys($files);
switch($desiredEdition) { switch($fileListSource) {
case 'UPDATEONLY': case 'UPDATEONLY':
$skipPackBuild = 1; $skipPackBuild = 1;
$removeFiles = preg_grep('/Windows10\.0-KB.*-EXPRESS/i', $filesKeys); $removeFiles = preg_grep('/Windows10\.0-KB.*-EXPRESS/i', $filesKeys);
@ -350,73 +280,9 @@ function uupGetFiles(
$skipPackBuild = 1; $skipPackBuild = 1;
$filesKeys = preg_grep('/WindowsUpdateBox.exe/i', $filesKeys); $filesKeys = preg_grep('/WindowsUpdateBox.exe/i', $filesKeys);
break; break;
case 'GENERATEDPACKS':
$skipPackBuild = 1;
break;
default:
$skipPackBuild = 0;
break;
} }
if($usePack && !$skipPackBuild) { if($fileListSource == 'GENERATEDPACKS') {
$esd = array_keys($files);
$esd = preg_grep('/\.esd$/i', $esd);
foreach($esd as $key => $val) {
$esd[$key] = strtoupper($val);
}
foreach($checkEditions as $val) {
$testEsd[] = $val.'_'.strtoupper($usePack).'.ESD';
}
$foundMetadata = array_intersect($testEsd, $esd);
consoleLogger('Found '.count($foundMetadata).' metadata ESD file(s).');
if(empty($foundMetadata)) {
return array('error' => 'NO_METADATA_ESD');
}
$removeFiles = array();
$removeFiles[0] = preg_grep('/RetailDemo-OfflineContent/i', $filesKeys);
$removeFiles[1] = preg_grep('/Windows10\.0-KB.*-EXPRESS/i', $filesKeys);
foreach($removeFiles as $val) {
foreach($val as $temp) {
if(isset($files[$temp])) unset($files[$temp]);
}
}
unset($removeFiles, $temp, $val);
$filesKeys = array_keys($files);
$filesTemp = array();
if(!$noLangPack) {
$temp = preg_grep('/.*'.$usePack.'-Package.*/i', $filesKeys);
$filesTemp = array_merge($filesTemp, $temp);
$temp = preg_grep('/.*'.$usePack.'_lp..../i', $filesKeys);
$filesTemp = array_merge($filesTemp, $temp);
}
foreach($packsForLangs[$usePack] as $num) {
foreach($packs[$num] as $key => $val) {
if($key == 'editionNeutral'
|| $key == $desiredEdition
|| !$desiredEdition) {
$temp = packsByEdition($key, $val, $usePack, $filesKeys);
$filesTemp = array_merge($filesTemp, $temp);
}
}
}
$filesKeys = array_unique($filesTemp);
unset($filesTemp, $temp, $val, $num);
}
if($desiredEdition == 'GENERATEDPACKS') {
$temp = preg_grep('/Windows10\.0-KB.*-EXPRESS/i', $filesKeys, PREG_GREP_INVERT); $temp = preg_grep('/Windows10\.0-KB.*-EXPRESS/i', $filesKeys, PREG_GREP_INVERT);
$temp = preg_grep('/Windows10\.0-KB/i', $temp); $temp = preg_grep('/Windows10\.0-KB/i', $temp);
$filesList = array_merge($filesList, $temp); $filesList = array_merge($filesList, $temp);
@ -428,8 +294,10 @@ function uupGetFiles(
$name = preg_replace('/~/', '-', $name); $name = preg_replace('/~/', '-', $name);
$name = strtolower($name); $name = strtolower($name);
if(isset($files[$name])) {
$newFiles[$name] = $files[$name]; $newFiles[$name] = $files[$name];
} }
}
$files = $newFiles; $files = $newFiles;
$filesKeys = array_keys($files); $filesKeys = array_keys($files);
@ -456,20 +324,3 @@ function uupGetFiles(
'files' => $files, 'files' => $files,
); );
} }
function packsByEdition($edition, $pack, $lang, $filesKeys) {
$filesTemp = array();
if($edition != 'editionNeutral') {
$temp = preg_grep('/'.$edition.'_'.$lang.'\.esd/i', $filesKeys);
$filesTemp = array_merge($filesTemp, $temp);
}
foreach($pack as $val) {
$temp = preg_grep('/'.$val.'.*/i', $filesKeys);
$filesTemp = array_merge($filesTemp, $temp);
}
return $filesTemp;
}
?>

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2017 UUP dump API authors Copyright 2019 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,52 +21,36 @@ 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, 'build'); $info = uupUpdateInfo($updateId);
} }
if(isset($info['info'])) { if(isset($info['info'])) $info = $info['info'];
$build = explode('.', $info['info']);
if(isset($info['build'])) {
$build = explode('.', $info['build']);
$build = $build[0]; $build = $build[0];
} else { } else {
$build = 9841; $build = 9841;
} }
$packs = uupGetPacks($build); if(!isset($info['arch'])) {
$packsForLangs = $packs['packsForLangs']; $arch = null;
$fancyEditionNames = $packs['fancyEditionNames'];
$packs = $packs['packs'];
if(file_exists('packs/'.$updateId.'.json.gz')) {
$genPack = @gzdecode(@file_get_contents('packs/'.$updateId.'.json.gz'));
if(!empty($genPack)) {
$genPack = json_decode($genPack, 1);
if(!isset($genPack[$lang])) {
return array('error' => 'UNSUPPORTED_LANG');
} }
$packsForLangs = array(); $genPack = uupGetGenPacks($build, $info['arch'], $updateId);
$packsForLangs[$lang] = array(0); $fancyTexts = uupGetInfoTexts();
$fancyEditionNames = $fancyTexts['fancyEditionNames'];
$packs = array();
$packs[0] = $genPack[$lang];
}
}
if($lang) { if($lang) {
$lang = strtolower($lang); $lang = strtolower($lang);
if(!isset($packsForLangs[$lang])) { if(!isset($genPack[$lang])) {
return array('error' => 'UNSUPPORTED_LANG'); return array('error' => 'UNSUPPORTED_LANG');
} }
} }
$editionList = array(); $editionList = array();
$editionListFancy = array(); $editionListFancy = array();
foreach($packsForLangs[$lang] as $val) { foreach(array_keys($genPack[$lang]) as $edition) {
foreach(array_keys($packs[$val]) as $edition) {
if($edition == 'editionNeutral') continue;
if(isset($fancyEditionNames[$edition])) { if(isset($fancyEditionNames[$edition])) {
$fancyName = $fancyEditionNames[$edition]; $fancyName = $fancyEditionNames[$edition];
} else { } else {
@ -76,7 +60,6 @@ function uupListEditions($lang = 'en-us', $updateId = 0) {
$editionList[] = $edition; $editionList[] = $edition;
$editionListFancy[$edition] = $fancyName; $editionListFancy[$edition] = $fancyName;
} }
}
return array( return array(
'apiVersion' => uupApiVersion(), 'apiVersion' => uupApiVersion(),
@ -84,4 +67,3 @@ function uupListEditions($lang = 'en-us', $updateId = 0) {
'editionFancyNames' => $editionListFancy, 'editionFancyNames' => $editionListFancy,
); );
} }
?>

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2017 UUP dump API authors Copyright 2019 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,40 +21,37 @@ require_once dirname(__FILE__).'/updateinfo.php';
function uupListLangs($updateId = 0) { function uupListLangs($updateId = 0) {
if($updateId) { if($updateId) {
$info = uupUpdateInfo($updateId, 'build'); $info = uupUpdateInfo($updateId);
} }
if(isset($info['info'])) { if(isset($info['info'])) $info = $info['info'];
$build = explode('.', $info['info']);
if(isset($info['build'])) {
$build = explode('.', $info['build']);
$build = $build[0]; $build = $build[0];
} else { } else {
$build = 9841; $build = 9841;
} }
$packs = uupGetPacks($build); if(!isset($info['arch'])) {
$packsForLangs = $packs['packsForLangs']; $arch = null;
$fancyLangNames = $packs['fancyLangNames'];
if(file_exists('packs/'.$updateId.'.json.gz')) {
$genPack = @gzdecode(@file_get_contents('packs/'.$updateId.'.json.gz'));
if(!empty($genPack)) {
$genPack = json_decode($genPack, 1);
$packsForLangs = $genPack;
}
} }
$genPack = uupGetGenPacks($build, $info['arch'], $updateId);
$fancyTexts = uupGetInfoTexts();
$fancyLangNames = $fancyTexts['fancyLangNames'];
$langList = array(); $langList = array();
$langListFancy = array(); $langListFancy = array();
foreach($packsForLangs as $key => $val) { foreach(array_keys($genPack) as $val) {
if(isset($fancyLangNames[$key])) { if(isset($fancyLangNames[$val])) {
$fancyName = $fancyLangNames[$key]; $fancyName = $fancyLangNames[$val];
} else { } else {
$fancyName = $key; $fancyName = $val;
} }
$langList[] = $key; $langList[] = $val;
$langListFancy[$key] = $fancyName; $langListFancy[$val] = $fancyName;
} }
return array( return array(
@ -63,4 +60,3 @@ function uupListLangs($updateId = 0) {
'langFancyNames' => $langListFancy, 'langFancyNames' => $langListFancy,
); );
} }
?>

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2018 UUP dump API authors Copyright 2019 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.
@ -16,7 +16,7 @@ limitations under the License.
*/ */
function uupApiVersion() { function uupApiVersion() {
return '1.17.3'; return '1.18.0';
} }
require_once dirname(__FILE__).'/auths.php'; require_once dirname(__FILE__).'/auths.php';

View File

@ -15,7 +15,9 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
function uupGetPacks($build = 15063) { require_once dirname(__FILE__).'/../listid.php';
function uupGetInfoTexts() {
$fancyLangNames = array( $fancyLangNames = array(
'ar-sa' => 'Arabic (Saudi Arabia)', 'ar-sa' => 'Arabic (Saudi Arabia)',
'bg-bg' => 'Bulgarian', 'bg-bg' => 'Bulgarian',
@ -61,7 +63,7 @@ function uupGetPacks($build = 15063) {
$fancyEditionNames = array( $fancyEditionNames = array(
'CLOUD' => 'Windows 10 S', 'CLOUD' => 'Windows 10 S',
'CLOUDN' => 'Windows 10 S N', 'CLOUDN' => 'Windows 10 S N',
'CLOUDE' => 'Windows 10 CloudE', 'CLOUDE' => 'Windows 10 Lean',
'CORE' => 'Windows 10 Home', 'CORE' => 'Windows 10 Home',
'CORECOUNTRYSPECIFIC' => 'Windows 10 Home China', 'CORECOUNTRYSPECIFIC' => 'Windows 10 Home China',
'COREN' => 'Windows 10 Home N', 'COREN' => 'Windows 10 Home N',
@ -165,33 +167,171 @@ function uupGetPacks($build = 15063) {
'STARTERN', 'STARTERN',
); );
if($build < 17063) {
require dirname(__FILE__).'/packs/legacy.php';
} elseif ($build >= 17661) {
require dirname(__FILE__).'/packs/17661.php';
} elseif ($build >= 17655) {
require dirname(__FILE__).'/packs/17655.php';
} elseif ($build >= 17650) {
require dirname(__FILE__).'/packs/17650.php';
} elseif ($build >= 17634) {
require dirname(__FILE__).'/packs/17634.php';
} elseif ($build >= 17623) {
require dirname(__FILE__).'/packs/17623.php';
} elseif ($build >= 17093) {
require dirname(__FILE__).'/packs/17093.php';
} elseif ($build >= 17063) {
require dirname(__FILE__).'/packs/17063.php';
}
return array( return array(
'packs' => $packs,
'packsForLangs' => $packsForLangs,
'editionPacks' => $editionPacks,
'fancyEditionNames' => $fancyEditionNames, 'fancyEditionNames' => $fancyEditionNames,
'fancyLangNames' => $fancyLangNames, 'fancyLangNames' => $fancyLangNames,
'allEditions' => $allEditions, 'allEditions' => $allEditions,
'skipNeutral' => $skipNeutral,
'skipLangPack' => $skipLangPack,
); );
} }
?>
function uupGetGenPacks($build = 15063, $arch = null, $updateId = null) {
$internalPacks = dirname(__FILE__).'/packs';
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'));
if(empty($genPack)) return array();
$genPack = json_decode($genPack, 1);
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);
}
}
} 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;
}

File diff suppressed because one or more lines are too long