]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Steal more entitlements from MobileSafari: I want Nitro.
[cydia.git] / MobileCydia.mm
index 90adca538f37d007fd9b0e5dd211d10a51266e3c..e6e6949575ac82208e078956ad08b31d83f386a2 100644 (file)
@@ -66,6 +66,8 @@
 
 #include <IOKit/IOKitLib.h>
 
+#include <QuartzCore/CALayer.h>
+
 #include <WebCore/WebCoreThread.h>
 
 #include <algorithm>
@@ -119,14 +121,17 @@ extern "C" {
 #include <errno.h>
 
 #include <Cytore.hpp>
+#include "Sources.h"
 
 #include <CydiaSubstrate/CydiaSubstrate.h>
 #include "Menes/Menes.h"
 
+#include "CyteKit/IndirectDelegate.h"
 #include "CyteKit/PerlCompatibleRegEx.hpp"
 #include "CyteKit/TableViewCell.h"
 #include "CyteKit/WebScriptObject-Cyte.h"
 #include "CyteKit/WebViewController.h"
+#include "CyteKit/WebViewTableViewCell.h"
 #include "CyteKit/stringWithUTF8Bytes.h"
 
 #include "Cydia/MIMEAddress.h"
@@ -206,8 +211,7 @@ void PrintTimes() {
 #define _end }
 /* }}} */
 
-#include "Version.h"
-#define Cydia_ CYDIA_VERSION
+extern NSString *Cydia_;
 
 #define lprintf(args...) fprintf(stderr, args)
 
@@ -245,6 +249,15 @@ union SplitHash {
 };
 // }}}
 
+static bool ShowPromoted_;
+
+static NSString *Colon_;
+NSString *Elision_;
+static NSString *Error_;
+static NSString *Warning_;
+
+static bool AprilFools_;
+
 static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
 
 static _finline NSString *CydiaURL(NSString *path) {
@@ -258,6 +271,15 @@ static _finline NSString *CydiaURL(NSString *path) {
     return [[NSString stringWithUTF8String:page] stringByAppendingString:path];
 }
 
+static void ReapZombie(pid_t pid) {
+    int status;
+  wait:
+    if (waitpid(pid, &status, 0) == -1)
+        if (errno == EINTR)
+            goto wait;
+        else _assert(false);
+}
+
 static _finline void UpdateExternalStatus(uint64_t newStatus) {
     int notify_token;
     if (notify_register_check("com.saurik.Cydia.status", &notify_token) == NOTIFY_STATUS_OK) {
@@ -267,9 +289,9 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) {
     notify_post("com.saurik.Cydia.status");
 }
 
-static CGFloat CYStatusBarHeight(UIInterfaceOrientation orientation) {
+static CGFloat CYStatusBarHeight() {
     CGSize size([[UIApplication sharedApplication] statusBarFrame].size);
-    return UIInterfaceOrientationIsPortrait(orientation) ? size.height : size.width;
+    return UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? size.height : size.width;
 }
 
 /* NSForcedOrderingSearch doesn't work on the iPhone */
@@ -397,7 +419,6 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s
 /* Cydia NSString Additions {{{ */
 @interface NSString (Cydia)
 - (NSComparisonResult) compareByPath:(NSString *)other;
-- (NSString *) stringByCachingURLWithCurrentCDN;
 - (NSString *) stringByAddingPercentEscapesIncludingReserved;
 @end
 
@@ -433,13 +454,6 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s
     return result == NSOrderedSame ? value : result;
 }
 
-- (NSString *) stringByCachingURLWithCurrentCDN {
-    return [self
-        stringByReplacingOccurrencesOfString:@"://cydia.saurik.com/"
-        withString:@"://cache.cydia.saurik.com/"
-    ];
-}
-
 - (NSString *) stringByAddingPercentEscapesIncludingReserved {
     return [(id)CFURLCreateStringByAddingPercentEscapes(
         kCFAllocatorDefault,
@@ -677,16 +691,15 @@ static _H<UIFont> Font18Bold_;
 static _H<UIFont> Font22Bold_;
 
 static const char *Machine_ = NULL;
-static NSString *System_ = nil;
+static _H<NSString> System_;
 static NSString *SerialNumber_ = nil;
 static NSString *ChipID_ = nil;
 static NSString *BBSNum_ = nil;
 static _H<NSString> Token_;
 static NSString *UniqueID_ = nil;
-static NSString *PLMN_ = nil;
-static NSString *Build_ = nil;
-static NSString *Product_ = nil;
-static NSString *Safari_ = nil;
+static _H<NSString> UserAgent_;
+static _H<NSString> Product_;
+static _H<NSString> Safari_;
 
 static CFLocaleRef Locale_;
 static NSArray *Languages_;
@@ -699,15 +712,16 @@ static _transient NSString *Role_;
 static _transient NSMutableDictionary *Packages_;
 static _transient NSMutableDictionary *Values_;
 static _transient NSMutableDictionary *Sections_;
-static _transient NSMutableDictionary *Sources_;
+_H<NSMutableDictionary> Sources_;
 static _transient NSNumber *Version_;
-static _transient _H<NSString> CydiaSource_;
-static bool Changed_;
+bool Changed_;
 static time_t now_;
 
 bool IsWildcat_;
 static CGFloat ScreenScale_;
 static NSString *Idiom_;
+static _H<NSString> Firmware_;
+static NSString *Major_;
 
 static _H<NSMutableDictionary> SessionData_;
 static _H<NSObject> HostConfig_;
@@ -723,45 +737,6 @@ static NSString *kCydiaProgressEventTypeStatus = @"Status";
 static NSString *kCydiaProgressEventTypeWarning = @"Warning";
 /* }}} */
 
-static void AddSource(NSDictionary *source) {
-    [Sources_ setObject:source forKey:[NSString stringWithFormat:@"%@:%@:%@", [source objectForKey:@"Type"], [source objectForKey:@"URI"], [source objectForKey:@"Distribution"]]];
-    Changed_ = true;
-}
-
-static void AddSource(NSString *href, NSString *distribution, NSArray *sections = nil) {
-    AddSource([NSMutableDictionary dictionaryWithObjectsAndKeys:
-        @"deb", @"Type",
-        href, @"URI",
-        distribution, @"Distribution",
-        sections ?: [NSMutableArray array], @"Sections",
-    nil]);
-}
-
-static void WriteSources() {
-    FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w"));
-    _assert(file != NULL);
-
-    fprintf(file, "deb http://%s/ tangelo main\n",
-        [CydiaSource_ UTF8String]
-    );
-
-    for (NSString *key in [Sources_ allKeys]) {
-        NSDictionary *source([Sources_ objectForKey:key]);
-
-        NSArray *sections([source objectForKey:@"Sections"] ?: [NSArray array]);
-
-        fprintf(file, "%s %s %s%s%s\n",
-            [[source objectForKey:@"Type"] UTF8String],
-            [[source objectForKey:@"URI"] UTF8String],
-            [[source objectForKey:@"Distribution"] UTF8String],
-            [sections count] == 0 ? "" : " ",
-            [[sections componentsJoinedByString:@" "] UTF8String]
-        );
-    }
-
-    fclose(file);
-}
-
 /* Display Helpers {{{ */
 inline float Interpolate(float begin, float end, float fraction) {
     return (end - begin) * fraction + begin;
@@ -871,6 +846,7 @@ static NSString *CYHex(NSData *data, bool reverse = false) {
 @class CYPackageController;
 
 @protocol CydiaDelegate
+- (void) returnToCydia;
 - (void) saveState;
 - (void) retainNetworkActivityIndicator;
 - (void) releaseNetworkActivityIndicator;
@@ -923,6 +899,7 @@ class Status :
     }
 
     virtual void IMSHit(pkgAcquire::ItemDesc &item) {
+        Done(item);
     }
 
     virtual void Fetch(pkgAcquire::ItemDesc &item) {
@@ -932,6 +909,9 @@ class Status :
     }
 
     virtual void Done(pkgAcquire::ItemDesc &item) {
+        NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]);
+        CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:Colon_, UCLocalize("DONE"), name] ofType:kCydiaProgressEventTypeStatus forItem:item]);
+        [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
     }
 
     virtual void Fail(pkgAcquire::ItemDesc &item) {
@@ -1306,6 +1286,10 @@ static void PackageImport(const void *key, const void *value, void *context) {
 
 /* Source Class {{{ */
 @interface Source : NSObject {
+    unsigned era_;
+    Database *database_;
+    metaIndex *index_;
+
     CYString depiction_;
     CYString description_;
     CYString label_;
@@ -1327,9 +1311,9 @@ static void PackageImport(const void *key, const void *value, void *context) {
     BOOL trusted_;
 }
 
-- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool;
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool;
 
-- (NSComparisonResult) compareByNameAndType:(Source *)source;
+- (NSComparisonResult) compareByName:(Source *)source;
 
 - (NSString *) depictionForPackage:(NSString *)package;
 - (NSString *) supportForPackage:(NSString *)package;
@@ -1337,12 +1321,10 @@ static void PackageImport(const void *key, const void *value, void *context) {
 - (NSDictionary *) record;
 - (BOOL) trusted;
 
-- (NSString *) uri;
+- (NSString *) rooturi;
 - (NSString *) distribution;
 - (NSString *) type;
 
-- (NSString *) base;
-
 - (NSString *) key;
 - (NSString *) host;
 
@@ -1353,6 +1335,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 - (NSString *) version;
 
 - (NSString *) defaultIcon;
+- (NSURL *) iconURL;
 
 @end
 
@@ -1382,6 +1365,8 @@ static void PackageImport(const void *key, const void *value, void *context) {
     if (false);
     else if (selector == @selector(addSection:))
         return @"addSection";
+    else if (selector == @selector(getField:))
+        return @"getField";
     else if (selector == @selector(removeSection:))
         return @"removeSection";
     else if (selector == @selector(remove))
@@ -1396,17 +1381,19 @@ static void PackageImport(const void *key, const void *value, void *context) {
 
 + (NSArray *) _attributeKeys {
     return [NSArray arrayWithObjects:
+        @"baseuri",
         @"distribution",
         @"host",
         @"key",
+        @"iconuri",
         @"label",
         @"name",
         @"origin",
+        @"rooturi",
         @"sections",
         @"shortDescription",
         @"trusted",
         @"type",
-        @"uri",
         @"version",
     nil];
 }
@@ -1479,19 +1466,44 @@ static void PackageImport(const void *key, const void *value, void *context) {
         authority_ = [url path];
 }
 
-- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool {
     if ((self = [super init]) != nil) {
+        era_ = [database era];
+        database_ = database;
+        index_ = index;
+
         [self setMetaIndex:index inPool:pool];
     } return self;
 }
 
-- (NSComparisonResult) compareByNameAndType:(Source *)source {
-    NSDictionary *lhr = [self record];
-    NSDictionary *rhr = [source record];
+- (NSString *) getField:(NSString *)name {
+@synchronized (database_) {
+    if ([database_ era] != era_ || index_ == NULL)
+        return nil;
+
+    debReleaseIndex *dindex(dynamic_cast<debReleaseIndex *>(index_));
+    if (dindex == NULL)
+        return nil;
+
+    FileFd fd;
+    if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly)) {
+         _error->Discard();
+         return nil;
+    }
 
-    if (lhr != rhr)
-        return lhr == nil ? NSOrderedDescending : NSOrderedAscending;
+    pkgTagFile tags(&fd);
 
+    pkgTagSection section;
+    tags.Step(section);
+
+    const char *start, *end;
+    if (!section.Find([name UTF8String], start, end))
+        return (NSString *) [NSNull null];
+
+    return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]];
+} }
+
+- (NSComparisonResult) compareByName:(Source *)source {
     NSString *lhs = [self name];
     NSString *rhs = [source name];
 
@@ -1580,7 +1592,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
     return trusted_;
 }
 
-- (NSString *) uri {
+- (NSString *) rooturi {
     return uri_;
 }
 
@@ -1592,8 +1604,21 @@ static void PackageImport(const void *key, const void *value, void *context) {
     return type_;
 }
 
-- (NSString *) base {
-    return base_;
+- (NSString *) baseuri {
+    return base_.empty() ? nil : (id) base_;
+}
+
+- (NSString *) iconuri {
+    if (NSString *base = [self baseuri])
+        return [base stringByAppendingString:@"CydiaIcon.png"];
+
+    return nil;
+}
+
+- (NSURL *) iconURL {
+    if (NSString *uri = [self iconuri])
+        return [NSURL URLWithString:uri];
+    return nil;
 }
 
 - (NSString *) key {
@@ -1788,6 +1813,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 /* }}} */
 /* Package Class {{{ */
 struct ParsedPackage {
+    CYString md5sum_;
     CYString tagline_;
 
     CYString architecture_;
@@ -1804,11 +1830,12 @@ struct ParsedPackage {
 };
 
 @interface Package : NSObject {
-    uint32_t era_ : 26;
+    uint32_t era_ : 25;
     uint32_t role_ : 3;
     uint32_t essential_ : 1;
     uint32_t obsolete_ : 1;
     uint32_t ignored_ : 1;
+    uint32_t pooled_ : 1;
 
     apr_pool_t *pool_;
 
@@ -2055,6 +2082,8 @@ struct PackageNameOrdering :
 }
 
 - (void) dealloc {
+    if (!pooled_)
+        apr_pool_destroy(pool_);
     if (parsed_ != NULL)
         delete parsed_;
     [super dealloc];
@@ -2095,6 +2124,7 @@ struct PackageNameOrdering :
         @"longDescription",
         @"longSection",
         @"maintainer",
+        @"md5sum",
         @"mode",
         @"name",
         @"purposes",
@@ -2147,7 +2177,7 @@ struct PackageNameOrdering :
     if (!parser.Find([name UTF8String], start, end))
         return (NSString *) [NSNull null];
 
-    return [(NSString *) CYStringCreate(start, end - start) autorelease];
+    return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]];
 } }
 
 - (void) parse {
@@ -2183,6 +2213,7 @@ struct PackageNameOrdering :
                 {"support", &parsed->support_},
                 {"sponsor", &parsed->sponsor_},
                 {"author", &parsed->author_},
+                {"md5sum", &parsed->md5sum_},
             };
 
             for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
@@ -2221,7 +2252,12 @@ struct PackageNameOrdering :
 - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
     if ((self = [super init]) != nil) {
     _profile(Package$initWithVersion)
-        pool_ = pool;
+        if (pool == NULL)
+            apr_pool_create(&pool_, NULL);
+        else {
+            pool_ = pool;
+            pooled_ = true;
+        }
 
         database_ = database;
         era_ = [database era];
@@ -2412,6 +2448,10 @@ struct PackageNameOrdering :
     return maintainer.empty() ? nil : [MIMEAddress addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
 } }
 
+- (NSString *) md5sum {
+    return parsed_ == NULL ? nil : (id) parsed_->md5sum_;
+}
+
 - (size_t) size {
 @synchronized (database_) {
     if ([database_ era] != era_ || version_.end())
@@ -2453,8 +2493,8 @@ struct PackageNameOrdering :
     if (!parser.ShortDesc(start, end))
         return nil;
 
-    if (end - start > 100)
-        end = start + 100;
+    if (end - start > 200)
+        end = start + 200;
 
     /*
     if (const char *stop = reinterpret_cast<const char *>(memchr(start, '\n', end - start)))
@@ -2584,11 +2624,19 @@ struct PackageNameOrdering :
 }
 
 - (BOOL) hasMode {
+@synchronized (database_) {
+    if ([database_ era] != era_ || iterator_.end())
+        return nil;
+
     pkgDepCache::StateCache &state([database_ cache][iterator_]);
     return state.Mode != pkgDepCache::ModeKeep;
-}
+} }
 
 - (NSString *) mode {
+@synchronized (database_) {
+    if ([database_ era] != era_ || iterator_.end())
+        return nil;
+
     pkgDepCache::StateCache &state([database_ cache][iterator_]);
 
     switch (state.Mode) {
@@ -2620,7 +2668,7 @@ struct PackageNameOrdering :
             }
         _nodefault
     }
-}
+} }
 
 - (NSString *) id {
     return id_;
@@ -2865,7 +2913,7 @@ struct PackageNameOrdering :
 
     string = [self shortDescription];
     length = [string length];
-    NSUInteger stop(std::min<NSUInteger>(length, 100));
+    NSUInteger stop(std::min<NSUInteger>(length, 200));
 
     for (NSString *term in query) {
         range = [string rangeOfString:term options:MatchCompareOptions_ range:NSMakeRange(0, stop)];
@@ -3144,11 +3192,6 @@ struct PackageNameOrdering :
 @end
 /* }}} */
 
-static NSString *Colon_;
-NSString *Elision_;
-static NSString *Error_;
-static NSString *Warning_;
-
 class CydiaLogCleaner :
     public pkgArchiveCleaner
 {
@@ -3294,11 +3337,13 @@ class CydiaLogCleaner :
 }
 
 - (Package *) packageWithName:(NSString *)name {
+    if (name == nil)
+        return nil;
 @synchronized (self) {
     if (static_cast<pkgDepCache *>(cache_) == NULL)
         return nil;
     pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String]));
-    return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:pool_ database:self];
+    return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:NULL database:self];
 } }
 
 - (id) init {
@@ -3419,6 +3464,10 @@ class CydiaLogCleaner :
 
         lprintf("%c:[%s]\n", warning ? 'W' : 'E', error.c_str());
 
+        static Pcre no_pubkey("^GPG error:.* NO_PUBKEY .*$");
+        if (warning && no_pubkey(error.c_str()))
+            continue;
+
         [delegate_ addProgressEventOnMainThread:[CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:(warning ? kCydiaProgressEventTypeWarning : kCydiaProgressEventTypeError)] forTask:title];
     }
 
@@ -3532,7 +3581,7 @@ class CydiaLogCleaner :
     }
 
     for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
-        Source *object([[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease]);
+        Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:pool_] autorelease]);
         [sourceList_ addObject:object];
 
         std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
@@ -3887,11 +3936,16 @@ static _H<NSMutableSet> Diversions_;
 
 @end
 
+@class CydiaObject;
+
 @interface CydiaWebViewController : CyteWebViewController {
     _H<CydiaObject> cydia_;
 }
 
 + (void) addDiversion:(Diversion *)diversion;
++ (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request;
++ (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia;
+- (void) setDelegate:(id)delegate;
 
 @end
 
@@ -3911,14 +3965,17 @@ static _H<NSMutableSet> Diversions_;
 + (NSArray *) _attributeKeys {
     return [NSArray arrayWithObjects:
         @"bbsnum",
-        @"cydiaSource",
+        @"build",
+        @"coreFoundationVersionNumber",
         @"device",
         @"ecid",
         @"firmware",
         @"hostname",
         @"idiom",
+        @"mcc",
+        @"mnc",
         @"model",
-        @"plmn",
+        @"operator",
         @"role",
         @"serial",
         @"token",
@@ -3935,7 +3992,15 @@ static _H<NSMutableSet> Diversions_;
 }
 
 - (NSString *) version {
-    return @ Cydia_;
+    return Cydia_;
+}
+
+- (NSString *) build {
+    return System_;
+}
+
+- (NSString *) coreFoundationVersionNumber {
+    return [NSString stringWithFormat:@"%.2f", kCFCoreFoundationVersionNumber];
 }
 
 - (NSString *) device {
@@ -3954,8 +4019,22 @@ static _H<NSMutableSet> Diversions_;
     return (id) Idiom_ ?: [NSNull null];
 }
 
-- (NSString *) plmn {
-    return (id) PLMN_ ?: [NSNull null];
+- (NSString *) mcc {
+    if (CFStringRef (*$CTSIMSupportCopyMobileSubscriberCountryCode)(CFAllocatorRef) = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode")))
+        return [(NSString *) (*$CTSIMSupportCopyMobileSubscriberCountryCode)(kCFAllocatorDefault) autorelease];
+    return nil;
+}
+
+- (NSString *) mnc {
+    if (CFStringRef (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(CFAllocatorRef) = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberNetworkCode")))
+        return [(NSString *) (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(kCFAllocatorDefault) autorelease];
+    return nil;
+}
+
+- (NSString *) operator {
+    if (CFStringRef (*$CTRegistrationCopyOperatorName)(CFAllocatorRef) = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTRegistrationCopyOperatorName")))
+        return [(NSString *) (*$CTRegistrationCopyOperatorName)(kCFAllocatorDefault) autorelease];
+    return nil;
 }
 
 - (NSString *) bbsnum {
@@ -4038,12 +4117,12 @@ static _H<NSMutableSet> Diversions_;
         return @"removeButton";
     else if (selector == @selector(saveConfig))
         return @"saveConfig";
-    else if (selector == @selector(setCydiaSource:))
-        return @"setCydiaSource";
     else if (selector == @selector(setMetadataValue::))
         return @"setMetadataValue";
     else if (selector == @selector(setSessionValue::))
         return @"setSessionValue";
+    else if (selector == @selector(setShowPromoted:))
+        return @"setShowPromoted";
     else if (selector == @selector(substitutePackageNames:))
         return @"substitutePackageNames";
     else if (selector == @selector(scrollToBottom:))
@@ -4068,6 +4147,10 @@ static _H<NSMutableSet> Diversions_;
         return @"setPasteboardString";
     else if (selector == @selector(setPasteboardURL:))
         return @"setPasteboardURL";
+    else if (selector == @selector(setScrollAlwaysBounceVertical:))
+        return @"setScrollAlwaysBounceVertical";
+    else if (selector == @selector(setScrollIndicatorStyle:))
+        return @"setScrollIndicatorStyle";
     else if (selector == @selector(setToken:))
         return @"setToken";
     else if (selector == @selector(setViewportWidth:))
@@ -4094,6 +4177,14 @@ static _H<NSMutableSet> Diversions_;
     [delegate_ performSelectorOnMainThread:@selector(unloadData) withObject:nil waitUntilDone:NO];
 }
 
+- (void) setScrollAlwaysBounceVertical:(NSNumber *)value {
+    [indirect_ performSelectorOnMainThread:@selector(setScrollAlwaysBounceVerticalNumber:) withObject:value waitUntilDone:NO];
+}
+
+- (void) setScrollIndicatorStyle:(NSString *)style {
+    [indirect_ performSelectorOnMainThread:@selector(setScrollIndicatorStyleWithName:) withObject:style waitUntilDone:NO];
+}
+
 - (void) addInternalRedirect:(NSString *)from :(NSString *)to {
     [CydiaWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO];
 }
@@ -4142,30 +4233,20 @@ static _H<NSMutableSet> Diversions_;
     return value;
 }
 
-- (void) _setCydiaSource:(NSString *)source {
-    @synchronized (HostConfig_) {
-        CydiaSource_ = source;
-        [Metadata_ setObject:source forKey:@"CydiaSource"];
-    }
+- (NSArray *) getMetadataKeys {
+@synchronized (Values_) {
+    return [Values_ allKeys];
+} }
 
+- (void) _setShowPromoted:(NSNumber *)value {
+    [Metadata_ setObject:value forKey:@"ShowPromoted"];
     Changed_ = true;
 }
 
-- (void) setCydiaSource:(NSString *)source {
-    [self performSelectorOnMainThread:@selector(_setCydiaSource:) withObject:source waitUntilDone:NO];
+- (void) setShowPromoted:(NSNumber *)value {
+    [self performSelectorOnMainThread:@selector(_setShowPromoted:) withObject:value waitUntilDone:NO];
 }
 
-- (NSString *) cydiaSource {
-    @synchronized (HostConfig_) {
-        return (id) CydiaSource_ ?: [NSNull null];
-    }
-}
-
-- (NSArray *) getMetadataKeys {
-@synchronized (Values_) {
-    return [Values_ allKeys];
-} }
-
 - (id) getMetadataValue:(NSString *)key {
 @synchronized (Values_) {
     return [Values_ objectForKey:key];
@@ -4327,12 +4408,7 @@ static _H<NSMutableSet> Diversions_;
         fclose(du);
     } else _assert(close(fds[0]));
 
-    int status;
-  wait:
-    if (waitpid(pid, &status, 0) == -1)
-        if (errno == EINTR)
-            goto wait;
-        else _assert(false);
+    ReapZombie(pid);
 
     return value;
 }
@@ -4471,7 +4547,9 @@ static _H<NSMutableSet> Diversions_;
     return request_ == nil ? nil : [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]];
 }
 
-+ (void) initialize {
++ (void) _initialize {
+    [super _initialize];
+
     Diversions_ = [NSMutableSet setWithCapacity:0];
 }
 
@@ -4481,7 +4559,10 @@ static _H<NSMutableSet> Diversions_;
 
 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
     [super webView:view didClearWindowObject:window forFrame:frame];
+    [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
 
++ (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia {
     WebDataSource *source([frame dataSource]);
     NSURLResponse *response([source response]);
     NSURL *url([response URL]);
@@ -4498,7 +4579,7 @@ static _H<NSMutableSet> Diversions_;
     }
 
     if (bridged)
-        [window setValue:cydia_ forKey:@"cydia"];
+        [window setValue:cydia forKey:@"cydia"];
 }
 
 - (void) _setupMail:(MFMailComposeViewController *)controller {
@@ -4513,24 +4594,36 @@ static _H<NSMutableSet> Diversions_;
 }
 
 - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
-    NSURL *url([request URL]);
-    NSString *host([url host]);
+    return [CydiaWebViewController requestWithHeaders:[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]];
+}
 
-    NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]);
++ (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request {
+    NSMutableURLRequest *copy([request mutableCopy]);
 
-    if (System_ != NULL && [copy valueForHTTPHeaderField:@"X-System"] == nil)
-        [copy setValue:System_ forHTTPHeaderField:@"X-System"];
+    NSURL *url([copy URL]);
+    NSString *host([url host]);
+
+    if ([copy valueForHTTPHeaderField:@"X-Cydia-Cf-Version"] == nil)
+        [copy setValue:[NSString stringWithFormat:@"%.2f", kCFCoreFoundationVersionNumber] forHTTPHeaderField:@"X-Cydia-Cf-Version"];
     if (Machine_ != NULL && [copy valueForHTTPHeaderField:@"X-Machine"] == nil)
         [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
 
+    bool bridged;
     bool token;
+
     @synchronized (HostConfig_) {
-        token = [TokenHosts_ containsObject:host] || [BridgedHosts_ containsObject:host];
+        bridged = [BridgedHosts_ containsObject:host];
+        token = [TokenHosts_ containsObject:host];
     }
 
-    if ([url isCydiaSecure] && token) {
-        if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil)
-            [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+    if ([url isCydiaSecure]) {
+        if (bridged) {
+            if (UniqueID_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Id"] == nil)
+                [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
+        } else if (token) {
+            if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil)
+                [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+        }
     }
 
     return copy;
@@ -4542,16 +4635,7 @@ static _H<NSMutableSet> Diversions_;
 }
 
 - (NSString *) applicationNameForUserAgent {
-    NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]);
-
-    if (Safari_ != nil)
-        application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application];
-    if (Build_ != nil)
-        application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application];
-    if (Product_ != nil)
-        application = [NSString stringWithFormat:@"Version/%@ %@", Product_, application];
-
-    return application;
+    return UserAgent_;
 }
 
 - (id) init {
@@ -4560,6 +4644,23 @@ static _H<NSMutableSet> Diversions_;
     } return self;
 }
 
+@end
+
+@interface AppCacheController : CydiaWebViewController {
+}
+
+@end
+
+@implementation AppCacheController
+
+- (void) didReceiveMemoryWarning {
+    // XXX: this doesn't work
+}
+
+- (bool) retainsNetworkActivityIndicator {
+    return false;
+}
+
 @end
 /* }}} */
 
@@ -4665,8 +4766,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) _doContinue {
-    [self dismissModalViewControllerAnimated:YES];
     [delegate_ cancelAndClear:NO];
+    [self dismissModalViewControllerAnimated:YES];
 }
 
 - (id) invokeDefaultMethodWithArguments:(NSArray *)args {
@@ -5106,6 +5207,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     switch (Finish_) {
         case 0:
+            [delegate_ returnToCydia];
         break;
 
         case 1:
@@ -5155,6 +5257,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     ] autorelease];
 }
 
+- (void) uicache {
+    _trace();
+    system("su -c /usr/bin/uicache mobile");
+    _trace();
+}
+
 - (void) invoke:(NSInvocation *)invocation withTitle:(NSString *)title {
     UpdateExternalStatus(1);
 
@@ -5232,9 +5340,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         case 4: [progress_ setFinish:UCLocalize("REBOOT_DEVICE")]; break;
     }
 
-    _trace();
-    system("su -c /usr/bin/uicache mobile");
-    _trace();
+    UIProgressHUD *hud([delegate_ addProgressHUD]);
+    [hud setText:UCLocalize("LOADING")];
+    [self yieldToSelector:@selector(uicache)];
+    [delegate_ removeProgressHUD:hud];
 
     UpdateExternalStatus(Finish_ == 0 ? 0 : 2);
 
@@ -5350,79 +5459,83 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     badge_ = nil;
     placard_ = nil;
 
-    [package parse];
+    if (package == nil)
+        [content_ setBackgroundColor:[UIColor whiteColor]];
+    else {
+        [package parse];
 
-    Source *source = [package source];
+        Source *source = [package source];
 
-    icon_ = [package icon];
+        icon_ = [package icon];
 
-    if (NSString *name = [package name])
-        name_ = [NSString stringWithString:name];
+        if (NSString *name = [package name])
+            name_ = [NSString stringWithString:name];
 
-    NSString *description(nil);
+        NSString *description(nil);
 
-    if (description == nil && IsWildcat_)
-        description = [package longDescription];
-    if (description == nil)
-        description = [package shortDescription];
+        if (description == nil && IsWildcat_)
+            description = [package longDescription];
+        if (description == nil)
+            description = [package shortDescription];
 
-    if (description != nil)
-        description_ = [NSString stringWithString:description];
+        if (description != nil)
+            description_ = [NSString stringWithString:description];
 
-    commercial_ = [package isCommercial];
+        commercial_ = [package isCommercial];
 
-    NSString *label = nil;
-    bool trusted = false;
+        NSString *label = nil;
+        bool trusted = false;
 
-    if (source != nil) {
-        label = [source label];
-        trusted = [source trusted];
-    } else if ([[package id] isEqualToString:@"firmware"])
-        label = UCLocalize("APPLE");
-    else
-        label = [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("UNKNOWN"), UCLocalize("LOCAL")];
+        if (source != nil) {
+            label = [source label];
+            trusted = [source trusted];
+        } else if ([[package id] isEqualToString:@"firmware"])
+            label = UCLocalize("APPLE");
+        else
+            label = [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("UNKNOWN"), UCLocalize("LOCAL")];
 
-    NSString *from(label);
+        NSString *from(label);
 
-    NSString *section = [package simpleSection];
-    if (section != nil && ![section isEqualToString:label]) {
-        section = [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"];
-        from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section];
-    }
+        NSString *section = [package simpleSection];
+        if (section != nil && ![section isEqualToString:label]) {
+            section = [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"];
+            from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section];
+        }
 
-    source_ = [NSString stringWithFormat:UCLocalize("FROM"), from];
+        source_ = [NSString stringWithFormat:UCLocalize("FROM"), from];
 
-    if (NSString *purpose = [package primaryPurpose])
-        badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]];
+        if (NSString *purpose = [package primaryPurpose])
+            badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]];
 
-    UIColor *color;
-    NSString *placard;
+        UIColor *color;
+        NSString *placard;
 
-    if (NSString *mode = [package mode]) {
-        if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) {
-            color = RemovingColor_;
-            //placard = @"removing";
+        if (NSString *mode = [package mode]) {
+            if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) {
+                color = RemovingColor_;
+                //placard = @"removing";
+            } else {
+                color = InstallingColor_;
+                //placard = @"installing";
+            }
+
+            // XXX: the removing/installing placards are not @2x
+            placard = nil;
         } else {
-            color = InstallingColor_;
-            //placard = @"installing";
+            color = [UIColor whiteColor];
+
+            if ([package installed] != nil)
+                placard = @"installed";
+            else
+                placard = nil;
         }
 
-        // XXX: the removing/installing placards are not @2x
-        placard = nil;
-    } else {
-        color = [UIColor whiteColor];
+        [content_ setBackgroundColor:color];
 
-        if ([package installed] != nil)
-            placard = @"installed";
-        else
-            placard = nil;
+        if (placard != nil)
+            placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]];
     }
 
-    [content_ setBackgroundColor:color];
-
-    if (placard != nil)
-        placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]];
-
     [self setNeedsDisplay];
     [content_ setNeedsDisplay];
 }
@@ -5435,11 +5548,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         CGRect rect;
         rect.size = [(UIImage *) icon_ size];
 
-        rect.size.width /= 4;
-        rect.size.height /= 4;
+        while (rect.size.width > 16 || rect.size.height > 16) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
 
-        rect.origin.x = 14 - rect.size.width / 4;
-        rect.origin.y = 14 - rect.size.height / 4;
+        rect.origin.x = 18 - rect.size.width / 2;
+        rect.origin.y = 18 - rect.size.height / 2;
 
         [icon_ drawInRect:rect];
     }
@@ -5451,8 +5566,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         rect.size.width /= 4;
         rect.size.height /= 4;
 
-        rect.origin.x = 20 - rect.size.width / 4;
-        rect.origin.y = 20 - rect.size.height / 4;
+        rect.origin.x = 23 - rect.size.width / 2;
+        rect.origin.y = 23 - rect.size.height / 2;
 
         [badge_ drawInRect:rect];
     }
@@ -5476,8 +5591,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         CGRect rect;
         rect.size = [(UIImage *) icon_ size];
 
-        rect.size.width /= 2;
-        rect.size.height /= 2;
+        while (rect.size.width > 32 || rect.size.height > 32) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
 
         rect.origin.x = 25 - rect.size.width / 2;
         rect.origin.y = 25 - rect.size.height / 2;
@@ -5688,14 +5805,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [list_ setRowHeight:24.0f];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [self setView:list_];
 }
 
 - (void) viewDidLoad {
@@ -5707,14 +5822,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) releaseSubviews {
     list_ = nil;
 
+    package_ = nil;
+    files_ = nil;
+
     [super releaseSubviews];
 }
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
         database_ = database;
-
-        files_ = [NSMutableArray arrayWithCapacity:32];
     } return self;
 }
 
@@ -5722,7 +5838,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     package_ = nil;
     name_ = nil;
 
-    [files_ removeAllObjects];
+    files_ = [NSMutableArray arrayWithCapacity:32];
 
     if (package != nil) {
         package_ = package;
@@ -5878,7 +5994,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if ((self = [super init]) != nil) {
         database_ = database;
         buttons_ = [NSMutableArray arrayWithCapacity:4];
-        name_ = [NSString stringWithString:name];
+        name_ = name == nil ? @"" : [NSString stringWithString:name];
         [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, (id) name_]]];
     } return self;
 }
@@ -6018,7 +6134,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     CGRect intersection = CGRectIntersection(viewframe, kbframe);
 
     if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
-        intersection.size.height += CYStatusBarHeight([self interfaceOrientation]);
+        intersection.size.height += CYStatusBarHeight();
 
     [self resizeForKeyboardBounds:intersection duration:duration curve:curve];
 }
@@ -6134,27 +6250,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         database_ = database;
         title_ = [title copy];
         [[self navigationItem] setTitle:title_];
-
-#if TryIndexedCollation
-        if ([[self class] hasIndexedCollation])
-            index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles];
-        else
-#endif
-            index_ = [NSMutableArray arrayWithCapacity:32];
-
-        indices_ = [NSMutableDictionary dictionaryWithCapacity:32];
-
-        packages_ = [NSArray array];
-        sections_ = [NSMutableArray arrayWithCapacity:16];
     } return self;
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
 
     list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-    [[self view] addSubview:list_];
+    [view addSubview:list_];
 
     // XXX: is 20 the most optimal number here?
     [list_ setSectionIndexMinimumDisplayRowCount:20];
@@ -6168,6 +6274,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) releaseSubviews {
     list_ = nil;
 
+    packages_ = nil;
+    sections_ = nil;
+    index_ = nil;
+    indices_ = nil;
+
     [super releaseSubviews];
 }
 
@@ -6199,6 +6310,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     NSArray *packages;
 
+  reload:
     if ([self shouldYield]) {
         do {
             UIProgressHUD *hud;
@@ -6216,21 +6328,26 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             if (hud != nil)
                 [delegate_ removeProgressHUD:hud];
         } while (reloading_ == 2);
-
-        reloading_ = 0;
     } else {
         packages = [self _reloadPackages];
     }
 
+@synchronized (database_) {
+    if (era_ != [database_ era])
+        goto reload;
+    reloading_ = 0;
+
     packages_ = packages;
 
-    [indices_ removeAllObjects];
-    [sections_ removeAllObjects];
+    indices_ = [NSMutableDictionary dictionaryWithCapacity:32];
+    sections_ = [NSMutableArray arrayWithCapacity:16];
 
     Section *section = nil;
 
 #if TryIndexedCollation
     if ([[self class] hasIndexedCollation]) {
+        index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles];
+
         id collation = [objc_getClass("UILocalizedIndexedCollation") currentCollation];
         NSArray *titles = [collation sectionIndexTitles];
         int secidx = -1;
@@ -6263,7 +6380,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     } else
 #endif
     {
-        [index_ removeAllObjects];
+        index_ = [NSMutableArray arrayWithCapacity:32];
 
         bool sectioned([self showsSections]);
         if (!sectioned) {
@@ -6305,11 +6422,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [(UITableView *) list_ setDataSource:self];
         [list_ reloadData];
     _end
-}
+} }
 
 - (void) reloadData {
     [super reloadData];
-    [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0];
+
+    if ([self shouldYield])
+        [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0];
+    else
+        [self _reloadData];
 }
 
 - (void) resetCursor {
@@ -6469,7 +6590,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (id) init {
     if ((self = [super init]) != nil) {
-        [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/manage/", UI_]]];
+        [self setURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]];
     } return self;
 }
 
@@ -6494,13 +6615,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [delegate_ queue];
 }
 
-- (UIBarButtonItem *) customButton {
+- (UIBarButtonItem *) rightButton {
     return Queuing_ ? [[[UIBarButtonItem alloc]
         initWithTitle:UCLocalize("QUEUE")
         style:UIBarButtonItemStyleDone
         target:self
         action:@selector(queueButtonClicked)
-    ] autorelease] : [super customButton];
+    ] autorelease] : nil;
 }
 
 - (void) queueStatusDidChange {
@@ -6660,7 +6781,32 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation CYTabBarController
 
+- (void) didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+
+    // presenting a UINavigationController on 2.x does not update its transitionView
+    // it thereby will not allow its topViewController to be unloaded by memory pressure
+    if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+        UIViewController *selected([self selectedViewController]);
+        for (UINavigationController *controller in [self viewControllers])
+            if (controller != selected)
+                if (UIViewController *top = [controller topViewController])
+                    [top unloadView];
+    }
+}
+
 - (void) setUnselectedViewController:(UIViewController *)transient {
+    if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+        if (transient != nil) {
+            [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
+            [self setSelectedIndex:0];
+        } return;
+    }
+
+    UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
+    [navigation setViewControllers:[NSArray arrayWithObject:transient]];
+    transient = navigation;
+
     NSMutableArray *controllers = [[self viewControllers] mutableCopy];
     if (transient != nil) {
         if (transient_ == nil)
@@ -6688,6 +6834,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
     if ([self unselectedViewController])
         [self setUnselectedViewController:nil];
+
+    // presenting a UINavigationController on 2.x does not update its transitionView
+    // if this view was unloaded, the tranitionView may currently be presenting nothing
+    if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+        UINavigationController *navigation((UINavigationController *) viewController);
+        [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
+        [navigation popViewControllerAnimated:NO];
+    }
 }
 
 - (NSArray *) navigationURLCollection {
@@ -6703,6 +6857,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return items;
 }
 
+- (void) dismissModalViewControllerAnimated:(BOOL)animated {
+    if ([self modalViewController] == nil && [self unselectedViewController] != nil)
+        [self setUnselectedViewController:nil];
+    else
+        [super dismissModalViewControllerAnimated:YES];
+}
+
 - (void) unloadData {
     [super unloadData];
 
@@ -6841,7 +7002,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     CGRect barframe([refreshbar_ frame]);
 
     if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
-        barframe.origin.y = CYStatusBarHeight([self interfaceOrientation]);
+        barframe.origin.y = CYStatusBarHeight();
     else
         barframe.origin.y = 0;
 
@@ -6925,8 +7086,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) reloadData {
     [super reloadData];
 
-    if (UIViewController *visible = [self visibleViewController])
+    UIViewController *visible([self visibleViewController]);
+    if (visible != nil)
         [visible reloadData];
+
+    // on the iPad, this view controller is ALSO visible. :(
+    if (IsWildcat_)
+        if (UIViewController *top = [self topViewController])
+            if (top != visible)
+                [top reloadData];
 }
 
 - (void) unloadData {
@@ -7018,15 +7186,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [package parse];
         UIImage *icon([package icon]);
         [self _returnPNGWithImage:icon forRequest:request];
-    } else if ([command isEqualToString:@"source-icon"]) {
-        if (path == nil)
-            goto fail;
-        path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-        NSString *source(Simplify(path));
-        UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sources/%@.png", App_, source]]);
-        if (icon == nil)
-            icon = [UIImage applicationImageNamed:@"unknown.png"];
-        [self _returnPNGWithImage:icon forRequest:request];
     } else if ([command isEqualToString:@"uikit-image"]) {
         if (path == nil)
             goto fail;
@@ -7037,8 +7196,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         if (path == nil)
             goto fail;
         path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-        NSString *section(Simplify(path));
-        UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, [section stringByReplacingOccurrencesOfString:@" " withString:@"_"]]]);
+        UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, [path stringByReplacingOccurrencesOfString:@" " withString:@"_"]]]);
         if (icon == nil)
             icon = [UIImage applicationImageNamed:@"unknown.png"];
         [self _returnPNGWithImage:icon forRequest:request];
@@ -7055,7 +7213,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 /* Section Controller {{{ */
 @interface SectionController : FilteredPackageListController {
+    _H<IndirectDelegate, 1> indirect_;
+    _H<CydiaObject> cydia_;
     _H<NSString> section_;
+    std::vector< _H<CyteWebViewTableViewCell, 1> > promoted_;
 }
 
 - (id) initWithDatabase:(Database *)database section:(NSString *)section;
@@ -7069,7 +7230,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if (name == nil)
         name = @"all";
 
-    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sections/%@", name]];
+    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sections/%@", [name stringByAddingPercentEscapesIncludingReserved]]];
 }
 
 - (id) initWithDatabase:(Database *)database section:(NSString *)name {
@@ -7082,10 +7243,102 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         title = UCLocalize("NO_SECTION");
 
     if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) {
+        indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+        cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
         section_ = name;
     } return self;
 }
 
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
+    return [super numberOfSectionsInTableView:list] + 1;
+}
+
+- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section {
+    return section == 0 ? nil : [super tableView:list titleForHeaderInSection:(section - 1)];
+}
+
+- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section {
+    return section == 0 ? promoted_.size() : [super tableView:list numberOfRowsInSection:(section - 1)];
+}
+
++ (NSIndexPath *) adjustedIndexPath:(NSIndexPath *)path {
+    return [NSIndexPath indexPathForRow:[path row] inSection:([path section] - 1)];
+}
+
+- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+    if ([path section] != 0)
+        return [super tableView:table cellForRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+
+    return promoted_[[path row]];
+}
+
+- (void) tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+    if ([path section] != 0)
+        return [super tableView:table didSelectRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+}
+
+- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
+    NSInteger section([super tableView:tableView sectionForSectionIndexTitle:title atIndex:index]);
+    return section == 0 ? 0 : section + 1;
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+    NSURL *url([request URL]);
+    if (url == nil)
+        return;
+
+    if ([frame isEqualToString:@"_open"])
+        [delegate_ openURL:url];
+    else {
+        CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+        [controller setDelegate:delegate_];
+        [[self navigationController] pushViewController:controller animated:YES];
+    }
+
+    [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+    return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+    [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) loadView {
+    [super loadView];
+
+    // XXX: this code is horrible. I mean, wtf Jay?
+    if (ShowPromoted_ && [[Metadata_ objectForKey:@"ShowPromoted"] boolValue]) {
+        promoted_.resize(1);
+
+        for (unsigned i(0); i != promoted_.size(); ++i) {
+            CyteWebViewTableViewCell *promoted([CyteWebViewTableViewCell cellWithRequest:[NSURLRequest
+                requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/sectionhead/%u/%@",
+                    UI_, i, section_ == nil ? @"" : [section_ stringByAddingPercentEscapesIncludingReserved]]
+                ]]
+
+                cachePolicy:NSURLRequestUseProtocolCachePolicy
+                timeoutInterval:120
+            ]]);
+
+            [promoted setDelegate:self];
+            promoted_[i] = promoted;
+        }
+    }
+}
+
+- (void) setDelegate:(id)delegate {
+    [super setDelegate:delegate];
+    [cydia_ setDelegate:delegate];
+}
+
+- (void) releaseSubviews {
+    promoted_.clear();
+    [super releaseSubviews];
+}
+
 @end
 /* }}} */
 /* Sections Controller {{{ */
@@ -7196,14 +7449,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [list_ setRowHeight:45.0f];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [self setView:list_];
 }
 
 - (void) viewDidLoad {
@@ -7215,15 +7466,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) releaseSubviews {
     list_ = nil;
 
+    sections_ = nil;
+    filtered_ = nil;
+
     [super releaseSubviews];
 }
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
         database_ = database;
-
-        sections_ = [NSMutableArray arrayWithCapacity:16];
-        filtered_ = [NSMutableArray arrayWithCapacity:16];
     } return self;
 }
 
@@ -7232,8 +7483,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     NSArray *packages = [database_ packages];
 
-    [sections_ removeAllObjects];
-    [filtered_ removeAllObjects];
+    sections_ = [NSMutableArray arrayWithCapacity:16];
+    filtered_ = [NSMutableArray arrayWithCapacity:16];
 
     NSMutableDictionary *sections([NSMutableDictionary dictionaryWithCapacity:32]);
 
@@ -7301,7 +7552,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     _H<NSArray> packages_;
     _H<NSMutableArray> sections_;
     _H<UITableView, 2> list_;
+    _H<CyteWebView, 1> dickbar_;
     unsigned upgrades_;
+    _H<IndirectDelegate, 1> indirect_;
+    _H<CydiaObject> cydia_;
 }
 
 - (id) initWithDatabase:(Database *)database;
@@ -7378,34 +7632,108 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
 
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[view bounds] style:UITableViewStylePlain] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [list_ setRowHeight:73];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [view addSubview:list_];
+
+    if (AprilFools_ && kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+        CGRect dickframe([view bounds]);
+        dickframe.size.height = 44;
+
+        dickbar_ = [[[CyteWebView alloc] initWithFrame:dickframe] autorelease];
+        [dickbar_ setDelegate:self];
+        [view addSubview:dickbar_];
+
+        [dickbar_ setBackgroundColor:[UIColor clearColor]];
+        [dickbar_ setScalesPageToFit:YES];
+
+        UIWebDocumentView *document([dickbar_ _documentView]);
+        [document setBackgroundColor:[UIColor clearColor]];
+        [document setDrawsBackground:NO];
+
+        WebView *webview([document webView]);
+        [webview setShouldUpdateWhileOffscreen:NO];
+
+        UIScrollView *scroller([dickbar_ scrollView]);
+        [scroller setScrollingEnabled:NO];
+        [scroller setFixedBackgroundPattern:YES];
+        [scroller setBackgroundColor:[UIColor clearColor]];
+
+        WebPreferences *preferences([webview preferences]);
+        [preferences setCacheModel:WebCacheModelDocumentBrowser];
+        [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+        [preferences setOfflineWebApplicationCacheEnabled:YES];
+
+        [dickbar_ loadRequest:[NSURLRequest
+            requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/dickbar/", UI_]]]
+            cachePolicy:NSURLRequestUseProtocolCachePolicy
+            timeoutInterval:120
+        ]];
+
+        UIEdgeInsets inset = {44, 0, 0, 0};
+        [list_ setContentInset:inset];
+
+        [dickbar_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
+    }
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+    NSURL *url([request URL]);
+    if (url == nil)
+        return;
+
+    if ([frame isEqualToString:@"_open"])
+        [delegate_ openURL:url];
+    else {
+        CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+        [controller setDelegate:delegate_];
+        [[self navigationController] pushViewController:controller animated:YES];
+    }
+
+    [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+    return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+    [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) setDelegate:(id)delegate {
+    [super setDelegate:delegate];
+    [cydia_ setDelegate:delegate];
 }
 
 - (void) viewDidLoad {
     [super viewDidLoad];
 
-    [[self navigationItem] setTitle:UCLocalize("CHANGES")];
+    [[self navigationItem] setTitle:(AprilFools_ ? @"Timeline" : UCLocalize("CHANGES"))];
 }
 
 - (void) releaseSubviews {
     list_ = nil;
 
+    packages_ = nil;
+    sections_ = nil;
+    dickbar_ = nil;
+
     [super releaseSubviews];
 }
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
+        indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+        cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
         database_ = database;
-
-        packages_ = [NSArray array];
-        sections_ = [NSMutableArray arrayWithCapacity:16];
     } return self;
 }
 
@@ -7450,7 +7778,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         goto reload;
 
     packages_ = packages;
-    [sections_ removeAllObjects];
+    sections_ = [NSMutableArray arrayWithCapacity:16];
 
     Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
     Section *ignored = nil;
@@ -7557,7 +7885,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if ([search_ text] == nil || [[search_ text] isEqualToString:@""])
         return [NSURL URLWithString:@"cydia://search"];
     else
-        return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]];
+        return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [[search_ text] stringByAddingPercentEscapesIncludingReserved]]];
 }
 
 - (void) useSearch {
@@ -7692,7 +8020,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation PackageSettingsController
 
 - (NSURL *) navigationURL {
-    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", [package_ id]]];
+    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", (id) name_]];
 }
 
 - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
@@ -7752,15 +8080,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         _assert(false);
     }
 
-    _forever {
-        int status;
-        int result(waitpid(pid, &status, 0));
-
-        if (result != -1) {
-            _assert(result == pid);
-            break;
-        }
-    }
+    ReapZombie(pid);
 }
 
 - (void) onIgnored:(id)control {
@@ -7786,13 +8106,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
 
     table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease];
     [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [(UITableView *) table_ setDataSource:self];
     [table_ setDelegate:self];
-    [[self view] addSubview:table_];
+    [view addSubview:table_];
 
     subscribedSwitch_ = [[[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)] autorelease];
     [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
@@ -7925,6 +8247,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @interface SourceCell : CyteTableViewCell <
     CyteTableViewCellDelegate
 > {
+    _H<NSURL> url_;
     _H<UIImage> icon_;
     _H<NSString> origin_;
     _H<NSString> label_;
@@ -7936,31 +8259,28 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation SourceCell
 
-- (void) _setImage:(UIImage *)image {
-    icon_ = image;
-    [content_ setNeedsDisplay];
+- (void) _setImage:(NSArray *)data {
+    if ([url_ isEqual:[data objectAtIndex:0]]) {
+        icon_ = [data objectAtIndex:1];
+        [content_ setNeedsDisplay];
+    }
 }
 
-- (void) _setSource:(Source *)source {
+- (void) _setSource:(NSURL *) url {
     NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
 
-    if (NSString *base = [source base])
-        if ([base length] != 0) {
-            NSURL *url([NSURL URLWithString:[base stringByAppendingString:@"CydiaIcon.png"]]);
-
-            if (NSData *data = [NSURLConnection
-                sendSynchronousRequest:[NSURLRequest
-                    requestWithURL:url
-                    //cachePolicy:NSURLRequestUseProtocolCachePolicy
-                    //timeoutInterval:5
-                ]
-
-                returningResponse:NULL
-                error:NULL
-            ])
-                if (UIImage *image = [UIImage imageWithData:data])
-                    [self performSelectorOnMainThread:@selector(_setImage:) withObject:image waitUntilDone:NO];
-        }
+    if (NSData *data = [NSURLConnection
+        sendSynchronousRequest:[NSURLRequest
+            requestWithURL:url
+            //cachePolicy:NSURLRequestUseProtocolCachePolicy
+            //timeoutInterval:5
+        ]
+
+        returningResponse:NULL
+        error:NULL
+    ])
+        if (UIImage *image = [UIImage imageWithData:data])
+            [self performSelectorOnMainThread:@selector(_setImage:) withObject:[NSArray arrayWithObjects:url, image, nil] waitUntilDone:NO];
 
     [pool release];
 }
@@ -7969,11 +8289,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     icon_ = [UIImage applicationImageNamed:@"unknown.png"];
 
     origin_ = [source name];
-    label_ = [source uri];
+    label_ = [source rooturi];
 
     [content_ setNeedsDisplay];
 
-    [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:source];
+    url_ = [source iconURL];
+    [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:url_];
 }
 
 - (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
@@ -7988,6 +8309,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
         [content_ setDelegate:self];
         [content_ setOpaque:YES];
+
+        [[content_ layer] setContentsGravity:kCAGravityTopLeft];
     } return self;
 }
 
@@ -7999,19 +8322,31 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     bool highlighted(highlighted_);
     float width(rect.size.width);
 
-    if (icon_ != nil)
-        [icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
+    if (icon_ != nil) {
+        CGRect rect;
+        rect.size = [(UIImage *) icon_ size];
+
+        while (rect.size.width > 32 || rect.size.height > 32) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
+
+        rect.origin.x = 25 - rect.size.width / 2;
+        rect.origin.y = 25 - rect.size.height / 2;
+
+        [icon_ drawInRect:rect];
+    }
 
     if (highlighted)
         UISetColor(White_);
 
     if (!highlighted)
         UISetColor(Black_);
-    [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
+    [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 65) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
 
     if (!highlighted)
-        UISetColor(Blue_);
-    [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
+        UISetColor(Gray_);
+    [label_ drawAtPoint:CGPointMake(48, 29) forWidth:(width - 65) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
 }
 
 @end
@@ -8029,7 +8364,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation SourceController
 
 - (NSURL *) navigationURL {
-    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [source_ name]]];
+    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [key_ stringByAddingPercentEscapesIncludingReserved]]];
 }
 
 - (id) initWithDatabase:(Database *)database source:(Source *)source {
@@ -8057,6 +8392,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     UITableViewDelegate
 > {
     _transient Database *database_;
+    unsigned era_;
+
     _H<UITableView, 2> list_;
     _H<NSMutableArray> sources_;
     int offset_;
@@ -8109,38 +8446,24 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
-    return offset_ == 0 ? 1 : 2;
+    return 1;
 }
 
 - (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
-    switch (section + (offset_ == 0 ? 1 : 0)) {
-        case 0: return UCLocalize("ENTERED_BY_USER");
-        case 1: return UCLocalize("INSTALLED_BY_PACKAGE");
-
-        _nodefault
-    }
+    return nil;
 }
 
 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    int count = [sources_ count];
-    switch (section) {
-        case 0: return (offset_ == 0 ? count : offset_);
-        case 1: return count - offset_;
-
-        _nodefault
-    }
+    return [sources_ count];
 }
 
 - (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath {
-    unsigned idx = 0;
-    switch (indexPath.section) {
-        case 0: idx = indexPath.row; break;
-        case 1: idx = indexPath.row + offset_; break;
+@synchronized (database_) {
+    if ([database_ era] != era_)
+        return nil;
 
-        _nodefault
-    }
-    return [sources_ objectAtIndex:idx];
-}
+    return [sources_ objectAtIndex:[indexPath row]];
+} }
 
 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *cellIdentifier = @"SourceCell";
@@ -8181,6 +8504,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) complete {
     [delegate_ addTrivialSource:href_];
+    href_ = nil;
+
     [delegate_ syncData];
 }
 
@@ -8191,7 +8516,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         href = [href substringFromIndex:(colon.location + 3)];
     href = [href stringByAddingPercentEscapes];
     href = [CydiaURL(@"api/repotag/") stringByAppendingString:href];
-    href = [href stringByCachingURLWithCurrentCDN];
 
     NSURL *url([NSURL URLWithString:href]);
 
@@ -8222,17 +8546,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         trivial_bz2_ == nil &&
         trivial_gz_ == nil
     ) {
+        NSString *warning(cydia_ ? [self yieldToSelector:@selector(getWarning)] : nil);
+
         [delegate_ releaseNetworkActivityIndicator];
 
         [delegate_ removeProgressHUD:hud_];
         hud_ = nil;
 
-        bool defer(false);
-
         if (cydia_) {
-            if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
-                defer = true;
-
+            if (warning != nil) {
                 UIAlertView *alert = [[[UIAlertView alloc]
                     initWithTitle:UCLocalize("SOURCE_WARNING")
                     message:warning
@@ -8246,8 +8568,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
                 [alert setContext:@"warning"];
                 [alert setNumberOfRows:1];
                 [alert show];
-            } else
-                [self complete];
+
+                // XXX: there used to be this great mechanism called yieldToPopup... who deleted it?
+                error_ = nil;
+                return;
+            }
+
+            [self complete];
         } else if (error_ != nil) {
             UIAlertView *alert = [[[UIAlertView alloc]
                 initWithTitle:UCLocalize("VERIFICATION_ERROR")
@@ -8259,6 +8586,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
             [alert setContext:@"urlerror"];
             [alert show];
+
+            href_ = nil;
         } else {
             UIAlertView *alert = [[[UIAlertView alloc]
                 initWithTitle:UCLocalize("NOT_REPOSITORY")
@@ -8270,9 +8599,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
             [alert setContext:@"trivial"];
             [alert show];
+
+            href_ = nil;
         }
 
-        href_ = nil;
         error_ = nil;
     }
 }
@@ -8309,8 +8639,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
 
     if ([url isCydiaSecure]) {
-        if (UniqueID_ != nil)
+        if (UniqueID_ != nil) {
             [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+            [request setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
+        }
     }
 
     return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
@@ -8358,7 +8690,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     else if ([context isEqualToString:@"warning"]) {
         switch (button) {
             case 1:
-                [self complete];
+                [self performSelector:@selector(complete) withObject:nil afterDelay:0];
             break;
 
             case 0:
@@ -8367,21 +8699,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             _nodefault
         }
 
-        href_ = nil;
-
         [alert dismissWithClickedButtonIndex:-1 animated:YES];
     }
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-    [list_ setRowHeight:56];
+    [list_ setRowHeight:53];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [self setView:list_];
 }
 
 - (void) viewDidLoad {
@@ -8394,27 +8722,31 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) releaseSubviews {
     list_ = nil;
 
+    sources_ = nil;
+
     [super releaseSubviews];
 }
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
         database_ = database;
-        sources_ = [NSMutableArray arrayWithCapacity:16];
     } return self;
 }
 
 - (void) reloadData {
     [super reloadData];
 
+@synchronized (database_) {
+    era_ = [database_ era];
+
     pkgSourceList list;
     if ([database_ popErrorWithTitle:UCLocalize("SOURCES") forOperation:list.ReadMainList()])
         return;
 
-    [sources_ removeAllObjects];
+    sources_ = [NSMutableArray arrayWithCapacity:16];
     [sources_ addObjectsFromArray:[database_ sources]];
     _trace();
-    [sources_ sortUsingSelector:@selector(compareByNameAndType:)];
+    [sources_ sortUsingSelector:@selector(compareByName:)];
     _trace();
 
     int count([sources_ count]);
@@ -8428,7 +8760,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [list_ setEditing:NO];
     [self updateButtonsForEditingStatus:NO animated:NO];
     [list_ reloadData];
-}
+} }
 
 - (void) showAddSourcePrompt {
     UIAlertView *alert = [[[UIAlertView alloc]
@@ -8518,13 +8850,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation SettingsController
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease];
+    table_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped] autorelease];
     [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [table_ setDelegate:self];
     [(UITableView *) table_ setDataSource:self];
-    [[self view] addSubview:table_];
+    [self setView:table_];
 
     NSArray *items = [NSArray arrayWithObjects:
         UCLocalize("USER"),
@@ -8532,6 +8862,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         UCLocalize("DEVELOPER"),
     nil];
     segment_ = [[[UISegmentedControl alloc] initWithItems:items] autorelease];
+    [segment_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin)];
     container_ = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)] autorelease];
     [container_ addSubview:segment_];
 }
@@ -8700,8 +9031,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation StashController
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-    [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
+
+    [view setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
 
     spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
     CGRect spinrect = [spinner_ frame];
@@ -8709,7 +9043,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     spinrect.origin.y = [[self view] frame].size.height - 80.0f;
     [spinner_ setFrame:spinrect];
     [spinner_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin];
-    [[self view] addSubview:spinner_];
+    [view addSubview:spinner_];
     [spinner_ startAnimating];
 
     CGRect captrect;
@@ -8725,7 +9059,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [caption_ setBackgroundColor:[UIColor clearColor]];
     [caption_ setShadowColor:[UIColor blackColor]];
     [caption_ setTextAlignment:UITextAlignmentCenter];
-    [[self view] addSubview:caption_];
+    [view addSubview:caption_];
 
     CGRect statusrect;
     statusrect.size.width = [[self view] frame].size.width;
@@ -8740,7 +9074,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [status_ setBackgroundColor:[UIColor clearColor]];
     [status_ setShadowColor:[UIColor blackColor]];
     [status_ setTextAlignment:UITextAlignmentCenter];
-    [[self view] addSubview:status_];
+    [view addSubview:status_];
 }
 
 - (void) releaseSubviews {
@@ -8877,10 +9211,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     }
 }
 
+- (void) returnToCydia {
+    [self _loaded];
+}
+
 - (void) _saveConfig {
-    _trace();
-    MetaFile_.Sync();
-    _trace();
+    @synchronized (database_) {
+        _trace();
+        MetaFile_.Sync();
+        _trace();
+    }
 
     if (Changed_) {
         NSString *error(nil);
@@ -8898,7 +9238,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         }
     }
 
-    WriteSources();
+    CydiaWriteSources();
 }
 
 // Navigation controller for the queuing badge.
@@ -8985,9 +9325,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     [database_ yieldToSelector:@selector(reloadDataWithInvocation:) withObject:invocation];
 
-    if (hud != nil)
-        [self removeProgressHUD:hud];
-
     size_t changes(0);
 
     [essential_ removeAllObjects];
@@ -9020,7 +9357,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     [self _updateData];
 
-    [self refreshIfPossible];
+    if (hud != nil)
+        [self removeProgressHUD:hud];
 } }
 
 - (void) updateData {
@@ -9088,6 +9426,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) reloadData {
     [self reloadDataWithInvocation:nil];
+    if ([database_ progressDelegate] == nil)
+        [self _loaded];
 }
 
 - (void) syncData {
@@ -9096,15 +9436,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) addSource:(NSDictionary *) source {
-    AddSource(source);
+    CydiaAddSource(source);
 }
 
 - (void) addSource:(NSString *)href withDistribution:(NSString *)distribution andSections:(NSArray *)sections {
-    AddSource(href, distribution, sections);
+    CydiaAddSource(href, distribution, sections);
 }
 
 - (void) addTrivialSource:(NSString *)href {
-    AddSource(href, @"./");
+    CydiaAddSource(href, @"./");
 }
 
 - (void) updateValues {
@@ -9198,6 +9538,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     ++locked_;
     [self detachNewProgressSelector:@selector(perform_) toTarget:self forController:navigation title:@"RUNNING"];
     --locked_;
+    [self refreshIfPossible];
 }
 
 - (void) showSettings {
@@ -9351,7 +9692,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (UIProgressHUD *) addProgressHUD {
-    UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window_] autorelease]);
+    UIProgressHUD *hud([[[UIProgressHUD alloc] init] autorelease]);
     [hud setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
 
     [window_ setUserInteractionEnabled:NO];
@@ -9360,10 +9701,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if (UIViewController *modal = [target modalViewController])
         target = modal;
 
-    UIView *view([target view]);
-    [view addSubview:hud];
-
-    [hud show:YES];
+    [hud showInView:[target view]];
 
     ++locked_;
     return hud;
@@ -9371,7 +9709,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) removeProgressHUD:(UIProgressHUD *)hud {
     --locked_;
-    [hud show:NO];
+    [hud hide];
     [hud removeFromSuperview];
     [window_ setUserInteractionEnabled:YES];
 }
@@ -9385,10 +9723,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if ([[url absoluteString] length] <= [scheme length] + 3)
         return nil;
     NSString *path([[url absoluteString] substringFromIndex:[scheme length] + 3]);
-    NSArray *components([path pathComponents]);
+    NSArray *components([path componentsSeparatedByString:@"/"]);
 
-    if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"])
-        return [self pageForPackage:[components objectAtIndex:1]];
+    if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"]) {
+        CyteViewController *controller([self pageForPackage:[components objectAtIndex:1]]);
+        if (controller != nil)
+            [controller setDelegate:self];
+        return controller;
+    }
 
     if ([components count] < 1 || ![scheme isEqualToString:@"cydia"])
         return nil;
@@ -9406,6 +9748,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
             controller = [[[ManageController alloc] init] autorelease];
         }
 
+        if ([base isEqualToString:@"storage"]) {
+            controller = [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/storage/", UI_]]] autorelease];
+        }
+
         if ([base isEqualToString:@"sources"]) {
             controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease];
         }
@@ -9437,13 +9783,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         }
 
         if (!external && [base isEqualToString:@"search"]) {
-            controller = [[[SearchController alloc] initWithDatabase:database_ query:argument] autorelease];
+            controller = [[[SearchController alloc] initWithDatabase:database_ query:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] autorelease];
         }
 
         if (!external && [base isEqualToString:@"sections"]) {
             if ([argument isEqualToString:@"all"])
                 argument = nil;
-            controller = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease];
+            controller = [[[SectionController alloc] initWithDatabase:database_ section:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] autorelease];
         }
 
         if (!external && [base isEqualToString:@"sources"]) {
@@ -9451,7 +9797,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
                 controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease];
                 [(SourcesController *)controller showAddSourcePrompt];
             } else {
-                Source *source = [database_ sourceWithKey:argument];
+                Source *source = [database_ sourceWithKey:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
                 controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease];
             }
         }
@@ -9483,11 +9829,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (BOOL) openCydiaURL:(NSURL *)url forExternal:(BOOL)external {
     CyteViewController *page([self pageForURL:url forExternal:external]);
 
-    if (page != nil) {
-        UINavigationController *nav = [[[UINavigationController alloc] init] autorelease];
-        [nav setViewControllers:[NSArray arrayWithObject:page]];
-        [tabbar_ setUnselectedViewController:nav];
-    }
+    if (page != nil)
+        [tabbar_ setUnselectedViewController:page];
 
     return page != nil;
 }
@@ -9572,10 +9915,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     [self removeStashController];
 
-    if (ExecFork() == 0) {
+    pid_t pid(ExecFork());
+    if (pid == 0) {
         execlp("launchctl", "launchctl", "stop", "com.apple.SpringBoard", NULL);
         perror("launchctl stop");
+        exit(0);
     }
+
+    ReapZombie(pid);
 }
 
 - (void) setupViewControllers {
@@ -9584,7 +9931,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSMutableArray *items([NSMutableArray arrayWithObjects:
         [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage applicationImageNamed:@"home.png"] tag:0] autorelease],
         [[[UITabBarItem alloc] initWithTitle:UCLocalize("SECTIONS") image:[UIImage applicationImageNamed:@"install.png"] tag:0] autorelease],
-        [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage applicationImageNamed:@"changes.png"] tag:0] autorelease],
+        [[[UITabBarItem alloc] initWithTitle:(AprilFools_ ? @"Timeline" : UCLocalize("CHANGES")) image:[UIImage applicationImageNamed:@"changes.png"] tag:0] autorelease],
         [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage applicationImageNamed:@"search.png"] tag:0] autorelease],
     nil]);
 
@@ -9606,7 +9953,29 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [tabbar_ setUpdateDelegate:self];
 }
 
+- (void) _sendMemoryWarningNotification {
+    if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: maybe 4_0?
+        [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationMemoryWarningNotification" object:[UIApplication sharedApplication]];
+    else
+        [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidReceiveMemoryWarningNotification" object:[UIApplication sharedApplication]];
+}
+
+- (void) _sendMemoryWarningNotifications {
+    while (true) {
+        [self performSelectorOnMainThread:@selector(_sendMemoryWarningNotification) withObject:nil waitUntilDone:NO];
+        sleep(2);
+        //usleep(2000000);
+    }
+}
+
+- (void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
+    NSLog(@"--");
+    [[NSURLCache sharedURLCache] removeAllCachedResponses];
+}
+
 - (void) applicationDidFinishLaunching:(id)unused {
+    //[NSThread detachNewThreadSelector:@selector(_sendMemoryWarningNotifications) toTarget:self withObject:nil];
+
 _trace();
     if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
         [self setApplicationSupportsShakeToEdit:NO];
@@ -9638,7 +10007,7 @@ _trace();
     broken_ = [NSMutableArray arrayWithCapacity:4];
 
     // XXX: I really need this thing... like, seriously... I'm sorry
-    [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData];
+    [[[AppCacheController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData];
 
     window_ = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
     [window_ orderFront:self];
@@ -9705,7 +10074,8 @@ _trace();
         [window_ setUserInteractionEnabled:NO];
     }
 
-    [self reloadData];
+    [self reloadDataWithInvocation:nil];
+    [self refreshIfPossible];
     PrintTimes();
 
     [self disemulate];
@@ -9723,8 +10093,8 @@ _trace();
     NSDate *closed = [Metadata_ objectForKey:@"LastClosed"];
     if (valid && closed != nil) {
         NSTimeInterval interval([closed timeIntervalSinceNow]);
-        // XXX: Is 15 minutes the optimal time here?
-        if (interval > 0 && interval <= -(15*60))
+        // XXX: Is 30 minutes the optimal time here?
+        if (interval <= -(30*60))
             valid = NO;
     }
 
@@ -9868,7 +10238,6 @@ MSHook(id, NSURLConnection$init$, NSURLConnection *self, SEL _cmd, NSURLRequest
 
     NSURL *url([copy URL]);
 
-    NSString *href([url absoluteString]);
     NSString *host([url host]);
     NSString *scheme([[url scheme] lowercaseString]);
 
@@ -9881,9 +10250,9 @@ MSHook(id, NSURLConnection$init$, NSURLConnection *self, SEL _cmd, NSURLRequest
 
         if (NSString *control = [copy valueForHTTPHeaderField:@"Cache-Control"])
             if ([control isEqualToString:@"max-age=0"])
-                if ([CachedURLs_ containsObject:href]) {
+                if ([CachedURLs_ containsObject:url]) {
 #if !ForRelease
-                    NSLog(@"~~~: %@", href);
+                    NSLog(@"~~~: %@", url);
 #endif
 
                     [copy setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
@@ -9930,6 +10299,13 @@ int main(int argc, char *argv[]) {
             NSLog(@"unknown UIUserInterfaceIdiom!");
     }
 
+    Pcre pattern("^([0-9]+\\.[0-9]+)");
+
+    if (pattern([device systemVersion]))
+        Firmware_ = pattern[1];
+    if (pattern(Cydia_))
+        Major_ = pattern[1];
+
     SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4];
 
     HostConfig_ = [[[NSObject alloc] init] autorelease];
@@ -9941,7 +10317,11 @@ int main(int argc, char *argv[]) {
         CachedURLs_ = [NSMutableSet setWithCapacity:32];
     }
 
-    UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]);
+    NSString *ui(@"ui/ios");
+    if (Idiom_ != nil)
+        ui = [ui stringByAppendingString:[NSString stringWithFormat:@"~%@", Idiom_]];
+    ui = [ui stringByAppendingString:[NSString stringWithFormat:@"/%@", Major_]];
+    UI_ = CydiaURL(ui);
 
     PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
 
@@ -10083,28 +10463,21 @@ int main(int argc, char *argv[]) {
 
     UniqueID_ = [device uniqueIdentifier];
 
-    CFStringRef (*$CTSIMSupportCopyMobileSubscriberCountryCode)(CFAllocatorRef);
-    $CTSIMSupportCopyMobileSubscriberCountryCode = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode"));
-    CFStringRef mcc($CTSIMSupportCopyMobileSubscriberCountryCode == NULL ? NULL : (*$CTSIMSupportCopyMobileSubscriberCountryCode)(kCFAllocatorDefault));
-
-    CFStringRef (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(CFAllocatorRef);
-    $CTSIMSupportCopyMobileSubscriberNetworkCode = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode"));
-    CFStringRef mnc($CTSIMSupportCopyMobileSubscriberNetworkCode == NULL ? NULL : (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(kCFAllocatorDefault));
-
-    if (mcc != NULL && mnc != NULL)
-        PLMN_ = [NSString stringWithFormat:@"%@%@", mcc, mnc];
-
-    if (mnc != NULL)
-        CFRelease(mnc);
-    if (mcc != NULL)
-        CFRelease(mcc);
-
-    if (NSDictionary *system = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"])
-        Build_ = [system objectForKey:@"ProductBuildVersion"];
     if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) {
         Product_ = [info objectForKey:@"SafariProductVersion"];
         Safari_ = [info objectForKey:@"CFBundleVersion"];
     }
+
+    NSString *agent([NSString stringWithFormat:@"Cydia/%@ CF/%.2f", Cydia_, kCFCoreFoundationVersionNumber]);
+
+    if (Pcre match = Pcre("^[0-9]+(\\.[0-9]+)+", Safari_))
+        agent = [NSString stringWithFormat:@"Safari/%@ %@", match[0], agent];
+    if (Pcre match = Pcre("^[0-9]+[A-Z][0-9]+[a-z]?", System_))
+        agent = [NSString stringWithFormat:@"Mobile/%@ %@", match[0], agent];
+    if (Pcre match = Pcre("^[0-9]+(\\.[0-9]+)+", Product_))
+        agent = [NSString stringWithFormat:@"Version/%@ %@", match[0], agent];
+
+    UserAgent_ = agent;
     /* }}} */
     /* Load Database {{{ */
     _trace();
@@ -10126,10 +10499,6 @@ int main(int argc, char *argv[]) {
         Token_ = [Metadata_ objectForKey:@"Token"];
 
         Version_ = [Metadata_ objectForKey:@"Version"];
-
-        @synchronized (HostConfig_) {
-            CydiaSource_ = [Metadata_ objectForKey:@"CydiaSource"];
-        }
     }
 
     if (Settings_ != nil)
@@ -10155,27 +10524,22 @@ int main(int argc, char *argv[]) {
         [Metadata_ setObject:Version_ forKey:@"Version"];
     }
 
-    @synchronized (HostConfig_) {
-        if (CydiaSource_ == nil) {
-            CydiaSource_ = @"apt.saurik.com";
-            [Metadata_ setObject:CydiaSource_ forKey:@"CydiaSource"];
-        }
-    }
-
     if ([Version_ unsignedIntValue] == 0) {
-        AddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
-        AddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
-        AddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
-        AddSource(@"http://repo666.ultrasn0w.com/", @"./");
+        CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+        CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+        CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+        CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
 
         Version_ = [NSNumber numberWithUnsignedInt:1];
         [Metadata_ setObject:Version_ forKey:@"Version"];
 
+        [Metadata_ removeObjectForKey:@"LastUpdate"];
+
         Changed_ = true;
     }
     /* }}} */
 
-    WriteSources();
+    CydiaWriteSources();
 
     _trace();
     MetaFile_.Open("/var/lib/cydia/metadata.cb0");
@@ -10212,11 +10576,7 @@ int main(int argc, char *argv[]) {
 
     int version([[NSString stringWithContentsOfFile:@"/var/lib/cydia/firmware.ver"] intValue]);
 
-    if (access("/tmp/.cydia.fw", F_OK) == 0) {
-        unlink("/tmp/.cydia.fw");
-        goto firmware;
-    } else if (access("/User", F_OK) != 0 || version < 4) {
-      firmware:
+    if (access("/User", F_OK) != 0 || version != 5) {
         _trace();
         system("/usr/libexec/cydia/firmware.sh");
         _trace();
@@ -10273,11 +10633,21 @@ int main(int argc, char *argv[]) {
     //UIKeyboardDisableAutomaticAppearance();
     /* }}} */
 
+    BOOL (*GSSystemHasCapability)(CFStringRef) = reinterpret_cast<BOOL (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemHasCapability"));
+    ShowPromoted_ = GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("armv7"));
+
     Colon_ = UCLocalize("COLON_DELIMITED");
     Elision_ = UCLocalize("ELISION");
     Error_ = UCLocalize("ERROR");
     Warning_ = UCLocalize("WARNING");
 
+#if !ForRelease
+    AprilFools_ = true;
+#else
+    CFGregorianDate date(CFAbsoluteTimeGetGregorianDate(CFAbsoluteTimeGetCurrent(), CFTimeZoneCopySystem()));
+    AprilFools_ = date.month == 4 && date.day == 1;
+#endif
+
     _trace();
     int value(UIApplicationMain(argc, argv, @"Cydia", @"Cydia"));