X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/1912e6165f5d7fd1329fb0df428029cbcc4af1f3..f35f9983c2c2518c6ede1be4bf4b1031ea7d5d41:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 7f053191..3ec3ceba 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -790,6 +790,10 @@ class CYString { _finline operator id() { return (NSString *) static_cast(*this); } + + _finline operator const char *() { + return reinterpret_cast(data_); + } }; /* }}} */ /* C++ NSString Algorithm Adapters {{{ */ @@ -1050,7 +1054,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_; /* }}} */ @@ -1710,7 +1714,7 @@ typedef std::map< unsigned long, _H > SourceMap; bool essential_; bool obsolete_; - NSString *latest_; + CYString latest_; CYString installed_; CYString id_; @@ -1732,9 +1736,10 @@ typedef std::map< unsigned long, _H > SourceMap; NSString *role_; NSMutableDictionary *metadata_; - _transient NSDate *firstSeen_; - _transient NSDate *lastSeen_; + time_t firstSeen_; + time_t lastSeen_; bool subscribed_; + bool ignored_; } - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database; @@ -1758,7 +1763,7 @@ typedef std::map< unsigned long, _H > SourceMap; - (unichar) index; - (NSMutableDictionary *) metadata; -- (NSDate *) seen; +- (time_t) seen; - (BOOL) subscribed; - (BOOL) ignored; @@ -1837,7 +1842,7 @@ uint32_t PackageChangesRadix(Package *self, void *) { value.bits.ignored = [self ignored] ? 0 : 1; value.bits.upgradable = 1; } else { - value.bits.timestamp = static_cast([[self seen] timeIntervalSince1970]) >> 2; + value.bits.timestamp = static_cast([self seen]) >> 2; value.bits.ignored = 0; value.bits.upgradable = 0; } @@ -1958,9 +1963,6 @@ struct PackageNameOrdering : if (source_ != nil) [source_ release]; - if (latest_ != nil) - [latest_ release]; - if (sponsor$_ != nil) [sponsor$_ release]; if (author$_ != nil) @@ -2078,8 +2080,7 @@ struct PackageNameOrdering : database_ = database; _profile(Package$initWithVersion$Latest) - const char *latest(StripVersion_(version_.VerStr())); - latest_ = (NSString *) CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast(latest), strlen(latest), kCFStringEncodingASCII, NO); + latest_.set(pool_, StripVersion_(version_.VerStr())); _end pkgCache::VerIterator current; @@ -2131,23 +2132,23 @@ struct PackageNameOrdering : firstSeen_ = now_; metadata_ = [[NSMutableDictionary dictionaryWithObjectsAndKeys: - firstSeen_, @"FirstSeen", - latest_, @"LastVersion", + [NSDate dateWithTimeIntervalSince1970:firstSeen_], @"FirstSeen", + static_cast(latest_), @"LastVersion", nil] mutableCopy]; changed = true; } else { - firstSeen_ = [metadata_ objectForKey:@"FirstSeen"]; - lastSeen_ = [metadata_ objectForKey:@"LastSeen"]; + firstSeen_ = [[metadata_ objectForKey:@"FirstSeen"] timeIntervalSince1970]; + lastSeen_ = [[metadata_ objectForKey:@"LastSeen"] timeIntervalSince1970]; if (NSNumber *subscribed = [metadata_ objectForKey:@"IsSubscribed"]) subscribed_ = [subscribed boolValue]; NSString *version([metadata_ objectForKey:@"LastVersion"]); - if (firstSeen_ == nil) { - firstSeen_ = lastSeen_ == nil ? now_ : lastSeen_; - [metadata_ setObject:firstSeen_ forKey:@"FirstSeen"]; + if (firstSeen_ == 0) { + firstSeen_ = lastSeen_ == 0 ? now_ : lastSeen_; + [metadata_ setObject:[NSDate dateWithTimeIntervalSince1970:firstSeen_] forKey:@"FirstSeen"]; changed = true; } @@ -2157,7 +2158,7 @@ struct PackageNameOrdering : } else if (![version isEqualToString:latest_]) { [metadata_ setObject:latest_ forKey:@"LastVersion"]; lastSeen_ = now_; - [metadata_ setObject:lastSeen_ forKey:@"LastSeen"]; + [metadata_ setObject:[NSDate dateWithTimeIntervalSince1970:lastSeen_] forKey:@"LastSeen"]; changed = true; } } @@ -2178,6 +2179,8 @@ struct PackageNameOrdering : obsolete_ = [self hasTag:@"cydia::obsolete"]; essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"]; _end + + ignored_ = iterator_->SelectedState == pkgCache::State::Hold; _end } return self; } @@ -2245,16 +2248,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_) { @@ -2298,10 +2307,8 @@ struct PackageNameOrdering : return metadata_; } -- (NSDate *) seen { - if (subscribed_ && lastSeen_ != nil) - return lastSeen_; - return firstSeen_; +- (time_t) seen { + return subscribed_ ? lastSeen_ : firstSeen_; } - (BOOL) subscribed { @@ -2309,11 +2316,7 @@ struct PackageNameOrdering : } - (BOOL) ignored { - NSDictionary *metadata([self metadata]); - if (NSNumber *ignored = [metadata objectForKey:@"IsIgnored"]) - return [ignored boolValue]; - else - return false; + return ignored_; } - (NSString *) latest { @@ -2448,7 +2451,7 @@ struct PackageNameOrdering : icon = [UIImage imageAtPath:[static_cast(icon_) 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]]; @@ -2908,12 +2911,17 @@ static NSString *Warning_; return era_; } +- (void) releasePackages { + CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&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]; } @@ -3201,9 +3209,7 @@ static NSString *Warning_; @synchronized (self) { ++era_; - CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&CFRelease), NULL); - CFArrayRemoveAllValues(packages_); - + [self releasePackages]; sources_.clear(); _error->Discard(); @@ -3222,11 +3228,6 @@ static NSString *Warning_; delete policy_; policy_ = NULL; - if (now_ != nil) { - [now_ release]; - now_ = nil; - } - cache_.Close(); apr_pool_clear(pool_); @@ -3263,7 +3264,7 @@ static NSString *Warning_; unlink("/tmp/cydia.chk"); - now_ = [[NSDate date] retain]; + now_ = [[NSDate date] timeIntervalSince1970]; policy_ = new pkgDepCache::Policy(); records_ = new pkgRecords(cache_); @@ -3669,7 +3670,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]; @@ -7011,9 +7012,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; @@ -7027,22 +7028,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]; @@ -7052,9 +7045,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]; } @@ -7240,7 +7236,7 @@ freeing the view controllers on tab change */ } - (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 { @@ -7881,9 +7877,8 @@ typedef enum { Database *database_; int tag_; - - UIKeyboard *keyboard_; - int huds_; + int hudcount_; + NSURL *starturl_; SectionsController *sections_; ChangesController *changes_; @@ -8443,7 +8438,7 @@ static _finline void _setHomePage(Cydia *self) { } - (BOOL) hudIsShowing { - return (huds_ > 0); + return (hudcount_ > 0); } - (void) applicationSuspend:(__GSEvent *)event { @@ -8481,7 +8476,7 @@ static _finline void _setHomePage(Cydia *self) { while ([target modalViewController] != nil) target = [target modalViewController]; [[target view] addSubview:hud]; - huds_++; + hudcount_++; return hud; } @@ -8489,7 +8484,7 @@ static _finline void _setHomePage(Cydia *self) { [hud show:NO]; [hud removeFromSuperview]; [window_ setUserInteractionEnabled:YES]; - huds_--; + hudcount_--; } - (CYViewController *) pageForPackage:(NSString *)name { @@ -8553,14 +8548,26 @@ 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; + + NSLog(@"open url: %@", url); + + 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]; + NSLog(@"first: %@", url); + if (!loaded_) starturl_ = [url retain]; + else [self openCydiaURL:url]; } - (void) applicationWillResignActive:(UIApplication *)application { @@ -8741,9 +8748,15 @@ _trace(); [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); + } + + [starturl_ release]; + starturl_ = nil; + [window_ setUserInteractionEnabled:YES]; // XXX: does this actually slow anything down?