listlangs.php cleanup

This commit is contained in:
Kaenbyou Rin 2023-10-28 23:03:40 +02:00
parent db1e155c8d
commit 954547ea84

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2022 UUP dump API authors Copyright 2023 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.
@ -19,63 +19,45 @@ require_once dirname(__FILE__).'/shared/main.php';
require_once dirname(__FILE__).'/shared/packs.php'; require_once dirname(__FILE__).'/shared/packs.php';
require_once dirname(__FILE__).'/updateinfo.php'; require_once dirname(__FILE__).'/updateinfo.php';
function uupListLangs($updateId = 0) { function uupListLangsInternal($updateId) {
if($updateId) { $genPack = uupApiGetPacks($updateId);
$info = uupUpdateInfo($updateId, false, true); $fancyLangNames = uupGetInfoTexts()['fancyLangNames'];
}
if(isset($info['info'])) { $langList = [];
$info = $info['info']; $langListFancy = [];
unset($info['files']);
}
if(isset($info['build'])) {
$build = explode('.', $info['build']);
$build = $build[0];
} else {
$build = 15063;
}
if(!isset($info['arch'])) {
$info['arch'] = null;
}
$genPack = uupGetGenPacks($build, $info['arch'], $updateId);
$fancyTexts = uupGetInfoTexts();
$fancyLangNames = $fancyTexts['fancyLangNames'];
$langList = array();
$langListFancy = array();
foreach($genPack as $key => $val) { foreach($genPack as $key => $val) {
if(!count(array_diff(array_keys($val), array('LXP')))) { if(!count(array_diff(array_keys($val), ['LXP', 'FOD']))) {
continue;
}
if(!count(array_diff(array_keys($val), array('FOD')))) {
continue; continue;
} }
if(isset($fancyLangNames[$key])) { $fancyName = isset($fancyLangNames[$key]) ? $fancyLangNames[$key] : $key;
$fancyName = $fancyLangNames[$key];
} else {
$fancyName = $key;
}
$langList[] = $key; $langList[] = $key;
$langListFancy[$key] = $fancyName; $langListFancy[$key] = $fancyName;
} }
if(isset($info)) { return [
return array(
'apiVersion' => uupApiVersion(),
'langList' => $langList, 'langList' => $langList,
'langFancyNames' => $langListFancy, 'langFancyNames' => $langListFancy,
'updateInfo' => $info ];
); }
} else {
return array( function uupListLangs($updateId = 0, $returnInfo = true) {
'apiVersion' => uupApiVersion(), if($returnInfo) {
'langList' => $langList, $info = uupUpdateInfo($updateId, ignoreFiles: true);
'langFancyNames' => $langListFancy $info = isset($info['info']) ? $info['info'] : false;
); }
}
$langList = uupListLangsInternal($updateId);
$response = [
'apiVersion' => uupApiVersion(),
'langList' => $langList['langList'],
'langFancyNames' => $langList['langFancyNames'],
];
if($returnInfo) $response['updateInfo'] = $info;
return $response;
} }