X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/4e89e88014a46af14f9eb348844e4c674bfba64d..947a8eefa4cc11fbccdb9b1495ec0f0f28663bd9:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 64c388c9..05486472 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,21 @@ extern "C" { #include #include -#include #include -#include "UICaboodle/BrowserView.h" +#include "Menes/Menes.h" + +#include "CyteKit/PerlCompatibleRegEx.hpp" +#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,124 +273,6 @@ 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; @@ -570,38 +459,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 +474,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 +481,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,77 +674,6 @@ 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) const { - return [NSString stringWithUTF8Bytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2])]; - } - - _finline bool operator ()(NSString *data) { - // XXX: length is for characters, not for bytes - return operator ()([data UTF8String], [data length]); - } - - _finline bool operator ()(const char *data) { - return operator ()(data, strlen(data)); - } - - bool operator ()(const char *data, size_t size) { - data_ = data; - return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0; - } - - NSString *operator ->*(NSString *format) const { - id values[capture_]; - for (int i(0); i != capture_; ++i) - values[i] = this->operator [](i + 1); - - return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast(values)] autorelease]; - } -}; -/* }}} */ /* Mime Addresses {{{ */ @interface Address : NSObject { NSString *name_; @@ -1170,6 +939,34 @@ bool isSectionVisible(NSString *section) { return hidden == nil || ![hidden boolValue]; } +static id 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, bool capital) { + 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, capital ? "%.2X" : "%.2x", bytes[reverse ? length - i - 1 : i]); + + return [NSString stringWithUTF8String:string]; +} + @class Cydia; /* Delegate Prototypes {{{ */ @@ -1202,57 +999,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 @@ -3116,7 +2868,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; @@ -4067,6 +3822,8 @@ static NSString *Warning_; @end /* }}} */ +static NSMutableSet *Diversions_; + @interface Diversion : NSObject { Pcre pattern_; _H key_; @@ -4089,6 +3846,22 @@ static NSString *Warning_; return !pattern_(url) ? nil : pattern_->*format_; } ++ (NSURL *) divertURL:(NSURL *)url { + divert: + NSString *href([url absoluteString]); + + for (Diversion *diversion in 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_; } @@ -4112,7 +3885,7 @@ static NSString *Warning_; @end -@interface CYBrowserController : BrowserController { +@interface CydiaWebViewController : CyteWebViewController { CydiaObject *cydia_; } @@ -4120,8 +3893,6 @@ static NSString *Warning_; @end -static NSMutableSet *Diversions_; - /* Web Scripting {{{ */ @implementation CydiaObject @@ -4212,14 +3983,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 +4003,10 @@ static NSMutableSet *Diversions_; return @"getKernelString"; else if (selector == @selector(getInstalledPackages)) return @"getInstalledPackages"; + 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 +4029,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 +4043,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 +4067,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 { @@ -4389,6 +4168,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 +4264,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 +4290,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 +4313,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 +4409,7 @@ static NSMutableSet *Diversions_; @end /* }}} */ /* Emulated Loading Controller {{{ */ -@interface CYEmulatedLoadingController : CYViewController { +@interface CYEmulatedLoadingController : CyteViewController { _transient Database *database_; _H indicator_; _H tabbar_; @@ -4663,7 +4458,7 @@ static NSMutableSet *Diversions_; /* }}} */ /* Cydia Browser Controller {{{ */ -@implementation CYBrowserController +@implementation CydiaWebViewController - (void) dealloc { [cydia_ release]; @@ -4671,7 +4466,7 @@ static NSMutableSet *Diversions_; } - (NSURL *) navigationURL { - return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[[webview_ request] URL] absoluteString]]]; + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]]; } + (void) initialize { @@ -4688,27 +4483,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,7 +4522,7 @@ static NSMutableSet *Diversions_; } - (id) init { - if ((self = [super initWithWidth:0 ofClass:[CYBrowserController class]]) != nil) { + if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) { cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_]; WebView *webview([[webview_ _documentView] webView]); @@ -4804,7 +4601,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) queue; @end -@interface ConfirmationController : CYBrowserController { +@interface ConfirmationController : CydiaWebViewController { _transient Database *database_; UIAlertView *essential_; @@ -4975,13 +4772,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: @@ -5216,7 +5016,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Progress Controller {{{ */ -@interface ProgressController : CYBrowserController < +@interface ProgressController : CydiaWebViewController < ProgressDelegate > { _transient Database *database_; @@ -5330,7 +5130,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 @@ -5914,7 +5714,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* File Table {{{ */ -@interface FileTable : CYViewController < +@interface FileTable : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -5980,6 +5780,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("INSTALLED_FILES")]; } @@ -6050,7 +5852,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Controller {{{ */ -@interface CYPackageController : CYBrowserController < +@interface CYPackageController : CydiaWebViewController < UIActionSheetDelegate > { _transient Database *database_; @@ -6216,7 +6018,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Package List Controller {{{ */ -@interface PackageListController : CYViewController < +@interface PackageListController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -6586,7 +6388,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Home Controller {{{ */ -@interface HomeController : CYBrowserController { +@interface HomeController : CydiaWebViewController { } @end @@ -6596,6 +6398,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 +6414,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/" @@ -6621,6 +6426,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("ABOUT") style:UIBarButtonItemStylePlain @@ -6629,10 +6436,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { ] autorelease]]; } +- (void) unloadData { + [super unloadData]; + [self reloadData]; +} + @end /* }}} */ /* Manage Controller {{{ */ -@interface ManageController : CYBrowserController { +@interface ManageController : CydiaWebViewController { } - (void) queueStatusDidChange; @@ -6652,52 +6464,39 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("SETTINGS") style:UIBarButtonItemStylePlain target:self action:@selector(settingsButtonClicked) ] autorelease]]; - - [self queueStatusDidChange]; } - (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 @@ -6821,14 +6620,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Cydia Navigation Controller Interface {{{ */ -@interface CYNavigationController : UINavigationController { - _transient Database *database_; - _transient id delegate_; -} +@interface UINavigationController (Cydia) - (NSArray *) navigationURLCollection; -- (id) initWithDatabase:(Database *)database; -- (void) unloadData:(BOOL)selected; +- (void) unloadData; @end /* }}} */ @@ -6907,12 +6702,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) unloadData { - CYNavigationController *selected((CYNavigationController *) [self selectedViewController]); - for (CYNavigationController *controller in [self viewControllers]) - [controller unloadData:(controller == selected)]; + UIViewController *selected([self selectedViewController]); + for (UINavigationController *controller in [self viewControllers]) + [controller unloadData]; - if (CYNavigationController *unselected = (CYNavigationController *) [self unselectedViewController]) - [unselected unloadData:YES]; + [selected reloadData]; + + if (UIViewController *unselected = [self unselectedViewController]) + [unselected reloadData]; + + [super unloadData]; } - (void) dealloc { @@ -7126,12 +6925,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Cydia Navigation Controller Implementation {{{ */ -@implementation CYNavigationController +@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]; @@ -7140,28 +6939,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return stack; } -- (void) unloadData:(BOOL)selected { - CYViewController *top((CYViewController *) [self topViewController]); - bool loaded([top hasLoaded]); - - for (CYViewController *page in [self viewControllers]) { - NSLog(@"%@ %@", page, top); - if (!selected || page != top) - [page unloadData]; - } +- (void) reloadData { + [super reloadData]; - if (selected && loaded) - [top reloadData]; + if (UIViewController *visible = [self visibleViewController]) + [visible reloadData]; } -- (void) setDelegate:(id)delegate { - delegate_ = delegate; -} +- (void) unloadData { + for (CyteViewController *page in [self viewControllers]) + [page unloadData]; -- (id) initWithDatabase:(Database *)database { - if ((self = [super init]) != nil) { - database_ = database; - } return self; + [super unloadData]; } @end @@ -7316,7 +7105,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Sections Controller {{{ */ -@interface SectionsController : CYViewController < +@interface SectionsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7442,6 +7231,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("SECTIONS")]; } @@ -7524,7 +7315,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Changes Controller {{{ */ -@interface ChangesController : CYViewController < +@interface ChangesController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -7630,6 +7421,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("CHANGES")]; } @@ -7779,8 +7572,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 @@ -7799,11 +7591,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]]; } -- (void) setSearchTerm:(NSString *)searchTerm { - [search_ setText:searchTerm]; - [self reloadData]; -} - - (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar { [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; [search_ resignFirstResponder]; @@ -7815,10 +7602,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self reloadData]; } -- (id) initWithDatabase:(Database *)database { - if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:nil])) { +- (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; } @@ -7858,7 +7648,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Package Settings Controller {{{ */ -@interface PackageSettingsController : CYViewController < +@interface PackageSettingsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -8009,6 +7799,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("SETTINGS")]; } @@ -8250,7 +8042,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Sources Controller {{{ */ -@interface SourcesController : CYViewController < +@interface SourcesController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -8594,6 +8386,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("SOURCES")]; [self updateButtonsForEditingStatus:NO animated:NO]; } @@ -8705,7 +8499,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* }}} */ /* Settings Controller {{{ */ -@interface SettingsController : CYViewController < +@interface SettingsController : CyteViewController < UITableViewDataSource, UITableViewDelegate > { @@ -8750,6 +8544,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) viewDidLoad { + [super viewDidLoad]; + [[self navigationItem] setTitle:UCLocalize("WHO_ARE_YOU")]; int index = -1; @@ -8903,7 +8699,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Stash Controller {{{ */ -@interface StashController : CYViewController { +@interface StashController : CyteViewController { UIActivityIndicatorView *spinner_; UILabel *status_; UILabel *caption_; @@ -8977,6 +8773,35 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @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 +} + +@end + @interface Cydia : UIApplication < ConfirmationControllerDelegate, DatabaseDelegate, @@ -9078,17 +8903,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_ unloadData]; + [self unloadData]; - CYNavigationController *navigation = [self queueNavigationController]; + UINavigationController *navigation = [self queueNavigationController]; id queuedelegate = nil; if ([[navigation viewControllers] count] > 0) @@ -9224,7 +9053,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (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]; @@ -9331,8 +9160,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]; @@ -9397,11 +9225,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 { @@ -9551,28 +9375,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; @@ -9587,12 +9415,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]; @@ -9611,7 +9439,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"]) { @@ -9629,8 +9457,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"]) { @@ -9674,10 +9501,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]; } @@ -9784,7 +9611,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]; } @@ -9802,16 +9629,19 @@ _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]]; + // this would disallow http{,s} URLs from accessing this data + //[WebView registerURLSchemeAsLocal:@"cydia"]; + Font12_ = [[UIFont systemFontOfSize:12] retain]; Font12Bold_ = [[UIFont boldSystemFontOfSize:12] retain]; Font14_ = [[UIFont systemFontOfSize:14] retain]; @@ -9822,7 +9652,7 @@ _trace(); broken_ = [[NSMutableArray alloc] initWithCapacity:4]; // XXX: I really need this thing... like, seriously... I'm sorry - [[[CYBrowserController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData]; + [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData]; window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [window_ orderFront:self]; @@ -9881,7 +9711,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) @@ -9938,13 +9768,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]; } @@ -10241,28 +10071,8 @@ 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_ = CYIOGetValue("IOService:/", @"IOPlatformSerialNumber"); + ChipID_ = CYHex(CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true, true); UniqueID_ = [[UIDevice currentDevice] uniqueIdentifier];