]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Centralize addCydiaHost: to Cydia delegate_.
[cydia.git] / MobileCydia.mm
index ddec663963debce48ababdefa004c942b589e405..617562f6d68f8d63e4c99c474237ebe6ff7d6c64 100644 (file)
@@ -125,6 +125,8 @@ extern "C" {
 #include "SDURLCache/SDURLCache.h"
 
 #include "substrate.h"
 #include "SDURLCache/SDURLCache.h"
 
 #include "substrate.h"
+
+#include "Version.h"
 /* }}} */
 
 /* Profiler {{{ */
 /* }}} */
 
 /* Profiler {{{ */
@@ -218,12 +220,13 @@ union SplitHash {
 static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
 
 static _finline NSString *CydiaURL(NSString *path) {
 static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
 
 static _finline NSString *CydiaURL(NSString *path) {
-    char page[25];
-    page[0] = 'h'; page[1] = 't'; page[2] = 't'; page[3] = 'p'; page[4] = ':';
-    page[5] = '/'; page[6] = '/'; page[7] = 'c'; page[8] = 'y'; page[9] = 'd';
-    page[10] = 'i'; page[11] = 'a'; page[12] = '.'; page[13] = 's'; page[14] = 'a';
-    page[15] = 'u'; page[16] = 'r'; page[17] = 'i'; page[18] = 'k'; page[19] = '.';
-    page[20] = 'c'; page[21] = 'o'; page[22] = 'm'; page[23] = '/'; page[24] = '\0';
+    char page[26];
+    page[0] = 'h'; page[1] = 't'; page[2] = 't'; page[3] = 'p'; page[4] = 's';
+    page[5] = ':'; page[6] = '/'; page[7] = '/'; page[8] = 'c'; page[9] = 'y';
+    page[10] = 'd'; page[11] = 'i'; page[12] = 'a'; page[13] = '.'; page[14] = 's';
+    page[15] = 'a'; page[16] = 'u'; page[17] = 'r'; page[18] = 'i'; page[19] = 'k';
+    page[20] = '.'; page[21] = 'c'; page[22] = 'o'; page[23] = 'm'; page[24] = '/';
+    page[25] = '\0';
     return [[NSString stringWithUTF8String:page] stringByAppendingString:path];
 }
 
     return [[NSString stringWithUTF8String:page] stringByAppendingString:path];
 }
 
@@ -1025,7 +1028,6 @@ static UIColor *InstallingColor_;
 static UIColor *RemovingColor_;
 
 static NSString *App_;
 static UIColor *RemovingColor_;
 
 static NSString *App_;
-static NSString *Home_;
 
 static BOOL Advanced_;
 static BOOL Ignored_;
 
 static BOOL Advanced_;
 static BOOL Ignored_;
@@ -1040,7 +1042,7 @@ static const char *Machine_ = NULL;
 static NSString *System_ = nil;
 static NSString *SerialNumber_ = nil;
 static NSString *ChipID_ = nil;
 static NSString *System_ = nil;
 static NSString *SerialNumber_ = nil;
 static NSString *ChipID_ = nil;
-static NSString *Token_ = nil;
+static _H<NSString> Token_;
 static NSString *UniqueID_ = nil;
 static NSString *PLMN_ = nil;
 static NSString *Build_ = nil;
 static NSString *UniqueID_ = nil;
 static NSString *PLMN_ = nil;
 static NSString *Build_ = nil;
@@ -1063,6 +1065,9 @@ static time_t now_;
 
 bool IsWildcat_;
 static CGFloat ScreenScale_;
 
 bool IsWildcat_;
 static CGFloat ScreenScale_;
+static NSString *Idiom_;
+
+static NSMutableSet *CydiaHosts_;
 /* }}} */
 
 /* Display Helpers {{{ */
 /* }}} */
 
 /* Display Helpers {{{ */
@@ -1165,6 +1170,7 @@ bool isSectionVisible(NSString *section) {
 - (CYViewController *) pageForPackage:(NSString *)name;
 - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
 - (void) reloadDataWithInvocation:(NSInvocation *)invocation;
 - (CYViewController *) pageForPackage:(NSString *)name;
 - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
 - (void) reloadDataWithInvocation:(NSInvocation *)invocation;
+- (void) addCydiaHost:(NSString *)host;
 @end
 /* }}} */
 
 @end
 /* }}} */
 
@@ -1172,21 +1178,31 @@ bool isSectionVisible(NSString *section) {
 @interface CydiaProgressEvent : NSObject {
     _H<NSString> message_;
     _H<NSString> type_;
 @interface CydiaProgressEvent : NSObject {
     _H<NSString> message_;
     _H<NSString> type_;
+
+    _H<NSArray> item_;
     _H<NSString> package_;
     _H<NSString> package_;
-    _H<NSString> uri_;
+    _H<NSString> url_;
+    _H<NSString> version_;
 }
 
 + (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type;
 + (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forPackage:(NSString *)package;
 }
 
 + (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type;
 + (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forPackage:(NSString *)package;
++ (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forItem:(pkgAcquire::ItemDesc &)item;
 
 - (id) initWithMessage:(NSString *)message ofType:(NSString *)type;
 
 - (NSString *) message;
 - (NSString *) type;
 
 - (id) initWithMessage:(NSString *)message ofType:(NSString *)type;
 
 - (NSString *) message;
 - (NSString *) type;
+
+- (NSArray *) item;
 - (NSString *) package;
 - (NSString *) package;
-- (NSString *) uri;
+- (NSString *) url;
+- (NSString *) version;
 
 
+- (void) setItem:(NSArray *)item;
 - (void) setPackage:(NSString *)package;
 - (void) setPackage:(NSString *)package;
+- (void) setURL:(NSString *)url;
+- (void) setVersion:(NSString *)version;
 
 - (NSString *) compound:(NSString *)value;
 - (NSString *) compoundMessage;
 
 - (NSString *) compound:(NSString *)value;
 - (NSString *) compoundMessage;
@@ -1197,6 +1213,7 @@ bool isSectionVisible(NSString *section) {
 @protocol ProgressDelegate
 - (void) addProgressEvent:(CydiaProgressEvent *)event;
 - (void) setProgressPercent:(NSNumber *)percent;
 @protocol ProgressDelegate
 - (void) addProgressEvent:(CydiaProgressEvent *)event;
 - (void) setProgressPercent:(NSNumber *)percent;
+- (void) setProgressStatus:(NSDictionary *)status;
 - (void) setProgressCancellable:(NSNumber *)cancellable;
 - (bool) isProgressCancelled;
 - (void) setTitle:(NSString *)title;
 - (void) setProgressCancellable:(NSNumber *)cancellable;
 - (bool) isProgressCancelled;
 - (void) setTitle:(NSString *)title;
@@ -1234,7 +1251,7 @@ class Status :
 
     virtual void Fetch(pkgAcquire::ItemDesc &item) {
         NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]);
 
     virtual void Fetch(pkgAcquire::ItemDesc &item) {
         NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]);
-        CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:UCLocalize("DOWNLOADING_"), name] ofType:@"STATUS"]);
+        CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:UCLocalize("DOWNLOADING_"), name] ofType:@"STATUS" forItem:item]);
         [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
     }
 
         [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
     }
 
@@ -1252,23 +1269,26 @@ class Status :
         if (error.empty())
             return;
 
         if (error.empty())
             return;
 
-        //NSString *description([NSString stringWithUTF8String:item.Description.c_str()]);
-        //NSArray *fields([description componentsSeparatedByString:@" "]);
-        //NSString *source([fields count] == 0 ? nil : [fields objectAtIndex:0]);
-
-        CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:@"ERROR"]);
+        CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:@"ERROR" forItem:item]);
         [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
     }
 
     virtual bool Pulse(pkgAcquire *Owner) {
         bool value = pkgAcquireStatus::Pulse(Owner);
 
         [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
     }
 
     virtual bool Pulse(pkgAcquire *Owner) {
         bool value = pkgAcquireStatus::Pulse(Owner);
 
-        float percent(
+        double percent(
             double(CurrentBytes + CurrentItems) /
             double(TotalBytes + TotalItems)
         );
 
             double(CurrentBytes + CurrentItems) /
             double(TotalBytes + TotalItems)
         );
 
-        [delegate_ performSelectorOnMainThread:@selector(setProgressPercent:) withObject:[NSNumber numberWithFloat:percent] waitUntilDone:YES];
+        [delegate_ performSelectorOnMainThread:@selector(setProgressStatus:) withObject:[NSDictionary dictionaryWithObjectsAndKeys:
+            [NSNumber numberWithDouble:percent], @"Percent",
+
+            [NSNumber numberWithDouble:CurrentBytes], @"Current",
+            [NSNumber numberWithDouble:TotalBytes], @"Total",
+            [NSNumber numberWithDouble:CurrentCPS], @"Speed",
+        nil] waitUntilDone:YES];
+
         if (value && ![delegate_ isProgressCancelled])
             return true;
         else {
         if (value && ![delegate_ isProgressCancelled])
             return true;
         else {
@@ -1289,6 +1309,7 @@ class Status :
     virtual void Stop() {
         pkgAcquireStatus::Stop();
         [delegate_ performSelectorOnMainThread:@selector(setProgressCancellable:) withObject:[NSNumber numberWithBool:NO] waitUntilDone:YES];
     virtual void Stop() {
         pkgAcquireStatus::Stop();
         [delegate_ performSelectorOnMainThread:@selector(setProgressCancellable:) withObject:[NSNumber numberWithBool:NO] waitUntilDone:YES];
+        [delegate_ performSelectorOnMainThread:@selector(setProgressStatus:) withObject:nil waitUntilDone:YES];
     }
 };
 /* }}} */
     }
 };
 /* }}} */
@@ -1381,12 +1402,31 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
     return event;
 }
 
     return event;
 }
 
++ (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forItem:(pkgAcquire::ItemDesc &)item {
+    CydiaProgressEvent *event([self eventWithMessage:message ofType:type]);
+
+    NSString *description([NSString stringWithUTF8String:item.Description.c_str()]);
+    NSArray *fields([description componentsSeparatedByString:@" "]);
+    [event setItem:fields];
+
+    if ([fields count] > 3) {
+        [event setPackage:[fields objectAtIndex:2]];
+        [event setVersion:[fields objectAtIndex:3]];
+    }
+
+    [event setURL:[NSString stringWithUTF8String:item.URI.c_str()]];
+
+    return event;
+}
+
 + (NSArray *) _attributeKeys {
     return [NSArray arrayWithObjects:
 + (NSArray *) _attributeKeys {
     return [NSArray arrayWithObjects:
+        @"item",
         @"message",
         @"package",
         @"type",
         @"message",
         @"package",
         @"type",
-        @"uri",
+        @"url",
+        @"version",
     nil];
 }
 
     nil];
 }
 
@@ -1413,18 +1453,38 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
     return type_;
 }
 
     return type_;
 }
 
-- (NSString *) package {
-    return package_;
+- (NSArray *) item {
+    return (id) item_ ?: [NSNull null];
 }
 
 }
 
-- (NSString *) uri {
-    return uri_;
+- (void) setItem:(NSArray *)item {
+    item_ = item;
+}
+
+- (NSString *) package {
+    return (id) package_ ?: [NSNull null];
 }
 
 - (void) setPackage:(NSString *)package {
     package_ = package;
 }
 
 }
 
 - (void) setPackage:(NSString *)package {
     package_ = package;
 }
 
+- (NSString *) url {
+    return (id) url_ ?: [NSNull null];
+}
+
+- (void) setURL:(NSString *)url {
+    url_ = url;
+}
+
+- (void) setVersion:(NSString *)version {
+    version_ = version;
+}
+
+- (NSString *) version {
+    return (id) version_ ?: [NSNull null];
+}
+
 - (NSString *) compound:(NSString *)value {
     if (value != nil) {
         NSString *mode(nil); {
 - (NSString *) compound:(NSString *)value {
     if (value != nil) {
         NSString *mode(nil); {
@@ -1581,12 +1641,12 @@ static void PackageImport(const void *key, const void *value, void *context) {
     CYString type_;
     CYString version_;
 
     CYString type_;
     CYString version_;
 
-    NSString *host_;
-    NSString *authority_;
+    _H<NSString> host_;
+    _H<NSString> authority_;
 
     CYString defaultIcon_;
 
 
     CYString defaultIcon_;
 
-    NSDictionary *record_;
+    _H<NSDictionary> record_;
     BOOL trusted_;
 }
 
     BOOL trusted_;
 }
 
@@ -1631,20 +1691,9 @@ static void PackageImport(const void *key, const void *value, void *context) {
     version_.clear();
     defaultIcon_.clear();
 
     version_.clear();
     defaultIcon_.clear();
 
-    if (record_ != nil) {
-        [record_ release];
-        record_ = nil;
-    }
-
-    if (host_ != nil) {
-        [host_ release];
-        host_ = nil;
-    }
-
-    if (authority_ != nil) {
-        [authority_ release];
-        authority_ = nil;
-    }
+    record_ = nil;
+    host_ = nil;
+    authority_ = nil;
 }
 
 - (void) dealloc {
 }
 
 - (void) dealloc {
@@ -1722,22 +1771,18 @@ static void PackageImport(const void *key, const void *value, void *context) {
     }
 
     record_ = [Sources_ objectForKey:[self key]];
     }
 
     record_ = [Sources_ objectForKey:[self key]];
-    if (record_ != nil)
-        record_ = [record_ retain];
 
     NSURL *url([NSURL URLWithString:uri_]);
 
     host_ = [url host];
     if (host_ != nil)
 
     NSURL *url([NSURL URLWithString:uri_]);
 
     host_ = [url host];
     if (host_ != nil)
-        host_ = [[host_ lowercaseString] retain];
+        host_ = [host_ lowercaseString];
 
     if (host_ != nil)
 
     if (host_ != nil)
-        authority_ = host_;
+        // XXX: this is due to a bug in _H<>
+        authority_ = (id) host_;
     else
         authority_ = [url path];
     else
         authority_ = [url path];
-
-    if (authority_ != nil)
-        authority_ = [authority_ retain];
 }
 
 - (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
 }
 
 - (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
@@ -1806,7 +1851,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 }
 
 - (NSString *) name {
 }
 
 - (NSString *) name {
-    return origin_.empty() ? authority_ : origin_;
+    return origin_.empty() ? (id) authority_ : origin_;
 }
 
 - (NSString *) description {
 }
 
 - (NSString *) description {
@@ -1814,7 +1859,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 }
 
 - (NSString *) label {
 }
 
 - (NSString *) label {
-    return label_.empty() ? authority_ : label_;
+    return label_.empty() ? (id) authority_ : label_;
 }
 
 - (NSString *) origin {
 }
 
 - (NSString *) origin {
@@ -2318,13 +2363,16 @@ struct PackageNameOrdering :
         @"purposes",
         @"relations",
         @"section",
         @"purposes",
         @"relations",
         @"section",
+        @"selection",
         @"shortDescription",
         @"shortSection",
         @"simpleSection",
         @"size",
         @"source",
         @"sponsor",
         @"shortDescription",
         @"shortSection",
         @"simpleSection",
         @"size",
         @"source",
         @"sponsor",
+        @"state",
         @"support",
         @"support",
+        @"tags",
         @"warnings",
     nil];
 }
         @"warnings",
     nil];
 }
@@ -2873,6 +2921,54 @@ struct PackageNameOrdering :
     return files;
 }
 
     return files;
 }
 
+- (NSString *) state {
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
+        return nil;
+
+    switch (iterator_->CurrentState) {
+        case pkgCache::State::NotInstalled:
+            return @"NotInstalled";
+        case pkgCache::State::UnPacked:
+            return @"UnPacked";
+        case pkgCache::State::HalfConfigured:
+            return @"HalfConfigured";
+        case pkgCache::State::HalfInstalled:
+            return @"HalfInstalled";
+        case pkgCache::State::ConfigFiles:
+            return @"ConfigFiles";
+        case pkgCache::State::Installed:
+            return @"Installed";
+        case pkgCache::State::TriggersAwaited:
+            return @"TriggersAwaited";
+        case pkgCache::State::TriggersPending:
+            return @"TriggersPending";
+    }
+
+    return (NSString *) [NSNull null];
+} }
+
+- (NSString *) selection {
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
+        return nil;
+
+    switch (iterator_->SelectedState) {
+        case pkgCache::State::Unknown:
+            return @"Unknown";
+        case pkgCache::State::Install:
+            return @"Install";
+        case pkgCache::State::Hold:
+            return @"Hold";
+        case pkgCache::State::DeInstall:
+            return @"DeInstall";
+        case pkgCache::State::Purge:
+            return @"Purge";
+    }
+
+    return (NSString *) [NSNull null];
+} }
+
 - (NSArray *) warnings {
     NSMutableArray *warnings([NSMutableArray arrayWithCapacity:4]);
     const char *name(iterator_.Name());
 - (NSArray *) warnings {
     NSMutableArray *warnings([NSMutableArray arrayWithCapacity:4]);
     const char *name(iterator_.Name());
@@ -3011,6 +3107,10 @@ struct PackageNameOrdering :
     _assert(false);
 }
 
     _assert(false);
 }
 
+- (NSArray *) tags {
+    return tags_;
+}
+
 - (BOOL) hasTag:(NSString *)tag {
     return tags_ == nil ? NO : [tags_ containsObject:tag];
 }
 - (BOOL) hasTag:(NSString *)tag {
     return tags_ == nil ? NO : [tags_ containsObject:tag];
 }
@@ -3334,14 +3434,23 @@ static NSString *Warning_;
         size_t size(line.size());
         lprintf("S:%s\n", data);
 
         size_t size(line.size());
         lprintf("S:%s\n", data);
 
-        if (conffile_r(data, size))
+        if (conffile_r(data, size)) {
+            // status: /fail : conffile-prompt : '/fail' '/fail.dpkg-new' 1 1
             [delegate_ performSelectorOnMainThread:@selector(setConfigurationData:) withObject:conffile_r[1] waitUntilDone:YES];
             [delegate_ performSelectorOnMainThread:@selector(setConfigurationData:) withObject:conffile_r[1] waitUntilDone:YES];
-        else if (strncmp(data, "status: ", 8) == 0) {
+        } else if (strncmp(data, "status: ", 8) == 0) {
+            // status: <package>: {unpacked,half-configured,installed}
             CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:(data + 8)] ofType:@"STATUS"]);
             CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:(data + 8)] ofType:@"STATUS"]);
-            [progress_ performSelectorOnMainThread:@selector(addProgressEvent) withObject:event waitUntilDone:YES];
+            [progress_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
+        } else if (strncmp(data, "processing: ", 12) == 0) {
+            // processing: configure: config-test
+            CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:(data + 12)] ofType:@"STATUS"]);
+            [progress_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
         } else if (pmstatus_r(data, size)) {
             std::string type([pmstatus_r[1] UTF8String]);
         } else if (pmstatus_r(data, size)) {
             std::string type([pmstatus_r[1] UTF8String]);
+
             NSString *package = pmstatus_r[2];
             NSString *package = pmstatus_r[2];
+            if ([package isEqualToString:@"dpkg-exec"])
+                package = nil;
 
             float percent([pmstatus_r[3] floatValue]);
             [progress_ performSelectorOnMainThread:@selector(setProgressPercent:) withObject:[NSNumber numberWithFloat:(percent / 100)] waitUntilDone:YES];
 
             float percent([pmstatus_r[3] floatValue]);
             [progress_ performSelectorOnMainThread:@selector(setProgressPercent:) withObject:[NSNumber numberWithFloat:(percent / 100)] waitUntilDone:YES];
@@ -3572,8 +3681,9 @@ static NSString *Warning_;
             [delegate_ repairWithSelector:@selector(configure)];
         else if (error == "The package lists or status file could not be parsed or opened.")
             [delegate_ repairWithSelector:@selector(update)];
             [delegate_ repairWithSelector:@selector(configure)];
         else if (error == "The package lists or status file could not be parsed or opened.")
             [delegate_ repairWithSelector:@selector(update)];
-        // else if (error == "Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied)")
         // else if (error == "Could not get lock /var/lib/dpkg/lock - open (35 Resource temporarily unavailable)")
         // else if (error == "Could not get lock /var/lib/dpkg/lock - open (35 Resource temporarily unavailable)")
+        // else if (error == "Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied)")
+        // else if (error == "Malformed Status line")
         // else if (error == "The list of sources could not be read.")
         else {
             [delegate_ addProgressEventOnMainThread:[CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:(warning ? @"WARNING" : @"ERROR")] forTask:title];
         // else if (error == "The list of sources could not be read.")
         else {
             [delegate_ addProgressEventOnMainThread:[CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:(warning ? @"WARNING" : @"ERROR")] forTask:title];
@@ -3961,6 +4071,8 @@ static NSString *Warning_;
         @"plmn",
         @"role",
         @"serial",
         @"plmn",
         @"role",
         @"serial",
+        @"token",
+        @"version",
     nil];
 }
 
     nil];
 }
 
@@ -3972,6 +4084,10 @@ static NSString *Warning_;
     return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
 }
 
     return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
 }
 
+- (NSString *) version {
+    return @ Cydia_;
+}
+
 - (NSString *) device {
     return [[UIDevice currentDevice] uniqueIdentifier];
 }
 - (NSString *) device {
     return [[UIDevice currentDevice] uniqueIdentifier];
 }
@@ -3985,25 +4101,15 @@ static NSString *Warning_;
 }
 
 - (NSString *) idiom {
 }
 
 - (NSString *) idiom {
-    UIDevice *device([UIDevice currentDevice]);
-    if (![device respondsToSelector:@selector(userInterfaceIdiom)])
-        return @"iphone";
-
-    UIUserInterfaceIdiom idiom([device userInterfaceIdiom]);
-    if (idiom == UIUserInterfaceIdiomPhone)
-        return @"iphone";
-    else if (idiom == UIUserInterfaceIdiomPad)
-        return @"ipad";
-    else
-        return @"unknown";
+    return (id) Idiom_ ?: [NSNull null];
 }
 
 - (NSString *) plmn {
 }
 
 - (NSString *) plmn {
-    return PLMN_;
+    return (id) PLMN_ ?: [NSNull null];
 }
 
 - (NSString *) ecid {
 }
 
 - (NSString *) ecid {
-    return ChipID_;
+    return (id) ChipID_ ?: [NSNull null];
 }
 
 - (NSString *) serial {
 }
 
 - (NSString *) serial {
@@ -4011,15 +4117,21 @@ static NSString *Warning_;
 }
 
 - (NSString *) role {
 }
 
 - (NSString *) role {
-    return Role_;
+    return (id) Role_ ?: [NSNull null];
 }
 
 - (NSString *) model {
     return [NSString stringWithUTF8String:Machine_];
 }
 
 }
 
 - (NSString *) model {
     return [NSString stringWithUTF8String:Machine_];
 }
 
+- (NSString *) token {
+    return (id) Token_ ?: [NSNull null];
+}
+
 + (NSString *) webScriptNameForSelector:(SEL)selector {
     if (false);
 + (NSString *) webScriptNameForSelector:(SEL)selector {
     if (false);
+    else if (selector == @selector(addCydiaHost:))
+        return @"addCydiaHost";
     else if (selector == @selector(addTrivialSource:))
         return @"addTrivialSource";
     else if (selector == @selector(close))
     else if (selector == @selector(addTrivialSource:))
         return @"addTrivialSource";
     else if (selector == @selector(close))
@@ -4046,12 +4158,24 @@ static NSString *Warning_;
         return @"refreshSources";
     else if (selector == @selector(removeButton))
         return @"removeButton";
         return @"refreshSources";
     else if (selector == @selector(removeButton))
         return @"removeButton";
+    else if (selector == @selector(substitutePackageNames:))
+        return @"substitutePackageNames";
     else if (selector == @selector(scrollToBottom:))
         return @"scrollToBottom";
     else if (selector == @selector(scrollToBottom:))
         return @"scrollToBottom";
+    else if (selector == @selector(setAllowsNavigationAction:))
+        return @"setAllowsNavigationAction";
     else if (selector == @selector(setButtonImage:withStyle:toFunction:))
         return @"setButtonImage";
     else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
         return @"setButtonTitle";
     else if (selector == @selector(setButtonImage:withStyle:toFunction:))
         return @"setButtonImage";
     else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
         return @"setButtonTitle";
+    else if (selector == @selector(setHidesBackButton:))
+        return @"setHidesBackButton";
+    else if (selector == @selector(setHidesNavigationBar:))
+        return @"setHidesNavigationBar";
+    else if (selector == @selector(setNavigationBarStyle:))
+        return @"setNavigationBarStyle";
+    else if (selector == @selector(setNavigationBarTintRed:green:blue:alpha:))
+        return @"setNavigationBarTintColor";
     else if (selector == @selector(setPopupHook:))
         return @"setPopupHook";
     else if (selector == @selector(setToken:))
     else if (selector == @selector(setPopupHook:))
         return @"setPopupHook";
     else if (selector == @selector(setToken:))
@@ -4108,6 +4232,10 @@ static NSString *Warning_;
     return [NSString stringWithCString:value];
 }
 
     return [NSString stringWithCString:value];
 }
 
+- (void) addCydiaHost:(NSString *)host {
+    [delegate_ performSelectorOnMainThread:@selector(addCydiaHost:) withObject:host waitUntilDone:NO];
+}
+
 - (void) addTrivialSource:(NSString *)href {
     [delegate_ performSelectorOnMainThread:@selector(addTrivialSource:) withObject:href waitUntilDone:NO];
 }
 - (void) addTrivialSource:(NSString *)href {
     [delegate_ performSelectorOnMainThread:@selector(addTrivialSource:) withObject:href waitUntilDone:NO];
 }
@@ -4132,9 +4260,11 @@ static NSString *Warning_;
 } }
 
 - (Package *) getPackageById:(NSString *)id {
 } }
 
 - (Package *) getPackageById:(NSString *)id {
-    Package *package([[Database sharedInstance] packageWithName:id]);
-    [package parse];
-    return package;
+    if (Package *package = [[Database sharedInstance] packageWithName:id]) {
+        [package parse];
+        return package;
+    } else
+        return (Package *) [NSNull null];
 }
 
 - (NSArray *) statfs:(NSString *)path {
 }
 
 - (NSArray *) statfs:(NSString *)path {
@@ -4202,6 +4332,17 @@ static NSString *Warning_;
     [delegate_ performSelectorOnMainThread:@selector(installPackages:) withObject:packages waitUntilDone:NO];
 }
 
     [delegate_ performSelectorOnMainThread:@selector(installPackages:) withObject:packages waitUntilDone:NO];
 }
 
+- (NSString *) substitutePackageNames:(NSString *)message {
+    NSMutableArray *words([[message componentsSeparatedByString:@" "] mutableCopy]);
+    for (size_t i(0), e([words count]); i != e; ++i) {
+        NSString *word([words objectAtIndex:i]);
+        if (Package *package = [[Database sharedInstance] packageWithName:word])
+            [words replaceObjectAtIndex:i withObject:[package name]];
+    }
+
+    return [words componentsJoinedByString:@" "];
+}
+
 - (void) removeButton {
     [indirect_ removeButton];
 }
 - (void) removeButton {
     [indirect_ removeButton];
 }
@@ -4214,12 +4355,36 @@ static NSString *Warning_;
     [indirect_ setButtonTitle:button withStyle:style toFunction:function];
 }
 
     [indirect_ setButtonTitle:button withStyle:style toFunction:function];
 }
 
+- (void) setAllowsNavigationAction:(NSString *)value {
+    [indirect_ performSelectorOnMainThread:@selector(setAllowsNavigationActionByNumber:) withObject:value waitUntilDone:NO];
+}
+
+- (void) setHidesBackButton:(NSString *)value {
+    [indirect_ performSelectorOnMainThread:@selector(setHidesBackButtonByNumber:) withObject:value waitUntilDone:NO];
+}
+
+- (void) setHidesNavigationBar:(NSString *)value {
+    [indirect_ performSelectorOnMainThread:@selector(setHidesNavigationBarByNumber:) withObject:value waitUntilDone:NO];
+}
+
+- (void) setNavigationBarStyle:(NSString *)value {
+    [indirect_ performSelectorOnMainThread:@selector(setNavigationBarStyle:) withObject:value waitUntilDone:NO];
+}
+
+- (void) setNavigationBarTintRed:(NSNumber *)red green:(NSNumber *)green blue:(NSNumber *)blue alpha:(NSNumber *)alpha {
+    float opacity(alpha == (id) [WebUndefined undefined] ? 1 : [alpha floatValue]);
+    UIColor *color([UIColor colorWithRed:[red floatValue] green:[green floatValue] blue:[blue floatValue] alpha:opacity]);
+    [indirect_ performSelectorOnMainThread:@selector(setNavigationBarTintColor:) withObject:color waitUntilDone:NO];
+}
+
 - (void) _setToken:(NSString *)token {
 - (void) _setToken:(NSString *)token {
-    if (Token_ != nil)
-        [Token_ release];
-    Token_ = [token retain];
+    Token_ = token;
+
+    if (token == nil)
+        [Metadata_ removeObjectForKey:@"Token"];
+    else
+        [Metadata_ setObject:Token_ forKey:@"Token"];
 
 
-    [Metadata_ setObject:Token_ forKey:@"Token"];
     Changed_ = true;
 }
 
     Changed_ = true;
 }
 
@@ -4344,9 +4509,16 @@ static NSString *Warning_;
     } return self;
 }
 
     } return self;
 }
 
+// XXX: factor this out somewhere
+- (UIColor *) groupTableViewBackgroundColor {
+    UIDevice *device([UIDevice currentDevice]);
+    bool iPad([device respondsToSelector:@selector(userInterfaceIdiom)] && [device userInterfaceIdiom] == UIUserInterfaceIdiomPad);
+    return iPad ? [UIColor colorWithRed:0.821 green:0.834 blue:0.860 alpha:1] : [UIColor groupTableViewBackgroundColor];
+}
+
 - (void) loadView {
     [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
 - (void) loadView {
     [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-    [[self view] setBackgroundColor:[UIColor pinStripeColor]];
+    [[self view] setBackgroundColor:[self groupTableViewBackgroundColor]];
 
     indicator_ = [[[CYLoadingIndicator alloc] initWithFrame:[[self view] bounds]] autorelease];
     [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
 
     indicator_ = [[[CYLoadingIndicator alloc] initWithFrame:[[self view] bounds]] autorelease];
     [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
@@ -4400,7 +4572,7 @@ static NSString *Warning_;
     NSURLResponse *response([source response]);
 
     NSURL *url([response URL]);
     NSURLResponse *response([source response]);
 
     NSURL *url([response URL]);
-    NSString *scheme([url scheme]);
+    //NSString *scheme([url scheme]);
     NSString *host([url host]);
 
     if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
     NSString *host([url host]);
 
     if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
@@ -4409,11 +4581,7 @@ static NSString *Warning_;
         [self setHeaders:headers forHost:host];
     }
 
         [self setHeaders:headers forHost:host];
     }
 
-    if (
-        [host isEqualToString:@"cydia.saurik.com"] ||
-        [host hasSuffix:@".cydia.saurik.com"] ||
-        [scheme isEqualToString:@"file"]
-    )
+    if ([CydiaHosts_ containsObject:host])
         [window setValue:cydia_ forKey:@"cydia"];
 }
 
         [window setValue:cydia_ forKey:@"cydia"];
 }
 
@@ -4445,12 +4613,7 @@ static NSString *Warning_;
 
         WebView *webview([[webview_ _documentView] webView]);
 
 
         WebView *webview([[webview_ _documentView] webView]);
 
-        Package *package([[Database sharedInstance] packageWithName:@"cydia"]);
-
-        NSString *application = package == nil ? @"Cydia" : [NSString
-            stringWithFormat:@"Cydia/%@",
-            [package installed]
-        ];
+        NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]);
 
         if (Safari_ != nil)
             application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application];
 
         if (Safari_ != nil)
             application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application];
@@ -4770,7 +4933,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             [NSNumber numberWithInteger:[database_ fetcher].PartialPresent()], @"resuming",
         nil];
 
             [NSNumber numberWithInteger:[database_ fetcher].PartialPresent()], @"resuming",
         nil];
 
-        [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/confirm/", UI_]]];
+        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/confirm/", UI_]]];
 
         [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
             initWithTitle:UCLocalize("CANCEL")
 
         [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
             initWithTitle:UCLocalize("CANCEL")
@@ -4817,7 +4980,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     _transient id delegate_;
 
     bool running_;
     _transient id delegate_;
 
     bool running_;
-    float progress_;
+    float percent_;
+
+    float current_;
+    float total_;
+    float speed_;
 
     _H<NSMutableArray> events_;
     _H<NSString> title_;
 
     _H<NSMutableArray> events_;
     _H<NSString> title_;
@@ -4832,11 +4999,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 + (NSArray *) _attributeKeys {
     return [NSArray arrayWithObjects:
 
 + (NSArray *) _attributeKeys {
     return [NSArray arrayWithObjects:
+        @"current",
         @"events",
         @"finish",
         @"events",
         @"finish",
-        @"progress",
+        @"percent",
         @"running",
         @"running",
+        @"speed",
         @"title",
         @"title",
+        @"total",
     nil];
 }
 
     nil];
 }
 
@@ -4858,12 +5028,36 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     delegate_ = delegate;
 }
 
     delegate_ = delegate;
 }
 
-- (void) setProgress:(float)value {
-    progress_ = value;
+- (void) setPercent:(float)value {
+    percent_ = value;
+}
+
+- (NSNumber *) percent {
+    return [NSNumber numberWithFloat:percent_];
+}
+
+- (void) setCurrent:(float)value {
+    current_ = value;
+}
+
+- (NSNumber *) current {
+    return [NSNumber numberWithFloat:current_];
 }
 
 }
 
-- (NSNumber *) progress {
-    return [NSNumber numberWithFloat:progress_];
+- (void) setTotal:(float)value {
+    total_ = value;
+}
+
+- (NSNumber *) total {
+    return [NSNumber numberWithFloat:total_];
+}
+
+- (void) setSpeed:(float)value {
+    speed_ = value;
+}
+
+- (NSNumber *) speed {
+    return [NSNumber numberWithFloat:speed_];
 }
 
 - (NSArray *) events {
 }
 
 - (NSArray *) events {
@@ -4930,6 +5124,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [super dealloc];
 }
 
     [super dealloc];
 }
 
+- (void) updateCancel {
+    [[self navigationItem] setLeftBarButtonItem:(cancel_ == 1 ? [[[UIBarButtonItem alloc]
+        initWithTitle:UCLocalize("CANCEL")
+        style:UIBarButtonItemStylePlain
+        target:self
+        action:@selector(cancel)
+    ] autorelease] : nil)];
+}
+
 - (id) initWithDatabase:(Database *)database delegate:(id)delegate {
     if ((self = [super init]) != nil) {
         database_ = database;
 - (id) initWithDatabase:(Database *)database delegate:(id)delegate {
     if ((self = [super init]) != nil) {
         database_ = database;
@@ -4939,6 +5142,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
         progress_ = [[[CydiaProgressData alloc] init] autorelease];
         [progress_ setDelegate:self];
 
         progress_ = [[[CydiaProgressData alloc] init] autorelease];
         [progress_ setDelegate:self];
+
+        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/progress/", UI_]]];
+
+        [scroller_ setBackgroundColor:[UIColor blackColor]];
+
+        [[self navigationItem] setHidesBackButton:YES];
+
+        [self updateCancel];
     } return self;
 }
 
     } return self;
 }
 
@@ -4951,28 +5162,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [self dispatchEvent:@"CydiaProgressUpdate"];
 }
 
     [self dispatchEvent:@"CydiaProgressUpdate"];
 }
 
-- (void) updateCancel {
-    [[self navigationItem] setLeftBarButtonItem:(cancel_ == 1 ? [[[UIBarButtonItem alloc]
-        initWithTitle:UCLocalize("CANCEL")
-        style:UIBarButtonItemStylePlain
-        target:self
-        action:@selector(cancel)
-    ] autorelease] : nil)];
-}
-
 - (void) viewWillAppear:(BOOL)animated {
 - (void) viewWillAppear:(BOOL)animated {
-    if (![self hasLoaded]) {
-        [scroller_ setBackgroundColor:[UIColor blackColor]];
-        [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/progress/", UI_]]];
-    }
-
-    [super viewDidAppear:animated];
-
-    [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlack];
-
-    [[self navigationItem] setHidesBackButton:YES];
+    if (![self hasLoaded])
+        [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlack];
 
 
-    [self updateCancel];
+    [super viewWillAppear:animated];
 }
 
 - (void) close {
 }
 
 - (void) close {
@@ -5149,7 +5343,23 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) setProgressPercent:(NSNumber *)percent {
 }
 
 - (void) setProgressPercent:(NSNumber *)percent {
-    [progress_ setProgress:[percent floatValue]];
+    [progress_ setPercent:[percent floatValue]];
+    [self updateProgress];
+}
+
+- (void) setProgressStatus:(NSDictionary *)status {
+    if (status == nil) {
+        [progress_ setCurrent:0];
+        [progress_ setTotal:0];
+        [progress_ setSpeed:0];
+    } else {
+        [progress_ setPercent:[[status objectForKey:@"Percent"] floatValue]];
+
+        [progress_ setCurrent:[[status objectForKey:@"Current"] floatValue]];
+        [progress_ setTotal:[[status objectForKey:@"Total"] floatValue]];
+        [progress_ setSpeed:[[status objectForKey:@"Speed"] floatValue]];
+    }
+
     [self updateProgress];
 }
 
     [self updateProgress];
 }
 
@@ -5729,11 +5939,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     UIActionSheetDelegate
 > {
     _transient Database *database_;
     UIActionSheetDelegate
 > {
     _transient Database *database_;
-    Package *package_;
-    NSString *name_;
+    _H<Package> package_;
+    _H<NSString> name_;
     bool commercial_;
     bool commercial_;
-    NSMutableArray *buttons_;
-    UIBarButtonItem *button_;
+    _H<NSMutableArray> buttons_;
+    _H<UIBarButtonItem> button_;
 }
 
 - (id) initWithDatabase:(Database *)database forPackage:(NSString *)name;
 }
 
 - (id) initWithDatabase:(Database *)database forPackage:(NSString *)name;
@@ -5742,22 +5952,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation CYPackageController
 
 
 @implementation CYPackageController
 
-- (void) dealloc {
-    if (package_ != nil)
-        [package_ release];
-    if (name_ != nil)
-        [name_ release];
-
-    [buttons_ release];
-
-    if (button_ != nil)
-        [button_ release];
-
-    [super dealloc];
-}
-
 - (NSURL *) navigationURL {
 - (NSURL *) navigationURL {
-    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", name_]];
+    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", (id) name_]];
 }
 
 /* XXX: this is not safe at all... localization of /fail/ */
 }
 
 /* XXX: this is not safe at all... localization of /fail/ */
@@ -5851,23 +6047,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (id) initWithDatabase:(Database *)database forPackage:(NSString *)name {
     if ((self = [super init]) != nil) {
         database_ = database;
 - (id) initWithDatabase:(Database *)database forPackage:(NSString *)name {
     if ((self = [super init]) != nil) {
         database_ = database;
-        buttons_ = [[NSMutableArray alloc] initWithCapacity:4];
-        name_ = [[NSString alloc] initWithString:name];
-        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/package/#!/%@", UI_, name_]]];
+        buttons_ = [NSMutableArray arrayWithCapacity:4];
+        name_ = [NSString stringWithString:name];
+        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, (id) name_]]];
     } return self;
 }
 
 - (void) reloadData {
     } return self;
 }
 
 - (void) reloadData {
-    if (package_ != nil)
-        [package_ autorelease];
     package_ = [database_ packageWithName:name_];
 
     [buttons_ removeAllObjects];
 
     if (package_ != nil) {
     package_ = [database_ packageWithName:name_];
 
     [buttons_ removeAllObjects];
 
     if (package_ != nil) {
-        [package_ parse];
+        [(Package *) package_ parse];
 
 
-        package_ = [package_ retain];
         commercial_ = [package_ isCommercial];
 
         if ([package_ mode] != nil)
         commercial_ = [package_ isCommercial];
 
         if ([package_ mode] != nil)
@@ -5883,9 +6076,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             [buttons_ addObject:UCLocalize("REMOVE")];
     }
 
             [buttons_ addObject:UCLocalize("REMOVE")];
     }
 
-    if (button_ != nil)
-        [button_ release];
-
     NSString *title;
     switch ([buttons_ count]) {
         case 0: title = nil; break;
     NSString *title;
     switch ([buttons_ count]) {
         case 0: title = nil; break;
@@ -5893,12 +6083,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         default: title = UCLocalize("MODIFY"); break;
     }
 
         default: title = UCLocalize("MODIFY"); break;
     }
 
-    button_ = [[UIBarButtonItem alloc]
+    button_ = [[[UIBarButtonItem alloc]
         initWithTitle:title
         style:UIBarButtonItemStylePlain
         target:self
         action:@selector(customButtonClicked)
         initWithTitle:title
         style:UIBarButtonItemStylePlain
         target:self
         action:@selector(customButtonClicked)
-    ];
+    ] autorelease];
 
     [super reloadData];
 }
 
     [super reloadData];
 }
@@ -6288,8 +6478,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation HomeController
 
 
 @implementation HomeController
 
-+ (BOOL) shouldHideNavigationBar {
-    return NO;
+- (id) init {
+    if ((self = [super init]) != nil) {
+        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/home/", UI_]]];
+    } return self;
 }
 
 - (NSURL *) navigationURL {
 }
 
 - (NSURL *) navigationURL {
@@ -6324,23 +6516,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [alert show];
 }
 
     [alert show];
 }
 
-- (void) viewWillDisappear:(BOOL)animated {
-    [super viewWillDisappear:animated];
-
-    if ([[self class] shouldHideNavigationBar])
-        [[self navigationController] setNavigationBarHidden:NO animated:animated];
-}
-
-- (void) viewWillAppear:(BOOL)animated {
-    if (![self hasLoaded])
-        [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/home/", UI_]]];
-
-    [super viewWillAppear:animated];
-
-    if ([[self class] shouldHideNavigationBar])
-        [[self navigationController] setNavigationBarHidden:YES animated:animated];
-}
-
 - (void) viewDidLoad {
     [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
         initWithTitle:UCLocalize("ABOUT")
 - (void) viewDidLoad {
     [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
         initWithTitle:UCLocalize("ABOUT")
@@ -6362,15 +6537,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation ManageController
 
 
 @implementation ManageController
 
-- (NSURL *) navigationURL {
-    return [NSURL URLWithString:@"cydia://manage"];
+- (id) init {
+    if ((self = [super init]) != nil) {
+        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/manage/", UI_]]];
+    } return self;
 }
 
 }
 
-- (void) viewWillAppear:(BOOL)animated {
-    if (![self hasLoaded])
-        [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/manage/", UI_]]];
-
-    [super viewWillAppear:animated];
+- (NSURL *) navigationURL {
+    return [NSURL URLWithString:@"cydia://manage"];
 }
 
 - (void) viewDidLoad {
 }
 
 - (void) viewDidLoad {
@@ -6716,6 +6890,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [refreshbar_ setProgress:[percent floatValue]];
 }
 
     [refreshbar_ setProgress:[percent floatValue]];
 }
 
+- (void) setProgressStatus:(NSDictionary *)status {
+    if (status != nil)
+        [self setProgressPercent:[status objectForKey:@"Percent"]];
+}
+
 - (void) setUpdateDelegate:(id)delegate {
     updatedelegate_ = delegate;
 }
 - (void) setUpdateDelegate:(id)delegate {
     updatedelegate_ = delegate;
 }
@@ -6889,10 +7068,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSURL *url([request URL]);
     if (url == nil)
         return NO;
     NSURL *url([request URL]);
     if (url == nil)
         return NO;
+
     NSString *scheme([[url scheme] lowercaseString]);
     NSString *scheme([[url scheme] lowercaseString]);
-    if (scheme == nil || ![scheme isEqualToString:@"cydia"])
-        return NO;
-    return YES;
+    if (scheme != nil && [scheme isEqualToString:@"cydia"])
+        return YES;
+    if ([[url absoluteString] hasPrefix:@"about:cydia-"])
+        return YES;
+
+    return NO;
 }
 
 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
 }
 
 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
@@ -6919,8 +7102,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     NSURL *url([request URL]);
     NSString *href([url absoluteString]);
 
     NSURL *url([request URL]);
     NSString *href([url absoluteString]);
+    NSString *scheme([[url scheme] lowercaseString]);
+
+    NSString *path;
+
+    if ([scheme isEqualToString:@"cydia"])
+        path = [href substringFromIndex:8];
+    else if ([scheme isEqualToString:@"about"])
+        path = [href substringFromIndex:12];
+    else _assert(false);
 
 
-    NSString *path([href substringFromIndex:8]);
     NSRange slash([path rangeOfString:@"/"]);
 
     NSString *command;
     NSRange slash([path rangeOfString:@"/"]);
 
     NSString *command;
@@ -6980,7 +7171,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 /* Section Controller {{{ */
 @interface SectionController : FilteredPackageListController {
 
 /* Section Controller {{{ */
 @interface SectionController : FilteredPackageListController {
-    NSString *section_;
+    _H<NSString> section_;
 }
 
 - (id) initWithDatabase:(Database *)database section:(NSString *)section;
 }
 
 - (id) initWithDatabase:(Database *)database section:(NSString *)section;
@@ -7473,7 +7664,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @interface SearchController : FilteredPackageListController <
     UISearchBarDelegate
 > {
 @interface SearchController : FilteredPackageListController <
     UISearchBarDelegate
 > {
-    UISearchBar *search_;
+    _H<UISearchBar> search_;
     BOOL searchloaded_;
 }
 
     BOOL searchloaded_;
 }
 
@@ -7486,7 +7677,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation SearchController
 
 - (void) dealloc {
 @implementation SearchController
 
 - (void) dealloc {
-    [search_ release];
+    [search_ setDelegate:nil];
     [super dealloc];
 }
 
     [super dealloc];
 }
 
@@ -7515,7 +7706,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil])) {
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil])) {
-        search_ = [[UISearchBar alloc] init];
+        search_ = [[[UISearchBar alloc] init] autorelease];
+        [search_ setDelegate:self];
     } return self;
 }
 
     } return self;
 }
 
@@ -7535,7 +7727,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             textField = MSHookIvar<UITextField *>(search_, "_searchField");
 
         [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
             textField = MSHookIvar<UITextField *>(search_, "_searchField");
 
         [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
-        [search_ setDelegate:self];
         [textField setEnablesReturnKeyAutomatically:NO];
         [[self navigationItem] setTitleView:textField];
     }
         [textField setEnablesReturnKeyAutomatically:NO];
         [[self navigationItem] setTitleView:textField];
     }
@@ -8731,6 +8922,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         ] autorelease];
 
         [alert setContext:@"fixhalf"];
         ] autorelease];
 
         [alert setContext:@"fixhalf"];
+        [alert setNumberOfRows:2];
         [alert show];
     } else if (!Ignored_ && [essential_ count] != 0) {
         int count = [essential_ count];
         [alert show];
     } else if (!Ignored_ && [essential_ count] != 0) {
         int count = [essential_ count];
@@ -8908,11 +9100,33 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     }
 }
 
     }
 }
 
-- (void) presentModalViewController:(UIViewController *)controller {
+- (void) disemulate {
+    if (emulated_ == nil)
+        return;
+
+    [window_ addSubview:[tabbar_ view]];
+    [[emulated_ view] removeFromSuperview];
+    [emulated_ release];
+    emulated_ = nil;
+    [window_ setUserInteractionEnabled:YES];
+}
+
+- (void) presentModalViewController:(UIViewController *)controller force:(BOOL)force {
     UINavigationController *navigation([[[CYNavigationController alloc] initWithRootViewController:controller] autorelease]);
     if (IsWildcat_)
         [navigation setModalPresentationStyle:UIModalPresentationFormSheet];
     UINavigationController *navigation([[[CYNavigationController alloc] initWithRootViewController:controller] autorelease]);
     if (IsWildcat_)
         [navigation setModalPresentationStyle:UIModalPresentationFormSheet];
-    [((UIViewController *) emulated_ ?: tabbar_) presentModalViewController:navigation animated:YES];
+
+    UIViewController *parent;
+    if (emulated_ == nil)
+        parent = tabbar_;
+    else if (!force)
+        parent = emulated_;
+    else {
+        [self disemulate];
+        parent = tabbar_;
+    }
+
+    [parent presentModalViewController:navigation animated:YES];
 }
 
 - (ProgressController *) invokeNewProgress:(NSInvocation *)invocation forController:(UINavigationController *)navigation withTitle:(NSString *)title {
 }
 
 - (ProgressController *) invokeNewProgress:(NSInvocation *)invocation forController:(UINavigationController *)navigation withTitle:(NSString *)title {
@@ -8921,7 +9135,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if (navigation != nil)
         [navigation pushViewController:progress animated:YES];
     else
     if (navigation != nil)
         [navigation pushViewController:progress animated:YES];
     else
-        [self presentModalViewController:progress];
+        [self presentModalViewController:progress force:YES];
 
     [progress invoke:invocation withTitle:title];
     return progress;
 
     [progress invoke:invocation withTitle:title];
     return progress;
@@ -8933,7 +9147,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) repairWithInvocation:(NSInvocation *)invocation {
     _trace();
 
 - (void) repairWithInvocation:(NSInvocation *)invocation {
     _trace();
-    [self invokeNewProgress:invocation forController:nil withTitle:UCLocalize("REPAIRING")];
+    [self invokeNewProgress:invocation forController:nil withTitle:@"REPAIRING"];
     _trace();
 }
 
     _trace();
 }
 
@@ -8959,7 +9173,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     fclose(file);
 
 
     fclose(file);
 
-    [self detachNewProgressSelector:@selector(update_) toTarget:self forController:nil title:UCLocalize("UPDATING_SOURCES")];
+    [self detachNewProgressSelector:@selector(update_) toTarget:self forController:nil title:@"UPDATING_SOURCES"];
 
     [self complete];
 }
 
     [self complete];
 }
@@ -9065,7 +9279,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) confirmWithNavigationController:(UINavigationController *)navigation {
     Queuing_ = false;
     ++locked_;
 - (void) confirmWithNavigationController:(UINavigationController *)navigation {
     Queuing_ = false;
     ++locked_;
-    [self detachNewProgressSelector:@selector(perform) toTarget:database_ forController:navigation title:UCLocalize("RUNNING")];
+    [self detachNewProgressSelector:@selector(perform) toTarget:database_ forController:navigation title:@"RUNNING"];
     --locked_;
     [self complete];
 }
     --locked_;
     [self complete];
 }
@@ -9390,6 +9604,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     ] autorelease];
 
     [alert setContext:@"conffile"];
     ] autorelease];
 
     [alert setContext:@"conffile"];
+    [alert setNumberOfRows:2];
     [alert show];
 }
 
     [alert show];
 }
 
@@ -9449,11 +9664,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [tabbar_ setUpdateDelegate:self];
 }
 
     [tabbar_ setUpdateDelegate:self];
 }
 
+- (void) addCydiaHost:(NSString *)host {
+    [CydiaHosts_ addObject:host];
+}
+
 - (void) applicationDidFinishLaunching:(id)unused {
 _trace();
     if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
         [self setApplicationSupportsShakeToEdit:NO];
 
 - (void) applicationDidFinishLaunching:(id)unused {
 _trace();
     if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
         [self setApplicationSupportsShakeToEdit:NO];
 
+    [self addCydiaHost:[[NSURL URLWithString:CydiaURL(@"")] host]];
+
     [NSURLCache setSharedURLCache:[[[SDURLCache alloc]
         initWithMemoryCapacity:524288
         diskCapacity:10485760
     [NSURLCache setSharedURLCache:[[[SDURLCache alloc]
         initWithMemoryCapacity:524288
         diskCapacity:10485760
@@ -9515,7 +9736,7 @@ _trace();
 _trace();
     if (Role_ == nil) {
         [window_ setUserInteractionEnabled:YES];
 _trace();
     if (Role_ == nil) {
         [window_ setUserInteractionEnabled:YES];
-        [self presentModalViewController:[[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease]];
+        [self presentModalViewController:[[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease] force:NO];
         return;
     } else {
         if ([emulated_ modalViewController] != nil)
         return;
     } else {
         if ([emulated_ modalViewController] != nil)
@@ -9526,13 +9747,7 @@ _trace();
     [self reloadData];
     PrintTimes();
 
     [self reloadData];
     PrintTimes();
 
-    [window_ addSubview:[tabbar_ view]];
-
-    [[emulated_ view] removeFromSuperview];
-    [emulated_ release];
-    emulated_ = nil;
-
-    [window_ setUserInteractionEnabled:YES];
+    [self disemulate];
 
     int selectedIndex = 0;
     NSMutableArray *items = nil;
 
     int selectedIndex = 0;
     NSMutableArray *items = nil;
@@ -9707,11 +9922,22 @@ int main(int argc, char *argv[]) { _pooled
     else
         ScreenScale_ = 1;
 
     else
         ScreenScale_ = 1;
 
-    NSMutableArray *parts([NSMutableArray arrayWithCapacity:2]);
-    if (ScreenScale_ > 1)
-        [parts addObject:@"@2x"];
-    [parts addObject:(IsWildcat_ ? @"~ipad" : @"~iphone")];
-    UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios%@", [parts componentsJoinedByString:@""]]);
+    UIDevice *device([UIDevice currentDevice]);
+    if (![device respondsToSelector:@selector(userInterfaceIdiom)])
+        Idiom_ = @"iphone";
+    else {
+        UIUserInterfaceIdiom idiom([device userInterfaceIdiom]);
+        if (idiom == UIUserInterfaceIdiomPhone)
+            Idiom_ = @"iphone";
+        else if (idiom == UIUserInterfaceIdiomPad)
+            Idiom_ = @"ipad";
+        else
+            NSLog(@"unknown UIUserInterfaceIdiom!");
+    }
+
+    CydiaHosts_ = [NSMutableSet setWithCapacity:2];
+
+    UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]);
 
     PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
 
 
     PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
 
@@ -9752,9 +9978,9 @@ int main(int argc, char *argv[]) { _pooled
     else {
         lang = [[Languages_ objectAtIndex:0] UTF8String];
         setenv("LANG", lang, true);
     else {
         lang = [[Languages_ objectAtIndex:0] UTF8String];
         setenv("LANG", lang, true);
+        std::setlocale(LC_ALL, lang);
     }
 
     }
 
-    //std::setlocale(LC_ALL, lang);
     NSLog(@"Setting Language: %s", lang);
     /* }}} */
 
     NSLog(@"Setting Language: %s", lang);
     /* }}} */
 
@@ -9785,7 +10011,6 @@ int main(int argc, char *argv[]) { _pooled
     /* }}} */
 
     App_ = [[NSBundle mainBundle] bundlePath];
     /* }}} */
 
     App_ = [[NSBundle mainBundle] bundlePath];
-    Home_ = NSHomeDirectory();
     Advanced_ = YES;
 
     setuid(0);
     Advanced_ = YES;
 
     setuid(0);
@@ -9925,8 +10150,11 @@ int main(int argc, char *argv[]) { _pooled
     Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];
 
 #define MobileSubstrate_(name) \
     Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];
 
 #define MobileSubstrate_(name) \
-    if (substrate && access("/Library/MobileSubstrate/DynamicLibraries/" #name ".dylib", F_OK) == 0) \
-        dlopen("/Library/MobileSubstrate/DynamicLibraries/" #name ".dylib", RTLD_LAZY | RTLD_GLOBAL);
+    if (substrate && access("/Library/MobileSubstrate/DynamicLibraries/" #name ".dylib", F_OK) == 0) { \
+        void *handle(dlopen("/Library/MobileSubstrate/DynamicLibraries/" #name ".dylib", RTLD_LAZY | RTLD_GLOBAL)); \
+        if (handle == NULL) \
+            NSLog(@"%s", dlerror()); \
+    }
 
     MobileSubstrate_(Activator)
     MobileSubstrate_(libstatusbar)
 
     MobileSubstrate_(Activator)
     MobileSubstrate_(libstatusbar)
@@ -9941,7 +10169,7 @@ int main(int argc, char *argv[]) { _pooled
     if (access("/tmp/.cydia.fw", F_OK) == 0) {
         unlink("/tmp/.cydia.fw");
         goto firmware;
     if (access("/tmp/.cydia.fw", F_OK) == 0) {
         unlink("/tmp/.cydia.fw");
         goto firmware;
-    } else if (access("/User", F_OK) != 0 || version < 2) {
+    } else if (access("/User", F_OK) != 0 || version < 4) {
       firmware:
         _trace();
         system("/usr/libexec/cydia/firmware.sh");
       firmware:
         _trace();
         system("/usr/libexec/cydia/firmware.sh");