summaryrefslogtreecommitdiff
path: root/tools/upalyzer/analyze.php
diff options
context:
space:
mode:
Diffstat (limited to 'tools/upalyzer/analyze.php')
-rw-r--r--tools/upalyzer/analyze.php79
1 files changed, 34 insertions, 45 deletions
diff --git a/tools/upalyzer/analyze.php b/tools/upalyzer/analyze.php
index 45ba2f0c..36842a6d 100644
--- a/tools/upalyzer/analyze.php
+++ b/tools/upalyzer/analyze.php
@@ -26,13 +26,15 @@
List of current updates:
<?php
-$update_file = file('resources2.txt');
+$update_file = array_filter(array_reverse(file('resources2.txt')));
$updates = array();
$update_file_maxlen = 0;
$data_size = 0;
$data_uncompressed_size = 0;
$data_used_size = 0;
$data_overhead_size = 0;
+$update_entries = array();
+$update_entry_maxlen = 0;
foreach ($update_file as $update_line)
{
@@ -42,71 +44,51 @@ foreach ($update_file as $update_line)
'file' => $file,
'adler32' => trim($splitted[1]),
'filesize' => filesize($file),
- 'size' => 0);
+ 'size' => 0,
+ 'used_entry_count' => 0,
+ 'used_size' => 0,
+ 'uncompressed_size' => 0);
$update_file_maxlen = max($update_file_maxlen, strlen($file));
- $uncompressed_size = 0;
$entries = array();
$zip = zip_open($file);
+
if ($zip) {
while ($zip_entry = zip_read($zip)) {
- $uncompressed_size = $uncompressed_size + zip_entry_filesize($zip_entry);
+ $update['uncompressed_size'] += zip_entry_filesize($zip_entry);
+ $entry_name = zip_entry_name($zip_entry);
$entry_size = zip_entry_compressedsize($zip_entry);
+ $entry_used = !array_key_exists($entry_name, $update_entries);
$entries[zip_entry_name($zip_entry)] = array(
- 'name' => zip_entry_name($zip_entry),
- 'size' => $entry_size);
+ 'name' => $entry_name,
+ 'size' => $entry_size,
+ 'used' => $entry_used);
$update['size'] += $entry_size;
+
+ if ($entry_used) {
+ $update['used_entry_count']++;
+ $update['used_size'] += $entry_size;
+ }
+
+ $update_entries[$entry_name] = $update['file'];
+ $update_entry_maxlen = max($update_entry_maxlen, strlen($entry_name));
}
zip_close($zip);
}
+
$update['entries'] = $entries;
- $update['uncompressed_size'] = $uncompressed_size;
+ $update['used_percentage'] = $update['used_size'] / $update['size'];
$updates[] = $update;
+ $data_used_size += $update['used_size'];
$data_size += $update['size'];
- $data_uncompressed_size += $uncompressed_size;
+ $data_uncompressed_size += $update['uncompressed_size'];
$data_overhead_size += $update['filesize'] - $update['size'];
}
-function get_update_for_file($file)
-{
- global $updates;
-
- for ($i = count($updates) - 1; $i >= 0; $i--) {
- $update = $updates[$i];
- if (array_key_exists($file, $update['entries'])) {
- return $update;
- }
- }
- return null;
-}
-
-foreach ($updates as &$update)
-{
- $entry_count = count($update['entries']);
- $used_entry_count = 0;
- $used_entry_size = 0;
-
- foreach ($update['entries'] as $file => $entry) {
- $update_for_file = get_update_for_file($file);
- if (strcmp($update_for_file['file'], $update['file']) == 0) {
- $used_entry_count++;
- $used_entry_size += $entry['size'];
- $entry['used'] = true;
- }
- }
-
- $update['used_entry_count'] = $used_entry_count;
- $update['used_size'] = $used_entry_size;
- $update['used_percentage'] = $used_entry_size / $update['size'];
-
- $data_used_size += $update['used_size'];
-}
-
foreach ($updates as &$update)
{
- echo $update['file'];
- echo str_repeat(' ', $update_file_maxlen - strlen($update['file']) + 2);
+ printf("%-{$update_file_maxlen}s ", $update['file']);
echo $update['adler32'];
printf(" %4d kb", $update['filesize'] / 1024);
printf(" %4d kb", $update['uncompressed_size'] / 1024);
@@ -125,6 +107,13 @@ printf("Obsoleted data: %4d kb (%d%%)\n",
($data_size - $data_used_size) / 1024,
100 - ($data_used_size / $data_size) * 100);
+printf("\n");
+
+foreach ($update_entries as $entry => $update)
+{
+ printf("%-{$update_entry_maxlen}s %s\n", $entry, $update);
+}
+
/*
if ($dh = opendir('.')) {
while (($file = readdir($dh)) !== false) {