]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Allow profiling usage of Database::sections_ in -[Database mappedSectionForPointer:].
[cydia.git] / MobileCydia.mm
index c0db7b0c46dc12bb839e09be1067a25edb35c451..b7050fc6d3dafbded0ce1e5468f64f2a1b8bd902 100644 (file)
 #include <sys/sysctl.h>
 #include <sys/param.h>
 #include <sys/mount.h>
+#include <sys/reboot.h>
 
 #include <fcntl.h>
 #include <notify.h>
@@ -118,9 +119,10 @@ extern "C" {
 #include <errno.h>
 #include <pcre.h>
 
-#include <ext/hash_map>
+#include <Cytore.hpp>
 
 #include "UICaboodle/BrowserView.h"
+#include "SDURLCache/SDURLCache.h"
 
 #include "substrate.h"
 /* }}} */
@@ -204,6 +206,15 @@ void PrintTimes() {
     while (false); \
     [_pool release];
 
+// Hash Functions/Structures {{{
+extern "C" uint32_t hashlittle(const void *key, size_t length, uint32_t initval = 0);
+
+union SplitHash {
+    uint32_t u32;
+    uint16_t u16[2];
+};
+// }}}
+
 static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
 
 void NSLogPoint(const char *fix, const CGPoint &point) {
@@ -267,8 +278,6 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) {
 }
 
 - (id) yieldToSelector:(SEL)selector withObject:(id)object {
-    /*return [self performSelector:selector withObject:object];*/
-
     volatile bool stopped(false);
 
     NSMutableArray *context([NSMutableArray arrayWithObjects:
@@ -757,17 +766,24 @@ class CYString {
             cache_ = reinterpret_cast<CFStringRef>(CFRetain(rhs.cache_));
     }
 
+    void copy(apr_pool_t *pool) {
+        char *temp(reinterpret_cast<char *>(apr_palloc(pool, size_ + 1)));
+        memcpy(temp, data_, size_);
+        temp[size_] = '\0';
+        data_ = temp;
+    }
+
     void set(apr_pool_t *pool, const char *data, size_t size) {
         if (size == 0)
             clear();
         else {
             clear_();
 
-            char *temp(reinterpret_cast<char *>(apr_palloc(pool, size + 1)));
-            memcpy(temp, data, size);
-            temp[size] = '\0';
-            data_ = temp;
+            data_ = const_cast<char *>(data);
             size_ = size;
+
+            if (pool != NULL)
+                copy(pool);
         }
     }
 
@@ -792,6 +808,10 @@ class CYString {
     _finline operator id() {
         return (NSString *) static_cast<CFStringRef>(*this);
     }
+
+    _finline operator const char *() {
+        return reinterpret_cast<const char *>(data_);
+    }
 };
 /* }}} */
 /* C++ NSString Algorithm Adapters {{{ */
@@ -953,6 +973,11 @@ class CYColor {
   private:
     CGColorRef color_;
 
+    static CGColorRef Create_(CGColorSpaceRef space, float red, float green, float blue, float alpha) {
+        CGFloat color[] = {red, green, blue, alpha};
+        return CGColorCreate(space, color);
+    }
+
   public:
     CYColor() :
         color_(NULL)
@@ -960,7 +985,7 @@ class CYColor {
     }
 
     CYColor(CGColorSpaceRef space, float red, float green, float blue, float alpha) :
-        color_(NULL)
+        color_(Create_(space, red, green, blue, alpha))
     {
         Set(space, red, green, blue, alpha);
     }
@@ -976,8 +1001,7 @@ class CYColor {
 
     void Set(CGColorSpaceRef space, float red, float green, float blue, float alpha) {
         Clear();
-        float color[] = {red, green, blue, alpha};
-        color_ = CGColorCreate(space, (CGFloat *) color);
+        color_ = Create_(space, red, green, blue, alpha);
     }
 
     operator CGColorRef() {
@@ -988,9 +1012,6 @@ class CYColor {
 
 /* Random Global Variables {{{ */
 static const int PulseInterval_ = 50000;
-static const int ButtonBarWidth_ = 60;
-static const int ButtonBarHeight_ = 48;
-static const float KeyboardTime_ = 0.3f;
 
 static int Finish_;
 static NSArray *Finishes_;
@@ -1048,7 +1069,7 @@ static _transient NSMutableDictionary *Packages_;
 static _transient NSMutableDictionary *Sections_;
 static _transient NSMutableDictionary *Sources_;
 static bool Changed_;
-static NSDate *now_;
+static time_t now_;
 
 static bool IsWildcat_;
 /* }}} */
@@ -1075,21 +1096,9 @@ NSString *SizeString(double size) {
     return [NSString stringWithFormat:@"%s%.1f %s", (negative ? "-" : ""), size, powers_[power]];
 }
 
-const char *StripVersion_(const char *version) {
+static _finline const char *StripVersion_(const char *version) {
     const char *colon(strchr(version, ':'));
-    if (colon != NULL)
-        version = colon + 1;
-    return version;
-}
-
-// XXX: rename this to involve "Create"
-CFStringRef StripVersion(const char *version) {
-    const char *colon(strchr(version, ':'));
-    if (colon != NULL)
-        version = colon + 1;
-    return CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast<const uint8_t *>(version), strlen(version), kCFStringEncodingUTF8, NO);
-    // XXX: performance
-    return CYStringCreate(version);
+    return colon == NULL ? version : colon + 1;
 }
 
 NSString *LocalizeSection(NSString *section) {
@@ -1173,6 +1182,8 @@ bool isSectionVisible(NSString *section) {
 @class PackageController;
 
 @protocol CydiaDelegate
+- (void) retainNetworkActivityIndicator;
+- (void) releaseNetworkActivityIndicator;
 - (void) setPackageController:(PackageController *)view;
 - (void) clearPackage:(Package *)package;
 - (void) installPackage:(Package *)package;
@@ -1186,12 +1197,13 @@ bool isSectionVisible(NSString *section) {
 - (void) syncData;
 - (void) showSettings;
 - (UIProgressHUD *) addProgressHUD;
-- (BOOL) hudIsShowing;
 - (void) removeProgressHUD:(UIProgressHUD *)hud;
 - (CYViewController *) pageForPackage:(NSString *)name;
 - (PackageController *) packageController;
 - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
 @end
+
+static id<CydiaDelegate> CydiaApp;
 /* }}} */
 
 /* Status Delegation {{{ */
@@ -1343,6 +1355,8 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
     int cydiafd_;
     int statusfd_;
     FILE *input_;
+
+    std::map<const char *, _H<NSString> > sections_;
 }
 
 + (Database *) sharedInstance;
@@ -1372,12 +1386,13 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 - (bool) upgrade;
 - (void) update;
 
-- (void) setVisible;
-
 - (void) updateWithStatus:(Status &)status;
 
 - (void) setDelegate:(id)delegate;
 - (Source *) getSource:(pkgCache::PkgFileIterator)file;
+
+- (NSString *) mappedSectionForPointer:(const char *)pointer;
+
 @end
 /* }}} */
 /* Delegate Helpers {{{ */
@@ -1416,6 +1431,102 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 @end
 /* }}} */
 
+// Cytore Definitions {{{
+struct PackageValue :
+    Cytore::Block
+{
+    Cytore::Offset<PackageValue> next_;
+
+    uint32_t index_ : 23;
+    uint32_t subscribed_ : 1;
+    uint32_t : 8;
+
+    int32_t first_;
+    int32_t last_;
+
+    uint16_t vhash_;
+    uint16_t nhash_;
+
+    char version_[8];
+    char name_[];
+};
+
+struct MetaValue :
+    Cytore::Block
+{
+    uint32_t active_;
+    Cytore::Offset<PackageValue> packages_[1 << 16];
+};
+
+static Cytore::File<MetaValue> MetaFile_;
+// }}}
+// Cytore Helper Functions {{{
+static PackageValue *PackageFind(const char *name, size_t length) {
+    SplitHash nhash = { hashlittle(name, length) };
+
+    PackageValue *metadata;
+
+    Cytore::Offset<PackageValue> *offset(&MetaFile_->packages_[nhash.u16[0]]);
+    offset: if (offset->IsNull()) {
+        *offset = MetaFile_.New<PackageValue>(length + 1);
+        metadata = &MetaFile_.Get(*offset);
+
+        memcpy(metadata->name_, name, length + 1);
+        metadata->nhash_ = nhash.u16[1];
+    } else {
+        metadata = &MetaFile_.Get(*offset);
+
+        if (metadata->nhash_ != nhash.u16[1] || strncmp(metadata->name_, name, length + 1) != 0) {
+            offset = &metadata->next_;
+            goto offset;
+        }
+    }
+
+    return metadata;
+}
+
+static void PackageImport(const void *key, const void *value, void *context) {
+    char buffer[1024];
+    if (!CFStringGetCString((CFStringRef) key, buffer, sizeof(buffer), kCFStringEncodingUTF8)) {
+        NSLog(@"failed to import package %@", key);
+        return;
+    }
+
+    PackageValue *metadata(PackageFind(buffer, strlen(buffer)));
+    NSDictionary *package((NSDictionary *) value);
+
+    if (NSNumber *subscribed = [package objectForKey:@"IsSubscribed"])
+        if ([subscribed boolValue] && !metadata->subscribed_)
+            metadata->subscribed_ = true;
+
+    if (NSDate *date = [package objectForKey:@"FirstSeen"]) {
+        time_t time([date timeIntervalSince1970]);
+        if (metadata->first_ > time || metadata->first_ == 0)
+            metadata->first_ = time;
+    }
+
+    NSDate *date([package objectForKey:@"LastSeen"]);
+    NSString *version([package objectForKey:@"LastVersion"]);
+
+    if (date != nil && version != nil) {
+        time_t time([date timeIntervalSince1970]);
+        if (metadata->last_ < time || metadata->last_ == 0)
+            if (CFStringGetCString((CFStringRef) version, buffer, sizeof(buffer), kCFStringEncodingUTF8)) {
+                size_t length(strlen(buffer));
+                uint16_t vhash(hashlittle(buffer, length));
+
+                size_t capped(std::min<size_t>(8, length));
+                char *latest(buffer + length - capped);
+
+                strncpy(metadata->version_, latest, sizeof(metadata->version_));
+                metadata->vhash_ = vhash;
+
+                metadata->last_ = time;
+            }
+    }
+}
+// }}}
+
 /* Source Class {{{ */
 @interface Source : NSObject {
     CYString depiction_;
@@ -1703,53 +1814,51 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 @end
 /* }}} */
 /* Package Class {{{ */
+struct ParsedPackage {
+    CYString tagline_;
+
+    CYString icon_;
+
+    CYString depiction_;
+    CYString homepage_;
+
+    CYString sponsor_;
+    CYString author_;
+
+    CYString bugs_;
+    CYString support_;
+};
+
 @interface Package : NSObject {
-    unsigned era_;
+    uint32_t era_ : 26;
+    uint32_t role_ : 3;
+    uint32_t essential_ : 1;
+    uint32_t obsolete_ : 1;
+    uint32_t ignored_ : 1;
+
     apr_pool_t *pool_;
 
+    _transient Database *database_;
+
     pkgCache::VerIterator version_;
     pkgCache::PkgIterator iterator_;
-    _transient Database *database_;
     pkgCache::VerFileIterator file_;
 
-    Source *source_;
-    bool cached_;
-    bool parsed_;
-
-    CYString section_;
-    _transient NSString *section$_;
-    bool essential_;
-    bool required_;
-    bool visible_;
-    bool obsolete_;
-
-    NSString *latest_;
-    CYString installed_;
-
     CYString id_;
     CYString name_;
-    CYString tagline_;
-    CYString icon_;
-    CYString depiction_;
-    CYString homepage_;
 
-    CYString sponsor_;
-    Address *sponsor$_;
+    CYString latest_;
+    CYString installed_;
 
-    CYString author_;
-    Address *author$_;
+    const char *section_;
+    _transient NSString *section$_;
 
-    CYString bugs_;
-    CYString support_;
-    NSMutableArray *tags_;
-    NSString *role_;
+    Source *source_;
 
-    NSArray *relationships_;
+    PackageValue *metadata_;
+    ParsedPackage *parsed_;
 
-    NSMutableDictionary *metadata_;
-    _transient NSDate *firstSeen_;
-    _transient NSDate *lastSeen_;
-    bool subscribed_;
+    NSMutableArray *tags_;
 }
 
 - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
@@ -1772,9 +1881,12 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 - (NSString *) shortDescription;
 - (unichar) index;
 
-- (NSMutableDictionary *) metadata;
-- (NSDate *) seen;
-- (BOOL) subscribed;
+- (PackageValue *) metadata;
+- (time_t) seen;
+
+- (bool) subscribed;
+- (bool) setSubscribed:(bool)subscribed;
+
 - (BOOL) ignored;
 
 - (NSString *) latest;
@@ -1794,8 +1906,6 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 - (BOOL) hasMode;
 - (NSString *) mode;
 
-- (void) setVisible;
-
 - (NSString *) id;
 - (NSString *) name;
 - (UIImage *) icon;
@@ -1806,12 +1916,10 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 - (NSString *) support;
 
 - (NSArray *) files;
-- (NSArray *) relationships;
 - (NSArray *) warnings;
 - (NSArray *) applications;
 
 - (Source *) source;
-- (NSString *) role;
 
 - (BOOL) matches:(NSString *)text;
 
@@ -1821,18 +1929,18 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
 - (NSArray *) purposes;
 - (bool) isCommercial;
 
+- (void) setIndex:(size_t)index;
+
 - (CYString &) cyname;
 
 - (uint32_t) compareBySection:(NSArray *)sections;
 
-- (uint32_t) compareForChanges;
-
 - (void) install;
 - (void) remove;
 
 - (bool) isUnfilteredAndSearchedForBy:(NSString *)search;
 - (bool) isUnfilteredAndSelectedForBy:(NSString *)search;
-- (bool) isInstalledAndVisible:(NSNumber *)number;
+- (bool) isInstalledAndUnfiltered:(NSNumber *)number;
 - (bool) isVisibleInSection:(NSString *)section;
 - (bool) isVisibleInSource:(Source *)source;
 
@@ -1857,7 +1965,7 @@ uint32_t PackageChangesRadix(Package *self, void *) {
         value.bits.ignored = [self ignored] ? 0 : 1;
         value.bits.upgradable = 1;
     } else {
-        value.bits.timestamp = static_cast<uint32_t>([[self seen] timeIntervalSince1970]) >> 2;
+        value.bits.timestamp = [self seen] >> 2;
         value.bits.ignored = 0;
         value.bits.upgradable = 0;
     }
@@ -1865,9 +1973,6 @@ uint32_t PackageChangesRadix(Package *self, void *) {
     return _not(uint32_t) - value.key;
 }
 
-_finline static void Stifle(uint8_t &value) {
-}
-
 uint32_t PackagePrefixRadix(Package *self, void *context) {
     size_t offset(reinterpret_cast<size_t>(context));
     CYString &name([self cyname]);
@@ -1890,8 +1995,6 @@ uint32_t PackagePrefixRadix(Package *self, void *context) {
 
     uint8_t data[4];
 
-    // 0.607997
-
     if (offset == 0 && zeros != 0) {
         memset(data, '0', zeros);
         memcpy(data + zeros, text, 4 - zeros);
@@ -1975,26 +2078,12 @@ struct PackageNameOrdering :
 }
 
 - (void) dealloc {
+    if (parsed_ != NULL)
+        delete parsed_;
     if (source_ != nil)
         [source_ release];
-
-    if (latest_ != nil)
-        [latest_ release];
-
-    if (sponsor$_ != nil)
-        [sponsor$_ release];
-    if (author$_ != nil)
-        [author$_ release];
     if (tags_ != nil)
         [tags_ release];
-    if (role_ != nil)
-        [role_ release];
-
-    if (relationships_ != nil)
-        [relationships_ release];
-    if (metadata_ != nil)
-        [metadata_ release];
-
     [super dealloc];
 }
 
@@ -2022,12 +2111,15 @@ struct PackageNameOrdering :
 }
 
 - (void) parse {
-    if (parsed_)
+    if (parsed_ != NULL)
         return;
-    parsed_ = true;
-    if (file_.end())
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
         return;
 
+    ParsedPackage *parsed(new ParsedPackage);
+    parsed_ = parsed;
+
     _profile(Package$parse)
         pkgRecords::Parser *parser;
 
@@ -2042,14 +2134,14 @@ struct PackageNameOrdering :
                 const char *name_;
                 CYString *value_;
             } names[] = {
-                {"icon", &icon_},
-                {"depiction", &depiction_},
-                {"homepage", &homepage_},
+                {"icon", &parsed->icon_},
+                {"depiction", &parsed->depiction_},
+                {"homepage", &parsed->homepage_},
                 {"website", &website},
-                {"bugs", &bugs_},
-                {"support", &support_},
-                {"sponsor", &sponsor_},
-                {"author", &author_},
+                {"bugs", &parsed->bugs_},
+                {"support", &parsed->support_},
+                {"sponsor", &parsed->sponsor_},
+                {"author", &parsed->author_},
             };
 
             for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
@@ -2072,47 +2164,33 @@ struct PackageNameOrdering :
                     stop = end;
                 while (stop != start && stop[-1] == '\r')
                     --stop;
-                tagline_.set(pool_, start, stop - start);
+                parsed->tagline_.set(pool_, start, stop - start);
             }
         _end
 
         _profile(Package$parse$Retain)
-            if (homepage_.empty())
-                homepage_ = website;
-            if (homepage_ == depiction_)
-                homepage_.clear();
+            if (parsed->homepage_.empty())
+                parsed->homepage_ = website;
+            if (parsed->homepage_ == parsed->depiction_)
+                parsed->homepage_.clear();
         _end
     _end
-}
-
-- (void) setVisible {
-    visible_ = required_ && [self unfiltered];
-}
+} }
 
 - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
     if ((self = [super init]) != nil) {
     _profile(Package$initWithVersion)
-        era_ = [database era];
         pool_ = pool;
 
-        version_ = version;
-
-        _profile(Package$initWithVersion$ParentPkg)
-            iterator_ = version.ParentPkg();
-        _end
-
         database_ = database;
+        era_ = [database era];
 
-        _profile(Package$initWithVersion$Latest)
-            latest_ = (NSString *) StripVersion(version_.VerStr());
-        _end
+        version_ = version;
 
-        pkgCache::VerIterator current;
-        _profile(Package$initWithVersion$Versions)
-            current = iterator_.CurrentVer();
-            if (!current.end())
-                installed_.set(pool_, StripVersion_(current.VerStr()));
+        pkgCache::PkgIterator iterator(version.ParentPkg());
+        iterator_ = iterator;
 
+        _profile(Package$initWithVersion$Version)
             if (!version_.end())
                 file_ = version_.FileList();
             else {
@@ -2121,106 +2199,89 @@ struct PackageNameOrdering :
             }
         _end
 
-        _profile(Package$initWithVersion$Name)
-            id_.set(pool_, iterator_.Name());
-            name_.set(pool, iterator_.Display());
-        _end
-
-        _profile(Package$initWithVersion$lowercaseString)
-            char *data(id_.data());
-            for (size_t i(0), e(id_.size()); i != e; ++i)
-                // XXX: do not use tolower() as this is not locale-specific? :(
-                data[i] |= 0x20;
-        _end
+        _profile(Package$initWithVersion$Cache)
+            name_.set(NULL, iterator.Display());
 
-        if (!file_.end()) {
-            _profile(Package$initWithVersion$Source)
-                source_ = [database_ getSource:file_.File()];
-                if (source_ != nil)
-                    [source_ retain];
-                cached_ = true;
-            _end
-        }
+            latest_.set(NULL, StripVersion_(version_.VerStr()));
 
-        required_ = true;
+            pkgCache::VerIterator current(iterator.CurrentVer());
+            if (!current.end())
+                installed_.set(NULL, StripVersion_(current.VerStr()));
+        _end
 
         _profile(Package$initWithVersion$Tags)
-            pkgCache::TagIterator tag(iterator_.TagList());
+            pkgCache::TagIterator tag(iterator.TagList());
             if (!tag.end()) {
                 tags_ = [[NSMutableArray alloc] initWithCapacity:8];
                 do {
                     const char *name(tag.Name());
                     [tags_ addObject:[(NSString *)CYStringCreate(name) autorelease]];
-                    if (role_ == nil && strncmp(name, "role::", 6) == 0 /*&& strcmp(name, "role::leaper") != 0*/)
-                        role_ = (NSString *) CYStringCreate(name + 6);
-                    if (required_ && strncmp(name, "require::", 9) == 0 && (
-                        true
-                    ))
-                        required_ = false;
+
+                    if (role_ == 0 && strncmp(name, "role::", 6) == 0 /*&& strcmp(name, "role::leaper") != 0*/) {
+                        if (strcmp(name + 6, "enduser") == 0)
+                            role_ = 1;
+                        else if (strcmp(name + 6, "hacker") == 0)
+                            role_ = 2;
+                        else if (strcmp(name + 6, "developer") == 0)
+                            role_ = 3;
+                        else if (strcmp(name + 6, "cydia") == 0)
+                            role_ = 7;
+                        else
+                            role_ = 4;
+                    }
+
+                    if (strncmp(name, "cydia::", 7) == 0) {
+                        if (strcmp(name + 7, "essential") == 0)
+                            essential_ = true;
+                        else if (strcmp(name + 7, "obsolete") == 0)
+                            obsolete_ = true;
+                    }
+
                     ++tag;
                 } while (!tag.end());
             }
         _end
 
-        bool changed(false);
-
         _profile(Package$initWithVersion$Metadata)
-            metadata_ = [Packages_ objectForKey:id_];
-
-            if (metadata_ == nil) {
-                firstSeen_ = now_;
+            const char *mixed(iterator.Name());
+            size_t size(strlen(mixed));
+            char lower[size + 1];
 
-                metadata_ = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
-                    firstSeen_, @"FirstSeen",
-                    latest_, @"LastVersion",
-                nil] mutableCopy];
+            for (size_t i(0); i != size; ++i)
+                lower[i] = mixed[i] | 0x20;
+            lower[size] = '\0';
 
-                changed = true;
-            } else {
-                firstSeen_ = [metadata_ objectForKey:@"FirstSeen"];
-                lastSeen_ = [metadata_ objectForKey:@"LastSeen"];
+            PackageValue *metadata(PackageFind(lower, size));
+            metadata_ = metadata;
 
-                if (NSNumber *subscribed = [metadata_ objectForKey:@"IsSubscribed"])
-                    subscribed_ = [subscribed boolValue];
+            id_.set(NULL, metadata->name_, size);
 
-                NSString *version([metadata_ objectForKey:@"LastVersion"]);
+            const char *latest(version_.VerStr());
+            size_t length(strlen(latest));
 
-                if (firstSeen_ == nil) {
-                    firstSeen_ = lastSeen_ == nil ? now_ : lastSeen_;
-                    [metadata_ setObject:firstSeen_ forKey:@"FirstSeen"];
-                    changed = true;
-                }
+            uint16_t vhash(hashlittle(latest, length));
 
-                if (version == nil) {
-                    [metadata_ setObject:latest_ forKey:@"LastVersion"];
-                    changed = true;
-                } else if (![version isEqualToString:latest_]) {
-                    [metadata_ setObject:latest_ forKey:@"LastVersion"];
-                    lastSeen_ = now_;
-                    [metadata_ setObject:lastSeen_ forKey:@"LastSeen"];
-                    changed = true;
-                }
-            }
+            size_t capped(std::min<size_t>(8, length));
+            latest = latest + length - capped;
 
-            metadata_ = [metadata_ retain];
+            if (metadata->first_ == 0)
+                metadata->first_ = now_;
 
-            if (changed) {
-                [Packages_ setObject:metadata_ forKey:id_];
-                Changed_ = true;
-            }
+            if (metadata->vhash_ != vhash || strncmp(metadata->version_, latest, sizeof(metadata->version_)) != 0) {
+                strncpy(metadata->version_, latest, sizeof(metadata->version_));
+                metadata->vhash_ = vhash;
+                metadata->last_ = now_;
+            } else if (metadata->last_ == 0)
+                metadata->last_ = metadata->first_;
         _end
 
         _profile(Package$initWithVersion$Section)
-            section_.set(pool_, iterator_.Section());
-        _end
-
-        _profile(Package$initWithVersion$hasTag)
-            obsolete_ = [self hasTag:@"cydia::obsolete"];
-            essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"];
+            section_ = iterator.Section();
         _end
 
-        _profile(Package$initWithVersion$setVisible)
-            [self setVisible];
+        _profile(Package$initWithVersion$Flags)
+            essential_ |= ((iterator->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES);
+            ignored_ = iterator->SelectedState == pkgCache::State::Hold;
         _end
     _end } return self;
 }
@@ -2235,12 +2296,26 @@ struct PackageNameOrdering :
     if (version.end())
         return nil;
 
-    return [[[Package alloc]
-        initWithVersion:version
-        withZone:zone
-        inPool:pool
-        database:database
-    ] autorelease];
+    Package *package;
+
+    _profile(Package$packageWithIterator$Allocate)
+        package = [Package allocWithZone:zone];
+    _end
+
+    _profile(Package$packageWithIterator$Initialize)
+        package = [package
+            initWithVersion:version
+            withZone:zone
+            inPool:pool
+            database:database
+        ];
+    _end
+
+    _profile(Package$packageWithIterator$Autorelease)
+        package = [package autorelease];
+    _end
+
+    return package;
 }
 
 - (pkgCache::PkgIterator) iterator {
@@ -2249,20 +2324,12 @@ struct PackageNameOrdering :
 
 - (NSString *) section {
     if (section$_ == nil) {
-        if (section_.empty())
+        if (section_ == NULL)
             return nil;
 
-        std::replace(section_.data(), section_.data() + section_.size(), '_', ' ');
-        NSString *name(section_);
-
-      lookup:
-        if (NSDictionary *value = [SectionMap_ objectForKey:name])
-            if (NSString *rename = [value objectForKey:@"Rename"]) {
-                name = rename;
-                goto lookup;
-            }
-
-        section$_ = name;
+        _profile(Package$section$mappedSectionForPointer)
+            section$_ = [database_ mappedSectionForPointer:section_];
+        _end
     } return section$_;
 }
 
@@ -2295,16 +2362,22 @@ struct PackageNameOrdering :
 }
 
 - (Address *) maintainer {
-    if (file_.end())
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
         return nil;
+
     pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
     const std::string &maintainer(parser->Maintainer());
     return maintainer.empty() ? nil : [Address addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
-}
+} }
 
 - (size_t) size {
-    return version_.end() ? 0 : version_->InstalledSize;
-}
+@synchronized (database_) {
+    if ([database_ era] != era_ || version_.end())
+        return 0;
+
+    return version_->InstalledSize;
+} }
 
 - (NSString *) longDescription {
 @synchronized (database_) {
@@ -2329,7 +2402,7 @@ struct PackageNameOrdering :
 } }
 
 - (NSString *) shortDescription {
-    return tagline_;
+    return parsed_ == NULL ? nil : static_cast<NSString *>(parsed_->tagline_);
 }
 
 - (unichar) index {
@@ -2344,26 +2417,29 @@ struct PackageNameOrdering :
     _end
 }
 
-- (NSMutableDictionary *) metadata {
+- (PackageValue *) metadata {
     return metadata_;
 }
 
-- (NSDate *) seen {
-    if (subscribed_ && lastSeen_ != nil)
-        return lastSeen_;
-    return firstSeen_;
+- (time_t) seen {
+    PackageValue *metadata([self metadata]);
+    return metadata->subscribed_ ? metadata->last_ : metadata->first_;
 }
 
-- (BOOL) subscribed {
-    return subscribed_;
+- (bool) subscribed {
+    return [self metadata]->subscribed_;
 }
 
-- (BOOL) ignored {
-    NSDictionary *metadata([self metadata]);
-    if (NSNumber *ignored = [metadata objectForKey:@"IsIgnored"])
-        return [ignored boolValue];
-    else
+- (bool) setSubscribed:(bool)subscribed {
+    PackageValue *metadata([self metadata]);
+    if (metadata->subscribed_ == subscribed)
         return false;
+    metadata->subscribed_ = subscribed;
+    return true;
+}
+
+- (BOOL) ignored {
+    return ignored_;
 }
 
 - (NSString *) latest {
@@ -2386,9 +2462,9 @@ struct PackageNameOrdering :
     _profile(Package$upgradableAndEssential)
         pkgCache::VerIterator current(iterator_.CurrentVer());
         if (current.end())
-            return essential && essential_ && visible_;
+            return essential && essential_;
         else
-            return !version_.end() && version_ != current;// && (!essential || ![database_ cache][iterator_].Keep());
+            return !version_.end() && version_ != current;
     _end
 }
 
@@ -2402,22 +2478,29 @@ struct PackageNameOrdering :
 
 - (BOOL) unfiltered {
     _profile(Package$unfiltered$obsolete)
-        if (obsolete_)
+        if (_unlikely(obsolete_))
             return false;
     _end
 
     _profile(Package$unfiltered$hasSupportingRole)
-        if (![self hasSupportingRole])
+        if (_unlikely(![self hasSupportingRole]))
             return false;
     _end
 
+    return true;
+}
+
+- (BOOL) visible {
+    if (![self unfiltered])
+        return false;
+
     NSString *section;
 
-    _profile(Package$unfiltered$section)
+    _profile(Package$visible$section)
         section = [self section];
     _end
 
-    _profile(Package$unfiltered$isSectionVisible)
+    _profile(Package$visible$isSectionVisible)
         if (section != nil && !isSectionVisible(section))
             return false;
     _end
@@ -2425,10 +2508,6 @@ struct PackageNameOrdering :
     return true;
 }
 
-- (BOOL) visible {
-    return visible_;
-}
-
 - (BOOL) half {
     unsigned char current(iterator_->CurrentState);
     return current == pkgCache::State::HalfConfigured || current == pkgCache::State::HalfInstalled;
@@ -2493,13 +2572,14 @@ struct PackageNameOrdering :
     NSString *section = [self simpleSection];
 
     UIImage *icon(nil);
-    if (!icon_.empty())
-        if ([static_cast<id>(icon_) hasPrefix:@"file:///"])
-            // XXX: correct escaping
-            icon = [UIImage imageAtPath:[static_cast<id>(icon_) substringFromIndex:7]];
+    if (parsed_ != NULL)
+        if (NSString *href = parsed_->icon_)
+            if ([href hasPrefix:@"file:///"])
+                // XXX: correct escaping
+                icon = [UIImage imageAtPath:[href substringFromIndex:7]];
     if (icon == nil) if (section != nil)
         icon = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]];
-    if (icon == nil) if (source_ != nil) if (NSString *dicon = [source_ defaultIcon])
+    if (icon == nil) if (Source *source = [self source]) if (NSString *dicon = [source defaultIcon])
         if ([dicon hasPrefix:@"file:///"])
             // XXX: correct escaping
             icon = [UIImage imageAtPath:[dicon substringFromIndex:7]];
@@ -2509,31 +2589,23 @@ struct PackageNameOrdering :
 }
 
 - (NSString *) homepage {
-    return homepage_;
+    return parsed_ == NULL ? nil : static_cast<NSString *>(parsed_->homepage_);
 }
 
 - (NSString *) depiction {
-    return !depiction_.empty() ? depiction_ : [[self source] depictionForPackage:id_];
+    return parsed_ != NULL && !parsed_->depiction_.empty() ? parsed_->depiction_ : [[self source] depictionForPackage:id_];
 }
 
 - (Address *) sponsor {
-    if (sponsor$_ == nil) {
-        if (sponsor_.empty())
-            return nil;
-        sponsor$_ = [[Address addressWithString:sponsor_] retain];
-    } return sponsor$_;
+    return parsed_ == NULL || parsed_->sponsor_.empty() ? nil : [Address addressWithString:parsed_->sponsor_];
 }
 
 - (Address *) author {
-    if (author$_ == nil) {
-        if (author_.empty())
-            return nil;
-        author$_ = [[Address addressWithString:author_] retain];
-    } return author$_;
+    return parsed_ == NULL || parsed_->author_.empty() ? nil : [Address addressWithString:parsed_->author_];
 }
 
 - (NSString *) support {
-    return !bugs_.empty() ? bugs_ : [[self source] supportForPackage:id_];
+    return parsed_ != NULL && !parsed_->bugs_.empty() ? parsed_->bugs_ : [[self source] supportForPackage:id_];
 }
 
 - (NSArray *) files {
@@ -2552,10 +2624,6 @@ struct PackageNameOrdering :
     return files;
 }
 
-- (NSArray *) relationships {
-    return relationships_;
-}
-
 - (NSArray *) warnings {
     NSMutableArray *warnings([NSMutableArray arrayWithCapacity:4]);
     const char *name(iterator_.Name());
@@ -2641,25 +2709,16 @@ struct PackageNameOrdering :
 }
 
 - (Source *) source {
-    if (!cached_) {
+    if (source_ == nil) {
         @synchronized (database_) {
             if ([database_ era] != era_ || file_.end())
-                source_ = nil;
-            else {
-                source_ = [database_ getSource:file_.File()];
-                if (source_ != nil)
-                    [source_ retain];
-            }
-
-            cached_ = true;
+                source_ = (Source *) [NSNull null];
+            else
+                source_ = [([database_ getSource:file_.File()] ?: (Source *) [NSNull null]) retain];
         }
     }
 
-    return source_;
-}
-
-- (NSString *) role {
-    return role_;
+    return source_ == (Source *) [NSNull null] ? nil : source_;
 }
 
 - (BOOL) matches:(NSString *)text {
@@ -2684,17 +2743,17 @@ struct PackageNameOrdering :
 }
 
 - (bool) hasSupportingRole {
-    if (role_ == nil)
+    if (role_ == 0)
         return true;
-    if ([role_ isEqualToString:@"enduser"])
+    if (role_ == 1)
         return true;
     if ([Role_ isEqualToString:@"User"])
         return false;
-    if ([role_ isEqualToString:@"hacker"])
+    if (role_ == 2)
         return true;
     if ([Role_ isEqualToString:@"Hacker"])
         return false;
-    if ([role_ isEqualToString:@"developer"])
+    if (role_ == 3)
         return true;
     if ([Role_ isEqualToString:@"Developer"])
         return false;
@@ -2724,6 +2783,11 @@ struct PackageNameOrdering :
     return [self hasTag:@"cydia::commercial"];
 }
 
+- (void) setIndex:(size_t)index {
+    if (metadata_->index_ != index)
+        metadata_->index_ = index;
+}
+
 - (CYString &) cyname {
     return name_.empty() ? id_ : name_;
 }
@@ -2738,57 +2802,42 @@ struct PackageNameOrdering :
     return _not(uint32_t);
 }
 
-- (uint32_t) compareForChanges {
-    union {
-        uint32_t key;
-
-        struct {
-            uint32_t timestamp : 30;
-            uint32_t ignored : 1;
-            uint32_t upgradable : 1;
-        } bits;
-    } value;
-
-    bool upgradable([self upgradableAndEssential:YES]);
-    value.bits.upgradable = upgradable ? 1 : 0;
-
-    if (upgradable) {
-        value.bits.timestamp = 0;
-        value.bits.ignored = [self ignored] ? 0 : 1;
-        value.bits.upgradable = 1;
-    } else {
-        value.bits.timestamp = static_cast<uint32_t>([[self seen] timeIntervalSince1970]) >> 2;
-        value.bits.ignored = 0;
-        value.bits.upgradable = 0;
-    }
-
-    return _not(uint32_t) - value.key;
-}
-
 - (void) clear {
+@synchronized (database_) {
     pkgProblemResolver *resolver = [database_ resolver];
     resolver->Clear(iterator_);
-    resolver->Protect(iterator_);
-}
+
+    pkgCacheFile &cache([database_ cache]);
+    cache->SetReInstall(iterator_, false);
+    cache->MarkKeep(iterator_, false);
+} }
 
 - (void) install {
+@synchronized (database_) {
     pkgProblemResolver *resolver = [database_ resolver];
     resolver->Clear(iterator_);
     resolver->Protect(iterator_);
+
     pkgCacheFile &cache([database_ cache]);
+    cache->SetReInstall(iterator_, false);
     cache->MarkInstall(iterator_, false);
+
     pkgDepCache::StateCache &state((*cache)[iterator_]);
     if (!state.Install())
         cache->SetReInstall(iterator_, true);
-}
+} }
 
 - (void) remove {
+@synchronized (database_) {
     pkgProblemResolver *resolver = [database_ resolver];
     resolver->Clear(iterator_);
-    resolver->Protect(iterator_);
     resolver->Remove(iterator_);
-    [database_ cache]->MarkDelete(iterator_, true);
-}
+    resolver->Protect(iterator_);
+
+    pkgCacheFile &cache([database_ cache]);
+    cache->SetReInstall(iterator_, false);
+    cache->MarkDelete(iterator_, true);
+} }
 
 - (bool) isUnfilteredAndSearchedForBy:(NSString *)search {
     _profile(Package$isUnfilteredAndSearchedForBy)
@@ -2825,19 +2874,18 @@ struct PackageNameOrdering :
     _end
 }
 
-- (bool) isInstalledAndVisible:(NSNumber *)number {
-    return ((![number boolValue] && ![role_ isEqualToString:@"cydia"]) || [self visible]) && ![self uninstalled];
+- (bool) isInstalledAndUnfiltered:(NSNumber *)number {
+    return ![self uninstalled] && (![number boolValue] && role_ != 7 || [self unfiltered]);
 }
 
 - (bool) isVisibleInSection:(NSString *)name {
-    NSString *section = [self section];
+    NSString *section([self section]);
 
-    return
-        [self visible] && (
-            name == nil ||
-            section == nil && [name length] == 0 ||
-            [name isEqualToString:section]
-        );
+    return (
+        name == nil ||
+        section == nil && [name length] == 0 ||
+        [name isEqualToString:section]
+    ) && [self visible];
 }
 
 - (bool) isVisibleInSource:(Source *)source {
@@ -2966,6 +3014,7 @@ struct PackageNameOrdering :
 /* }}} */
 
 static NSString *Colon_;
+static NSString *Elision_;
 static NSString *Error_;
 static NSString *Warning_;
 
@@ -2983,12 +3032,17 @@ static NSString *Warning_;
     return era_;
 }
 
+- (void) releasePackages {
+    CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast<CFArrayApplierFunction>(&CFRelease), NULL);
+    CFArrayRemoveAllValues(packages_);
+}
+
 - (void) dealloc {
     // XXX: actually implement this thing
     _assert(false);
-    NSRecycleZone(zone_);
-    // XXX: malloc_destroy_zone(zone_);
+    [self releasePackages];
     apr_pool_destroy(pool_);
+    NSRecycleZone(zone_);
     [super dealloc];
 }
 
@@ -3096,7 +3150,13 @@ static NSString *Warning_;
         zone_ = NSCreateZone(1024 * 1024, 256 * 1024, NO);
         apr_pool_create(&pool_, NULL);
 
-        packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
+        size_t capacity(MetaFile_->active_);
+        if (capacity == 0)
+            capacity = 16384;
+        else
+            capacity += 1024;
+
+        packages_ = CFArrayCreateMutable(kCFAllocatorDefault, capacity, NULL);
 
         int fds[2];
 
@@ -3276,9 +3336,7 @@ static NSString *Warning_;
 @synchronized (self) {
     ++era_;
 
-    CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast<CFArrayApplierFunction>(&CFRelease), NULL);
-    CFArrayRemoveAllValues(packages_);
-
+    [self releasePackages];
     sources_.clear();
 
     _error->Discard();
@@ -3297,15 +3355,12 @@ static NSString *Warning_;
     delete policy_;
     policy_ = NULL;
 
-    if (now_ != nil) {
-        [now_ release];
-        now_ = nil;
-    }
-
     cache_.Close();
 
     apr_pool_clear(pool_);
+
     NSRecycleZone(zone_);
+    zone_ = NSCreateZone(1024 * 1024, 256 * 1024, NO);
 
     int chk(creat("/tmp/cydia.chk", 0644));
     if (chk != -1)
@@ -3338,7 +3393,7 @@ static NSString *Warning_;
 
     unlink("/tmp/cydia.chk");
 
-    now_ = [[NSDate date] retain];
+    now_ = [[NSDate date] timeIntervalSince1970];
 
     policy_ = new pkgDepCache::Policy();
     records_ = new pkgRecords(cache_);
@@ -3424,12 +3479,35 @@ static NSString *Warning_;
         //[packages_ sortUsingFunction:reinterpret_cast<NSComparisonResult (*)(id, id, void *)>(&PackageNameCompare) context:NULL];
 
         _trace();
-    }
-} } CYPoolEnd() _trace(); }
 
-- (void) configure {
+        size_t count(CFArrayGetCount(packages_));
+        MetaFile_->active_ = count;
+
+        for (size_t index(0); index != count; ++index)
+            [(Package *) CFArrayGetValueAtIndex(packages_, index) setIndex:index];
+
+        _trace();
+    }
+} } CYPoolEnd() _trace(); }
+
+- (void) clear {
+@synchronized (self) {
+    delete resolver_;
+    resolver_ = new pkgProblemResolver(cache_);
+
+    for (pkgCache::PkgIterator iterator(cache_->PkgBegin()); !iterator.end(); ++iterator) {
+        if (!cache_[iterator].Keep()) {
+            cache_->MarkKeep(iterator, false);
+            cache_->SetReInstall(iterator, false);
+        }
+    }
+} }
+
+- (void) configure {
     NSString *dpkg = [NSString stringWithFormat:@"dpkg --configure -a --status-fd %u", statusfd_];
+    _trace();
     system([dpkg UTF8String]);
+    _trace();
 }
 
 - (bool) clean {
@@ -3503,6 +3581,8 @@ static NSString *Warning_;
         return;
     }
 
+    [CydiaApp retainNetworkActivityIndicator];
+
     bool failed = false;
     for (pkgAcquire::ItemIterator item = fetcher_->ItemsBegin(); item != fetcher_->ItemsEnd(); item++) {
         if ((*item)->Status == pkgAcquire::Item::StatDone && (*item)->Complete)
@@ -3524,6 +3604,8 @@ static NSString *Warning_;
         ];
     }
 
+    [CydiaApp releaseNetworkActivityIndicator];
+
     if (failed) {
         _trace();
         return;
@@ -3570,11 +3652,6 @@ static NSString *Warning_;
     [self updateWithStatus:status_];
 }
 
-- (void) setVisible {
-    for (Package *package in [self packages])
-        [package setVisible];
-}
-
 - (void) updateWithStatus:(Status &)status {
     _transient NSObject<ProgressDelegate> *delegate(status.getDelegate());
     NSString *title(UCLocalize("REFRESHING_DATA"));
@@ -3607,6 +3684,37 @@ static NSString *Warning_;
     return i == sources_.end() ? nil : i->second;
 }
 
+- (NSString *) mappedSectionForPointer:(const char *)section {
+    _H<NSString> *mapped;
+
+    _profile(Database$mappedSectionForPointer$Cache)
+        mapped = &sections_[section];
+    _end
+
+    if (*mapped == NULL) {
+        size_t length(strlen(section));
+        char spaced[length + 1];
+
+        _profile(Database$mappedSectionForPointer$Replace)
+            for (size_t index(0); index != length; ++index)
+                spaced[index] = section[index] == '_' ? ' ' : section[index];
+            spaced[length] = '\0';
+        _end
+
+        NSString *string;
+
+        _profile(Database$mappedSectionForPointer$stringWithUTF8String)
+            string = [NSString stringWithUTF8String:spaced];
+        _end
+
+        _profile(Database$mappedSectionForPointer$Map)
+            string = [SectionMap_ objectForKey:string] ?: string;
+        _end
+
+        *mapped = string;
+    } return *mapped;
+}
+
 @end
 /* }}} */
 
@@ -3736,7 +3844,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (NSArray *) getInstalledPackages {
     NSArray *packages([[Database sharedInstance] packages]);
-    NSMutableArray *installed([NSMutableArray arrayWithCapacity:[packages count]]);
+    NSMutableArray *installed([NSMutableArray arrayWithCapacity:1024]);
     for (Package *package in packages)
         if ([package installed] != nil)
             [installed addObject:package];
@@ -3863,6 +3971,71 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @end
 /* }}} */
 
+/* @ Loading... Indicator {{{ */
+@interface CYLoadingIndicator : UIView {
+    UIActivityIndicatorView *spinner_;
+    UILabel *label_;
+    UIView *container_;
+}
+
+@property (readonly, nonatomic) UILabel *label;
+@property (readonly, nonatomic) UIActivityIndicatorView *activityIndicatorView;
+
+@end
+
+@implementation CYLoadingIndicator
+
+- (id)initWithFrame:(CGRect)frame {
+    if ((self = [super initWithFrame:frame])) {
+        container_ = [[[UIView alloc] init] autorelease];
+        [container_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin];
+
+        spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
+        [spinner_ startAnimating];
+        [container_ addSubview:spinner_];
+
+        label_ = [[[UILabel alloc] init] autorelease];
+        [label_ setFont:[UIFont boldSystemFontOfSize:15.0f]];
+        [label_ setBackgroundColor:[UIColor clearColor]];
+        [label_ setTextColor:[UIColor blackColor]];
+        [label_ setShadowColor:[UIColor whiteColor]];
+        [label_ setShadowOffset:CGSizeMake(0, 1)];
+        [label_ setText:[NSString stringWithFormat:Elision_, UCLocalize("LOADING"), nil]];
+        [container_ addSubview:label_];
+
+        CGSize viewsize = frame.size;
+        CGSize spinnersize = [spinner_ bounds].size;
+        CGSize textsize = [[label_ text] sizeWithFont:[label_ font]];
+        float bothwidth = spinnersize.width + textsize.width + 5.0f;
+
+        CGRect containrect = {
+            CGPointMake(floorf((viewsize.width / 2) - (bothwidth / 2)), floorf((viewsize.height / 2) - (spinnersize.height / 2))),
+            CGSizeMake(bothwidth, spinnersize.height)
+        };
+        CGRect textrect = {
+            CGPointMake(spinnersize.width + 5.0f, floorf((spinnersize.height / 2) - (textsize.height / 2))),
+            textsize
+        };
+        CGRect spinrect = {
+            CGPointZero,
+            spinnersize
+        };
+
+        [container_ setFrame:containrect];
+        [spinner_ setFrame:spinrect];
+        [label_ setFrame:textrect];
+        [self addSubview:container_];
+    }
+
+    return self;
+}
+
+- (UILabel *)label { return label_; }
+- (UIActivityIndicatorView *)activityIndicatorView { return spinner_; }
+
+@end
+/* }}} */
+
 /* Cydia Browser Controller {{{ */
 @interface CYBrowserController : BrowserController {
     CydiaObject *cydia_;
@@ -4297,8 +4470,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         bounds.size.height - prgsize.height - 20
     }, prgsize};
 
-    float closewidth = bounds.size.width - 20;
-    if (closewidth > 300) closewidth = 300;
+    float closewidth = std::min(bounds.size.width - 20, 300.0f);
 
     [progress_ setFrame:prgrect];
     [status_ setFrame:CGRectMake(
@@ -4338,8 +4510,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     if ([context isEqualToString:@"conffile"]) {
         FILE *input = [database_ input];
-        if (button == [alert cancelButtonIndex]) fprintf(input, "N\n");
-        else if (button == [alert firstOtherButtonIndex]) fprintf(input, "Y\n");
+        if (button == [alert cancelButtonIndex])
+            fprintf(input, "N\n");
+        else if (button == [alert firstOtherButtonIndex])
+            fprintf(input, "Y\n");
         fflush(input);
     }
 }
@@ -4363,15 +4537,24 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         break;
 
         case 2:
-            system("launchctl stop com.apple.SpringBoard");
-        break;
+            _trace();
+            goto reload;
 
         case 3:
-            system("launchctl unload "SpringBoard_"; launchctl load "SpringBoard_);
+            _trace();
+            goto reload;
+
+        reload:
+            system("/usr/bin/sbreload");
+            _trace();
         break;
 
         case 4:
-            system("reboot");
+            _trace();
+            if (void (*SBReboot)(mach_port_t) = reinterpret_cast<void (*)(mach_port_t)>(dlsym(RTLD_DEFAULT, "SBReboot")))
+                SBReboot(SBSSpringBoardServerPort());
+            else
+                reboot2(RB_AUTOBOOT);
         break;
     }
 }
@@ -4420,7 +4603,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         case 4: [close_ setTitle:UCLocalize("REBOOT_DEVICE")]; break;
     }
 
+    _trace();
     system("su -c /usr/bin/uicache mobile");
+    _trace();
 
     UpdateExternalStatus(Finish_ == 0 ? 2 : 0);
 
@@ -4593,8 +4778,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) _addProgressOutput:(NSString *)output {
     [output_ setText:[NSString stringWithFormat:@"%@\n%@", [output_ text], output]];
     CGSize size = [output_ contentSize];
-    CGRect rect = {{0, size.height}, {size.width, 0}};
-    [output_ scrollRectToVisible:rect animated:YES];
+    CGPoint offset = [output_ contentOffset];
+    if (size.height - offset.y < [output_ frame].size.height + 20.f) {
+        CGRect rect = {{0, size.height-1}, {size.width, 1}};
+        [output_ scrollRectToVisible:rect animated:YES];
+    }
 }
 
 - (BOOL) isRunning {
@@ -4616,9 +4804,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @end
 
 @implementation ContentView
+
 - (id) initWithFrame:(CGRect)frame {
     if ((self = [super initWithFrame:frame]) != nil) {
-        /* Fix landscape stretching. */
         [self setNeedsDisplayOnBoundsChange:YES];
     } return self;
 }
@@ -4631,10 +4819,47 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [super drawRect:rect];
     [delegate_ drawContentRect:rect];
 }
+
+@end
+/* }}} */
+/* Cydia TableView Cell {{{ */
+@interface CYTableViewCell : UITableViewCell {
+    ContentView *content_;
+    bool highlighted_;
+}
+
+@end
+
+@implementation CYTableViewCell
+
+- (void) dealloc {
+    [content_ release];
+    [super dealloc];
+}
+
+- (void) _updateHighlightColorsForView:(id)view highlighted:(BOOL)highlighted {
+    //NSLog(@"_updateHighlightColorsForView:%@ highlighted:%s [content_=%@]", view, highlighted ? "YES" : "NO", content_);
+
+    if (view == content_) {
+        //NSLog(@"_updateHighlightColorsForView:content_ highlighted:%s", highlighted ? "YES" : "NO", content_);
+        highlighted_ = highlighted;
+    }
+
+    [super _updateHighlightColorsForView:view highlighted:highlighted];
+}
+
+- (void) setSelected:(BOOL)selected animated:(BOOL)animated {
+    //NSLog(@"setSelected:%s animated:%s", selected ? "YES" : "NO", animated ? "YES" : "NO");
+    highlighted_ = selected;
+
+    [super setSelected:selected animated:animated];
+    [content_ setNeedsDisplay];
+}
+
 @end
 /* }}} */
 /* Package Cell {{{ */
-@interface PackageCell : UITableViewCell <
+@interface PackageCell : CYTableViewCell <
     ContentDelegate
 > {
     UIImage *icon_;
@@ -4644,10 +4869,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSString *source_;
     UIImage *badge_;
     Package *package_;
-    UIColor *color_;
-    ContentView *content_;
-    BOOL faded_;
-    float fade_;
     UIImage *placard_;
 }
 
@@ -4698,15 +4919,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) dealloc {
     [self clearPackage];
-    [content_ release];
-    [color_ release];
     [super dealloc];
 }
 
-- (float) fade {
-    return faded_ ? [self selectionPercent] : fade_;
-}
-
 - (PackageCell *) init {
     CGRect frame(CGRectMake(0, 0, 320, 74));
     if ((self = [super initWithFrame:frame reuseIdentifier:@"Package"]) != nil) {
@@ -4719,8 +4934,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
         [content_ setDelegate:self];
         [content_ setOpaque:YES];
-        if ([self respondsToSelector:@selector(selectionPercent)])
-            faded_ = YES;
     } return self;
 }
 
@@ -4791,7 +5004,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) drawContentRect:(CGRect)rect {
-    bool selected([self isSelected]);
+    bool highlighted(highlighted_);
     float width([self bounds].size.width);
 
 #if 0
@@ -4814,23 +5027,27 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     }
 
     if (badge_ != nil) {
-        CGSize size = [badge_ size];
+        CGRect rect;
+        rect.size = [badge_ size];
+
+        rect.size.width /= 2;
+        rect.size.height /= 2;
 
-        [badge_ drawAtPoint:CGPointMake(
-            36 - size.width / 2,
-            36 - size.height / 2
-        )];
+        rect.origin.x = 36 - rect.size.width / 2;
+        rect.origin.y = 36 - rect.size.height / 2;
+
+        [badge_ drawInRect:rect];
     }
 
-    if (selected)
+    if (highlighted)
         UISetColor(White_);
 
-    if (!selected)
+    if (!highlighted)
         UISetColor(commercial_ ? Purple_ : Black_);
     [name_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - (placard_ == nil ? 80 : 106)) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
     [source_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
 
-    if (!selected)
+    if (!highlighted)
         UISetColor(commercial_ ? Purplish_ : Gray_);
     [description_ drawAtPoint:CGPointMake(12, 46) forWidth:(width - 46) withFont:Font14_ lineBreakMode:UILineBreakModeTailTruncation];
 
@@ -4838,12 +5055,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [placard_ drawAtPoint:CGPointMake(width - 52, 9)];
 }
 
-- (void) setSelected:(BOOL)selected animated:(BOOL)fade {
-    //[self _setBackgroundColor];
-    [super setSelected:selected animated:fade];
-    [content_ setNeedsDisplay];
-}
-
 + (int) heightForPackage:(Package *)package {
     return 73;
 }
@@ -4851,7 +5062,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @end
 /* }}} */
 /* Section Cell {{{ */
-@interface SectionCell : UITableViewCell <
+@interface SectionCell : CYTableViewCell <
     ContentDelegate
 > {
     NSString *basic_;
@@ -4859,7 +5070,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSString *name_;
     NSString *count_;
     UIImage *icon_;
-    ContentView *content_;
     UISwitch *switch_;
     BOOL editing_;
 }
@@ -4896,8 +5106,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [self clearSection];
     [icon_ release];
     [switch_ release];
-    [content_ release];
-
     [super dealloc];
 }
 
@@ -4920,14 +5128,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) onSwitch:(id)sender {
-    NSMutableDictionary *metadata = [Sections_ objectForKey:basic_];
+    NSMutableDictionary *metadata([Sections_ objectForKey:basic_]);
     if (metadata == nil) {
         metadata = [NSMutableDictionary dictionaryWithCapacity:2];
         [Sections_ setObject:metadata forKey:basic_];
     }
 
-    Changed_ = true;
     [metadata setObject:[NSNumber numberWithBool:([switch_ isOn] == NO)] forKey:@"Hidden"];
+    Changed_ = true;
 }
 
 - (void) setSection:(Section *)section editing:(BOOL)editing {
@@ -4974,20 +5182,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) drawContentRect:(CGRect)rect {
-    BOOL selected = [self isSelected];
+    bool highlighted(highlighted_ && !editing_);
 
     [icon_ drawInRect:CGRectMake(8, 7, 32, 32)];
 
-    if (selected)
+    if (highlighted)
         UISetColor(White_);
 
-    if (!selected)
-        UISetColor(Black_);
-
     float width(rect.size.width);
     if (editing_)
         width -= 87;
 
+    if (!highlighted)
+        UISetColor(Black_);
     [name_ drawAtPoint:CGPointMake(48, 9) forWidth:(width - 70) withFont:Font22Bold_ lineBreakMode:UILineBreakModeTailTruncation];
 
     CGSize size = [count_ sizeWithFont:Font14_];
@@ -5237,7 +5444,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) reloadButtonClicked {
-    // Don't reload a package view by clicking the button.
+    // Don't reload a commerical package by tapping the loading button,
+    // but if it's not an Install button, we should forward it on.
+    if (![package_ uninstalled])
+        [self _customButtonClicked];
 }
 
 - (void) applyLoadingTitle {
@@ -5306,6 +5516,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         target:self
         action:@selector(customButtonClicked)
     ];
+
+    [self reloadURL];
 }
 
 - (bool) isLoading {
@@ -5324,6 +5536,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     UITableViewDelegate
 > {
     _transient Database *database_;
+    unsigned era_;
     NSMutableArray *packages_;
     NSMutableArray *sections_;
     UITableView *list_;
@@ -5363,13 +5576,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [super dealloc];
 }
 
++ (BOOL) hasIndexedCollation {
+    return NO; // XXX: objc_getClass("UILocalizedIndexedCollation") != nil;
+}
+
 - (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
     NSInteger count([sections_ count]);
     return count == 0 ? 1 : count;
 }
 
 - (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section {
-    if ([sections_ count] == 0)
+    if ([sections_ count] == 0 || [[sections_ objectAtIndex:section] count] == 0)
         return nil;
     return [[sections_ objectAtIndex:section] name];
 }
@@ -5381,11 +5598,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (Package *) packageAtIndexPath:(NSIndexPath *)path {
+@synchronized (database_) {
+    if ([database_ era] != era_)
+        return nil;
+
     Section *section([sections_ objectAtIndex:[path section]]);
     NSInteger row([path row]);
     Package *package([packages_ objectAtIndex:([section row] + row)]);
-    return package;
-}
+    return [[package retain] autorelease];
+} }
 
 - (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
     PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]);
@@ -5411,10 +5632,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (NSArray *) sectionIndexTitlesForTableView:(UITableView *)tableView {
+    // XXX: is 20 the most optimal number here?
     return [packages_ count] > 20 ? index_ : nil;
 }
 
-- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
+- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
+    if ([[self class] hasIndexedCollation]) {
+        return [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionForSectionIndexTitleAtIndex:index];
+    }
+
     return index;
 }
 
@@ -5425,7 +5651,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         target_ = target;
         action_ = action;
 
-        index_ = [[NSMutableArray alloc] initWithCapacity:32];
+        index_ = [[self class] hasIndexedCollation]
+            ? [[[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles] retain]
+            : [[NSMutableArray alloc] initWithCapacity:32];
         indices_ = [[NSMutableDictionary alloc] initWithCapacity:32];
 
         packages_ = [[NSMutableArray arrayWithCapacity:16] retain];
@@ -5450,6 +5678,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) reloadData {
+    era_ = [database_ era];
     NSArray *packages = [database_ packages];
 
     [packages_ removeAllObjects];
@@ -5461,37 +5690,70 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
                 [packages_ addObject:package];
     _end
 
-    [index_ removeAllObjects];
     [indices_ removeAllObjects];
 
     Section *section = nil;
 
-    _profile(PackageTable$reloadData$Section)
-        for (size_t offset(0), end([packages_ count]); offset != end; ++offset) {
-            Package *package;
-            unichar index;
+    if ([[self class] hasIndexedCollation]) {
+        id collation = [objc_getClass("UILocalizedIndexedCollation") currentCollation];
+        NSArray *titles = [collation sectionIndexTitles];
+        int secidx = -1;
 
-            _profile(PackageTable$reloadData$Section$Package)
-                package = [packages_ objectAtIndex:offset];
-                index = [package index];
-            _end
+        _profile(PackageTable$reloadData$Section)
+            for (size_t offset(0), end([packages_ count]); offset != end; ++offset) {
+                Package *package;
+                int index;
 
-            if (section == nil || [section index] != index) {
-                _profile(PackageTable$reloadData$Section$Allocate)
-                    section = [[[Section alloc] initWithIndex:index row:offset] autorelease];
+                _profile(PackageTable$reloadData$Section$Package)
+                    package = [packages_ objectAtIndex:offset];
+                    index = [collation sectionForObject:package collationStringSelector:@selector(name)];
                 _end
 
-                [index_ addObject:[section name]];
-                //[indices_ setObject:[NSNumber numberForInt:[sections_ count]] forKey:index];
+                while (secidx < index) {
+                    secidx += 1;
 
-                _profile(PackageTable$reloadData$Section$Add)
-                    [sections_ addObject:section];
-                _end
+                    _profile(PackageTable$reloadData$Section$Allocate)
+                        section = [[[Section alloc] initWithName:[titles objectAtIndex:secidx] row:offset localize:NO] autorelease];
+                    _end
+
+                    _profile(PackageTable$reloadData$Section$Add)
+                        [sections_ addObject:section];
+                    _end
+                }
+
+                [section addToCount];
             }
+        _end
+    } else {
+        [index_ removeAllObjects];
 
-            [section addToCount];
-        }
-    _end
+        _profile(PackageTable$reloadData$Section)
+            for (size_t offset(0), end([packages_ count]); offset != end; ++offset) {
+                Package *package;
+                unichar index;
+
+                _profile(PackageTable$reloadData$Section$Package)
+                    package = [packages_ objectAtIndex:offset];
+                    index = [package index];
+                _end
+
+                if (section == nil || [section index] != index) {
+                    _profile(PackageTable$reloadData$Section$Allocate)
+                        section = [[[Section alloc] initWithIndex:index row:offset] autorelease];
+                    _end
+
+                    [index_ addObject:[section name]];
+                    //[indices_ setObject:[NSNumber numberForInt:[sections_ count]] forKey:index];
+
+                    _profile(PackageTable$reloadData$Section$Add)
+                        [sections_ addObject:section];
+                    _end
+                }
+
+                [section addToCount];
+            }
+        _end
+    }
 
     _profile(PackageTable$reloadData$List)
         [list_ reloadData];
@@ -5642,34 +5904,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 /* }}} */
 
-/* Add Source Controller {{{ */
-@interface AddSourceController : CYViewController {
-    _transient Database *database_;
-}
-
-- (id) initWithDatabase:(Database *)database;
-
-@end
-
-@implementation AddSourceController
-
-- (id) initWithDatabase:(Database *)database {
-    if ((self = [super init]) != nil) {
-        database_ = database;
-    } return self;
-}
-
-@end
-/* }}} */
 /* Source Cell {{{ */
-@interface SourceCell : UITableViewCell <
+@interface SourceCell : CYTableViewCell <
     ContentDelegate
 > {
     UIImage *icon_;
     NSString *origin_;
     NSString *description_;
     NSString *label_;
-    ContentView *content_;
 }
 
 - (void) setSource:(Source *)source;
@@ -5708,7 +5950,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) dealloc {
     [self clearSource];
-    [content_ release];
     [super dealloc];
 }
 
@@ -5727,30 +5968,25 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     } return self;
 }
 
-- (void) setSelected:(BOOL)selected animated:(BOOL)animated {
-    [super setSelected:selected animated:animated];
-    [content_ setNeedsDisplay];
-}
-
 - (void) drawContentRect:(CGRect)rect {
-    bool selected([self isSelected]);
+    bool highlighted(highlighted_);
     float width(rect.size.width);
 
     if (icon_ != nil)
         [icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
 
-    if (selected)
+    if (highlighted)
         UISetColor(White_);
 
-    if (!selected)
+    if (!highlighted)
         UISetColor(Black_);
     [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
 
-    if (!selected)
+    if (!highlighted)
         UISetColor(Blue_);
     [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
 
-    if (!selected)
+    if (!highlighted)
         UISetColor(Gray_);
     [description_ drawAtPoint:CGPointMake(12, 46) forWidth:(width - 40) withFont:Font14_ lineBreakMode:UILineBreakModeTailTruncation];
 }
@@ -5758,7 +5994,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @end
 /* }}} */
 /* Source Table {{{ */
-@interface SourceTable : CYViewController <
+@interface SourceController : CYViewController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -5786,7 +6022,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @end
 
-@implementation SourceTable
+@implementation SourceController
 
 - (void) _releaseConnection:(NSURLConnection *)connection {
     if (connection != nil) {
@@ -6135,11 +6371,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [sources_ sortUsingSelector:@selector(compareByNameAndType:)];
     _trace();
 
-     int count([sources_ count]);
+    int count([sources_ count]);
     offset_ = 0;
     for (int i = 0; i != count; i++) {
-        if ([[sources_ objectAtIndex:i] record] == nil) break;
-        else offset_++;
+        if ([[sources_ objectAtIndex:i] record] == nil)
+            break;
+        offset_++;
     }
 
     [list_ setEditing:NO];
@@ -6235,7 +6472,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (NSString *) title { return UCLocalize("INSTALLED"); }
 
 - (id) initWithDatabase:(Database *)database {
-    if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndVisible:) with:[NSNumber numberWithBool:YES]]) != nil) {
+    if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndUnfiltered:) with:[NSNumber numberWithBool:YES]]) != nil) {
         [self updateRoleButton];
         [self queueStatusDidChange];
     } return self;
@@ -6302,6 +6539,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 @implementation HomeController
 
++ (BOOL)shouldHideNavigationBar {
+    return NO;
+}
+
 - (void) _setMoreHeaders:(NSMutableURLRequest *)request {
     [super _setMoreHeaders:request];
 
@@ -6332,12 +6573,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
-    //[[self navigationController] setNavigationBarHidden:YES animated:animated];
+
+    if ([[self class] shouldHideNavigationBar])
+        [[self navigationController] setNavigationBarHidden:YES animated:animated];
 }
 
 - (void) viewWillDisappear:(BOOL)animated {
     [super viewWillDisappear:animated];
-    //[[self navigationController] setNavigationBarHidden:NO animated:animated];
+
+    if ([[self class] shouldHideNavigationBar])
+        [[self navigationController] setNavigationBarHidden:NO animated:animated];
 }
 
 - (id) init {
@@ -6439,6 +6684,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) positionViews {
     CGRect frame = [cancel_ frame];
+    frame.size = [cancel_ sizeThatFits:frame.size];
     frame.origin.x = [self frame].size.width - frame.size.width - 5;
     frame.origin.y = ([self frame].size.height - frame.size.height) / 2;
     [cancel_ setFrame:frame];
@@ -6473,7 +6719,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if ((self = [super initWithFrame:frame])) {
         [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
 
-        [self setTintColor:[UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1]];
         [self setBarStyle:UIBarStyleBlack];
 
         UIBarStyle barstyle([self _barStyle:NO]);
@@ -6536,10 +6781,25 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @class CYNavigationController;
 
 /* Cydia Tab Bar Controller {{{ */
-@interface CYTabBarController : UITabBarController {
+@interface CYTabBarController : UITabBarController <
+    ProgressDelegate
+> {
     _transient Database *database_;
+    RefreshBar *refreshbar_;
+
+    bool dropped_;
+    bool updating_;
+    // XXX: ok, "updatedelegate_"?...
+    _transient NSObject<CydiaDelegate> *updatedelegate_;
+
+    id root_;
 }
 
+- (void) dropBar:(BOOL)animated;
+- (void) beginUpdate;
+- (void) raiseBar:(BOOL)animated;
+- (BOOL) updating;
+
 @end
 
 @implementation CYTabBarController
@@ -6558,52 +6818,282 @@ freeing the view controllers on tab change */
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
         database_ = database;
+
+        [[self view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
+
+        refreshbar_ = [[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self];
     } return self;
 }
 
-@end
-/* }}} */
+- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
+    return IsWildcat_ || orientation == UIInterfaceOrientationPortrait;
+}
 
-/* Cydia Navigation Controller {{{ */
-@interface CYNavigationController : UINavigationController {
-    _transient Database *database_;
-    _transient id<UINavigationControllerDelegate> delegate_;
+- (void) setUpdate:(NSDate *)date {
+    [self beginUpdate];
 }
 
-- (id) initWithDatabase:(Database *)database;
-- (void) reloadData;
+- (void) beginUpdate {
+    [refreshbar_ start];
+    [self dropBar:YES];
 
-@end
+    [updatedelegate_ retainNetworkActivityIndicator];
+    updating_ = true;
 
+    [NSThread
+        detachNewThreadSelector:@selector(performUpdate)
+        toTarget:self
+        withObject:nil
+    ];
+}
 
-@implementation CYNavigationController
+- (void) performUpdate { _pooled
+    Status status;
+    status.setDelegate(self);
+    [database_ updateWithStatus:status];
 
-- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
-    // Inherit autorotation settings for modal parents.
-    if ([self parentViewController] && [[self parentViewController] modalViewController] == self) {
-        return [[self parentViewController] shouldAutorotateToInterfaceOrientation:orientation];
-    } else {
-        return [super shouldAutorotateToInterfaceOrientation:orientation];
-    }
+    [self
+        performSelectorOnMainThread:@selector(completeUpdate)
+        withObject:nil
+        waitUntilDone:NO
+    ];
 }
 
-- (void) dealloc {
-    [super dealloc];
+- (void) stopUpdateWithSelector:(SEL)selector {
+    updating_ = false;
+    [updatedelegate_ releaseNetworkActivityIndicator];
+
+    [self raiseBar:YES];
+    [refreshbar_ stop];
+
+    [updatedelegate_ performSelector:selector withObject:nil afterDelay:0];
 }
 
-- (void) reloadData {
-    size_t count([[self viewControllers] count]);
-    for (size_t i(0); i != count; ++i) {
-        CYViewController *page([[self viewControllers] objectAtIndex:(count - i - 1)]);
-        [page reloadData];
-    }
+- (void) completeUpdate {
+    if (!updating_)
+        return;
+    [self stopUpdateWithSelector:@selector(reloadData)];
 }
 
-- (void) setDelegate:(id<UINavigationControllerDelegate>)delegate {
-    delegate_ = delegate;
+- (void) cancelUpdate {
+    [self stopUpdateWithSelector:@selector(updateData)];
 }
 
-- (id) initWithDatabase:(Database *)database {
+- (void) cancelPressed {
+    [self cancelUpdate];
+}
+
+- (BOOL) updating {
+    return updating_;
+}
+
+- (void) setProgressError:(NSString *)error withTitle:(NSString *)title {
+    [refreshbar_ setPrompt:[NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), UCLocalize("ERROR"), error]];
+}
+
+- (void) startProgress {
+}
+
+- (void) setProgressTitle:(NSString *)title {
+    [self
+        performSelectorOnMainThread:@selector(_setProgressTitle:)
+        withObject:title
+        waitUntilDone:YES
+    ];
+}
+
+- (bool) isCancelling:(size_t)received {
+    return !updating_;
+}
+
+- (void) setProgressPercent:(float)percent {
+    [self
+        performSelectorOnMainThread:@selector(_setProgressPercent:)
+        withObject:[NSNumber numberWithFloat:percent]
+        waitUntilDone:YES
+    ];
+}
+
+- (void) addProgressOutput:(NSString *)output {
+    [self
+        performSelectorOnMainThread:@selector(_addProgressOutput:)
+        withObject:output
+        waitUntilDone:YES
+    ];
+}
+
+- (void) _setProgressTitle:(NSString *)title {
+    [refreshbar_ setPrompt:title];
+}
+
+- (void) _setProgressPercent:(NSNumber *)percent {
+    [refreshbar_ setProgress:[percent floatValue]];
+}
+
+- (void) _addProgressOutput:(NSString *)output {
+}
+
+- (void) setUpdateDelegate:(id)delegate {
+    updatedelegate_ = delegate;
+}
+
+- (CGFloat) statusBarHeight {
+    if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) {
+        return [[UIApplication sharedApplication] statusBarFrame].size.height;
+    } else {
+        return [[UIApplication sharedApplication] statusBarFrame].size.width;
+    }
+}
+
+- (UIView *) transitionView {
+    if ([self respondsToSelector:@selector(_transitionView)])
+        return [self _transitionView];
+    else
+        return MSHookIvar<id>(self, "_viewControllerTransitionView");
+}
+
+- (void) dropBar:(BOOL)animated {
+    if (dropped_)
+        return;
+    dropped_ = true;
+
+    UIView *transition([self transitionView]);
+    [[self view] addSubview:refreshbar_];
+
+    CGRect barframe([refreshbar_ frame]);
+
+    if (false) // XXX: _UIApplicationLinkedOnOrAfter(4)
+        barframe.origin.y = [self statusBarHeight];
+    else
+        barframe.origin.y = 0;
+
+    [refreshbar_ setFrame:barframe];
+
+    if (animated)
+        [UIView beginAnimations:nil context:NULL];
+
+    CGRect viewframe = [transition frame];
+    viewframe.origin.y += barframe.size.height;
+    viewframe.size.height -= barframe.size.height;
+    [transition setFrame:viewframe];
+
+    if (animated)
+        [UIView commitAnimations];
+
+    // Ensure bar has the proper width for our view, it might have changed
+    barframe.size.width = viewframe.size.width;
+    [refreshbar_ setFrame:barframe];
+
+    // XXX: fix Apple's layout bug
+    [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+}
+
+- (void) raiseBar:(BOOL)animated {
+    if (!dropped_)
+        return;
+    dropped_ = false;
+
+    UIView *transition([self transitionView]);
+    [refreshbar_ removeFromSuperview];
+
+    CGRect barframe([refreshbar_ frame]);
+
+    if (animated)
+        [UIView beginAnimations:nil context:NULL];
+
+    CGRect viewframe = [transition frame];
+    viewframe.origin.y -= barframe.size.height;
+    viewframe.size.height += barframe.size.height;
+    [transition setFrame:viewframe];
+
+    if (animated)
+        [UIView commitAnimations];
+
+    // XXX: fix Apple's layout bug
+    // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+}
+
+#if 0
+- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
+    // XXX: fix Apple's layout bug
+    // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+}
+#endif
+
+- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
+    bool dropped(dropped_);
+
+    if (dropped)
+        [self raiseBar:NO];
+
+    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
+
+    if (dropped)
+        [self dropBar:NO];
+
+    // XXX: fix Apple's layout bug
+    // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+}
+
+- (void) statusBarFrameChanged:(NSNotification *)notification {
+    if (dropped_) {
+        [self raiseBar:NO];
+        [self dropBar:NO];
+    }
+}
+
+- (void) dealloc {
+    [refreshbar_ release];
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+    [super dealloc];
+}
+
+@end
+/* }}} */
+
+/* Cydia Navigation Controller {{{ */
+@interface CYNavigationController : UINavigationController {
+    _transient Database *database_;
+    _transient id<UINavigationControllerDelegate> delegate_;
+}
+
+- (id) initWithDatabase:(Database *)database;
+- (void) reloadData;
+
+@end
+
+
+@implementation CYNavigationController
+
+- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
+    // Inherit autorotation settings for modal parents.
+    if ([self parentViewController] && [[self parentViewController] modalViewController] == self) {
+        return [[self parentViewController] shouldAutorotateToInterfaceOrientation:orientation];
+    } else if ([self parentViewController]) {
+        return [[self parentViewController] shouldAutorotateToInterfaceOrientation:orientation];
+    } else {
+        return [super shouldAutorotateToInterfaceOrientation:orientation];
+    }
+}
+
+- (void) dealloc {
+    [super dealloc];
+}
+
+- (void) reloadData {
+    size_t count([[self viewControllers] count]);
+    for (size_t i(0); i != count; ++i) {
+        CYViewController *page([[self viewControllers] objectAtIndex:(count - i - 1)]);
+        [page reloadData];
+    }
+}
+
+- (void) setDelegate:(id<UINavigationControllerDelegate>)delegate {
+    delegate_ = delegate;
+}
+
+- (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
         database_ = database;
     } return self;
@@ -6713,7 +7203,7 @@ freeing the view controllers on tab change */
 /* }}} */
 
 /* Sections Controller {{{ */
-@interface SectionsController : CYViewController <
+@interface CYSectionsController : CYViewController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -6733,7 +7223,7 @@ freeing the view controllers on tab change */
 
 @end
 
-@implementation SectionsController
+@implementation CYSectionsController
 
 - (void) dealloc {
     [list_ setDataSource:nil];
@@ -6746,11 +7236,27 @@ freeing the view controllers on tab change */
     [super dealloc];
 }
 
+- (void) setEditing:(BOOL)editing {
+    if ((editing_ = editing))
+        [list_ reloadData];
+    else
+        [delegate_ updateData];
+
+    [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")];
+    [[[self navigationItem] rightBarButtonItem] setTitle:[sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT")];
+    [[[self navigationItem] rightBarButtonItem] setStyle:editing_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain];
+}
+
 - (void) viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
     [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
 }
 
+- (void) viewWillDisappear:(BOOL)animated {
+    [super viewWillDisappear:animated];
+    if (editing_) [self setEditing:NO];
+}
+
 - (Section *) sectionAtIndexPath:(NSIndexPath *)indexPath {
     Section *section = (editing_ ? [sections_ objectAtIndex:[indexPath row]] : ([indexPath row] == 0 ? nil : [filtered_ objectAtIndex:([indexPath row] - 1)]));
     return section;
@@ -6768,7 +7274,9 @@ freeing the view controllers on tab change */
     static NSString *reuseIdentifier = @"SectionCell";
 
     SectionCell *cell = (SectionCell *) [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
-    if (cell == nil) cell = [[[SectionCell alloc] initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier] autorelease];
+    if (cell == nil)
+        cell = [[[SectionCell alloc] initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier] autorelease];
+
     [cell setSection:[self sectionAtIndexPath:indexPath] editing:editing_];
 
     return cell;
@@ -6837,40 +7345,13 @@ freeing the view controllers on tab change */
     [sections_ removeAllObjects];
     [filtered_ removeAllObjects];
 
-#if 0
-    typedef __gnu_cxx::hash_map<NSString *, Section *, NSStringMapHash, NSStringMapEqual> SectionMap;
-    SectionMap sections;
-    sections.resize(64);
-#else
     NSMutableDictionary *sections([NSMutableDictionary dictionaryWithCapacity:32]);
-#endif
 
     _trace();
     for (Package *package in packages) {
         NSString *name([package section]);
         NSString *key(name == nil ? @"" : name);
 
-#if 0
-        Section **section;
-
-        _profile(SectionsView$reloadData$Section)
-            section = &sections[key];
-            if (*section == nil) {
-                _profile(SectionsView$reloadData$Section$Allocate)
-                    *section = [[[Section alloc] initWithName:name localize:YES] autorelease];
-                _end
-            }
-        _end
-
-        [*section addToCount];
-
-        _profile(SectionsView$reloadData$Filter)
-            if (![package valid] || ![package visible])
-                continue;
-        _end
-
-        [*section addToRow];
-#else
         Section *section;
 
         _profile(SectionsView$reloadData$Section)
@@ -6891,16 +7372,10 @@ freeing the view controllers on tab change */
         _end
 
         [section addToRow];
-#endif
     }
     _trace();
 
-#if 0
-    for (SectionMap::const_iterator i(sections.begin()), e(sections.end()); i != e; ++i)
-        [sections_ addObject:i->second];
-#else
     [sections_ addObjectsFromArray:[sections allValues]];
-#endif
 
     [sections_ sortUsingSelector:@selector(compareByLocalized:)];
 
@@ -6930,15 +7405,8 @@ freeing the view controllers on tab change */
         [self editButtonClicked];
 }
 
-- (void) editButtonClicked {
-    if ((editing_ = !editing_))
-        [list_ reloadData];
-    else
-        [delegate_ updateData];
-
-    [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")];
-    [[[self navigationItem] rightBarButtonItem] setTitle:[sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT")];
-    [[[self navigationItem] rightBarButtonItem] setStyle:editing_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain];
+- (void)editButtonClicked {
+    [self setEditing:!editing_];
 }
 
 - (UIView *) accessoryView {
@@ -6953,6 +7421,7 @@ freeing the view controllers on tab change */
     UITableViewDelegate
 > {
     _transient Database *database_;
+    unsigned era_;
     CFMutableArrayRef packages_;
     NSMutableArray *sections_;
     UITableView *list_;
@@ -7010,10 +7479,14 @@ freeing the view controllers on tab change */
 }
 
 - (Package *) packageAtIndexPath:(NSIndexPath *)path {
+@synchronized (database_) {
+    if ([database_ era] != era_)
+        return nil;
+
     Section *section([sections_ objectAtIndex:[path section]]);
     NSInteger row([path row]);
-    return [self packageAtIndex:([section row] + row)];
-}
+    return [[[self packageAtIndex:([section row] + row)] retain] autorelease];
+} }
 
 - (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
     PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]);
@@ -7071,10 +7544,7 @@ freeing the view controllers on tab change */
 - (void) _reloadPackages:(NSArray *)packages {
     _trace();
     for (Package *package in packages)
-        if (
-            [package uninstalled] && [package valid] && [package visible] ||
-            [package upgradableAndEssential:YES]
-        )
+        if ([package upgradableAndEssential:YES] || [package visible])
             CFArrayAppendValue(packages_, package);
 
     _trace();
@@ -7083,16 +7553,16 @@ freeing the view controllers on tab change */
 }
 
 - (void) reloadData {
+    era_ = [database_ era];
     NSArray *packages = [database_ packages];
 
     CFArrayRemoveAllValues(packages_);
 
     [sections_ removeAllObjects];
 
-#if 0
+#if 1
     UIProgressHUD *hud([delegate_ addProgressHUD]);
-    // XXX: localize
-    [hud setText:@"Loading Changes"];
+    [hud setText:UCLocalize("LOADING")];
     //NSLog(@"HUD:%@::%@", delegate_, hud);
     [self yieldToSelector:@selector(_reloadPackages:) withObject:packages];
     [delegate_ removeProgressHUD:hud];
@@ -7101,9 +7571,9 @@ freeing the view controllers on tab change */
 #endif
 
     Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
-    Section *ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") localize:NO] autorelease];
+    Section *ignored = nil;
     Section *section = nil;
-    NSDate *last = nil;
+    time_t last = 0;
 
     upgrades_ = 0;
     bool unseens = false;
@@ -7117,22 +7587,14 @@ freeing the view controllers on tab change */
 
         if (!uae) {
             unseens = true;
-            NSDate *seen;
-
-            _profile(ChangesController$reloadData$Remember)
-                seen = [package seen];
-            _end
+            time_t seen([package seen]);
 
-            if (section == nil || last != seen && (seen == nil || [seen compare:last] != NSOrderedSame)) {
+            if (section == nil || last != seen) {
                 last = seen;
 
                 NSString *name;
-                if (seen == nil)
-                    name = UCLocalize("UNKNOWN");
-                else {
-                    name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) seen);
-                    [name autorelease];
-                }
+                name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) [NSDate dateWithTimeIntervalSince1970:seen]);
+                [name autorelease];
 
                 _profile(ChangesController$reloadData$Allocate)
                     name = [NSString stringWithFormat:UCLocalize("NEW_AT"), name];
@@ -7142,9 +7604,12 @@ freeing the view controllers on tab change */
             }
 
             [section addToCount];
-        } else if ([package ignored])
+        } else if ([package ignored]) {
+            if (ignored == nil) {
+                ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") row:offset localize:NO] autorelease];
+            }
             [ignored addToCount];
-        else {
+        else {
             ++upgrades_;
             [upgradable addToCount];
         }
@@ -7228,7 +7693,13 @@ freeing the view controllers on tab change */
         search_ = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)];
         [search_ layoutSubviews];
         [search_ setPlaceholder:UCLocalize("SEARCH_EX")];
-        UITextField *textField = [search_ searchField];
+
+        UITextField *textField;
+        if ([search_ respondsToSelector:@selector(searchField)])
+            textField = [search_ searchField];
+        else
+            textField = MSHookIvar<UITextField *>(search_, "_searchField");
+
         [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
         [search_ setDelegate:self];
         [textField setEnablesReturnKeyAutomatically:NO];
@@ -7255,7 +7726,7 @@ freeing the view controllers on tab change */
 @end
 /* }}} */
 /* Settings Controller {{{ */
-@interface SettingsController : CYViewController <
+@interface CYPackageSettingsController : CYViewController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -7273,7 +7744,7 @@ freeing the view controllers on tab change */
 
 @end
 
-@implementation SettingsController
+@implementation CYPackageSettingsController
 
 - (void) dealloc {
     [name_ release];
@@ -7299,38 +7770,23 @@ freeing the view controllers on tab change */
     if (package_ == nil)
         return 0;
 
-    return 1;
+    return 2;
 }
 
 - (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
     return UCLocalize("SHOW_ALL_CHANGES_EX");
 }
 
-- (void) onSomething:(BOOL)value withKey:(NSString *)key {
+- (void) onSubscribed:(id)control {
+    bool value([control isOn]);
     if (package_ == nil)
         return;
-
-    NSMutableDictionary *metadata([package_ metadata]);
-
-    BOOL before;
-    if (NSNumber *number = [metadata objectForKey:key])
-        before = [number boolValue];
-    else
-        before = NO;
-
-    if (value != before) {
-        [metadata setObject:[NSNumber numberWithBool:value] forKey:key];
-        Changed_ = true;
+    if ([package_ setSubscribed:value])
         [delegate_ updateData];
-    }
-}
-
-- (void) onSubscribed:(id)control {
-    [self onSomething:(int) [control isOn] withKey:@"IsSubscribed"];
 }
 
 - (void) onIgnored:(id)control {
-    [self onSomething:(int) [control isOn] withKey:@"IsIgnored"];
+    // TODO: set Held state - possibly call out to dpkg, etc.
 }
 
 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -7437,7 +7893,7 @@ freeing the view controllers on tab change */
 /* }}} */
 
 /* Role Controller {{{ */
-@interface RoleController : CYViewController <
+@interface CYSettingsController : CYViewController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -7454,7 +7910,7 @@ freeing the view controllers on tab change */
 
 @end
 
-@implementation RoleController
+@implementation CYSettingsController
 - (void) dealloc {
     [table_ release];
     [segment_ release];
@@ -7505,435 +7961,172 @@ freeing the view controllers on tab change */
     [segment_ setFrame:CGRectMake(width / 32.0f, 0, width - (width / 32.0f * 2.0f), 44.0f)];
 }
 
-- (void) viewWillAppear:(BOOL)animated {
-    [super viewWillAppear:animated];
-
-    [self resizeSegmentedControl];
-}
-
-- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
-    [self resizeSegmentedControl];
-}
-
-- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
-    [self resizeSegmentedControl];
-}
-
-- (void) save {
-    NSString *role(nil);
-
-    switch ([segment_ selectedSegmentIndex]) {
-        case 0: role = @"User"; break;
-        case 1: role = @"Hacker"; break;
-        case 2: role = @"Developer"; break;
-
-        _nodefault
-    }
-
-    if (![role isEqualToString:Role_]) {
-        bool rolling(Role_ == nil);
-        Role_ = role;
-
-        Settings_ = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-            Role_, @"Role",
-        nil];
-
-        [Metadata_ setObject:Settings_ forKey:@"Settings"];
-
-        Changed_ = true;
-
-        if (rolling)
-            [roledelegate_ loadData];
-        else
-            [roledelegate_ updateData];
-    }
-}
-
-- (void) segmentChanged:(UISegmentedControl *)control {
-    [self showDoneButton];
-}
-
-- (void) saveAndClose {
-    [self save];
-
-    [[self navigationItem] setRightBarButtonItem:nil];
-    [[self navigationController] dismissModalViewControllerAnimated:YES];
-}
-
-- (void) doneButtonClicked {
-    UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)] autorelease];
-    [spinner startAnimating];
-    UIBarButtonItem *spinItem = [[[UIBarButtonItem alloc] initWithCustomView:spinner] autorelease];
-    [[self navigationItem] setRightBarButtonItem:spinItem];
-
-    [self performSelector:@selector(saveAndClose) withObject:nil afterDelay:0];
-}
-
-- (void) showDoneButton {
-    [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc]
-        initWithTitle:UCLocalize("DONE")
-        style:UIBarButtonItemStyleDone
-        target:self
-        action:@selector(doneButtonClicked)
-    ] autorelease] animated:([[self navigationItem] rightBarButtonItem] == nil)];
-}
-
-- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
-    // XXX: For not having a single cell in the table, this sure is a lot of sections.
-    return 6;
-}
-
-- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return 0; // :(
-}
-
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    return nil; // This method is required by the protocol.
-}
-
-- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
-    if (section == 1)
-        return UCLocalize("ROLE_EX");
-    if (section == 4)
-        return [NSString stringWithFormat:
-            @"%@: %@\n%@: %@\n%@: %@",
-            UCLocalize("USER"), UCLocalize("USER_EX"),
-            UCLocalize("HACKER"), UCLocalize("HACKER_EX"),
-            UCLocalize("DEVELOPER"), UCLocalize("DEVELOPER_EX")
-        ];
-    else return nil;
-}
-
-- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
-    if (section == 3) return 44.0f;
-    else return 0;
-}
-
-- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
-    if (section == 3) return container_;
-    else return nil;
-}
-
-@end
-/* }}} */
-/* Stash Controller {{{ */
-@interface CYStashController : CYViewController {
-    // XXX: just delete these things
-    _transient UIActivityIndicatorView *spinner_;
-    _transient UILabel *status_;
-    _transient UILabel *caption_;
-}
-@end
-
-@implementation CYStashController
-- (id) init {
-    if ((self = [super init])) {
-        [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
-
-        spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
-        CGRect spinrect = [spinner_ frame];
-        spinrect.origin.x = ([[self view] frame].size.width / 2) - (spinrect.size.width / 2);
-        spinrect.origin.y = [[self view] frame].size.height - 80.0f;
-        [spinner_ setFrame:spinrect];
-        [spinner_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin];
-        [[self view] addSubview:spinner_];
-        [spinner_ startAnimating];
-
-        CGRect captrect;
-        captrect.size.width = [[self view] frame].size.width;
-        captrect.size.height = 40.0f;
-        captrect.origin.x = 0;
-        captrect.origin.y = ([[self view] frame].size.height / 2) - (captrect.size.height * 2);
-        caption_ = [[[UILabel alloc] initWithFrame:captrect] autorelease];
-        [caption_ setText:@"Initializing Filesystem"];
-        [caption_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
-        [caption_ setFont:[UIFont boldSystemFontOfSize:28.0f]];
-        [caption_ setTextColor:[UIColor whiteColor]];
-        [caption_ setBackgroundColor:[UIColor clearColor]];
-        [caption_ setShadowColor:[UIColor blackColor]];
-        [caption_ setTextAlignment:UITextAlignmentCenter];
-        [[self view] addSubview:caption_];
-
-        CGRect statusrect;
-        statusrect.size.width = [[self view] frame].size.width;
-        statusrect.size.height = 30.0f;
-        statusrect.origin.x = 0;
-        statusrect.origin.y = ([[self view] frame].size.height / 2) - statusrect.size.height;
-        status_ = [[[UILabel alloc] initWithFrame:statusrect] autorelease];
-        [status_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
-        [status_ setText:@"(Cydia will exit when complete.)"];
-        [status_ setFont:[UIFont systemFontOfSize:16.0f]];
-        [status_ setTextColor:[UIColor whiteColor]];
-        [status_ setBackgroundColor:[UIColor clearColor]];
-        [status_ setShadowColor:[UIColor blackColor]];
-        [status_ setTextAlignment:UITextAlignmentCenter];
-        [[self view] addSubview:status_];
-    } return self;
-}
-
-- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
-    return IsWildcat_ || orientation == UIInterfaceOrientationPortrait;
-}
-@end
-/* }}} */
-
-/* Cydia Container {{{ */
-@interface CYContainer : UIViewController <ProgressDelegate> {
-    _transient Database *database_;
-    RefreshBar *refreshbar_;
-
-    bool dropped_;
-    bool updating_;
-    // XXX: ok, "updatedelegate_"?...
-    _transient NSObject<CydiaDelegate> *updatedelegate_;
-    // XXX: can't we query for this variable when we need it?
-    _transient UITabBarController *root_;
-}
-
-- (void) setTabBarController:(UITabBarController *)controller;
-
-- (void) dropBar:(BOOL)animated;
-- (void) beginUpdate;
-- (void) raiseBar:(BOOL)animated;
-- (BOOL) updating;
-
-@end
-
-@implementation CYContainer
-
-- (BOOL) _reallyWantsFullScreenLayout {
-    return YES;
-}
-
-// NOTE: UIWindow only sends the top controller these messages,
-//       So we have to forward them on.
-
-- (void) viewDidAppear:(BOOL)animated {
-    [super viewDidAppear:animated];
-    [root_ viewDidAppear:animated];
-}
-
-- (void) viewWillAppear:(BOOL)animated {
-    [super viewWillAppear:animated];
-    [root_ viewWillAppear:animated];
-}
-
-- (void) viewDidDisappear:(BOOL)animated {
-    [super viewDidDisappear:animated];
-    [root_ viewDidDisappear:animated];
-}
-
-- (void) viewWillDisappear:(BOOL)animated {
-    [super viewWillDisappear:animated];
-    [root_ viewWillDisappear:animated];
-}
-
-- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
-    return ![updatedelegate_ hudIsShowing] && (IsWildcat_ || orientation == UIInterfaceOrientationPortrait);
-}
-
-- (void) setTabBarController:(UITabBarController *)controller {
-    root_ = controller;
-    [[self view] addSubview:[root_ view]];
-}
-
-- (void) setUpdate:(NSDate *)date {
-    [self beginUpdate];
-}
-
-- (void) beginUpdate {
-    [self dropBar:YES];
-    [refreshbar_ start];
-
-    updating_ = true;
-
-    [NSThread
-        detachNewThreadSelector:@selector(performUpdate)
-        toTarget:self
-        withObject:nil
-    ];
-}
-
-- (void) performUpdate { _pooled
-    Status status;
-    status.setDelegate(self);
-    [database_ updateWithStatus:status];
-
-    [self
-        performSelectorOnMainThread:@selector(completeUpdate)
-        withObject:nil
-        waitUntilDone:NO
-    ];
-}
-
-- (void) completeUpdate {
-    if (!updating_) return;
-    updating_ = false;
-
-    [self raiseBar:YES];
-    [refreshbar_ stop];
-    [updatedelegate_ performSelector:@selector(reloadData) withObject:nil afterDelay:0];
-}
-
-- (void) cancelUpdate {
-    updating_ = false;
-    [self raiseBar:YES];
-    [refreshbar_ stop];
-    [updatedelegate_ performSelector:@selector(updateData) withObject:nil afterDelay:0];
-}
-
-- (void) cancelPressed {
-    [self cancelUpdate];
-}
-
-- (BOOL) updating {
-    return updating_;
-}
-
-- (void) setProgressError:(NSString *)error withTitle:(NSString *)title {
-    [refreshbar_ setPrompt:[NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), UCLocalize("ERROR"), error]];
-}
-
-- (void) startProgress {
-}
-
-- (void) setProgressTitle:(NSString *)title {
-    [self
-        performSelectorOnMainThread:@selector(_setProgressTitle:)
-        withObject:title
-        waitUntilDone:YES
-    ];
-}
-
-- (bool) isCancelling:(size_t)received {
-    return !updating_;
-}
-
-- (void) setProgressPercent:(float)percent {
-    [self
-        performSelectorOnMainThread:@selector(_setProgressPercent:)
-        withObject:[NSNumber numberWithFloat:percent]
-        waitUntilDone:YES
-    ];
-}
-
-- (void) addProgressOutput:(NSString *)output {
-    [self
-        performSelectorOnMainThread:@selector(_addProgressOutput:)
-        withObject:output
-        waitUntilDone:YES
-    ];
-}
-
-- (void) _setProgressTitle:(NSString *)title {
-    [refreshbar_ setPrompt:title];
-}
+- (void) viewWillAppear:(BOOL)animated {
+    [super viewWillAppear:animated];
 
-- (void) _setProgressPercent:(NSNumber *)percent {
-    [refreshbar_ setProgress:[percent floatValue]];
+    [self resizeSegmentedControl];
 }
 
-- (void) _addProgressOutput:(NSString *)output {
+- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
+    [self resizeSegmentedControl];
 }
 
-- (void) setUpdateDelegate:(id)delegate {
-    updatedelegate_ = delegate;
+- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
+    [self resizeSegmentedControl];
 }
 
-- (CGFloat) statusBarHeight {
-    if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) {
-        return [[UIApplication sharedApplication] statusBarFrame].size.height;
-    } else {
-        return [[UIApplication sharedApplication] statusBarFrame].size.width;
+- (void) save {
+    NSString *role(nil);
+
+    switch ([segment_ selectedSegmentIndex]) {
+        case 0: role = @"User"; break;
+        case 1: role = @"Hacker"; break;
+        case 2: role = @"Developer"; break;
+
+        _nodefault
     }
-}
 
-- (void) dropBar:(BOOL)animated {
-    if (dropped_) return;
-    dropped_ = true;
+    if (![role isEqualToString:Role_]) {
+        bool rolling(Role_ == nil);
+        Role_ = role;
 
-    [[self view] addSubview:refreshbar_];
+        Settings_ = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+            Role_, @"Role",
+        nil];
 
-    CGFloat sboffset = [self statusBarHeight];
+        [Metadata_ setObject:Settings_ forKey:@"Settings"];
+        Changed_ = true;
 
-    CGRect barframe = [refreshbar_ frame];
-    barframe.origin.y = sboffset;
-    [refreshbar_ setFrame:barframe];
+        if (rolling)
+            [roledelegate_ loadData];
+        else
+            [roledelegate_ updateData];
+    }
+}
 
-    if (animated) [UIView beginAnimations:nil context:NULL];
-    CGRect viewframe = [[root_ view] frame];
-    viewframe.origin.y += barframe.size.height + sboffset;
-    viewframe.size.height -= barframe.size.height + sboffset;
-    [[root_ view] setFrame:viewframe];
-    if (animated) [UIView commitAnimations];
+- (void) segmentChanged:(UISegmentedControl *)control {
+    [self showDoneButton];
+}
 
-    // Ensure bar has the proper width for our view, it might have changed
-    barframe.size.width = viewframe.size.width;
-    [refreshbar_ setFrame:barframe];
+- (void) saveAndClose {
+    [self save];
 
-    // XXX: fix Apple's layout bug
-    [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+    [[self navigationItem] setRightBarButtonItem:nil];
+    [[self navigationController] dismissModalViewControllerAnimated:YES];
 }
 
-- (void) raiseBar:(BOOL)animated {
-    if (!dropped_) return;
-    dropped_ = false;
+- (void) doneButtonClicked {
+    UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20.0f, 20.0f)] autorelease];
+    [spinner startAnimating];
+    UIBarButtonItem *spinItem = [[[UIBarButtonItem alloc] initWithCustomView:spinner] autorelease];
+    [[self navigationItem] setRightBarButtonItem:spinItem];
 
-    [refreshbar_ removeFromSuperview];
+    [self performSelector:@selector(saveAndClose) withObject:nil afterDelay:0];
+}
 
-    CGFloat sboffset = [self statusBarHeight];
+- (void) showDoneButton {
+    [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc]
+        initWithTitle:UCLocalize("DONE")
+        style:UIBarButtonItemStyleDone
+        target:self
+        action:@selector(doneButtonClicked)
+    ] autorelease] animated:([[self navigationItem] rightBarButtonItem] == nil)];
+}
 
-    if (animated) [UIView beginAnimations:nil context:NULL];
-    CGRect barframe = [refreshbar_ frame];
-    CGRect viewframe = [[root_ view] frame];
-    viewframe.origin.y -= barframe.size.height + sboffset;
-    viewframe.size.height += barframe.size.height + sboffset;
-    [[root_ view] setFrame:viewframe];
-    if (animated) [UIView commitAnimations];
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
+    // XXX: For not having a single cell in the table, this sure is a lot of sections.
+    return 6;
+}
 
-    // XXX: fix Apple's layout bug
-    [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+    return 0; // :(
 }
 
-- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
-    // XXX: fix Apple's layout bug
-    [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+    return nil; // This method is required by the protocol.
 }
 
-- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
-    if (dropped_) {
-        [self raiseBar:NO];
-        [self dropBar:NO];
-    }
+- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
+    if (section == 1)
+        return UCLocalize("ROLE_EX");
+    if (section == 4)
+        return [NSString stringWithFormat:
+            @"%@: %@\n%@: %@\n%@: %@",
+            UCLocalize("USER"), UCLocalize("USER_EX"),
+            UCLocalize("HACKER"), UCLocalize("HACKER_EX"),
+            UCLocalize("DEVELOPER"), UCLocalize("DEVELOPER_EX")
+        ];
+    else return nil;
+}
 
-    // XXX: fix Apple's layout bug
-    [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation];
+- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
+    return section == 3 ? 44.0f : 0;
 }
 
-- (void) statusBarFrameChanged:(NSNotification *)notification {
-    if (dropped_) {
-        [self raiseBar:NO];
-        [self dropBar:NO];
-    }
+- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
+    return section == 3 ? container_ : nil;
 }
 
-- (void) dealloc {
-    [refreshbar_ release];
-    [[NSNotificationCenter defaultCenter] removeObserver:self];
-    [super dealloc];
+@end
+/* }}} */
+/* Stash Controller {{{ */
+@interface CYStashController : CYViewController {
+    // XXX: just delete these things
+    _transient UIActivityIndicatorView *spinner_;
+    _transient UILabel *status_;
+    _transient UILabel *caption_;
 }
+@end
 
-- (id) initWithDatabase:(Database *)database {
-    if ((self = [super init]) != nil) {
-        database_ = database;
+@implementation CYStashController
+- (id) init {
+    if ((self = [super init])) {
+        [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
 
-        [[self view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
+        spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
+        CGRect spinrect = [spinner_ frame];
+        spinrect.origin.x = ([[self view] frame].size.width / 2) - (spinrect.size.width / 2);
+        spinrect.origin.y = [[self view] frame].size.height - 80.0f;
+        [spinner_ setFrame:spinrect];
+        [spinner_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin];
+        [[self view] addSubview:spinner_];
+        [spinner_ startAnimating];
 
-        refreshbar_ = [[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self];
+        CGRect captrect;
+        captrect.size.width = [[self view] frame].size.width;
+        captrect.size.height = 40.0f;
+        captrect.origin.x = 0;
+        captrect.origin.y = ([[self view] frame].size.height / 2) - (captrect.size.height * 2);
+        caption_ = [[[UILabel alloc] initWithFrame:captrect] autorelease];
+        [caption_ setText:UCLocalize("PREPARING_FILESYSTEM")];
+        [caption_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
+        [caption_ setFont:[UIFont boldSystemFontOfSize:28.0f]];
+        [caption_ setTextColor:[UIColor whiteColor]];
+        [caption_ setBackgroundColor:[UIColor clearColor]];
+        [caption_ setShadowColor:[UIColor blackColor]];
+        [caption_ setTextAlignment:UITextAlignmentCenter];
+        [[self view] addSubview:caption_];
+
+        CGRect statusrect;
+        statusrect.size.width = [[self view] frame].size.width;
+        statusrect.size.height = 30.0f;
+        statusrect.origin.x = 0;
+        statusrect.origin.y = ([[self view] frame].size.height / 2) - statusrect.size.height;
+        status_ = [[[UILabel alloc] initWithFrame:statusrect] autorelease];
+        [status_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
+        [status_ setText:UCLocalize("EXIT_WHEN_COMPLETE")];
+        [status_ setFont:[UIFont systemFontOfSize:16.0f]];
+        [status_ setTextColor:[UIColor whiteColor]];
+        [status_ setBackgroundColor:[UIColor clearColor]];
+        [status_ setShadowColor:[UIColor blackColor]];
+        [status_ setTextAlignment:UITextAlignmentCenter];
+        [[self view] addSubview:status_];
     } return self;
 }
 
+- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
+    return IsWildcat_ || orientation == UIInterfaceOrientationPortrait;
+}
 @end
 /* }}} */
 
@@ -7957,7 +8150,6 @@ typedef enum {
     // XXX: evaluate all fields for _transient
 
     UIWindow *window_;
-    CYContainer *container_;
     CYTabBarController *tabbar_;
 
     NSMutableArray *essential_;
@@ -7965,16 +8157,17 @@ typedef enum {
 
     Database *database_;
 
+    NSURL *starturl_;
     int tag_;
 
-    UIKeyboard *keyboard_;
-    int huds_;
+    unsigned locked_;
+    unsigned activity_;
 
-    SectionsController *sections_;
+    CYSectionsController *sections_;
     ChangesController *changes_;
     ManageController *manage_;
     SearchController *search_;
-    SourceTable *sources_;
+    SourceController *sources_;
     InstalledController *installed_;
     id queueDelegate_;
 
@@ -7987,6 +8180,9 @@ typedef enum {
 - (void) setPage:(CYViewController *)page;
 - (void) loadData;
 
+// XXX: I hate prototypes
+- (id) queueBadgeController;
+
 @end
 
 static _finline void _setHomePage(Cydia *self) {
@@ -7996,15 +8192,11 @@ static _finline void _setHomePage(Cydia *self) {
 @implementation Cydia
 
 - (void) beginUpdate {
-    [container_ beginUpdate];
+    [tabbar_ beginUpdate];
 }
 
 - (BOOL) updating {
-    return [container_ updating];
-}
-
-- (UIView *) rotatingContentViewForWindow:(UIWindow *)window {
-    return window_;
+    return [tabbar_ updating];
 }
 
 - (void) _loaded {
@@ -8038,42 +8230,59 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) _saveConfig {
+    _trace();
+    MetaFile_.Sync();
+    _trace();
+
     if (Changed_) {
-        _trace();
         NSString *error(nil);
+
         if (NSData *data = [NSPropertyListSerialization dataFromPropertyList:Metadata_ format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error]) {
             _trace();
             NSError *error(nil);
             if (![data writeToFile:@"/var/lib/cydia/metadata.plist" options:NSAtomicWrite error:&error])
                 NSLog(@"failure to save metadata data: %@", error);
             _trace();
+
+            Changed_ = false;
         } else {
             NSLog(@"failure to serialize metadata: %@", error);
-            return;
         }
-
-        Changed_ = false;
     }
 }
 
 - (void) _updateData {
     [self _saveConfig];
 
-    /* XXX: this is just stupid */
-    if (tag_ != 1 && sections_ != nil)
-        [sections_ reloadData];
-    if (tag_ != 2 && changes_ != nil)
-        [changes_ reloadData];
-    if (tag_ != 4 && search_ != nil)
-        [search_ reloadData];
+    NSMutableSet *tabs([[[NSMutableSet alloc] initWithCapacity:10] autorelease]);
+
+    [tabs addObject:[tabbar_ selectedViewController]];
+
+    if (sections_ != nil)
+        [tabs addObject:sections_];
+    if (changes_ != nil)
+        [tabs addObject:changes_];
+    if (manage_ != nil)
+        [tabs addObject:manage_];
+    if (search_ != nil)
+        [tabs addObject:search_];
+    if (sources_ != nil)
+        [tabs addObject:sources_];
+    if (installed_ != nil)
+        [tabs addObject:installed_];
+
+    for (CYNavigationController *tab in tabs)
+        [tab reloadData];
 
-    [(CYNavigationController *)[tabbar_ selectedViewController] reloadData];
+    [queueDelegate_ queueStatusDidChange];
+    [[[self queueBadgeController] tabBarItem] setBadgeValue:(Queuing_ ? UCLocalize("Q_D") : nil)];
 }
 
 - (int)indexOfTabWithTag:(int)tag {
     int i = 0;
     for (UINavigationController *controller in [tabbar_ viewControllers]) {
-        if ([[controller tabBarItem] tag] == tag) return i;
+        if ([[controller tabBarItem] tag] == tag)
+            return i;
         i += 1;
     }
 
@@ -8127,7 +8336,7 @@ static _finline void _setHomePage(Cydia *self) {
 
     // If we can reach the server, auto-refresh!
     if (reachable)
-        [container_ performSelectorOnMainThread:@selector(setUpdate:) withObject:update waitUntilDone:NO];
+        [tabbar_ performSelectorOnMainThread:@selector(setUpdate:) withObject:update waitUntilDone:NO];
 
     [pool release];
 }
@@ -8142,7 +8351,8 @@ static _finline void _setHomePage(Cydia *self) {
 
     [database_ yieldToSelector:@selector(reloadData) withObject:nil];
 
-    if (hud) [self removeProgressHUD:hud];
+    if (hud != nil)
+        [self removeProgressHUD:hud];
 
     size_t changes(0);
 
@@ -8160,24 +8370,20 @@ static _finline void _setHomePage(Cydia *self) {
         }
     }
 
+    NSLog(@"changes:#%u", changes);
+
     UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem];
     if (changes != 0) {
+        _trace();
         NSString *badge([[NSNumber numberWithInt:changes] stringValue]);
         [changesItem setBadgeValue:badge];
         [changesItem setAnimatedBadge:([essential_ count] > 0)];
-
-        if ([self respondsToSelector:@selector(setApplicationBadge:)])
-            [self setApplicationBadge:badge];
-        else
-            [self setApplicationBadgeString:badge];
+        [self setApplicationIconBadgeNumber:changes];
     } else {
+        _trace();
         [changesItem setBadgeValue:nil];
         [changesItem setAnimatedBadge:NO];
-
-        if ([self respondsToSelector:@selector(removeApplicationBadge)])
-            [self removeApplicationBadge];
-        else // XXX: maybe use setApplicationBadgeString also?
-            [self setApplicationIconBadgeNumber:0];
+        [self setApplicationIconBadgeNumber:0];
     }
 
     [self _updateData];
@@ -8186,7 +8392,6 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) updateData {
-    [database_ setVisible];
     [self _updateData];
 }
 
@@ -8214,8 +8419,9 @@ static _finline void _setHomePage(Cydia *self) {
 
     ProgressController *progress = [[[ProgressController alloc] initWithDatabase:database_ delegate:self] autorelease];
     CYNavigationController *navigation = [[[CYNavigationController alloc] initWithRootViewController:progress] autorelease];
-    if (IsWildcat_) [navigation setModalPresentationStyle:UIModalPresentationFormSheet];
-    [container_ presentModalViewController:navigation animated:YES];
+    if (IsWildcat_)
+        [navigation setModalPresentationStyle:UIModalPresentationFormSheet];
+    [tabbar_ presentModalViewController:navigation animated:YES];
 
     [progress
         detachNewThreadSelector:@selector(update_)
@@ -8239,10 +8445,6 @@ static _finline void _setHomePage(Cydia *self) {
         _error->Discard();
 }
 
-- (CGRect) popUpBounds {
-    return [[tabbar_ view] bounds];
-}
-
 - (bool) perform {
     if (![database_ prepare])
         return false;
@@ -8252,8 +8454,9 @@ static _finline void _setHomePage(Cydia *self) {
     CYNavigationController *confirm_([[[CYNavigationController alloc] initWithRootViewController:page] autorelease]);
     [confirm_ setDelegate:self];
 
-    if (IsWildcat_) [confirm_ setModalPresentationStyle:UIModalPresentationFormSheet];
-    [container_ presentModalViewController:confirm_ animated:YES];
+    if (IsWildcat_)
+        [confirm_ setModalPresentationStyle:UIModalPresentationFormSheet];
+    [tabbar_ presentModalViewController:confirm_ animated:YES];
 
     return true;
 }
@@ -8312,14 +8515,17 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) confirmWithNavigationController:(UINavigationController *)navigation {
+    Queuing_ = false;
+
     ProgressController *progress = [[[ProgressController alloc] initWithDatabase:database_ delegate:self] autorelease];
 
     if (navigation != nil) {
         [navigation pushViewController:progress animated:YES];
     } else {
         navigation = [[[CYNavigationController alloc] initWithRootViewController:progress] autorelease];
-        if (IsWildcat_) [navigation setModalPresentationStyle:UIModalPresentationFormSheet];
-        [container_ presentModalViewController:navigation animated:YES];
+        if (IsWildcat_)
+            [navigation setModalPresentationStyle:UIModalPresentationFormSheet];
+        [tabbar_ presentModalViewController:navigation animated:YES];
     }
 
     [progress
@@ -8328,9 +8534,12 @@ static _finline void _setHomePage(Cydia *self) {
         withObject:nil
         title:UCLocalize("RUNNING")
     ];
+
+    ++locked_;
 }
 
 - (void) progressControllerIsComplete:(ProgressController *)progress {
+    --locked_;
     [self complete];
 }
 
@@ -8339,9 +8548,9 @@ static _finline void _setHomePage(Cydia *self) {
 
     CYNavigationController *navController = (CYNavigationController *) [tabbar_ selectedViewController];
     [navController setViewControllers:[NSArray arrayWithObject:page]];
-    for (CYNavigationController *page in [tabbar_ viewControllers]) {
-        if (page != navController) [page setViewControllers:nil];
-    }
+    for (CYNavigationController *page in [tabbar_ viewControllers])
+        if (page != navController)
+            [page setViewControllers:nil];
 }
 
 - (CYViewController *) _pageForURL:(NSURL *)url withClass:(Class)_class {
@@ -8350,9 +8559,9 @@ static _finline void _setHomePage(Cydia *self) {
     return browser;
 }
 
-- (SectionsController *) sectionsController {
+- (CYSectionsController *) sectionsController {
     if (sections_ == nil)
-        sections_ = [[SectionsController alloc] initWithDatabase:database_];
+        sections_ = [[CYSectionsController alloc] initWithDatabase:database_];
     return sections_;
 }
 
@@ -8368,7 +8577,8 @@ static _finline void _setHomePage(Cydia *self) {
             _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]
             withClass:[ManageController class]
         ] retain];
-        if (!IsWildcat_) queueDelegate_ = manage_;
+        if (!IsWildcat_)
+            queueDelegate_ = manage_;
     }
     return manage_;
 }
@@ -8379,16 +8589,17 @@ static _finline void _setHomePage(Cydia *self) {
     return search_;
 }
 
-- (SourceTable *) sourcesController {
+- (SourceController *) sourcesController {
     if (sources_ == nil)
-        sources_ = [[SourceTable alloc] initWithDatabase:database_];
+        sources_ = [[SourceController alloc] initWithDatabase:database_];
     return sources_;
 }
 
 - (InstalledController *) installedController {
     if (installed_ == nil) {
         installed_ = [[InstalledController alloc] initWithDatabase:database_];
-        if (IsWildcat_) queueDelegate_ = installed_;
+        if (IsWildcat_)
+            queueDelegate_ = installed_;
     }
     return installed_;
 }
@@ -8419,10 +8630,21 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) showSettings {
-    RoleController *role = [[[RoleController alloc] initWithDatabase:database_ delegate:self] autorelease];
+    CYSettingsController *role = [[[CYSettingsController alloc] initWithDatabase:database_ delegate:self] autorelease];
     CYNavigationController *nav = [[[CYNavigationController alloc] initWithRootViewController:role] autorelease];
-    if (IsWildcat_) [nav setModalPresentationStyle:UIModalPresentationFormSheet];
-    [container_ presentModalViewController:nav animated:YES];
+    if (IsWildcat_)
+        [nav setModalPresentationStyle:UIModalPresentationFormSheet];
+    [tabbar_ presentModalViewController:nav animated:YES];
+}
+
+- (void) retainNetworkActivityIndicator {
+    if (activity_++ == 0)
+        [self setNetworkActivityIndicatorVisible:YES];
+}
+
+- (void) releaseNetworkActivityIndicator {
+    if (--activity_ == 0)
+        [self setNetworkActivityIndicatorVisible:NO];
 }
 
 - (void) setPackageController:(PackageController *)view {
@@ -8442,7 +8664,8 @@ static _finline void _setHomePage(Cydia *self) {
 // Returns the navigation controller for the queuing badge.
 - (id) queueBadgeController {
     int index = [self indexOfTabWithTag:kManageTag];
-    if (index == -1) index = [self indexOfTabWithTag:kInstalledTag];
+    if (index == -1)
+        index = [self indexOfTabWithTag:kInstalledTag];
 
     return [[tabbar_ viewControllers] objectAtIndex:index];
 }
@@ -8450,29 +8673,13 @@ static _finline void _setHomePage(Cydia *self) {
 - (void) cancelAndClear:(bool)clear {
     @synchronized (self) {
         if (clear) {
-            // Clear all marks.
-            pkgCacheFile &cache([database_ cache]);
-            for (pkgCache::PkgIterator iterator = cache->PkgBegin(); !iterator.end(); ++iterator) {
-                // Unmark method taken from Synaptic Package Manager.
-                // Thanks for being sane, unlike Aptitude.
-                if (!cache[iterator].Keep()) {
-                    cache->MarkKeep(iterator, false);
-                    cache->SetReInstall(iterator, false);
-                }
-            }
-
-            // Stop queuing.
+            [database_ clear];
             Queuing_ = false;
-            [[[self queueBadgeController] tabBarItem] setBadgeValue:nil];
         } else {
-            // Start queuing.
             Queuing_ = true;
-            [[[self queueBadgeController] tabBarItem] setBadgeValue:UCLocalize("Q_D")];
         }
 
-        // Show the changes in the current view.
-        [(CYNavigationController *) [tabbar_ selectedViewController] reloadData];
-        [queueDelegate_ queueStatusDidChange];
+        [self _updateData];
     }
 }
 
@@ -8521,7 +8728,9 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) system:(NSString *)command { _pooled
+    _trace();
     system([command UTF8String]);
+    _trace();
 }
 
 - (void) applicationWillSuspend {
@@ -8529,13 +8738,10 @@ static _finline void _setHomePage(Cydia *self) {
     [super applicationWillSuspend];
 }
 
-- (BOOL) hudIsShowing {
-    return (huds_ > 0);
-}
-
-- (void) applicationSuspend:(__GSEvent *)event {
+- (BOOL) isSafeToSuspend {
     // Use external process status API internally.
     // This is probably a really bad idea.
+    // XXX: what is the point of this? does this solve anything at all?
     uint64_t status = 0;
     int notify_token;
     if (notify_register_check("com.saurik.Cydia.status", &notify_token) == NOTIFY_STATUS_OK) {
@@ -8543,17 +8749,21 @@ static _finline void _setHomePage(Cydia *self) {
         notify_cancel(notify_token);
     }
 
-    if (![self hudIsShowing] && status == 0)
+    return locked_ == 0 && status == 0;
+}
+
+- (void) applicationSuspend:(__GSEvent *)event {
+    if ([self isSafeToSuspend])
         [super applicationSuspend:event];
 }
 
 - (void) _animateSuspension:(BOOL)arg0 duration:(double)arg1 startTime:(double)arg2 scale:(float)arg3 {
-    if (![self hudIsShowing])
+    if ([self isSafeToSuspend])
         [super _animateSuspension:arg0 duration:arg1 startTime:arg2 scale:arg3];
 }
 
 - (void) _setSuspended:(BOOL)value {
-    if (![self hudIsShowing])
+    if ([self isSafeToSuspend])
         [super _setSuspended:value];
 }
 
@@ -8564,11 +8774,11 @@ static _finline void _setHomePage(Cydia *self) {
     [window_ setUserInteractionEnabled:NO];
     [hud show:YES];
 
-    UIViewController *target = container_;
+    UIViewController *target = tabbar_;
     while ([target modalViewController] != nil) target = [target modalViewController];
     [[target view] addSubview:hud];
 
-    huds_++;
+    ++locked_;
     return hud;
 }
 
@@ -8576,7 +8786,7 @@ static _finline void _setHomePage(Cydia *self) {
     [hud show:NO];
     [hud removeFromSuperview];
     [window_ setUserInteractionEnabled:YES];
-    huds_--;
+    --locked_;
 }
 
 - (CYViewController *) pageForPackage:(NSString *)name {
@@ -8609,12 +8819,12 @@ static _finline void _setHomePage(Cydia *self) {
     if (![path hasPrefix:@"/"])
         path = [@"/" stringByAppendingString:path];
 
-    if ([path isEqualToString:@"/add-source"])
-        return [[[AddSourceController alloc] initWithDatabase:database_] autorelease];
-    else if ([path isEqualToString:@"/storage"])
+    if ([path isEqualToString:@"/storage"])
         return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[CYBrowserController class]];
+    /*else if ([path isEqualToString:@"/add-source"])
+        return [[[AddSourceController alloc] initWithDatabase:database_] autorelease];*/
     else if ([path isEqualToString:@"/sources"])
-        return [[[SourceTable alloc] initWithDatabase:database_] autorelease];
+        return [[[SourceController alloc] initWithDatabase:database_] autorelease];
     else if ([path isEqualToString:@"/packages"])
         return [[[InstalledController alloc] initWithDatabase:database_] autorelease];
     else if ([path hasPrefix:@"/url/"])
@@ -8622,7 +8832,7 @@ static _finline void _setHomePage(Cydia *self) {
     else if ([path hasPrefix:@"/launch/"])
         [self launchApplicationWithIdentifier:[path substringFromIndex:8] suspended:NO];
     else if ([path hasPrefix:@"/package-settings/"])
-        return [[[SettingsController alloc] initWithDatabase:database_ package:[path substringFromIndex:18]] autorelease];
+        return [[[CYPackageSettingsController alloc] initWithDatabase:database_ package:[path substringFromIndex:18]] autorelease];
     else if ([path hasPrefix:@"/package-signature/"])
         return [[[SignatureController alloc] initWithDatabase:database_ package:[path substringFromIndex:19]] autorelease];
     else if ([path hasPrefix:@"/package/"])
@@ -8640,25 +8850,37 @@ static _finline void _setHomePage(Cydia *self) {
     return nil;
 }
 
-- (void) applicationOpenURL:(NSURL *)url {
-    [super applicationOpenURL:url];
-    int tag;
-    if (CYViewController *page = [self pageForURL:url hasTag:&tag]) {
+- (BOOL) openCydiaURL:(NSURL *)url {
+    CYViewController *page = nil;
+    int tag = 0;
+
+    if ((page = [self pageForURL:url hasTag:&tag])) {
         [self setPage:page];
         tag_ = tag;
         [tabbar_ setSelectedViewController:(tag_ == -1 ? nil : [[tabbar_ viewControllers] objectAtIndex:tag_])];
     }
+
+    return !!page;
+}
+
+- (void) applicationOpenURL:(NSURL *)url {
+    [super applicationOpenURL:url];
+
+    if (!loaded_) starturl_ = [url retain];
+    else [self openCydiaURL:url];
 }
 
 - (void) applicationWillResignActive:(UIApplication *)application {
     // Stop refreshing if you get a phone call or lock the device.
-    if ([container_ updating]) [container_ cancelUpdate];
+    if ([tabbar_ updating])
+        [tabbar_ cancelUpdate];
 
     if ([[self superclass] instancesRespondToSelector:@selector(applicationWillResignActive:)])
         [super applicationWillResignActive:application];
 }
 
 - (void) addStashController {
+    ++locked_;
     stash_ = [[CYStashController alloc] init];
     [window_ addSubview:[stash_ view]];
 }
@@ -8666,6 +8888,7 @@ static _finline void _setHomePage(Cydia *self) {
 - (void) removeStashController {
     [[stash_ view] removeFromSuperview];
     [stash_ release];
+    --locked_;
 }
 
 - (void) stash {
@@ -8717,7 +8940,30 @@ static _finline void _setHomePage(Cydia *self) {
     [tabbar_ setViewControllers:controllers];
 }
 
+- (void)showFakeTabBarInView:(UIView *)view {
+    static UITabBar *fake = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 0, 49.0f)];
+    if (view != nil) {
+        CGRect frame = [fake frame];
+        frame.origin.y = [view frame].size.height - frame.size.height;
+        frame.size.width = [view frame].size.width;
+        [fake setFrame:frame];
+        [fake setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
+        [view addSubview:fake];
+    } else {
+        [fake removeFromSuperview];
+    }
+}
+
 - (void) applicationDidFinishLaunching:(id)unused {
+_trace();
+    CydiaApp = self;
+
+    [NSURLCache setSharedURLCache:[[[SDURLCache alloc]
+        initWithMemoryCapacity:524288
+        diskCapacity:10485760
+        diskPath:[NSString stringWithFormat:@"%@/Library/Caches/com.saurik.Cydia/SDURLCache", @"/var/root"]
+    ] autorelease]];
+
     [CYBrowserController _initialize];
 
     [NSURLProtocol registerClass:[CydiaURLProtocol class]];
@@ -8733,9 +8979,7 @@ static _finline void _setHomePage(Cydia *self) {
     essential_ = [[NSMutableArray alloc] initWithCapacity:4];
     broken_ = [[NSMutableArray alloc] initWithCapacity:4];
 
-    UIScreen *screen([UIScreen mainScreen]);
-
-    window_ = [[UIWindow alloc] initWithFrame:[screen bounds]];
+    window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     [window_ orderFront:self];
     [window_ makeKey:self];
     [window_ setHidden:NO];
@@ -8763,14 +9007,12 @@ static _finline void _setHomePage(Cydia *self) {
     database_ = [Database sharedInstance];
 
     [self setupTabBarController];
-
-    container_ = [[CYContainer alloc] initWithDatabase:database_];
-    [container_ setUpdateDelegate:self];
-    [container_ setTabBarController:tabbar_];
-    [window_ addSubview:[container_ view]];
+    [tabbar_ setUpdateDelegate:self];
+    [window_ addSubview:[tabbar_ view]];
 
     // Show pinstripes while loading data.
-    [[container_ view] setBackgroundColor:[UIColor pinStripeColor]];
+    [[tabbar_ view] setBackgroundColor:[UIColor pinStripeColor]];
+    [self showFakeTabBarInView:[tabbar_ tabBar]];
 
     [self performSelector:@selector(loadData) withObject:nil afterDelay:0];
 _trace();
@@ -8783,58 +9025,33 @@ _trace();
         return;
     }
 
+    CGRect fixframe = [[tabbar_ view] frame];
+    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
+        fixframe.size = CGSizeMake(fixframe.size.height, fixframe.size.width);
+    CYLoadingIndicator *loading = [[[CYLoadingIndicator alloc] initWithFrame:fixframe] autorelease];
+    [loading setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+    [[tabbar_ view] addSubview:loading];
     [window_ setUserInteractionEnabled:NO];
 
-    UIView *container = [[[UIView alloc] init] autorelease];
-    [container setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin];
-
-    UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
-    [spinner startAnimating];
-    [container addSubview:spinner];
-
-    UILabel *label = [[[UILabel alloc] init] autorelease];
-    [label setFont:[UIFont boldSystemFontOfSize:15.0f]];
-    [label setBackgroundColor:[UIColor clearColor]];
-    [label setTextColor:[UIColor blackColor]];
-    [label setShadowColor:[UIColor whiteColor]];
-    [label setShadowOffset:CGSizeMake(0, 1)];
-    [label setText:UCLocalize("LOADING_DATA")];
-    [container addSubview:label];
-
-    CGSize viewsize = [[tabbar_ view] frame].size;
-    CGSize spinnersize = [spinner bounds].size;
-    CGSize textsize = [[label text] sizeWithFont:[label font]];
-    float bothwidth = spinnersize.width + textsize.width + 5.0f;
-
-    CGRect containrect = {
-        CGPointMake(floorf((viewsize.width / 2) - (bothwidth / 2)), floorf((viewsize.height / 2) - (spinnersize.height / 2))),
-        CGSizeMake(bothwidth, spinnersize.height)
-    };
-    CGRect textrect = {
-        CGPointMake(spinnersize.width + 5.0f, floorf((spinnersize.height / 2) - (textsize.height / 2))),
-        textsize
-    };
-    CGRect spinrect = {
-        CGPointZero,
-        spinnersize
-    };
-
-    [container setFrame:containrect];
-    [spinner setFrame:spinrect];
-    [label setFrame:textrect];
-    [[container_ view] addSubview:container];
-
     [self reloadData];
     PrintTimes();
 
-    // Show the home page
-    [tabbar_ setSelectedIndex:0];
-    _setHomePage(self);
+    // Show the initial page
+    if (starturl_ == nil || ![self openCydiaURL:starturl_]) {
+        [tabbar_ setSelectedIndex:0];
+        _setHomePage(self);
+    }
+
+    [self showFakeTabBarInView:nil];
+
+    [starturl_ release];
+    starturl_ = nil;
+
     [window_ setUserInteractionEnabled:YES];
 
     // XXX: does this actually slow anything down?
-    [[container_ view] setBackgroundColor:[UIColor clearColor]];
-    [container removeFromSuperview];
+    [[tabbar_ view] setBackgroundColor:[UIColor clearColor]];
+    [loading removeFromSuperview];
 }
 
 - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item {
@@ -9074,11 +9291,6 @@ int main(int argc, char *argv[]) { _pooled
     if (Settings_ != nil)
         Role_ = [Settings_ objectForKey:@"Role"];
 
-    if (Packages_ == nil) {
-        Packages_ = [[[NSMutableDictionary alloc] initWithCapacity:128] autorelease];
-        [Metadata_ setObject:Packages_ forKey:@"Packages"];
-    }
-
     if (Sections_ == nil) {
         Sections_ = [[[NSMutableDictionary alloc] initWithCapacity:32] autorelease];
         [Metadata_ setObject:Sections_ forKey:@"Sections"];
@@ -9090,6 +9302,18 @@ int main(int argc, char *argv[]) { _pooled
     }
     /* }}} */
 
+    _trace();
+    MetaFile_.Open("/var/lib/cydia/metadata.cb0");
+    _trace();
+
+    if (Packages_ != nil) {
+        CFDictionaryApplyFunction((CFDictionaryRef) Packages_, &PackageImport, NULL);
+        _trace();
+        [Metadata_ removeObjectForKey:@"Packages"];
+        Packages_ = nil;
+        Changed_ = true;
+    }
+
     Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];
 
     if (substrate && access("/Library/MobileSubstrate/DynamicLibraries/SimulatedKeyEvents.dylib", F_OK) == 0)
@@ -9163,6 +9387,7 @@ int main(int argc, char *argv[]) { _pooled
     /* }}} */
 
     Colon_ = UCLocalize("COLON_DELIMITED");
+    Elision_ = UCLocalize("ELISION");
     Error_ = UCLocalize("ERROR");
     Warning_ = UCLocalize("WARNING");