X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/9dac415b3549213d312f7be3f971c322a3d63a5b..df27070399c61922ec227823602f0d7f06043726:/MobileCydia.mm?ds=sidebyside diff --git a/MobileCydia.mm b/MobileCydia.mm index e278ab86..c072c267 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -41,8 +41,8 @@ #define USE_SYSTEM_MALLOC 1 /* #include Directives {{{ */ -#include "UICaboodle/UCPlatform.h" -#include "UICaboodle/UCLocalize.h" +#include "CyteKit/UCPlatform.h" +#include "CyteKit/Localize.h" #include #include @@ -117,14 +117,22 @@ extern "C" { #include #include -#include #include -#include "UICaboodle/BrowserView.h" +#include "Menes/Menes.h" + +#include "CyteKit/PerlCompatibleRegEx.hpp" +#include "CyteKit/TableViewCell.h" +#include "CyteKit/WebScriptObject-Cyte.h" +#include "CyteKit/WebViewController.h" +#include "CyteKit/stringWithUTF8Bytes.h" + +#include "Cydia/ProgressEvent.h" + #include "SDURLCache/SDURLCache.h" -#include "substrate.h" +#include /* }}} */ /* Profiler {{{ */ @@ -266,206 +274,11 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) { notify_post("com.saurik.Cydia.status"); } -/* [NSObject yieldToSelector:(withObject:)] {{{*/ -@interface NSObject (Cydia) -- (id) yieldToSelector:(SEL)selector withObject:(id)object; -- (id) yieldToSelector:(SEL)selector; -@end - -@implementation NSObject (Cydia) - -- (void) doNothing { -} - -- (void) _yieldToContext:(NSMutableArray *)context { _pooled - SEL selector(reinterpret_cast([[context objectAtIndex:0] pointerValue])); - id object([[context objectAtIndex:1] nonretainedObjectValue]); - volatile bool &stopped(*reinterpret_cast([[context objectAtIndex:2] pointerValue])); - - /* XXX: deal with exceptions */ - id value([self performSelector:selector withObject:object]); - - NSMethodSignature *signature([self methodSignatureForSelector:selector]); - [context removeAllObjects]; - if ([signature methodReturnLength] != 0 && value != nil) - [context addObject:value]; - - stopped = true; - - [self - performSelectorOnMainThread:@selector(doNothing) - withObject:nil - waitUntilDone:NO - ]; -} - -- (id) yieldToSelector:(SEL)selector withObject:(id)object { - volatile bool stopped(false); - - NSMutableArray *context([NSMutableArray arrayWithObjects: - [NSValue valueWithPointer:selector], - [NSValue valueWithNonretainedObject:object], - [NSValue valueWithPointer:const_cast(&stopped)], - nil]); - - NSThread *thread([[[NSThread alloc] - initWithTarget:self - selector:@selector(_yieldToContext:) - object:context - ] autorelease]); - - [thread start]; - - NSRunLoop *loop([NSRunLoop currentRunLoop]); - NSDate *future([NSDate distantFuture]); - NSString *mode([loop currentMode] ?: NSDefaultRunLoopMode); - -_trace(); - while (!stopped && [loop runMode:mode beforeDate:future]); -_trace(); - - return [context count] == 0 ? nil : [context objectAtIndex:0]; -} - -- (id) yieldToSelector:(SEL)selector { - return [self yieldToSelector:selector withObject:nil]; -} - -@end -/* }}} */ - -/* Cydia Alert View {{{ */ -@interface CYAlertView : UIAlertView { - unsigned button_; -} - -- (int) yieldToPopupAlertAnimated:(BOOL)animated; - -@end - -@implementation CYAlertView - -- (id) initWithTitle:(NSString *)title buttons:(NSArray *)buttons defaultButtonIndex:(int)index { - if ((self = [super init]) != nil) { - [self setTitle:title]; - [self setDelegate:self]; - for (NSString *button in buttons) [self addButtonWithTitle:button]; - [self setCancelButtonIndex:index]; - } return self; -} - -- (void) _updateFrameForDisplay { - [super _updateFrameForDisplay]; - if ([self cancelButtonIndex] == -1) { - NSArray *buttons = [self buttons]; - if ([buttons count]) { - UIImage *background = [[buttons objectAtIndex:0] backgroundForState:0]; - for (UIThreePartButton *button in buttons) - [button setBackground:background forState:0]; - } - } -} - -- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - button_ = buttonIndex + 1; -} - -- (void) dismiss { - [self dismissWithClickedButtonIndex:-1 animated:YES]; -} - -- (int) yieldToPopupAlertAnimated:(BOOL)animated { - [self setRunsModal:YES]; - button_ = 0; - [self show]; - return button_; -} - -@end -/* }}} */ - /* NSForcedOrderingSearch doesn't work on the iPhone */ static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch; static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch; static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive | kCFCompareNonliteral | kCFCompareLocalized | kCFCompareNumerically | kCFCompareWidthInsensitive | kCFCompareForcedOrdering; -/* Radix Sort {{{ */ -typedef uint32_t (*SKRadixFunction)(id, void *); - -@interface NSMutableArray (Radix) -- (void) radixSortUsingFunction:(SKRadixFunction)function withContext:(void *)argument; -@end - -struct RadixItem_ { - size_t index; - uint32_t key; -}; - -@implementation NSMutableArray (Radix) - -- (void) radixSortUsingFunction:(SKRadixFunction)function withContext:(void *)argument { - size_t count([self count]); - struct RadixItem_ *swap(new RadixItem_[count * 2]); - - for (size_t i(0); i != count; ++i) { - RadixItem_ &item(swap[i]); - item.index = i; - - id object([self objectAtIndex:i]); - item.key = function(object, argument); - } - - struct RadixItem_ *lhs(swap), *rhs(swap + count); - - static const size_t width = 32; - static const size_t bits = 11; - static const size_t slots = 1 << bits; - static const size_t passes = (width + (bits - 1)) / bits; - - size_t *hist(new size_t[slots]); - - for (size_t pass(0); pass != passes; ++pass) { - memset(hist, 0, sizeof(size_t) * slots); - - for (size_t i(0); i != count; ++i) { - uint32_t key(lhs[i].key); - key >>= pass * bits; - key &= _not(uint32_t) >> width - bits; - ++hist[key]; - } - - size_t offset(0); - for (size_t i(0); i != slots; ++i) { - size_t local(offset); - offset += hist[i]; - hist[i] = local; - } - - for (size_t i(0); i != count; ++i) { - uint32_t key(lhs[i].key); - key >>= pass * bits; - key &= _not(uint32_t) >> width - bits; - rhs[hist[key]++] = lhs[i]; - } - - RadixItem_ *tmp(lhs); - lhs = rhs; - rhs = tmp; - } - - delete [] hist; - - const void **values(new const void *[count]); - for (size_t i(0); i != count; ++i) - values[i] = [self objectAtIndex:lhs[i].index]; - CFArrayReplaceValues((CFMutableArrayRef) self, CFRangeMake(0, count), values, count); - delete [] values; - - delete [] swap; -} - -@end -/* }}} */ /* Insertion Sort {{{ */ CFIndex SKBSearch_(const void *element, CFIndex elementSize, const void *list, CFIndex count, CFComparatorFunction comparator, void *context) { @@ -570,38 +383,6 @@ void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFCompar @end /* }}} */ -@interface NSInvocation (Cydia) -+ (NSInvocation *) invocationWithSelector:(SEL)selector forTarget:(id)target; -@end - -@implementation NSInvocation (Cydia) - -+ (NSInvocation *) invocationWithSelector:(SEL)selector forTarget:(id)target { - NSInvocation *invocation([NSInvocation invocationWithMethodSignature:[target methodSignatureForSelector:selector]]); - [invocation setTarget:target]; - [invocation setSelector:selector]; - return invocation; -} - -@end - -@implementation WebScriptObject (NSFastEnumeration) - -- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count { - size_t length([self count] - state->state); - if (length <= 0) - return 0; - else if (length > count) - length = count; - for (size_t i(0); i != length; ++i) - objects[i] = [self objectAtIndex:state->state++]; - state->itemsPtr = objects; - state->mutationsPtr = (unsigned long *) self; - return length; -} - -@end - NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) { size_t length([self length] - state->state); if (length <= 0) @@ -617,9 +398,6 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s /* Cydia NSString Additions {{{ */ @interface NSString (Cydia) -+ (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length; -+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length withZone:(NSZone *)zone inPool:(apr_pool_t *)pool; -+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length; - (NSComparisonResult) compareByPath:(NSString *)other; - (NSString *) stringByCachingURLWithCurrentCDN; - (NSString *) stringByAddingPercentEscapesIncludingReserved; @@ -627,20 +405,6 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s @implementation NSString (Cydia) -+ (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length { - return [[[NSString alloc] initWithBytesNoCopy:const_cast(bytes) length:length encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease]; -} - -+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length withZone:(NSZone *)zone inPool:(apr_pool_t *)pool { - char *data(reinterpret_cast(apr_palloc(pool, length))); - memcpy(data, bytes, length); - return [[[NSString allocWithZone:zone] initWithBytesNoCopy:data length:length encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease]; -} - -+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length { - return [[[NSString alloc] initWithBytes:bytes length:length encoding:NSUTF8StringEncoding] autorelease]; -} - - (NSComparisonResult) compareByPath:(NSString *)other { NSString *prefix = [self commonPrefixWithString:other options:0]; size_t length = [prefix length]; @@ -834,73 +598,10 @@ struct NSStringMapEqual : }; /* }}} */ -/* Perl-Compatible RegEx {{{ */ -class Pcre { - private: - pcre *code_; - pcre_extra *study_; - int capture_; - int *matches_; - const char *data_; - - public: - Pcre() : - code_(NULL), - study_(NULL) - { - } - - Pcre(const char *regex) : - code_(NULL), - study_(NULL) - { - this->operator =(regex); - } - - void operator =(const char *regex) { - _assert(code_ == NULL); - - const char *error; - int offset; - code_ = pcre_compile(regex, 0, &error, &offset, NULL); - - if (code_ == NULL) { - lprintf("%d:%s\n", offset, error); - _assert(false); - } - - pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_); - matches_ = new int[(capture_ + 1) * 3]; - } - - ~Pcre() { - pcre_free(code_); - delete matches_; - } - - NSString *operator [](size_t match) { - return [NSString stringWithUTF8Bytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2])]; - } - - bool operator ()(NSString *data) { - // XXX: length is for characters, not for bytes - return operator ()([data UTF8String], [data length]); - } - - bool operator ()(const char *data, size_t size) { - data_ = data; - return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0; - } - - _finline size_t size() const { - return capture_; - } -}; -/* }}} */ /* Mime Addresses {{{ */ @interface Address : NSObject { - NSString *name_; - NSString *address_; + _H name_; + _H address_; } - (NSString *) name; @@ -915,13 +616,6 @@ class Pcre { @implementation Address -- (void) dealloc { - [name_ release]; - if (address_ != nil) - [address_ release]; - [super dealloc]; -} - - (NSString *) name { return name_; } @@ -931,12 +625,7 @@ class Pcre { } - (void) setAddress:(NSString *)address { - if (address_ != nil) - [address_ autorelease]; - if (address == nil) - address_ = nil; - else - address_ = [address retain]; + address_ = address; } + (Address *) addressWithString:(NSString *)string { @@ -966,10 +655,10 @@ class Pcre { static Pcre address_r("^\"?(.*)\"? <([^>]*)>$"); if (address_r(data, size)) { - name_ = [address_r[1] retain]; - address_ = [address_r[2] retain]; + name_ = address_r[1]; + address_ = address_r[2]; } else { - name_ = [string retain]; + name_ = string; address_ = nil; } } return self; @@ -1051,16 +740,17 @@ static NSString *App_; static BOOL Advanced_; static BOOL Ignored_; -static UIFont *Font12_; -static UIFont *Font12Bold_; -static UIFont *Font14_; -static UIFont *Font18Bold_; -static UIFont *Font22Bold_; +static _H Font12_; +static _H Font12Bold_; +static _H Font14_; +static _H Font18Bold_; +static _H Font22Bold_; static const char *Machine_ = NULL; static NSString *System_ = nil; static NSString *SerialNumber_ = nil; static NSString *ChipID_ = nil; +static NSString *BBSNum_ = nil; static _H Token_; static NSString *UniqueID_ = nil; static NSString *PLMN_ = nil; @@ -1086,10 +776,10 @@ bool IsWildcat_; static CGFloat ScreenScale_; static NSString *Idiom_; -static NSMutableDictionary *SessionData_; -static NSObject *HostConfig_; -static NSMutableSet *BridgedHosts_; -static NSMutableSet *PipelinedHosts_; +static _H SessionData_; +static _H HostConfig_; +static _H BridgedHosts_; +static _H PipelinedHosts_; static NSString *kCydiaProgressEventTypeError = @"Error"; static NSString *kCydiaProgressEventTypeInformation = @"Information"; @@ -1162,6 +852,34 @@ bool isSectionVisible(NSString *section) { return hidden == nil || ![hidden boolValue]; } +static NSObject *CYIOGetValue(const char *path, NSString *property) { + io_registry_entry_t entry(IORegistryEntryFromPath(kIOMasterPortDefault, path)); + if (entry == MACH_PORT_NULL) + return nil; + + CFTypeRef value(IORegistryEntryCreateCFProperty(entry, (CFStringRef) property, kCFAllocatorDefault, 0)); + IOObjectRelease(entry); + + if (value == NULL) + return nil; + return [(id) value autorelease]; +} + +static NSString *CYHex(NSData *data, bool reverse = false) { + if (data == nil) + return nil; + + size_t length([data length]); + uint8_t bytes[length]; + [data getBytes:bytes]; + + char string[length * 2 + 1]; + for (size_t i(0); i != length; ++i) + sprintf(string + i * 2, "%.2x", bytes[reverse ? length - i - 1 : i]); + + return [NSString stringWithUTF8String:string]; +} + @class Cydia; /* Delegate Prototypes {{{ */ @@ -1194,57 +912,12 @@ bool isSectionVisible(NSString *section) { - (void) showSettings; - (UIProgressHUD *) addProgressHUD; - (void) removeProgressHUD:(UIProgressHUD *)hud; -- (CYViewController *) pageForPackage:(NSString *)name; +- (CyteViewController *) pageForPackage:(NSString *)name; - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item; - (void) reloadDataWithInvocation:(NSInvocation *)invocation; @end /* }}} */ -/* ProgressEvent Interface/Delegate {{{ */ -@interface CydiaProgressEvent : NSObject { - _H message_; - _H type_; - - _H item_; - _H package_; - _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 *) 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; -- (NSString *) compoundTitle; - -@end - -@protocol ProgressDelegate -- (void) addProgressEvent:(CydiaProgressEvent *)event; -- (void) setProgressPercent:(NSNumber *)percent; -- (void) setProgressStatus:(NSDictionary *)status; -- (void) setProgressCancellable:(NSNumber *)cancellable; -- (bool) isProgressCancelled; -- (void) setTitle:(NSString *)title; -@end -/* }}} */ /* Status Delegation {{{ */ class Status : public pkgAcquireStatus @@ -1358,7 +1031,7 @@ typedef std::map< unsigned long, _H > SourceMap; pkgSourceList *list_; SourceMap sourceMap_; - NSMutableArray *sourceList_; + _H sourceList_; CFMutableArrayRef packages_; @@ -1693,7 +1366,7 @@ static void PackageImport(const void *key, const void *value, void *context) { - (NSString *) host; - (NSString *) name; -- (NSString *) description; +- (NSString *) shortDescription; - (NSString *) label; - (NSString *) origin; - (NSString *) version; @@ -1722,21 +1395,15 @@ static void PackageImport(const void *key, const void *value, void *context) { authority_ = nil; } -- (void) dealloc { - // XXX: this is a very inefficient way to call these deconstructors - [self _clear]; - [super dealloc]; -} - + (NSArray *) _attributeKeys { return [NSArray arrayWithObjects: - @"description", @"distribution", @"host", @"key", @"label", @"name", @"origin", + @"shortDescription", @"trusted", @"type", @"uri", @@ -1880,7 +1547,7 @@ static void PackageImport(const void *key, const void *value, void *context) { return origin_.empty() ? (id) authority_ : origin_; } -- (NSString *) description { +- (NSString *) shortDescription { return description_; } @@ -1904,8 +1571,8 @@ static void PackageImport(const void *key, const void *value, void *context) { /* }}} */ /* CydiaOperation Class {{{ */ @interface CydiaOperation : NSObject { - NSString *operator_; - NSString *value_; + _H operator_; + _H value_; } - (NSString *) operator; @@ -1915,16 +1582,10 @@ static void PackageImport(const void *key, const void *value, void *context) { @implementation CydiaOperation -- (void) dealloc { - [operator_ release]; - [value_ release]; - [super dealloc]; -} - - (id) initWithOperator:(const char *)_operator value:(const char *)value { if ((self = [super init]) != nil) { - operator_ = [[NSString alloc] initWithUTF8String:_operator]; - value_ = [[NSString alloc] initWithUTF8String:value]; + operator_ = [NSString stringWithUTF8String:_operator]; + value_ = [NSString stringWithUTF8String:value]; } return self; } @@ -1955,8 +1616,8 @@ static void PackageImport(const void *key, const void *value, void *context) { /* }}} */ /* CydiaClause Class {{{ */ @interface CydiaClause : NSObject { - NSString *package_; - CydiaOperation *version_; + _H package_; + _H version_; } - (NSString *) package; @@ -1966,20 +1627,14 @@ static void PackageImport(const void *key, const void *value, void *context) { @implementation CydiaClause -- (void) dealloc { - [package_ release]; - [version_ release]; - [super dealloc]; -} - - (id) initWithIterator:(pkgCache::DepIterator &)dep { if ((self = [super init]) != nil) { - package_ = [[NSString alloc] initWithUTF8String:dep.TargetPkg().Name()]; + package_ = [NSString stringWithUTF8String:dep.TargetPkg().Name()]; if (const char *version = dep.TargetVer()) - version_ = [[CydiaOperation alloc] initWithOperator:dep.CompType() value:version]; + version_ = [[[CydiaOperation alloc] initWithOperator:dep.CompType() value:version] autorelease]; else - version_ = [[NSNull null] retain]; + version_ = (id) [NSNull null]; } return self; } @@ -2010,8 +1665,8 @@ static void PackageImport(const void *key, const void *value, void *context) { /* }}} */ /* CydiaRelation Class {{{ */ @interface CydiaRelation : NSObject { - NSString *relationship_; - NSMutableArray *clauses_; + _H relationship_; + _H clauses_; } - (NSString *) relationship; @@ -2021,16 +1676,10 @@ static void PackageImport(const void *key, const void *value, void *context) { @implementation CydiaRelation -- (void) dealloc { - [relationship_ release]; - [clauses_ release]; - [super dealloc]; -} - - (id) initWithIterator:(pkgCache::DepIterator &)dep { if ((self = [super init]) != nil) { - relationship_ = [[NSString alloc] initWithUTF8String:dep.DepType()]; - clauses_ = [[NSMutableArray alloc] initWithCapacity:8]; + relationship_ = [NSString stringWithUTF8String:dep.DepType()]; + clauses_ = [NSMutableArray arrayWithCapacity:8]; pkgCache::DepIterator start; pkgCache::DepIterator end; @@ -2116,12 +1765,12 @@ struct ParsedPackage { const char *section_; _transient NSString *section$_; - Source *source_; + _H source_; PackageValue *metadata_; ParsedPackage *parsed_; - NSMutableArray *tags_; + _H tags_; } - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database; @@ -2343,10 +1992,6 @@ struct PackageNameOrdering : - (void) dealloc { if (parsed_ != NULL) delete parsed_; - if (source_ != nil) - [source_ release]; - if (tags_ != nil) - [tags_ release]; [super dealloc]; } @@ -2535,7 +2180,7 @@ struct PackageNameOrdering : _profile(Package$initWithVersion$Tags) pkgCache::TagIterator tag(iterator.TagList()); if (!tag.end()) { - tags_ = [[NSMutableArray alloc] initWithCapacity:8]; + tags_ = [NSMutableArray arrayWithCapacity:8]; do { const char *name(tag.Name()); [tags_ addObject:[(NSString *)CYStringCreate(name) autorelease]]; @@ -3085,7 +2730,7 @@ struct PackageNameOrdering : if ([database_ era] != era_ || file_.end()) source_ = (Source *) [NSNull null]; else - source_ = [([database_ getSource:file_.File()] ?: (Source *) [NSNull null]) retain]; + source_ = [database_ getSource:file_.File()] ?: (Source *) [NSNull null]; } } @@ -3108,7 +2753,10 @@ struct PackageNameOrdering : [self parse]; - range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_]; + NSString *description([self shortDescription]); + NSUInteger length([description length]); + + range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_ range:NSMakeRange(0, std::min(length, 100))]; if (range.location != NSNotFound) return YES; @@ -3142,7 +2790,7 @@ struct PackageNameOrdering : } - (NSString *) primaryPurpose { - for (NSString *tag in tags_) + for (NSString *tag in (NSArray *) tags_) if ([tag hasPrefix:@"purpose::"]) return [tag substringFromIndex:9]; return nil; @@ -3150,7 +2798,7 @@ struct PackageNameOrdering : - (NSArray *) purposes { NSMutableArray *purposes([NSMutableArray arrayWithCapacity:2]); - for (NSString *tag in tags_) + for (NSString *tag in (NSArray *) tags_) if ([tag hasPrefix:@"purpose::"]) [purposes addObject:[tag substringFromIndex:9]]; return [purposes count] == 0 ? nil : purposes; @@ -3273,11 +2921,11 @@ struct PackageNameOrdering : /* }}} */ /* Section Class {{{ */ @interface Section : NSObject { - NSString *name_; + _H name_; unichar index_; size_t row_; size_t count_; - NSString *localized_; + _H localized_; } - (NSComparisonResult) compareByLocalized:(Section *)section; @@ -3301,13 +2949,6 @@ struct PackageNameOrdering : @implementation Section -- (void) dealloc { - [name_ release]; - if (localized_ != nil) - [localized_ release]; - [super dealloc]; -} - - (NSComparisonResult) compareByLocalized:(Section *)section { NSString *lhs(localized_); NSString *rhs([section localized]); @@ -3328,7 +2969,7 @@ struct PackageNameOrdering : - (Section *) initWithName:(NSString *)name localized:(NSString *)localized { if ((self = [self initWithName:name localize:NO]) != nil) { if (localized != nil) - localized_ = [localized retain]; + localized_ = localized; } return self; } @@ -3338,18 +2979,18 @@ struct PackageNameOrdering : - (Section *) initWithName:(NSString *)name row:(size_t)row localize:(BOOL)localize { if ((self = [super init]) != nil) { - name_ = [name retain]; + name_ = name; index_ = '\0'; row_ = row; if (localize) - localized_ = [LocalizeSection(name_) retain]; + localized_ = LocalizeSection(name_); } return self; } /* XXX: localize the index thingees */ - (Section *) initWithIndex:(unichar)index row:(size_t)row { if ((self = [super init]) != nil) { - name_ = [[NSString stringWithCharacters:&index length:1] retain]; + name_ = [NSString stringWithCharacters:&index length:1]; index_ = index; row_ = row; } return self; @@ -3395,13 +3036,22 @@ static NSString *Elision_; static NSString *Error_; static NSString *Warning_; +class CydiaLogCleaner : + public pkgArchiveCleaner +{ + protected: + virtual void Erase(const char *File, std::string Pkg, std::string Ver, struct stat &St) { + unlink(File); + } +}; + /* Database Implementation {{{ */ @implementation Database + (Database *) sharedInstance { - static Database *instance; + static _H instance; if (instance == nil) - instance = [[Database alloc] init]; + instance = [[[Database alloc] init] autorelease]; return instance; } @@ -3417,7 +3067,6 @@ static NSString *Warning_; - (void) dealloc { // XXX: actually implement this thing _assert(false); - [sourceList_ release]; [self releasePackages]; apr_pool_destroy(pool_); NSRecycleZone(zone_); @@ -3545,7 +3194,7 @@ static NSString *Warning_; capacity += 1024; packages_ = CFArrayCreateMutable(kCFAllocatorDefault, capacity, NULL); - sourceList_ = [[NSMutableArray alloc] initWithCapacity:16]; + sourceList_ = [NSMutableArray arrayWithCapacity:16]; int fds[2]; @@ -3774,7 +3423,6 @@ static NSString *Warning_; { /*std::vector packages; packages.reserve(std::max(10000U, [packages_ count] + 1000)); - [packages_ release]; packages_ = nil;*/ _trace(); @@ -3782,7 +3430,7 @@ static NSString *Warning_; for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator) if (Package *package = [Package packageWithIterator:iterator withZone:zone_ inPool:pool_ database:self]) //packages.push_back(package); - CFArrayAppendValue(packages_, [package retain]); + CFArrayAppendValue(packages_, CFRetain(package)); _trace(); @@ -3792,9 +3440,9 @@ static NSString *Warning_; packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()]; _trace();*/ - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(16)]; - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(4)]; - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(16)]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(4)]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; /*_trace(); PrintTimes(); @@ -3859,15 +3507,7 @@ static NSString *Warning_; pkgAcquire fetcher; fetcher.Clean(_config->FindDir("Dir::Cache::Archives")); - class LogCleaner : - public pkgArchiveCleaner - { - protected: - virtual void Erase(const char *File, std::string Pkg, std::string Ver, struct stat &St) { - unlink(File); - } - } cleaner; - + CydiaLogCleaner cleaner; if ([self popErrorWithTitle:title forOperation:cleaner.Go(_config->FindDir("Dir::Cache::Archives") + "partial/", cache_)]) return false; @@ -3998,13 +3638,13 @@ static NSString *Warning_; bool success(ListUpdate(status, list, PulseInterval_)); if (status.WasCancelled()) _error->Discard(); - else + else { [self popErrorWithTitle:title forOperation:success]; + [Metadata_ setObject:[NSDate date] forKey:@"LastUpdate"]; + Changed_ = true; + } [delegate_ performSelectorOnMainThread:@selector(releaseNetworkActivityIndicator) withObject:nil waitUntilDone:YES]; - - [Metadata_ setObject:[NSDate date] forKey:@"LastUpdate"]; - Changed_ = true; } - (void) setDelegate:(NSObject *)delegate { @@ -4059,6 +3699,8 @@ static NSString *Warning_; @end /* }}} */ +static _H Diversions_; + @interface Diversion : NSObject { Pcre pattern_; _H key_; @@ -4078,15 +3720,23 @@ static NSString *Warning_; } - (NSString *) divert:(NSString *)url { - if (!pattern_(url)) - return nil; + return !pattern_(url) ? nil : pattern_->*format_; +} - size_t count(pattern_.size()); - id values[count]; - for (size_t i(0); i != count; ++i) - values[i] = pattern_[i + 1]; ++ (NSURL *) divertURL:(NSURL *)url { + divert: + NSString *href([url absoluteString]); + + for (Diversion *diversion in (id) Diversions_) + if (NSString *diverted = [diversion divert:href]) { +#if !ForRelease + NSLog(@"div: %@", diverted); +#endif + url = [NSURL URLWithString:diverted]; + goto divert; + } - return [[[NSString alloc] initWithFormat:format_ arguments:reinterpret_cast(values)] autorelease]; + return url; } - (NSString *) key { @@ -4104,7 +3754,7 @@ static NSString *Warning_; @end @interface CydiaObject : NSObject { - id indirect_; + _H indirect_; _transient id delegate_; } @@ -4112,27 +3762,20 @@ static NSString *Warning_; @end -@interface CYBrowserController : BrowserController { - CydiaObject *cydia_; +@interface CydiaWebViewController : CyteWebViewController { + _H cydia_; } + (void) addDiversion:(Diversion *)diversion; @end -static NSMutableSet *Diversions_; - /* Web Scripting {{{ */ @implementation CydiaObject -- (void) dealloc { - [indirect_ release]; - [super dealloc]; -} - - (id) initWithDelegate:(IndirectDelegate *)indirect { if ((self = [super init]) != nil) { - indirect_ = [indirect retain]; + indirect_ = indirect; } return self; } @@ -4142,6 +3785,7 @@ static NSMutableSet *Diversions_; + (NSArray *) _attributeKeys { return [NSArray arrayWithObjects: + @"bbsnum", @"device", @"ecid", @"firmware", @@ -4188,6 +3832,10 @@ static NSMutableSet *Diversions_; return (id) PLMN_ ?: [NSNull null]; } +- (NSString *) bbsnum { + return (id) BBSNum_ ?: [NSNull null]; +} + - (NSString *) ecid { return (id) ChipID_ ?: [NSNull null]; } @@ -4212,14 +3860,14 @@ static NSMutableSet *Diversions_; if (false); else if (selector == @selector(addBridgedHost:)) return @"addBridgedHost"; + else if (selector == @selector(addInternalRedirect::)) + return @"addInternalRedirect"; else if (selector == @selector(addPipelinedHost:scheme:)) return @"addPipelinedHost"; else if (selector == @selector(addTrivialSource:)) return @"addTrivialSource"; else if (selector == @selector(close)) return @"close"; - else if (selector == @selector(divert::)) - return @"divert"; else if (selector == @selector(du:)) return @"du"; else if (selector == @selector(stringWithFormat:arguments:)) @@ -4232,6 +3880,12 @@ static NSMutableSet *Diversions_; return @"getKernelString"; else if (selector == @selector(getInstalledPackages)) return @"getInstalledPackages"; + else if (selector == @selector(getIORegistryEntry::)) + return @"getIORegistryEntry"; + else if (selector == @selector(getLocaleIdentifier)) + return @"getLocaleIdentifier"; + else if (selector == @selector(getPreferredLanguages)) + return @"getPreferredLanguages"; else if (selector == @selector(getPackageById:)) return @"getPackageById"; else if (selector == @selector(getSessionValue:)) @@ -4254,6 +3908,8 @@ static NSMutableSet *Diversions_; return @"scrollToBottom"; else if (selector == @selector(setAllowsNavigationAction:)) return @"setAllowsNavigationAction"; + else if (selector == @selector(setBadgeValue:)) + return @"setBadgeValue"; else if (selector == @selector(setButtonImage:withStyle:toFunction:)) return @"setButtonImage"; else if (selector == @selector(setButtonTitle:withStyle:toFunction:)) @@ -4266,8 +3922,10 @@ static NSMutableSet *Diversions_; return @"setNavigationBarStyle"; else if (selector == @selector(setNavigationBarTintRed:green:blue:alpha:)) return @"setNavigationBarTintColor"; - else if (selector == @selector(setPopupHook:)) - return @"setPopupHook"; + else if (selector == @selector(setPasteboardString:)) + return @"setPasteboardString"; + else if (selector == @selector(setPasteboardURL:)) + return @"setPasteboardURL"; else if (selector == @selector(setToken:)) return @"setToken"; else if (selector == @selector(setViewportWidth:)) @@ -4288,8 +3946,8 @@ static NSMutableSet *Diversions_; return [feature isEqualToString:@"window.open"]; } -- (void) divert:(NSString *)from :(NSString *)to { - [CYBrowserController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO]; +- (void) addInternalRedirect:(NSString *)from :(NSString *)to { + [CydiaWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO]; } - (NSNumber *) getKernelNumber:(NSString *)name { @@ -4326,6 +3984,16 @@ static NSMutableSet *Diversions_; return [NSString stringWithCString:value]; } +- (NSObject *) getIORegistryEntry:(NSString *)path :(NSString *)entry { + NSObject *value(CYIOGetValue([path UTF8String], entry)); + + if (value != nil) + if ([value isKindOfClass:[NSData class]]) + value = CYHex((NSData *) value); + + return value; +} + - (id) getSessionValue:(NSString *)key { @synchronized (SessionData_) { return [SessionData_ objectForKey:key]; @@ -4389,6 +4057,14 @@ static NSMutableSet *Diversions_; return (Package *) [NSNull null]; } +- (NSString *) getLocaleIdentifier { + return Locale_ == NULL ? (NSString *) [NSNull null] : (NSString *) CFLocaleGetIdentifier(Locale_); +} + +- (NSArray *) getPreferredLanguages { + return Languages_; +} + - (NSArray *) statfs:(NSString *)path { struct statfs stat; @@ -4477,6 +4153,10 @@ static NSMutableSet *Diversions_; [indirect_ setButtonTitle:button withStyle:style toFunction:function]; } +- (void) setBadgeValue:(id)value { + [indirect_ performSelectorOnMainThread:@selector(setBadgeValue:) withObject:value waitUntilDone:NO]; +} + - (void) setAllowsNavigationAction:(NSString *)value { [indirect_ performSelectorOnMainThread:@selector(setAllowsNavigationActionByNumber:) withObject:value waitUntilDone:NO]; } @@ -4499,6 +4179,14 @@ static NSMutableSet *Diversions_; [indirect_ performSelectorOnMainThread:@selector(setNavigationBarTintColor:) withObject:color waitUntilDone:NO]; } +- (void) setPasteboardString:(NSString *)value { + [[objc_getClass("UIPasteboard") generalPasteboard] setString:value]; +} + +- (void) setPasteboardURL:(NSString *)value { + [[objc_getClass("UIPasteboard") generalPasteboard] setURL:[NSURL URLWithString:value]]; +} + - (void) _setToken:(NSString *)token { Token_ = token; @@ -4514,10 +4202,6 @@ static NSMutableSet *Diversions_; [self performSelectorOnMainThread:@selector(_setToken:) withObject:token waitUntilDone:NO]; } -- (void) setPopupHook:(id)function { - [indirect_ setPopupHook:function]; -} - - (void) scrollToBottom:(NSNumber *)animated { [indirect_ performSelectorOnMainThread:@selector(scrollToBottomAnimated:) withObject:animated waitUntilDone:NO]; } @@ -4614,7 +4298,7 @@ static NSMutableSet *Diversions_; @end /* }}} */ /* Emulated Loading Controller {{{ */ -@interface CYEmulatedLoadingController : CYViewController { +@interface CYEmulatedLoadingController : CyteViewController { _transient Database *database_; _H indicator_; _H tabbar_; @@ -4663,19 +4347,14 @@ static NSMutableSet *Diversions_; /* }}} */ /* Cydia Browser Controller {{{ */ -@implementation CYBrowserController - -- (void) dealloc { - [cydia_ release]; - [super dealloc]; -} +@implementation CydiaWebViewController - (NSURL *) navigationURL { - return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[[webview_ request] URL] absoluteString]]]; + return request_ == nil ? nil : [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]]; } + (void) initialize { - Diversions_ = [[NSMutableSet alloc] initWithCapacity:0]; + Diversions_ = [NSMutableSet setWithCapacity:0]; } + (void) addDiversion:(Diversion *)diversion { @@ -4688,27 +4367,29 @@ static NSMutableSet *Diversions_; WebDataSource *source([frame dataSource]); NSURLResponse *response([source response]); NSURL *url([response URL]); + NSString *scheme([[url scheme] lowercaseString]); + + bool bridged(false); @synchronized (HostConfig_) { - if ([[[url scheme] lowercaseString] isEqualToString:@"https"]) + if ([scheme isEqualToString:@"file"]) + bridged = true; + else if ([scheme isEqualToString:@"https"]) if ([BridgedHosts_ containsObject:[url host]]) - [window setValue:cydia_ forKey:@"cydia"]; + bridged = true; } + + if (bridged) + [window setValue:cydia_ forKey:@"cydia"]; +} + +- (NSURL *) URLWithURL:(NSURL *)url { + return [Diversion divertURL:url]; } - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]); - divert: - NSURL *url([copy URL]); - NSString *href([url absoluteString]); - - for (Diversion *diversion in Diversions_) - if (NSString *diverted = [diversion divert:href]) { - [copy setURL:[NSURL URLWithString:diverted]]; - goto divert; - } - if (System_ != NULL) [copy setValue:System_ forHTTPHeaderField:@"X-System"]; if (Machine_ != NULL) @@ -4725,8 +4406,8 @@ static NSMutableSet *Diversions_; } - (id) init { - if ((self = [super initWithWidth:0 ofClass:[CYBrowserController class]]) != nil) { - cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_]; + if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) { + cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease]; WebView *webview([[webview_ _documentView] webView]); @@ -4804,14 +4485,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) queue; @end -@interface ConfirmationController : CYBrowserController { +@interface ConfirmationController : CydiaWebViewController { _transient Database *database_; - UIAlertView *essential_; + _H essential_; - NSDictionary *changes_; - NSMutableArray *issues_; - NSDictionary *sizes_; + _H changes_; + _H issues_; + _H sizes_; BOOL substrate_; } @@ -4822,17 +4503,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation ConfirmationController -- (void) dealloc { - [changes_ release]; - [issues_ release]; - [sizes_ release]; - - if (essential_ != nil) - [essential_ release]; - - [super dealloc]; -} - - (void) complete { if (substrate_) RestartSubstrate_ = true; @@ -4872,9 +4542,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super webView:view didClearWindowObject:window forFrame:frame]; [window setValue:[[NSDictionary dictionaryWithObjectsAndKeys: - changes_, @"changes", - issues_, @"issues", - sizes_, @"sizes", + (id) changes_, @"changes", + (id) issues_, @"issues", + (id) sizes_, @"sizes", self, @"queue", nil] Cydia$webScriptObjectInContext:window] forKey:@"cydiaConfirm"]; } @@ -4895,7 +4565,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSArray *packages([database_ packages]); pkgDepCache::Policy *policy([database_ policy]); - issues_ = [[NSMutableArray arrayWithCapacity:4] retain]; + issues_ = [NSMutableArray arrayWithCapacity:4]; for (Package *package in packages) { pkgCache::PkgIterator iterator([package iterator]); @@ -4975,13 +4645,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (state.NewInstall()) [installs addObject:name]; + // XXX: else if (state.Install()) else if (!state.Delete() && (state.iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall) [reinstalls addObject:name]; + // XXX: move before previous if else if (state.Upgrade()) [upgrades addObject:name]; else if (state.Downgrade()) [downgrades addObject:name]; else if (!state.Delete()) + // XXX: _assert(state.Keep()); continue; else if (special_r(name)) [issues_ addObject:[NSDictionary dictionaryWithObjectsAndKeys: @@ -5014,7 +4687,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { else if (Advanced_) { NSString *parenthetical(UCLocalize("PARENTHETICAL")); - essential_ = [[UIAlertView alloc] + essential_ = [[[UIAlertView alloc] initWithTitle:UCLocalize("REMOVING_ESSENTIALS") message:UCLocalize("REMOVING_ESSENTIALS_EX") delegate:self @@ -5022,22 +4695,22 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { otherButtonTitles: [NSString stringWithFormat:parenthetical, UCLocalize("FORCE_REMOVAL"), UCLocalize("UNSAFE")], nil - ]; + ] autorelease]; [essential_ setContext:@"remove"]; } else { - essential_ = [[UIAlertView alloc] + essential_ = [[[UIAlertView alloc] initWithTitle:UCLocalize("UNABLE_TO_COMPLY") message:UCLocalize("UNABLE_TO_COMPLY_EX") delegate:self cancelButtonTitle:UCLocalize("OKAY") otherButtonTitles:nil - ]; + ] autorelease]; [essential_ setContext:@"unable"]; } - changes_ = [[NSDictionary alloc] initWithObjectsAndKeys: + changes_ = [NSDictionary dictionaryWithObjectsAndKeys: installs, @"installs", reinstalls, @"reinstalls", upgrades, @"upgrades", @@ -5045,22 +4718,24 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { removes, @"removes", nil]; - sizes_ = [[NSDictionary alloc] initWithObjectsAndKeys: + sizes_ = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger:[database_ fetcher].FetchNeeded()], @"downloading", [NSNumber numberWithInteger:[database_ fetcher].PartialPresent()], @"resuming", nil]; [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/confirm/", UI_]]]; - - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("CANCEL") - style:UIBarButtonItemStylePlain - target:self - action:@selector(cancelButtonClicked) - ] autorelease]]; } return self; } +- (UIBarButtonItem *) leftButton { + return [[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("CANCEL") + style:UIBarButtonItemStylePlain + target:self + action:@selector(cancelButtonClicked) + ] autorelease]; +} + #if !AlwaysReload - (void) applyRightButton { if ([issues_ count] == 0 && ![self isLoading]) @@ -5216,7 +4891,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Progress Controller {{{ */ -@interface ProgressController : CYBrowserController < +@interface ProgressController : CydiaWebViewController < ProgressDelegate > { _transient Database *database_; @@ -5241,13 +4916,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super dealloc]; } -- (void) updateCancel { - [[self navigationItem] setLeftBarButtonItem:(cancel_ == 1 ? [[[UIBarButtonItem alloc] +- (UIBarButtonItem *) leftButton { + return cancel_ == 1 ? [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CANCEL") style:UIBarButtonItemStylePlain target:self action:@selector(cancel) - ] autorelease] : nil)]; + ] autorelease] : nil; +} + +- (void) updateCancel { + [super applyLeftButton]; } - (id) initWithDatabase:(Database *)database delegate:(id)delegate { @@ -5330,7 +5009,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (UIBarButtonItem *) rightButton { - return [[progress_ running] boolValue] ? nil : [[[UIBarButtonItem alloc] + return [[progress_ running] boolValue] ? [super rightButton] : [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CLOSE") style:UIBarButtonItemStylePlain target:self @@ -5481,89 +5160,23 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -/* Cell Content View {{{ */ -@protocol ContentDelegate -- (void) drawContentRect:(CGRect)rect; -@end - -@interface ContentView : UIView { - _transient id delegate_; -} - -@end - -@implementation ContentView - -- (id) initWithFrame:(CGRect)frame { - if ((self = [super initWithFrame:frame]) != nil) { - [self setNeedsDisplayOnBoundsChange:YES]; - } return self; -} - -- (void) setDelegate:(id)delegate { - delegate_ = delegate; -} - -- (void) drawRect:(CGRect)rect { - [super drawRect:rect]; - [delegate_ drawContentRect:rect]; -} - -@end -/* }}} */ -/* Cydia TableView Cell {{{ */ -@interface CYTableViewCell : UITableViewCell { - ContentView *content_; - bool highlighted_; -} - -@end - -@implementation CYTableViewCell - -- (void) dealloc { - [content_ release]; - [super dealloc]; -} - -- (void) _updateHighlightColorsForView:(id)view highlighted:(BOOL)highlighted { - //NSLog(@"_updateHighlightColorsForView:%@ highlighted:%s [content_=%@]", view, highlighted ? "YES" : "NO", content_); - - if (view == content_) { - //NSLog(@"_updateHighlightColorsForView:content_ highlighted:%s", highlighted ? "YES" : "NO", content_); - highlighted_ = highlighted; - } - - [super _updateHighlightColorsForView:view highlighted:highlighted]; -} - -- (void) setSelected:(BOOL)selected animated:(BOOL)animated { - //NSLog(@"setSelected:%s animated:%s", selected ? "YES" : "NO", animated ? "YES" : "NO"); - highlighted_ = selected; - - [super setSelected:selected animated:animated]; - [content_ setNeedsDisplay]; -} - -@end -/* }}} */ - /* Package Cell {{{ */ @interface PackageCell : CYTableViewCell < - ContentDelegate + CyteTableViewCellDelegate > { - UIImage *icon_; - NSString *name_; - NSString *description_; + _H icon_; + _H name_; + _H description_; bool commercial_; - NSString *source_; - UIImage *badge_; - Package *package_; - UIImage *placard_; + _H source_; + _H badge_; + _H package_; + _H placard_; + bool summarized_; } - (PackageCell *) init; -- (void) setPackage:(Package *)package; +- (void) setPackage:(Package *)package asSummary:(bool)summary; - (void) drawContentRect:(CGRect)rect; @@ -5571,53 +5184,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation PackageCell -- (void) clearPackage { - if (icon_ != nil) { - [icon_ release]; - icon_ = nil; - } - - if (name_ != nil) { - [name_ release]; - name_ = nil; - } - - if (description_ != nil) { - [description_ release]; - description_ = nil; - } - - if (source_ != nil) { - [source_ release]; - source_ = nil; - } - - if (badge_ != nil) { - [badge_ release]; - badge_ = nil; - } - - if (placard_ != nil) { - [placard_ release]; - placard_ = nil; - } - - [package_ release]; - package_ = nil; -} - -- (void) dealloc { - [self clearPackage]; - [super dealloc]; -} - - (PackageCell *) init { CGRect frame(CGRectMake(0, 0, 320, 74)); if ((self = [super initWithFrame:frame reuseIdentifier:@"Package"]) != nil) { UIView *content([self contentView]); CGRect bounds([content bounds]); - content_ = [[ContentView alloc] initWithFrame:bounds]; + content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [content addSubview:content_]; @@ -5627,28 +5200,35 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (NSString *) accessibilityLabel { - return [NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), name_, description_]; + return [NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), (id) name_, (id) description_]; } -- (void) setPackage:(Package *)package { - [self clearPackage]; +- (void) setPackage:(Package *)package asSummary:(bool)summary { + summarized_ = summary; + + icon_ = nil; + name_ = nil; + description_ = nil; + source_ = nil; + badge_ = nil; + placard_ = nil; + package_ = nil; + [package parse]; Source *source = [package source]; - icon_ = [[package icon] retain]; - name_ = [[package name] retain]; + icon_ = [package icon]; + name_ = [package name]; if (IsWildcat_) description_ = [package longDescription]; if (description_ == nil) description_ = [package shortDescription]; - if (description_ != nil) - description_ = [description_ retain]; commercial_ = [package isCommercial]; - package_ = [package retain]; + package_ = package; NSString *label = nil; bool trusted = false; @@ -5669,12 +5249,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section]; } - from = [NSString stringWithFormat:UCLocalize("FROM"), from]; - source_ = [from retain]; + source_ = [NSString stringWithFormat:UCLocalize("FROM"), from]; if (NSString *purpose = [package primaryPurpose]) - if ((badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]]) != nil) - badge_ = [badge_ retain]; + badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]]; UIColor *color; NSString *placard; @@ -5702,26 +5280,60 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [content_ setBackgroundColor:color]; if (placard != nil) - if ((placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]]) != nil) - placard_ = [placard_ retain]; + placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]]; [self setNeedsDisplay]; [content_ setNeedsDisplay]; } -- (void) drawContentRect:(CGRect)rect { +- (void) drawSummaryContentRect:(CGRect)rect { bool highlighted(highlighted_); float width([self bounds].size.width); -#if 0 - CGContextRef context(UIGraphicsGetCurrentContext()); - [([[self selectedBackgroundView] superview] != nil ? [UIColor clearColor] : [self backgroundColor]) set]; - CGContextFillRect(context, rect); -#endif + if (icon_ != nil) { + CGRect rect; + rect.size = [(UIImage *) icon_ size]; + + rect.size.width /= 4; + rect.size.height /= 4; + + rect.origin.x = 14 - rect.size.width / 4; + rect.origin.y = 14 - rect.size.height / 4; + + [icon_ drawInRect:rect]; + } + + if (badge_ != nil) { + CGRect rect; + rect.size = [(UIImage *) badge_ size]; + + rect.size.width /= 4; + rect.size.height /= 4; + + rect.origin.x = 20 - rect.size.width / 4; + rect.origin.y = 20 - rect.size.height / 4; + + [badge_ drawInRect:rect]; + } + + if (highlighted) + UISetColor(White_); + + if (!highlighted) + UISetColor(commercial_ ? Purple_ : Black_); + [name_ drawAtPoint:CGPointMake(36, 8) forWidth:(width - (placard_ == nil ? 68 : 94)) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation]; + + if (placard_ != nil) + [placard_ drawAtPoint:CGPointMake(width - 52, 9)]; +} + +- (void) drawNormalContentRect:(CGRect)rect { + bool highlighted(highlighted_); + float width([self bounds].size.width); if (icon_ != nil) { CGRect rect; - rect.size = [icon_ size]; + rect.size = [(UIImage *) icon_ size]; rect.size.width /= 2; rect.size.height /= 2; @@ -5734,7 +5346,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (badge_ != nil) { CGRect rect; - rect.size = [badge_ size]; + rect.size = [(UIImage *) badge_ size]; rect.size.width /= 2; rect.size.height /= 2; @@ -5761,18 +5373,25 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [placard_ drawAtPoint:CGPointMake(width - 52, 9)]; } +- (void) drawContentRect:(CGRect)rect { + if (summarized_) + [self drawSummaryContentRect:rect]; + else + [self drawNormalContentRect:rect]; +} + @end /* }}} */ /* Section Cell {{{ */ @interface SectionCell : CYTableViewCell < - ContentDelegate + CyteTableViewCellDelegate > { - NSString *basic_; - NSString *section_; - NSString *name_; - NSString *count_; - UIImage *icon_; - UISwitch *switch_; + _H basic_; + _H section_; + _H name_; + _H count_; + _H icon_; + _H switch_; BOOL editing_; } @@ -5782,45 +5401,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation SectionCell -- (void) clearSection { - if (basic_ != nil) { - [basic_ release]; - basic_ = nil; - } - - if (section_ != nil) { - [section_ release]; - section_ = nil; - } - - if (name_ != nil) { - [name_ release]; - name_ = nil; - } - - if (count_ != nil) { - [count_ release]; - count_ = nil; - } -} - -- (void) dealloc { - [self clearSection]; - [icon_ release]; - [switch_ release]; - [super dealloc]; -} - - (id) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) { - icon_ = [[UIImage applicationImageNamed:@"folder.png"] retain]; - switch_ = [[UISwitch alloc] initWithFrame:CGRectMake(218, 9, 60, 25)]; + icon_ = [UIImage applicationImageNamed:@"folder.png"]; + switch_ = [[[UISwitch alloc] initWithFrame:CGRectMake(218, 9, 60, 25)] autorelease]; [switch_ addTarget:self action:@selector(onSwitch:) forEvents:UIControlEventValueChanged]; UIView *content([self contentView]); CGRect bounds([content bounds]); - content_ = [[ContentView alloc] initWithFrame:bounds]; + content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [content addSubview:content_]; [content_ setBackgroundColor:[UIColor whiteColor]]; @@ -5849,22 +5439,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { editing_ = editing; } - [self clearSection]; + basic_ = nil; + section_ = nil; + name_ = nil; + count_ = nil; if (section == nil) { - name_ = [UCLocalize("ALL_PACKAGES") retain]; + name_ = UCLocalize("ALL_PACKAGES"); count_ = nil; } else { basic_ = [section name]; - if (basic_ != nil) - basic_ = [basic_ retain]; - section_ = [section localized]; - if (section_ != nil) - section_ = [section_ retain]; - name_ = [(section_ == nil || [section_ length] == 0 ? UCLocalize("NO_SECTION") : section_) retain]; - count_ = [[NSString stringWithFormat:@"%d", [section count]] retain]; + name_ = section_ == nil || [section_ length] == 0 ? UCLocalize("NO_SECTION") : (NSString *) section_; + count_ = [NSString stringWithFormat:@"%d", [section count]]; if (editing_) [switch_ setOn:(isSectionVisible(basic_) ? 1 : 0) animated:NO]; @@ -5914,15 +5502,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* File Table {{{ */ -@interface FileTable : CYViewController < +@interface FileTable : CyteViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; - Package *package_; - NSString *name_; - NSMutableArray *files_; - UITableView *list_; + _H package_; + _H name_; + _H files_; + _H list_; } - (id) initWithDatabase:(Database *)database; @@ -5933,12 +5521,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation FileTable - (void) dealloc { - [self releaseSubviews]; - - [package_ release]; - [name_ release]; - [files_ release]; - + [(UITableView *) list_ setDataSource:nil]; + [list_ setDelegate:nil]; [super dealloc]; } @@ -5971,20 +5555,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) loadView { [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; + list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [list_ setRowHeight:24.0f]; - [list_ setDataSource:self]; + [(UITableView *) list_ setDataSource:self]; [list_ setDelegate:self]; [[self view] addSubview:list_]; } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("INSTALLED_FILES")]; } - (void) releaseSubviews { - [list_ release]; list_ = nil; } @@ -5992,26 +5577,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ((self = [super init]) != nil) { database_ = database; - files_ = [[NSMutableArray arrayWithCapacity:32] retain]; + files_ = [NSMutableArray arrayWithCapacity:32]; } return self; } - (void) setPackage:(Package *)package { - if (package_ != nil) { - [package_ autorelease]; - package_ = nil; - } - - if (name_ != nil) { - [name_ release]; - name_ = nil; - } + package_ = nil; + name_ = nil; [files_ removeAllObjects]; if (package != nil) { - package_ = [package retain]; - name_ = [[package id] retain]; + package_ = package; + name_ = [package id]; if (NSArray *files = [package files]) [files_ addObjectsFromArray:files]; @@ -6050,7 +5628,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Controller {{{ */ -@interface CYPackageController : CYBrowserController < +@interface CYPackageController : CydiaWebViewController < UIActionSheetDelegate > { _transient Database *database_; @@ -6216,39 +5794,39 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Package List Controller {{{ */ -@interface PackageListController : CYViewController < +@interface PackageListController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; unsigned era_; - NSMutableArray *packages_; - NSMutableArray *sections_; - UITableView *list_; - NSMutableArray *index_; - NSMutableDictionary *indices_; - NSString *title_; + _H packages_; + _H sections_; + _H list_; + _H index_; + _H indices_; + _H title_; } - (id) initWithDatabase:(Database *)database title:(NSString *)title; - (void) setDelegate:(id)delegate; - (void) resetCursor; +- (void) clearData; @end @implementation PackageListController - (void) dealloc { - [packages_ release]; - [sections_ release]; - [list_ release]; - [index_ release]; - [indices_ release]; - [title_ release]; - + [list_ setDataSource:nil]; + [list_ setDelegate:nil]; [super dealloc]; } +- (bool) isSummarized { + return false; +} + - (void) deselectWithAnimation:(BOOL)animated { [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; } @@ -6368,7 +5946,7 @@ 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]]; + [cell setPackage:[self packageAtIndexPath:path] asSummary:[self isSummarized]]; return cell; } @@ -6379,8 +5957,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (NSArray *) sectionIndexTitlesForTableView:(UITableView *)tableView { - // XXX: is 20 the most optimal number here? - return [packages_ count] > 20 ? index_ : nil; + if ([self isSummarized]) + return nil; + + return index_; } - (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { @@ -6393,6 +5973,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return index; } +- (void) updateHeight { + [list_ setRowHeight:([self isSummarized] ? 38 : 73)]; +} + - (id) initWithDatabase:(Database *)database title:(NSString *)title { if ((self = [super init]) != nil) { database_ = database; @@ -6401,23 +5985,27 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { #if TryIndexedCollation if ([[self class] hasIndexedCollation]) - index_ = [[[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles] retain] + index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles]; else #endif - index_ = [[NSMutableArray alloc] initWithCapacity:32]; + index_ = [NSMutableArray arrayWithCapacity:32]; - indices_ = [[NSMutableDictionary alloc] initWithCapacity:32]; + indices_ = [NSMutableDictionary dictionaryWithCapacity:32]; - packages_ = [[NSMutableArray arrayWithCapacity:16] retain]; - sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; + packages_ = [NSMutableArray arrayWithCapacity:16]; + sections_ = [NSMutableArray arrayWithCapacity:16]; - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; + list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:73]; [[self view] addSubview:list_]; - [list_ setDataSource:self]; + // XXX: is 20 the most optimal number here? + [list_ setSectionIndexMinimumDisplayRowCount:20]; + + [(UITableView *) list_ setDataSource:self]; [list_ setDelegate:self]; + + [self updateHeight]; } return self; } @@ -6429,12 +6017,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return true; } -- (void) reloadData { - [super reloadData]; - - era_ = [database_ era]; - NSArray *packages = [database_ packages]; +- (bool) shouldYield { + return false; +} +- (void) _reloadPackages:(NSArray *)packages { [packages_ removeAllObjects]; [sections_ removeAllObjects]; @@ -6443,6 +6030,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ([self hasPackage:package]) [packages_ addObject:package]; _end +} + +- (void) _reloadData { + era_ = [database_ era]; + NSArray *packages = [database_ packages]; + + if ([self shouldYield]) { + UIProgressHUD *hud([delegate_ addProgressHUD]); + [hud setText:UCLocalize("LOADING")]; + [self yieldToSelector:@selector(_reloadPackages:) withObject:packages]; + [delegate_ removeProgressHUD:hud]; + } else { + [self _reloadPackages:packages]; + } [indices_ removeAllObjects]; @@ -6484,6 +6085,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { { [index_ removeAllObjects]; + bool summary([self isSummarized]); + if (summary) { + section = [[[Section alloc] initWithName:nil localize:false] autorelease]; + [sections_ addObject:section]; + } + _profile(PackageTable$reloadData$Section) for (size_t offset(0), end([packages_ count]); offset != end; ++offset) { Package *package; @@ -6494,7 +6101,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { index = [package index]; _end - if (section == nil || [section index] != index) { + if (!summary && (section == nil || [section index] != index)) { _profile(PackageTable$reloadData$Section$Allocate) section = [[[Section alloc] initWithIndex:index row:offset] autorelease]; _end @@ -6512,13 +6119,30 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _end } + [self updateHeight]; + _profile(PackageTable$reloadData$List) + [(UITableView *) list_ setDataSource:self]; [list_ reloadData]; _end } +- (void) reloadData { + [super reloadData]; + [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0]; +} + - (void) resetCursor { - [list_ scrollRectToVisible:CGRectMake(0, 0, 0, 0) animated:NO]; + [list_ scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO]; +} + +- (void) clearData { + [self updateHeight]; + + [list_ setDataSource:nil]; + [list_ reloadData]; + + [self resetCursor]; } @end @@ -6527,22 +6151,23 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @interface FilteredPackageListController : PackageListController { SEL filter_; IMP imp_; - id object_; + _H object_; } - (void) setObject:(id)object; - (void) setObject:(id)object forFilter:(SEL)filter; +- (SEL) filter; +- (void) setFilter:(SEL)filter; + - (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object; @end @implementation FilteredPackageListController -- (void) dealloc { - if (object_ != nil) - [object_ release]; - [super dealloc]; +- (SEL) filter { + return filter_; } - (void) setFilter:(SEL)filter { @@ -6556,12 +6181,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) setObject:(id)object { - if (object_ != nil) - [object_ release]; - if (object == nil) - object_ = nil; - else - object_ = [object retain]; + object_ = object; } - (void) setObject:(id)object forFilter:(SEL)filter { @@ -6586,7 +6206,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Home Controller {{{ */ -@interface HomeController : CYBrowserController { +@interface HomeController : CydiaWebViewController { } @end @@ -6596,6 +6216,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) init { if ((self = [super init]) != nil) { [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/home/", UI_]]]; + [self reloadData]; } return self; } @@ -6611,7 +6232,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert setCancelButtonIndex:0]; [alert setMessage: - @"Copyright (C) 2008-2011\n" + @"Copyright \u00a9 2008-2011\n" + "SaurikIT, LLC\n" + "\n" "Jay Freeman (saurik)\n" "saurik@saurik.com\n" "http://www.saurik.com/" @@ -6620,19 +6243,24 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert show]; } -- (void) viewDidLoad { - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] +- (UIBarButtonItem *) leftButton { + return [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ABOUT") style:UIBarButtonItemStylePlain target:self action:@selector(aboutButtonClicked) - ] autorelease]]; + ] autorelease]; +} + +- (void) unloadData { + [super unloadData]; + [self reloadData]; } @end /* }}} */ /* Manage Controller {{{ */ -@interface ManageController : CYBrowserController { +@interface ManageController : CydiaWebViewController { } - (void) queueStatusDidChange; @@ -6651,53 +6279,38 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSURL URLWithString:@"cydia://manage"]; } -- (void) viewDidLoad { - [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] +- (UIBarButtonItem *) leftButton { + return [[[UIBarButtonItem alloc] initWithTitle:UCLocalize("SETTINGS") style:UIBarButtonItemStylePlain target:self action:@selector(settingsButtonClicked) - ] autorelease]]; - - [self queueStatusDidChange]; + ] autorelease]; } - (void) settingsButtonClicked { [delegate_ showSettings]; } -#if !AlwaysReload - (void) queueButtonClicked { [delegate_ queue]; } -- (void) applyLoadingTitle { - // Disable "Loading" title. -} - -- (void) applyRightButton { - // Disable right button. +- (UIBarButtonItem *) customButton { + return Queuing_ ? [[[UIBarButtonItem alloc] + initWithTitle:UCLocalize("QUEUE") + style:UIBarButtonItemStyleDone + target:self + action:@selector(queueButtonClicked) + ] autorelease] : [super customButton]; } -#endif - (void) queueStatusDidChange { -#if !AlwaysReload - if (!IsWildcat_ && Queuing_) { - [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] - initWithTitle:UCLocalize("QUEUE") - style:UIBarButtonItemStyleDone - target:self - action:@selector(queueButtonClicked) - ] autorelease]]; - } else { - [[self navigationItem] setRightBarButtonItem:nil]; - } -#endif + [self applyRightButton]; } - (bool) isLoading { - // Never show as loading. - return false; + return !Queuing_ && [super isLoading]; } @end @@ -6705,24 +6318,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* Refresh Bar {{{ */ @interface RefreshBar : UINavigationBar { - UIProgressIndicator *indicator_; - UITextLabel *prompt_; - UIProgressBar *progress_; - UINavigationButton *cancel_; + _H indicator_; + _H prompt_; + _H progress_; + _H cancel_; } @end @implementation RefreshBar -- (void) dealloc { - [indicator_ release]; - [prompt_ release]; - [progress_ release]; - [cancel_ release]; - [super dealloc]; -} - - (void) positionViews { CGRect frame = [cancel_ frame]; frame.size = [cancel_ sizeThatFits:frame.size]; @@ -6768,23 +6373,23 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UIProgressIndicatorStyleMediumBrown : UIProgressIndicatorStyleMediumWhite; - indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectZero]; - [indicator_ setStyle:style]; + indicator_ = [[[UIProgressIndicator alloc] initWithFrame:CGRectZero] autorelease]; + [(UIProgressIndicator *) indicator_ setStyle:style]; [indicator_ startAnimation]; [self addSubview:indicator_]; - prompt_ = [[UITextLabel alloc] initWithFrame:CGRectZero]; + prompt_ = [[[UITextLabel alloc] initWithFrame:CGRectZero] autorelease]; [prompt_ setColor:[UIColor colorWithCGColor:(ugly ? Blueish_ : Off_)]]; [prompt_ setBackgroundColor:[UIColor clearColor]]; [prompt_ setFont:[UIFont systemFontOfSize:15]]; [self addSubview:prompt_]; - progress_ = [[UIProgressBar alloc] initWithFrame:CGRectZero]; + progress_ = [[[UIProgressBar alloc] initWithFrame:CGRectZero] autorelease]; [progress_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin]; - [progress_ setStyle:0]; + [(UIProgressBar *) progress_ setStyle:0]; [self addSubview:progress_]; - cancel_ = [[UINavigationButton alloc] initWithTitle:UCLocalize("CANCEL") style:UINavigationButtonStyleHighlighted]; + cancel_ = [[[UINavigationButton alloc] initWithTitle:UCLocalize("CANCEL") style:UINavigationButtonStyleHighlighted] autorelease]; [cancel_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; [cancel_ addTarget:delegate action:@selector(cancelPressed) forControlEvents:UIControlEventTouchUpInside]; [cancel_ setBarStyle:barstyle]; @@ -6820,7 +6425,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -@class CYNavigationController; +/* Cydia Navigation Controller Interface {{{ */ +@interface UINavigationController (Cydia) + +- (NSArray *) navigationURLCollection; +- (void) unloadData; + +@end +/* }}} */ /* Cydia Tab Bar Controller {{{ */ @interface CYTabBarController : UITabBarController < @@ -6828,15 +6440,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { ProgressDelegate > { _transient Database *database_; - RefreshBar *refreshbar_; + _H refreshbar_; bool dropped_; bool updating_; // XXX: ok, "updatedelegate_"?... _transient NSObject *updatedelegate_; - id root_; - UIViewController *remembered_; + _H remembered_; _transient UIViewController *transient_; } @@ -6845,6 +6456,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) beginUpdate; - (void) raiseBar:(BOOL)animated; - (BOOL) updating; +- (void) unloadData; @end @@ -6854,7 +6466,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSMutableArray *controllers = [[self viewControllers] mutableCopy]; if (transient != nil) { if (transient_ == nil) - remembered_ = [[controllers objectAtIndex:0] retain]; + remembered_ = [controllers objectAtIndex:0]; transient_ = transient; [transient_ setTabBarItem:[remembered_ tabBarItem]]; [controllers replaceObjectAtIndex:0 withObject:transient_]; @@ -6865,7 +6477,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [remembered_ setTabBarItem:[transient_ tabBarItem]]; transient_ = transient; [controllers replaceObjectAtIndex:0 withObject:remembered_]; - [remembered_ release]; remembered_ = nil; [self setViewControllers:controllers]; [self revealTabBarSelection]; @@ -6894,15 +6505,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return items; } -- (void) reloadData { - for (CYViewController *controller in [self viewControllers]) - [controller reloadData]; +- (void) unloadData { + UIViewController *selected([self selectedViewController]); + for (UINavigationController *controller in [self viewControllers]) + [controller unloadData]; + + [selected reloadData]; + + if (UIViewController *unselected = [self unselectedViewController]) + [unselected reloadData]; - [(CYNavigationController *)[self unselectedViewController] reloadData]; + [super unloadData]; } - (void) dealloc { - [refreshbar_ release]; + [refreshbar_ setDelegate:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; @@ -6916,7 +6533,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [[self view] setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil]; - refreshbar_ = [[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self]; + refreshbar_ = [[[RefreshBar alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, [UINavigationBar defaultSize].height) delegate:self] autorelease]; } return self; } @@ -6925,7 +6542,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) beginUpdate { - [refreshbar_ start]; + [(RefreshBar *) refreshbar_ start]; [self dropBar:YES]; [updatedelegate_ retainNetworkActivityIndicator]; @@ -7049,9 +6666,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { // Ensure bar has the proper width for our view, it might have changed barframe.size.width = viewframe.size.width; [refreshbar_ setFrame:barframe]; - - // XXX: fix Apple's layout bug - [[root_ selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } - (void) raiseBar:(BOOL)animated { @@ -7074,18 +6688,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (animated) [UIView commitAnimations]; - - // XXX: fix Apple's layout bug - // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } -#if 0 -- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { - // XXX: fix Apple's layout bug - // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; -} -#endif - - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { bool dropped(dropped_); @@ -7096,9 +6700,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (dropped) [self dropBar:NO]; - - // XXX: fix Apple's layout bug - // SRK [[self selectedViewController] _updateLayoutForStatusBarAndInterfaceOrientation]; } - (void) statusBarFrameChanged:(NSNotification *)notification { @@ -7110,25 +6711,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -/* Cydia Navigation Controller {{{ */ -@interface CYNavigationController : UINavigationController { - _transient Database *database_; - _transient id delegate_; -} - -- (NSArray *) navigationURLCollection; -- (id) initWithDatabase:(Database *)database; -- (void) reloadData; - -@end - -@implementation CYNavigationController +/* Cydia Navigation Controller Implementation {{{ */ +@implementation UINavigationController (Cydia) - (NSArray *) navigationURLCollection { NSMutableArray *stack([NSMutableArray array]); - for (CYViewController *controller in [self viewControllers]) { + for (CyteViewController *controller in [self viewControllers]) { NSString *url = [[controller navigationURL] absoluteString]; if (url != nil) [stack addObject:url]; @@ -7138,23 +6728,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) reloadData { - for (CYViewController *page in [self viewControllers]) { - // Only reload controllers that have already loaded. - // This prevents a page from accidentally loading too - // early if it hasn't been shown on the screen yet. - if ([page hasLoaded]) - [page reloadData]; - } -} + [super reloadData]; -- (void) setDelegate:(id)delegate { - delegate_ = delegate; + if (UIViewController *visible = [self visibleViewController]) + [visible reloadData]; } -- (id) initWithDatabase:(Database *)database { - if ((self = [super init]) != nil) { - database_ = database; - } return self; +- (void) unloadData { + for (CyteViewController *page in [self viewControllers]) + [page unloadData]; + + [super unloadData]; } @end @@ -7236,6 +6820,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { Package *package([database packageWithName:path]); if (package == nil) goto fail; + [package parse]; UIImage *icon([package icon]); [self _returnPNGWithImage:icon forRequest:request]; } else if ([command isEqualToString:@"source-icon"]) { @@ -7309,14 +6894,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Sections Controller {{{ */ -@interface SectionsController : CYViewController < +@interface SectionsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; - NSMutableArray *sections_; - NSMutableArray *filtered_; - UITableView *list_; + _H sections_; + _H filtered_; + _H list_; } - (id) initWithDatabase:(Database *)database; @@ -7326,14 +6911,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation SectionsController -- (void) dealloc { - [self releaseSubviews]; - [sections_ release]; - [filtered_ release]; - - [super dealloc]; -} - - (NSURL *) navigationURL { return [NSURL URLWithString:@"cydia://sections"]; } @@ -7426,20 +7003,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) loadView { [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds]]; + list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [list_ setRowHeight:45.0f]; - [list_ setDataSource:self]; + [(UITableView *) list_ setDataSource:self]; [list_ setDelegate:self]; [[self view] addSubview:list_]; } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("SECTIONS")]; } - (void) releaseSubviews { - [list_ release]; list_ = nil; } @@ -7447,8 +7025,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if ((self = [super init]) != nil) { database_ = database; - sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; - filtered_ = [[NSMutableArray arrayWithCapacity:16] retain]; + sections_ = [NSMutableArray arrayWithCapacity:16]; + filtered_ = [NSMutableArray arrayWithCapacity:16]; } return self; } @@ -7494,7 +7072,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sections_ sortUsingSelector:@selector(compareByLocalized:)]; - for (Section *section in sections_) { + for (Section *section in (id) sections_) { size_t count([section row]); if (count == 0) continue; @@ -7517,15 +7095,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Changes Controller {{{ */ -@interface ChangesController : CYViewController < +@interface ChangesController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; unsigned era_; CFMutableArrayRef packages_; - NSMutableArray *sections_; - UITableView *list_; + _H sections_; + _H list_; unsigned upgrades_; } @@ -7536,10 +7114,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation ChangesController - (void) dealloc { - [self releaseSubviews]; CFRelease(packages_); - [sections_ release]; - [super dealloc]; } @@ -7590,7 +7165,7 @@ 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]]; + [cell setPackage:[self packageAtIndexPath:path] asSummary:false]; return cell; } @@ -7614,20 +7189,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) loadView { [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; + list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [list_ setRowHeight:73]; - [list_ setDataSource:self]; + [(UITableView *) list_ setDataSource:self]; [list_ setDelegate:self]; [[self view] addSubview:list_]; } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("CHANGES")]; } - (void) releaseSubviews { - [list_ release]; list_ = nil; } @@ -7636,7 +7212,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { database_ = database; packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL); - sections_ = [[NSMutableArray arrayWithCapacity:16] retain]; + sections_ = [NSMutableArray arrayWithCapacity:16]; } return self; } @@ -7654,7 +7230,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _end _trace(); _profile(ChangesController$_reloadPackages$radixSort) - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; _end _trace(); } @@ -7664,8 +7240,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { era_ = [database_ era]; NSArray *packages = [database_ packages]; - [sections_ removeAllObjects]; - #if 1 UIProgressHUD *hud([delegate_ addProgressHUD]); [hud setText:UCLocalize("LOADING")]; @@ -7676,6 +7250,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self _reloadPackages:packages]; #endif + [sections_ removeAllObjects]; + Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease]; Section *ignored = nil; Section *section = nil; @@ -7772,8 +7348,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { BOOL searchloaded_; } -- (id) initWithDatabase:(Database *)database; -- (void) setSearchTerm:(NSString *)term; +- (id) initWithDatabase:(Database *)database query:(NSString *)query; - (void) reloadData; @end @@ -7792,26 +7367,59 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]]; } -- (void) setSearchTerm:(NSString *)searchTerm { - [search_ setText:searchTerm]; +- (void) useSearch { + [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; + [self clearData]; [self reloadData]; } -- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { - [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; - [search_ resignFirstResponder]; +- (void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + if ([self filter] == @selector(isUnfilteredAndSelectedForBy:)) + [self useSearch]; +} + +- (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar { + [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSelectedForBy:)]; + [self clearData]; [self reloadData]; } +- (void) searchBarButtonClicked:(UISearchBar *)searchBar { + [search_ resignFirstResponder]; + [self useSearch]; +} + +- (void) searchBarCancelButtonClicked:(UISearchBar *)searchBar { + [search_ setText:@""]; + [self searchBarButtonClicked:searchBar]; +} + +- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { + [self searchBarButtonClicked:searchBar]; +} + - (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text { [self setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)]; [self reloadData]; } -- (id) initWithDatabase:(Database *)database { - if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil])) { +- (bool) shouldYield { + return [self filter] == @selector(isUnfilteredAndSearchedForBy:); +} + +- (bool) isSummarized { + return [self filter] == @selector(isUnfilteredAndSelectedForBy:); +} + +- (id) initWithDatabase:(Database *)database query:(NSString *)query { + if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:query])) { search_ = [[[UISearchBar alloc] init] autorelease]; [search_ setDelegate:self]; + + if (query != nil) + [search_ setText:query]; } return self; } @@ -7851,18 +7459,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Settings Controller {{{ */ -@interface PackageSettingsController : CYViewController < +@interface PackageSettingsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; - NSString *name_; - Package *package_; - UITableView *table_; - UISwitch *subscribedSwitch_; - UISwitch *ignoredSwitch_; - UITableViewCell *subscribedCell_; - UITableViewCell *ignoredCell_; + _H name_; + _H package_; + _H table_; + _H subscribedSwitch_; + _H ignoredSwitch_; + _H subscribedCell_; + _H ignoredCell_; } - (id) initWithDatabase:(Database *)database package:(NSString *)package; @@ -7871,14 +7479,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation PackageSettingsController -- (void) dealloc { - [self releaseSubviews]; - [name_ release]; - [package_ release]; - - [super dealloc]; -} - - (NSURL *) navigationURL { return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", [package_ id]]]; } @@ -7976,68 +7576,58 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) loadView { [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; + table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease]; [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [table_ setDataSource:self]; + [(UITableView *) table_ setDataSource:self]; [table_ setDelegate:self]; [[self view] addSubview:table_]; - subscribedSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; + subscribedSwitch_ = [[[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)] autorelease]; [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; [subscribedSwitch_ addTarget:self action:@selector(onSubscribed:) forEvents:UIControlEventValueChanged]; - ignoredSwitch_ = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)]; + ignoredSwitch_ = [[[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)] autorelease]; [ignoredSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; [ignoredSwitch_ addTarget:self action:@selector(onIgnored:) forEvents:UIControlEventValueChanged]; - subscribedCell_ = [[UITableViewCell alloc] init]; + subscribedCell_ = [[[UITableViewCell alloc] init] autorelease]; [subscribedCell_ setText:UCLocalize("SHOW_ALL_CHANGES")]; [subscribedCell_ setAccessoryView:subscribedSwitch_]; [subscribedCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; - ignoredCell_ = [[UITableViewCell alloc] init]; + ignoredCell_ = [[[UITableViewCell alloc] init] autorelease]; [ignoredCell_ setText:UCLocalize("IGNORE_UPGRADES")]; [ignoredCell_ setAccessoryView:ignoredSwitch_]; [ignoredCell_ setSelectionStyle:UITableViewCellSelectionStyleNone]; } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("SETTINGS")]; } - (void) releaseSubviews { - [ignoredCell_ release]; ignoredCell_ = nil; - - [subscribedCell_ release]; subscribedCell_ = nil; - - [table_ release]; table_ = nil; - - [ignoredSwitch_ release]; ignoredSwitch_ = nil; - - [subscribedSwitch_ release]; subscribedSwitch_ = nil; } - (id) initWithDatabase:(Database *)database package:(NSString *)package { if ((self = [super init]) != nil) { database_ = database; - name_ = [package retain]; + name_ = package; } return self; } - (void) reloadData { [super reloadData]; - if (package_ != nil) - [package_ autorelease]; package_ = [database_ packageWithName:name_]; if (package_ != nil) { - package_ = [package_ retain]; [subscribedSwitch_ setOn:([package_ subscribed] ? 1 : 0) animated:NO]; [ignoredSwitch_ setOn:([package_ ignored] ? 1 : 0) animated:NO]; } // XXX: what now, G? @@ -8123,11 +7713,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* Source Cell {{{ */ @interface SourceCell : CYTableViewCell < - ContentDelegate + CyteTableViewCellDelegate > { - UIImage *icon_; - NSString *origin_; - NSString *label_; + _H icon_; + _H origin_; + _H label_; } - (void) setSource:(Source *)source; @@ -8136,42 +7726,25 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation SourceCell -- (void) clearSource { - [icon_ release]; - [origin_ release]; - [label_ release]; - - icon_ = nil; - origin_ = nil; - label_ = nil; -} - - (void) setSource:(Source *)source { - [self clearSource]; - + icon_ = nil; if (icon_ == nil) icon_ = [UIImage applicationImageNamed:[NSString stringWithFormat:@"Sources/%@.png", [source host]]]; if (icon_ == nil) icon_ = [UIImage applicationImageNamed:@"unknown.png"]; - icon_ = [icon_ retain]; - origin_ = [[source name] retain]; - label_ = [[source uri] retain]; + origin_ = [source name]; + label_ = [source uri]; [content_ setNeedsDisplay]; } -- (void) dealloc { - [self clearSource]; - [super dealloc]; -} - - (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) { UIView *content([self contentView]); CGRect bounds([content bounds]); - content_ = [[ContentView alloc] initWithFrame:bounds]; + content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [content_ setBackgroundColor:[UIColor whiteColor]]; [content addSubview:content_]; @@ -8209,7 +7782,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* Source Controller {{{ */ @interface SourceController : FilteredPackageListController { _transient Source *source_; - NSString *key_; + _H key_; } - (id) initWithDatabase:(Database *)database source:(Source *)source; @@ -8225,14 +7798,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) initWithDatabase:(Database *)database source:(Source *)source { if ((self = [super initWithDatabase:database title:[source label] filter:@selector(isVisibleInSource:) with:source]) != nil) { source_ = source; - key_ = [[source key] retain]; + key_ = [source key]; } return self; } - (void) reloadData { source_ = [database_ sourceWithKey:key_]; - [key_ release]; - key_ = [[source_ key] retain]; + key_ = [source_ key]; [self setObject:source_]; [[self navigationItem] setTitle:[source_ label]]; @@ -8243,18 +7815,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Sources Controller {{{ */ -@interface SourcesController : CYViewController < +@interface SourcesController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; - UITableView *list_; - NSMutableArray *sources_; + _H list_; + _H sources_; int offset_; - NSString *href_; - UIProgressHUD *hud_; - NSError *error_; + _H href_; + _H hud_; + _H error_; //NSURLConnection *installer_; NSURLConnection *trivial_; @@ -8281,19 +7853,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) dealloc { - [self releaseSubviews]; - - [href_ release]; - [hud_ release]; - [error_ release]; - //[self _releaseConnection:installer_]; [self _releaseConnection:trivial_]; [self _releaseConnection:trivial_gz_]; [self _releaseConnection:trivial_bz2_]; //[self _releaseConnection:automatic_]; - [sources_ release]; [super dealloc]; } @@ -8370,9 +7935,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { - Source *source = [self sourceAtIndexPath:indexPath]; - [Sources_ removeObjectForKey:[source key]]; - [delegate_ syncData]; + if (editingStyle == UITableViewCellEditingStyleDelete) { + Source *source = [self sourceAtIndexPath:indexPath]; + [Sources_ removeObjectForKey:[source key]]; + [delegate_ syncData]; + } } - (void) complete { @@ -8418,6 +7985,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { trivial_bz2_ == nil && trivial_gz_ == nil ) { + [delegate_ releaseNetworkActivityIndicator]; + + [delegate_ removeProgressHUD:hud_]; + hud_ = nil; + bool defer(false); if (cydia_) { @@ -8463,21 +8035,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [alert show]; } - [delegate_ releaseNetworkActivityIndicator]; - - [delegate_ removeProgressHUD:hud_]; - [hud_ autorelease]; - hud_ = nil; - - if (!defer) { - [href_ release]; - href_ = nil; - } - - if (error_ != nil) { - [error_ release]; - error_ = nil; - } + href_ = nil; + error_ = nil; } } @@ -8490,8 +8049,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { lprintf("connection:\"%s\" didFailWithError:\"%s\"", [href_ UTF8String], [[error localizedDescription] UTF8String]); - if (error_ != nil) - error_ = [error retain]; + error_ = error; [self _endConnection:connection]; } @@ -8530,7 +8088,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { href_ = [href stringByAppendingString:@"/"]; else href_ = href; - href_ = [href_ retain]; trivial_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages"] method:@"HEAD"] retain]; trivial_bz2_ = [[self _requestHRef:[href_ stringByAppendingString:@"Packages.bz2"] method:@"HEAD"] retain]; @@ -8540,7 +8097,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { cydia_ = false; // XXX: this is stupid - hud_ = [[delegate_ addProgressHUD] retain]; + hud_ = [delegate_ addProgressHUD]; [hud_ setText:UCLocalize("VERIFYING_URL")]; [delegate_ retainNetworkActivityIndicator]; } break; @@ -8568,7 +8125,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _nodefault } - [href_ release]; href_ = nil; [alert dismissWithClickedButtonIndex:-1 animated:YES]; @@ -8578,28 +8134,29 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) loadView { [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - list_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain]; + list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease]; [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [list_ setRowHeight:56]; - [list_ setDataSource:self]; + [(UITableView *) list_ setDataSource:self]; [list_ setDelegate:self]; [[self view] addSubview:list_]; } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("SOURCES")]; [self updateButtonsForEditingStatus:NO animated:NO]; } - (void) releaseSubviews { - [list_ release]; list_ = nil; } - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; - sources_ = [[NSMutableArray arrayWithCapacity:16] retain]; + sources_ = [NSMutableArray arrayWithCapacity:16]; } return self; } @@ -8641,7 +8198,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { ] autorelease]; [alert setContext:@"source"]; - [alert setTransform:CGAffineTransformTranslate([alert transform], 0.0, 100.0)]; [alert setNumberOfRows:1]; [alert addTextFieldWithValue:@"http://" label:@""]; @@ -8698,16 +8254,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Settings Controller {{{ */ -@interface SettingsController : CYViewController < +@interface SettingsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { _transient Database *database_; // XXX: ok, "roledelegate_"?... _transient id roledelegate_; - UITableView *table_; - UISegmentedControl *segment_; - UIView *container_; + _H table_; + _H segment_; + _H container_; } - (void) showDoneButton; @@ -8717,19 +8273,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @implementation SettingsController -- (void) dealloc { - [self releaseSubviews]; - - [super dealloc]; -} - - (void) loadView { [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; - table_ = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped]; + table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease]; [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [table_ setDelegate:self]; - [table_ setDataSource:self]; + [(UITableView *) table_ setDataSource:self]; [[self view] addSubview:table_]; NSArray *items = [NSArray arrayWithObjects: @@ -8737,12 +8287,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UCLocalize("HACKER"), UCLocalize("DEVELOPER"), nil]; - segment_ = [[UISegmentedControl alloc] initWithItems:items]; - container_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)]; + segment_ = [[[UISegmentedControl alloc] initWithItems:items] autorelease]; + container_ = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)] autorelease]; [container_ addSubview:segment_]; } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("WHO_ARE_YOU")]; int index = -1; @@ -8759,13 +8311,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) releaseSubviews { - [table_ release]; table_ = nil; - - [segment_ release]; segment_ = nil; - - [container_ release]; container_ = nil; } @@ -8896,22 +8443,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Stash Controller {{{ */ -@interface StashController : CYViewController { - UIActivityIndicatorView *spinner_; - UILabel *status_; - UILabel *caption_; +@interface StashController : CyteViewController { + _H spinner_; + _H status_; + _H caption_; } @end @implementation StashController -- (void) dealloc { - [self releaseSubviews]; - - [super dealloc]; -} - - (void) loadView { [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]]; [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]]; @@ -8956,19 +8497,37 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [[self view] addSubview:status_]; } -- (void) releaseSubviews { - [spinner_ release]; - spinner_ = nil; +@end +/* }}} */ + +@interface CYURLCache : SDURLCache { +} - [status_ release]; - status_ = nil; +@end + +@implementation CYURLCache - [caption_ release]; - caption_ = nil; +- (void) logEvent:(NSString *)event forRequest:(NSURLRequest *)request { +#if !ForRelease + if (false); + else if ([event isEqualToString:@"no-cache"]) + event = @"!!!"; + else if ([event isEqualToString:@"store"]) + event = @">>>"; + else if ([event isEqualToString:@"invalid"]) + event = @"???"; + else if ([event isEqualToString:@"memory"]) + event = @"mem"; + else if ([event isEqualToString:@"disk"]) + event = @"ssd"; + else if ([event isEqualToString:@"miss"]) + event = @"---"; + + NSLog(@"%@: %@", event, [[request URL] absoluteString]); +#endif } @end -/* }}} */ @interface Cydia : UIApplication < ConfirmationControllerDelegate, @@ -8977,23 +8536,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UINavigationControllerDelegate, UITabBarControllerDelegate > { - // XXX: evaluate all fields for _transient - - UIWindow *window_; - CYTabBarController *tabbar_; - CYEmulatedLoadingController *emulated_; + _H window_; + _H tabbar_; + _H emulated_; - NSMutableArray *essential_; - NSMutableArray *broken_; + _H essential_; + _H broken_; Database *database_; - NSURL *starturl_; + _H starturl_; unsigned locked_; unsigned activity_; - StashController *stash_; + _H stash_; bool loaded_; } @@ -9071,17 +8628,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } // Navigation controller for the queuing badge. -- (CYNavigationController *) queueNavigationController { +- (UINavigationController *) queueNavigationController { NSArray *controllers = [tabbar_ viewControllers]; return [controllers objectAtIndex:3]; } +- (void) unloadData { + [tabbar_ unloadData]; +} + - (void) _updateData { [self _saveConfig]; - [tabbar_ reloadData]; + [self unloadData]; - CYNavigationController *navigation = [self queueNavigationController]; + UINavigationController *navigation = [self queueNavigationController]; id queuedelegate = nil; if ([[navigation viewControllers] count] > 0) @@ -9211,13 +8772,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [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]); + UINavigationController *navigation([[[UINavigationController alloc] initWithRootViewController:controller] autorelease]); if (IsWildcat_) [navigation setModalPresentationStyle:UIModalPresentationFormSheet]; @@ -9324,8 +8884,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { ConfirmationController *page([[[ConfirmationController alloc] initWithDatabase:database_] autorelease]); [page setDelegate:self]; - CYNavigationController *confirm_([[[CYNavigationController alloc] initWithRootViewController:page] autorelease]); - [confirm_ setDelegate:self]; + UINavigationController *confirm_([[[UINavigationController alloc] initWithRootViewController:page] autorelease]); if (IsWildcat_) [confirm_ setModalPresentationStyle:UIModalPresentationFormSheet]; @@ -9390,11 +8949,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) showSettings { - SettingsController *role = [[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease]; - CYNavigationController *nav = [[[CYNavigationController alloc] initWithRootViewController:role] autorelease]; - if (IsWildcat_) - [nav setModalPresentationStyle:UIModalPresentationFormSheet]; - [tabbar_ presentModalViewController:nav animated:YES]; + [self presentModalViewController:[[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease] force:NO]; } - (void) retainNetworkActivityIndicator { @@ -9444,7 +8999,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } else if ([context isEqualToString:@"fixhalf"]) { if (button == [alert cancelButtonIndex]) { @synchronized (self) { - for (Package *broken in broken_) { + for (Package *broken in (id) broken_) { [broken remove]; NSString *id = [broken id]; @@ -9466,7 +9021,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } else if ([context isEqualToString:@"upgrade"]) { if (button == [alert firstOtherButtonIndex]) { @synchronized (self) { - for (Package *essential in essential_) + for (Package *essential in (id) essential_) [essential install]; [self resolve]; @@ -9544,28 +9099,32 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [hud setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; [window_ setUserInteractionEnabled:NO]; - [hud show:YES]; - UIViewController *target = tabbar_; - while ([target modalViewController] != nil) target = [target modalViewController]; - [[target view] addSubview:hud]; + UIViewController *target(tabbar_); + if (UIViewController *modal = [target modalViewController]) + target = modal; + + UIView *view([target view]); + [view addSubview:hud]; + + [hud show:YES]; ++locked_; return hud; } - (void) removeProgressHUD:(UIProgressHUD *)hud { + --locked_; [hud show:NO]; [hud removeFromSuperview]; [window_ setUserInteractionEnabled:YES]; - --locked_; } -- (CYViewController *) pageForPackage:(NSString *)name { +- (CyteViewController *) pageForPackage:(NSString *)name { return [[[CYPackageController alloc] initWithDatabase:database_ forPackage:name] autorelease]; } -- (CYViewController *) pageForURL:(NSURL *)url forExternal:(BOOL)external { +- (CyteViewController *) pageForURL:(NSURL *)url forExternal:(BOOL)external { NSString *scheme([[url scheme] lowercaseString]); if ([[url absoluteString] length] <= [scheme length] + 3) return nil; @@ -9580,12 +9139,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSString *base([components objectAtIndex:0]); - CYViewController *controller = nil; + CyteViewController *controller = nil; if ([base isEqualToString:@"url"]) { // This kind of URL can contain slashes in the argument, so we can't parse them below. NSString *destination = [[url absoluteString] substringFromIndex:([scheme length] + [@"://" length] + [base length] + [@"/" length])]; - controller = [[[CYBrowserController alloc] initWithURL:[NSURL URLWithString:destination]] autorelease]; + controller = [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:destination]] autorelease]; } else if (!external && [components count] == 1) { if ([base isEqualToString:@"manage"]) { controller = [[[ManageController alloc] init] autorelease]; @@ -9604,7 +9163,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } if ([base isEqualToString:@"search"]) { - controller = [[[SearchController alloc] initWithDatabase:database_] autorelease]; + controller = [[[SearchController alloc] initWithDatabase:database_ query:nil] autorelease]; } if ([base isEqualToString:@"changes"]) { @@ -9622,8 +9181,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } if (!external && [base isEqualToString:@"search"]) { - controller = [[[SearchController alloc] initWithDatabase:database_] autorelease]; - [(SearchController *)controller setSearchTerm:argument]; + controller = [[[SearchController alloc] initWithDatabase:database_ query:argument] autorelease]; } if (!external && [base isEqualToString:@"sections"]) { @@ -9667,10 +9225,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (BOOL) openCydiaURL:(NSURL *)url forExternal:(BOOL)external { - CYViewController *page([self pageForURL:url forExternal:external]); + CyteViewController *page([self pageForURL:url forExternal:external]); if (page != nil) { - CYNavigationController *nav = [[[CYNavigationController alloc] init] autorelease]; + UINavigationController *nav = [[[UINavigationController alloc] init] autorelease]; [nav setViewControllers:[NSArray arrayWithObject:page]]; [tabbar_ setUnselectedViewController:nav]; } @@ -9681,8 +9239,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) applicationOpenURL:(NSURL *)url { [super applicationOpenURL:url]; - if (!loaded_) starturl_ = [url retain]; - else [self openCydiaURL:url forExternal:YES]; + if (!loaded_) + starturl_ = url; + else + [self openCydiaURL:url forExternal:YES]; } - (void) applicationWillResignActive:(UIApplication *)application { @@ -9732,13 +9292,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) addStashController { ++locked_; - stash_ = [[StashController alloc] init]; + stash_ = [[[StashController alloc] init] autorelease]; [window_ addSubview:[stash_ view]]; } - (void) removeStashController { [[stash_ view] removeFromSuperview]; - [stash_ release]; + stash_ = nil; --locked_; } @@ -9759,7 +9319,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) setupViewControllers { - tabbar_ = [[CYTabBarController alloc] initWithDatabase:database_]; + tabbar_ = [[[CYTabBarController alloc] initWithDatabase:database_] autorelease]; NSMutableArray *items([NSMutableArray arrayWithObjects: [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage applicationImageNamed:@"home.png"] tag:0] autorelease], @@ -9777,7 +9337,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSMutableArray *controllers([NSMutableArray array]); for (UITabBarItem *item in items) { - CYNavigationController *controller([[[CYNavigationController alloc] initWithDatabase:database_] autorelease]); + UINavigationController *controller([[[UINavigationController alloc] init] autorelease]); [controller setTabBarItem:item]; [controllers addObject:controller]; } @@ -9795,26 +9355,32 @@ _trace(); [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]]; } - [NSURLCache setSharedURLCache:[[[SDURLCache alloc] + [NSURLCache setSharedURLCache:[[[CYURLCache alloc] initWithMemoryCapacity:524288 diskCapacity:10485760 diskPath:[NSString stringWithFormat:@"%@/Library/Caches/com.saurik.Cydia/SDURLCache", @"/var/root"] ] autorelease]]; - [CYBrowserController _initialize]; + [CydiaWebViewController _initialize]; [NSURLProtocol registerClass:[CydiaURLProtocol class]]; - Font12_ = [[UIFont systemFontOfSize:12] retain]; - Font12Bold_ = [[UIFont boldSystemFontOfSize:12] retain]; - Font14_ = [[UIFont systemFontOfSize:14] retain]; - Font18Bold_ = [[UIFont boldSystemFontOfSize:18] retain]; - Font22Bold_ = [[UIFont boldSystemFontOfSize:22] retain]; + // this would disallow http{,s} URLs from accessing this data + //[WebView registerURLSchemeAsLocal:@"cydia"]; + + Font12_ = [UIFont systemFontOfSize:12]; + Font12Bold_ = [UIFont boldSystemFontOfSize:12]; + Font14_ = [UIFont systemFontOfSize:14]; + Font18Bold_ = [UIFont boldSystemFontOfSize:18]; + Font22Bold_ = [UIFont boldSystemFontOfSize:22]; - essential_ = [[NSMutableArray alloc] initWithCapacity:4]; - broken_ = [[NSMutableArray alloc] initWithCapacity:4]; + essential_ = [NSMutableArray arrayWithCapacity:4]; + broken_ = [NSMutableArray arrayWithCapacity:4]; - window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + // XXX: I really need this thing... like, seriously... I'm sorry + [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData]; + + window_ = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; [window_ orderFront:self]; [window_ makeKey:self]; [window_ setHidden:NO]; @@ -9845,7 +9411,7 @@ _trace(); [window_ setUserInteractionEnabled:NO]; [self setupViewControllers]; - emulated_ = [[CYEmulatedLoadingController alloc] initWithDatabase:database_]; + emulated_ = [[[CYEmulatedLoadingController alloc] initWithDatabase:database_] autorelease]; [window_ addSubview:[emulated_ view]]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; @@ -9871,7 +9437,7 @@ _trace(); _trace(); if (Role_ == nil) { [window_ setUserInteractionEnabled:YES]; - [self presentModalViewController:[[[SettingsController alloc] initWithDatabase:database_ delegate:self] autorelease] force:NO]; + [self showSettings]; return; } else { if ([emulated_ modalViewController] != nil) @@ -9928,13 +9494,13 @@ _trace(); for (unsigned int tab = 0; tab < [[tabbar_ viewControllers] count]; tab++) { NSArray *stack = [items objectAtIndex:tab]; - CYNavigationController *navigation = [[tabbar_ viewControllers] objectAtIndex:tab]; + UINavigationController *navigation = [[tabbar_ viewControllers] objectAtIndex:tab]; NSMutableArray *current = [NSMutableArray array]; for (unsigned int nav = 0; nav < [stack count]; nav++) { NSString *addr = [stack objectAtIndex:nav]; NSURL *url = [NSURL URLWithString:addr]; - CYViewController *page = [self pageForURL:url forExternal:NO]; + CyteViewController *page = [self pageForURL:url forExternal:NO]; if (page != nil) [current addObject:page]; } @@ -9945,7 +9511,6 @@ _trace(); // (Try to) show the startup URL. if (starturl_ != nil) { [self openCydiaURL:starturl_ forExternal:NO]; - [starturl_ release]; starturl_ = nil; } } @@ -9998,52 +9563,42 @@ MSHook(void, UIWebDocumentView$_setUIKitDelegate$, UIWebDocumentView *self, SEL return _UIWebDocumentView$_setUIKitDelegate$(self, _cmd, delegate); } -static NSNumber *shouldPlayKeyboardSounds; - -Class $UIHardware; - -MSHook(void, UIHardware$_playSystemSound$, Class self, SEL _cmd, int sound) { - switch (sound) { - case 1104: // Keyboard Button Clicked - case 1105: // Keyboard Delete Repeated - if (shouldPlayKeyboardSounds == nil) { - NSDictionary *dict([[[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.preferences.sounds.plist"] autorelease]); - shouldPlayKeyboardSounds = [([dict objectForKey:@"keyboard"] ?: (id) kCFBooleanTrue) retain]; - } - - if (![shouldPlayKeyboardSounds boolValue]) - break; +static NSSet *MobilizedFiles_; - default: - _UIHardware$_playSystemSound$(self, _cmd, sound); +static NSURL *MobilizeURL(NSURL *url) { + NSString *path([url path]); + if ([path hasPrefix:@"/var/root/"]) { + NSString *file([path substringFromIndex:10]); + if ([MobilizedFiles_ containsObject:file]) + url = [NSURL fileURLWithPath:[@"/var/mobile/" stringByAppendingString:file] isDirectory:NO]; } -} -Class $UIApplication; - -MSHook(void, UIApplication$_updateApplicationAccessibility, UIApplication *self, SEL _cmd) { - static BOOL initialized = NO; - static BOOL started = NO; + return url; +} - NSDictionary *dict([[[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.Accessibility.plist"] autorelease]); - BOOL enabled = [[dict objectForKey:@"VoiceOverTouchEnabled"] boolValue] || [[dict objectForKey:@"VoiceOverTouchEnabledByiTunes"] boolValue]; +Class $CFXPreferencesPropertyListSource; +@class CFXPreferencesPropertyListSource; - if ([self respondsToSelector:@selector(_accessibilityBundlePrincipalClass)]) { - id bundle = [self performSelector:@selector(_accessibilityBundlePrincipalClass)]; - if (![bundle respondsToSelector:@selector(_accessibilityStopServer)]) return; - if (![bundle respondsToSelector:@selector(_accessibilityStartServer)]) return; +MSHook(BOOL, CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync, CFXPreferencesPropertyListSource *self, SEL _cmd) { + NSURL *&url(MSHookIvar(self, "_url")), *old(url); + NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); + url = MobilizeURL(url); + BOOL value(_CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync(self, _cmd)); + //NSLog(@"%@ %s", [url absoluteString], value ? "YES" : "NO"); + url = old; + [pool release]; + return value; +} - if (initialized && !enabled) { - initialized = NO; - [bundle performSelector:@selector(_accessibilityStopServer)]; - } else if (enabled) { - initialized = YES; - if (!started) { - started = YES; - [bundle performSelector:@selector(_accessibilityStartServer)]; - } - } - } +MSHook(void *, CFXPreferencesPropertyListSource$createPlistFromDisk, CFXPreferencesPropertyListSource *self, SEL _cmd) { + NSURL *&url(MSHookIvar(self, "_url")), *old(url); + NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); + url = MobilizeURL(url); + void *value(_CFXPreferencesPropertyListSource$createPlistFromDisk(self, _cmd)); + //NSLog(@"%@ %@", [url absoluteString], value); + url = old; + [pool release]; + return value; } Class $NSURLConnection; @@ -10097,9 +9652,9 @@ int main(int argc, char *argv[]) { _pooled NSLog(@"unknown UIUserInterfaceIdiom!"); } - SessionData_ = [[NSMutableDictionary alloc] initWithCapacity:4]; + SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4]; - HostConfig_ = [[NSObject alloc] init]; + HostConfig_ = [[[NSObject alloc] init] autorelease]; @synchronized (HostConfig_) { BridgedHosts_ = [NSMutableSet setWithCapacity:4]; PipelinedHosts_ = [NSMutableSet setWithCapacity:4]; @@ -10109,9 +9664,28 @@ int main(int argc, char *argv[]) { _pooled PackageName = reinterpret_cast(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname)))); + MobilizedFiles_ = [NSMutableSet setWithObjects: + @"Library/Preferences/com.apple.Accessibility.plist", + @"Library/Preferences/com.apple.preferences.sounds.plist", + nil]; + /* Library Hacks {{{ */ class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16"); + $CFXPreferencesPropertyListSource = objc_getClass("CFXPreferencesPropertyListSource"); + + Method CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync(class_getInstanceMethod($CFXPreferencesPropertyListSource, @selector(_backingPlistChangedSinceLastSync))); + if (CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync != NULL) { + _CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync = reinterpret_cast(method_getImplementation(CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync)); + method_setImplementation(CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync, reinterpret_cast(&$CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync)); + } + + Method CFXPreferencesPropertyListSource$createPlistFromDisk(class_getInstanceMethod($CFXPreferencesPropertyListSource, @selector(createPlistFromDisk))); + if (CFXPreferencesPropertyListSource$createPlistFromDisk != NULL) { + _CFXPreferencesPropertyListSource$createPlistFromDisk = reinterpret_cast(method_getImplementation(CFXPreferencesPropertyListSource$createPlistFromDisk)); + method_setImplementation(CFXPreferencesPropertyListSource$createPlistFromDisk, reinterpret_cast(&$CFXPreferencesPropertyListSource$createPlistFromDisk)); + } + $WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate"); Method UIWebDocumentView$_setUIKitDelegate$(class_getInstanceMethod([WebView class], @selector(_setUIKitDelegate:))); if (UIWebDocumentView$_setUIKitDelegate$ != NULL) { @@ -10125,20 +9699,6 @@ int main(int argc, char *argv[]) { _pooled _NSURLConnection$init$ = reinterpret_cast(method_getImplementation(NSURLConnection$init$)); method_setImplementation(NSURLConnection$init$, reinterpret_cast(&$NSURLConnection$init$)); } - - $UIHardware = objc_getClass("UIHardware"); - Method UIHardware$_playSystemSound$(class_getClassMethod($UIHardware, @selector(_playSystemSound:))); - if (UIHardware$_playSystemSound$ != NULL) { - _UIHardware$_playSystemSound$ = reinterpret_cast(method_getImplementation(UIHardware$_playSystemSound$)); - method_setImplementation(UIHardware$_playSystemSound$, reinterpret_cast(&$UIHardware$_playSystemSound$)); - } - - $UIApplication = objc_getClass("UIApplication"); - Method UIApplication$_updateApplicationAccessibility(class_getInstanceMethod($UIApplication, @selector(_updateApplicationAccessibility))); - if (UIApplication$_updateApplicationAccessibility != NULL) { - _UIApplication$_updateApplicationAccessibility = reinterpret_cast(method_getImplementation(UIApplication$_updateApplicationAccessibility)); - method_setImplementation(UIApplication$_updateApplicationAccessibility, reinterpret_cast(&$UIApplication$_updateApplicationAccessibility)); - } /* }}} */ /* Set Locale {{{ */ Locale_ = CFLocaleCopyCurrent(); @@ -10150,16 +9710,23 @@ int main(int argc, char *argv[]) { _pooled const char *lang; if (Locale_ != NULL) lang = [(NSString *) CFLocaleGetIdentifier(Locale_) UTF8String]; - else if (Languages_ == nil || [Languages_ count] == 0) + else if (Languages_ != nil && [Languages_ count] != 0) + lang = [[Languages_ objectAtIndex:0] UTF8String]; + else // XXX: consider just setting to C and then falling through? lang = NULL; - else { - lang = [[Languages_ objectAtIndex:0] UTF8String]; - setenv("LANG", lang, true); - std::setlocale(LC_ALL, lang); + + if (lang != NULL) { + Pcre pattern("^([a-z][a-z])(?:-[A-Za-z]*)?(_[A-Z][A-Z])?$"); + lang = !pattern(lang) ? NULL : [pattern->*@"%1$@%2$@" UTF8String]; } NSLog(@"Setting Language: %s", lang); + + if (lang != NULL) { + setenv("LANG", lang, true); + std::setlocale(LC_ALL, lang); + } /* }}} */ apr_app_initialize(&argc, const_cast(&argv), NULL); @@ -10229,28 +9796,9 @@ int main(int argc, char *argv[]) { _pooled else Machine_ = machine; - if (CFMutableDictionaryRef dict = IOServiceMatching("IOPlatformExpertDevice")) { - if (io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, dict)) { - if (CFTypeRef serial = IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0)) { - SerialNumber_ = [NSString stringWithString:(NSString *)serial]; - CFRelease(serial); - } - - if (CFTypeRef ecid = IORegistryEntrySearchCFProperty(service, kIODeviceTreePlane, CFSTR("unique-chip-id"), kCFAllocatorDefault, kIORegistryIterateRecursively)) { - NSData *data((NSData *) ecid); - size_t length([data length]); - uint8_t bytes[length]; - [data getBytes:bytes]; - char string[length * 2 + 1]; - for (size_t i(0); i != length; ++i) - sprintf(string + i * 2, "%.2X", bytes[length - i - 1]); - ChipID_ = [NSString stringWithUTF8String:string]; - CFRelease(ecid); - } - - IOObjectRelease(service); - } - } + SerialNumber_ = (NSString *) CYIOGetValue("IOService:/", @"IOPlatformSerialNumber"); + ChipID_ = [CYHex((NSData *) CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true) uppercaseString]; + BBSNum_ = CYHex((NSData *) CYIOGetValue("IOService:/AppleARMPE/baseband", @"snum"), false); UniqueID_ = [[UIDevice currentDevice] uniqueIdentifier];