#include "SDURLCache/SDURLCache.h"
#include "substrate.h"
+
+#include "Version.h"
/* }}} */
/* Profiler {{{ */
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];
}
@interface CydiaProgressEvent : NSObject {
_H<NSString> message_;
_H<NSString> type_;
+
+ _H<NSArray> item_;
_H<NSString> package_;
- _H<NSString> uri_;
+ _H<NSString> url_;
+ _H<NSString> 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;
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];
}
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];
}
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];
}
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); {
[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];
[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];
@"role",
@"serial",
@"token",
+ @"version",
nil];
}
return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
+- (NSString *) version {
+ return @ Cydia_;
+}
+
- (NSString *) device {
return [[UIDevice currentDevice] uniqueIdentifier];
}
} }
- (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 {
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];
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 {
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;
}
}
-- (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 {
if (navigation != nil)
[navigation pushViewController:progress animated:YES];
else
- [self presentModalViewController:progress];
+ [self presentModalViewController:progress force:YES];
[progress invoke:invocation withTitle:title];
return progress;
_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)
[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;