/* Mime Addresses {{{ */
@interface Address : NSObject {
NSString *name_;
- NSString *email_;
+ NSString *address_;
}
- (NSString *) name;
-- (NSString *) email;
+- (NSString *) address;
+ (Address *) addressWithString:(NSString *)string;
- (Address *) initWithString:(NSString *)string;
- (void) dealloc {
[name_ release];
- if (email_ != nil)
- [email_ release];
+ if (address_ != nil)
+ [address_ release];
[super dealloc];
}
return name_;
}
-- (NSString *) email {
- return email_;
+- (NSString *) address {
+ return address_;
}
+ (Address *) addressWithString:(NSString *)string {
return [[[Address alloc] initWithString:string] autorelease];
}
++ (NSArray *) _attributeKeys {
+ return [NSArray arrayWithObjects:@"address", @"name", nil];
+}
+
+- (NSArray *) attributeKeys {
+ return [[self class] _attributeKeys];
+}
+
++ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
+ return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
+}
+
- (Address *) initWithString:(NSString *)string {
if ((self = [super init]) != nil) {
const char *data = [string UTF8String];
size_t size = [string length];
- static Pcre email_r("^\"?(.*)\"? <([^>]*)>$");
+ static Pcre address_r("^\"?(.*)\"? <([^>]*)>$");
- if (email_r(data, size)) {
- name_ = [email_r[1] retain];
- email_ = [email_r[2] retain];
+ if (address_r(data, size)) {
+ name_ = [address_r[1] retain];
+ address_ = [address_r[2] retain];
} else {
name_ = [[NSString alloc]
initWithBytes:data
encoding:kCFStringEncodingUTF8
];
- email_ = nil;
+ address_ = nil;
}
} return self;
}
static const float KeyboardTime_ = 0.3f;
static const char * const SpringBoard_ = "/System/Library/LaunchDaemons/com.apple.SpringBoard.plist";
-#ifndef Cydia_
-#define Cydia_ ""
-#endif
-
static CGColor Blue_;
static CGColor Blueish_;
static CGColor Black_;
static BOOL Sounds_Keyboard_;
static BOOL Advanced_;
-//static BOOL Loaded_;
+static BOOL Loaded_;
static BOOL Ignored_;
static UIFont *Font12_;
[super dealloc];
}
++ (NSArray *) _attributeKeys {
+ return [NSArray arrayWithObjects:@"description", @"distribution", @"host", @"key", @"label", @"name", @"origin", @"trusted", @"type", @"uri", @"version", nil];
+}
+
+- (NSArray *) attributeKeys {
+ return [[self class] _attributeKeys];
+}
+
++ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
+ return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
+}
+
- (Source *) initWithMetaIndex:(metaIndex *)index {
if ((self = [super init]) != nil) {
trusted_ = index->IsTrusted();
NSString *name_;
NSString *tagline_;
NSString *icon_;
- NSString *website_;
+ NSString *homepage_;
Address *sponsor_;
Address *author_;
NSArray *tags_;
- (NSString *) name;
- (NSString *) tagline;
- (NSString *) icon;
-- (NSString *) website;
+- (NSString *) homepage;
- (Address *) author;
- (NSArray *) relationships;
[tagline_ release];
if (icon_ != nil)
[icon_ release];
- if (website_ != nil)
- [website_ release];
+ if (homepage_ != nil)
+ [homepage_ release];
if (sponsor_ != nil)
[sponsor_ release];
if (author_ != nil)
[super dealloc];
}
++ (NSArray *) _attributeKeys {
+ return [NSArray arrayWithObjects:@"author", @"description", @"essential", @"homepage", @"icon", @"id", @"installed", @"latest", @"maintainer", @"name", @"section", @"size", @"source", @"sponsor", @"tagline", nil];
+}
+
+- (NSArray *) attributeKeys {
+ return [[self class] _attributeKeys];
+}
+
++ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
+ return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
+}
+
- (Package *) initWithIterator:(pkgCache::PkgIterator)iterator database:(Database *)database {
if ((self = [super init]) != nil) {
iterator_ = iterator;
icon_ = Scour("Icon", begin, end);
if (icon_ != nil)
icon_ = [icon_ retain];
- website_ = Scour("Homepage", begin, end);
- if (website_ == nil)
- website_ = Scour("Website", begin, end);
- if (website_ != nil)
- website_ = [website_ retain];
+ homepage_ = Scour("Homepage", begin, end);
+ if (homepage_ == nil)
+ homepage_ = Scour("Website", begin, end);
+ if (homepage_ != nil)
+ homepage_ = [homepage_ retain];
NSString *sponsor = Scour("Sponsor", begin, end);
if (sponsor != nil)
sponsor_ = [[Address addressWithString:sponsor] retain];
return icon_;
}
-- (NSString *) website {
- return website_;
+- (NSString *) homepage {
+ return homepage_;
}
- (Address *) sponsor {
@end
/* }}} */
+int Finish_;
+NSArray *Finishes_;
+
/* Database Implementation {{{ */
@implementation Database
std::istream is(&ib);
std::string line;
+ static Pcre finish_r("^finish:([^:]*)$");
+
while (std::getline(is, line)) {
const char *data(line.c_str());
- //size_t size = line.size();
+ size_t size = line.size();
fprintf(stderr, "C:%s\n", data);
+
+ if (finish_r(data, size)) {
+ NSString *finish = finish_r[1];
+ int index = [Finishes_ indexOfObject:finish];
+ if (index != INT_MAX && index > Finish_)
+ Finish_ = index;
+ }
}
[pool release];
cydiafd_ = fds[1];
_config->Set("APT::Keep-Fds::", cydiafd_);
- setenv("CYDIA", [[[[NSNumber numberWithInt:cydiafd_] stringValue] stringByAppendingString:@" 0"] UTF8String], _not(int));
+ setenv("CYDIA", [[[[NSNumber numberWithInt:cydiafd_] stringValue] stringByAppendingString:@" 1"] UTF8String], _not(int));
[NSThread
detachNewThreadSelector:@selector(_readCydia:)
[close_ setAutosizesToFit:NO];
[close_ setDrawsShadow:YES];
[close_ setStretchBackground:YES];
- [close_ setTitle:@"Return to Cydia"];
[close_ setEnabled:YES];
GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 22);
}
- (void) closeButtonPushed {
- [delegate_ progressViewIsComplete:self];
- [self resetView];
+ switch (Finish_) {
+ case 0:
+ [delegate_ progressViewIsComplete:self];
+ [self resetView];
+ break;
+
+ case 1:
+ [delegate_ suspendWithAnimation:YES];
+ break;
+
+ case 2:
+ system("killall SpringBoard");
+ break;
+
+ case 3:
+ system("launchctl unload /System/Library/LaunchDaemons/com.apple.SpringBoard.plist; launchctl load /System/Library/LaunchDaemons/com.apple.SpringBoard.plist");
+ break;
+
+ case 4:
+ system("reboot");
+ break;
+ }
}
- (void) _retachThread {
[progress_ removeFromSuperview];
[status_ removeFromSuperview];
+ switch (Finish_) {
+ case 0: [close_ setTitle:@"Return to Cydia"]; break;
+ case 1: [close_ setTitle:@"Close Cydia (Restart)"]; break;
+ case 2: [close_ setTitle:@"Restart SpringBoard"]; break;
+ case 3: [close_ setTitle:@"Reload SpringBoard"]; break;
+ case 4: [close_ setTitle:@"Reboot Device"]; break;
+ }
+
#ifdef __OBJC2__
notify_post("com.apple.mobile.application_installed");
#endif
@end
/* }}} */
/* Package View {{{ */
-@protocol PackageViewDelegate
-- (void) performPackage:(Package *)package;
-@end
-
-@interface PackageView : RVPage {
- _transient Database *database_;
- UIPreferencesTable *table_;
+@interface PackageView : BrowserView {
Package *package_;
NSString *name_;
- UITextView *description_;
NSMutableArray *buttons_;
}
@implementation PackageView
- (void) dealloc {
- [table_ setDataSource:nil];
- [table_ setDelegate:nil];
-
if (package_ != nil)
[package_ release];
if (name_ != nil)
[name_ release];
- if (description_ != nil)
- [description_ release];
- [table_ release];
[buttons_ release];
[super dealloc];
}
-- (int) numberOfGroupsInPreferencesTable:(UIPreferencesTable *)table {
- int number = 2;
- if ([package_ installed] != nil)
- ++number;
- if ([package_ source] != nil)
- ++number;
- return number;
-}
-
-- (NSString *) preferencesTable:(UIPreferencesTable *)table titleForGroup:(int)group {
- if (group-- == 0)
- return nil;
- else if ([package_ installed] != nil && group-- == 0)
- return @"Installed Package";
- else if (group-- == 0)
- return @"Package Details";
- else if ([package_ source] != nil && group-- == 0)
- return @"Source Information";
- else _assert(false);
-}
-
-- (float) preferencesTable:(UIPreferencesTable *)table heightForRow:(int)row inGroup:(int)group withProposedHeight:(float)proposed {
- if (description_ == nil || group != 0 || row != ([package_ author] == nil ? 1 : 2))
- return proposed;
- else
- return [description_ visibleTextRect].size.height + TextViewOffset_;
-}
-
-- (int) preferencesTable:(UIPreferencesTable *)table numberOfRowsInGroup:(int)group {
- if (group-- == 0) {
- int number = 1;
- if ([package_ author] != nil)
- ++number;
- if (description_ != nil)
- ++number;
- if ([package_ website] != nil)
- ++number;
- return number;
- } else if ([package_ installed] != nil && group-- == 0)
- return 2;
- else if (group-- == 0) {
- int number = 2;
- if ([package_ size] != 0)
- ++number;
- if ([package_ maintainer] != nil)
- ++number;
- if ([package_ sponsor] != nil)
- ++number;
- if ([package_ relationships] != nil)
- ++number;
- if ([[package_ source] trusted])
- ++number;
- return number;
- } else if ([package_ source] != nil && group-- == 0) {
- Source *source = [package_ source];
- NSString *description = [source description];
- int number = 1;
- if (description != nil && ![description isEqualToString:[source label]])
- ++number;
- if ([source origin] != nil)
- ++number;
- return number;
- } else _assert(false);
-}
-
-- (UIPreferencesTableCell *) preferencesTable:(UIPreferencesTable *)table cellForRow:(int)row inGroup:(int)group {
- UIPreferencesTableCell *cell = [[[UIPreferencesTableCell alloc] init] autorelease];
- [cell setShowSelection:NO];
-
- if (group-- == 0) {
- if (false) {
- } else if (row-- == 0) {
- [cell setTitle:[package_ name]];
- [cell setValue:[package_ latest]];
- } else if ([package_ author] != nil && row-- == 0) {
- [cell setTitle:@"Author"];
- [cell setValue:[[package_ author] name]];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- } else if (description_ != nil && row-- == 0) {
- [cell addSubview:description_];
- } else if ([package_ website] != nil && row-- == 0) {
- [cell setTitle:@"More Information"];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- } else _assert(false);
- } else if ([package_ installed] != nil && group-- == 0) {
- if (false) {
- } else if (row-- == 0) {
- [cell setTitle:@"Version"];
- NSString *installed([package_ installed]);
- [cell setValue:(installed == nil ? @"n/a" : installed)];
- } else if (row-- == 0) {
- [cell setTitle:@"Filesystem Content"];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- } else _assert(false);
- } else if (group-- == 0) {
- if (false) {
- } else if (row-- == 0) {
- [cell setTitle:@"Identifier"];
- [cell setValue:[package_ id]];
- } else if (row-- == 0) {
- [cell setTitle:@"Section"];
- NSString *section([package_ section]);
- [cell setValue:(section == nil ? @"n/a" : section)];
- } else if ([package_ size] != 0 && row-- == 0) {
- [cell setTitle:@"Expanded Size"];
- [cell setValue:SizeString([package_ size])];
- } else if ([package_ maintainer] != nil && row-- == 0) {
- [cell setTitle:@"Maintainer"];
- [cell setValue:[[package_ maintainer] name]];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- } else if ([package_ sponsor] != nil && row-- == 0) {
- [cell setTitle:@"Sponsor"];
- [cell setValue:[[package_ sponsor] name]];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- } else if ([package_ relationships] != nil && row-- == 0) {
- [cell setTitle:@"Package Relationships"];
- [cell setShowDisclosure:YES];
- [cell setShowSelection:YES];
- } else if ([[package_ source] trusted] && row-- == 0) {
- [cell setIcon:[UIImage applicationImageNamed:@"trusted.png"]];
- [cell setValue:@"This package has been signed."];
- } else _assert(false);
- } else if ([package_ source] != nil && group-- == 0) {
- Source *source = [package_ source];
- NSString *description = [source description];
-
- if (false) {
- } else if (row-- == 0) {
- NSString *label = [source label];
- if (label == nil)
- label = [source uri];
- [cell setTitle:label];
- [cell setValue:[source version]];
- } else if (description != nil && ![description isEqualToString:[source label]] && row-- == 0) {
- [cell setValue:description];
- } else if ([source origin] != nil && row-- == 0) {
- [cell setTitle:@"Origin"];
- [cell setValue:[source origin]];
- } else _assert(false);
- } else _assert(false);
-
- return cell;
-}
-
-- (BOOL) canSelectRow:(int)row {
- return YES;
-}
-
-- (void) tableRowSelected:(NSNotification *)notification {
- int row = [table_ selectedRow];
- if (row == INT_MAX)
- return;
-
- #define _else else goto _label; return; } _label:
-
- if (true) {
- if (row-- == 0) {
- } else if (row-- == 0) {
- } else if ([package_ author] != nil && row-- == 0) {
- [delegate_ openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@?subject=%@",
- [[package_ author] email],
- [[NSString stringWithFormat:@"regarding apt package \"%@\"",
- [package_ name]
- ] stringByAddingPercentEscapes]
- ]]];
- } else if (description_ != nil && row-- == 0) {
- } else if ([package_ website] != nil && row-- == 0) {
- NSURL *url = [NSURL URLWithString:[package_ website]];
- BrowserView *browser = [[[BrowserView alloc] initWithBook:book_ database:database_] autorelease];
- [browser setDelegate:delegate_];
- [book_ pushPage:browser];
- [browser loadURL:url];
- } _else if ([package_ installed] != nil) {
- if (row-- == 0) {
- } else if (row-- == 0) {
- } else if (row-- == 0) {
- FileTable *files = [[[FileTable alloc] initWithBook:book_ database:database_] autorelease];
- [files setDelegate:delegate_];
- [files setPackage:package_];
- [book_ pushPage:files];
- } _else if (true) {
- if (row-- == 0) {
- } else if (row-- == 0) {
- } else if (row-- == 0) {
- } else if ([package_ size] != 0 && row-- == 0) {
- } else if ([package_ maintainer] != nil && row-- == 0) {
- [delegate_ openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto:%@?subject=%@",
- [[package_ maintainer] email],
- [[NSString stringWithFormat:@"regarding apt package \"%@\"",
- [package_ name]
- ] stringByAddingPercentEscapes]
- ]]];
- } else if ([package_ sponsor] != nil && row-- == 0) {
- NSURL *url = [NSURL URLWithString:[[package_ sponsor] email]];
- BrowserView *browser = [[[BrowserView alloc] initWithBook:book_ database:database_] autorelease];
- [browser setDelegate:delegate_];
- [book_ pushPage:browser];
- [browser loadURL:url];
- } else if ([package_ relationships] != nil && row-- == 0) {
- } else if ([[package_ source] trusted] && row-- == 0) {
- } _else if ([package_ source] != nil) {
- Source *source = [package_ source];
- NSString *description = [source description];
-
- if (row-- == 0) {
- } else if (row-- == 0) {
- } else if (description != nil && ![description isEqualToString:[source label]] && row-- == 0) {
- } else if ([source origin] != nil && row-- == 0) {
- } _else _assert(false);
-
- #undef _else
-}
-
- (void) _clickButtonWithName:(NSString *)name {
if ([name isEqualToString:@"Install"])
[delegate_ installPackage:package_];
[sheet dismiss];
}
+- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+ [window setValue:package_ forKey:@"package"];
+}
+
- (void) _rightButtonClicked {
+ /*[super _rightButtonClicked];
+ return;*/
+
int count = [buttons_ count];
_assert(count != 0);
}
}
-- (NSString *) rightButtonTitle {
+- (NSString *) _rightButtonTitle {
int count = [buttons_ count];
return count == 0 ? nil : count != 1 ? @"Modify" : [buttons_ objectAtIndex:0];
}
}
- (id) initWithBook:(RVBook *)book database:(Database *)database {
- if ((self = [super initWithBook:book]) != nil) {
+ if ((self = [super initWithBook:book database:database]) != nil) {
database_ = database;
-
- table_ = [[UIPreferencesTable alloc] initWithFrame:[self bounds]];
- [self addSubview:table_];
-
- [table_ setDataSource:self];
- [table_ setDelegate:self];
-
buttons_ = [[NSMutableArray alloc] initWithCapacity:4];
} return self;
}
name_ = nil;
}
- if (description_ != nil) {
- [description_ release];
- description_ = nil;
- }
-
[buttons_ removeAllObjects];
if (package != nil) {
package_ = [package retain];
name_ = [[package id] retain];
- NSString *description([package description]);
- if (description == nil)
- description = [package tagline];
- if (description != nil) {
- description_ = [GetTextView(description, 12, true) retain];
- [description_ setTextColor:Black_];
- }
-
- [table_ reloadData];
+ [self loadURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"package" ofType:@"html"]]];
if ([package_ source] == nil);
else if ([package_ upgradableAndEssential:NO])
}
}
-- (void) resetViewAnimated:(BOOL)animated {
- [table_ resetViewAnimated:animated];
-}
-
- (void) reloadData {
[self setPackage:[database_ packageWithName:name_]];
[self reloadButtons];
@end
/* }}} */
+/* Home View {{{ */
@interface HomeView : BrowserView {
}
}
@end
-
+/* }}} */
+/* Manage View {{{ */
@interface ManageView : BrowserView {
}
return @"Settings";
}
-- (NSString *) rightButtonTitle {
+- (NSString *) _rightButtonTitle {
return nil;
}
@end
+/* }}} */
/* Browser Implementation {{{ */
@implementation BrowserView
page = [[[SourceTable alloc] initWithBook:book_ database:database_] autorelease];
else if ([href isEqualToString:@"cydia://packages"])
page = [[[InstalledView alloc] initWithBook:book_ database:database_] autorelease];
- else if ([href hasPrefix:@"apptapp://package/"]) {
+ else if ([href hasPrefix:@"cydia://files/"]) {
+ NSString *name = [href substringFromIndex:14];
+
+ if (Package *package = [database_ packageWithName:name]) {
+ FileTable *files = [[[FileTable alloc] initWithBook:book_ database:database_] autorelease];
+ [files setPackage:package];
+ page = files;
+ }
+ } else if ([href hasPrefix:@"apptapp://package/"]) {
NSString *name = [href substringFromIndex:18];
if (Package *package = [database_ packageWithName:name]) {
[self reloadURL];
}
+- (NSString *) _rightButtonTitle {
+ return @"Reload";
+}
+
- (NSString *) rightButtonTitle {
- return loading_ ? @"" : @"Reload";
+ return loading_ ? @"" : [self _rightButtonTitle];
}
- (NSString *) title {
[self updateData];
- /*if ([packages count] == 0);
- else if (Loaded_)*/
+ if ([packages count] == 0);
+ else if (Loaded_)
[self _loaded];
- /*else {
+ else {
Loaded_ = YES;
[book_ update];
- }*/
+ }
/*[hud show:NO];
[hud removeFromSuperview];*/
White_.Set(space_, 1.0, 1.0, 1.0, 1.0);
Gray_.Set(space_, 0.4, 0.4, 0.4, 1.0);
+ Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];
+
SectionMap_ = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sections" ofType:@"plist"]] autorelease];
int value = UIApplicationMain(argc, argv, [Cydia class]);