X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/ac11599cdfe478888286dc1726e663839e90acf9..0df874bdd0eb406410000fefe47798010605de8d:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 6a73c601..151cae37 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -695,6 +695,16 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s /* }}} */ /* C++ NSString Wrapper Cache {{{ */ +static _finline CFStringRef CYStringCreate(const char *data, size_t size) { + return size == 0 ? NULL : + CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(data), size, kCFStringEncodingUTF8, NO, kCFAllocatorNull) ?: + CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(data), size, kCFStringEncodingISOLatin1, NO, kCFAllocatorNull); +} + +static _finline CFStringRef CYStringCreate(const char *data) { + return CYStringCreate(data, strlen(data)); +} + class CYString { private: char *data_; @@ -773,14 +783,10 @@ class CYString { return size_ == rhs.size_ && memcmp(data_, rhs.data_, size_) == 0; } - operator CFStringRef() { - if (cache_ == NULL) { - if (size_ == 0) - return nil; - cache_ = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(data_), size_, kCFStringEncodingUTF8, NO, kCFAllocatorNull); - if (cache_ == NULL) - cache_ = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(data_), size_, kCFStringEncodingISOLatin1, NO, kCFAllocatorNull); - } return cache_; + _finline operator CFStringRef() { + if (cache_ == NULL) + cache_ = CYStringCreate(data_, size_); + return cache_; } _finline operator id() { @@ -1069,10 +1075,6 @@ NSString *SizeString(double size) { return [NSString stringWithFormat:@"%s%.1f %s", (negative ? "-" : ""), size, powers_[power]]; } -static _finline CFStringRef CFCString(const char *value) { - return CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(value), strlen(value), kCFStringEncodingUTF8, NO, kCFAllocatorNull); -} - const char *StripVersion_(const char *version) { const char *colon(strchr(version, ':')); if (colon != NULL) @@ -1086,7 +1088,7 @@ CFStringRef StripVersion(const char *version) { version = colon + 1; return CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast(version), strlen(version), kCFStringEncodingUTF8, NO); // XXX: performance - return CFCString(version); + return CYStringCreate(version); } NSString *LocalizeSection(NSString *section) { @@ -1183,6 +1185,7 @@ bool isSectionVisible(NSString *section) { - (void) syncData; - (void) showSettings; - (UIProgressHUD *) addProgressHUD; +- (BOOL) hudIsShowing; - (void) removeProgressHUD:(UIProgressHUD *)hud; - (CYViewController *) pageForPackage:(NSString *)name; - (PackageController *) packageController; @@ -1330,7 +1333,7 @@ typedef std::map< unsigned long, _H > SourceMap; pkgSourceList *list_; SourceMap sources_; - NSMutableArray *packages_; + CFMutableArrayRef packages_; _transient NSObject *delegate_; Status status_; @@ -1972,8 +1975,6 @@ struct PackageNameOrdering : - (void) dealloc { if (source_ != nil) [source_ release]; - if (section$_ != nil) - [section$_ release]; if (latest_ != nil) [latest_ release]; @@ -2093,7 +2094,11 @@ struct PackageNameOrdering : pool_ = pool; version_ = version; - iterator_ = version.ParentPkg(); + + _profile(Package$initWithVersion$ParentPkg) + iterator_ = version.ParentPkg(); + _end + database_ = database; _profile(Package$initWithVersion$Latest) @@ -2119,7 +2124,7 @@ struct PackageNameOrdering : name_.set(pool, iterator_.Display()); _end - _profile(Package$lowercaseString) + _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? :( @@ -2143,9 +2148,9 @@ struct PackageNameOrdering : tags_ = [[NSMutableArray alloc] initWithCapacity:8]; do { const char *name(tag.Name()); - [tags_ addObject:(NSString *)CFCString(name)]; + [tags_ addObject:(NSString *)CYStringCreate(name)]; if (role_ == nil && strncmp(name, "role::", 6) == 0 /*&& strcmp(name, "role::leaper") != 0*/) - role_ = (NSString *) CFCString(name + 6); + role_ = (NSString *) CYStringCreate(name + 6); if (required_ && strncmp(name, "require::", 9) == 0 && ( true )) @@ -2207,9 +2212,14 @@ struct PackageNameOrdering : section_.set(pool_, iterator_.Section()); _end - obsolete_ = [self hasTag:@"cydia::obsolete"]; - essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"]; - [self setVisible]; + _profile(Package$initWithVersion$hasTag) + obsolete_ = [self hasTag:@"cydia::obsolete"]; + essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"]; + _end + + _profile(Package$initWithVersion$setVisible) + [self setVisible]; + _end _end } return self; } @@ -2240,7 +2250,7 @@ struct PackageNameOrdering : if (section_.empty()) return nil; - std::replace(section_.data(), section_.data() + section_.size(), ' ', '_'); + std::replace(section_.data(), section_.data() + section_.size(), '_', ' '); NSString *name(section_); lookup: @@ -2250,7 +2260,7 @@ struct PackageNameOrdering : goto lookup; } - section$_ = [[name stringByReplacingCharacter:'_' withCharacter:' '] retain]; + section$_ = name; } return section$_; } @@ -2389,8 +2399,28 @@ struct PackageNameOrdering : } - (BOOL) unfiltered { - NSString *section([self section]); - return !obsolete_ && [self hasSupportingRole] && (section == nil || isSectionVisible(section)); + _profile(Package$unfiltered$obsolete) + if (obsolete_) + return false; + _end + + _profile(Package$unfiltered$hasSupportingRole) + if (![self hasSupportingRole]) + return false; + _end + + NSString *section; + + _profile(Package$unfiltered$section) + section = [self section]; + _end + + _profile(Package$unfiltered$isSectionVisible) + if (section != nil && !isSectionVisible(section)) + return false; + _end + + return true; } - (BOOL) visible { @@ -2794,7 +2824,7 @@ struct PackageNameOrdering : } - (bool) isInstalledAndVisible:(NSNumber *)number { - return (![number boolValue] || [self visible]) && ![self uninstalled]; + return ((![number boolValue] && ![role_ isEqualToString:@"cydia"]) || [self visible]) && ![self uninstalled]; } - (bool) isVisibleInSection:(NSString *)name { @@ -3063,7 +3093,7 @@ static NSString *Warning_; zone_ = NSCreateZone(1024 * 1024, 256 * 1024, NO); apr_pool_create(&pool_, NULL); - packages_ = [[NSMutableArray alloc] init]; + packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL); int fds[2]; @@ -3131,7 +3161,7 @@ static NSString *Warning_; } - (NSArray *) packages { - return packages_; + return (NSArray *) packages_; } - (NSArray *) sources { @@ -3147,7 +3177,7 @@ static NSString *Warning_; NSMutableArray *issues([NSMutableArray arrayWithCapacity:4]); - for (Package *package in packages_) { + for (Package *package in [self packages]) { if (![package broken]) continue; pkgCache::PkgIterator pkg([package iterator]); @@ -3243,7 +3273,9 @@ static NSString *Warning_; @synchronized (self) { ++era_; - [packages_ removeAllObjects]; + CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&CFRelease), NULL); + CFArrayRemoveAllValues(packages_); + sources_.clear(); _error->Discard(); @@ -3336,8 +3368,6 @@ static NSString *Warning_; return; } - _trace(); - for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) { std::vector *indices = (*source)->GetIndexFiles(); for (std::vector::const_iterator index = indices->begin(); index != indices->end(); ++index) @@ -3349,8 +3379,6 @@ static NSString *Warning_; } } - _trace(); - { /*std::vector packages; packages.reserve(std::max(10000U, [packages_ count] + 1000)); @@ -3362,7 +3390,7 @@ static NSString *Warning_; for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator) if (Package *package = [Package packageWithIterator:iterator withZone:zone_ inPool:pool_ database:self]) //packages.push_back(package); - [packages_ addObject:package]; + CFArrayAppendValue(packages_, [package retain]); _trace(); @@ -3372,9 +3400,9 @@ static NSString *Warning_; packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()]; _trace();*/ - [packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(16)]; - [packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(4)]; - [packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(16)]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(4)]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; /*_trace(); PrintTimes(); @@ -3388,14 +3416,13 @@ static NSString *Warning_; //CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast(&PackageNameCompare), NULL); - CFArrayInsertionSortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast(&PackageNameCompare), NULL); + CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&PackageNameCompare), NULL); //[packages_ sortUsingFunction:reinterpret_cast(&PackageNameCompare) context:NULL]; _trace(); } -} -} CYPoolEnd() } +} } CYPoolEnd() _trace(); } - (void) configure { NSString *dpkg = [NSString stringWithFormat:@"dpkg --configure -a --status-fd %u", statusfd_]; @@ -3541,7 +3568,7 @@ static NSString *Warning_; } - (void) setVisible { - for (Package *package in packages_) + for (Package *package in [self packages]) [package setVisible]; } @@ -6927,7 +6954,7 @@ freeing the view controllers on tab change */ UITableViewDelegate > { _transient Database *database_; - NSMutableArray *packages_; + CFMutableArrayRef packages_; NSMutableArray *sections_; UITableView *list_; unsigned upgrades_; @@ -6945,7 +6972,8 @@ freeing the view controllers on tab change */ [list_ setDelegate:nil]; [list_ setDataSource:nil]; - [packages_ release]; + CFRelease(packages_); + [sections_ release]; [list_ release]; [super dealloc]; @@ -6978,10 +7006,14 @@ freeing the view controllers on tab change */ return [[sections_ objectAtIndex:section] count]; } +- (Package *) packageAtIndex:(NSUInteger)index { + return (Package *) CFArrayGetValueAtIndex(packages_, index); +} + - (Package *) packageAtIndexPath:(NSIndexPath *)path { Section *section([sections_ objectAtIndex:[path section]]); NSInteger row([path row]); - return [packages_ objectAtIndex:([section row] + row)]; + return [self packageAtIndex:([section row] + row)]; } - (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path { @@ -7021,7 +7053,8 @@ freeing the view controllers on tab change */ database_ = database; [[self navigationItem] setTitle:UCLocalize("CHANGES")]; - packages_ = [[NSMutableArray arrayWithCapacity:16] retain]; + packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL); + sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; @@ -7043,25 +7076,30 @@ freeing the view controllers on tab change */ [package uninstalled] && [package valid] && [package visible] || [package upgradableAndEssential:YES] ) - [packages_ addObject:package]; + CFArrayAppendValue(packages_, package); _trace(); - [packages_ radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; _trace(); } - (void) reloadData { NSArray *packages = [database_ packages]; - [packages_ removeAllObjects]; + CFArrayRemoveAllValues(packages_); + [sections_ removeAllObjects]; +#if 0 UIProgressHUD *hud([delegate_ addProgressHUD]); // XXX: localize [hud setText:@"Loading Changes"]; //NSLog(@"HUD:%@::%@", delegate_, hud); [self yieldToSelector:@selector(_reloadPackages:) withObject:packages]; [delegate_ removeProgressHUD:hud]; +#else + [self _reloadPackages:packages]; +#endif Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease]; Section *ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") localize:NO] autorelease]; @@ -7073,8 +7111,8 @@ freeing the view controllers on tab change */ CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle)); - for (size_t offset = 0, count = [packages_ count]; offset != count; ++offset) { - Package *package = [packages_ objectAtIndex:offset]; + for (size_t offset = 0, count = CFArrayGetCount(packages_); offset != count; ++offset) { + Package *package = [self packageAtIndex:offset]; BOOL uae = [package upgradableAndEssential:YES]; @@ -7119,7 +7157,7 @@ freeing the view controllers on tab change */ if (unseens) { Section *last = [sections_ lastObject]; size_t count = [last count]; - [packages_ removeObjectsInRange:NSMakeRange([packages_ count] - count, count)]; + CFArrayReplaceValues(packages_, CFRangeMake(CFArrayGetCount(packages_) - count, count), NULL, 0); [sections_ removeLastObject]; } @@ -7517,11 +7555,22 @@ freeing the view controllers on tab change */ [self showDoneButton]; } -- (void) doneButtonClicked { +- (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 { UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:UCLocalize("DONE") @@ -7641,7 +7690,7 @@ freeing the view controllers on tab change */ bool dropped_; bool updating_; - id updatedelegate_; + NSObject *updatedelegate_; UITabBarController *root_; } @@ -7684,7 +7733,7 @@ freeing the view controllers on tab change */ } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { - return IsWildcat_ || orientation == UIInterfaceOrientationPortrait; + return ![updatedelegate_ hudIsShowing] && (IsWildcat_ || orientation == UIInterfaceOrientationPortrait); } - (void) setTabBarController:(UITabBarController *)controller { @@ -7920,7 +7969,7 @@ typedef enum { int tag_; UIKeyboard *keyboard_; - UIProgressHUD *hud_; + int huds_; SectionsController *sections_; ChangesController *changes_; @@ -8093,7 +8142,6 @@ static _finline void _setHomePage(Cydia *self) { [hud setText:UCLocalize("RELOADING_DATA")]; [database_ yieldToSelector:@selector(reloadData) withObject:nil]; - _trace(); if (hud) [self removeProgressHUD:hud]; @@ -8482,6 +8530,10 @@ static _finline void _setHomePage(Cydia *self) { [super applicationWillSuspend]; } +- (BOOL) hudIsShowing { + return (huds_ > 0); +} + - (void) applicationSuspend:(__GSEvent *)event { // Use external process status API internally. // This is probably a really bad idea. @@ -8492,17 +8544,17 @@ static _finline void _setHomePage(Cydia *self) { notify_cancel(notify_token); } - if (hud_ == nil && status == 0) + if (![self hudIsShowing] && status == 0) [super applicationSuspend:event]; } - (void) _animateSuspension:(BOOL)arg0 duration:(double)arg1 startTime:(double)arg2 scale:(float)arg3 { - if (hud_ == nil) + if (![self hudIsShowing]) [super _animateSuspension:arg0 duration:arg1 startTime:arg2 scale:arg3]; } - (void) _setSuspended:(BOOL)value { - if (hud_ == nil) + if (![self hudIsShowing]) [super _setSuspended:value]; } @@ -8517,6 +8569,7 @@ static _finline void _setHomePage(Cydia *self) { while ([target modalViewController] != nil) target = [target modalViewController]; [[target view] addSubview:hud]; + huds_++; return hud; } @@ -8524,6 +8577,7 @@ static _finline void _setHomePage(Cydia *self) { [hud show:NO]; [hud removeFromSuperview]; [window_ setUserInteractionEnabled:YES]; + huds_--; } - (CYViewController *) pageForPackage:(NSString *)name { @@ -8662,7 +8716,6 @@ static _finline void _setHomePage(Cydia *self) { } [tabbar_ setViewControllers:controllers]; - [tabbar_ setSelectedIndex:0]; } - (void) applicationDidFinishLaunching:(id)unused { @@ -8718,16 +8771,16 @@ static _finline void _setHomePage(Cydia *self) { [[container_ view] setBackgroundColor:[UIColor pinStripeColor]]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; +_trace(); } - (void) loadData { +_trace(); if (Role_ == nil) { [self showSettings]; return; } - [UIKeyboard initImplementationNow]; - [window_ setUserInteractionEnabled:NO]; UIView *container = [[UIView alloc] init]; @@ -8776,6 +8829,7 @@ static _finline void _setHomePage(Cydia *self) { PrintTimes(); // Show the home page + [tabbar_ setSelectedIndex:0]; _setHomePage(self); [window_ setUserInteractionEnabled:YES]; @@ -9005,7 +9059,6 @@ int main(int argc, char *argv[]) { _pooled Metadata_ = [[[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"] autorelease]; _trace(); SectionMap_ = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sections" ofType:@"plist"]] autorelease]; - _trace(); if (Metadata_ == NULL) Metadata_ = [NSMutableDictionary dictionaryWithCapacity:2];