From 59c011d87e67a2b7a44bf70576c7fa10e85698bc Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 10 Dec 2008 07:17:44 +0000 Subject: [PATCH] Honest-to-goodness Storage data. --- Cydia.app/storage.html | 236 +++++++++++++++++++++++++++++++++++++++ Cydia.app/storage.js | 53 +++++++++ Cydia.mm | 30 ++++- UICaboodle/BrowserView.m | 39 +++++++ 4 files changed, 357 insertions(+), 1 deletion(-) create mode 100644 Cydia.app/storage.html create mode 100644 Cydia.app/storage.js diff --git a/Cydia.app/storage.html b/Cydia.app/storage.html new file mode 100644 index 00000000..21a87adc --- /dev/null +++ b/Cydia.app/storage.html @@ -0,0 +1,236 @@ + + + Storage + + + + + + + + + + + + +
+
+
+
+
+
+
+ + +
A small partition used to store iPhone OS. Cydia adds a few important programs and libraries.
+ +
+
+ +
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + +
Most content is stored on this partition: from applications (Cydia and Apple) to multimedia.
+ +
+
+ +
+
+ +
+
+ diff --git a/Cydia.app/storage.js b/Cydia.app/storage.js new file mode 100644 index 00000000..926a61d3 --- /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('
' + + '
' + + '
' + name + ' (' + Math.round(value * 1000) / 10 + '%)
' + + '
'); +}; + +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 5e14c372..ae230f69 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -79,6 +79,8 @@ #include #include #include +#include +#include #include #include @@ -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) @@ -4751,6 +4753,30 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return @"About"; } +@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 {{{ */ @@ -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 b3ed5909..cb16bc85 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]; -- 2.45.2