#include <IOKit/IOKitLib.h>
+#include <QuartzCore/CALayer.h>
+
#include <WebCore/WebCoreThread.h>
#include <algorithm>
#include <errno.h>
#include <Cytore.hpp>
+#include "Sources.h"
#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"
#define _end }
/* }}} */
-#include "Version.h"
-#define Cydia_ CYDIA_VERSION
+extern NSString *Cydia_;
#define lprintf(args...) fprintf(stderr, args)
};
// }}}
+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) {
return [[NSString stringWithUTF8String:page] stringByAppendingString:path];
}
+static void ReapZombie(pid_t pid) {
+ int status;
+ wait:
+ if (waitpid(pid, &status, 0) == -1)
+ if (errno == EINTR)
+ goto wait;
+ else _assert(false);
+}
+
static _finline void UpdateExternalStatus(uint64_t newStatus) {
int notify_token;
if (notify_register_check("com.saurik.Cydia.status", ¬ify_token) == NOTIFY_STATUS_OK) {
notify_post("com.saurik.Cydia.status");
}
-static CGFloat CYStatusBarHeight(UIInterfaceOrientation orientation) {
+static CGFloat CYStatusBarHeight() {
CGSize size([[UIApplication sharedApplication] statusBarFrame].size);
- return UIInterfaceOrientationIsPortrait(orientation) ? size.height : size.width;
+ return UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? size.height : size.width;
}
/* NSForcedOrderingSearch doesn't work on the iPhone */
/* Cydia NSString Additions {{{ */
@interface NSString (Cydia)
- (NSComparisonResult) compareByPath:(NSString *)other;
-- (NSString *) stringByCachingURLWithCurrentCDN;
- (NSString *) stringByAddingPercentEscapesIncludingReserved;
@end
return result == NSOrderedSame ? value : result;
}
-- (NSString *) stringByCachingURLWithCurrentCDN {
- return [self
- stringByReplacingOccurrencesOfString:@"://cydia.saurik.com/"
- withString:@"://cache.cydia.saurik.com/"
- ];
-}
-
- (NSString *) stringByAddingPercentEscapesIncludingReserved {
return [(id)CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
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 *Packages_;
static _transient NSMutableDictionary *Values_;
static _transient NSMutableDictionary *Sections_;
-static _transient NSMutableDictionary *Sources_;
+_H<NSMutableDictionary> Sources_;
static _transient NSNumber *Version_;
-static _transient _H<NSString> CydiaSource_;
-static bool Changed_;
+bool Changed_;
static time_t now_;
bool IsWildcat_;
static CGFloat ScreenScale_;
static NSString *Idiom_;
+static _H<NSString> Firmware_;
+static NSString *Major_;
static _H<NSMutableDictionary> SessionData_;
static _H<NSObject> HostConfig_;
static NSString *kCydiaProgressEventTypeWarning = @"Warning";
/* }}} */
-static void AddSource(NSDictionary *source) {
- [Sources_ setObject:source forKey:[NSString stringWithFormat:@"%@:%@:%@", [source objectForKey:@"Type"], [source objectForKey:@"URI"], [source objectForKey:@"Distribution"]]];
- Changed_ = true;
-}
-
-static void AddSource(NSString *href, NSString *distribution, NSArray *sections = nil) {
- AddSource([NSMutableDictionary dictionaryWithObjectsAndKeys:
- @"deb", @"Type",
- href, @"URI",
- distribution, @"Distribution",
- sections ?: [NSMutableArray array], @"Sections",
- nil]);
-}
-
-static void WriteSources() {
- FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w"));
- _assert(file != NULL);
-
- fprintf(file, "deb http://%s/ tangelo main\n",
- [CydiaSource_ UTF8String]
- );
-
- for (NSString *key in [Sources_ allKeys]) {
- NSDictionary *source([Sources_ objectForKey:key]);
-
- NSArray *sections([source objectForKey:@"Sections"] ?: [NSArray array]);
-
- fprintf(file, "%s %s %s%s%s\n",
- [[source objectForKey:@"Type"] UTF8String],
- [[source objectForKey:@"URI"] UTF8String],
- [[source objectForKey:@"Distribution"] UTF8String],
- [sections count] == 0 ? "" : " ",
- [[sections componentsJoinedByString:@" "] UTF8String]
- );
- }
-
- fclose(file);
-}
-
/* Display Helpers {{{ */
inline float Interpolate(float begin, float end, float fraction) {
return (end - begin) * fraction + begin;
@class CYPackageController;
@protocol CydiaDelegate
+- (void) returnToCydia;
- (void) saveState;
- (void) retainNetworkActivityIndicator;
- (void) releaseNetworkActivityIndicator;
}
virtual void IMSHit(pkgAcquire::ItemDesc &item) {
+ Done(item);
}
virtual void Fetch(pkgAcquire::ItemDesc &item) {
}
virtual void Done(pkgAcquire::ItemDesc &item) {
+ NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]);
+ CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:Colon_, UCLocalize("DONE"), name] ofType:kCydiaProgressEventTypeStatus forItem:item]);
+ [delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
}
virtual void Fail(pkgAcquire::ItemDesc &item) {
/* Source Class {{{ */
@interface Source : NSObject {
+ unsigned era_;
+ Database *database_;
+ metaIndex *index_;
+
CYString depiction_;
CYString description_;
CYString label_;
BOOL trusted_;
}
-- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool;
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool;
-- (NSComparisonResult) compareByNameAndType:(Source *)source;
+- (NSComparisonResult) compareByName:(Source *)source;
- (NSString *) depictionForPackage:(NSString *)package;
- (NSString *) supportForPackage:(NSString *)package;
- (NSDictionary *) record;
- (BOOL) trusted;
-- (NSString *) uri;
+- (NSString *) rooturi;
- (NSString *) distribution;
- (NSString *) type;
-- (NSString *) base;
-
- (NSString *) key;
- (NSString *) host;
- (NSString *) version;
- (NSString *) defaultIcon;
+- (NSURL *) iconURL;
@end
if (false);
else if (selector == @selector(addSection:))
return @"addSection";
+ else if (selector == @selector(getField:))
+ return @"getField";
else if (selector == @selector(removeSection:))
return @"removeSection";
else if (selector == @selector(remove))
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
+ @"baseuri",
@"distribution",
@"host",
@"key",
+ @"iconuri",
@"label",
@"name",
@"origin",
+ @"rooturi",
@"sections",
@"shortDescription",
@"trusted",
@"type",
- @"uri",
@"version",
nil];
}
authority_ = [url path];
}
-- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool {
if ((self = [super init]) != nil) {
+ era_ = [database era];
+ database_ = database;
+ index_ = index;
+
[self setMetaIndex:index inPool:pool];
} return self;
}
-- (NSComparisonResult) compareByNameAndType:(Source *)source {
- NSDictionary *lhr = [self record];
- NSDictionary *rhr = [source record];
+- (NSString *) getField:(NSString *)name {
+@synchronized (database_) {
+ if ([database_ era] != era_ || index_ == NULL)
+ return nil;
+
+ debReleaseIndex *dindex(dynamic_cast<debReleaseIndex *>(index_));
+ if (dindex == NULL)
+ return nil;
+
+ FileFd fd;
+ if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly)) {
+ _error->Discard();
+ return nil;
+ }
- if (lhr != rhr)
- return lhr == nil ? NSOrderedDescending : NSOrderedAscending;
+ pkgTagFile tags(&fd);
+ pkgTagSection section;
+ tags.Step(section);
+
+ const char *start, *end;
+ if (!section.Find([name UTF8String], start, end))
+ return (NSString *) [NSNull null];
+
+ return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]];
+} }
+
+- (NSComparisonResult) compareByName:(Source *)source {
NSString *lhs = [self name];
NSString *rhs = [source name];
return trusted_;
}
-- (NSString *) uri {
+- (NSString *) rooturi {
return uri_;
}
return type_;
}
-- (NSString *) base {
- return base_;
+- (NSString *) baseuri {
+ return base_.empty() ? nil : (id) base_;
+}
+
+- (NSString *) iconuri {
+ if (NSString *base = [self baseuri])
+ return [base stringByAppendingString:@"CydiaIcon.png"];
+
+ return nil;
+}
+
+- (NSURL *) iconURL {
+ if (NSString *uri = [self iconuri])
+ return [NSURL URLWithString:uri];
+ return nil;
}
- (NSString *) key {
/* }}} */
/* Package Class {{{ */
struct ParsedPackage {
+ CYString md5sum_;
CYString tagline_;
CYString architecture_;
};
@interface Package : NSObject {
- uint32_t era_ : 26;
+ uint32_t era_ : 25;
uint32_t role_ : 3;
uint32_t essential_ : 1;
uint32_t obsolete_ : 1;
uint32_t ignored_ : 1;
+ uint32_t pooled_ : 1;
apr_pool_t *pool_;
}
- (void) dealloc {
+ if (!pooled_)
+ apr_pool_destroy(pool_);
if (parsed_ != NULL)
delete parsed_;
[super dealloc];
@"longDescription",
@"longSection",
@"maintainer",
+ @"md5sum",
@"mode",
@"name",
@"purposes",
if (!parser.Find([name UTF8String], start, end))
return (NSString *) [NSNull null];
- return [(NSString *) CYStringCreate(start, end - start) autorelease];
+ return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]];
} }
- (void) parse {
{"support", &parsed->support_},
{"sponsor", &parsed->sponsor_},
{"author", &parsed->author_},
+ {"md5sum", &parsed->md5sum_},
};
for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
if ((self = [super init]) != nil) {
_profile(Package$initWithVersion)
- pool_ = pool;
+ if (pool == NULL)
+ apr_pool_create(&pool_, NULL);
+ else {
+ pool_ = pool;
+ pooled_ = true;
+ }
database_ = database;
era_ = [database era];
return maintainer.empty() ? nil : [MIMEAddress addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
} }
+- (NSString *) md5sum {
+ return parsed_ == NULL ? nil : (id) parsed_->md5sum_;
+}
+
- (size_t) size {
@synchronized (database_) {
if ([database_ era] != era_ || version_.end())
if (!parser.ShortDesc(start, end))
return nil;
- if (end - start > 100)
- end = start + 100;
+ if (end - start > 200)
+ end = start + 200;
/*
if (const char *stop = reinterpret_cast<const char *>(memchr(start, '\n', end - start)))
}
- (BOOL) hasMode {
+@synchronized (database_) {
+ if ([database_ era] != era_ || iterator_.end())
+ return nil;
+
pkgDepCache::StateCache &state([database_ cache][iterator_]);
return state.Mode != pkgDepCache::ModeKeep;
-}
+} }
- (NSString *) mode {
+@synchronized (database_) {
+ if ([database_ era] != era_ || iterator_.end())
+ return nil;
+
pkgDepCache::StateCache &state([database_ cache][iterator_]);
switch (state.Mode) {
}
_nodefault
}
-}
+} }
- (NSString *) id {
return id_;
string = [self shortDescription];
length = [string length];
- NSUInteger stop(std::min<NSUInteger>(length, 100));
+ NSUInteger stop(std::min<NSUInteger>(length, 200));
for (NSString *term in query) {
range = [string rangeOfString:term options:MatchCompareOptions_ range:NSMakeRange(0, stop)];
@end
/* }}} */
-static NSString *Colon_;
-NSString *Elision_;
-static NSString *Error_;
-static NSString *Warning_;
-
class CydiaLogCleaner :
public pkgArchiveCleaner
{
}
- (Package *) packageWithName:(NSString *)name {
+ if (name == nil)
+ return nil;
@synchronized (self) {
if (static_cast<pkgDepCache *>(cache_) == NULL)
return nil;
pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String]));
- return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:pool_ database:self];
+ return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:NULL database:self];
} }
- (id) init {
lprintf("%c:[%s]\n", warning ? 'W' : 'E', error.c_str());
+ static Pcre no_pubkey("^GPG error:.* NO_PUBKEY .*$");
+ if (warning && no_pubkey(error.c_str()))
+ continue;
+
[delegate_ addProgressEventOnMainThread:[CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:(warning ? kCydiaProgressEventTypeWarning : kCydiaProgressEventTypeError)] forTask:title];
}
}
for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
- Source *object([[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease]);
+ Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:pool_] autorelease]);
[sourceList_ addObject:object];
std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
@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",
}
- (NSString *) version {
- return @ Cydia_;
+ return Cydia_;
+}
+
+- (NSString *) build {
+ return System_;
+}
+
+- (NSString *) coreFoundationVersionNumber {
+ return [NSString stringWithFormat:@"%.2f", kCFCoreFoundationVersionNumber];
}
- (NSString *) device {
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 @"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:))
[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];
}
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];
fclose(du);
} else _assert(close(fds[0]));
- int status;
- wait:
- if (waitpid(pid, &status, 0) == -1)
- if (errno == EINTR)
- goto wait;
- else _assert(false);
+ ReapZombie(pid);
return value;
}
return request_ == nil ? nil : [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]];
}
-+ (void) initialize {
++ (void) _initialize {
+ [super _initialize];
+
Diversions_ = [NSMutableSet setWithCapacity:0];
}
- (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]);
- if (System_ != NULL && [copy valueForHTTPHeaderField:@"X-System"] == nil)
- [copy setValue:System_ forHTTPHeaderField:@"X-System"];
+ NSURL *url([copy URL]);
+ NSString *host([url host]);
+
+ 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"];
+ bool bridged;
bool token;
+
@synchronized (HostConfig_) {
- token = [TokenHosts_ containsObject:host] || [BridgedHosts_ containsObject:host];
+ bridged = [BridgedHosts_ containsObject:host];
+ token = [TokenHosts_ containsObject:host];
}
- if ([url isCydiaSecure] && token) {
- if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil)
- [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+ if ([url isCydiaSecure]) {
+ if (bridged) {
+ if (UniqueID_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Id"] == nil)
+ [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
+ } else if (token) {
+ if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil)
+ [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+ }
}
return copy;
}
- (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 {
} return self;
}
+@end
+
+@interface AppCacheController : CydiaWebViewController {
+}
+
+@end
+
+@implementation AppCacheController
+
+- (void) didReceiveMemoryWarning {
+ // XXX: this doesn't work
+}
+
+- (bool) retainsNetworkActivityIndicator {
+ return false;
+}
+
@end
/* }}} */
}
- (void) _doContinue {
- [self dismissModalViewControllerAnimated:YES];
[delegate_ cancelAndClear:NO];
+ [self dismissModalViewControllerAnimated:YES];
}
- (id) invokeDefaultMethodWithArguments:(NSArray *)args {
switch (Finish_) {
case 0:
+ [delegate_ returnToCydia];
break;
case 1:
] autorelease];
}
+- (void) uicache {
+ _trace();
+ system("su -c /usr/bin/uicache mobile");
+ _trace();
+}
+
- (void) invoke:(NSInvocation *)invocation withTitle:(NSString *)title {
UpdateExternalStatus(1);
case 4: [progress_ setFinish:UCLocalize("REBOOT_DEVICE")]; break;
}
- _trace();
- system("su -c /usr/bin/uicache mobile");
- _trace();
+ UIProgressHUD *hud([delegate_ addProgressHUD]);
+ [hud setText:UCLocalize("LOADING")];
+ [self yieldToSelector:@selector(uicache)];
+ [delegate_ removeProgressHUD:hud];
UpdateExternalStatus(Finish_ == 0 ? 0 : 2);
badge_ = nil;
placard_ = nil;
- [package parse];
+ if (package == nil)
+ [content_ setBackgroundColor:[UIColor whiteColor]];
+ else {
+ [package parse];
- Source *source = [package source];
+ Source *source = [package source];
- icon_ = [package icon];
+ icon_ = [package icon];
- if (NSString *name = [package name])
- name_ = [NSString stringWithString:name];
+ if (NSString *name = [package name])
+ name_ = [NSString stringWithString:name];
- NSString *description(nil);
+ NSString *description(nil);
- if (description == nil && IsWildcat_)
- description = [package longDescription];
- if (description == nil)
- description = [package shortDescription];
+ if (description == nil && IsWildcat_)
+ description = [package longDescription];
+ if (description == nil)
+ description = [package shortDescription];
- if (description != nil)
- description_ = [NSString stringWithString:description];
+ if (description != nil)
+ description_ = [NSString stringWithString:description];
- commercial_ = [package isCommercial];
+ commercial_ = [package isCommercial];
- NSString *label = nil;
- bool trusted = false;
+ NSString *label = nil;
+ bool trusted = false;
- if (source != nil) {
- label = [source label];
- trusted = [source trusted];
- } else if ([[package id] isEqualToString:@"firmware"])
- label = UCLocalize("APPLE");
- else
- label = [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("UNKNOWN"), UCLocalize("LOCAL")];
+ if (source != nil) {
+ label = [source label];
+ trusted = [source trusted];
+ } else if ([[package id] isEqualToString:@"firmware"])
+ label = UCLocalize("APPLE");
+ else
+ label = [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("UNKNOWN"), UCLocalize("LOCAL")];
- NSString *from(label);
+ NSString *from(label);
- NSString *section = [package simpleSection];
- if (section != nil && ![section isEqualToString:label]) {
- section = [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"];
- from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section];
- }
+ NSString *section = [package simpleSection];
+ if (section != nil && ![section isEqualToString:label]) {
+ section = [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"];
+ from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section];
+ }
- source_ = [NSString stringWithFormat:UCLocalize("FROM"), from];
+ source_ = [NSString stringWithFormat:UCLocalize("FROM"), from];
- if (NSString *purpose = [package primaryPurpose])
- badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]];
+ if (NSString *purpose = [package primaryPurpose])
+ badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]];
- UIColor *color;
- NSString *placard;
+ UIColor *color;
+ NSString *placard;
- if (NSString *mode = [package mode]) {
- if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) {
- color = RemovingColor_;
- //placard = @"removing";
+ if (NSString *mode = [package mode]) {
+ if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) {
+ color = RemovingColor_;
+ //placard = @"removing";
+ } else {
+ color = InstallingColor_;
+ //placard = @"installing";
+ }
+
+ // XXX: the removing/installing placards are not @2x
+ placard = nil;
} else {
- color = InstallingColor_;
- //placard = @"installing";
+ color = [UIColor whiteColor];
+
+ if ([package installed] != nil)
+ placard = @"installed";
+ else
+ placard = nil;
}
- // XXX: the removing/installing placards are not @2x
- placard = nil;
- } else {
- color = [UIColor whiteColor];
+ [content_ setBackgroundColor:color];
- if ([package installed] != nil)
- placard = @"installed";
- else
- placard = nil;
+ if (placard != nil)
+ placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]];
}
- [content_ setBackgroundColor:color];
-
- if (placard != nil)
- placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]];
-
[self setNeedsDisplay];
[content_ setNeedsDisplay];
}
CGRect rect;
rect.size = [(UIImage *) icon_ size];
- rect.size.width /= 4;
- rect.size.height /= 4;
+ while (rect.size.width > 16 || rect.size.height > 16) {
+ rect.size.width /= 2;
+ rect.size.height /= 2;
+ }
- rect.origin.x = 14 - rect.size.width / 4;
- rect.origin.y = 14 - rect.size.height / 4;
+ rect.origin.x = 18 - rect.size.width / 2;
+ rect.origin.y = 18 - rect.size.height / 2;
[icon_ drawInRect:rect];
}
rect.size.width /= 4;
rect.size.height /= 4;
- rect.origin.x = 20 - rect.size.width / 4;
- rect.origin.y = 20 - rect.size.height / 4;
+ rect.origin.x = 23 - rect.size.width / 2;
+ rect.origin.y = 23 - rect.size.height / 2;
[badge_ drawInRect:rect];
}
CGRect rect;
rect.size = [(UIImage *) icon_ size];
- rect.size.width /= 2;
- rect.size.height /= 2;
+ while (rect.size.width > 32 || rect.size.height > 32) {
+ rect.size.width /= 2;
+ rect.size.height /= 2;
+ }
rect.origin.x = 25 - rect.size.width / 2;
rect.origin.y = 25 - rect.size.height / 2;
}
- (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) releaseSubviews {
list_ = nil;
+ package_ = nil;
+ files_ = nil;
+
[super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
database_ = database;
-
- files_ = [NSMutableArray arrayWithCapacity:32];
} return self;
}
package_ = nil;
name_ = nil;
- [files_ removeAllObjects];
+ files_ = [NSMutableArray arrayWithCapacity:32];
if (package != nil) {
package_ = package;
if ((self = [super init]) != nil) {
database_ = database;
buttons_ = [NSMutableArray arrayWithCapacity:4];
- name_ = [NSString stringWithString:name];
+ name_ = name == nil ? @"" : [NSString stringWithString:name];
[self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, (id) name_]]];
} return self;
}
CGRect intersection = CGRectIntersection(viewframe, kbframe);
if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
- intersection.size.height += CYStatusBarHeight([self interfaceOrientation]);
+ intersection.size.height += CYStatusBarHeight();
[self resizeForKeyboardBounds:intersection duration:duration curve:curve];
}
database_ = database;
title_ = [title copy];
[[self navigationItem] setTitle:title_];
-
-#if TryIndexedCollation
- if ([[self class] hasIndexedCollation])
- index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles];
- else
-#endif
- index_ = [NSMutableArray arrayWithCapacity:32];
-
- indices_ = [NSMutableDictionary dictionaryWithCapacity:32];
-
- packages_ = [NSArray array];
- sections_ = [NSMutableArray arrayWithCapacity:16];
} return self;
}
- (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];
- (void) releaseSubviews {
list_ = nil;
+ packages_ = nil;
+ sections_ = nil;
+ index_ = nil;
+ indices_ = nil;
+
[super releaseSubviews];
}
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_ removeAllObjects];
- [sections_ removeAllObjects];
+ indices_ = [NSMutableDictionary dictionaryWithCapacity:32];
+ sections_ = [NSMutableArray arrayWithCapacity:16];
Section *section = nil;
#if TryIndexedCollation
if ([[self class] hasIndexedCollation]) {
+ index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles];
+
id collation = [objc_getClass("UILocalizedIndexedCollation") currentCollation];
NSArray *titles = [collation sectionIndexTitles];
int secidx = -1;
} else
#endif
{
- [index_ removeAllObjects];
+ index_ = [NSMutableArray arrayWithCapacity:32];
bool sectioned([self showsSections]);
if (!sectioned) {
[(UITableView *) list_ setDataSource:self];
[list_ reloadData];
_end
-}
+} }
- (void) reloadData {
[super reloadData];
- [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0];
+
+ if ([self shouldYield])
+ [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0];
+ else
+ [self _reloadData];
}
- (void) resetCursor {
- (id) init {
if ((self = [super init]) != nil) {
- [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/manage/", UI_]]];
+ [self setURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"manage" ofType:@"html"]]];
} return self;
}
[delegate_ queue];
}
-- (UIBarButtonItem *) customButton {
+- (UIBarButtonItem *) rightButton {
return Queuing_ ? [[[UIBarButtonItem alloc]
initWithTitle:UCLocalize("QUEUE")
style:UIBarButtonItemStyleDone
target:self
action:@selector(queueButtonClicked)
- ] autorelease] : [super customButton];
+ ] autorelease] : nil;
}
- (void) queueStatusDidChange {
@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 {
return items;
}
+- (void) dismissModalViewControllerAnimated:(BOOL)animated {
+ if ([self modalViewController] == nil && [self unselectedViewController] != nil)
+ [self setUnselectedViewController:nil];
+ else
+ [super dismissModalViewControllerAnimated:YES];
+}
+
- (void) unloadData {
[super unloadData];
CGRect barframe([refreshbar_ frame]);
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
- barframe.origin.y = CYStatusBarHeight([self interfaceOrientation]);
+ barframe.origin.y = CYStatusBarHeight();
else
barframe.origin.y = 0;
- (void) reloadData {
[super reloadData];
- if (UIViewController *visible = [self visibleViewController])
+ UIViewController *visible([self visibleViewController]);
+ if (visible != nil)
[visible reloadData];
+
+ // on the iPad, this view controller is ALSO visible. :(
+ if (IsWildcat_)
+ if (UIViewController *top = [self topViewController])
+ if (top != visible)
+ [top reloadData];
}
- (void) unloadData {
[package parse];
UIImage *icon([package icon]);
[self _returnPNGWithImage:icon forRequest:request];
- } else if ([command isEqualToString:@"source-icon"]) {
- if (path == nil)
- goto fail;
- path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSString *source(Simplify(path));
- UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sources/%@.png", App_, source]]);
- if (icon == nil)
- icon = [UIImage applicationImageNamed:@"unknown.png"];
- [self _returnPNGWithImage:icon forRequest:request];
} else if ([command isEqualToString:@"uikit-image"]) {
if (path == nil)
goto fail;
if (path == nil)
goto fail;
path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSString *section(Simplify(path));
- UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, [section stringByReplacingOccurrencesOfString:@" " withString:@"_"]]]);
+ UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, [path stringByReplacingOccurrencesOfString:@" " withString:@"_"]]]);
if (icon == nil)
icon = [UIImage applicationImageNamed:@"unknown.png"];
[self _returnPNGWithImage:icon forRequest:request];
/* 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 {
- (void) releaseSubviews {
list_ = nil;
+ sections_ = nil;
+ filtered_ = nil;
+
[super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
database_ = database;
-
- sections_ = [NSMutableArray arrayWithCapacity:16];
- filtered_ = [NSMutableArray arrayWithCapacity:16];
} return self;
}
NSArray *packages = [database_ packages];
- [sections_ removeAllObjects];
- [filtered_ removeAllObjects];
+ sections_ = [NSMutableArray arrayWithCapacity:16];
+ filtered_ = [NSMutableArray arrayWithCapacity:16];
NSMutableDictionary *sections([NSMutableDictionary dictionaryWithCapacity:32]);
_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 {
list_ = nil;
+ 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;
-
- packages_ = [NSArray array];
- sections_ = [NSMutableArray arrayWithCapacity:16];
} return self;
}
goto reload;
packages_ = packages;
- [sections_ removeAllObjects];
+ sections_ = [NSMutableArray arrayWithCapacity:16];
Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
Section *ignored = nil;
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 {
@implementation PackageSettingsController
- (NSURL *) navigationURL {
- return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", [package_ id]]];
+ return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/settings", (id) name_]];
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
_assert(false);
}
- _forever {
- int status;
- int result(waitpid(pid, &status, 0));
-
- if (result != -1) {
- _assert(result == pid);
- break;
- }
- }
+ ReapZombie(pid);
}
- (void) onIgnored:(id)control {
}
- (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];
@interface SourceCell : CyteTableViewCell <
CyteTableViewCellDelegate
> {
+ _H<NSURL> url_;
_H<UIImage> icon_;
_H<NSString> origin_;
_H<NSString> label_;
@implementation SourceCell
-- (void) _setImage:(UIImage *)image {
- icon_ = image;
- [content_ setNeedsDisplay];
+- (void) _setImage:(NSArray *)data {
+ if ([url_ isEqual:[data objectAtIndex:0]]) {
+ icon_ = [data objectAtIndex:1];
+ [content_ setNeedsDisplay];
+ }
}
-- (void) _setSource:(Source *)source {
+- (void) _setSource:(NSURL *) url {
NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
- if (NSString *base = [source base])
- if ([base length] != 0) {
- NSURL *url([NSURL URLWithString:[base stringByAppendingString:@"CydiaIcon.png"]]);
-
- if (NSData *data = [NSURLConnection
- sendSynchronousRequest:[NSURLRequest
- requestWithURL:url
- //cachePolicy:NSURLRequestUseProtocolCachePolicy
- //timeoutInterval:5
- ]
-
- returningResponse:NULL
- error:NULL
- ])
- if (UIImage *image = [UIImage imageWithData:data])
- [self performSelectorOnMainThread:@selector(_setImage:) withObject:image waitUntilDone:NO];
- }
+ if (NSData *data = [NSURLConnection
+ sendSynchronousRequest:[NSURLRequest
+ requestWithURL:url
+ //cachePolicy:NSURLRequestUseProtocolCachePolicy
+ //timeoutInterval:5
+ ]
+
+ returningResponse:NULL
+ error:NULL
+ ])
+ if (UIImage *image = [UIImage imageWithData:data])
+ [self performSelectorOnMainThread:@selector(_setImage:) withObject:[NSArray arrayWithObjects:url, image, nil] waitUntilDone:NO];
[pool release];
}
icon_ = [UIImage applicationImageNamed:@"unknown.png"];
origin_ = [source name];
- label_ = [source uri];
+ label_ = [source rooturi];
[content_ setNeedsDisplay];
- [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:source];
+ url_ = [source iconURL];
+ [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:url_];
}
- (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
[content_ setDelegate:self];
[content_ setOpaque:YES];
+
+ [[content_ layer] setContentsGravity:kCAGravityTopLeft];
} return self;
}
bool highlighted(highlighted_);
float width(rect.size.width);
- if (icon_ != nil)
- [icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
+ if (icon_ != nil) {
+ CGRect rect;
+ rect.size = [(UIImage *) icon_ size];
+
+ while (rect.size.width > 32 || rect.size.height > 32) {
+ rect.size.width /= 2;
+ rect.size.height /= 2;
+ }
+
+ rect.origin.x = 25 - rect.size.width / 2;
+ rect.origin.y = 25 - rect.size.height / 2;
+
+ [icon_ drawInRect:rect];
+ }
if (highlighted)
UISetColor(White_);
if (!highlighted)
UISetColor(Black_);
- [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 80) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
+ [origin_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - 65) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation];
if (!highlighted)
- UISetColor(Blue_);
- [label_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
+ UISetColor(Gray_);
+ [label_ drawAtPoint:CGPointMake(48, 29) forWidth:(width - 65) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation];
}
@end
@implementation SourceController
- (NSURL *) navigationURL {
- return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [source_ name]]];
+ return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [key_ stringByAddingPercentEscapesIncludingReserved]]];
}
- (id) initWithDatabase:(Database *)database source:(Source *)source {
UITableViewDelegate
> {
_transient Database *database_;
+ unsigned era_;
+
_H<UITableView, 2> list_;
_H<NSMutableArray> sources_;
int offset_;
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
- return offset_ == 0 ? 1 : 2;
+ return 1;
}
- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- switch (section + (offset_ == 0 ? 1 : 0)) {
- case 0: return UCLocalize("ENTERED_BY_USER");
- case 1: return UCLocalize("INSTALLED_BY_PACKAGE");
-
- _nodefault
- }
+ return nil;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- int count = [sources_ count];
- switch (section) {
- case 0: return (offset_ == 0 ? count : offset_);
- case 1: return count - offset_;
-
- _nodefault
- }
+ return [sources_ count];
}
- (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath {
- unsigned idx = 0;
- switch (indexPath.section) {
- case 0: idx = indexPath.row; break;
- case 1: idx = indexPath.row + offset_; break;
+@synchronized (database_) {
+ if ([database_ era] != era_)
+ return nil;
- _nodefault
- }
- return [sources_ objectAtIndex:idx];
-}
+ return [sources_ objectAtIndex:[indexPath row]];
+} }
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"SourceCell";
- (void) complete {
[delegate_ addTrivialSource:href_];
+ href_ = nil;
+
[delegate_ syncData];
}
href = [href substringFromIndex:(colon.location + 3)];
href = [href stringByAddingPercentEscapes];
href = [CydiaURL(@"api/repotag/") stringByAppendingString:href];
- href = [href stringByCachingURLWithCurrentCDN];
NSURL *url([NSURL URLWithString:href]);
trivial_bz2_ == nil &&
trivial_gz_ == nil
) {
+ NSString *warning(cydia_ ? [self yieldToSelector:@selector(getWarning)] : nil);
+
[delegate_ releaseNetworkActivityIndicator];
[delegate_ removeProgressHUD:hud_];
hud_ = nil;
- bool defer(false);
-
if (cydia_) {
- if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
- defer = true;
-
+ if (warning != nil) {
UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:UCLocalize("SOURCE_WARNING")
message:warning
[alert setContext:@"warning"];
[alert setNumberOfRows:1];
[alert show];
- } else
- [self complete];
+
+ // XXX: there used to be this great mechanism called yieldToPopup... who deleted it?
+ error_ = nil;
+ return;
+ }
+
+ [self complete];
} else if (error_ != nil) {
UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:UCLocalize("VERIFICATION_ERROR")
[alert setContext:@"urlerror"];
[alert show];
+
+ href_ = nil;
} else {
UIAlertView *alert = [[[UIAlertView alloc]
initWithTitle:UCLocalize("NOT_REPOSITORY")
[alert setContext:@"trivial"];
[alert show];
+
+ href_ = nil;
}
- href_ = nil;
error_ = nil;
}
}
[request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
if ([url isCydiaSecure]) {
- if (UniqueID_ != nil)
+ if (UniqueID_ != nil) {
[request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+ [request setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
+ }
}
return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
else if ([context isEqualToString:@"warning"]) {
switch (button) {
case 1:
- [self complete];
+ [self performSelector:@selector(complete) withObject:nil afterDelay:0];
break;
case 0:
_nodefault
}
- href_ = nil;
-
[alert dismissWithClickedButtonIndex:-1 animated:YES];
}
}
- (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:56];
+ [list_ setRowHeight:53];
[(UITableView *) list_ setDataSource:self];
[list_ setDelegate:self];
- [[self view] addSubview:list_];
+ [self setView:list_];
}
- (void) viewDidLoad {
- (void) releaseSubviews {
list_ = nil;
+ sources_ = nil;
+
[super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
database_ = database;
- sources_ = [NSMutableArray arrayWithCapacity:16];
} return self;
}
- (void) reloadData {
[super reloadData];
+@synchronized (database_) {
+ era_ = [database_ era];
+
pkgSourceList list;
if ([database_ popErrorWithTitle:UCLocalize("SOURCES") forOperation:list.ReadMainList()])
return;
- [sources_ removeAllObjects];
+ sources_ = [NSMutableArray arrayWithCapacity:16];
[sources_ addObjectsFromArray:[database_ sources]];
_trace();
- [sources_ sortUsingSelector:@selector(compareByNameAndType:)];
+ [sources_ sortUsingSelector:@selector(compareByName:)];
_trace();
int count([sources_ count]);
[list_ setEditing:NO];
[self updateButtonsForEditingStatus:NO animated:NO];
[list_ reloadData];
-}
+} }
- (void) showAddSourcePrompt {
UIAlertView *alert = [[[UIAlertView alloc]
@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"),
UCLocalize("DEVELOPER"),
nil];
segment_ = [[[UISegmentedControl alloc] initWithItems:items] autorelease];
+ [segment_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin)];
container_ = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)] autorelease];
[container_ addSubview:segment_];
}
@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 {
}
}
+- (void) returnToCydia {
+ [self _loaded];
+}
+
- (void) _saveConfig {
- _trace();
- MetaFile_.Sync();
- _trace();
+ @synchronized (database_) {
+ _trace();
+ MetaFile_.Sync();
+ _trace();
+ }
if (Changed_) {
NSString *error(nil);
}
}
- WriteSources();
+ CydiaWriteSources();
}
// Navigation controller for the queuing badge.
[database_ yieldToSelector:@selector(reloadDataWithInvocation:) withObject:invocation];
- if (hud != nil)
- [self removeProgressHUD:hud];
-
size_t changes(0);
[essential_ removeAllObjects];
[self _updateData];
- [self refreshIfPossible];
+ if (hud != nil)
+ [self removeProgressHUD:hud];
} }
- (void) updateData {
- (void) reloadData {
[self reloadDataWithInvocation:nil];
+ if ([database_ progressDelegate] == nil)
+ [self _loaded];
}
- (void) syncData {
}
- (void) addSource:(NSDictionary *) source {
- AddSource(source);
+ CydiaAddSource(source);
}
- (void) addSource:(NSString *)href withDistribution:(NSString *)distribution andSections:(NSArray *)sections {
- AddSource(href, distribution, sections);
+ CydiaAddSource(href, distribution, sections);
}
- (void) addTrivialSource:(NSString *)href {
- AddSource(href, @"./");
+ CydiaAddSource(href, @"./");
}
- (void) updateValues {
++locked_;
[self detachNewProgressSelector:@selector(perform_) toTarget:self forController:navigation title:@"RUNNING"];
--locked_;
+ [self refreshIfPossible];
}
- (void) showSettings {
}
- (UIProgressHUD *) addProgressHUD {
- UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window_] autorelease]);
+ UIProgressHUD *hud([[[UIProgressHUD alloc] init] autorelease]);
[hud setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[window_ setUserInteractionEnabled:NO];
if (UIViewController *modal = [target modalViewController])
target = modal;
- UIView *view([target view]);
- [view addSubview:hud];
-
- [hud show:YES];
+ [hud showInView:[target view]];
++locked_;
return hud;
- (void) removeProgressHUD:(UIProgressHUD *)hud {
--locked_;
- [hud show:NO];
+ [hud hide];
[hud removeFromSuperview];
[window_ setUserInteractionEnabled:YES];
}
if ([[url absoluteString] length] <= [scheme length] + 3)
return nil;
NSString *path([[url absoluteString] substringFromIndex:[scheme length] + 3]);
- NSArray *components([path pathComponents]);
+ 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;
controller = [[[ManageController alloc] init] autorelease];
}
+ if ([base isEqualToString:@"storage"]) {
+ controller = [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/storage/", UI_]]] autorelease];
+ }
+
if ([base isEqualToString:@"sources"]) {
controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease];
}
}
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"]) {
controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease];
[(SourcesController *)controller showAddSourcePrompt];
} else {
- Source *source = [database_ sourceWithKey:argument];
+ Source *source = [database_ sourceWithKey:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease];
}
}
- (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;
}
[self removeStashController];
- if (ExecFork() == 0) {
+ pid_t pid(ExecFork());
+ if (pid == 0) {
execlp("launchctl", "launchctl", "stop", "com.apple.SpringBoard", NULL);
perror("launchctl stop");
+ exit(0);
}
+
+ ReapZombie(pid);
}
- (void) setupViewControllers {
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]);
[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];
+
_trace();
if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
[self setApplicationSupportsShakeToEdit:NO];
broken_ = [NSMutableArray arrayWithCapacity:4];
// XXX: I really need this thing... like, seriously... I'm sorry
- [[[CydiaWebViewController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData];
+ [[[AppCacheController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData];
window_ = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[window_ orderFront:self];
[window_ setUserInteractionEnabled:NO];
}
- [self reloadData];
+ [self reloadDataWithInvocation:nil];
+ [self refreshIfPossible];
PrintTimes();
[self disemulate];
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;
}
NSURL *url([copy URL]);
- NSString *href([url absoluteString]);
NSString *host([url host]);
NSString *scheme([[url scheme] lowercaseString]);
if (NSString *control = [copy valueForHTTPHeaderField:@"Cache-Control"])
if ([control isEqualToString:@"max-age=0"])
- if ([CachedURLs_ containsObject:href]) {
+ if ([CachedURLs_ containsObject:url]) {
#if !ForRelease
- NSLog(@"~~~: %@", href);
+ NSLog(@"~~~: %@", url);
#endif
[copy setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
NSLog(@"unknown UIUserInterfaceIdiom!");
}
+ Pcre pattern("^([0-9]+\\.[0-9]+)");
+
+ if (pattern([device systemVersion]))
+ Firmware_ = pattern[1];
+ if (pattern(Cydia_))
+ Major_ = pattern[1];
+
SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4];
HostConfig_ = [[[NSObject alloc] init] autorelease];
CachedURLs_ = [NSMutableSet setWithCapacity:32];
}
- UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]);
+ NSString *ui(@"ui/ios");
+ if (Idiom_ != nil)
+ ui = [ui stringByAppendingString:[NSString stringWithFormat:@"~%@", Idiom_]];
+ ui = [ui stringByAppendingString:[NSString stringWithFormat:@"/%@", Major_]];
+ UI_ = CydiaURL(ui);
PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
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)
- PLMN_ = [NSString stringWithFormat:@"%@%@", mcc, mnc];
-
- 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) {
- AddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
- AddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
- AddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
- AddSource(@"http://repo666.ultrasn0w.com/", @"./");
+ CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+ CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+ CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+ CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
Version_ = [NSNumber numberWithUnsignedInt:1];
[Metadata_ setObject:Version_ forKey:@"Version"];
+ [Metadata_ removeObjectForKey:@"LastUpdate"];
+
Changed_ = true;
}
/* }}} */
- WriteSources();
+ CydiaWriteSources();
_trace();
MetaFile_.Open("/var/lib/cydia/metadata.cb0");
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"));