X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/ed3caba999d35cd2d60025fa24ea2e6e7087b86b..367a112d938db5c80814b42c428b517e4a65efd9:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 4f90372c..b359a279 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -48,12 +48,9 @@ #include #include "iPhonePrivate.h" -#include - #include #include -#include #include #include @@ -113,20 +110,12 @@ extern "C" { #include "Substrate.hpp" #include "Menes/Menes.h" -#include "CyteKit/IndirectDelegate.h" +#include "CyteKit/CyteKit.h" #include "CyteKit/RegEx.hpp" -#include "CyteKit/TableViewCell.h" -#include "CyteKit/TabBarController.h" -#include "CyteKit/WebScriptObject-Cyte.h" -#include "CyteKit/WebViewController.h" -#include "CyteKit/WebViewTableViewCell.h" -#include "CyteKit/stringWithUTF8Bytes.h" #include "Cydia/MIMEAddress.h" #include "Cydia/LoadingViewController.h" #include "Cydia/ProgressEvent.h" - -#include "SDURLCache/SDURLCache.h" /* }}} */ /* Profiler {{{ */ @@ -199,10 +188,6 @@ void PrintTimes() { #define _end } /* }}} */ -// XXX: I hate clang. Apple: please get over your petty hatred of GPL and fix your gcc fork -#define synchronized(lock) \ - synchronized(static_cast(lock)) - extern NSString *Cydia_; #define lprintf(args...) fprintf(stderr, args) @@ -240,16 +225,6 @@ union SplitHash { }; // }}} -@implementation NSDictionary (Cydia) -- (id) invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)arguments { - if (false); - else if ([name isEqualToString:@"get"]) - return [self objectForKey:[arguments objectAtIndex:0]]; - else if ([name isEqualToString:@"keys"]) - return [self allKeys]; - return nil; -} @end - static NSString *Colon_; NSString *Elision_; static NSString *Error_; @@ -271,26 +246,6 @@ static NSString *UniqueIdentifier(UIDevice *device = nil) { return [(id)$MGCopyAnswer(CFSTR("UniqueDeviceID")) autorelease]; } -static bool IsReachable(const char *name) { - SCNetworkReachabilityFlags flags; { - SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, name)); - SCNetworkReachabilityGetFlags(reachability, &flags); - CFRelease(reachability); - } - - // XXX: this elaborate mess is what Apple is using to determine this? :( - // XXX: do we care if the user has to intervene? maybe that's ok? - return - (flags & kSCNetworkReachabilityFlagsReachable) != 0 && ( - (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || ( - (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 || - (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0 - ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 || - (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0 - ) - ; -} - static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); static _finline NSString *CydiaURL(NSString *path) { @@ -317,11 +272,6 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) { notify_post("com.saurik.Cydia.status"); } -static CGFloat CYStatusBarHeight() { - CGSize size([[UIApplication sharedApplication] statusBarFrame].size); - return UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? size.height : size.width; -} - /* NSForcedOrderingSearch doesn't work on the iPhone */ static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch; static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch; @@ -329,53 +279,47 @@ static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareNumerically | kCF /* Insertion Sort {{{ */ -CFIndex SKBSearch_(const void *element, CFIndex elementSize, const void *list, CFIndex count, CFComparatorFunction comparator, void *context) { - const char *ptr = (const char *)list; - while (0 < count) { - CFIndex half = count / 2; - const char *probe = ptr + elementSize * half; - CFComparisonResult cr = comparator(element, probe, context); - if (0 == cr) return (probe - (const char *)list) / elementSize; - ptr = (cr < 0) ? ptr : probe + elementSize; - count = (cr < 0) ? half : (half + (count & 1) - 1); - } - return (ptr - (const char *)list) / elementSize; -} - -CFIndex CFBSearch_(const void *element, CFIndex elementSize, const void *list, CFIndex count, CFComparatorFunction comparator, void *context) { +template +size_t CFBSearch_(const Type_ &element, const void *list, size_t count, CFComparisonResult (*comparator)(Type_, Type_, void *), void *context) { const char *ptr = (const char *)list; while (0 < count) { - CFIndex half = count / 2; - const char *probe = ptr + elementSize * half; - CFComparisonResult cr = comparator(element, probe, context); - if (0 == cr) return (probe - (const char *)list) / elementSize; - ptr = (cr < 0) ? ptr : probe + elementSize; + size_t half = count / 2; + const char *probe = ptr + sizeof(Type_) * half; + CFComparisonResult cr = comparator(element, * (const Type_ *) probe, context); + if (0 == cr) return (probe - (const char *)list) / sizeof(Type_); + ptr = (cr < 0) ? ptr : probe + sizeof(Type_); count = (cr < 0) ? half : (half + (count & 1) - 1); } - return (ptr - (const char *)list) / elementSize; + return (ptr - (const char *)list) / sizeof(Type_); } -void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFComparatorFunction comparator, void *context) { - if (range.length == 0) +template +void CYArrayInsertionSortValues(Type_ *values, size_t length, CFComparisonResult (*comparator)(Type_, Type_, void *), void *context) { + if (length == 0) return; - const void **values(new const void *[range.length]); - CFArrayGetValues(array, range, values); #if HistogramInsertionSort > 0 - uint32_t total(0), *offsets(new uint32_t[range.length]); + uint32_t total(0), *offsets(new uint32_t[length]); #endif - for (CFIndex index(1); index != range.length; ++index) { - const void *value(values[index]); - //CFIndex correct(SKBSearch_(&value, sizeof(const void *), values, index, comparator, context)); - CFIndex correct(index); + for (size_t index(1); index != length; ++index) { + Type_ value(values[index]); +#if 0 + size_t correct(CFBSearch_(value, values, index, comparator, context)); +#else + size_t correct(index); while (comparator(value, values[correct - 1], context) == kCFCompareLessThan) { #if HistogramInsertionSort > 1 NSLog(@"%@ < %@", value, values[correct - 1]); #endif if (--correct == 0) break; + if (index - correct >= 8) { + correct = CFBSearch_(value, values, correct, comparator, context); + break; + } } +#endif if (correct != index) { size_t offset(index - correct); #if HistogramInsertionSort @@ -389,11 +333,8 @@ void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFCompar } } - CFArrayReplaceValues(array, range, values, range.length); - delete [] values; - #if HistogramInsertionSort > 0 - for (CFIndex index(0); index != range.length; ++index) + for (size_t index(0); index != range.length; ++index) if (offsets[index] != 0) NSLog(@"Insertion Displacement [%u]: %u", index, offsets[index]); NSLog(@"Average Insertion Displacement: %f", double(total) / range.length); @@ -403,47 +344,6 @@ void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFCompar /* }}} */ -/* Apple Bug Fixes {{{ */ -@implementation UIWebDocumentView (Cydia) - -- (void) _setScrollerOffset:(CGPoint)offset { - UIScroller *scroller([self _scroller]); - - CGSize size([scroller contentSize]); - CGSize bounds([scroller bounds].size); - - CGPoint max; - max.x = size.width - bounds.width; - max.y = size.height - bounds.height; - - // wtf Apple?! - if (max.x < 0) - max.x = 0; - if (max.y < 0) - max.y = 0; - - offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x; - offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y; - - [scroller setOffset:offset]; -} - -@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) - return 0; - else if (length > count) - length = count; - for (size_t i(0); i != length; ++i) - objects[i] = [self item:state->state++]; - state->itemsPtr = objects; - state->mutationsPtr = (unsigned long *) self; - return length; -} - /* Cydia NSString Additions {{{ */ @interface NSString (Cydia) - (NSComparisonResult) compareByPath:(NSString *)other; @@ -724,15 +624,7 @@ static _H Font18_; static _H Font18Bold_; static _H Font22Bold_; -static const char *Machine_ = NULL; -static _H System_; -static NSString *SerialNumber_ = nil; -static NSString *ChipID_ = nil; -static NSString *BBSNum_ = nil; static _H UniqueID_; -static _H UserAgent_; -static _H Product_; -static _H Safari_; static _H CollationLocale_; static _H CollationThumbs_; @@ -799,18 +691,9 @@ _H Sources_; static _transient NSNumber *Version_; static time_t now_; -bool IsWildcat_; -CGFloat ScreenScale_; -static NSString *Idiom_; -static _H Firmware_; -static NSString *Major_; - static _H SessionData_; -static _H HostConfig_; static _H BridgedHosts_; static _H InsecureHosts_; -static _H PipelinedHosts_; -static _H CachedURLs_; static NSString *kCydiaProgressEventTypeError = @"Error"; static NSString *kCydiaProgressEventTypeInformation = @"Information"; @@ -819,30 +702,6 @@ static NSString *kCydiaProgressEventTypeWarning = @"Warning"; /* }}} */ /* Display Helpers {{{ */ -inline float Interpolate(float begin, float end, float fraction) { - return (end - begin) * fraction + begin; -} - -static inline double Retina(double value) { - value *= ScreenScale_; - value = round(value); - value /= ScreenScale_; - return value; -} - -static inline CGRect Retina(CGRect value) { - value.origin.x *= ScreenScale_; - value.origin.y *= ScreenScale_; - value.size.width *= ScreenScale_; - value.size.height *= ScreenScale_; - value = CGRectIntegral(value); - value.origin.x /= ScreenScale_; - value.origin.y /= ScreenScale_; - value.size.width /= ScreenScale_; - value.size.height /= ScreenScale_; - return value; -} - static _finline const char *StripVersion_(const char *version) { const char *colon(strchr(version, ':')); return colon == NULL ? version : colon + 1; @@ -889,34 +748,6 @@ 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]; -} - static NSString *VerifySource(NSString *href) { static RegEx href_r("(http(s?)://|file:///)[^# ]*"); if (!href_r(href)) { @@ -1119,7 +950,7 @@ typedef std::map< unsigned long, _H > SourceMap; SourceMap sourceMap_; _H sourceList_; - CFMutableArrayRef packages_; + _H packages_; _transient NSObject *delegate_; _transient NSObject *progress_; @@ -1203,7 +1034,10 @@ class SourceStatus : } //printf("Set(%s, %s)\n", fetch ? "true" : "false", uri.c_str()); - [database_ setFetch:fetch forURI:uri.c_str()]; + + auto slash(uri.rfind('/')); + if (slash != std::string::npos) + [database_ setFetch:fetch forURI:uri.substr(0, slash).c_str()]; } _finline void Set(bool fetch, pkgAcquire::Item *item) { @@ -1668,13 +1502,10 @@ static void SaveConfig(NSObject *lock) { _profile(Source$setMetaIndex$DescURI) for (pkgAcquire::ItemIterator item(acquire.ItemsBegin()); item != acquire.ItemsEnd(); item++) { std::string file((*item)->DescURI()); - files_.insert(file); - if (file.length() < sizeof("Packages.bz2") || file.substr(file.length() - sizeof("Packages.bz2")) != "/Packages.bz2") + auto slash(file.rfind('/')); + if (slash == std::string::npos) continue; - file = file.substr(0, file.length() - 4); - files_.insert(file); - files_.insert(file + ".gz"); - files_.insert(file + "Index"); + files_.insert(file.substr(0, slash)); } _end @@ -2143,6 +1974,8 @@ struct ParsedPackage { } - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database; ++ (Package *) newPackageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database; + + (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database; - (pkgCache::PkgIterator) iterator; @@ -2712,7 +2545,7 @@ struct PackageNameOrdering : _end } return self; } -+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database { ++ (Package *) newPackageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database { pkgCache::VerIterator version; _profile(Package$packageWithIterator$GetCandidateVer) @@ -2737,13 +2570,14 @@ struct PackageNameOrdering : ]; _end - _profile(Package$packageWithIterator$Autorelease) - package = [package autorelease]; - _end - return package; } +// XXX: just in case a Cydia extension is using this (I bet this is unlikely, though, due to CYPool?) ++ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database { + return [[self newPackageWithIterator:iterator withZone:zone inPool:pool database:database] autorelease]; +} + - (pkgCache::PkgIterator) iterator { return iterator_; } @@ -3328,8 +3162,8 @@ struct PackageNameOrdering : } - (void) setIndex:(size_t)index { - if (metadata_->index_ != index) - metadata_->index_ = index; + if (metadata_->index_ != index + 1) + metadata_->index_ = index + 1; } - (CYString &) cyname { @@ -3520,12 +3354,11 @@ class CydiaLogCleaner : } - (void) releasePackages { - CFArrayApplyFunction(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&CFRelease), NULL); - CFArrayRemoveAllValues(packages_); + packages_ = nil; } - (bool) hasPackages { - return CFArrayGetCount(packages_) != 0; + return [packages_ count] != 0; } - (void) dealloc { @@ -3651,7 +3484,7 @@ class CydiaLogCleaner : , "any" #endif )); - return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:NULL database:self]; + return iterator.end() ? nil : [[Package newPackageWithIterator:iterator withZone:NULL inPool:NULL database:self] autorelease]; } } - (id) init { @@ -3664,13 +3497,6 @@ class CydiaLogCleaner : zone_ = NSCreateZone(1024 * 1024, 256 * 1024, NO); - size_t capacity(MetaFile_->active_); - if (capacity == 0) - capacity = 16384; - else - capacity += 1024; - - packages_ = CFArrayCreateMutable(kCFAllocatorDefault, capacity, NULL); sourceList_ = [NSMutableArray arrayWithCapacity:16]; int fds[2]; @@ -3739,7 +3565,7 @@ class CydiaLogCleaner : } - (NSArray *) packages { - return (NSArray *) packages_; + return packages_; } - (NSArray *) sources { @@ -3956,40 +3782,89 @@ class CydiaLogCleaner : } { - /*std::vector packages; - packages.reserve(std::max(10000U, [packages_ count] + 1000)); - packages_ = nil;*/ + size_t capacity(MetaFile_->active_); + if (capacity == 0) + capacity = 128*1024; + else + capacity += 1024; + + std::vector packages; + packages.reserve(capacity); + size_t lost(0); + size_t last(0); _profile(reloadDataWithInvocation$packageWithIterator) 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_, CFRetain(package)); + if (Package *package = [Package newPackageWithIterator:iterator withZone:zone_ inPool:&pool_ database:self]) { + if (unsigned index = package.metadata->index_) { + --index; + if (packages.size() == index) { + packages.push_back(package); + } else if (packages.size() <= index) { + packages.resize(index + 1, nil); + packages[index] = package; + continue; + } else { + std::swap(package, packages[index]); + if (package != nil) { + if (package.metadata->index_ == index + 1) + ++lost; + goto lost; + } + if (last != index) + continue; + } + } else { + ++lost; + lost: if (last == packages.size()) + packages.push_back(package); + else + packages[last] = package; + ++last; + } + + for (; last != packages.size(); ++last) + if (packages[last] == nil) + break; + } _end + for (size_t next(last + 1); last != packages.size(); ++last, ++next) { + while (true) { + if (next == packages.size()) + goto done; + if (packages[next] != nil) + break; + ++next; + } + + std::swap(packages[last], packages[next]); + } done:; - /*if (packages.empty()) - packages_ = [[NSArray alloc] init]; - else - packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()]; - _trace();*/ + packages.resize(last); - _profile(reloadDataWithInvocation$radix$8) - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(8)]; - _end + if (lost > 128) { + NSLog(@"lost = %zu", lost); - _profile(reloadDataWithInvocation$radix$4) - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(4)]; - _end + _profile(reloadDataWithInvocation$radix$8) + CYRadixSortUsingFunction(packages.data(), packages.size(), reinterpret_cast(&PackagePrefixRadix), reinterpret_cast(8)); + _end - _profile(reloadDataWithInvocation$radix$0) - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; - _end + _profile(reloadDataWithInvocation$radix$4) + CYRadixSortUsingFunction(packages.data(), packages.size(), reinterpret_cast(&PackagePrefixRadix), reinterpret_cast(4)); + _end + + _profile(reloadDataWithInvocation$radix$0) + CYRadixSortUsingFunction(packages.data(), packages.size(), reinterpret_cast(&PackagePrefixRadix), reinterpret_cast(0)); + _end + } _profile(reloadDataWithInvocation$insertion) - CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&PackageNameCompare), NULL); + CYArrayInsertionSortValues(packages.data(), packages.size(), &PackageNameCompare, NULL); _end + packages_ = [[[NSArray alloc] initWithObjects:packages.data() count:packages.size()] autorelease]; + /*_profile(reloadDataWithInvocation$CFQSortArray) CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast(&PackageNameCompare_), NULL); _end*/ @@ -4006,11 +3881,12 @@ class CydiaLogCleaner : [packages_ sortUsingFunction:reinterpret_cast(&PackageNameCompare) context:NULL]; _end*/ - - size_t count(CFArrayGetCount(packages_)); - MetaFile_->active_ = count; - for (size_t index(0); index != count; ++index) - [(Package *) CFArrayGetValueAtIndex(packages_, index) setIndex:index]; + MetaFile_->active_ = packages.size(); + for (size_t index(0), count(packages.size()); index != count; ++index) { + auto package(packages[index]); + [package setIndex:index]; + [package release]; + } } } } @@ -4279,76 +4155,16 @@ class CydiaLogCleaner : @end /* }}} */ -static _H Diversions_; - -@interface Diversion : NSObject { - RegEx pattern_; - _H key_; - _H format_; -} - -@end - -@implementation Diversion - -- (id) initWithFrom:(NSString *)from to:(NSString *)to { - if ((self = [super init]) != nil) { - pattern_ = [from UTF8String]; - key_ = from; - format_ = to; - } return self; -} - -- (NSString *) divert:(NSString *)url { - return !pattern_(url) ? nil : pattern_->*format_; -} - -+ (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 url; -} - -- (NSString *) key { - return key_; -} - -- (NSUInteger) hash { - return [key_ hash]; -} - -- (BOOL) isEqual:(Diversion *)object { - return self == object || [self class] == [object class] && [key_ isEqual:[object key]]; -} - -@end - -@interface CydiaObject : NSObject { - _H indirect_; +@interface CydiaObject : CyteObject { _transient id delegate_; } -- (id) initWithDelegate:(IndirectDelegate *)indirect; - @end -@class CydiaObject; - @interface CydiaWebViewController : CyteWebViewController { _H cydia_; } -+ (void) addDiversion:(Diversion *)diversion; + (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request; + (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia; - (void) setDelegate:(id)delegate; @@ -4358,85 +4174,30 @@ static _H Diversions_; /* Web Scripting {{{ */ @implementation CydiaObject -- (id) initWithDelegate:(IndirectDelegate *)indirect { - if ((self = [super init]) != nil) { - indirect_ = (CyteWebViewController *) indirect; - } return self; -} - - (void) setDelegate:(id)delegate { delegate_ = delegate; } -+ (NSArray *) _attributeKeys { - return [NSArray arrayWithObjects: - @"bittage", - @"bbsnum", - @"build", +- (NSArray *) attributeKeys { + return [[NSArray arrayWithObjects: @"cells", - @"coreFoundationVersionNumber", @"device", - @"ecid", - @"firmware", - @"hostname", - @"idiom", @"mcc", @"mnc", - @"model", @"operator", @"role", - @"serial", @"version", - nil]; -} - -- (NSArray *) attributeKeys { - return [[self class] _attributeKeys]; -} - -+ (BOOL) isKeyExcludedFromWebScript:(const char *)name { - return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name]; + nil] arrayByAddingObjectsFromArray:[super attributeKeys]]; } - (NSString *) version { return Cydia_; } -- (unsigned) bittage { -#if 0 -#elif defined(__arm64__) - return 64; -#elif defined(__arm__) - return 32; -#else - return 0; -#endif -} - -- (NSString *) build { - return System_; -} - -- (NSString *) coreFoundationVersionNumber { - return [NSString stringWithFormat:@"%.2f", kCFCoreFoundationVersionNumber]; -} - - (NSString *) device { return UniqueIdentifier(); } -- (NSString *) firmware { - return [[UIDevice currentDevice] systemVersion]; -} - -- (NSString *) hostname { - return [[UIDevice currentDevice] name]; -} - -- (NSString *) idiom { - return (id) Idiom_ ?: [NSNull null]; -} - - (NSArray *) cells { auto *$_CTServerConnectionCreate(reinterpret_cast(dlsym(RTLD_DEFAULT, "_CTServerConnectionCreate"))); if ($_CTServerConnectionCreate == NULL) @@ -4478,46 +4239,22 @@ static _H Diversions_; return nil; } -- (NSString *) bbsnum { - return (id) BBSNum_ ?: [NSNull null]; -} - -- (NSString *) ecid { - return (id) ChipID_ ?: [NSNull null]; -} - -- (NSString *) serial { - return SerialNumber_; -} - - (NSString *) role { return (id) [NSNull null]; } -- (NSString *) model { - return [NSString stringWithUTF8String:Machine_]; -} - + (NSString *) webScriptNameForSelector:(SEL)selector { if (false); else if (selector == @selector(addBridgedHost:)) return @"addBridgedHost"; else if (selector == @selector(addInsecureHost:)) return @"addInsecureHost"; - else if (selector == @selector(addInternalRedirect::)) - return @"addInternalRedirect"; - else if (selector == @selector(addPipelinedHost:scheme:)) - return @"addPipelinedHost"; else if (selector == @selector(addSource:::)) return @"addSource"; else if (selector == @selector(addTrivialSource:)) return @"addTrivialSource"; - else if (selector == @selector(close)) - return @"close"; else if (selector == @selector(du:)) return @"du"; - else if (selector == @selector(stringWithFormat:arguments:)) - return @"format"; else if (selector == @selector(getAllSources)) return @"getAllSources"; else if (selector == @selector(getApplicationInfo:value:)) @@ -4526,18 +4263,8 @@ static _H Diversions_; return @"getDisplayIdentifiers"; else if (selector == @selector(getLocalizedNameForDisplayIdentifier:)) return @"getLocalizedNameForDisplayIdentifier"; - else if (selector == @selector(getKernelNumber:)) - return @"getKernelNumber"; - else if (selector == @selector(getKernelString:)) - 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(getMetadataKeys)) @@ -4548,18 +4275,8 @@ static _H Diversions_; return @"getSessionValue"; else if (selector == @selector(installPackages:)) return @"installPackages"; - else if (selector == @selector(isReachable:)) - return @"isReachable"; - else if (selector == @selector(localizedStringForKey:value:table:)) - return @"localize"; - else if (selector == @selector(popViewController:)) - return @"popViewController"; else if (selector == @selector(refreshSources)) return @"refreshSources"; - else if (selector == @selector(registerFrame:)) - return @"registerFrame"; - else if (selector == @selector(removeButton)) - return @"removeButton"; else if (selector == @selector(saveConfig)) return @"saveConfig"; else if (selector == @selector(setMetadataValue::)) @@ -4568,42 +4285,8 @@ static _H Diversions_; return @"setSessionValue"; else if (selector == @selector(substitutePackageNames:)) return @"substitutePackageNames"; - else if (selector == @selector(scrollToBottom:)) - 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:)) - return @"setButtonTitle"; - else if (selector == @selector(setHidesBackButton:)) - return @"setHidesBackButton"; - else if (selector == @selector(setHidesNavigationBar:)) - return @"setHidesNavigationBar"; - else if (selector == @selector(setNavigationBarStyle:)) - return @"setNavigationBarStyle"; - else if (selector == @selector(setNavigationBarTintRed:green:blue:alpha:)) - return @"setNavigationBarTintColor"; - else if (selector == @selector(setPasteboardString:)) - return @"setPasteboardString"; - else if (selector == @selector(setPasteboardURL:)) - return @"setPasteboardURL"; - else if (selector == @selector(setScrollAlwaysBounceVertical:)) - return @"setScrollAlwaysBounceVertical"; - else if (selector == @selector(setScrollIndicatorStyle:)) - return @"setScrollIndicatorStyle"; else if (selector == @selector(setToken:)) return @"setToken"; - else if (selector == @selector(setViewportWidth:)) - return @"setViewportWidth"; - else if (selector == @selector(statfs:)) - return @"statfs"; - else if (selector == @selector(supports:)) - return @"supports"; - else if (selector == @selector(unload)) - return @"unload"; else return nil; } @@ -4612,26 +4295,6 @@ static _H Diversions_; return [self webScriptNameForSelector:selector] == nil; } -- (BOOL) supports:(NSString *)feature { - return [feature isEqualToString:@"window.open"]; -} - -- (void) unload { - [delegate_ performSelectorOnMainThread:@selector(unloadData) withObject:nil waitUntilDone:NO]; -} - -- (void) setScrollAlwaysBounceVertical:(NSNumber *)value { - [indirect_ performSelectorOnMainThread:@selector(setScrollAlwaysBounceVerticalNumber:) withObject:value waitUntilDone:NO]; -} - -- (void) setScrollIndicatorStyle:(NSString *)style { - [indirect_ performSelectorOnMainThread:@selector(setScrollIndicatorStyleWithName:) withObject:style waitUntilDone:NO]; -} - -- (void) addInternalRedirect:(NSString *)from :(NSString *)to { - [CydiaWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO]; -} - - (NSDictionary *) getApplicationInfo:(NSString *)display value:(NSString *)key { char path[1024]; if (SBBundlePathForDisplayIdentifier(SBSSpringBoardServerPort(), [display UTF8String], path) != 0) @@ -4667,43 +4330,11 @@ static _H Diversions_; return [NSNumber numberWithInt:value]; } -- (NSString *) getKernelString:(NSString *)name { - const char *string([name UTF8String]); - - size_t size; - if (sysctlbyname(string, NULL, &size, NULL, 0) == -1) - return (id) [NSNull null]; - - char value[size + 1]; - if (sysctlbyname(string, value, &size, NULL, 0) == -1) - return (id) [NSNull null]; - - // XXX: just in case you request something ludicrous - value[size] = '\0'; - - 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; -} - - (NSArray *) getMetadataKeys { @synchronized (Values_) { return [Values_ allKeys]; } } -- (void) registerFrame:(DOMHTMLIFrameElement *)iframe { - WebFrame *frame([iframe contentFrame]); - [indirect_ registerFrame:frame]; -} - - (id) getMetadataValue:(NSString *)key { @synchronized (Values_) { return [Values_ objectForKey:key]; @@ -4731,29 +4362,15 @@ static _H Diversions_; } } - (void) addBridgedHost:(NSString *)host { -@synchronized (HostConfig_) { +@synchronized (BridgedHosts_) { [BridgedHosts_ addObject:host]; } } - (void) addInsecureHost:(NSString *)host { -@synchronized (HostConfig_) { +@synchronized (InsecureHosts_) { [InsecureHosts_ addObject:host]; } } -- (void) addPipelinedHost:(NSString *)host scheme:(NSString *)scheme { -@synchronized (HostConfig_) { - if (scheme != (id) [WebUndefined undefined]) - host = [NSString stringWithFormat:@"%@:%@", [scheme lowercaseString], host]; - - [PipelinedHosts_ addObject:host]; -} } - -- (void) popViewController:(NSNumber *)value { - if (value == (id) [WebUndefined undefined]) - value = [NSNumber numberWithBool:YES]; - [indirect_ performSelectorOnMainThread:@selector(popViewControllerWithNumber:) withObject:value waitUntilDone:NO]; -} - - (void) addSource:(NSString *)href :(NSString *)distribution :(WebScriptObject *)sections { NSMutableArray *array([NSMutableArray arrayWithCapacity:[sections count]]); @@ -4807,27 +4424,6 @@ static _H 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; - - if (path == nil || statfs([path UTF8String], &stat) == -1) - return nil; - - return [NSArray arrayWithObjects: - [NSNumber numberWithUnsignedLong:stat.f_bsize], - [NSNumber numberWithUnsignedLong:stat.f_blocks], - [NSNumber numberWithUnsignedLong:stat.f_bfree], - nil]; -} - - (NSNumber *) du:(NSString *)path { NSNumber *value(nil); @@ -4849,14 +4445,6 @@ static _H Diversions_; return value; } -- (void) close { - [indirect_ performSelectorOnMainThread:@selector(close) withObject:nil waitUntilDone:NO]; -} - -- (NSNumber *) isReachable:(NSString *)name { - return [NSNumber numberWithBool:IsReachable([name UTF8String])]; -} - - (void) installPackages:(NSArray *)packages { [delegate_ performSelectorOnMainThread:@selector(installPackages:) withObject:packages waitUntilDone:NO]; } @@ -4878,81 +4466,10 @@ static _H Diversions_; return [words componentsJoinedByString:@" "]; } -- (void) removeButton { - [indirect_ removeButton]; -} - -- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { - [indirect_ setButtonImage:button withStyle:style toFunction:function]; -} - -- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { - [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]; -} - -- (void) setHidesBackButton:(NSString *)value { - [indirect_ performSelectorOnMainThread:@selector(setHidesBackButtonByNumber:) withObject:value waitUntilDone:NO]; -} - -- (void) setHidesNavigationBar:(NSString *)value { - [indirect_ performSelectorOnMainThread:@selector(setHidesNavigationBarByNumber:) withObject:value waitUntilDone:NO]; -} - -- (void) setNavigationBarStyle:(NSString *)value { - [indirect_ performSelectorOnMainThread:@selector(setNavigationBarStyle:) withObject:value waitUntilDone:NO]; -} - -- (void) setNavigationBarTintRed:(NSNumber *)red green:(NSNumber *)green blue:(NSNumber *)blue alpha:(NSNumber *)alpha { - float opacity(alpha == (id) [WebUndefined undefined] ? 1 : [alpha floatValue]); - UIColor *color([UIColor colorWithRed:[red floatValue] green:[green floatValue] blue:[blue floatValue] alpha:opacity]); - [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 { // XXX: the website expects this :/ } -- (void) scrollToBottom:(NSNumber *)animated { - [indirect_ performSelectorOnMainThread:@selector(scrollToBottomAnimated:) withObject:animated waitUntilDone:NO]; -} - -- (void) setViewportWidth:(float)width { - [indirect_ setViewportWidthOnMainThread:width]; -} - -- (NSString *) stringWithFormat:(NSString *)format arguments:(WebScriptObject *)arguments { - //NSLog(@"SWF:\"%@\" A:%@", format, [arguments description]); - unsigned count([arguments count]); - id values[count]; - for (unsigned i(0); i != count; ++i) - values[i] = [arguments objectAtIndex:i]; - return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast(values)] autorelease]; -} - -- (NSString *) localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table { - if (reinterpret_cast(value) == [WebUndefined undefined]) - value = nil; - if (reinterpret_cast(table) == [WebUndefined undefined]) - table = nil; - return [[NSBundle mainBundle] localizedStringForKey:key value:value table:table]; -} - @end /* }}} */ @@ -4965,7 +4482,7 @@ static _H Diversions_; if ([[[self scheme] lowercaseString] isEqualToString:@"https"]) return true; - @synchronized (HostConfig_) { + @synchronized (InsecureHosts_) { if ([InsecureHosts_ containsObject:[self host]]) return true; } @@ -4979,17 +4496,10 @@ static _H Diversions_; @implementation CydiaWebViewController - (NSURL *) navigationURL { - return request_ == nil ? nil : [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]]; -} - -+ (void) _initialize { - [super _initialize]; - - Diversions_ = [NSMutableSet setWithCapacity:0]; -} - -+ (void) addDiversion:(Diversion *)diversion { - [Diversions_ addObject:diversion]; + if (NSURLRequest *request = self.request) + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request URL] absoluteString]]]; + else + return nil; } - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { @@ -5005,7 +4515,7 @@ static _H Diversions_; bool bridged(false); - @synchronized (HostConfig_) { + @synchronized (BridgedHosts_) { if ([scheme isEqualToString:@"file"]) bridged = true; else if ([scheme isEqualToString:@"https"]) @@ -5024,10 +4534,6 @@ static _H Diversions_; [controller addAttachmentData:[NSData dataWithContentsOfFile:@"/tmp/dpkgl.log"] mimeType:@"text/plain" fileName:@"dpkgl.log"]; } -- (NSURL *) URLWithURL:(NSURL *)url { - return [Diversion divertURL:url]; -} - - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { return [CydiaWebViewController requestWithHeaders:[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]]; } @@ -5061,7 +4567,7 @@ static _H Diversions_; if (Machine_ != NULL && [copy valueForHTTPHeaderField:@"X-Machine"] == nil) [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; - bool bridged; @synchronized (HostConfig_) { + bool bridged; @synchronized (BridgedHosts_) { bridged = [BridgedHosts_ containsObject:host]; } @@ -5076,13 +4582,9 @@ static _H Diversions_; [cydia_ setDelegate:delegate]; } -- (NSString *) applicationNameForUserAgent { - return UserAgent_; -} - - (id) init { if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) { - cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease]; + cydia_ = [[[CydiaObject alloc] initWithDelegate:self.indirect] autorelease]; } return self; } @@ -5106,42 +4608,6 @@ static _H Diversions_; @end /* }}} */ -// CydiaScript {{{ -@interface NSObject (CydiaScript) -- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context; -@end - -@implementation NSObject (CydiaScript) - -- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context { - return self; -} - -@end - -@implementation NSArray (CydiaScript) - -- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context { - WebScriptObject *object([context evaluateWebScript:@"[]"]); - for (size_t i(0), e([self count]); i != e; ++i) - [object setWebScriptValueAtIndex:i value:[[self objectAtIndex:i] Cydia$webScriptObjectInContext:context]]; - return object; -} - -@end - -@implementation NSDictionary (CydiaScript) - -- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context { - WebScriptObject *object([context evaluateWebScript:@"({})"]); - for (id i in self) - [object setValue:[[self objectForKey:i] Cydia$webScriptObjectInContext:context] forKey:i]; - return object; -} - -@end -// }}} - /* Confirmation Controller {{{ */ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (!iterator.end()) @@ -5185,7 +4651,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) complete { if (substrate_) RestartSubstrate_ = true; - [delegate_ confirmWithNavigationController:[self navigationController]]; + [self.delegate confirmWithNavigationController:[self navigationController]]; } - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { @@ -5208,7 +4674,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) _doContinue { - [delegate_ cancelAndClear:NO]; + [self.delegate cancelAndClear:NO]; [self dismissModalViewControllerAnimated:YES]; } @@ -5431,7 +4897,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { #endif - (void) cancelButtonClicked { - [delegate_ cancelAndClear:YES]; + [self.delegate cancelAndClear:YES]; [self dismissModalViewControllerAnimated:YES]; } @@ -5615,7 +5081,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) initWithDatabase:(Database *)database delegate:(id)delegate { if ((self = [super init]) != nil) { database_ = database; - delegate_ = delegate; + self.delegate = delegate; [database_ setProgressDelegate:self]; @@ -5624,7 +5090,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/progress/", UI_]]]; - [scroller_ setBackgroundColor:[UIColor blackColor]]; + [self setPageColor:[UIColor blackColor]]; [[self navigationItem] setHidesBackButton:YES]; @@ -5650,19 +5116,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UpdateExternalStatus(0); if (Finish_ > 1) - [delegate_ saveState]; + [self.delegate saveState]; switch (Finish_) { case 0: - [delegate_ returnToCydia]; + [self.delegate returnToCydia]; break; case 1: - [delegate_ terminateWithSuccess]; - /*if ([delegate_ respondsToSelector:@selector(suspendWithAnimation:)]) - [delegate_ suspendWithAnimation:YES]; + [self.delegate terminateWithSuccess]; + /*if ([self.delegate respondsToSelector:@selector(suspendWithAnimation:)]) + [self.delegate suspendWithAnimation:YES]; else - [delegate_ suspend];*/ + [self.delegate suspend];*/ break; case 2: @@ -5674,9 +5140,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { goto reload; reload: { - UIProgressHUD *hud([delegate_ addProgressHUD]); + UIProgressHUD *hud([self.delegate addProgressHUD]); [hud setText:UCLocalize("LOADING")]; - [delegate_ performSelector:@selector(reloadSpringBoard) withObject:nil afterDelay:0.5]; + [self.delegate performSelector:@selector(reloadSpringBoard) withObject:nil afterDelay:0.5]; return; } @@ -5871,15 +5337,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (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_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; - [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [content addSubview:content_]; - - [content_ setDelegate:self]; - [content_ setOpaque:YES]; + [self.content setOpaque:YES]; } return self; } @@ -5898,7 +5356,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { placard_ = nil; if (package == nil) - [content_ setBackgroundColor:[UIColor whiteColor]]; + [self.content setBackgroundColor:[UIColor whiteColor]]; else { [package parse]; @@ -5958,18 +5416,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { placard = nil; } - [content_ setBackgroundColor:color]; + [self.content setBackgroundColor:color]; if (placard != nil) placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]]; } [self setNeedsDisplay]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } - (void) drawSummaryContentRect:(CGRect)rect { - bool highlighted(highlighted_); + bool highlighted(self.highlighted); float width([self bounds].size.width); if (icon_ != nil) { @@ -6012,7 +5470,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) drawNormalContentRect:(CGRect)rect { - bool highlighted(highlighted_); + bool highlighted(self.highlighted); float width([self bounds].size.width); if (icon_ != nil) { @@ -6094,15 +5552,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { 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_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; - [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [content addSubview:content_]; - [content_ setBackgroundColor:[UIColor whiteColor]]; - - [content_ setDelegate:self]; + [self.content setBackgroundColor:[UIColor whiteColor]]; } return self; } @@ -6147,7 +5597,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self setAccessoryType:editing ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator]; [self setSelectionStyle:editing ? UITableViewCellSelectionStyleNone : UITableViewCellSelectionStyleBlue]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } - (void) setFrame:(CGRect)frame { @@ -6162,7 +5612,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) drawContentRect:(CGRect)rect { - bool highlighted(highlighted_ && !editing_); + bool highlighted(self.highlighted && !editing_); [icon_ drawInRect:CGRectMake(7, 7, 32, 32)]; @@ -6188,7 +5638,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* File Table {{{ */ -@interface FileTable : CyteViewController < +@interface FileTable : CyteListController < UITableViewDataSource, UITableViewDelegate > { @@ -6196,11 +5646,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _H package_; _H name_; _H files_; - _H list_; } -- (id) initWithDatabase:(Database *)database; -- (void) setPackage:(Package *)package; +- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name; @end @@ -6232,47 +5680,36 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/files", [package_ id]]]; } -- (void) loadView { - list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:24.0f]; - [(UITableView *) list_ setDataSource:self]; - [list_ setDelegate:self]; - [self setView:list_]; -} - -- (void) viewDidLoad { - [super viewDidLoad]; - - [[self navigationItem] setTitle:UCLocalize("INSTALLED_FILES")]; +- (CGFloat) rowHeight { + return 24; } - (void) releaseSubviews { - list_ = nil; - package_ = nil; files_ = nil; [super releaseSubviews]; } -- (id) initWithDatabase:(Database *)database { - if ((self = [super init]) != nil) { +- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name { + if ((self = [super initWithTitle:UCLocalize("INSTALLED_FILES")]) != nil) { database_ = database; + name_ = name; } return self; } -- (void) setPackage:(Package *)package { - package_ = nil; - name_ = nil; +- (bool) shouldYield { + return false; +} - files_ = [NSMutableArray arrayWithCapacity:32]; +- (void) _reloadData { + files_ = nil; - if (package != nil) { - package_ = package; - name_ = [package id]; + package_ = [database_ packageWithName:name_]; + if (package_ != nil) { + files_ = [NSMutableArray arrayWithCapacity:32]; - if (NSArray *files = [package files]) + if (NSArray *files = [package_ files]) [files_ addObjectsFromArray:files]; if ([files_ count] != 0) { @@ -6297,13 +5734,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } - [list_ reloadData]; -} - -- (void) reloadData { - [super reloadData]; - - [self setPackage:[database_ packageWithName:name_]]; + [super _reloadData]; } @end @@ -6333,14 +5764,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) _clickButtonWithPackage:(Package *)package { - [delegate_ installPackage:package]; + [self.delegate installPackage:package]; } - (void) _clickButtonWithName:(NSString *)name { if ([name isEqualToString:@"CLEAR"]) - return [delegate_ clearPackage:package_]; + return [self.delegate clearPackage:package_]; else if ([name isEqualToString:@"REMOVE"]) - return [delegate_ removePackage:package_]; + return [self.delegate removePackage:package_]; else if ([name isEqualToString:@"DOWNGRADE"]) { sheet_ = [[[UIActionSheet alloc] initWithTitle:nil @@ -6354,7 +5785,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sheet_ addButtonWithTitle:[version latest]]; [sheet_ setContext:@"version"]; - [delegate_ showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]]; + [self.delegate showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]]; return; } @@ -6363,7 +5794,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { else if ([name isEqualToString:@"UPGRADE"]); else _assert(false); - [delegate_ installPackage:package_]; + [self.delegate installPackage:package_]; } - (void) actionSheet:(UIActionSheet *)sheet clickedButtonAtIndex:(NSInteger)button { @@ -6399,6 +5830,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { #if !AlwaysReload - (void) _customButtonClicked { + if (commercial_ && self.isLoading && [package_ uninstalled]) + return [self reloadURLWithCache:NO]; + size_t count(buttons_.size()); if (count == 0) return; @@ -6422,16 +5856,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sheet_ addButtonWithTitle:button]; [sheet_ setContext:@"modify"]; - [delegate_ showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]]; + [self.delegate showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]]; } } -- (void) reloadButtonClicked { - if (commercial_ && function_ == nil && [package_ uninstalled]) - return; - [self customButtonClicked]; -} - - (void) applyLoadingTitle { // Don't show "Loading" as the title. Ever. } @@ -6507,7 +5935,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Package List Controller {{{ */ -@interface PackageListController : CyteViewController < +@interface PackageListController : CyteListController < UITableViewDataSource, UITableViewDelegate > { @@ -6515,19 +5943,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { unsigned era_; _H packages_; _H sections_; - _H list_; _H thumbs_; std::vector offset_; - _H title_; unsigned reloading_; } - (id) initWithDatabase:(Database *)database title:(NSString *)title; -- (void) setDelegate:(id)delegate; -- (void) resetCursor; -- (void) clearData; - (NSArray *) sectionsForPackages:(NSMutableArray *)packages; @@ -6547,98 +5970,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return true; } -- (void) deselectWithAnimation:(BOOL)animated { - [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; -} - -- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve { - CGRect base = [[self view] bounds]; - base.size.height -= bounds.size.height; - base.origin = [list_ frame].origin; - - [UIView beginAnimations:nil context:NULL]; - [UIView setAnimationBeginsFromCurrentState:YES]; - [UIView setAnimationCurve:curve]; - [UIView setAnimationDuration:duration]; - [list_ setFrame:base]; - [UIView commitAnimations]; -} - -- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration { - [self resizeForKeyboardBounds:bounds duration:duration curve:UIViewAnimationCurveLinear]; -} - -- (void) resizeForKeyboardBounds:(CGRect)bounds { - [self resizeForKeyboardBounds:bounds duration:0]; -} - -- (void) getKeyboardCurve:(UIViewAnimationCurve *)curve duration:(NSTimeInterval *)duration forNotification:(NSNotification *)notification { - if (&UIKeyboardAnimationCurveUserInfoKey == NULL) - *curve = UIViewAnimationCurveEaseInOut; - else - [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:curve]; - - if (&UIKeyboardAnimationDurationUserInfoKey == NULL) - *duration = 0.3; - else - [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:duration]; -} - -- (void) keyboardWillShow:(NSNotification *)notification { - CGRect bounds; - CGPoint center; - [[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&bounds]; - [[[notification userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey] getValue:¢er]; - - NSTimeInterval duration; - UIViewAnimationCurve curve; - [self getKeyboardCurve:&curve duration:&duration forNotification:notification]; - - CGRect kbframe = CGRectMake(Retina(center.x - bounds.size.width / 2), Retina(center.y - bounds.size.height / 2), bounds.size.width, bounds.size.height); - UIViewController *base = self; - while ([base parentOrPresentingViewController] != nil) - base = [base parentOrPresentingViewController]; - CGRect viewframe = [[base view] convertRect:[list_ frame] fromView:[list_ superview]]; - CGRect intersection = CGRectIntersection(viewframe, kbframe); - - if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4) - intersection.size.height += CYStatusBarHeight(); - - [self resizeForKeyboardBounds:intersection duration:duration curve:curve]; -} - -- (void) keyboardWillHide:(NSNotification *)notification { - NSTimeInterval duration; - UIViewAnimationCurve curve; - [self getKeyboardCurve:&curve duration:&duration forNotification:notification]; - - [self resizeForKeyboardBounds:CGRectZero duration:duration curve:curve]; -} - -- (void) viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - - [self resizeForKeyboardBounds:CGRectZero]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; -} - -- (void) viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; - - [self resizeForKeyboardBounds:CGRectZero]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; -} - -- (void) viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - [self deselectWithAnimation:animated]; -} - - (void) didSelectPackage:(Package *)package { CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id] withReferrer:[[self referrerURL] absoluteString]] autorelease]); - [view setDelegate:delegate_]; + [view setDelegate:self.delegate]; [[self navigationController] pushViewController:view animated:YES]; } @@ -6694,39 +6028,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return offset_[index]; } -- (void) updateHeight { - [list_ setRowHeight:([self isSummarized] ? 38 : 73)]; +- (CGFloat) rowHeight { + return [self isSummarized] ? 38 : 73; } - (id) initWithDatabase:(Database *)database title:(NSString *)title { - if ((self = [super init]) != nil) { + if ((self = [super initWithTitle:title]) != nil) { database_ = database; - title_ = [title copy]; - [[self navigationItem] setTitle:title_]; } return self; } -- (void) loadView { - UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]); - [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; - [self setView:view]; - - list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [view addSubview:list_]; - - // XXX: is 20 the most optimal number here? - [list_ setSectionIndexMinimumDisplayRowCount:20]; - - [(UITableView *) list_ setDataSource:self]; - [list_ setDelegate:self]; - - [self updateHeight]; -} - - (void) releaseSubviews { - list_ = nil; - packages_ = nil; sections_ = nil; @@ -6736,14 +6048,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super releaseSubviews]; } -- (void) setDelegate:(id)delegate { - delegate_ = delegate; -} - -- (bool) shouldYield { - return false; -} - - (bool) shouldBlock { return false; } @@ -6772,7 +6076,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (![self shouldBlock]) hud = nil; else { - hud = [delegate_ addProgressHUD]; + hud = [self.delegate addProgressHUD]; [hud setText:UCLocalize("LOADING")]; } @@ -6780,7 +6084,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { packages = [self yieldToSelector:@selector(_reloadPackages)]; if (hud != nil) - [delegate_ removeProgressHUD:hud]; + [self.delegate removeProgressHUD:hud]; } while (reloading_ == 2); } else { packages = [self _reloadPackages]; @@ -6804,12 +6108,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { sections_ = [NSArray arrayWithObject:section]; } - [self updateHeight]; - - _profile(PackageTable$reloadData$List) - [(UITableView *) list_ setDataSource:self]; - [list_ reloadData]; - _end + [super _reloadData]; } PrintTimes(); @@ -6868,28 +6167,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return sections; } -- (void) reloadData { - [super reloadData]; - - if ([self shouldYield]) - [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0]; - else - [self _reloadData]; -} - -- (void) resetCursor { - [list_ scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO]; -} - -- (void) clearData { - [self updateHeight]; - - [list_ setDataSource:nil]; - [list_ reloadData]; - - [self resetCursor]; -} - @end /* }}} */ /* Filtered Package List Controller {{{ */ @@ -7026,15 +6303,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi @end /* }}} */ -/* Cydia Navigation Controller Interface {{{ */ -@interface UINavigationController (Cydia) - -- (NSArray *) navigationURLCollection; -- (void) unloadData; - -@end -/* }}} */ - /* Cydia Tab Bar Controller {{{ */ @interface CydiaTabBarController : CyteTabBarController < UITabBarControllerDelegate, @@ -7049,7 +6317,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi _transient NSObject *updatedelegate_; } -- (NSArray *) navigationURLCollection; - (void) beginUpdate; - (BOOL) updating; @@ -7057,19 +6324,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi @implementation CydiaTabBarController -- (NSArray *) navigationURLCollection { - NSMutableArray *items([NSMutableArray array]); - - // XXX: Should this deal with transient view controllers? - for (id navigation in [self viewControllers]) { - NSArray *stack = [navigation performSelector:@selector(navigationURLCollection)]; - if (stack != nil) - [items addObject:stack]; - } - - return items; -} - - (id) initWithDatabase:(Database *)database { if ((self = [super init]) != nil) { database_ = database; @@ -7168,103 +6422,19 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi @end /* }}} */ -/* Cydia Navigation Controller Implementation {{{ */ -@implementation UINavigationController (Cydia) - -- (NSArray *) navigationURLCollection { - NSMutableArray *stack([NSMutableArray array]); - - for (CyteViewController *controller in [self viewControllers]) { - NSString *url = [[controller navigationURL] absoluteString]; - if (url != nil) - [stack addObject:url]; - } - - return stack; -} - -- (void) reloadData { - [super reloadData]; - - UIViewController *visible([self visibleViewController]); - if (visible != nil) - [visible reloadData]; - - // on the iPad, this view controller is ALSO visible. :( - if (IsWildcat_) - if (UIViewController *modal = [self modalViewController]) - if ([modal modalPresentationStyle] == UIModalPresentationFormSheet) - if (UIViewController *top = [self topViewController]) - if (top != visible) - [top reloadData]; -} - -- (void) unloadData { - for (CyteViewController *page in [self viewControllers]) - [page unloadData]; - - [super unloadData]; -} - -@end -/* }}} */ - /* Cydia:// Protocol {{{ */ -@interface CydiaURLProtocol : NSURLProtocol { +@interface CydiaURLProtocol : CyteURLProtocol { } @end @implementation CydiaURLProtocol -+ (BOOL) canInitWithRequest:(NSURLRequest *)request { - NSURL *url([request URL]); - if (url == nil) - return NO; - - NSString *scheme([[url scheme] lowercaseString]); - if (scheme != nil && [scheme isEqualToString:@"cydia"]) - return YES; - if ([[url absoluteString] hasPrefix:@"about:cydia-"]) - return YES; - - return NO; -} - -+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request { - return request; -} - -- (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request { - id client([self client]); - if (icon == nil) - [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]]; - else { - NSData *data(UIImagePNGRepresentation(icon)); - - NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]); - [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; - [client URLProtocol:self didLoadData:data]; - [client URLProtocolDidFinishLoading:self]; - } ++ (NSString *) scheme { + return @"cydia"; } -- (void) startLoading { - id client([self client]); - NSURLRequest *request([self request]); - - NSURL *url([request URL]); - NSString *href([url absoluteString]); - NSString *scheme([[url scheme] lowercaseString]); - - NSString *path; - - if ([scheme isEqualToString:@"cydia"]) - path = [href substringFromIndex:8]; - else if ([scheme isEqualToString:@"about"]) - path = [href substringFromIndex:12]; - else _assert(false); - +- (bool) loadForPath:(NSString *)path ofRequest:(NSURLRequest *)request { NSRange slash([path rangeOfString:@"/"]); NSString *command; @@ -7324,11 +6494,10 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi icon = [UIImage imageNamed:@"unknown.png"]; [self _returnPNGWithImage:icon forRequest:request]; } else fail: { - [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]]; + return [super loadForPath:path ofRequest:request]; } -} -- (void) stopLoading { + return true; } @end @@ -7447,7 +6616,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (editing) [list_ reloadData]; else - [delegate_ updateData]; + [self.delegate updateData]; [self updateNavigationItem]; } @@ -7509,7 +6678,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi source:[self source] section:[section name] ] autorelease]; - [controller setDelegate:delegate_]; + [controller setDelegate:self.delegate]; [[self navigationController] pushViewController:controller animated:YES]; } @@ -7654,7 +6823,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) setLeftBarButtonItem { - if ([delegate_ updating]) + if ([self.delegate updating]) [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CANCEL") style:UIBarButtonItemStyleDone @@ -7671,16 +6840,16 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) refreshButtonClicked { - if ([delegate_ requestUpdate]) + if ([self.delegate requestUpdate]) [self setLeftBarButtonItem]; } - (void) cancelButtonClicked { - [delegate_ cancelUpdate]; + [self.delegate cancelUpdate]; } - (void) upgradeButtonClicked { - [delegate_ distUpgrade]; + [self.delegate distUpgrade]; [[self navigationItem] setRightBarButtonItem:nil animated:YES]; } @@ -7787,8 +6956,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (upgrades_ != 0) [sections insertObject:upgradable atIndex:0]; - [list_ reloadData]; - [[self navigationItem] setRightBarButtonItem:(upgrades_ == 0 ? nil : [[[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]] style:UIBarButtonItemStylePlain @@ -8025,7 +7192,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (package_ == nil) return; if ([package_ setSubscribed:value]) - [delegate_ updateData]; + [self.delegate updateData]; } - (void) _updateIgnored { @@ -8048,7 +7215,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [invocation setTarget:self]; [invocation setSelector:@selector(_updateIgnored)]; - [delegate_ reloadDataWithInvocation:invocation]; + [self.delegate reloadDataWithInvocation:invocation]; } - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -8239,7 +7406,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi #if !AlwaysReload - (void) queueButtonClicked { - [delegate_ queue]; + [self.delegate queue]; } #endif @@ -8289,7 +7456,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi - (void) _setImage:(NSArray *)data { if ([url_ isEqual:[data objectAtIndex:0]]) { icon_ = [data objectAtIndex:1]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } } @@ -8323,7 +7490,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi origin_ = [source name]; label_ = [source rooturi]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; url_ = [source iconURL]; [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:url_]; @@ -8336,27 +7503,19 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi icon_ = [UIImage imageNamed:@"folder.png"]; origin_ = UCLocalize("ALL_SOURCES"); label_ = UCLocalize("ALL_SOURCES_EX"); - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } - (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) { - UIView *content([self contentView]); - CGRect bounds([content bounds]); - - content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; - [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [content_ setBackgroundColor:[UIColor whiteColor]]; - [content addSubview:content_]; - - [content_ setDelegate:self]; - [content_ setOpaque:YES]; + [self.content setBackgroundColor:[UIColor whiteColor]]; + [self.content setOpaque:YES]; indicator_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGraySmall] autorelease]; [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin];// | UIViewAutoresizingFlexibleBottomMargin]; - [content addSubview:indicator_]; + [[self contentView] addSubview:indicator_]; - [[content_ layer] setContentsGravity:kCAGravityTopLeft]; + [[self.content layer] setContentsGravity:kCAGravityTopLeft]; } return self; } @@ -8380,7 +7539,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) drawContentRect:(CGRect)rect { - bool highlighted(highlighted_); + bool highlighted(self.highlighted); float width(rect.size.width); if (icon_ != nil) { @@ -8524,7 +7683,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi source:[self sourceAtIndexPath:indexPath] ] autorelease]); - [controller setDelegate:delegate_]; + [controller setDelegate:self.delegate]; [[self navigationController] pushViewController:controller animated:YES]; } @@ -8543,7 +7702,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [Sources_ removeObjectForKey:[source key]]; - [delegate_ syncData]; + [self.delegate syncData]; } } @@ -8552,10 +7711,10 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) complete { - [delegate_ addTrivialSource:href_]; + [self.delegate addTrivialSource:href_]; href_ = nil; - [delegate_ syncData]; + [self.delegate syncData]; } - (NSString *) getWarning { @@ -8594,9 +7753,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi ) { NSString *warning(cydia_ ? [self yieldToSelector:@selector(getWarning)] : nil); - [delegate_ releaseNetworkActivityIndicator]; + [self.delegate releaseNetworkActivityIndicator]; - [delegate_ removeProgressHUD:hud_]; + [self.delegate removeProgressHUD:hud_]; hud_ = nil; if (cydia_) { @@ -8713,9 +7872,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi cydia_ = false; // XXX: this is stupid - hud_ = [delegate_ addProgressHUD]; + hud_ = [self.delegate addProgressHUD]; [hud_ setText:UCLocalize("VERIFYING_URL")]; - [delegate_ retainNetworkActivityIndicator]; + [self.delegate retainNetworkActivityIndicator]; } break; case 0: @@ -8755,7 +7914,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi target:self action:@selector(addButtonClicked) ] autorelease] animated:animated]; - else if ([delegate_ updating]) + else if ([self.delegate updating]) [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CANCEL") style:UIBarButtonItemStyleDone @@ -8855,7 +8014,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [alert setNumberOfRows:1]; [alert addTextFieldWithValue:@"http://" label:@""]; - UITextInputTraits *traits = [[alert textField] textInputTraits]; + NSObject *traits = [[alert textField] textInputTraits]; [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; [traits setKeyboardType:UIKeyboardTypeURL]; @@ -8870,12 +8029,12 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) refreshButtonClicked { - if ([delegate_ requestUpdate]) + if ([self.delegate requestUpdate]) [self updateButtonsForEditingStatusAnimated:YES]; } - (void) cancelButtonClicked { - [delegate_ cancelUpdate]; + [self.delegate cancelUpdate]; } - (void) editButtonClicked { @@ -8955,63 +8114,12 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi @end /* }}} */ -@interface CYURLCache : SDURLCache { -} - -@end - -@implementation CYURLCache - -- (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 -} - -- (void) storeCachedResponse:(NSCachedURLResponse *)cached forRequest:(NSURLRequest *)request { - if (NSURLResponse *response = [cached response]) - if (NSString *mime = [response MIMEType]) - if ([mime isEqualToString:@"text/cache-manifest"]) { - NSURL *url([response URL]); - -#if !ForRelease - NSLog(@"###: %@", [url absoluteString]); -#endif - - @synchronized (HostConfig_) { - [CachedURLs_ addObject:url]; - } - } - - [super storeCachedResponse:cached forRequest:request]; -} - -- (void) createDiskCachePath { - [super createDiskCachePath]; -} - -@end - -@interface Cydia : UIApplication < +@interface Cydia : CyteApplication < ConfirmationControllerDelegate, DatabaseDelegate, CydiaDelegate > { - _H window_; + _H window_; _H tabbar_; _H emulated_; _H appcache_; @@ -9024,7 +8132,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi _H starturl_; unsigned locked_; - unsigned activity_; _H stash_; @@ -9064,7 +8171,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (bool) requestUpdate { - if (IsReachable("cydia.saurik.com")) { + if (CyteIsReachable("cydia.saurik.com")) { [self beginUpdate]; return true; } else { @@ -9146,13 +8253,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi return [controllers objectAtIndex:3]; } -- (void) unloadData { - [tabbar_ unloadData]; -} - - (void) _updateData { [self _saveConfig]; - [self unloadData]; + [window_ unloadData]; UINavigationController *navigation = [self queueNavigationController]; @@ -9181,7 +8284,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi // - We already auto-refreshed this launch. // - Auto-refresh is disabled. // - Cydia's server is not reachable - if (recently || loaded_ || ManualRefresh || !IsReachable("cydia.saurik.com")) { + if (recently || loaded_ || ManualRefresh || !CyteIsReachable("cydia.saurik.com")) { // If we are cancelling, we need to make sure it knows it's already loaded. loaded_ = true; @@ -9271,14 +8374,9 @@ _end if (emulated_ == nil) return; - if ([window_ respondsToSelector:@selector(setRootViewController:)]) - [window_ setRootViewController:tabbar_]; - else { - [window_ addSubview:[tabbar_ view]]; - [[emulated_ view] removeFromSuperview]; - } - + [window_ setRootViewController:tabbar_]; emulated_ = nil; + [window_ setUserInteractionEnabled:YES]; } @@ -9454,25 +8552,6 @@ _end [self unlockSuspend]; } -- (void) retainNetworkActivityIndicator { - if (activity_++ == 0) - [self setNetworkActivityIndicatorVisible:YES]; - -#if TraceLogging - NSLog(@"retainNetworkActivityIndicator->%d", activity_); -#endif -} - -- (void) releaseNetworkActivityIndicator { - if (--activity_ == 0) - [self setNetworkActivityIndicatorVisible:NO]; - -#if TraceLogging - NSLog(@"releaseNetworkActivityIndicator->%d", activity_); -#endif - -} - - (void) cancelAndClear:(bool)clear { @synchronized (self) { if (clear) { @@ -9605,7 +8684,7 @@ _end [super applicationSuspend]; } -- (void) applicationSuspend:(__GSEvent *)event { +- (void) applicationSuspend:(GSEventRef)event { if ([self isSafeToSuspend]) [super applicationSuspend:event]; } @@ -9735,10 +8814,7 @@ _end if ([arg2 isEqualToString:@"settings"]) { controller = [[[PackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease]; } else if ([arg2 isEqualToString:@"files"]) { - if (Package *package = [database_ packageWithName:arg1]) { - controller = [[[FileTable alloc] initWithDatabase:database_] autorelease]; - [(FileTable *)controller setPackage:package]; - } + controller = [[[FileTable alloc] initWithDatabase:database_ forPackage:arg1] autorelease]; } } @@ -9813,7 +8889,7 @@ _end } if (interval <= -(15*60)) { - if (IsReachable("cydia.saurik.com")) { + if (CyteIsReachable("cydia.saurik.com")) { [tabbar_ beginUpdate]; [appcache_ reloadURLWithCache:YES]; } @@ -9872,77 +8948,11 @@ _end [self reloadSpringBoard]; } -- (void) setupViewControllers { - tabbar_ = [[[CydiaTabBarController alloc] initWithDatabase:database_] autorelease]; - - NSMutableArray *items; - if (kCFCoreFoundationVersionNumber < 800) { - items = [NSMutableArray arrayWithObjects: - [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage imageNamed:@"home.png"] tag:0] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("SOURCES") image:[UIImage imageNamed:@"install.png"] tag:0] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage imageNamed:@"changes.png"] tag:0] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("INSTALLED") image:[UIImage imageNamed:@"manage.png"] tag:0] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage imageNamed:@"search.png"] tag:0] autorelease], - nil]; - } else { - items = [NSMutableArray arrayWithObjects: - [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage imageNamed:@"home7.png"] selectedImage:[UIImage imageNamed:@"home7s.png"]] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("SOURCES") image:[UIImage imageNamed:@"install7.png"] selectedImage:[UIImage imageNamed:@"install7s.png"]] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage imageNamed:@"changes7.png"] selectedImage:[UIImage imageNamed:@"changes7s.png"]] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("INSTALLED") image:[UIImage imageNamed:@"manage7.png"] selectedImage:[UIImage imageNamed:@"manage7s.png"]] autorelease], - [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage imageNamed:@"search7.png"] selectedImage:[UIImage imageNamed:@"search7s.png"]] autorelease], - nil]; - } - - NSMutableArray *controllers([NSMutableArray array]); - for (UITabBarItem *item in items) { - UINavigationController *controller([[[UINavigationController alloc] init] autorelease]); - [controller setTabBarItem:item]; - [controllers addObject:controller]; - } - [tabbar_ setViewControllers:controllers]; - - [tabbar_ setUpdateDelegate:self]; -} - -- (void) _sendMemoryWarningNotification { - if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: maybe 4_0? - [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationMemoryWarningNotification" object:[UIApplication sharedApplication]]; - else - [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidReceiveMemoryWarningNotification" object:[UIApplication sharedApplication]]; -} - -- (void) _sendMemoryWarningNotifications { - while (true) { - [self performSelectorOnMainThread:@selector(_sendMemoryWarningNotification) withObject:nil waitUntilDone:NO]; - sleep(2); - //usleep(2000000); - } -} - -- (void) applicationDidReceiveMemoryWarning:(UIApplication *)application { - NSLog(@"--"); - [[NSURLCache sharedURLCache] removeAllCachedResponses]; -} - - (void) applicationDidFinishLaunching:(id)unused { - //[NSThread detachNewThreadSelector:@selector(_sendMemoryWarningNotifications) toTarget:self withObject:nil]; + [super applicationDidFinishLaunching:unused]; + [CyteWebViewController _initialize]; -_trace(); - if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)]) - [self setApplicationSupportsShakeToEdit:NO]; - - @synchronized (HostConfig_) { - [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]]; - } - - [NSURLCache setSharedURLCache:[[[CYURLCache alloc] - initWithMemoryCapacity:524288 - diskCapacity:10485760 - diskPath:Cache("SDURLCache") - ] autorelease]]; - - [CydiaWebViewController _initialize]; + [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]]; [NSURLProtocol registerClass:[CydiaURLProtocol class]]; @@ -9963,7 +8973,7 @@ _trace(); appcache_ = [[[AppCacheController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] autorelease]; [appcache_ reloadData]; - window_ = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; + window_ = [[[CyteWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; [window_ orderFront:self]; [window_ makeKey:self]; [window_ setHidden:NO]; @@ -10010,7 +9020,18 @@ _trace(); [database_ setDelegate:self]; [window_ setUserInteractionEnabled:NO]; - [self setupViewControllers]; + + tabbar_ = [[[CydiaTabBarController alloc] initWithDatabase:database_] autorelease]; + + [tabbar_ addViewControllers:nil, + @"Cydia", @"home.png", @"home7.png", @"home7s.png", + UCLocalize("SOURCES"), @"install.png", @"install7.png", @"install7s.png", + UCLocalize("CHANGES"), @"changes.png", @"changes7.png", @"changes7s.png", + UCLocalize("INSTALLED"), @"manage.png", @"manage7.png", @"manage7s.png", + UCLocalize("SEARCH"), @"search.png", @"search7.png", @"search7s.png", + nil]; + + [tabbar_ setUpdateDelegate:self]; CydiaLoadingViewController *loading([[[CydiaLoadingViewController alloc] init] autorelease]); UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]); @@ -10023,10 +9044,7 @@ _trace(); if ([emulated_ respondsToSelector:@selector(concealTabBarSelection)]) [emulated_ concealTabBarSelection]; - if ([window_ respondsToSelector:@selector(setRootViewController:)]) - [window_ setRootViewController:emulated_]; - else - [window_ addSubview:[emulated_ view]]; + [window_ setRootViewController:emulated_]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; _trace(); @@ -10163,60 +9181,6 @@ id Dealloc_(id self, SEL selector) { return object; }*/ -Class $NSURLConnection; - -MSHook(id, NSURLConnection$init$, NSURLConnection *self, SEL _cmd, NSURLRequest *request, id delegate, BOOL usesCache, int64_t maxContentLength, BOOL startImmediately, NSDictionary *connectionProperties) { - NSMutableURLRequest *copy([[request mutableCopy] autorelease]); - - NSURL *url([copy URL]); - - NSString *host([url host]); - NSString *scheme([[url scheme] lowercaseString]); - - NSString *compound([NSString stringWithFormat:@"%@:%@", scheme, host]); - - @synchronized (HostConfig_) { - if ([copy respondsToSelector:@selector(setHTTPShouldUsePipelining:)]) - if ([PipelinedHosts_ containsObject:host] || [PipelinedHosts_ containsObject:compound]) - [copy setHTTPShouldUsePipelining:YES]; - - if (NSString *control = [copy valueForHTTPHeaderField:@"Cache-Control"]) - if ([control isEqualToString:@"max-age=0"]) - if ([CachedURLs_ containsObject:url]) { -#if !ForRelease - NSLog(@"~~~: %@", url); -#endif - - [copy setCachePolicy:NSURLRequestReturnCacheDataDontLoad]; - - [copy setValue:nil forHTTPHeaderField:@"Cache-Control"]; - [copy setValue:nil forHTTPHeaderField:@"If-Modified-Since"]; - [copy setValue:nil forHTTPHeaderField:@"If-None-Match"]; - } - } - - if ((self = _NSURLConnection$init$(self, _cmd, copy, delegate, usesCache, maxContentLength, startImmediately, connectionProperties)) != nil) { - } return self; -} - -Class $WAKWindow; - -static CGSize $WAKWindow$screenSize(WAKWindow *self, SEL _cmd) { - CGSize size([[UIScreen mainScreen] bounds].size); - /*if ([$WAKWindow respondsToSelector:@selector(hasLandscapeOrientation)]) - if ([$WAKWindow hasLandscapeOrientation]) - std::swap(size.width, size.height);*/ - return size; -} - -Class $NSUserDefaults; - -MSHook(id, NSUserDefaults$objectForKey$, NSUserDefaults *self, SEL _cmd, NSString *key) { - if ([key respondsToSelector:@selector(isEqualToString:)] && [key isEqualToString:@"WebKitLocalStorageDatabasePathPreferenceKey"]) - return Cache("LocalStorage"); - return _NSUserDefaults$objectForKey$(self, _cmd, key); -} - static NSMutableDictionary *AutoreleaseDeepMutableCopyOfDictionary(CFTypeRef type) { if (type == NULL) return nil; @@ -10227,17 +9191,47 @@ static NSMutableDictionary *AutoreleaseDeepMutableCopyOfDictionary(CFTypeRef typ return [(NSMutableDictionary *) copy autorelease]; } +int main_copy(); +int main_file(); +int main_gpgv(); +int main_rred(int, char *argv[]); + +int main_gzip(int, char *argv[]); + int main_store(int, char *argv[]); +int main_http(); + int main(int argc, char *argv[]) { -#ifdef __arm64__ const char *argv0(argv[0]); if (const char *slash = strrchr(argv0, '/')) argv0 = slash + 1; if (false); + else if (!strcmp(argv0, "copy")) + return main_copy(); + else if (!strcmp(argv0, "file")) + return main_file(); + else if (!strcmp(argv0, "gpgv")) + return main_gpgv(); + else if (!strcmp(argv0, "rred")) + return main_rred(argc, argv); +#ifdef __arm__ + else if (!strcmp(argv0, "bzip2")) + return main_gzip(argc, argv); + else if (!strcmp(argv0, "gzip")) + return main_gzip(argc, argv); + else if (!strcmp(argv0, "lzma")) + return main_gzip(argc, argv); +#endif +#ifdef __arm64__ else if (!strcmp(argv0, "store")) return main_store(argc, argv); #endif + else if (!strcmp(argv0, "http")) + return main_http(); + else if (!strcmp(argv0, "https")) + return main_http(); + else {} int fd(open("/tmp/cydia.log", O_WRONLY | O_APPEND | O_CREAT, 0644)); dup2(fd, 2); @@ -10247,70 +9241,16 @@ int main(int argc, char *argv[]) { _trace(); + CyteInitialize([NSString stringWithFormat:@"Cydia/%@", Cydia_]); UpdateExternalStatus(0); - UIScreen *screen([UIScreen mainScreen]); - if ([screen respondsToSelector:@selector(scale)]) - ScreenScale_ = [screen scale]; - else - ScreenScale_ = 1; - - UIDevice *device([UIDevice currentDevice]); - if ([device respondsToSelector:@selector(userInterfaceIdiom)]) { - UIUserInterfaceIdiom idiom([device userInterfaceIdiom]); - if (idiom == UIUserInterfaceIdiomPad) - IsWildcat_ = true; - } - - Idiom_ = IsWildcat_ ? @"ipad" : @"iphone"; - - RegEx pattern("([0-9]+\\.[0-9]+).*"); - - if (pattern([device systemVersion])) - Firmware_ = pattern[1]; - if (pattern(Cydia_)) - Major_ = pattern[1]; - SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4]; + BridgedHosts_ = [NSMutableSet setWithCapacity:4]; + InsecureHosts_ = [NSMutableSet setWithCapacity:4]; - HostConfig_ = [[[NSObject alloc] init] autorelease]; - @synchronized (HostConfig_) { - BridgedHosts_ = [NSMutableSet setWithCapacity:4]; - InsecureHosts_ = [NSMutableSet setWithCapacity:4]; - PipelinedHosts_ = [NSMutableSet setWithCapacity:4]; - CachedURLs_ = [NSMutableSet setWithCapacity:32]; - } - - NSString *ui(@"ui/ios"); - if (Idiom_ != nil) - ui = [ui stringByAppendingString:[NSString stringWithFormat:@"~%@", Idiom_]]; - ui = [ui stringByAppendingString:[NSString stringWithFormat:@"/%@", Major_]]; - UI_ = CydiaURL(ui); - + UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@/1.1", IsWildcat_ ? @"ipad" : @"iphone"]); PackageName = reinterpret_cast(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname)))); - /* Library Hacks {{{ */ - class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16"); - - $WAKWindow = objc_getClass("WAKWindow"); - if ($WAKWindow != NULL) - if (Method method = class_getInstanceMethod($WAKWindow, @selector(screenSize))) - method_setImplementation(method, (IMP) &$WAKWindow$screenSize); - - $NSURLConnection = objc_getClass("NSURLConnection"); - Method NSURLConnection$init$(class_getInstanceMethod($NSURLConnection, @selector(_initWithRequest:delegate:usesCache:maxContentLength:startImmediately:connectionProperties:))); - if (NSURLConnection$init$ != NULL) { - _NSURLConnection$init$ = reinterpret_cast(method_getImplementation(NSURLConnection$init$)); - method_setImplementation(NSURLConnection$init$, reinterpret_cast(&$NSURLConnection$init$)); - } - - $NSUserDefaults = objc_getClass("NSUserDefaults"); - Method NSUserDefaults$objectForKey$(class_getInstanceMethod($NSUserDefaults, @selector(objectForKey:))); - if (NSUserDefaults$objectForKey$ != NULL) { - _NSUserDefaults$objectForKey$ = reinterpret_cast(method_getImplementation(NSUserDefaults$objectForKey$)); - method_setImplementation(NSUserDefaults$objectForKey$, reinterpret_cast(&$NSUserDefaults$objectForKey$)); - } - /* }}} */ /* Set Locale {{{ */ Locale_ = CFLocaleCopyCurrent(); Languages_ = [NSLocale preferredLanguages]; @@ -10330,7 +9270,11 @@ int main(int argc, char *argv[]) { } if (Languages_ != nil) - for (NSString *language : Languages_) { + for (NSString *locale : Languages_) { + auto components([NSLocale componentsFromLocaleIdentifier:locale]); + NSString *language([components objectForKey:(id)kCFLocaleLanguageCode]); + if (NSString *script = [components objectForKey:(id)kCFLocaleScriptCode]) + language = [NSString stringWithFormat:@"%@-%@", language, script]; languages += [language UTF8String]; languages += ","; } @@ -10389,29 +9333,6 @@ int main(int argc, char *argv[]) { CollationStarts_ = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",@"ʒ",nil]; } /* }}} */ - /* Parse Arguments {{{ */ - bool substrate(false); - - if (argc != 0) { - char **args(argv); - int arge(1); - - for (int argi(1); argi != argc; ++argi) - if (strcmp(argv[argi], "--") == 0) { - arge = argi; - argv[argi] = argv[0]; - argv += argi; - argc -= argi; - break; - } - - for (int argi(1); argi != arge; ++argi) - if (strcmp(args[argi], "--substrate") == 0) - substrate = true; - else - fprintf(stderr, "unknown argument: %s\n", args[argi]); - } - /* }}} */ App_ = [[NSBundle mainBundle] bundlePath]; Advanced_ = YES; @@ -10429,6 +9350,7 @@ int main(int argc, char *argv[]) { void *gestalt(dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY)); $MGCopyAnswer = reinterpret_cast(dlsym(gestalt, "MGCopyAnswer")); + UniqueID_ = UniqueIdentifier([UIDevice currentDevice]); /* System Information {{{ */ size_t size; @@ -10442,47 +9364,6 @@ int main(int argc, char *argv[]) { if (sysctlbyname("kern.maxproc", NULL, NULL, &maxproc, sizeof(maxproc)) == -1) perror("sysctlbyname(\"kern.maxproc\", #)"); } - - sysctlbyname("kern.osversion", NULL, &size, NULL, 0); - char *osversion = new char[size]; - if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) == -1) - perror("sysctlbyname(\"kern.osversion\", ?)"); - else - System_ = [NSString stringWithUTF8String:osversion]; - - sysctlbyname("hw.machine", NULL, &size, NULL, 0); - char *machine = new char[size]; - if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == -1) - perror("sysctlbyname(\"hw.machine\", ?)"); - else - Machine_ = machine; - - int64_t usermem(0); - size = sizeof(usermem); - if (sysctlbyname("hw.usermem", &usermem, &size, NULL, 0) == -1) - usermem = 0; - - 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_ = UniqueIdentifier(device); - - if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) { - Product_ = [info objectForKey:@"SafariProductVersion"]; - Safari_ = [info objectForKey:@"CFBundleVersion"]; - } - - NSString *agent([NSString stringWithFormat:@"Cydia/%@ CyF/%.2f", Cydia_, kCFCoreFoundationVersionNumber]); - - if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", Safari_)) - agent = [NSString stringWithFormat:@"Safari/%@ %@", match[1], agent]; - if (RegEx match = RegEx("([0-9]+[A-Z][0-9]+[a-z]?).*", System_)) - agent = [NSString stringWithFormat:@"Mobile/%@ %@", match[1], agent]; - if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", Product_)) - agent = [NSString stringWithFormat:@"Version/%@ %@", match[1], agent]; - - UserAgent_ = agent; /* }}} */ /* Load Database {{{ */ SectionMap_ = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sections" ofType:@"plist"]] autorelease]; @@ -10584,7 +9465,8 @@ int main(int argc, char *argv[]) { _config->Set("Acquire::AllowInsecureRepositories", true); _config->Set("Acquire::Check-Valid-Until", false); - _config->Set("Dir::Bin::Methods::store", "/Applications/Cydia.app/store"); + + _config->Set("Dir::Bin::Methods", "/Applications/Cydia.app"); _config->Set("pkgCacheGen::ForceEssential", ""); @@ -10595,6 +9477,10 @@ int main(int argc, char *argv[]) { // XXX: this timeout might be important :( //_config->Set("Acquire::http::Timeout", 15); + int64_t usermem(0); + size = sizeof(usermem); + if (sysctlbyname("hw.usermem", &usermem, &size, NULL, 0) == -1) + usermem = 0; _config->Set("Acquire::http::MaxParallel", usermem >= 384 * 1024 * 1024 ? 16 : 3); mkdir([Cache("archives") UTF8String], 0755);