diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2008-12-10 07:17:44 +0000 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2010-09-30 07:09:08 +0000 |
commit | 59c011d87e67a2b7a44bf70576c7fa10e85698bc (patch) | |
tree | 3629f3d0ac28f172c0416159dff39ac83f22928c /Cydia.app/storage.js | |
parent | 092934d18a7bb1b3e1d768657293e99f432b5d0a (diff) |
Honest-to-goodness Storage data.
Diffstat (limited to 'Cydia.app/storage.js')
-rw-r--r-- | Cydia.app/storage.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Cydia.app/storage.js b/Cydia.app/storage.js new file mode 100644 index 0000000..926a61d --- /dev/null +++ b/Cydia.app/storage.js @@ -0,0 +1,53 @@ +var colors = ["#9090e0", "#4d4d70", "#7d7da0", "#7da0e0", "#d0d0f0", "#7070e0"]; + +var list = function (legend, color, name, value) { + legend.append('<div class="key">' + + '<div class="color" style="background-color: ' + color + '"><div></div></div>' + + '<div class="name">' + name + ' (' + Math.round(value * 1000) / 10 + '%)</div>' + + '</div>'); +}; + +console.log(cydia.statfs("/")); + +var setup = function (name, root, folders) { + var size = $("#" + name + "-size"); + var statfs = cydia.statfs(root); + var kb = statfs[0] * statfs[1] / 1024; + var total = kb / 1024; + + var unit; + if (total < 1000) + unit = 'M'; + else { + total = total / 1024; + unit = 'G' + } + + size.html(Math.round(total * 10) / 10 + " " + unit); + + var legend = $("#" + name + "-legend"); + var used = 0; + + if (folders != null) + for (var i = 0; i != folders.length; ++i) { + var folder = folders[i]; + var usage = cydia.du(folder[1]); + list(legend, colors[i + 2], folder[0], usage / kb); + total += usage; + } + + var free = statfs[0] * statfs[2] / 1024; + list(legend, colors[0], folders == null ? "Used" : "Other", (kb - free - total) / kb); + list(legend, colors[1], "Free", statfs[2] / statfs[1]); +}; + +$(function () { + setup("system", "/", null); + + setup("private", "/private/var", [ + ["Themes", "/Library/Themes/"], + ["iTunes", "/var/mobile/Media/iTunes_Control/"], + ["App Store", "/var/mobile/Applications/"], + ["Photos", "/var/mobile/Media/DCIM/"] + ]); +}); |