X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/a2ae332e5418cf18d5321883e74a6fb710ef6ec1..ae937f865f4066daf3b9915047e814a4f07b00eb:/Cydia.mm diff --git a/Cydia.mm b/Cydia.mm index 8f42c6de..1dfe4313 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -59,6 +59,8 @@ #include #include +#include + #include #include "iPhonePrivate.h" @@ -121,9 +123,6 @@ extern "C" { #include "UICaboodle/BrowserView.h" #include "substrate.h" - -// Apple's sample Reachability code, ASPL licensed. -#include "Reachability.h" /* }}} */ /* Profiler {{{ */ @@ -312,7 +311,7 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) { } return self; } -- (void)_updateFrameForDisplay { +- (void) _updateFrameForDisplay { [super _updateFrameForDisplay]; if ([self cancelButtonIndex] == -1) { NSArray *buttons = [self buttons]; @@ -619,7 +618,9 @@ void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFCompar @end /* }}} */ -NSUInteger WebScriptObject$countByEnumeratingWithState$objects$count$(WebScriptObject *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) { +@implementation WebScriptObject (NSFastEnumeration) + +- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count { size_t length([self count] - state->state); if (length <= 0) return 0; @@ -632,6 +633,8 @@ NSUInteger WebScriptObject$countByEnumeratingWithState$objects$count$(WebScriptO return length; } +@end + NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) { size_t length([self length] - state->state); if (length <= 0) @@ -970,17 +973,17 @@ class Pcre { @end /* }}} */ /* CoreGraphics Primitives {{{ */ -class CGColor { +class CYColor { private: CGColorRef color_; public: - CGColor() : + CYColor() : color_(NULL) { } - CGColor(CGColorSpaceRef space, float red, float green, float blue, float alpha) : + CYColor(CGColorSpaceRef space, float red, float green, float blue, float alpha) : color_(NULL) { Set(space, red, green, blue, alpha); @@ -991,14 +994,14 @@ class CGColor { CGColorRelease(color_); } - ~CGColor() { + ~CYColor() { Clear(); } void Set(CGColorSpaceRef space, float red, float green, float blue, float alpha) { Clear(); float color[] = {red, green, blue, alpha}; - color_ = CGColorCreate(space, color); + color_ = CGColorCreate(space, (CGFloat *) color); } operator CGColorRef() { @@ -1021,15 +1024,15 @@ static NSArray *Finishes_; static bool Queuing_; -static CGColor Blue_; -static CGColor Blueish_; -static CGColor Black_; -static CGColor Off_; -static CGColor White_; -static CGColor Gray_; -static CGColor Green_; -static CGColor Purple_; -static CGColor Purplish_; +static CYColor Blue_; +static CYColor Blueish_; +static CYColor Black_; +static CYColor Off_; +static CYColor White_; +static CYColor Gray_; +static CYColor Green_; +static CYColor Purple_; +static CYColor Purplish_; static UIColor *InstallingColor_; static UIColor *RemovingColor_; @@ -1047,14 +1050,14 @@ static UIFont *Font18Bold_; static UIFont *Font22Bold_; static const char *Machine_ = NULL; -static const NSString *System_ = NULL; -static const NSString *SerialNumber_ = nil; -static const NSString *ChipID_ = nil; -static const NSString *Token_ = nil; -static const NSString *UniqueID_ = nil; -static const NSString *Build_ = nil; -static const NSString *Product_ = nil; -static const NSString *Safari_ = nil; +static NSString *System_ = nil; +static NSString *SerialNumber_ = nil; +static NSString *ChipID_ = nil; +static NSString *Token_ = nil; +static NSString *UniqueID_ = nil; +static NSString *Build_ = nil; +static NSString *Product_ = nil; +static NSString *Safari_ = nil; static CFLocaleRef Locale_; static NSArray *Languages_; @@ -1432,8 +1435,11 @@ typedef std::map< unsigned long, _H > SourceMap; - (void) setProgressError:(NSString *)error forPackage:(NSString *)id { Package *package = id == nil ? nil : [[Database sharedInstance] packageWithName:id]; - // XXX: holy typecast batman! - [(id)self setProgressError:error withTitle:(package == nil ? id : [package name])]; + + [self performSelector:@selector(setProgressError:withTitle:) + withObject:error + withObject:(package == nil ? id : [package name]) + ]; } @end @@ -3070,7 +3076,7 @@ static NSString *Warning_; return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:pool_ database:self]; } } -- (Database *) init { +- (id) init { if ((self = [super init]) != nil) { policy_ = NULL; records_ = NULL; @@ -3578,7 +3584,8 @@ static NSString *Warning_; return; if ([self popErrorWithTitle:title forOperation:ListUpdate(status, list, PulseInterval_)]) - /* XXX: ignore this because users suck and don't understand why refreshing is important: return */; + /* XXX: ignore this because users suck and don't understand why refreshing is important: return */ + /* XXX: why the hell is an empty if statement a clang error? */ (void) 0; [Metadata_ setObject:[NSDate date] forKey:@"LastUpdate"]; Changed_ = true; @@ -3849,7 +3856,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { id values[count]; for (unsigned i(0); i != count; ++i) values[i] = [arguments objectAtIndex:i]; - return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast(values)] autorelease]; + return [[[NSString alloc] initWithFormat:format arguments:*(reinterpret_cast(&values))] autorelease]; } - (NSString *) localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table { @@ -5027,7 +5034,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super dealloc]; } -- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section { +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return files_ == nil ? 0 : [files_ count]; } @@ -5613,7 +5620,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [[self navigationController] pushViewController:view animated:YES]; } -- (id) title { return title_; } +- (NSString *) title { return title_; } - (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object { if ((self = [super init]) != nil) { @@ -5826,11 +5833,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; } -- (int) numberOfSectionsInTableView:(UITableView *)tableView { +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { return offset_ == 0 ? 1 : 2; } -- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section { +- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { switch (section + (offset_ == 0 ? 1 : 0)) { case 0: return UCLocalize("ENTERED_BY_USER"); case 1: return UCLocalize("INSTALLED_BY_PACKAGE"); @@ -5839,7 +5846,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } -- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section { +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { int count = [sources_ count]; switch (section) { case 0: return (offset_ == 0 ? count : offset_); @@ -6030,7 +6037,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self _endConnection:connection]; } -- (id)title { return UCLocalize("SOURCES"); } +- (NSString *) title { return UCLocalize("SOURCES"); } - (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method { NSMutableURLRequest *request = [NSMutableURLRequest @@ -6242,7 +6249,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super dealloc]; } -- (id) title { return UCLocalize("INSTALLED"); } +- (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) { @@ -6572,7 +6579,7 @@ freeing the view controllers on tab change */ /* Cydia Navigation Controller {{{ */ @interface CYNavigationController : UINavigationController { _transient Database *database_; - id delegate_; + id delegate_; } - (id) initWithDatabase:(Database *)database; @@ -6604,7 +6611,7 @@ freeing the view controllers on tab change */ } } -- (void) setDelegate:(id)delegate { +- (void) setDelegate:(id)delegate { delegate_ = delegate; } @@ -6761,7 +6768,7 @@ freeing the view controllers on tab change */ return section; } -- (int) tableView:(UITableView *)tableView numberOfRowsInSection:(int)section { +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return editing_ ? [sections_ count] : [filtered_ count] + 1; } @@ -6810,7 +6817,7 @@ freeing the view controllers on tab change */ [[self navigationController] pushViewController:table animated:YES]; } -- (id) title { return UCLocalize("SECTIONS"); } +- (NSString *) title { return UCLocalize("SECTIONS"); } - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { @@ -7044,7 +7051,7 @@ freeing the view controllers on tab change */ [delegate_ distUpgrade]; } -- (id) title { return UCLocalize("CHANGES"); } +- (NSString *) title { return UCLocalize("CHANGES"); } - (id) initWithDatabase:(Database *)database delegate:(id)delegate { if ((self = [super init]) != nil) { @@ -7200,18 +7207,18 @@ freeing the view controllers on tab change */ [super dealloc]; } -- (void) searchBarSearchButtonClicked:(id)searchBar { +- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { [packages_ setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; [search_ resignFirstResponder]; [self reloadData]; } -- (void) searchBar:(id)searchBar textDidChange:(NSString *)text { +- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text { [packages_ setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)]; [self reloadData]; } -- (id) title { return nil; } +- (NSString *) title { return nil; } - (id) initWithDatabase:(Database *)database { return [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil]; @@ -7342,7 +7349,7 @@ freeing the view controllers on tab change */ return nil; } -- (id) title { return UCLocalize("SETTINGS"); } +- (NSString *) title { return UCLocalize("SETTINGS"); } - (id) initWithDatabase:(Database *)database package:(NSString *)package { if ((self = [super init])) { @@ -7814,7 +7821,7 @@ freeing the view controllers on tab change */ [super dealloc]; } -- (id) initWithDatabase: (Database *)database { +- (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; @@ -7840,7 +7847,8 @@ typedef enum { @interface Cydia : UIApplication < ConfirmationControllerDelegate, ProgressControllerDelegate, - CydiaDelegate + CydiaDelegate, + UINavigationControllerDelegate > { UIWindow *window_; CYContainer *container_; @@ -7972,10 +7980,25 @@ static _finline void _setHomePage(Cydia *self) { - (void) _refreshIfPossible { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - Reachability* reachability = [Reachability reachabilityWithHostName:@"cydia.saurik.com"]; - NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus]; + SCNetworkReachabilityFlags flags; { + SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(NULL, "cydia.saurik.com")); + SCNetworkReachabilityGetFlags(reachability, &flags); + CFRelease(reachability); + } + + // XXX: this elaborate mess is what Apple is using to determine this? :( + // XXX: do we care if the user has to intervene? maybe that's ok? + bool reachable( + (flags & kSCNetworkReachabilityFlagsReachable) != 0 && ( + (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || ( + (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 || + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0 + ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 || + (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0 + ) + ); - if (loaded_ || ManualRefresh || remoteHostStatus == NotReachable) loaded: + if (loaded_ || ManualRefresh || !reachable) loaded: [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO]; else { loaded_ = true; @@ -8075,7 +8098,7 @@ static _finline void _setHomePage(Cydia *self) { [self _saveConfig]; ProgressController *progress = [[[ProgressController alloc] initWithDatabase:database_ delegate:self] autorelease]; - UINavigationController *navigation = [[[CYNavigationController alloc] initWithRootViewController:progress] autorelease]; + CYNavigationController *navigation = [[[CYNavigationController alloc] initWithRootViewController:progress] autorelease]; if (IsWildcat_) [navigation setModalPresentationStyle:UIModalPresentationFormSheet]; [container_ presentModalViewController:navigation animated:YES]; @@ -8111,7 +8134,7 @@ static _finline void _setHomePage(Cydia *self) { ConfirmationController *page([[[ConfirmationController alloc] initWithDatabase:database_] autorelease]); [page setDelegate:self]; - id confirm_ = [[CYNavigationController alloc] initWithRootViewController:page]; + CYNavigationController *confirm_ = [[CYNavigationController alloc] initWithRootViewController:page]; [confirm_ setDelegate:self]; if (IsWildcat_) [confirm_ setModalPresentationStyle:UIModalPresentationFormSheet]; @@ -8323,29 +8346,40 @@ static _finline void _setHomePage(Cydia *self) { #endif } +// Returns the navigation controller for the queuing badge. +- (id) queueBadgeController { + int index = [self indexOfTabWithTag:kManageTag]; + if (index == -1) index = [self indexOfTabWithTag:kInstalledTag]; + + return [[tabbar_ viewControllers] objectAtIndex:index]; +} + - (void) cancelAndClear:(bool)clear { @synchronized (self) { if (clear) { - /* XXX: clear marks instead of reloading data */ - /*pkgCacheFile &cache([database_ cache]); + // Clear all marks. + pkgCacheFile &cache([database_ cache]); for (pkgCache::PkgIterator iterator = cache->PkgBegin(); !iterator.end(); ++iterator) { - if (!cache[iterator].Keep()) cache->MarkKeep(iterator, false, false); + // 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); + } } - [self updateData]; - + // Stop queuing. Queuing_ = false; - [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kManageTag] != -1 ? [self indexOfTabWithTag:kManageTag] : [self indexOfTabWithTag:kInstalledTag]] tabBarItem] setBadgeValue:nil]; - [queueDelegate_ queueStatusDidChange];*/ - [self reloadData]; + [[[self queueBadgeController] tabBarItem] setBadgeValue:nil]; } else { + // Start queuing. Queuing_ = true; - - [[[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kManageTag] != -1 ? [self indexOfTabWithTag:kManageTag] : [self indexOfTabWithTag:kInstalledTag]] tabBarItem] setBadgeValue:UCLocalize("Q_D")]; - [(CYNavigationController *)[tabbar_ selectedViewController] reloadData]; - - [queueDelegate_ queueStatusDidChange]; - } + [[[self queueBadgeController] tabBarItem] setBadgeValue:UCLocalize("Q_D")]; + } + + // Show the changes in the current view. + [(CYNavigationController *) [tabbar_ selectedViewController] reloadData]; + [queueDelegate_ queueStatusDidChange]; } } @@ -8694,7 +8728,6 @@ int main(int argc, char *argv[]) { _pooled PackageName = reinterpret_cast(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname)))); /* Library Hacks {{{ */ - class_addMethod(objc_getClass("WebScriptObject"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &WebScriptObject$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16"); class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16"); $WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");