X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/3ea82d91d07fcd4ae6ae0db105228e091d2b9e91..2e9123cb835e70b48f8eb4b72520e2ef5cbe92ec:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 23621ce9..999a708f 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -125,6 +125,8 @@ extern "C" { #include "SDURLCache/SDURLCache.h" #include "substrate.h" + +#include "Version.h" /* }}} */ /* Profiler {{{ */ @@ -218,12 +220,13 @@ union SplitHash { static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); static _finline NSString *CydiaURL(NSString *path) { - char page[25]; - page[0] = 'h'; page[1] = 't'; page[2] = 't'; page[3] = 'p'; page[4] = ':'; - page[5] = '/'; page[6] = '/'; page[7] = 'c'; page[8] = 'y'; page[9] = 'd'; - page[10] = 'i'; page[11] = 'a'; page[12] = '.'; page[13] = 's'; page[14] = 'a'; - page[15] = 'u'; page[16] = 'r'; page[17] = 'i'; page[18] = 'k'; page[19] = '.'; - page[20] = 'c'; page[21] = 'o'; page[22] = 'm'; page[23] = '/'; page[24] = '\0'; + char page[26]; + page[0] = 'h'; page[1] = 't'; page[2] = 't'; page[3] = 'p'; page[4] = 's'; + page[5] = ':'; page[6] = '/'; page[7] = '/'; page[8] = 'c'; page[9] = 'y'; + page[10] = 'd'; page[11] = 'i'; page[12] = 'a'; page[13] = '.'; page[14] = 's'; + page[15] = 'a'; page[16] = 'u'; page[17] = 'r'; page[18] = 'i'; page[19] = 'k'; + page[20] = '.'; page[21] = 'c'; page[22] = 'o'; page[23] = 'm'; page[24] = '/'; + page[25] = '\0'; return [[NSString stringWithUTF8String:page] stringByAppendingString:path]; } @@ -1172,21 +1175,31 @@ bool isSectionVisible(NSString *section) { @interface CydiaProgressEvent : NSObject { _H message_; _H type_; + + _H item_; _H package_; - _H uri_; + _H url_; + _H version_; } + (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type; + (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forPackage:(NSString *)package; ++ (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forItem:(pkgAcquire::ItemDesc &)item; - (id) initWithMessage:(NSString *)message ofType:(NSString *)type; - (NSString *) message; - (NSString *) type; + +- (NSArray *) item; - (NSString *) package; -- (NSString *) uri; +- (NSString *) url; +- (NSString *) version; +- (void) setItem:(NSArray *)item; - (void) setPackage:(NSString *)package; +- (void) setURL:(NSString *)url; +- (void) setVersion:(NSString *)version; - (NSString *) compound:(NSString *)value; - (NSString *) compoundMessage; @@ -1234,7 +1247,7 @@ class Status : virtual void Fetch(pkgAcquire::ItemDesc &item) { NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]); - CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:UCLocalize("DOWNLOADING_"), name] ofType:@"STATUS"]); + CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:UCLocalize("DOWNLOADING_"), name] ofType:@"STATUS" forItem:item]); [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES]; } @@ -1252,11 +1265,7 @@ class Status : if (error.empty()) return; - //NSString *description([NSString stringWithUTF8String:item.Description.c_str()]); - //NSArray *fields([description componentsSeparatedByString:@" "]); - //NSString *source([fields count] == 0 ? nil : [fields objectAtIndex:0]); - - CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:@"ERROR"]); + CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:@"ERROR" forItem:item]); [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES]; } @@ -1381,12 +1390,31 @@ typedef std::map< unsigned long, _H > SourceMap; return event; } ++ (CydiaProgressEvent *) eventWithMessage:(NSString *)message ofType:(NSString *)type forItem:(pkgAcquire::ItemDesc &)item { + CydiaProgressEvent *event([self eventWithMessage:message ofType:type]); + + NSString *description([NSString stringWithUTF8String:item.Description.c_str()]); + NSArray *fields([description componentsSeparatedByString:@" "]); + [event setItem:fields]; + + if ([fields count] > 3) { + [event setPackage:[fields objectAtIndex:2]]; + [event setVersion:[fields objectAtIndex:3]]; + } + + [event setURL:[NSString stringWithUTF8String:item.URI.c_str()]]; + + return event; +} + + (NSArray *) _attributeKeys { return [NSArray arrayWithObjects: + @"item", @"message", @"package", @"type", - @"uri", + @"url", + @"version", nil]; } @@ -1413,18 +1441,38 @@ typedef std::map< unsigned long, _H > SourceMap; return type_; } -- (NSString *) package { - return package_; +- (NSArray *) item { + return (id) item_ ?: [NSNull null]; } -- (NSString *) uri { - return uri_; +- (void) setItem:(NSArray *)item { + item_ = item; +} + +- (NSString *) package { + return (id) package_ ?: [NSNull null]; } - (void) setPackage:(NSString *)package { package_ = package; } +- (NSString *) url { + return (id) url_ ?: [NSNull null]; +} + +- (void) setURL:(NSString *)url { + url_ = url; +} + +- (void) setVersion:(NSString *)version { + version_ = version; +} + +- (NSString *) version { + return (id) version_ ?: [NSNull null]; +} + - (NSString *) compound:(NSString *)value { if (value != nil) { NSString *mode(nil); { @@ -3341,7 +3389,10 @@ static NSString *Warning_; [progress_ performSelectorOnMainThread:@selector(addProgressEvent) withObject:event waitUntilDone:YES]; } else if (pmstatus_r(data, size)) { std::string type([pmstatus_r[1] UTF8String]); + NSString *package = pmstatus_r[2]; + if ([package isEqualToString:@"dpkg-exec"]) + package = nil; float percent([pmstatus_r[3] floatValue]); [progress_ performSelectorOnMainThread:@selector(setProgressPercent:) withObject:[NSNumber numberWithFloat:(percent / 100)] waitUntilDone:YES]; @@ -3572,8 +3623,9 @@ static NSString *Warning_; [delegate_ repairWithSelector:@selector(configure)]; else if (error == "The package lists or status file could not be parsed or opened.") [delegate_ repairWithSelector:@selector(update)]; - // else if (error == "Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied)") // else if (error == "Could not get lock /var/lib/dpkg/lock - open (35 Resource temporarily unavailable)") + // else if (error == "Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied)") + // else if (error == "Malformed Status line") // else if (error == "The list of sources could not be read.") else { [delegate_ addProgressEventOnMainThread:[CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:(warning ? @"WARNING" : @"ERROR")] forTask:title]; @@ -3962,6 +4014,7 @@ static NSString *Warning_; @"role", @"serial", @"token", + @"version", nil]; } @@ -3973,6 +4026,10 @@ static NSString *Warning_; return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name]; } +- (NSString *) version { + return @ Cydia_; +} + - (NSString *) device { return [[UIDevice currentDevice] uniqueIdentifier]; } @@ -4137,9 +4194,11 @@ static NSString *Warning_; } } - (Package *) getPackageById:(NSString *)id { - Package *package([[Database sharedInstance] packageWithName:id]); - [package parse]; - return package; + if (Package *package = [[Database sharedInstance] packageWithName:id]) { + [package parse]; + return package; + } else + return (Package *) [NSNull null]; } - (NSArray *) statfs:(NSString *)path { @@ -4452,12 +4511,7 @@ static NSString *Warning_; WebView *webview([[webview_ _documentView] webView]); - Package *package([[Database sharedInstance] packageWithName:@"cydia"]); - - NSString *application = package == nil ? @"Cydia" : [NSString - stringWithFormat:@"Cydia/%@", - [package installed] - ]; + NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]); if (Safari_ != nil) application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application]; @@ -6896,10 +6950,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSURL *url([request URL]); if (url == nil) return NO; + NSString *scheme([[url scheme] lowercaseString]); - if (scheme == nil || ![scheme isEqualToString:@"cydia"]) - return NO; - return YES; + if (scheme != nil && [scheme isEqualToString:@"cydia"]) + return YES; + if ([[url absoluteString] hasPrefix:@"about:cydia-"]) + return YES; + + return NO; } + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request { @@ -6926,8 +6984,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSURL *url([request URL]); NSString *href([url absoluteString]); + NSString *scheme([[url scheme] lowercaseString]); + + NSString *path; + + if ([scheme isEqualToString:@"cydia"]) + path = [href substringFromIndex:8]; + else if ([scheme isEqualToString:@"about"]) + path = [href substringFromIndex:12]; + else _assert(false); - NSString *path([href substringFromIndex:8]); NSRange slash([path rangeOfString:@"/"]); NSString *command; @@ -8915,11 +8981,33 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } -- (void) presentModalViewController:(UIViewController *)controller { +- (void) disemulate { + if (emulated_ == nil) + return; + + [window_ addSubview:[tabbar_ view]]; + [[emulated_ view] removeFromSuperview]; + [emulated_ release]; + emulated_ = nil; + [window_ setUserInteractionEnabled:YES]; +} + +- (void) presentModalViewController:(UIViewController *)controller force:(BOOL)force { UINavigationController *navigation([[[CYNavigationController alloc] initWithRootViewController:controller] autorelease]); if (IsWildcat_) [navigation setModalPresentationStyle:UIModalPresentationFormSheet]; - [((UIViewController *) emulated_ ?: tabbar_) presentModalViewController:navigation animated:YES]; + + UIViewController *parent; + if (emulated_ == nil) + parent = tabbar_; + else if (!force) + parent = emulated_; + else { + [self disemulate]; + parent = tabbar_; + } + + [parent presentModalViewController:navigation animated:YES]; } - (ProgressController *) invokeNewProgress:(NSInvocation *)invocation forController:(UINavigationController *)navigation withTitle:(NSString *)title { @@ -8928,7 +9016,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (navigation != nil) [navigation pushViewController:progress animated:YES]; else - [self presentModalViewController:progress]; + [self presentModalViewController:progress force:YES]; [progress invoke:invocation withTitle:title]; return progress; @@ -9522,7 +9610,7 @@ _trace(); _trace(); if (Role_ == nil) { [window_ setUserInteractionEnabled:YES]; - [self presentModalViewController:[[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease]]; + [self presentModalViewController:[[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease] force:NO]; return; } else { if ([emulated_ modalViewController] != nil) @@ -9533,13 +9621,7 @@ _trace(); [self reloadData]; PrintTimes(); - [window_ addSubview:[tabbar_ view]]; - - [[emulated_ view] removeFromSuperview]; - [emulated_ release]; - emulated_ = nil; - - [window_ setUserInteractionEnabled:YES]; + [self disemulate]; int selectedIndex = 0; NSMutableArray *items = nil;