summaryrefslogtreecommitdiff
path: root/UICaboodle
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 /UICaboodle
parent092934d18a7bb1b3e1d768657293e99f432b5d0a (diff)
Honest-to-goodness Storage data.
Diffstat (limited to 'UICaboodle')
-rw-r--r--UICaboodle/BrowserView.m39
1 files changed, 39 insertions, 0 deletions
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];