summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2008-12-10 07:17:44 +0000
committerJay Freeman (saurik) <saurik@saurik.com>2010-09-30 07:09:08 +0000
commit59c011d87e67a2b7a44bf70576c7fa10e85698bc (patch)
tree3629f3d0ac28f172c0416159dff39ac83f22928c
parent092934d18a7bb1b3e1d768657293e99f432b5d0a (diff)
Honest-to-goodness Storage data.
-rw-r--r--Cydia.app/storage.html236
-rw-r--r--Cydia.app/storage.js53
-rw-r--r--Cydia.mm30
-rw-r--r--UICaboodle/BrowserView.m39
4 files changed, 357 insertions, 1 deletions
diff --git a/Cydia.app/storage.html b/Cydia.app/storage.html
new file mode 100644
index 0000000..21a87ad
--- /dev/null
+++ b/Cydia.app/storage.html
@@ -0,0 +1,236 @@
+<?xml version="1.0" encoding="UTF-16"?>
+<html><head>
+ <title>Storage</title>
+ <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"/>
+ <link rel="stylesheet" type="text/css" href="menes/style.css"/>
+ <script type="text/javascript" src="menes/menes.js"></script>
+ <script type="text/javascript" src="storage.js"></script>
+ <base target="_blank"/>
+
+ <style>
+ body {
+ display: table;
+ font-family: Helvetica;
+ height: 337px;
+ margin: 0;
+ padding: 0;
+ -webkit-text-size-adjust: none;
+ -webkit-user-select: none;
+ }
+
+ div.page {
+ display: table-cell;
+ text-align: center;
+ margin: 0 auto;
+ vertical-align: middle;
+ width: 320px;
+ }
+
+ a.giant-button {
+ color: #193250;
+ display: block;
+ margin: 8px 10px;
+ text-decoration: none;
+ }
+
+ a.giant-button > div.contents {
+ position: absolute;
+ text-align: left;
+ width: 300px;
+ -webkit-background-size: 75px auto;
+ z-index: 2;
+ }
+
+ a.giant-button > div.contents > piechart {
+ float: left;
+ margin: 10px;
+ vertical-align: middle;
+ }
+
+ a.giant-button > div.contents > label {
+ display: block;
+ float: left;
+ font-size: 25px;
+ margin: 10px 0 4px 4px;
+ text-align: center;
+ text-shadow: rgba(200, 200, 200, 0.75) 1px 1px 0;
+ width: 155px;
+ }
+
+ a.giant-button > div.contents > div.text {
+ display: block;
+ float: left;
+ font-size: 14px;
+ margin-left: 4px;
+ text-align: center;
+ width: 155px;
+ }
+
+ div.key {
+ display: inline-block;
+ width: 50%;
+ }
+
+ a.giant-button > div.contents > div.legend {
+ float: left;
+ font-size: 14px;
+ left: 15px;
+ position: absolute;
+ top: 120px;
+ width: 290px;
+ }
+
+ a.giant-button > div.background {
+ background-color: #000000;
+ opacity: 0.15;
+ -webkit-border-radius: 10px;
+ }
+
+ div.key {
+ margin-bottom: 4px;
+ }
+
+ piechart {
+ /*-webkit-transform: rotate(-5deg);*/
+ /*-webkit-transform: rotateY(15deg) rotateX(-45deg);*/
+ }
+
+ piechart > div {
+ height: 100px;
+ padding: 1px;
+ position: relative;
+ width: 103px;
+ }
+
+ piechart > div > div.lslice,
+ piechart > div > div.rslice {
+ background-color: #4d4d70;
+ height: 100px;
+ position: absolute;
+ }
+
+ piechart > div > div.lslice {
+ -webkit-border-bottom-left-radius: 50px;
+ -webkit-border-top-left-radius: 50px;
+ width: 50px;
+ z-index: 2;
+ }
+
+ piechart > div > div.rslice {
+ -webkit-border-bottom-right-radius: 50px;
+ -webkit-border-top-right-radius: 50px;
+ left: 49px;
+ width: 53px;
+ z-index: 0;
+ }
+
+ piechart > div > div.xslice {
+ -webkit-border-bottom-left-radius: 50px;
+ -webkit-border-top-left-radius: 50px;
+ height: 100px;
+ left: 2px;
+ position: absolute;
+ -webkit-transform-origin: 50px 50%;
+ width: 50px;
+ }
+
+ piechart > div > div.tslice {
+ position: absolute;
+ text-align: center;
+ top: 42px;
+ width: 100px;
+ z-index: 3;
+ }
+
+ piechart > div > div.tslice > div {
+ background-color: rgba(255, 255, 255, 0.7);
+ -webkit-border-radius: 7px;
+ display: inline;
+ color: black;
+ font-size: 15px;
+ font-weight: bold;
+ margin: 0 auto;
+ padding: 2px 4px;
+ text-align: center;
+ }
+
+ div.color {
+ background-color: black;
+ border: 1px solid #4d4d70;
+ display: inline-block;
+ vertical-align: middle;
+ }
+
+ div.color > div {
+ border: 1px solid white;
+ display: inline-block;
+ height: 12px;
+ width: 12px;
+ }
+
+ div.name {
+ display: inline-block;
+ font-size: 14px;
+ margin-left: 5px;
+ vertical-align: middle;
+ }
+ </style>
+</head><body class="pinstripe">
+<dialog>
+ <panel>
+
+<a class="giant-button">
+ <div class="contents">
+ <piechart id="system-chart"><div>
+ <div class="lslice"></div>
+ <div class="rslice"></div>
+ <div class="tslice"><div id="system-size"></div></div>
+ <div class="xslice" id="system-slice" style="
+ background-color: #7d7da0; -webkit-transform: rotate(10deg); z-index: 1;
+ "></div>
+ </div></piechart>
+
+ <label>System</label>
+ <div class="text">A small partition used to store iPhone OS. Cydia adds a few important programs and libraries.</div>
+
+ <div class="legend" id="system-legend"></div>
+ </div>
+
+ <div class="background" style="height: 149px"></div>
+</a>
+
+<a class="giant-button">
+ <div class="contents">
+ <piechart id="private-chart"><div>
+ <div class="lslice"></div>
+ <div class="rslice"></div>
+ <div class="tslice"><div id="private-size"></div></div>
+ <div class="xslice" id="private-slice" style="
+ background-color: #9090e0; -webkit-transform: rotate(150deg); z-index: 1;
+ "></div>
+ <div class="xslice" id="private-slice" style="
+ background-color: #7070e0; -webkit-transform: rotate(120deg); z-index: 1;
+ "></div>
+ <div class="xslice" id="private-slice" style="
+ background-color: #d0d0f0; -webkit-transform: rotate(90deg); z-index: 1;
+ "></div>
+ <div class="xslice" id="private-slice" style="
+ background-color: #7da0e0; -webkit-transform: rotate(60deg); z-index: 1;
+ "></div>
+ <div class="xslice" id="private-slice" style="
+ background-color: #7d7da0; -webkit-transform: rotate(30deg); z-index: 1;
+ "></div>
+ </div></piechart>
+
+ <label>Private</label>
+ <div class="text">Most content is stored on this partition: from applications (Cydia and Apple) to multimedia.</div>
+
+ <div class="legend" id="private-legend"></div>
+ </div>
+
+ <div class="background" style="height: 189px"></div>
+</a>
+
+ </panel>
+</dialog>
+</body></html>
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/"]
+ ]);
+});
diff --git a/Cydia.mm b/Cydia.mm
index 5e14c37..ae230f6 100644
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -79,6 +79,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
+#include <sys/param.h>
+#include <sys/mount.h>
#include <notify.h>
#include <dlfcn.h>
@@ -264,7 +266,7 @@ extern NSString * const kCAFilterNearest;
#define ForSaurik (1 && !ForRelease)
#define IgnoreInstall (0 && !ForRelease)
#define RecycleWebViews 0
-#define AlwaysReload (0 && !ForRelease)
+#define AlwaysReload (1 && !ForRelease)
/* Radix Sort {{{ */
@interface NSMutableArray (Radix)
@@ -4753,6 +4755,30 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
@end
/* }}} */
+/* Storage View {{{ */
+@interface StorageView : BrowserView {
+}
+
+@end
+
+@implementation StorageView
+
+- (NSString *) title {
+ return @"Storage";
+}
+
+#if !AlwaysReload
+- (id) _rightButtonTitle {
+ return nil;
+}
+#endif
+
+- (bool) _loading {
+ return false;
+}
+
+@end
+/* }}} */
/* Manage View {{{ */
@interface ManageView : BrowserView {
}
@@ -6732,6 +6758,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
if ([href isEqualToString:@"cydia://add-source"])
return [[[AddSourceView alloc] initWithBook:book_ database:database_] autorelease];
+ else if ([href isEqualToString:@"cydia://storage"])
+ return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[StorageView class]];
else if ([href isEqualToString:@"cydia://sources"])
return [[[SourceTable alloc] initWithBook:book_ database:database_] autorelease];
else if ([href isEqualToString:@"cydia://packages"])
diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m
index b3ed590..cb16bc8 100644
--- a/UICaboodle/BrowserView.m
+++ b/UICaboodle/BrowserView.m
@@ -204,6 +204,10 @@
return @"setButtonTitle";
else if (selector == @selector(supports:))
return @"supports";
+ else if (selector == @selector(du:))
+ return @"du";
+ else if (selector == @selector(statfs:))
+ return @"statfs";
else
return nil;
}
@@ -220,6 +224,41 @@
return [[Database sharedInstance] packageWithName:id];
}
+- (NSArray *) statfs:(NSString *)path {
+ struct statfs stat;
+
+ if (path == nil || statfs([path UTF8String], &stat) == -1)
+ return nil;
+
+ return [NSArray arrayWithObjects:
+ [NSNumber numberWithUnsignedLong:stat.f_bsize],
+ [NSNumber numberWithUnsignedLong:stat.f_blocks],
+ [NSNumber numberWithUnsignedLong:stat.f_bfree],
+ nil];
+}
+
+- (NSNumber *) du:(NSString *)path {
+ NSNumber *value(nil);
+
+ /* XXX: omfg this is stupid */
+ if (FILE *du = popen([[@"du -s " stringByAppendingString:path] UTF8String], "r")) {
+ char line[1024];
+ while (fgets(line, sizeof(line), du) != NULL) {
+ size_t length(strlen(line));
+ while (length != 0 && line[length - 1] == '\n')
+ line[--length] = '\0';
+ if (char *tab = strchr(line, '\t')) {
+ *tab = '\0';
+ value = [NSNumber numberWithUnsignedLong:strtoul(line, NULL, 0)];
+ }
+ }
+
+ pclose(du);
+ }
+
+ return value;
+}
+
- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
if (button_ != nil)
[button_ autorelease];