{ $base = log($size) / log(1024); $base = floor($base); $suffix = array("", "KB", "MB", "GB", "TB"); return round(pow(1024, $base - floor($base)), 1) . $suffix[$base]; } $GLOBALS['last'] = 0; \Lobby\Update::$progress = function ($resource, $download_size, $downloaded, $upload_size, $uploaded) { if ($download_size == 0) { $percent = 0; } else { $percent = round($downloaded / $download_size * 100, 0); } if ($GLOBALS['last'] != $percent) { $GLOBALS['last'] = $percent; $rd_size = convertToReadableSize($download_size); echo "<script>document.querySelector('.downloadStatus').innerHTML = 'Downloaded {$percent}% of {$rd_size}';</script>"; flush(); if ($percent == 100) { echo "<p>Installing <b>{$GLOBALS['name']}</b>...</p>"; flush(); } } }; if ($type == "app" && \Lobby\Update::app($id)) { echo "Installed - The app has been installed. <a target='_parent' href='" . L_URL . "/admin/install-app.php?action=enable&id={$_GET['id']}" . H::csrf("g") . "'>Enable the app</a> to use it."; } else { if ($type == "lobby" && ($redirect = \Lobby\Update::software())) { echo "<a target='_parent' href='{$redirect}'>Updated Lobby</a>"; } }
\Lobby\Update::$progress = function ($resource, $download_size, $downloaded, $upload_size, $uploaded = "") { /** * On new versions of cURL, $resource parameter is not passed * So, swap vars if it doesn't exist */ if (!is_resource($resource)) { $uploaded = $upload_size; $upload_size = $downloaded; $downloaded = $download_size; $download_size = $resource; } if ($download_size > 1000 && $downloaded > 0) { $percent = round($downloaded / $download_size * 100, 0); } else { $percent = 1; } if ($GLOBALS['last'] != $percent || isset($GLOBALS['non_percent'])) { $GLOBALS['last'] = $percent; if ($download_size > 0) { $rd_size = FS::normalizeSize($download_size); echo "<script>document.getElementById('downloadStatus').innerHTML = 'Downloaded {$percent}% of {$rd_size}';</script>"; } else { $downloaded = FS::normalizeSize($downloaded); $GLOBALS['non_percent'] = 1; echo "<script>document.getElementById('downloadStatus').innerHTML = 'Downloaded {$downloaded}';</script>"; } flush(); if ($percent == 100 && !isset($GLOBALS['install-msg-printed'])) { echo "<p>Installing <b>{$GLOBALS['name']}</b>...</p>"; $GLOBALS['install-msg-printed'] = 1; flush(); } } };