#include <IOKit/IOKitLib.h>
+#include <QuartzCore/CALayer.h>
+
#include <WebCore/WebCoreThread.h>
#include <algorithm>
#include <errno.h>
#include <Cytore.hpp>
+#include "Sources.h"
#include <CydiaSubstrate/CydiaSubstrate.h>
#include "Menes/Menes.h"
#define _end }
/* }}} */
-#include "Version.h"
-#define Cydia_ CYDIA_VERSION
+extern NSString *Cydia_;
#define lprintf(args...) fprintf(stderr, args)
notify_post("com.saurik.Cydia.status");
}
-static CGFloat CYStatusBarHeight(UIInterfaceOrientation orientation) {
+static CGFloat CYStatusBarHeight() {
CGSize size([[UIApplication sharedApplication] statusBarFrame].size);
- return UIInterfaceOrientationIsPortrait(orientation) ? size.height : size.width;
+ return UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? size.height : size.width;
}
/* NSForcedOrderingSearch doesn't work on the iPhone */
static _transient NSMutableDictionary *Packages_;
static _transient NSMutableDictionary *Values_;
static _transient NSMutableDictionary *Sections_;
-static _transient NSMutableDictionary *Sources_;
+_H<NSMutableDictionary> Sources_;
static _transient NSNumber *Version_;
-static _transient _H<NSString> CydiaSource_;
-static bool Changed_;
+_H<NSString> CydiaSource_;
+bool Changed_;
static time_t now_;
bool IsWildcat_;
static CGFloat ScreenScale_;
static NSString *Idiom_;
-static NSString *Firmware_;
+_H<NSString> Firmware_;
+static NSString *Major_;
static _H<NSMutableDictionary> SessionData_;
static _H<NSObject> HostConfig_;
static NSString *kCydiaProgressEventTypeWarning = @"Warning";
/* }}} */
-static void AddSource(NSDictionary *source) {
- [Sources_ setObject:source forKey:[NSString stringWithFormat:@"%@:%@:%@", [source objectForKey:@"Type"], [source objectForKey:@"URI"], [source objectForKey:@"Distribution"]]];
- Changed_ = true;
-}
-
-static void AddSource(NSString *href, NSString *distribution, NSArray *sections = nil) {
- AddSource([NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"deb", @"Type",
- href, @"URI",
- distribution, @"Distribution",
- sections ?: [NSMutableArray array], @"Sections",
- nil]);
-}
-
-static void WriteSources() {
- FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w"));
- _assert(file != NULL);
-
- fprintf(file, "deb http://%s/ tangelo-3.7 main\n",
- [CydiaSource_ UTF8String]
- );
-
- for (NSString *key in [Sources_ allKeys]) {
- NSDictionary *source([Sources_ objectForKey:key]);
-
- NSArray *sections([source objectForKey:@"Sections"] ?: [NSArray array]);
-
- fprintf(file, "%s %s %s%s%s\n",
- [[source objectForKey:@"Type"] UTF8String],
- [[source objectForKey:@"URI"] UTF8String],
- [[source objectForKey:@"Distribution"] UTF8String],
- [sections count] == 0 ? "" : " ",
- [[sections componentsJoinedByString:@" "] UTF8String]
- );
- }
-
- fclose(file);
-}
-
/* Display Helpers {{{ */
inline float Interpolate(float begin, float end, float fraction) {
return (end - begin) * fraction + begin;
- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool;
-- (NSComparisonResult) compareByNameAndType:(Source *)source;
+- (NSComparisonResult) compareByName:(Source *)source;
- (NSString *) depictionForPackage:(NSString *)package;
- (NSString *) supportForPackage:(NSString *)package;
- (NSDictionary *) record;
- (BOOL) trusted;
-- (NSString *) uri;
+- (NSString *) rooturi;
- (NSString *) distribution;
- (NSString *) type;
-- (NSString *) base;
-
- (NSString *) key;
- (NSString *) host;
- (NSString *) version;
- (NSString *) defaultIcon;
+- (NSURL *) iconURL;
@end
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
+ @"baseuri",
@"distribution",
@"host",
@"key",
+ @"iconuri",
@"label",
@"name",
@"origin",
+ @"rooturi",
@"sections",
@"shortDescription",
@"trusted",
@"type",
- @"uri",
@"version",
nil];
}
return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]];
} }
-- (NSComparisonResult) compareByNameAndType:(Source *)source {
- NSDictionary *lhr = [self record];
- NSDictionary *rhr = [source record];
-
- if ((lhr == nil) != (rhr == nil))
- return lhr == nil ? NSOrderedDescending : NSOrderedAscending;
-
+- (NSComparisonResult) compareByName:(Source *)source {
NSString *lhs = [self name];
NSString *rhs = [source name];
return trusted_;
}
-- (NSString *) uri {
+- (NSString *) rooturi {
return uri_;
}
return type_;
}
-- (NSString *) base {
- return base_;
+- (NSString *) baseuri {
+ return base_.empty() ? nil : (id) base_;
+}
+
+- (NSString *) iconuri {
+ if (NSString *base = [self baseuri])
+ return [base stringByAppendingString:@"CydiaIcon.png"];
+
+ return nil;
+}
+
+- (NSURL *) iconURL {
+ if (NSString *uri = [self iconuri])
+ return [NSURL URLWithString:uri];
+ return nil;
}
- (NSString *) key {
/* }}} */
/* Package Class {{{ */
struct ParsedPackage {
+ CYString md5sum_;
CYString tagline_;
CYString architecture_;
};
@interface Package : NSObject {
- uint32_t era_ : 26;
+ uint32_t era_ : 25;
uint32_t role_ : 3;
uint32_t essential_ : 1;
uint32_t obsolete_ : 1;
uint32_t ignored_ : 1;
+ uint32_t pooled_ : 1;
apr_pool_t *pool_;
}
- (void) dealloc {
+ if (!pooled_)
+ apr_pool_destroy(pool_);
if (parsed_ != NULL)
delete parsed_;
[super dealloc];
@"longDescription",
@"longSection",
@"maintainer",
+ @"md5sum",
@"mode",
@"name",
@"purposes",
{"support", &parsed->support_},
{"sponsor", &parsed->sponsor_},
{"author", &parsed->author_},
+ {"md5sum", &parsed->md5sum_},
};
for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
if ((self = [super init]) != nil) {
_profile(Package$initWithVersion)
- pool_ = pool;
+ if (pool == NULL)
+ apr_pool_create(&pool_, NULL);
+ else {
+ pool_ = pool;
+ pooled_ = true;
+ }
database_ = database;
era_ = [database era];
return maintainer.empty() ? nil : [MIMEAddress addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
} }
+- (NSString *) md5sum {
+ return parsed_ == NULL ? nil : (id) parsed_->md5sum_;
+}
+
- (size_t) size {
@synchronized (database_) {
if ([database_ era] != era_ || version_.end())
if (static_cast<pkgDepCache *>(cache_) == NULL)
return nil;
pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String]));
- return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:pool_ database:self];
+ return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:NULL database:self];
} }
- (id) init {
}
- (NSString *) version {
- return @ Cydia_;
+ return Cydia_;
}
- (NSString *) device {
return request_ == nil ? nil : [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]];
}
-+ (void) initialize {
++ (void) _initialize {
+ [super _initialize];
+
Diversions_ = [NSMutableSet setWithCapacity:0];
}
if ([url isCydiaSecure] && token) {
if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil)
[copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+ if (UniqueID_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Id"] == nil)
+ [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
}
return copy;
}
- (NSString *) applicationNameForUserAgent {
- NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]);
+ NSString *application([NSString stringWithFormat:@"Cydia/%@", Cydia_]);
if (Safari_ != nil)
application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application];
CGRect rect;
rect.size = [(UIImage *) icon_ size];
- rect.size.width /= 4;
- rect.size.height /= 4;
+ while (rect.size.width > 16 || rect.size.height > 16) {
+ rect.size.width /= 2;
+ rect.size.height /= 2;
+ }
- rect.origin.x = 14 - rect.size.width / 4;
- rect.origin.y = 14 - rect.size.height / 4;
+ rect.origin.x = 18 - rect.size.width / 2;
+ rect.origin.y = 18 - rect.size.height / 2;
[icon_ drawInRect:rect];
}
rect.size.width /= 4;
rect.size.height /= 4;
- rect.origin.x = 20 - rect.size.width / 4;
- rect.origin.y = 20 - rect.size.height / 4;
+ rect.origin.x = 23 - rect.size.width / 2;
+ rect.origin.y = 23 - rect.size.height / 2;
[badge_ drawInRect:rect];
}
CGRect rect;
rect.size = [(UIImage *) icon_ size];
- rect.size.width /= 2;
- rect.size.height /= 2;
+ while (rect.size.width > 32 || rect.size.height > 32) {
+ rect.size.width /= 2;
+ rect.size.height /= 2;
+ }
rect.origin.x = 25 - rect.size.width / 2;
rect.origin.y = 25 - rect.size.height / 2;
CGRect intersection = CGRectIntersection(viewframe, kbframe);
if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
- intersection.size.height += CYStatusBarHeight([self interfaceOrientation]);
+ intersection.size.height += CYStatusBarHeight();
[self resizeForKeyboardBounds:intersection duration:duration curve:curve];
}
return items;
}
+- (void) dismissModalViewControllerAnimated:(BOOL)animated {
+ if ([self modalViewController] == nil && [self unselectedViewController] != nil)
+ [self setUnselectedViewController:nil];
+ else
+ [super dismissModalViewControllerAnimated:YES];
+}
+
- (void) unloadData {
[super unloadData];
CGRect barframe([refreshbar_ frame]);
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
- barframe.origin.y = CYStatusBarHeight([self interfaceOrientation]);
+ barframe.origin.y = CYStatusBarHeight();
else
barframe.origin.y = 0;
[package parse];
UIImage *icon([package icon]);
[self _returnPNGWithImage:icon forRequest:request];
- } else if ([command isEqualToString:@"source-icon"]) {
- if (path == nil)
- goto fail;
- path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSString *source(Simplify(path));
- UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sources/%@.png", App_, source]]);
- if (icon == nil)
- icon = [UIImage applicationImageNamed:@"unknown.png"];
- [self _returnPNGWithImage:icon forRequest:request];
} else if ([command isEqualToString:@"uikit-image"]) {
if (path == nil)
goto fail;
[content_ setNeedsDisplay];
}
-- (void) _setSource:(Source *)source {
+- (void) _setSource:(NSURL *) url {
NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
- if (NSString *base = [source base])
- if ([base length] != 0) {
- NSURL *url([NSURL URLWithString:[base stringByAppendingString:@"CydiaIcon.png"]]);
-
- if (NSData *data = [NSURLConnection
- sendSynchronousRequest:[NSURLRequest
- requestWithURL:url
- //cachePolicy:NSURLRequestUseProtocolCachePolicy
- //timeoutInterval:5
- ]
-
- returningResponse:NULL
- error:NULL
- ])
- if (UIImage *image = [UIImage imageWithData:data])
- [self performSelectorOnMainThread:@selector(_setImage:) withObject:image waitUntilDone:NO];
- }
+ if (NSData *data = [NSURLConnection
+ sendSynchronousRequest:[NSURLRequest
+ requestWithURL:url
+ //cachePolicy:NSURLRequestUseProtocolCachePolicy
+ //timeoutInterval:5
+ ]
+
+ returningResponse:NULL
+ error:NULL
+ ])
+ if (UIImage *image = [UIImage imageWithData:data])
+ [self performSelectorOnMainThread:@selector(_setImage:) withObject:image waitUntilDone:NO];
[pool release];
}
icon_ = [UIImage applicationImageNamed:@"unknown.png"];
origin_ = [source name];
- label_ = [source uri];
+ label_ = [source rooturi];
[content_ setNeedsDisplay];
- [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:source];
+ if (NSURL *url = [source iconURL])
+ [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:url];
}
- (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
[content_ setDelegate:self];
[content_ setOpaque:YES];
+
+ [[content_ layer] setContentsGravity:kCAGravityTopLeft];
} return self;
}
bool highlighted(highlighted_);
float width(rect.size.width);
- if (icon_ != nil)
- [icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
+ if (icon_ != nil) {
+ CGRect rect;
+ rect.size = [(UIImage *) icon_ size];
+
+ while (rect.size.width > 32 || rect.size.height > 32) {
+ rect.size.width /= 2;
+ rect.size.height /= 2;
+ }
+
+ rect.origin.x = 25 - rect.size.width / 2;
+ rect.origin.y = 25 - rect.size.height / 2;
+
+ [icon_ drawInRect:rect];
+ }
if (highlighted)
UISetColor(White_);
if (!highlighted)
UISetColor(Black_);
- [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
+ [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 60) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
if (!highlighted)
UISetColor(Blue_);
- [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
+ [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 75) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
}
@end
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
- return offset_ == 0 ? 1 : 2;
+ return 1;
}
- (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");
-
- _nodefault
- }
+ return nil;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- int count = [sources_ count];
- switch (section) {
- case 0: return (offset_ == 0 ? count : offset_);
- case 1: return count - offset_;
-
- _nodefault
- }
+ return [sources_ count];
}
- (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath {
- unsigned idx = 0;
- switch (indexPath.section) {
- case 0: idx = indexPath.row; break;
- case 1: idx = indexPath.row + offset_; break;
-
- _nodefault
- }
- return [sources_ objectAtIndex:idx];
+ return [sources_ objectAtIndex:[indexPath row]];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[delegate_ removeProgressHUD:hud_];
hud_ = nil;
- bool defer(false);
-
if (cydia_) {
if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
- defer = true;
-
UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:UCLocalize("SOURCE_WARNING")
message:warning
[alert setContext:@"warning"];
[alert setNumberOfRows:1];
[alert show];
- } else
- [self complete];
+
+ // XXX: there used to be this great mechanism called yieldToPopup... who deleted it?
+ error_ = nil;
+ return;
+ }
+
+ [self complete];
} else if (error_ != nil) {
UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:UCLocalize("VERIFICATION_ERROR")
[request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
if ([url isCydiaSecure]) {
- if (UniqueID_ != nil)
+ if (UniqueID_ != nil) {
[request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+ [request setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
+ }
}
return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
[list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
- [list_ setRowHeight:56];
+ [list_ setRowHeight:53];
[(UITableView *) list_ setDataSource:self];
[list_ setDelegate:self];
[[self view] addSubview:list_];
sources_ = [NSMutableArray arrayWithCapacity:16];
[sources_ addObjectsFromArray:[database_ sources]];
_trace();
- [sources_ sortUsingSelector:@selector(compareByNameAndType:)];
+ [sources_ sortUsingSelector:@selector(compareByName:)];
_trace();
int count([sources_ count]);
UCLocalize("DEVELOPER"),
nil];
segment_ = [[[UISegmentedControl alloc] initWithItems:items] autorelease];
+ [segment_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin)];
container_ = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)] autorelease];
[container_ addSubview:segment_];
}
}
}
- WriteSources();
+ CydiaWriteSources();
}
// Navigation controller for the queuing badge.
}
- (void) addSource:(NSDictionary *) source {
- AddSource(source);
+ CydiaAddSource(source);
}
- (void) addSource:(NSString *)href withDistribution:(NSString *)distribution andSections:(NSArray *)sections {
- AddSource(href, distribution, sections);
+ CydiaAddSource(href, distribution, sections);
}
- (void) addTrivialSource:(NSString *)href {
- AddSource(href, @"./");
+ CydiaAddSource(href, @"./");
}
- (void) updateValues {
}
Pcre pattern("^([0-9]+\\.[0-9]+)");
+
if (pattern([device systemVersion]))
Firmware_ = pattern[1];
+ if (pattern(Cydia_))
+ Major_ = pattern[1];
SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4];
NSString *ui(@"ui/ios");
if (Idiom_ != nil)
ui = [ui stringByAppendingString:[NSString stringWithFormat:@"~%@", Idiom_]];
+ ui = [ui stringByAppendingString:[NSString stringWithFormat:@"/%@", Major_]];
UI_ = CydiaURL(ui);
PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
}
if ([Version_ unsignedIntValue] == 0) {
- AddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
- AddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
- AddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
- AddSource(@"http://repo666.ultrasn0w.com/", @"./");
+ CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+ CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+ CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+ CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
Version_ = [NSNumber numberWithUnsignedInt:1];
[Metadata_ setObject:Version_ forKey:@"Version"];
}
/* }}} */
- WriteSources();
+ CydiaWriteSources();
_trace();
MetaFile_.Open("/var/lib/cydia/metadata.cb0");