| 1 |
<?php |
| 2 |
/* analyze.php |
| 3 |
* Copyright 2007 Bjørn Lindeijer |
| 4 |
* |
| 5 |
* This file is part of upalyzer. |
| 6 |
* |
| 7 |
* upalyzer is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* upalyzer is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with upalyzer. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
header("Content-type: text/html"); |
| 21 |
header("Cache-Control: no-store, no-cache, must-revalidate"); |
| 22 |
header("Cache-Control: post-check=0, pre-check=0", false); |
| 23 |
header("Pragma: no-cache"); |
| 24 |
|
| 25 |
?> |
| 26 |
<html> |
| 27 |
<head><title>Update analysis</title></head> |
| 28 |
<body> |
| 29 |
<pre> |
| 30 |
List of current updates: |
| 31 |
|
| 32 |
<?php |
| 33 |
$download_url_base = 'http://updates.themanaworld.org/tmwdata/'; |
| 34 |
$checkout_path = '/home/eathena/public_html/updates/tmwdata/'; |
| 35 |
$update_file = array_filter(array_reverse(file('resources2.txt'))); |
| 36 |
$updates = array(); |
| 37 |
$update_file_maxlen = 0; |
| 38 |
$data_size = 0; |
| 39 |
$data_uncompressed_size = 0; |
| 40 |
$data_used_size = 0; |
| 41 |
$data_overhead_size = 0; |
| 42 |
$update_entries = array(); |
| 43 |
$update_entry_maxlen = 0; |
| 44 |
|
| 45 |
foreach ($update_file as $update_line) |
| 46 |
{ |
| 47 |
list($file, $hash) = explode(' ', trim($update_line), 2); |
| 48 |
$update = array( |
| 49 |
'file' => $file, |
| 50 |
'adler32' => $hash, |
| 51 |
'filesize' => filesize($file), |
| 52 |
'size' => 0, |
| 53 |
'used_entry_count' => 0, |
| 54 |
'used_size' => 0, |
| 55 |
'uncompressed_size' => 0); |
| 56 |
$update_file_maxlen = max($update_file_maxlen, strlen($file)); |
| 57 |
|
| 58 |
$entries = array(); |
| 59 |
$zip = zip_open(realpath($file)); |
| 60 |
|
| 61 |
if ($zip && !is_int($zip)) { |
| 62 |
while ($zip_entry = zip_read($zip)) { |
| 63 |
$update['uncompressed_size'] += zip_entry_filesize($zip_entry); |
| 64 |
$entry_name = zip_entry_name($zip_entry); |
| 65 |
$entry_size = zip_entry_compressedsize($zip_entry); |
| 66 |
$entry_exists = file_exists($checkout_path . $entry_name); |
| 67 |
$entry_used = !array_key_exists($entry_name, $update_entries); |
| 68 |
$entries[$entry_name] = array( |
| 69 |
'name' => $entry_name, |
| 70 |
'size' => $entry_size, |
| 71 |
'used' => $entry_used, |
| 72 |
'obsolete' => !$entry_exists); |
| 73 |
$update['size'] += $entry_size; |
| 74 |
|
| 75 |
if ($entry_used) { |
| 76 |
if ($entry_exists) { |
| 77 |
$update['used_entry_count']++; |
| 78 |
$update['used_size'] += $entry_size; |
| 79 |
} |
| 80 |
$update_entries[$entry_name] = $update; |
| 81 |
} |
| 82 |
|
| 83 |
$update_entry_maxlen = max($update_entry_maxlen, strlen($entry_name)); |
| 84 |
} |
| 85 |
zip_close($zip); |
| 86 |
} |
| 87 |
else { |
| 88 |
$update['zip_error'] = $zip or true; |
| 89 |
} |
| 90 |
|
| 91 |
ksort($entries); |
| 92 |
$update['entries'] = $entries; |
| 93 |
$update['used_percentage'] = $update['used_size'] / $update['size']; |
| 94 |
$updates[] = $update; |
| 95 |
|
| 96 |
$data_used_size += $update['used_size']; |
| 97 |
$data_size += $update['size']; |
| 98 |
$data_uncompressed_size += $update['uncompressed_size']; |
| 99 |
$data_overhead_size += $update['filesize'] - $update['size']; |
| 100 |
} |
| 101 |
|
| 102 |
function print_update_name($update, $pad = true) |
| 103 |
{ |
| 104 |
global $update_file_maxlen; |
| 105 |
printf("<a href=\"#%s\">%s</a>", $update['file'], $update['file']); |
| 106 |
if ($pad) |
| 107 |
echo str_repeat(' ', $update_file_maxlen - strlen($update['file'])); |
| 108 |
} |
| 109 |
|
| 110 |
// Print overall statistics |
| 111 |
|
| 112 |
foreach (array_reverse($updates) as $update) |
| 113 |
{ |
| 114 |
print_update_name($update); |
| 115 |
printf(" %8s", $update['adler32']); |
| 116 |
printf(" %4d kb", $update['filesize'] / 1024); |
| 117 |
if (!$update['zip_error']) { |
| 118 |
printf(" %4d kb", $update['uncompressed_size'] / 1024); |
| 119 |
printf(" %3d%% used (%d/%d files)", $update['used_percentage'] * 100, |
| 120 |
$update['used_entry_count'], |
| 121 |
count($update['entries'])); |
| 122 |
} else { |
| 123 |
printf(" Error! "); |
| 124 |
if (is_int($update['zip_error'])) |
| 125 |
echo $update['zip_error']; |
| 126 |
} |
| 127 |
echo "\n"; |
| 128 |
} |
| 129 |
|
| 130 |
printf("\n"); |
| 131 |
printf("Amount of data: %4d kb (+%d kb zip file overhead)\n", |
| 132 |
$data_size / 1024, |
| 133 |
$data_overhead_size / 1024); |
| 134 |
printf("Uncompressed: %4d kb\n", $data_uncompressed_size / 1024); |
| 135 |
printf("Obsoleted data: %4d kb (%d%%)\n", |
| 136 |
($data_size - $data_used_size) / 1024, |
| 137 |
100 - ($data_used_size / $data_size) * 100); |
| 138 |
|
| 139 |
printf("\n"); |
| 140 |
|
| 141 |
|
| 142 |
// Print list of update entries and the update they are loaded from |
| 143 |
|
| 144 |
ksort($update_entries); |
| 145 |
|
| 146 |
foreach ($update_entries as $entry => $update) |
| 147 |
{ |
| 148 |
$exists = file_exists($checkout_path . $entry); |
| 149 |
printf("<span style=\"color: %s;\">%-{$update_entry_maxlen}s</span> ", |
| 150 |
$exists ? "black" : "rgb(100,100,100)", |
| 151 |
$entry); |
| 152 |
print_update_name($update, true); |
| 153 |
|
| 154 |
if ($exists && substr($entry, strlen($entry) - 1) != '/') |
| 155 |
printf(' <a href="%s%s">download</a>', $download_url_base, $entry); |
| 156 |
echo "\n"; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
// For each update, print its list of files and indicate whether they are used |
| 161 |
|
| 162 |
foreach (array_reverse($updates) as $update) |
| 163 |
{ |
| 164 |
print "\n<a name=\"".$update['file']."\"/><b>".$update['file']."</b>\n"; |
| 165 |
|
| 166 |
foreach ($update['entries'] as $entry_name => $entry) { |
| 167 |
printf("%s%-{$update_entry_maxlen}s%s", |
| 168 |
$entry['obsolete'] ? "<span style=\"color: rgb(100,100,100);\">" : "", |
| 169 |
$entry_name, |
| 170 |
$entry['obsolete'] ? "</span>" : ""); |
| 171 |
if ($entry['used'] && !$entry['obsolete']) { |
| 172 |
echo ' *'; |
| 173 |
} elseif (!$entry['obsolete']) { |
| 174 |
echo ' '; |
| 175 |
print_update_name($update_entries[$entry_name], false); |
| 176 |
} |
| 177 |
echo "\n"; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
/* |
| 182 |
if ($dh = opendir('.')) { |
| 183 |
while (($file = readdir($dh)) !== false) { |
| 184 |
} |
| 185 |
closedir($dh); |
| 186 |
} |
| 187 |
*/ |
| 188 |
?> |
| 189 |
</pre> |
| 190 |
</body> |
| 191 |
</html> |