X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/37fa9338c8b79e1212a8709b688fe13686837db5..3479309e59cd912a0be14d6c1c883ae5a87054a4:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 096c4ab5..8afda70c 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -66,6 +66,8 @@ #include +#include + #include #include @@ -206,8 +208,7 @@ void PrintTimes() { #define _end } /* }}} */ -#include "Version.h" -#define Cydia_ CYDIA_VERSION +extern NSString *Cydia_; #define lprintf(args...) fprintf(stderr, args) @@ -245,6 +246,11 @@ union SplitHash { }; // }}} +static NSString *Colon_; +NSString *Elision_; +static NSString *Error_; +static NSString *Warning_; + static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); static _finline NSString *CydiaURL(NSString *path) { @@ -267,9 +273,9 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) { 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 */ @@ -708,6 +714,8 @@ static time_t now_; bool IsWildcat_; static CGFloat ScreenScale_; static NSString *Idiom_; +static NSString *Firmware_; +static NSString *Major_; static _H SessionData_; static _H HostConfig_; @@ -741,8 +749,13 @@ static void WriteSources() { FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w")); _assert(file != NULL); - fprintf(file, "deb http://%s/ tangelo main\n", - [CydiaSource_ UTF8String] + NSString *distribution(@"ios"); + if (Firmware_ != nil) + distribution = [distribution stringByAppendingString:[NSString stringWithFormat:@"-%@", Firmware_]]; + + fprintf(file, "deb http://%s/ %s main\n", + [CydiaSource_ UTF8String], + [distribution UTF8String] ); for (NSString *key in [Sources_ allKeys]) { @@ -871,6 +884,8 @@ static NSString *CYHex(NSData *data, bool reverse = false) { @class CYPackageController; @protocol CydiaDelegate +- (void) returnToCydia; +- (void) saveState; - (void) retainNetworkActivityIndicator; - (void) releaseNetworkActivityIndicator; - (void) clearPackage:(Package *)package; @@ -922,6 +937,7 @@ class Status : } virtual void IMSHit(pkgAcquire::ItemDesc &item) { + Done(item); } virtual void Fetch(pkgAcquire::ItemDesc &item) { @@ -931,6 +947,9 @@ class Status : } virtual void Done(pkgAcquire::ItemDesc &item) { + NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]); + CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:Colon_, UCLocalize("DONE"), name] ofType:kCydiaProgressEventTypeStatus forItem:item]); + [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES]; } virtual void Fail(pkgAcquire::ItemDesc &item) { @@ -1305,6 +1324,10 @@ static void PackageImport(const void *key, const void *value, void *context) { /* Source Class {{{ */ @interface Source : NSObject { + unsigned era_; + Database *database_; + metaIndex *index_; + CYString depiction_; CYString description_; CYString label_; @@ -1326,7 +1349,7 @@ static void PackageImport(const void *key, const void *value, void *context) { BOOL trusted_; } -- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool; +- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool; - (NSComparisonResult) compareByNameAndType:(Source *)source; @@ -1381,6 +1404,8 @@ static void PackageImport(const void *key, const void *value, void *context) { if (false); else if (selector == @selector(addSection:)) return @"addSection"; + else if (selector == @selector(getField:)) + return @"getField"; else if (selector == @selector(removeSection:)) return @"removeSection"; else if (selector == @selector(remove)) @@ -1478,17 +1503,48 @@ static void PackageImport(const void *key, const void *value, void *context) { authority_ = [url path]; } -- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool { +- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool { if ((self = [super init]) != nil) { + era_ = [database era]; + database_ = database; + index_ = index; + [self setMetaIndex:index inPool:pool]; } return self; } +- (NSString *) getField:(NSString *)name { +@synchronized (database_) { + if ([database_ era] != era_ || index_ == NULL) + return nil; + + debReleaseIndex *dindex(dynamic_cast(index_)); + if (dindex == NULL) + return nil; + + FileFd fd; + if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly)) { + _error->Discard(); + return nil; + } + + pkgTagFile tags(&fd); + + pkgTagSection section; + tags.Step(section); + + const char *start, *end; + if (!section.Find([name UTF8String], start, end)) + return (NSString *) [NSNull null]; + + return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]]; +} } + - (NSComparisonResult) compareByNameAndType:(Source *)source { NSDictionary *lhr = [self record]; NSDictionary *rhr = [source record]; - if (lhr != rhr) + if ((lhr == nil) != (rhr == nil)) return lhr == nil ? NSOrderedDescending : NSOrderedAscending; NSString *lhs = [self name]; @@ -1787,8 +1843,10 @@ static void PackageImport(const void *key, const void *value, void *context) { /* }}} */ /* Package Class {{{ */ struct ParsedPackage { + CYString md5sum_; CYString tagline_; + CYString architecture_; CYString icon_; CYString depiction_; @@ -2081,6 +2139,7 @@ struct PackageNameOrdering : + (NSArray *) _attributeKeys { return [NSArray arrayWithObjects: @"applications", + @"architecture", @"author", @"depiction", @"essential", @@ -2092,6 +2151,7 @@ struct PackageNameOrdering : @"longDescription", @"longSection", @"maintainer", + @"md5sum", @"mode", @"name", @"purposes", @@ -2127,6 +2187,12 @@ struct PackageNameOrdering : return relations; } } +- (NSString *) architecture { + [self parse]; +@synchronized (database_) { + return parsed_->architecture_.empty() ? [NSNull null] : (id) parsed_->architecture_; +} } + - (NSString *) getField:(NSString *)name { @synchronized (database_) { if ([database_ era] != era_ || file_.end()) @@ -2138,7 +2204,7 @@ struct PackageNameOrdering : if (!parser.Find([name UTF8String], start, end)) return (NSString *) [NSNull null]; - return [(NSString *) CYStringCreate(start, end - start) autorelease]; + return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]]; } } - (void) parse { @@ -2165,6 +2231,7 @@ struct PackageNameOrdering : const char *name_; CYString *value_; } names[] = { + {"architecture", &parsed->architecture_}, {"icon", &parsed->icon_}, {"depiction", &parsed->depiction_}, {"homepage", &parsed->homepage_}, @@ -2173,6 +2240,7 @@ struct PackageNameOrdering : {"support", &parsed->support_}, {"sponsor", &parsed->sponsor_}, {"author", &parsed->author_}, + {"md5sum", &parsed->md5sum_}, }; for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) { @@ -2402,6 +2470,10 @@ struct PackageNameOrdering : 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()) @@ -2433,8 +2505,29 @@ struct PackageNameOrdering : } } - (NSString *) shortDescription { - return parsed_ == NULL ? nil : static_cast(parsed_->tagline_); -} + if (parsed_ != NULL) + return static_cast(parsed_->tagline_); + +@synchronized (database_) { + pkgRecords::Parser &parser([database_ records]->Lookup(file_)); + + const char *start, *end; + if (!parser.ShortDesc(start, end)) + return nil; + + if (end - start > 200) + end = start + 200; + + /* + if (const char *stop = reinterpret_cast(memchr(start, '\n', end - start))) + end = stop; + + while (end != start && end[-1] == '\r') + --end; + */ + + return [(id) CYStringCreate(start, end - start) autorelease]; +} } - (unichar) index { _profile(Package$index) @@ -2812,8 +2905,6 @@ struct PackageNameOrdering : NSRange range; NSUInteger length; - [self parse]; - string = [self name]; length = [string length]; @@ -2836,7 +2927,7 @@ struct PackageNameOrdering : string = [self shortDescription]; length = [string length]; - NSUInteger stop(std::min(length, 100)); + NSUInteger stop(std::min(length, 200)); for (NSString *term in query) { range = [string rangeOfString:term options:MatchCompareOptions_ range:NSMakeRange(0, stop)]; @@ -3115,11 +3206,6 @@ struct PackageNameOrdering : @end /* }}} */ -static NSString *Colon_; -NSString *Elision_; -static NSString *Error_; -static NSString *Warning_; - class CydiaLogCleaner : public pkgArchiveCleaner { @@ -3265,6 +3351,8 @@ class CydiaLogCleaner : } - (Package *) packageWithName:(NSString *)name { + if (name == nil) + return nil; @synchronized (self) { if (static_cast(cache_) == NULL) return nil; @@ -3503,7 +3591,7 @@ class CydiaLogCleaner : } for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) { - Source *object([[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease]); + Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:pool_] autorelease]); [sourceList_ addObject:object]; std::vector *indices = (*source)->GetIndexFiles(); @@ -3906,7 +3994,7 @@ static _H Diversions_; } - (NSString *) version { - return @ Cydia_; + return Cydia_; } - (NSString *) device { @@ -4442,7 +4530,9 @@ static _H Diversions_; return request_ == nil ? nil : [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]]; } -+ (void) initialize { ++ (void) _initialize { + [super _initialize]; + Diversions_ = [NSMutableSet setWithCapacity:0]; } @@ -4513,7 +4603,7 @@ static _H Diversions_; } - (NSString *) applicationNameForUserAgent { - NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]); + NSString *application([NSString stringWithFormat:@"Cydia/%@", Cydia_]); if (Safari_ != nil) application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application]; @@ -4531,6 +4621,18 @@ static _H Diversions_; } return self; } +@end + +@interface AppCacheController : CydiaWebViewController { +} + +@end + +@implementation AppCacheController + +- (void) didReceiveMemoryWarning { +} + @end /* }}} */ @@ -4636,8 +4738,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) _doContinue { - [self dismissModalViewControllerAnimated:YES]; [delegate_ cancelAndClear:NO]; + [self dismissModalViewControllerAnimated:YES]; } - (id) invokeDefaultMethodWithArguments:(NSArray *)args { @@ -5072,8 +5174,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) close { UpdateExternalStatus(0); + if (Finish_ > 1) + [delegate_ saveState]; + switch (Finish_) { case 0: + [delegate_ returnToCydia]; break; case 1: @@ -5276,7 +5382,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { bool commercial_; _H source_; _H badge_; - _H package_; _H placard_; bool summarized_; } @@ -5318,83 +5423,84 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { source_ = nil; badge_ = nil; placard_ = nil; - package_ = nil; - [package parse]; + if (package == nil) + [content_ setBackgroundColor:[UIColor whiteColor]]; + else { + [package parse]; - Source *source = [package source]; + Source *source = [package source]; - icon_ = [package icon]; + icon_ = [package icon]; - if (NSString *name = [package name]) - name_ = [NSString stringWithString:name]; + if (NSString *name = [package name]) + name_ = [NSString stringWithString:name]; - NSString *description(nil); + NSString *description(nil); - if (description == nil && IsWildcat_) - description = [package longDescription]; - if (description == nil) - description = [package shortDescription]; + if (description == nil && IsWildcat_) + description = [package longDescription]; + if (description == nil) + description = [package shortDescription]; - if (description != nil) - description_ = [NSString stringWithString:description]; + if (description != nil) + description_ = [NSString stringWithString:description]; - commercial_ = [package isCommercial]; + commercial_ = [package isCommercial]; - package_ = package; + NSString *label = nil; + bool trusted = false; - NSString *label = nil; - bool trusted = false; + if (source != nil) { + label = [source label]; + trusted = [source trusted]; + } else if ([[package id] isEqualToString:@"firmware"]) + label = UCLocalize("APPLE"); + else + label = [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("UNKNOWN"), UCLocalize("LOCAL")]; - if (source != nil) { - label = [source label]; - trusted = [source trusted]; - } else if ([[package id] isEqualToString:@"firmware"]) - label = UCLocalize("APPLE"); - else - label = [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("UNKNOWN"), UCLocalize("LOCAL")]; + NSString *from(label); - NSString *from(label); + NSString *section = [package simpleSection]; + if (section != nil && ![section isEqualToString:label]) { + section = [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"]; + from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section]; + } - NSString *section = [package simpleSection]; - if (section != nil && ![section isEqualToString:label]) { - section = [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"]; - from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section]; - } + source_ = [NSString stringWithFormat:UCLocalize("FROM"), from]; - source_ = [NSString stringWithFormat:UCLocalize("FROM"), from]; + if (NSString *purpose = [package primaryPurpose]) + badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]]; - if (NSString *purpose = [package primaryPurpose]) - badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]]; + UIColor *color; + NSString *placard; - UIColor *color; - NSString *placard; + if (NSString *mode = [package mode]) { + if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) { + color = RemovingColor_; + //placard = @"removing"; + } else { + color = InstallingColor_; + //placard = @"installing"; + } - if (NSString *mode = [package_ mode]) { - if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) { - color = RemovingColor_; - //placard = @"removing"; + // XXX: the removing/installing placards are not @2x + placard = nil; } else { - color = InstallingColor_; - //placard = @"installing"; + color = [UIColor whiteColor]; + + if ([package installed] != nil) + placard = @"installed"; + else + placard = nil; } - // XXX: the removing/installing placards are not @2x - placard = nil; - } else { - color = [UIColor whiteColor]; + [content_ setBackgroundColor:color]; - if ([package installed] != nil) - placard = @"installed"; - else - placard = nil; + if (placard != nil) + placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]]; } - [content_ setBackgroundColor:color]; - - if (placard != nil) - placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]]; - [self setNeedsDisplay]; [content_ setNeedsDisplay]; } @@ -5679,14 +5785,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + package_ = nil; + files_ = nil; + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - - files_ = [NSMutableArray arrayWithCapacity:32]; } return self; } @@ -5694,7 +5801,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { package_ = nil; name_ = nil; - [files_ removeAllObjects]; + files_ = [NSMutableArray arrayWithCapacity:32]; if (package != nil) { package_ = package; @@ -5850,7 +5957,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ((self = [super init]) != nil) { database_ = database; buttons_ = [NSMutableArray arrayWithCapacity:4]; - name_ = [NSString stringWithString:name]; + name_ = name == nil ? @"" : [NSString stringWithString:name]; [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, (id) name_]]]; } return self; } @@ -5990,7 +6097,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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]; } @@ -6068,7 +6175,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]); if (cell == nil) cell = [[[PackageCell alloc] init] autorelease]; - [cell setPackage:[self packageAtIndexPath:path] asSummary:[self isSummarized]]; + + Package *package([database_ packageWithName:[[self packageAtIndexPath:path] id]]); + [cell setPackage:package asSummary:[self isSummarized]]; return cell; } @@ -6104,18 +6213,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { database_ = database; title_ = [title copy]; [[self navigationItem] setTitle:title_]; - -#if TryIndexedCollation - if ([[self class] hasIndexedCollation]) - index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles]; - else -#endif - index_ = [NSMutableArray arrayWithCapacity:32]; - - indices_ = [NSMutableDictionary dictionaryWithCapacity:32]; - - packages_ = [NSArray array]; - sections_ = [NSMutableArray arrayWithCapacity:16]; } return self; } @@ -6138,6 +6235,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + packages_ = nil; + sections_ = nil; + index_ = nil; + indices_ = nil; + [super releaseSubviews]; } @@ -6194,13 +6296,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { packages_ = packages; - [indices_ removeAllObjects]; - [sections_ removeAllObjects]; + indices_ = [NSMutableDictionary dictionaryWithCapacity:32]; + sections_ = [NSMutableArray arrayWithCapacity:16]; Section *section = nil; #if TryIndexedCollation if ([[self class] hasIndexedCollation]) { + index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles]; + id collation = [objc_getClass("UILocalizedIndexedCollation") currentCollation]; NSArray *titles = [collation sectionIndexTitles]; int secidx = -1; @@ -6233,7 +6337,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } else #endif { - [index_ removeAllObjects]; + index_ = [NSMutableArray arrayWithCapacity:32]; bool sectioned([self showsSections]); if (!sectioned) { @@ -6279,7 +6383,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) reloadData { [super reloadData]; - [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0]; + + if ([self shouldYield]) + [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0]; + else + [self _reloadData]; } - (void) resetCursor { @@ -6397,6 +6505,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSURL URLWithString:@"cydia://home"]; } +- (void) didReceiveMemoryWarning { +} + - (void) aboutButtonClicked { UIAlertView *alert([[[UIAlertView alloc] init] autorelease]); @@ -6811,7 +6922,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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; @@ -6895,8 +7006,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) reloadData { [super reloadData]; - if (UIViewController *visible = [self visibleViewController]) + UIViewController *visible([self visibleViewController]); + if (visible != nil) [visible reloadData]; + + // on the iPad, this view controller is ALSO visible. :( + if (IsWildcat_) + if (UIViewController *top = [self topViewController]) + if (top != visible) + [top reloadData]; } - (void) unloadData { @@ -7007,8 +7125,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (path == nil) goto fail; path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *section(Simplify(path)); - UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, [section stringByReplacingOccurrencesOfString:@" " withString:@"_"]]]); + UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, [path stringByReplacingOccurrencesOfString:@" " withString:@"_"]]]); if (icon == nil) icon = [UIImage applicationImageNamed:@"unknown.png"]; [self _returnPNGWithImage:icon forRequest:request]; @@ -7185,15 +7302,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + sections_ = nil; + filtered_ = nil; + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - - sections_ = [NSMutableArray arrayWithCapacity:16]; - filtered_ = [NSMutableArray arrayWithCapacity:16]; } return self; } @@ -7202,8 +7319,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSArray *packages = [database_ packages]; - [sections_ removeAllObjects]; - [filtered_ removeAllObjects]; + sections_ = [NSMutableArray arrayWithCapacity:16]; + filtered_ = [NSMutableArray arrayWithCapacity:16]; NSMutableDictionary *sections([NSMutableDictionary dictionaryWithCapacity:32]); @@ -7323,7 +7440,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]); if (cell == nil) cell = [[[PackageCell alloc] init] autorelease]; - [cell setPackage:[self packageAtIndexPath:path] asSummary:false]; + + Package *package([database_ packageWithName:[[self packageAtIndexPath:path] id]]); + [cell setPackage:package asSummary:false]; return cell; } @@ -7365,15 +7484,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + packages_ = nil; + sections_ = nil; + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - - packages_ = [NSArray array]; - sections_ = [NSMutableArray arrayWithCapacity:16]; } return self; } @@ -7418,7 +7537,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { goto reload; packages_ = packages; - [sections_ removeAllObjects]; + sections_ = [NSMutableArray arrayWithCapacity:16]; Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease]; Section *ignored = nil; @@ -7660,7 +7779,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation PackageSettingsController - (NSURL *) navigationURL { - return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", [package_ id]]]; + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", (id) name_]]; } - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { @@ -7956,6 +8075,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [content_ setDelegate:self]; [content_ setOpaque:YES]; + + [[content_ layer] setContentsGravity:kCAGravityTopLeft]; } return self; } @@ -7975,11 +8096,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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 @@ -7997,7 +8118,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation SourceController - (NSURL *) navigationURL { - return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [source_ name]]]; + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [key_ stringByAddingPercentEscapesIncludingReserved]]]; } - (id) initWithDatabase:(Database *)database source:(Source *)source { @@ -8346,7 +8467,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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_]; @@ -8362,13 +8483,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) releaseSubviews { list_ = nil; + sources_ = nil; + [super releaseSubviews]; } - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - sources_ = [NSMutableArray arrayWithCapacity:16]; } return self; } @@ -8379,7 +8501,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ([database_ popErrorWithTitle:UCLocalize("SOURCES") forOperation:list.ReadMainList()]) return; - [sources_ removeAllObjects]; + sources_ = [NSMutableArray arrayWithCapacity:16]; [sources_ addObjectsFromArray:[database_ sources]]; _trace(); [sources_ sortUsingSelector:@selector(compareByNameAndType:)]; @@ -8845,6 +8967,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } +- (void) returnToCydia { + [self _loaded]; +} + - (void) _saveConfig { _trace(); MetaFile_.Sync(); @@ -8987,8 +9113,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } [self _updateData]; - - [self refreshIfPossible]; } } - (void) updateData { @@ -9056,6 +9180,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) reloadData { [self reloadDataWithInvocation:nil]; + if ([database_ progressDelegate] == nil) + [self _loaded]; } - (void) syncData { @@ -9166,6 +9292,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { ++locked_; [self detachNewProgressSelector:@selector(perform_) toTarget:self forController:navigation title:@"RUNNING"]; --locked_; + [self refreshIfPossible]; } - (void) showSettings { @@ -9319,7 +9446,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (UIProgressHUD *) addProgressHUD { - UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window_] autorelease]); + UIProgressHUD *hud([[[UIProgressHUD alloc] init] autorelease]); [hud setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [window_ setUserInteractionEnabled:NO]; @@ -9331,7 +9458,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UIView *view([target view]); [view addSubview:hud]; - [hud show:YES]; + [hud showInView:[tabbar_ view]]; ++locked_; return hud; @@ -9339,7 +9466,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) removeProgressHUD:(UIProgressHUD *)hud { --locked_; - [hud show:NO]; + [hud hide]; [hud removeFromSuperview]; [window_ setUserInteractionEnabled:YES]; } @@ -9419,7 +9546,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; [(SourcesController *)controller showAddSourcePrompt]; } else { - Source *source = [database_ sourceWithKey:argument]; + Source *source = [database_ sourceWithKey:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease]; } } @@ -9478,15 +9605,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super applicationWillResignActive:application]; } -- (void) applicationWillTerminate:(UIApplication *)application { - Changed_ = true; +- (void) saveState { [Metadata_ setObject:[tabbar_ navigationURLCollection] forKey:@"InterfaceState"]; [Metadata_ setObject:[NSDate date] forKey:@"LastClosed"]; [Metadata_ setObject:[NSNumber numberWithInt:[tabbar_ selectedIndex]] forKey:@"InterfaceIndex"]; + Changed_ = true; [self _saveConfig]; } +- (void) applicationWillTerminate:(UIApplication *)application { + [self saveState]; +} + - (void) setConfigurationData:(NSString *)data { static Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$"); @@ -9570,7 +9701,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [tabbar_ setUpdateDelegate:self]; } +- (void) _sendMemoryWarningNotification { + [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidReceiveMemoryWarningNotification" object:[UIApplication sharedApplication]]; +} + +- (void) _sendMemoryWarningNotifications { + while (true) { + [self performSelectorOnMainThread:@selector(_sendMemoryWarningNotification) withObject:nil waitUntilDone:NO]; + usleep(250000); + } +} + - (void) applicationDidFinishLaunching:(id)unused { + //[NSThread detachNewThreadSelector:@selector(_sendMemoryWarningNotifications) toTarget:self withObject:nil]; + _trace(); if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)]) [self setApplicationSupportsShakeToEdit:NO]; @@ -9602,7 +9746,7 @@ _trace(); broken_ = [NSMutableArray arrayWithCapacity:4]; // XXX: I really need this thing... like, seriously... I'm sorry - [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData]; + [[[AppCacheController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData]; window_ = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; [window_ orderFront:self]; @@ -9669,7 +9813,8 @@ _trace(); [window_ setUserInteractionEnabled:NO]; } - [self reloadData]; + [self reloadDataWithInvocation:nil]; + [self refreshIfPossible]; PrintTimes(); [self disemulate]; @@ -9894,6 +10039,13 @@ int main(int argc, char *argv[]) { NSLog(@"unknown UIUserInterfaceIdiom!"); } + Pcre pattern("^([0-9]+\\.[0-9]+)"); + + if (pattern([device systemVersion])) + Firmware_ = pattern[1]; + if (pattern(Cydia_)) + Major_ = pattern[1]; + SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4]; HostConfig_ = [[[NSObject alloc] init] autorelease]; @@ -9905,7 +10057,11 @@ int main(int argc, char *argv[]) { CachedURLs_ = [NSMutableSet setWithCapacity:32]; } - UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]); + 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(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname)))); @@ -10135,6 +10291,8 @@ int main(int argc, char *argv[]) { Version_ = [NSNumber numberWithUnsignedInt:1]; [Metadata_ setObject:Version_ forKey:@"Version"]; + [Metadata_ removeObjectForKey:@"LastUpdate"]; + Changed_ = true; } /* }}} */