#include <CydiaSubstrate/CydiaSubstrate.h>
#include "Menes/Menes.h"
+#include "CyteKit/IndirectDelegate.h"
#include "CyteKit/PerlCompatibleRegEx.hpp"
#include "CyteKit/TableViewCell.h"
#include "CyteKit/WebScriptObject-Cyte.h"
#include "CyteKit/WebViewController.h"
+#include "CyteKit/WebViewTableViewCell.h"
#include "CyteKit/stringWithUTF8Bytes.h"
#include "Cydia/MIMEAddress.h"
};
// }}}
+static bool ShowPromoted_;
+
static NSString *Colon_;
NSString *Elision_;
static NSString *Error_;
static NSString *Warning_;
+static bool AprilFools_;
+
static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
static _finline NSString *CydiaURL(NSString *path) {
static _H<UIFont> Font22Bold_;
static const char *Machine_ = NULL;
-static NSString *System_ = nil;
+static _H<NSString> System_;
static NSString *SerialNumber_ = nil;
static NSString *ChipID_ = nil;
static NSString *BBSNum_ = nil;
static _H<NSString> Token_;
static NSString *UniqueID_ = nil;
-static NSString *PLMN_ = nil;
-static NSString *Build_ = nil;
-static NSString *Product_ = nil;
-static NSString *Safari_ = nil;
+static _H<NSString> UserAgent_;
+static _H<NSString> Product_;
+static _H<NSString> Safari_;
static CFLocaleRef Locale_;
static NSArray *Languages_;
static _transient NSMutableDictionary *Sections_;
_H<NSMutableDictionary> Sources_;
static _transient NSNumber *Version_;
-_H<NSString> CydiaSource_;
bool Changed_;
static time_t now_;
bool IsWildcat_;
static CGFloat ScreenScale_;
static NSString *Idiom_;
-_H<NSString> Firmware_;
+static _H<NSString> Firmware_;
static NSString *Major_;
static _H<NSMutableDictionary> SessionData_;
@end
+@class CydiaObject;
+
@interface CydiaWebViewController : CyteWebViewController {
_H<CydiaObject> cydia_;
}
+ (void) addDiversion:(Diversion *)diversion;
++ (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request;
++ (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia;
+- (void) setDelegate:(id)delegate;
@end
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
@"bbsnum",
- @"cydiaSource",
+ @"build",
+ @"coreFoundationVersionNumber",
@"device",
@"ecid",
@"firmware",
@"hostname",
@"idiom",
+ @"mcc",
+ @"mnc",
@"model",
- @"plmn",
+ @"operator",
@"role",
@"serial",
@"token",
return Cydia_;
}
+- (NSString *) build {
+ return System_;
+}
+
+- (NSString *) coreFoundationVersionNumber {
+ return [NSString stringWithFormat:@"%.2f", kCFCoreFoundationVersionNumber];
+}
+
- (NSString *) device {
return [[UIDevice currentDevice] uniqueIdentifier];
}
return (id) Idiom_ ?: [NSNull null];
}
-- (NSString *) plmn {
- return (id) PLMN_ ?: [NSNull null];
+- (NSString *) mcc {
+ if (CFStringRef (*$CTSIMSupportCopyMobileSubscriberCountryCode)(CFAllocatorRef) = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode")))
+ return [(NSString *) (*$CTSIMSupportCopyMobileSubscriberCountryCode)(kCFAllocatorDefault) autorelease];
+ return nil;
+}
+
+- (NSString *) mnc {
+ if (CFStringRef (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(CFAllocatorRef) = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberNetworkCode")))
+ return [(NSString *) (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(kCFAllocatorDefault) autorelease];
+ return nil;
+}
+
+- (NSString *) operator {
+ if (CFStringRef (*$CTRegistrationCopyOperatorName)(CFAllocatorRef) = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTRegistrationCopyOperatorName")))
+ return [(NSString *) (*$CTRegistrationCopyOperatorName)(kCFAllocatorDefault) autorelease];
+ return nil;
}
- (NSString *) bbsnum {
return @"removeButton";
else if (selector == @selector(saveConfig))
return @"saveConfig";
- else if (selector == @selector(setCydiaSource:))
- return @"setCydiaSource";
else if (selector == @selector(setMetadataValue::))
return @"setMetadataValue";
else if (selector == @selector(setSessionValue::))
return @"setSessionValue";
+ else if (selector == @selector(setShowPromoted:))
+ return @"setShowPromoted";
else if (selector == @selector(substitutePackageNames:))
return @"substitutePackageNames";
else if (selector == @selector(scrollToBottom:))
return value;
}
-- (void) _setCydiaSource:(NSString *)source {
- @synchronized (HostConfig_) {
- CydiaSource_ = source;
- [Metadata_ setObject:source forKey:@"CydiaSource"];
- }
+- (NSArray *) getMetadataKeys {
+@synchronized (Values_) {
+ return [Values_ allKeys];
+} }
+- (void) _setShowPromoted:(NSNumber *)value {
+ [Metadata_ setObject:value forKey:@"ShowPromoted"];
Changed_ = true;
}
-- (void) setCydiaSource:(NSString *)source {
- [self performSelectorOnMainThread:@selector(_setCydiaSource:) withObject:source waitUntilDone:NO];
+- (void) setShowPromoted:(NSNumber *)value {
+ [self performSelectorOnMainThread:@selector(_setShowPromoted:) withObject:value waitUntilDone:NO];
}
-- (NSString *) cydiaSource {
- @synchronized (HostConfig_) {
- return (id) CydiaSource_ ?: [NSNull null];
- }
-}
-
-- (NSArray *) getMetadataKeys {
-@synchronized (Values_) {
- return [Values_ allKeys];
-} }
-
- (id) getMetadataValue:(NSString *)key {
@synchronized (Values_) {
return [Values_ objectForKey:key];
- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
[super webView:view didClearWindowObject:window forFrame:frame];
+ [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
++ (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia {
WebDataSource *source([frame dataSource]);
NSURLResponse *response([source response]);
NSURL *url([response URL]);
}
if (bridged)
- [window setValue:cydia_ forKey:@"cydia"];
+ [window setValue:cydia forKey:@"cydia"];
}
- (void) _setupMail:(MFMailComposeViewController *)controller {
}
- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
- NSURL *url([request URL]);
- NSString *host([url host]);
+ return [CydiaWebViewController requestWithHeaders:[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]];
+}
- NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]);
++ (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request {
+ NSMutableURLRequest *copy([request mutableCopy]);
+
+ NSURL *url([copy URL]);
+ NSString *host([url host]);
- if (System_ != NULL && [copy valueForHTTPHeaderField:@"X-System"] == nil)
- [copy setValue:System_ forHTTPHeaderField:@"X-System"];
+ if ([copy valueForHTTPHeaderField:@"X-Cydia-Cf-Version"] == nil)
+ [copy setValue:[NSString stringWithFormat:@"%.2f", kCFCoreFoundationVersionNumber] forHTTPHeaderField:@"X-Cydia-Cf-Version"];
if (Machine_ != NULL && [copy valueForHTTPHeaderField:@"X-Machine"] == nil)
[copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
}
- (NSString *) applicationNameForUserAgent {
- NSString *application([NSString stringWithFormat:@"Cydia/%@", Cydia_]);
-
- if (Safari_ != nil)
- application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application];
- if (Build_ != nil)
- application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application];
- if (Product_ != nil)
- application = [NSString stringWithFormat:@"Version/%@ %@", Product_, application];
-
- return application;
+ return UserAgent_;
}
- (id) init {
@implementation AppCacheController
- (void) didReceiveMemoryWarning {
+ // XXX: this doesn't work
+}
+
+- (bool) retainsNetworkActivityIndicator {
+ return false;
}
@end
}
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
- list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease];
+ list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
[list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[list_ setRowHeight:24.0f];
[(UITableView *) list_ setDataSource:self];
[list_ setDelegate:self];
- [[self view] addSubview:list_];
+ [self setView:list_];
}
- (void) viewDidLoad {
}
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+ 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];
- [[self view] addSubview:list_];
+ [view addSubview:list_];
// XXX: is 20 the most optimal number here?
[list_ setSectionIndexMinimumDisplayRowCount:20];
NSArray *packages;
+ reload:
if ([self shouldYield]) {
do {
UIProgressHUD *hud;
if (hud != nil)
[delegate_ removeProgressHUD:hud];
} while (reloading_ == 2);
-
- reloading_ = 0;
} else {
packages = [self _reloadPackages];
}
+@synchronized (database_) {
+ if (era_ != [database_ era])
+ goto reload;
+ reloading_ = 0;
+
packages_ = packages;
indices_ = [NSMutableDictionary dictionaryWithCapacity:32];
[(UITableView *) list_ setDataSource:self];
[list_ reloadData];
_end
-}
+} }
- (void) reloadData {
[super reloadData];
return [NSURL URLWithString:@"cydia://home"];
}
-- (void) didReceiveMemoryWarning {
-}
-
- (void) aboutButtonClicked {
UIAlertView *alert([[[UIAlertView alloc] init] autorelease]);
@implementation CYTabBarController
+- (void) didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+
+ // presenting a UINavigationController on 2.x does not update its transitionView
+ // it thereby will not allow its topViewController to be unloaded by memory pressure
+ if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+ UIViewController *selected([self selectedViewController]);
+ for (UINavigationController *controller in [self viewControllers])
+ if (controller != selected)
+ if (UIViewController *top = [controller topViewController])
+ [top unloadView];
+ }
+}
+
- (void) setUnselectedViewController:(UIViewController *)transient {
+ if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+ if (transient != nil) {
+ [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
+ [self setSelectedIndex:0];
+ } return;
+ }
+
+ UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
+ [navigation setViewControllers:[NSArray arrayWithObject:transient]];
+ transient = navigation;
+
NSMutableArray *controllers = [[self viewControllers] mutableCopy];
if (transient != nil) {
if (transient_ == nil)
- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([self unselectedViewController])
[self setUnselectedViewController:nil];
+
+ // presenting a UINavigationController on 2.x does not update its transitionView
+ // if this view was unloaded, the tranitionView may currently be presenting nothing
+ if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+ UINavigationController *navigation((UINavigationController *) viewController);
+ [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
+ [navigation popViewControllerAnimated:NO];
+ }
}
- (NSArray *) navigationURLCollection {
/* Section Controller {{{ */
@interface SectionController : FilteredPackageListController {
+ _H<IndirectDelegate, 1> indirect_;
+ _H<CydiaObject> cydia_;
_H<NSString> section_;
+ std::vector< _H<CyteWebViewTableViewCell, 1> > promoted_;
}
- (id) initWithDatabase:(Database *)database section:(NSString *)section;
if (name == nil)
name = @"all";
- return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sections/%@", name]];
+ return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sections/%@", [name stringByAddingPercentEscapesIncludingReserved]]];
}
- (id) initWithDatabase:(Database *)database section:(NSString *)name {
title = UCLocalize("NO_SECTION");
if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) {
+ indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+ cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
section_ = name;
} return self;
}
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
+ return [super numberOfSectionsInTableView:list] + 1;
+}
+
+- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section {
+ return section == 0 ? nil : [super tableView:list titleForHeaderInSection:(section - 1)];
+}
+
+- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section {
+ return section == 0 ? promoted_.size() : [super tableView:list numberOfRowsInSection:(section - 1)];
+}
+
++ (NSIndexPath *) adjustedIndexPath:(NSIndexPath *)path {
+ return [NSIndexPath indexPathForRow:[path row] inSection:([path section] - 1)];
+}
+
+- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+ if ([path section] != 0)
+ return [super tableView:table cellForRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+
+ return promoted_[[path row]];
+}
+
+- (void) tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+ if ([path section] != 0)
+ return [super tableView:table didSelectRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+}
+
+- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
+ NSInteger section([super tableView:tableView sectionForSectionIndexTitle:title atIndex:index]);
+ return section == 0 ? 0 : section + 1;
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+ NSURL *url([request URL]);
+ if (url == nil)
+ return;
+
+ if ([frame isEqualToString:@"_open"])
+ [delegate_ openURL:url];
+ else {
+ CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+ [controller setDelegate:delegate_];
+ [[self navigationController] pushViewController:controller animated:YES];
+ }
+
+ [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+ return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+ [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) loadView {
+ [super loadView];
+
+ // XXX: this code is horrible. I mean, wtf Jay?
+ if (ShowPromoted_ && [[Metadata_ objectForKey:@"ShowPromoted"] boolValue]) {
+ promoted_.resize(1);
+
+ for (unsigned i(0); i != promoted_.size(); ++i) {
+ CyteWebViewTableViewCell *promoted([CyteWebViewTableViewCell cellWithRequest:[NSURLRequest
+ requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/sectionhead/%u/%@",
+ UI_, i, section_ == nil ? @"" : [section_ stringByAddingPercentEscapesIncludingReserved]]
+ ]]
+
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:120
+ ]]);
+
+ [promoted setDelegate:self];
+ promoted_[i] = promoted;
+ }
+ }
+}
+
+- (void) setDelegate:(id)delegate {
+ [super setDelegate:delegate];
+ [cydia_ setDelegate:delegate];
+}
+
+- (void) releaseSubviews {
+ promoted_.clear();
+ [super releaseSubviews];
+}
+
@end
/* }}} */
/* Sections Controller {{{ */
}
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
- list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease];
+ list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
[list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[list_ setRowHeight:45.0f];
[(UITableView *) list_ setDataSource:self];
[list_ setDelegate:self];
- [[self view] addSubview:list_];
+ [self setView:list_];
}
- (void) viewDidLoad {
_H<NSArray> packages_;
_H<NSMutableArray> sections_;
_H<UITableView, 2> list_;
+ _H<CyteWebView, 1> dickbar_;
unsigned upgrades_;
+ _H<IndirectDelegate, 1> indirect_;
+ _H<CydiaObject> cydia_;
}
- (id) initWithDatabase:(Database *)database;
}
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+ 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_ = [[[UITableView alloc] initWithFrame:[view bounds] style:UITableViewStylePlain] autorelease];
[list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[list_ setRowHeight:73];
[(UITableView *) list_ setDataSource:self];
[list_ setDelegate:self];
- [[self view] addSubview:list_];
+ [view addSubview:list_];
+
+ if (AprilFools_ && kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+ CGRect dickframe([view bounds]);
+ dickframe.size.height = 44;
+
+ dickbar_ = [[[CyteWebView alloc] initWithFrame:dickframe] autorelease];
+ [dickbar_ setDelegate:self];
+ [view addSubview:dickbar_];
+
+ [dickbar_ setBackgroundColor:[UIColor clearColor]];
+ [dickbar_ setScalesPageToFit:YES];
+
+ UIWebDocumentView *document([dickbar_ _documentView]);
+ [document setBackgroundColor:[UIColor clearColor]];
+ [document setDrawsBackground:NO];
+
+ WebView *webview([document webView]);
+ [webview setShouldUpdateWhileOffscreen:NO];
+
+ UIScrollView *scroller([dickbar_ scrollView]);
+ [scroller setScrollingEnabled:NO];
+ [scroller setFixedBackgroundPattern:YES];
+ [scroller setBackgroundColor:[UIColor clearColor]];
+
+ WebPreferences *preferences([webview preferences]);
+ [preferences setCacheModel:WebCacheModelDocumentBrowser];
+ [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+ [preferences setOfflineWebApplicationCacheEnabled:YES];
+
+ [dickbar_ loadRequest:[NSURLRequest
+ requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/dickbar/", UI_]]]
+ cachePolicy:NSURLRequestUseProtocolCachePolicy
+ timeoutInterval:120
+ ]];
+
+ UIEdgeInsets inset = {44, 0, 0, 0};
+ [list_ setContentInset:inset];
+
+ [dickbar_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
+ }
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+ NSURL *url([request URL]);
+ if (url == nil)
+ return;
+
+ if ([frame isEqualToString:@"_open"])
+ [delegate_ openURL:url];
+ else {
+ CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+ [controller setDelegate:delegate_];
+ [[self navigationController] pushViewController:controller animated:YES];
+ }
+
+ [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+ return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+ [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) setDelegate:(id)delegate {
+ [super setDelegate:delegate];
+ [cydia_ setDelegate:delegate];
}
- (void) viewDidLoad {
[super viewDidLoad];
- [[self navigationItem] setTitle:UCLocalize("CHANGES")];
+ [[self navigationItem] setTitle:(AprilFools_ ? @"Timeline" : UCLocalize("CHANGES"))];
}
- (void) releaseSubviews {
packages_ = nil;
sections_ = nil;
+ dickbar_ = nil;
[super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
+ indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+ cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
database_ = database;
} return self;
}
if ([search_ text] == nil || [[search_ text] isEqualToString:@""])
return [NSURL URLWithString:@"cydia://search"];
else
- return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]];
+ return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [[search_ text] stringByAddingPercentEscapesIncludingReserved]]];
}
- (void) useSearch {
}
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+ UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+ [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+ [self setView:view];
table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease];
[table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[(UITableView *) table_ setDataSource:self];
[table_ setDelegate:self];
- [[self view] addSubview:table_];
+ [view addSubview:table_];
subscribedSwitch_ = [[[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)] autorelease];
[subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
}
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
- list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
+ list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain] autorelease];
[list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[list_ setRowHeight:53];
[(UITableView *) list_ setDataSource:self];
[list_ setDelegate:self];
- [[self view] addSubview:list_];
+ [self setView:list_];
}
- (void) viewDidLoad {
@implementation SettingsController
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
- table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease];
+ table_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped] autorelease];
[table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[table_ setDelegate:self];
[(UITableView *) table_ setDataSource:self];
- [[self view] addSubview:table_];
+ [self setView:table_];
NSArray *items = [NSArray arrayWithObjects:
UCLocalize("USER"),
@implementation StashController
- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
- [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
+ UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+ [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+ [self setView:view];
+
+ [view setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
CGRect spinrect = [spinner_ frame];
spinrect.origin.y = [[self view] frame].size.height - 80.0f;
[spinner_ setFrame:spinrect];
[spinner_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin];
- [[self view] addSubview:spinner_];
+ [view addSubview:spinner_];
[spinner_ startAnimating];
CGRect captrect;
[caption_ setBackgroundColor:[UIColor clearColor]];
[caption_ setShadowColor:[UIColor blackColor]];
[caption_ setTextAlignment:UITextAlignmentCenter];
- [[self view] addSubview:caption_];
+ [view addSubview:caption_];
CGRect statusrect;
statusrect.size.width = [[self view] frame].size.width;
[status_ setBackgroundColor:[UIColor clearColor]];
[status_ setShadowColor:[UIColor blackColor]];
[status_ setTextAlignment:UITextAlignmentCenter];
- [[self view] addSubview:status_];
+ [view addSubview:status_];
}
- (void) releaseSubviews {
NSString *path([[url absoluteString] substringFromIndex:[scheme length] + 3]);
NSArray *components([path componentsSeparatedByString:@"/"]);
- if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"])
- return [self pageForPackage:[components objectAtIndex:1]];
+ if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"]) {
+ CyteViewController *controller([self pageForPackage:[components objectAtIndex:1]]);
+ if (controller != nil)
+ [controller setDelegate:self];
+ return controller;
+ }
if ([components count] < 1 || ![scheme isEqualToString:@"cydia"])
return nil;
}
if (!external && [base isEqualToString:@"search"]) {
- controller = [[[SearchController alloc] initWithDatabase:database_ query:argument] autorelease];
+ controller = [[[SearchController alloc] initWithDatabase:database_ query:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] autorelease];
}
if (!external && [base isEqualToString:@"sections"]) {
if ([argument isEqualToString:@"all"])
argument = nil;
- controller = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease];
+ controller = [[[SectionController alloc] initWithDatabase:database_ section:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] autorelease];
}
if (!external && [base isEqualToString:@"sources"]) {
- (BOOL) openCydiaURL:(NSURL *)url forExternal:(BOOL)external {
CyteViewController *page([self pageForURL:url forExternal:external]);
- if (page != nil) {
- UINavigationController *nav = [[[UINavigationController alloc] init] autorelease];
- [nav setViewControllers:[NSArray arrayWithObject:page]];
- [tabbar_ setUnselectedViewController:nav];
- }
+ if (page != nil)
+ [tabbar_ setUnselectedViewController:page];
return page != nil;
}
NSMutableArray *items([NSMutableArray arrayWithObjects:
[[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage applicationImageNamed:@"home.png"] tag:0] autorelease],
[[[UITabBarItem alloc] initWithTitle:UCLocalize("SECTIONS") image:[UIImage applicationImageNamed:@"install.png"] tag:0] autorelease],
- [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage applicationImageNamed:@"changes.png"] tag:0] autorelease],
+ [[[UITabBarItem alloc] initWithTitle:(AprilFools_ ? @"Timeline" : UCLocalize("CHANGES")) image:[UIImage applicationImageNamed:@"changes.png"] tag:0] autorelease],
[[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage applicationImageNamed:@"search.png"] tag:0] autorelease],
nil]);
}
- (void) _sendMemoryWarningNotification {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidReceiveMemoryWarningNotification" object:[UIApplication sharedApplication]];
+ 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];
- usleep(250000);
+ sleep(2);
+ //usleep(2000000);
}
}
+- (void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
+ NSLog(@"--");
+ [[NSURLCache sharedURLCache] removeAllCachedResponses];
+}
+
- (void) applicationDidFinishLaunching:(id)unused {
//[NSThread detachNewThreadSelector:@selector(_sendMemoryWarningNotifications) toTarget:self withObject:nil];
NSDate *closed = [Metadata_ objectForKey:@"LastClosed"];
if (valid && closed != nil) {
NSTimeInterval interval([closed timeIntervalSinceNow]);
- // XXX: Is 15 minutes the optimal time here?
- if (interval > 0 && interval <= -(15*60))
+ // XXX: Is 30 minutes the optimal time here?
+ if (interval <= -(30*60))
valid = NO;
}
UniqueID_ = [device uniqueIdentifier];
- CFStringRef (*$CTSIMSupportCopyMobileSubscriberCountryCode)(CFAllocatorRef);
- $CTSIMSupportCopyMobileSubscriberCountryCode = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode"));
- CFStringRef mcc($CTSIMSupportCopyMobileSubscriberCountryCode == NULL ? NULL : (*$CTSIMSupportCopyMobileSubscriberCountryCode)(kCFAllocatorDefault));
-
- CFStringRef (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(CFAllocatorRef);
- $CTSIMSupportCopyMobileSubscriberNetworkCode = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode"));
- CFStringRef mnc($CTSIMSupportCopyMobileSubscriberNetworkCode == NULL ? NULL : (*$CTSIMSupportCopyMobileSubscriberNetworkCode)(kCFAllocatorDefault));
-
- if (mcc != NULL && mnc != NULL)
- if (CFStringGetLength(mcc) == 3) {
- CFIndex length(CFStringGetLength(mnc));
- if (length == 2 || length == 3) {
- PLMN_ = [NSString stringWithFormat:@"%@%@", mcc, mnc];
-
- Pcre pattern("^[0-9]{5,6}$");
- if (!pattern(PLMN_))
- PLMN_ = nil;
- }
- }
-
- if (mnc != NULL)
- CFRelease(mnc);
- if (mcc != NULL)
- CFRelease(mcc);
-
- if (NSDictionary *system = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"])
- Build_ = [system objectForKey:@"ProductBuildVersion"];
if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) {
Product_ = [info objectForKey:@"SafariProductVersion"];
Safari_ = [info objectForKey:@"CFBundleVersion"];
}
+
+ NSString *agent([NSString stringWithFormat:@"Cydia/%@ CF/%.2f", Cydia_, kCFCoreFoundationVersionNumber]);
+
+ if (Pcre match = Pcre("^[0-9]+(\\.[0-9]+)+", Safari_))
+ agent = [NSString stringWithFormat:@"Safari/%@ %@", match[0], agent];
+ if (Pcre match = Pcre("^[0-9]+[A-Z][0-9]+[a-z]?", System_))
+ agent = [NSString stringWithFormat:@"Mobile/%@ %@", match[0], agent];
+ if (Pcre match = Pcre("^[0-9]+(\\.[0-9]+)+", Product_))
+ agent = [NSString stringWithFormat:@"Version/%@ %@", match[0], agent];
+
+ UserAgent_ = agent;
/* }}} */
/* Load Database {{{ */
_trace();
Token_ = [Metadata_ objectForKey:@"Token"];
Version_ = [Metadata_ objectForKey:@"Version"];
-
- @synchronized (HostConfig_) {
- CydiaSource_ = [Metadata_ objectForKey:@"CydiaSource"];
- }
}
if (Settings_ != nil)
[Metadata_ setObject:Version_ forKey:@"Version"];
}
- @synchronized (HostConfig_) {
- if (CydiaSource_ == nil) {
- CydiaSource_ = @"apt.saurik.com";
- [Metadata_ setObject:CydiaSource_ forKey:@"CydiaSource"];
- }
- }
-
if ([Version_ unsignedIntValue] == 0) {
CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
int version([[NSString stringWithContentsOfFile:@"/var/lib/cydia/firmware.ver"] intValue]);
- if (access("/tmp/.cydia.fw", F_OK) == 0) {
- unlink("/tmp/.cydia.fw");
- goto firmware;
- } else if (access("/User", F_OK) != 0 || version < 4) {
- firmware:
+ if (access("/User", F_OK) != 0 || version != 5) {
_trace();
system("/usr/libexec/cydia/firmware.sh");
_trace();
//UIKeyboardDisableAutomaticAppearance();
/* }}} */
+ BOOL (*GSSystemHasCapability)(CFStringRef) = reinterpret_cast<BOOL (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemHasCapability"));
+ ShowPromoted_ = GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("armv7"));
+
Colon_ = UCLocalize("COLON_DELIMITED");
Elision_ = UCLocalize("ELISION");
Error_ = UCLocalize("ERROR");
Warning_ = UCLocalize("WARNING");
+#if !ForRelease
+ AprilFools_ = true;
+#else
+ CFGregorianDate date(CFAbsoluteTimeGetGregorianDate(CFAbsoluteTimeGetCurrent(), CFTimeZoneCopySystem()));
+ AprilFools_ = date.month == 4 && date.day == 1;
+#endif
+
_trace();
int value(UIApplicationMain(argc, argv, @"Cydia", @"Cydia"));