#include <Cytore.hpp>
+#include <CydiaSubstrate/CydiaSubstrate.h>
#include "Menes/Menes.h"
#include "CyteKit/PerlCompatibleRegEx.hpp"
+#include "CyteKit/TableViewCell.h"
#include "CyteKit/WebScriptObject-Cyte.h"
#include "CyteKit/WebViewController.h"
#include "CyteKit/stringWithUTF8Bytes.h"
+#include "Cydia/MIMEAddress.h"
+#include "Cydia/LoadingViewController.h"
#include "Cydia/ProgressEvent.h"
#include "SDURLCache/SDURLCache.h"
-
-#include <CydiaSubstrate/CydiaSubstrate.h>
/* }}} */
/* Profiler {{{ */
#define _end }
/* }}} */
-#define _pooled _H<NSAutoreleasePool> _pool([[NSAutoreleasePool alloc] init], true);
-
-#define CYPoolStart() \
- NSAutoreleasePool *_pool([[NSAutoreleasePool alloc] init]); \
- do
-#define CYPoolEnd() \
- while (false); \
- [_pool release];
-
+#include "Version.h"
#define Cydia_ CYDIA_VERSION
#define lprintf(args...) fprintf(stderr, args)
};
// }}}
+static NSString *Colon_;
+NSString *Elision_;
+static NSString *Error_;
+static NSString *Warning_;
+
static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
static _finline NSString *CydiaURL(NSString *path) {
notify_post("com.saurik.Cydia.status");
}
+static CGFloat CYStatusBarHeight(UIInterfaceOrientation orientation) {
+ CGSize size([[UIApplication sharedApplication] statusBarFrame].size);
+ return UIInterfaceOrientationIsPortrait(orientation) ? size.height : size.width;
+}
+
/* NSForcedOrderingSearch doesn't work on the iPhone */
static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch;
static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch;
static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive | kCFCompareNonliteral | kCFCompareLocalized | kCFCompareNumerically | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
-/* Radix Sort {{{ */
-typedef uint32_t (*SKRadixFunction)(id, void *);
-
-@interface NSMutableArray (Radix)
-- (void) radixSortUsingFunction:(SKRadixFunction)function withContext:(void *)argument;
-@end
-
-struct RadixItem_ {
- size_t index;
- uint32_t key;
-};
-
-@implementation NSMutableArray (Radix)
-
-- (void) radixSortUsingFunction:(SKRadixFunction)function withContext:(void *)argument {
- size_t count([self count]);
- struct RadixItem_ *swap(new RadixItem_[count * 2]);
-
- for (size_t i(0); i != count; ++i) {
- RadixItem_ &item(swap[i]);
- item.index = i;
-
- id object([self objectAtIndex:i]);
- item.key = function(object, argument);
- }
-
- struct RadixItem_ *lhs(swap), *rhs(swap + count);
-
- static const size_t width = 32;
- static const size_t bits = 11;
- static const size_t slots = 1 << bits;
- static const size_t passes = (width + (bits - 1)) / bits;
-
- size_t *hist(new size_t[slots]);
-
- for (size_t pass(0); pass != passes; ++pass) {
- memset(hist, 0, sizeof(size_t) * slots);
-
- for (size_t i(0); i != count; ++i) {
- uint32_t key(lhs[i].key);
- key >>= pass * bits;
- key &= _not(uint32_t) >> width - bits;
- ++hist[key];
- }
-
- size_t offset(0);
- for (size_t i(0); i != slots; ++i) {
- size_t local(offset);
- offset += hist[i];
- hist[i] = local;
- }
-
- for (size_t i(0); i != count; ++i) {
- uint32_t key(lhs[i].key);
- key >>= pass * bits;
- key &= _not(uint32_t) >> width - bits;
- rhs[hist[key]++] = lhs[i];
- }
-
- RadixItem_ *tmp(lhs);
- lhs = rhs;
- rhs = tmp;
- }
-
- delete [] hist;
-
- const void **values(new const void *[count]);
- for (size_t i(0); i != count; ++i)
- values[i] = [self objectAtIndex:lhs[i].index];
- CFArrayReplaceValues((CFMutableArrayRef) self, CFRangeMake(0, count), values, count);
- delete [] values;
-
- delete [] swap;
-}
-
-@end
-/* }}} */
/* Insertion Sort {{{ */
CFIndex SKBSearch_(const void *element, CFIndex elementSize, const void *list, CFIndex count, CFComparatorFunction comparator, void *context) {
};
/* }}} */
-/* Mime Addresses {{{ */
-@interface Address : NSObject {
- _H<NSString> name_;
- _H<NSString> address_;
-}
-
-- (NSString *) name;
-- (NSString *) address;
-
-- (void) setAddress:(NSString *)address;
-
-+ (Address *) addressWithString:(NSString *)string;
-- (Address *) initWithString:(NSString *)string;
-
-@end
-
-@implementation Address
-
-- (NSString *) name {
- return name_;
-}
-
-- (NSString *) address {
- return address_;
-}
-
-- (void) setAddress:(NSString *)address {
- address_ = address;
-}
-
-+ (Address *) addressWithString:(NSString *)string {
- return [[[Address alloc] initWithString:string] autorelease];
-}
-
-+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:
- @"address",
- @"name",
- nil];
-}
-
-- (NSArray *) attributeKeys {
- return [[self class] _attributeKeys];
-}
-
-+ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
- return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
-}
-
-- (Address *) initWithString:(NSString *)string {
- if ((self = [super init]) != nil) {
- const char *data = [string UTF8String];
- size_t size = [string length];
-
- static Pcre address_r("^\"?(.*)\"? <([^>]*)>$");
-
- if (address_r(data, size)) {
- name_ = address_r[1];
- address_ = address_r[2];
- } else {
- name_ = string;
- address_ = nil;
- }
- } return self;
-}
-
-@end
-/* }}} */
/* CoreGraphics Primitives {{{ */
class CYColor {
private:
static _transient NSMutableDictionary *Settings_;
static _transient NSString *Role_;
static _transient NSMutableDictionary *Packages_;
+static _transient NSMutableDictionary *Values_;
static _transient NSMutableDictionary *Sections_;
static _transient NSMutableDictionary *Sources_;
+static _transient NSNumber *Version_;
+static _transient _H<NSString> CydiaSource_;
static bool Changed_;
static time_t now_;
static _H<NSMutableDictionary> SessionData_;
static _H<NSObject> HostConfig_;
static _H<NSMutableSet> BridgedHosts_;
+static _H<NSMutableSet> TokenHosts_;
+static _H<NSMutableSet> InsecureHosts_;
static _H<NSMutableSet> PipelinedHosts_;
+static _H<NSMutableSet> CachedURLs_;
static NSString *kCydiaProgressEventTypeError = @"Error";
static NSString *kCydiaProgressEventTypeInformation = @"Information";
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-3.7 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;
- (void) clearPackage:(Package *)package;
- (void) loadData;
- (void) updateData;
- (void) syncData;
+- (void) addSource:(NSDictionary *)source;
- (void) addTrivialSource:(NSString *)href;
- (void) showSettings;
- (UIProgressHUD *) addProgressHUD;
}
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) {
CYString uri_;
CYString distribution_;
CYString type_;
+ CYString base_;
CYString version_;
_H<NSString> host_;
- (NSString *) uri;
- (NSString *) distribution;
- (NSString *) type;
+
+- (NSString *) base;
+
- (NSString *) key;
- (NSString *) host;
distribution_.clear();
type_.clear();
+ base_.clear();
+
description_.clear();
label_.clear();
origin_.clear();
authority_ = nil;
}
++ (NSString *) webScriptNameForSelector:(SEL)selector {
+ if (false);
+ else if (selector == @selector(addSection:))
+ return @"addSection";
+ else if (selector == @selector(removeSection:))
+ return @"removeSection";
+ else if (selector == @selector(remove))
+ return @"remove";
+ else
+ return nil;
+}
+
++ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector {
+ return [self webScriptNameForSelector:selector] == nil;
+}
+
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
@"distribution",
@"label",
@"name",
@"origin",
+ @"sections",
@"shortDescription",
@"trusted",
@"type",
debReleaseIndex *dindex(dynamic_cast<debReleaseIndex *>(index));
if (dindex != NULL) {
+ base_.set(pool, dindex->MetaIndexURI(""));
+
FileFd fd;
if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly))
_error->Discard();
host_ = [host_ lowercaseString];
if (host_ != nil)
- // XXX: this is due to a bug in _H<>
- authority_ = (id) host_;
+ authority_ = host_;
else
authority_ = [url path];
}
NSDictionary *lhr = [self record];
NSDictionary *rhr = [source record];
- if (lhr != rhr)
+ if ((lhr == nil) != (rhr == nil))
return lhr == nil ? NSOrderedDescending : NSOrderedAscending;
NSString *lhs = [self name];
return support_.empty() ? nil : [static_cast<id>(support_) stringByReplacingOccurrencesOfString:@"*" withString:package];
}
+- (NSArray *) sections {
+ return record_ == nil ? (id) [NSNull null] : [record_ objectForKey:@"Sections"] ?: [NSArray array];
+}
+
+- (void) _addSection:(NSString *)section {
+ if (record_ == nil)
+ return;
+ else if (NSMutableArray *sections = [record_ objectForKey:@"Sections"]) {
+ if (![sections containsObject:section]) {
+ [sections addObject:section];
+ Changed_ = true;
+ }
+ } else {
+ [record_ setObject:[NSMutableArray arrayWithObject:section] forKey:@"Sections"];
+ Changed_ = true;
+ }
+}
+
+- (bool) addSection:(NSString *)section {
+ if (record_ == nil)
+ return false;
+
+ [self performSelectorOnMainThread:@selector(_addSection:) withObject:section waitUntilDone:NO];
+ return true;
+}
+
+- (void) _removeSection:(NSString *)section {
+ if (record_ == nil)
+ return;
+
+ if (NSMutableArray *sections = [record_ objectForKey:@"Sections"])
+ if ([sections containsObject:section]) {
+ [sections removeObject:section];
+ Changed_ = true;
+ }
+}
+
+- (bool) removeSection:(NSString *)section {
+ if (record_ == nil)
+ return false;
+
+ [self performSelectorOnMainThread:@selector(_removeSection:) withObject:section waitUntilDone:NO];
+ return true;
+}
+
+- (void) _remove {
+ [Sources_ removeObjectForKey:[self key]];
+ Changed_ = true;
+}
+
+- (bool) remove {
+ bool value(record_ != nil);
+ [self performSelectorOnMainThread:@selector(_remove) withObject:nil waitUntilDone:NO];
+ return value;
+}
+
- (NSDictionary *) record {
return record_;
}
return type_;
}
+- (NSString *) base {
+ return base_;
+}
+
- (NSString *) key {
return [NSString stringWithFormat:@"%@:%@:%@", (NSString *) type_, (NSString *) uri_, (NSString *) distribution_];
}
struct ParsedPackage {
CYString tagline_;
+ CYString architecture_;
CYString icon_;
CYString depiction_;
apr_pool_t *pool_;
+ uint32_t rank_;
+
_transient Database *database_;
pkgCache::VerIterator version_;
- (NSString *) uri;
-- (Address *) maintainer;
+- (MIMEAddress *) maintainer;
- (size_t) size;
- (NSString *) longDescription;
- (NSString *) shortDescription;
- (UIImage *) icon;
- (NSString *) homepage;
- (NSString *) depiction;
-- (Address *) author;
+- (MIMEAddress *) author;
- (NSString *) support;
- (Source *) source;
-- (BOOL) matches:(NSString *)text;
+- (uint32_t) rank;
+- (BOOL) matches:(NSArray *)query;
- (bool) hasSupportingRole;
- (BOOL) hasTag:(NSString *)tag;
- (void) install;
- (void) remove;
-- (bool) isUnfilteredAndSearchedForBy:(NSString *)search;
+- (bool) isUnfilteredAndSearchedForBy:(NSArray *)query;
- (bool) isUnfilteredAndSelectedForBy:(NSString *)search;
- (bool) isInstalledAndUnfiltered:(NSNumber *)number;
- (bool) isVisibleInSection:(NSString *)section;
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
@"applications",
+ @"architecture",
@"author",
@"depiction",
@"essential",
return relations;
} }
+- (NSString *) architecture {
+ [self parse];
+@synchronized (database_) {
+ return parsed_->architecture_.empty() ? [NSNull null] : (id) parsed_->architecture_;
+} }
+
- (NSString *) getField:(NSString *)name {
@synchronized (database_) {
if ([database_ era] != era_ || file_.end())
const char *name_;
CYString *value_;
} names[] = {
+ {"architecture", &parsed->architecture_},
{"icon", &parsed->icon_},
{"depiction", &parsed->depiction_},
{"homepage", &parsed->homepage_},
#endif
}
-- (Address *) maintainer {
+- (MIMEAddress *) maintainer {
@synchronized (database_) {
if ([database_ era] != era_ || file_.end())
return nil;
pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
const std::string &maintainer(parser->Maintainer());
- return maintainer.empty() ? nil : [Address addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
+ return maintainer.empty() ? nil : [MIMEAddress addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
} }
- (size_t) size {
} }
- (NSString *) shortDescription {
- return parsed_ == NULL ? nil : static_cast<NSString *>(parsed_->tagline_);
-}
+ if (parsed_ != NULL)
+ return static_cast<NSString *>(parsed_->tagline_);
+
+@synchronized (database_) {
+ pkgRecords::Parser &parser([database_ records]->Lookup(file_));
+
+ const char *start, *end;
+ if (!parser.ShortDesc(start, end))
+ return nil;
+
+ if (end - start > 200)
+ end = start + 200;
+
+ /*
+ if (const char *stop = reinterpret_cast<const char *>(memchr(start, '\n', end - start)))
+ end = stop;
+
+ while (end != start && end[-1] == '\r')
+ --end;
+ */
+
+ return [(id) CYStringCreate(start, end - start) autorelease];
+} }
- (unichar) index {
_profile(Package$index)
if (parsed_ != NULL)
if (NSString *href = parsed_->icon_)
if ([href hasPrefix:@"file:///"])
- // XXX: correct escaping
- icon = [UIImage imageAtPath:[href substringFromIndex:7]];
+ icon = [UIImage imageAtPath:[[href substringFromIndex:7] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if (icon == nil) if (section != nil)
- icon = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]];
+ icon = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, [section stringByReplacingOccurrencesOfString:@" " withString:@"_"]]];
if (icon == nil) if (Source *source = [self source]) if (NSString *dicon = [source defaultIcon])
if ([dicon hasPrefix:@"file:///"])
- // XXX: correct escaping
- icon = [UIImage imageAtPath:[dicon substringFromIndex:7]];
+ icon = [UIImage imageAtPath:[[dicon substringFromIndex:7] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if (icon == nil)
icon = [UIImage applicationImageNamed:@"unknown.png"];
return icon;
return parsed_ != NULL && !parsed_->depiction_.empty() ? parsed_->depiction_ : [[self source] depictionForPackage:id_];
}
-- (Address *) sponsor {
- return parsed_ == NULL || parsed_->sponsor_.empty() ? nil : [Address addressWithString:parsed_->sponsor_];
+- (MIMEAddress *) sponsor {
+ return parsed_ == NULL || parsed_->sponsor_.empty() ? nil : [MIMEAddress addressWithString:parsed_->sponsor_];
}
-- (Address *) author {
- return parsed_ == NULL || parsed_->author_.empty() ? nil : [Address addressWithString:parsed_->author_];
+- (MIMEAddress *) author {
+ return parsed_ == NULL || parsed_->author_.empty() ? nil : [MIMEAddress addressWithString:parsed_->author_];
}
- (NSString *) support {
return source_ == (Source *) [NSNull null] ? nil : source_;
}
-- (BOOL) matches:(NSString *)text {
- if (text == nil)
+- (uint32_t) rank {
+ return rank_;
+}
+
+- (BOOL) matches:(NSArray *)query {
+ if (query == nil || [query count] == 0)
return NO;
+ rank_ = 0;
+
+ NSString *string;
NSRange range;
+ NSUInteger length;
- range = [[self id] rangeOfString:text options:MatchCompareOptions_];
- if (range.location != NSNotFound)
- return YES;
+ string = [self name];
+ length = [string length];
- range = [[self name] rangeOfString:text options:MatchCompareOptions_];
- if (range.location != NSNotFound)
- return YES;
+ for (NSString *term in query) {
+ range = [string rangeOfString:term options:MatchCompareOptions_];
+ if (range.location != NSNotFound)
+ rank_ -= 6 * 1000000 / length;
+ }
- [self parse];
+ if (rank_ == 0) {
+ string = [self id];
+ length = [string length];
+
+ for (NSString *term in query) {
+ range = [string rangeOfString:term options:MatchCompareOptions_];
+ if (range.location != NSNotFound)
+ rank_ -= 6 * 1000000 / length;
+ }
+ }
- NSString *description([self shortDescription]);
- NSUInteger length([description length]);
+ string = [self shortDescription];
+ length = [string length];
+ NSUInteger stop(std::min<NSUInteger>(length, 200));
- range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_ range:NSMakeRange(0, std::min<NSUInteger>(length, 100))];
- if (range.location != NSNotFound)
- return YES;
+ for (NSString *term in query) {
+ range = [string rangeOfString:term options:MatchCompareOptions_ range:NSMakeRange(0, stop)];
+ if (range.location != NSNotFound)
+ rank_ -= 2 * 100000;
+ }
- return NO;
+ return rank_ != 0;
}
- (bool) hasSupportingRole {
cache->MarkDelete(iterator_, true);
} }
-- (bool) isUnfilteredAndSearchedForBy:(NSString *)search {
+- (bool) isUnfilteredAndSearchedForBy:(NSArray *)query {
_profile(Package$isUnfilteredAndSearchedForBy)
bool value(true);
_end
_profile(Package$isUnfilteredAndSearchedForBy$Match)
- value &= [self matches:search];
+ value &= [self matches:query];
_end
return value;
@end
/* }}} */
-static NSString *Colon_;
-static NSString *Elision_;
-static NSString *Error_;
-static NSString *Warning_;
+class CydiaLogCleaner :
+ public pkgArchiveCleaner
+{
+ protected:
+ virtual void Erase(const char *File, std::string Pkg, std::string Ver, struct stat &St) {
+ unlink(File);
+ }
+};
/* Database Implementation {{{ */
@implementation Database
[super dealloc];
}
-- (void) _readCydia:(NSNumber *)fd { _pooled
+- (void) _readCydia:(NSNumber *)fd {
__gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
std::istream is(&ib);
std::string line;
static Pcre finish_r("^finish:([^:]*)$");
while (std::getline(is, line)) {
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
const char *data(line.c_str());
size_t size = line.size();
lprintf("C:%s\n", data);
if (index != INT_MAX && index > Finish_)
Finish_ = index;
}
+
+ [pool release];
}
_assume(false);
}
-- (void) _readStatus:(NSNumber *)fd { _pooled
+- (void) _readStatus:(NSNumber *)fd {
__gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
std::istream is(&ib);
std::string line;
static Pcre pmstatus_r("^([^:]*):([^:]*):([^:]*):(.*)$");
while (std::getline(is, line)) {
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
const char *data(line.c_str());
size_t size(line.size());
lprintf("S:%s\n", data);
lprintf("E:unknown pmstatus\n");
} else
lprintf("E:unknown status\n");
+
+ [pool release];
}
_assume(false);
}
-- (void) _readOutput:(NSNumber *)fd { _pooled
+- (void) _readOutput:(NSNumber *)fd {
__gnu_cxx::stdio_filebuf<char> ib([fd intValue], std::ios::in);
std::istream is(&ib);
std::string line;
while (std::getline(is, line)) {
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
lprintf("O:%s\n", line.c_str());
CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:line.c_str()] ofType:kCydiaProgressEventTypeInformation]);
[progress_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
+
+ [pool release];
}
_assume(false);
}
- (Package *) packageWithName:(NSString *)name {
+ if (name == nil)
+ return nil;
@synchronized (self) {
if (static_cast<pkgDepCache *>(cache_) == NULL)
return nil;
return [self popErrorWithTitle:title] || !success;
}
-- (void) reloadDataWithInvocation:(NSInvocation *)invocation { CYPoolStart() {
+- (void) reloadDataWithInvocation:(NSInvocation *)invocation {
@synchronized (self) {
++era_;
packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()];
_trace();*/
- [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<SKRadixFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(16)];
- [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<SKRadixFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(4)];
- [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<SKRadixFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(0)];
+ [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(16)];
+ [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(4)];
+ [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(0)];
/*_trace();
PrintTimes();
_trace();
}
-} } CYPoolEnd() _trace(); }
+} }
- (void) clear {
@synchronized (self) {
pkgAcquire fetcher;
fetcher.Clean(_config->FindDir("Dir::Cache::Archives"));
- class LogCleaner :
- public pkgArchiveCleaner
- {
- protected:
- virtual void Erase(const char *File, std::string Pkg, std::string Ver, struct stat &St) {
- unlink(File);
- }
- } cleaner;
-
+ CydiaLogCleaner cleaner;
if ([self popErrorWithTitle:title forOperation:cleaner.Go(_config->FindDir("Dir::Cache::Archives") + "partial/", cache_)])
return false;
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
@"bbsnum",
+ @"cydiaSource",
@"device",
@"ecid",
@"firmware",
if (false);
else if (selector == @selector(addBridgedHost:))
return @"addBridgedHost";
+ else if (selector == @selector(addInsecureHost:))
+ return @"addInsecureHost";
else if (selector == @selector(addInternalRedirect::))
return @"addInternalRedirect";
else if (selector == @selector(addPipelinedHost:scheme:))
return @"addPipelinedHost";
+ else if (selector == @selector(addSource:::))
+ return @"addSource";
+ else if (selector == @selector(addTokenHost:))
+ return @"addTokenHost";
else if (selector == @selector(addTrivialSource:))
return @"addTrivialSource";
else if (selector == @selector(close))
return @"getPreferredLanguages";
else if (selector == @selector(getPackageById:))
return @"getPackageById";
+ else if (selector == @selector(getMetadataKeys))
+ return @"getMetadataKeys";
+ else if (selector == @selector(getMetadataValue:))
+ return @"getMetadataValue";
else if (selector == @selector(getSessionValue:))
return @"getSessionValue";
else if (selector == @selector(installPackages:))
return @"refreshSources";
else if (selector == @selector(removeButton))
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(substitutePackageNames:))
return @"statfs";
else if (selector == @selector(supports:))
return @"supports";
+ else if (selector == @selector(unload))
+ return @"unload";
else
return nil;
}
return [feature isEqualToString:@"window.open"];
}
+- (void) unload {
+ [delegate_ performSelectorOnMainThread:@selector(unloadData) withObject:nil 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"];
+ }
+
+ Changed_ = true;
+}
+
+- (void) setCydiaSource:(NSString *)source {
+ [self performSelectorOnMainThread:@selector(_setCydiaSource:) withObject:source 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) setMetadataValue:(NSString *)key :(NSString *)value {
+@synchronized (Values_) {
+ if (value == nil || value == (id) [WebUndefined undefined] || value == (id) [NSNull null])
+ [Values_ removeObjectForKey:key];
+ else
+ [Values_ setObject:value forKey:key];
+
+ [delegate_ performSelectorOnMainThread:@selector(updateValues) withObject:nil waitUntilDone:YES];
+} }
+
- (id) getSessionValue:(NSString *)key {
@synchronized (SessionData_) {
return [SessionData_ objectForKey:key];
[BridgedHosts_ addObject:host];
} }
+- (void) addInsecureHost:(NSString *)host {
+@synchronized (HostConfig_) {
+ [InsecureHosts_ addObject:host];
+} }
+
+- (void) addTokenHost:(NSString *)host {
+@synchronized (HostConfig_) {
+ [TokenHosts_ addObject:host];
+} }
+
- (void) addPipelinedHost:(NSString *)host scheme:(NSString *)scheme {
@synchronized (HostConfig_) {
if (scheme != (id) [WebUndefined undefined])
[indirect_ performSelectorOnMainThread:@selector(popViewControllerWithNumber:) withObject:value waitUntilDone:NO];
}
+- (void) addSource:(NSString *)href :(NSString *)distribution :(WebScriptObject *)sections {
+ NSMutableArray *array([NSMutableArray arrayWithCapacity:[sections count]]);
+
+ for (NSString *section in sections)
+ [array addObject:section];
+
+ [delegate_ performSelectorOnMainThread:@selector(addSource:) withObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
+ @"deb", @"Type",
+ href, @"URI",
+ distribution, @"Distribution",
+ array, @"Sections",
+ nil] waitUntilDone:NO];
+}
+
- (void) addTrivialSource:(NSString *)href {
[delegate_ performSelectorOnMainThread:@selector(addTrivialSource:) withObject:href waitUntilDone:NO];
}
[delegate_ performSelectorOnMainThread:@selector(syncData) withObject:nil waitUntilDone:NO];
}
+- (void) saveConfig {
+ [delegate_ performSelectorOnMainThread:@selector(_saveConfig) withObject:nil waitUntilDone:NO];
+}
+
- (NSArray *) getAllSources {
return [[Database sharedInstance] sources];
}
@end
/* }}} */
-/* @ Loading... Indicator {{{ */
-@interface CYLoadingIndicator : UIView {
- _H<UIActivityIndicatorView> spinner_;
- _H<UILabel> label_;
- _H<UIView> container_;
-}
-
-@property (readonly, nonatomic) UILabel *label;
-@property (readonly, nonatomic) UIActivityIndicatorView *activityIndicatorView;
-
+@interface NSURL (CydiaSecure)
@end
-@implementation CYLoadingIndicator
+@implementation NSURL (CydiaSecure)
-- (id) initWithFrame:(CGRect)frame {
- if ((self = [super initWithFrame:frame]) != nil) {
- container_ = [[[UIView alloc] init] autorelease];
- [container_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin];
-
- spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
- [spinner_ startAnimating];
- [container_ addSubview:spinner_];
-
- label_ = [[[UILabel alloc] init] autorelease];
- [label_ setFont:[UIFont boldSystemFontOfSize:15.0f]];
- [label_ setBackgroundColor:[UIColor clearColor]];
- [label_ setTextColor:[UIColor blackColor]];
- [label_ setShadowColor:[UIColor whiteColor]];
- [label_ setShadowOffset:CGSizeMake(0, 1)];
- [label_ setText:[NSString stringWithFormat:Elision_, UCLocalize("LOADING"), nil]];
- [container_ addSubview:label_];
-
- CGSize viewsize = frame.size;
- CGSize spinnersize = [spinner_ bounds].size;
- CGSize textsize = [[label_ text] sizeWithFont:[label_ font]];
- float bothwidth = spinnersize.width + textsize.width + 5.0f;
-
- CGRect containrect = {
- CGPointMake(floorf((viewsize.width / 2) - (bothwidth / 2)), floorf((viewsize.height / 2) - (spinnersize.height / 2))),
- CGSizeMake(bothwidth, spinnersize.height)
- };
- CGRect textrect = {
- CGPointMake(spinnersize.width + 5.0f, floorf((spinnersize.height / 2) - (textsize.height / 2))),
- textsize
- };
- CGRect spinrect = {
- CGPointZero,
- spinnersize
- };
-
- [container_ setFrame:containrect];
- [spinner_ setFrame:spinrect];
- [label_ setFrame:textrect];
- [self addSubview:container_];
- } return self;
-}
+- (bool) isCydiaSecure {
+ if ([[[self scheme] lowercaseString] isEqualToString:@"https"])
+ return true;
-- (UILabel *) label {
- return label_;
-}
-
-- (UIActivityIndicatorView *) activityIndicatorView {
- return spinner_;
-}
-
-@end
-/* }}} */
-/* Emulated Loading Controller {{{ */
-@interface CYEmulatedLoadingController : CyteViewController {
- _transient Database *database_;
- _H<CYLoadingIndicator> indicator_;
- _H<UITabBar> tabbar_;
- _H<UINavigationBar> navbar_;
-}
-
-@end
-
-@implementation CYEmulatedLoadingController
-
-- (id) initWithDatabase:(Database *)database {
- if ((self = [super init]) != nil) {
- database_ = database;
- } return self;
-}
-
-- (void) loadView {
- [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
- UITableView *table([[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease]);
- [table setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
- [[self view] addSubview:table];
-
- indicator_ = [[[CYLoadingIndicator alloc] initWithFrame:[[self view] bounds]] autorelease];
- [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
- [[self view] addSubview:indicator_];
-
- tabbar_ = [[[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 0, 49.0f)] autorelease];
- [tabbar_ setFrame:CGRectMake(0.0f, [[self view] bounds].size.height - [tabbar_ bounds].size.height, [[self view] bounds].size.width, [tabbar_ bounds].size.height)];
- [tabbar_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth];
- [[self view] addSubview:tabbar_];
-
- navbar_ = [[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 0, 44.0f)] autorelease];
- [navbar_ setFrame:CGRectMake(0.0f, 0.0f, [[self view] bounds].size.width, [navbar_ bounds].size.height)];
- [navbar_ setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth];
- [[self view] addSubview:navbar_];
-}
+ @synchronized (HostConfig_) {
+ if ([InsecureHosts_ containsObject:[self host]])
+ return true;
+ }
-- (void) releaseSubviews {
- indicator_ = nil;
- tabbar_ = nil;
- navbar_ = nil;
+ return false;
}
@end
-/* }}} */
/* Cydia Browser Controller {{{ */
@implementation CydiaWebViewController
[window setValue:cydia_ forKey:@"cydia"];
}
+- (void) _setupMail:(MFMailComposeViewController *)controller {
+ [controller addAttachmentData:[NSData dataWithContentsOfFile:@"/tmp/cydia.log"] mimeType:@"text/plain" fileName:@"cydia.log"];
+
+ system("/usr/bin/dpkg -l >/tmp/dpkgl.log");
+ [controller addAttachmentData:[NSData dataWithContentsOfFile:@"/tmp/dpkgl.log"] mimeType:@"text/plain" fileName:@"dpkgl.log"];
+}
+
- (NSURL *) URLWithURL:(NSURL *)url {
return [Diversion divertURL:url];
}
- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+ NSURL *url([request URL]);
+ NSString *host([url host]);
+
NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]);
- if (System_ != NULL)
+ if (System_ != NULL && [copy valueForHTTPHeaderField:@"X-System"] == nil)
[copy setValue:System_ forHTTPHeaderField:@"X-System"];
- if (Machine_ != NULL)
+ if (Machine_ != NULL && [copy valueForHTTPHeaderField:@"X-Machine"] == nil)
[copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
- if (Token_ != nil)
- [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+
+ bool token;
+ @synchronized (HostConfig_) {
+ token = [TokenHosts_ containsObject:host] || [BridgedHosts_ containsObject:host];
+ }
+
+ if ([url isCydiaSecure] && token) {
+ if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil)
+ [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+ }
return copy;
}
[cydia_ setDelegate:delegate];
}
+- (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;
+}
+
- (id) init {
if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) {
cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
+ } return self;
+}
- WebView *webview([[webview_ _documentView] webView]);
+@end
- NSString *application([NSString stringWithFormat:@"Cydia/%@", @ Cydia_]);
+@interface AppCacheController : CydiaWebViewController {
+}
- 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];
+@end
- [webview setApplicationNameForUserAgent:application];
- } return self;
+@implementation AppCacheController
+
+- (void) didReceiveMemoryWarning {
}
@end
}
- (void) _doContinue {
- [self dismissModalViewControllerAnimated:YES];
[delegate_ cancelAndClear:NO];
+ [self dismissModalViewControllerAnimated:YES];
}
- (id) invokeDefaultMethodWithArguments:(NSArray *)args {
ProgressDelegate
> {
_transient Database *database_;
- _H<CydiaProgressData> progress_;
+ _H<CydiaProgressData, 1> progress_;
unsigned cancel_;
}
- (void) dealloc {
[database_ setProgressDelegate:nil];
- [progress_ setDelegate:nil];
[super dealloc];
}
- (void) close {
UpdateExternalStatus(0);
+ if (Finish_ > 1)
+ [delegate_ saveState];
+
switch (Finish_) {
case 0:
+ [delegate_ returnToCydia];
break;
case 1:
@end
/* }}} */
-/* Cell Content View {{{ */
-@protocol ContentDelegate
-- (void) drawContentRect:(CGRect)rect;
-@end
-
-@interface ContentView : UIView {
- _transient id<ContentDelegate> delegate_;
-}
-
-@end
-
-@implementation ContentView
-
-- (id) initWithFrame:(CGRect)frame {
- if ((self = [super initWithFrame:frame]) != nil) {
- [self setNeedsDisplayOnBoundsChange:YES];
- } return self;
-}
-
-- (void) setDelegate:(id<ContentDelegate>)delegate {
- delegate_ = delegate;
-}
-
-- (void) drawRect:(CGRect)rect {
- [super drawRect:rect];
- [delegate_ drawContentRect:rect];
-}
-
-@end
-/* }}} */
-/* Cydia TableView Cell {{{ */
-@interface CYTableViewCell : UITableViewCell {
- _H<ContentView> content_;
- bool highlighted_;
-}
-
-@end
-
-@implementation CYTableViewCell
-
-- (void) _updateHighlightColorsForView:(UIView *)view highlighted:(BOOL)highlighted {
- //NSLog(@"_updateHighlightColorsForView:%@ highlighted:%s [content_=%@]", view, highlighted ? "YES" : "NO", content_);
-
- if (view == (UIView *) content_) {
- //NSLog(@"_updateHighlightColorsForView:content_ highlighted:%s", highlighted ? "YES" : "NO", content_);
- highlighted_ = highlighted;
- }
-
- [super _updateHighlightColorsForView:view highlighted:highlighted];
-}
-
-- (void) setSelected:(BOOL)selected animated:(BOOL)animated {
- //NSLog(@"setSelected:%s animated:%s", selected ? "YES" : "NO", animated ? "YES" : "NO");
- highlighted_ = selected;
-
- [super setSelected:selected animated:animated];
- [content_ setNeedsDisplay];
-}
-
-@end
-/* }}} */
-
/* Package Cell {{{ */
-@interface PackageCell : CYTableViewCell <
- ContentDelegate
+@interface PackageCell : CyteTableViewCell <
+ CyteTableViewCellDelegate
> {
_H<UIImage> icon_;
_H<NSString> name_;
bool commercial_;
_H<NSString> source_;
_H<UIImage> badge_;
- _H<Package> package_;
_H<UIImage> placard_;
bool summarized_;
}
UIView *content([self contentView]);
CGRect bounds([content bounds]);
- content_ = [[[ContentView alloc] initWithFrame:bounds] autorelease];
+ content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease];
[content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[content addSubview:content_];
source_ = nil;
badge_ = nil;
placard_ = nil;
- package_ = 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];
- name_ = [package name];
+ if (NSString *name = [package name])
+ name_ = [NSString stringWithString:name];
- if (IsWildcat_)
- description_ = [package longDescription];
- if (description_ == nil)
- description_ = [package shortDescription];
+ NSString *description(nil);
- commercial_ = [package isCommercial];
+ if (description == nil && IsWildcat_)
+ description = [package longDescription];
+ if (description == nil)
+ description = [package shortDescription];
- package_ = package;
+ if (description != nil)
+ description_ = [NSString stringWithString:description];
- NSString *label = nil;
- bool trusted = false;
+ commercial_ = [package isCommercial];
- 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 *label = nil;
+ bool trusted = false;
- NSString *from(label);
+ 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 *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 *from(label);
- source_ = [NSString stringWithFormat:UCLocalize("FROM"), from];
+ 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];
+ }
- if (NSString *purpose = [package primaryPurpose])
- badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]];
+ source_ = [NSString stringWithFormat:UCLocalize("FROM"), from];
- UIColor *color;
- NSString *placard;
+ if (NSString *purpose = [package primaryPurpose])
+ badge_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/Purposes/%@.png", App_, purpose]];
- if (NSString *mode = [package_ mode]) {
- if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) {
- color = RemovingColor_;
- //placard = @"removing";
- } else {
- color = InstallingColor_;
- //placard = @"installing";
- }
+ UIColor *color;
+ NSString *placard;
- // XXX: the removing/installing placards are not @2x
- placard = nil;
- } else {
- color = [UIColor whiteColor];
+ if (NSString *mode = [package mode]) {
+ if ([mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"]) {
+ color = RemovingColor_;
+ //placard = @"removing";
+ } else {
+ color = InstallingColor_;
+ //placard = @"installing";
+ }
- if ([package installed] != nil)
- placard = @"installed";
- else
+ // 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];
@end
/* }}} */
/* Section Cell {{{ */
-@interface SectionCell : CYTableViewCell <
- ContentDelegate
+@interface SectionCell : CyteTableViewCell <
+ CyteTableViewCellDelegate
> {
_H<NSString> basic_;
_H<NSString> section_;
UIView *content([self contentView]);
CGRect bounds([content bounds]);
- content_ = [[[ContentView alloc] initWithFrame:bounds] autorelease];
+ content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease];
[content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[content addSubview:content_];
[content_ setBackgroundColor:[UIColor whiteColor]];
_H<Package> package_;
_H<NSString> name_;
_H<NSMutableArray> files_;
- _H<UITableView> list_;
+ _H<UITableView, 2> list_;
}
- (id) initWithDatabase:(Database *)database;
@implementation FileTable
-- (void) dealloc {
- [(UITableView *) list_ setDataSource:nil];
- [list_ setDelegate:nil];
- [super dealloc];
-}
-
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return files_ == nil ? 0 : [files_ count];
}
- (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;
}
> {
_transient Database *database_;
unsigned era_;
- _H<NSMutableArray> packages_;
+ _H<NSArray> packages_;
_H<NSMutableArray> sections_;
- _H<UITableView> list_;
+ _H<UITableView, 2> list_;
_H<NSMutableArray> index_;
_H<NSMutableDictionary> indices_;
_H<NSString> title_;
+ unsigned reloading_;
}
- (id) initWithDatabase:(Database *)database title:(NSString *)title;
@implementation PackageListController
-- (void) dealloc {
- [list_ setDataSource:nil];
- [list_ setDelegate:nil];
- [super dealloc];
-}
-
- (bool) isSummarized {
return false;
}
+- (bool) showsSections {
+ return true;
+}
+
- (void) deselectWithAnimation:(BOOL)animated {
[list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
}
[self resizeForKeyboardBounds:bounds duration:0];
}
+- (void) getKeyboardCurve:(UIViewAnimationCurve *)curve duration:(NSTimeInterval *)duration forNotification:(NSNotification *)notification {
+ if (&UIKeyboardAnimationCurveUserInfoKey == NULL)
+ *curve = UIViewAnimationCurveEaseInOut;
+ else
+ [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:curve];
+
+ if (&UIKeyboardAnimationDurationUserInfoKey == NULL)
+ *duration = 0.3;
+ else
+ [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:duration];
+}
+
- (void) keyboardWillShow:(NSNotification *)notification {
CGRect bounds;
CGPoint center;
- NSTimeInterval duration;
- UIViewAnimationCurve curve;
[[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&bounds];
[[[notification userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey] getValue:¢er];
- [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve];
- [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&duration];
+
+ NSTimeInterval duration;
+ UIViewAnimationCurve curve;
+ [self getKeyboardCurve:&curve duration:&duration forNotification:notification];
CGRect kbframe = CGRectMake(round(center.x - bounds.size.width / 2.0), round(center.y - bounds.size.height / 2.0), bounds.size.width, bounds.size.height);
UIViewController *base = self;
CGRect viewframe = [[base view] convertRect:[list_ frame] fromView:[list_ superview]];
CGRect intersection = CGRectIntersection(viewframe, kbframe);
+ if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
+ intersection.size.height += CYStatusBarHeight([self interfaceOrientation]);
+
[self resizeForKeyboardBounds:intersection duration:duration curve:curve];
}
- (void) keyboardWillHide:(NSNotification *)notification {
NSTimeInterval duration;
UIViewAnimationCurve curve;
- [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&curve];
- [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&duration];
+ [self getKeyboardCurve:&curve duration:&duration forNotification:notification];
[self resizeForKeyboardBounds:CGRectZero duration:duration curve:curve];
}
PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]);
if (cell == nil)
cell = [[[PackageCell alloc] init] autorelease];
- [cell setPackage:[self packageAtIndexPath:path] asSummary:[self isSummarized]];
+
+ Package *package([database_ packageWithName:[[self packageAtIndexPath:path] id]]);
+ [cell setPackage:package asSummary:[self isSummarized]];
return cell;
}
}
- (NSArray *) sectionIndexTitlesForTableView:(UITableView *)tableView {
- if ([self isSummarized])
+ if (![self showsSections])
return nil;
return index_;
database_ = database;
title_ = [title copy];
[[self navigationItem] setTitle:title_];
+ } return self;
+}
-#if TryIndexedCollation
- if ([[self class] hasIndexedCollation])
- index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles];
- else
-#endif
- index_ = [NSMutableArray arrayWithCapacity:32];
+- (void) loadView {
+ [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+
+ list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
+ [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
+ [[self view] addSubview:list_];
- indices_ = [NSMutableDictionary dictionaryWithCapacity:32];
+ // XXX: is 20 the most optimal number here?
+ [list_ setSectionIndexMinimumDisplayRowCount:20];
- packages_ = [NSMutableArray arrayWithCapacity:16];
- sections_ = [NSMutableArray arrayWithCapacity:16];
+ [(UITableView *) list_ setDataSource:self];
+ [list_ setDelegate:self];
- list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
- [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
- [[self view] addSubview:list_];
+ [self updateHeight];
+}
- // XXX: is 20 the most optimal number here?
- [list_ setSectionIndexMinimumDisplayRowCount:20];
+- (void) releaseSubviews {
+ list_ = nil;
- [(UITableView *) list_ setDataSource:self];
- [list_ setDelegate:self];
+ packages_ = nil;
+ sections_ = nil;
+ index_ = nil;
+ indices_ = nil;
- [self updateHeight];
- } return self;
+ [super releaseSubviews];
}
- (void) setDelegate:(id)delegate {
delegate_ = delegate;
}
-- (bool) hasPackage:(Package *)package {
- return true;
+- (bool) shouldYield {
+ return false;
}
-- (bool) shouldYield {
+- (bool) shouldBlock {
return false;
}
-- (void) _reloadPackages:(NSArray *)packages {
- [packages_ removeAllObjects];
- [sections_ removeAllObjects];
+- (NSMutableArray *) _reloadPackages {
+@synchronized (database_) {
+ era_ = [database_ era];
+ NSArray *packages([database_ packages]);
- _profile(PackageTable$reloadData$Filter)
- for (Package *package in packages)
- if ([self hasPackage:package])
- [packages_ addObject:package];
- _end
-}
+ return [NSMutableArray arrayWithArray:packages];
+} }
- (void) _reloadData {
- era_ = [database_ era];
- NSArray *packages = [database_ packages];
+ if (reloading_ != 0) {
+ reloading_ = 2;
+ return;
+ }
+
+ NSArray *packages;
if ([self shouldYield]) {
- UIProgressHUD *hud([delegate_ addProgressHUD]);
- [hud setText:UCLocalize("LOADING")];
- [self yieldToSelector:@selector(_reloadPackages:) withObject:packages];
- [delegate_ removeProgressHUD:hud];
+ do {
+ UIProgressHUD *hud;
+
+ if (![self shouldBlock])
+ hud = nil;
+ else {
+ hud = [delegate_ addProgressHUD];
+ [hud setText:UCLocalize("LOADING")];
+ }
+
+ reloading_ = 1;
+ packages = [self yieldToSelector:@selector(_reloadPackages)];
+
+ if (hud != nil)
+ [delegate_ removeProgressHUD:hud];
+ } while (reloading_ == 2);
+
+ reloading_ = 0;
} else {
- [self _reloadPackages:packages];
+ packages = [self _reloadPackages];
}
- [indices_ removeAllObjects];
+ packages_ = packages;
+
+ 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 summary([self isSummarized]);
- if (summary) {
+ bool sectioned([self showsSections]);
+ if (!sectioned) {
section = [[[Section alloc] initWithName:nil localize:false] autorelease];
[sections_ addObject:section];
}
index = [package index];
_end
- if (!summary && (section == nil || [section index] != index)) {
+ if (sectioned && (section == nil || [section index] != index)) {
_profile(PackageTable$reloadData$Section$Allocate)
section = [[[Section alloc] initWithIndex:index row:offset] autorelease];
_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 {
}
- (void) setFilter:(SEL)filter {
+@synchronized (self) {
filter_ = filter;
/* XXX: this is an unsafe optimization of doomy hell */
_assert(method != NULL);
imp_ = method_getImplementation(method);
_assert(imp_ != NULL);
-}
+} }
- (void) setObject:(id)object {
+@synchronized (self) {
object_ = object;
-}
+} }
- (void) setObject:(id)object forFilter:(SEL)filter {
+@synchronized (self) {
[self setFilter:filter];
[self setObject:object];
-}
+} }
+
+- (NSMutableArray *) _reloadPackages {
+@synchronized (database_) {
+ era_ = [database_ era];
+ NSArray *packages([database_ packages]);
+
+ NSMutableArray *filtered([NSMutableArray arrayWithCapacity:[packages count]]);
-- (bool) hasPackage:(Package *)package {
- _profile(FilteredPackageTable$hasPackage)
- return [package valid] && (*reinterpret_cast<bool (*)(id, SEL, id)>(imp_))(package, filter_, object_);
+ IMP imp;
+ SEL filter;
+ _H<NSObject> object;
+
+ @synchronized (self) {
+ imp = imp_;
+ filter = filter_;
+ object = object_;
+ }
+
+ _profile(PackageTable$reloadData$Filter)
+ for (Package *package in packages)
+ if ([package valid] && (*reinterpret_cast<bool (*)(id, SEL, id)>(imp))(package, filter, object))
+ [filtered addObject:package];
_end
-}
+
+ return filtered;
+} }
- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object {
if ((self = [super initWithDatabase:database title:title]) != nil) {
return [NSURL URLWithString:@"cydia://home"];
}
+- (void) didReceiveMemoryWarning {
+}
+
- (void) aboutButtonClicked {
UIAlertView *alert([[[UIAlertView alloc] init] autorelease]);
] autorelease];
}
-- (void) unloadData {
- [super unloadData];
- [self reloadData];
-}
-
@end
/* }}} */
/* Manage Controller {{{ */
ProgressDelegate
> {
_transient Database *database_;
- _H<RefreshBar> refreshbar_;
+ _H<RefreshBar, 1> refreshbar_;
bool dropped_;
bool updating_;
}
- (void) unloadData {
- UIViewController *selected([self selectedViewController]);
+ [super unloadData];
+
for (UINavigationController *controller in [self viewControllers])
[controller unloadData];
- [selected reloadData];
+ if (UIViewController *selected = [self selectedViewController])
+ [selected reloadData];
- if (UIViewController *unselected = [self unselectedViewController])
+ if (UIViewController *unselected = [self unselectedViewController]) {
+ [unselected unloadData];
[unselected reloadData];
-
- [super unloadData];
+ }
}
- (void) dealloc {
- [refreshbar_ setDelegate:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
];
}
-- (void) performUpdate { _pooled
+- (void) performUpdate {
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
Status status;
status.setDelegate(self);
[database_ updateWithStatus:status];
withObject:nil
waitUntilDone:NO
];
+
+ [pool release];
}
- (void) stopUpdateWithSelector:(SEL)selector {
updatedelegate_ = delegate;
}
-- (CGFloat) statusBarHeight {
- if (UIInterfaceOrientationIsPortrait([self interfaceOrientation])) {
- return [[UIApplication sharedApplication] statusBarFrame].size.height;
- } else {
- return [[UIApplication sharedApplication] statusBarFrame].size.width;
- }
-}
-
- (UIView *) transitionView {
if ([self respondsToSelector:@selector(_transitionView)])
return [self _transitionView];
CGRect barframe([refreshbar_ frame]);
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
- barframe.origin.y = [self statusBarHeight];
+ barframe.origin.y = CYStatusBarHeight([self interfaceOrientation]);
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 {
if (path == nil)
goto fail;
path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSString *section(Simplify(path));
- UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sections/%@.png", App_, section]]);
+ 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];
_transient Database *database_;
_H<NSMutableArray> sections_;
_H<NSMutableArray> filtered_;
- _H<UITableView> list_;
+ _H<UITableView, 2> list_;
}
- (id) initWithDatabase:(Database *)database;
- (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]);
> {
_transient Database *database_;
unsigned era_;
- CFMutableArrayRef packages_;
+ _H<NSArray> packages_;
_H<NSMutableArray> sections_;
- _H<UITableView> list_;
+ _H<UITableView, 2> list_;
unsigned upgrades_;
}
@implementation ChangesController
-- (void) dealloc {
- CFRelease(packages_);
- [super dealloc];
-}
-
- (NSURL *) navigationURL {
return [NSURL URLWithString:@"cydia://changes"];
}
return [[sections_ objectAtIndex:section] count];
}
-- (Package *) packageAtIndex:(NSUInteger)index {
- return (Package *) CFArrayGetValueAtIndex(packages_, index);
-}
-
- (Package *) packageAtIndexPath:(NSIndexPath *)path {
@synchronized (database_) {
if ([database_ era] != era_)
return nil;
Section *section([sections_ objectAtIndex:sectionIndex]);
NSInteger row([path row]);
- return [[[self packageAtIndex:([section row] + row)] retain] autorelease];
+ return [[[packages_ objectAtIndex:([section row] + row)] retain] autorelease];
} }
- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
PackageCell *cell((PackageCell *) [table dequeueReusableCellWithIdentifier:@"Package"]);
if (cell == nil)
cell = [[[PackageCell alloc] init] autorelease];
- [cell setPackage:[self packageAtIndexPath:path] asSummary:false];
+
+ Package *package([database_ packageWithName:[[self packageAtIndexPath:path] id]]);
+ [cell setPackage:package asSummary:false];
return cell;
}
- (void) upgradeButtonClicked {
[delegate_ distUpgrade];
+ [[self navigationItem] setRightBarButtonItem:nil animated:YES];
}
- (void) loadView {
- (void) releaseSubviews {
list_ = nil;
+
+ packages_ = nil;
+ sections_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database {
if ((self = [super init]) != nil) {
database_ = database;
-
- packages_ = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
- sections_ = [NSMutableArray arrayWithCapacity:16];
} return self;
}
-// this mostly works because reloadData (below) is @synchronized (database_)
-// XXX: that said, I've been running into problems with NSRangeExceptions :(
-- (void) _reloadPackages:(NSArray *)packages {
- CFRelease(packages_);
- packages_ = CFArrayCreateMutable(kCFAllocatorDefault, [packages count], NULL);
+- (NSMutableArray *) _reloadPackages {
+@synchronized (database_) {
+ era_ = [database_ era];
+ NSArray *packages([database_ packages]);
+
+ NSMutableArray *filtered([NSMutableArray arrayWithCapacity:[packages count]]);
_trace();
_profile(ChangesController$_reloadPackages$Filter)
for (Package *package in packages)
if ([package upgradableAndEssential:YES] || [package visible])
- CFArrayAppendValue(packages_, package);
+ CFArrayAppendValue((CFMutableArrayRef) filtered, package);
_end
_trace();
_profile(ChangesController$_reloadPackages$radixSort)
- [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<SKRadixFunction>(&PackageChangesRadix) withContext:NULL];
+ [filtered radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackageChangesRadix) withContext:NULL];
_end
_trace();
-}
+
+ return filtered;
+} }
- (void) _reloadData {
-@synchronized (database_) {
- era_ = [database_ era];
- NSArray *packages = [database_ packages];
+ NSArray *packages;
-#if 1
- UIProgressHUD *hud([delegate_ addProgressHUD]);
- [hud setText:UCLocalize("LOADING")];
- //NSLog(@"HUD:%@::%@", delegate_, hud);
- [self yieldToSelector:@selector(_reloadPackages:) withObject:packages];
- [delegate_ removeProgressHUD:hud];
-#else
- [self _reloadPackages:packages];
-#endif
+ reload:
+ if (true) {
+ UIProgressHUD *hud([delegate_ addProgressHUD]);
+ [hud setText:UCLocalize("LOADING")];
+ //NSLog(@"HUD:%@::%@", delegate_, hud);
+ packages = [self yieldToSelector:@selector(_reloadPackages)];
+ [delegate_ removeProgressHUD:hud];
+ } else {
+ packages = [self _reloadPackages];
+ }
+
+@synchronized (database_) {
+ if (era_ != [database_ era])
+ goto reload;
- [sections_ removeAllObjects];
+ packages_ = packages;
+ sections_ = [NSMutableArray arrayWithCapacity:16];
Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
Section *ignored = nil;
CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle));
- for (size_t offset = 0, count = CFArrayGetCount(packages_); offset != count; ++offset) {
- Package *package = [self packageAtIndex:offset];
+ for (size_t offset = 0, count = [packages_ count]; offset != count; ++offset) {
+ Package *package = [packages_ objectAtIndex:offset];
BOOL uae = [package upgradableAndEssential:YES];
if (unseens) {
Section *last = [sections_ lastObject];
size_t count = [last count];
- CFArrayReplaceValues(packages_, CFRangeMake(CFArrayGetCount(packages_) - count, count), NULL, 0);
+ [packages_ removeObjectsInRange:NSMakeRange([packages_ count] - count, count)];
[sections_ removeLastObject];
}
[list_ reloadData];
- if (upgrades_ > 0)
- [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc]
- initWithTitle:[NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(upgradeButtonClicked)
- ] autorelease]];
+ [[self navigationItem] setRightBarButtonItem:(upgrades_ == 0 ? nil : [[[UIBarButtonItem alloc]
+ initWithTitle:[NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]]
+ style:UIBarButtonItemStylePlain
+ target:self
+ action:@selector(upgradeButtonClicked)
+ ] autorelease]) animated:YES];
- if (![delegate_ updating])
- [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
- initWithTitle:UCLocalize("REFRESH")
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(refreshButtonClicked)
- ] autorelease]];
+ [[self navigationItem] setLeftBarButtonItem:([delegate_ updating] ? nil : [[[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("REFRESH")
+ style:UIBarButtonItemStylePlain
+ target:self
+ action:@selector(refreshButtonClicked)
+ ] autorelease]) animated:YES];
PrintTimes();
} }
@interface SearchController : FilteredPackageListController <
UISearchBarDelegate
> {
- _H<UISearchBar> search_;
+ _H<UISearchBar, 1> search_;
BOOL searchloaded_;
}
@implementation SearchController
-- (void) dealloc {
- [search_ setDelegate:nil];
- [super dealloc];
-}
-
- (NSURL *) navigationURL {
if ([search_ text] == nil || [[search_ text] isEqualToString:@""])
return [NSURL URLWithString:@"cydia://search"];
}
- (void) useSearch {
- [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)];
+ [self setObject:[[search_ text] componentsSeparatedByString:@" "] forFilter:@selector(isUnfilteredAndSearchedForBy:)];
[self clearData];
[self reloadData];
}
}
- (bool) shouldYield {
+ return YES;
+}
+
+- (bool) shouldBlock {
return [self filter] == @selector(isUnfilteredAndSearchedForBy:);
}
return [self filter] == @selector(isUnfilteredAndSelectedForBy:);
}
+- (bool) showsSections {
+ return false;
+}
+
+- (NSMutableArray *) _reloadPackages {
+ NSMutableArray *packages([super _reloadPackages]);
+ if ([self filter] == @selector(isUnfilteredAndSearchedForBy:))
+ [packages radixSortUsingSelector:@selector(rank)];
+ return packages;
+}
+
- (id) initWithDatabase:(Database *)database query:(NSString *)query {
- if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:query])) {
+ if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:[query componentsSeparatedByString:@" "]])) {
search_ = [[[UISearchBar alloc] init] autorelease];
[search_ setDelegate:self];
}
- (void) reloadData {
- [self setObject:[search_ text]];
+ id object([search_ text]);
+ if ([self filter] == @selector(isUnfilteredAndSearchedForBy:))
+ object = [object componentsSeparatedByString:@" "];
+
+ [self setObject:object];
[self resetCursor];
[super reloadData];
_transient Database *database_;
_H<NSString> name_;
_H<Package> package_;
- _H<UITableView> table_;
+ _H<UITableView, 2> table_;
_H<UISwitch> subscribedSwitch_;
_H<UISwitch> ignoredSwitch_;
_H<UITableViewCell> subscribedCell_;
@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 {
table_ = nil;
ignoredSwitch_ = nil;
subscribedSwitch_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database package:(NSString *)package {
@implementation InstalledController
-- (void) dealloc {
- [super dealloc];
-}
-
- (NSURL *) navigationURL {
return [NSURL URLWithString:@"cydia://installed"];
}
/* }}} */
/* Source Cell {{{ */
-@interface SourceCell : CYTableViewCell <
- ContentDelegate
+@interface SourceCell : CyteTableViewCell <
+ CyteTableViewCellDelegate
> {
_H<UIImage> icon_;
_H<NSString> origin_;
@implementation SourceCell
+- (void) _setImage:(UIImage *)image {
+ icon_ = image;
+ [content_ setNeedsDisplay];
+}
+
+- (void) _setSource:(Source *)source {
+ 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];
+ }
+
+ [pool release];
+}
+
- (void) setSource:(Source *)source {
- icon_ = nil;
- if (icon_ == nil)
- icon_ = [UIImage applicationImageNamed:[NSString stringWithFormat:@"Sources/%@.png", [source host]]];
- if (icon_ == nil)
- icon_ = [UIImage applicationImageNamed:@"unknown.png"];
+ icon_ = [UIImage applicationImageNamed:@"unknown.png"];
origin_ = [source name];
label_ = [source uri];
[content_ setNeedsDisplay];
+
+ [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:source];
}
- (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
UIView *content([self contentView]);
CGRect bounds([content bounds]);
- content_ = [[[ContentView alloc] initWithFrame:bounds] autorelease];
+ content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease];
[content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[content_ setBackgroundColor:[UIColor whiteColor]];
[content addSubview:content_];
@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_;
- _H<UITableView> list_;
+ _H<UITableView, 2> list_;
_H<NSMutableArray> sources_;
int offset_;
}
- (NSURLConnection *) _requestHRef:(NSString *)href method:(NSString *)method {
+ NSURL *url([NSURL URLWithString:href]);
+
NSMutableURLRequest *request = [NSMutableURLRequest
- requestWithURL:[NSURL URLWithString:href]
+ requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:120.0
];
if (Machine_ != NULL)
[request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
- if (UniqueID_ != nil)
- [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+
+ if ([url isCydiaSecure]) {
+ if (UniqueID_ != nil)
+ [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+ }
return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
}
- (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;
}
if ([database_ popErrorWithTitle:UCLocalize("SOURCES") forOperation:list.ReadMainList()])
return;
- [sources_ removeAllObjects];
+ sources_ = [NSMutableArray arrayWithCapacity:16];
[sources_ addObjectsFromArray:[database_ sources]];
_trace();
[sources_ sortUsingSelector:@selector(compareByNameAndType:)];
_transient Database *database_;
// XXX: ok, "roledelegate_"?...
_transient id roledelegate_;
- _H<UITableView> table_;
+ _H<UITableView, 2> table_;
_H<UISegmentedControl> segment_;
_H<UIView> container_;
}
table_ = nil;
segment_ = nil;
container_ = nil;
+
+ [super releaseSubviews];
}
- (id) initWithDatabase:(Database *)database delegate:(id)delegate {
[[self view] addSubview:status_];
}
+- (void) releaseSubviews {
+ spinner_ = nil;
+ status_ = nil;
+ caption_ = nil;
+
+ [super releaseSubviews];
+}
+
@end
/* }}} */
#endif
}
+- (void) storeCachedResponse:(NSCachedURLResponse *)cached forRequest:(NSURLRequest *)request {
+ if (NSURLResponse *response = [cached response])
+ if (NSString *mime = [response MIMEType])
+ if ([mime isEqualToString:@"text/cache-manifest"]) {
+ NSURL *url([response URL]);
+
+#if !ForRelease
+ NSLog(@"###: %@", [url absoluteString]);
+#endif
+
+ @synchronized (HostConfig_) {
+ [CachedURLs_ addObject:url];
+ }
+ }
+
+ [super storeCachedResponse:cached forRequest:request];
+}
+
@end
@interface Cydia : UIApplication <
> {
_H<UIWindow> window_;
_H<CYTabBarController> tabbar_;
- _H<CYEmulatedLoadingController> emulated_;
+ _H<CydiaLoadingViewController> emulated_;
_H<NSMutableArray> essential_;
_H<NSMutableArray> broken_;
}
}
+- (void) returnToCydia {
+ [self _loaded];
+}
+
- (void) _saveConfig {
_trace();
MetaFile_.Sync();
NSLog(@"failure to serialize metadata: %@", error);
}
}
+
+ WriteSources();
}
// Navigation controller for the queuing badge.
- (void) _updateData {
[self _saveConfig];
-
[self unloadData];
UINavigationController *navigation = [self queueNavigationController];
// - We already auto-refreshed this launch.
// - Auto-refresh is disabled.
if (recently || loaded_ || ManualRefresh) {
- [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO];
-
// If we are cancelling, we need to make sure it knows it's already loaded.
loaded_ = true;
- return;
+
+ [self performSelectorOnMainThread:@selector(_loaded) withObject:nil waitUntilDone:NO];
} else {
// We are going to load, so remember that.
loaded_ = true;
- }
- SCNetworkReachabilityFlags flags; {
- SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(NULL, "cydia.saurik.com"));
- SCNetworkReachabilityGetFlags(reachability, &flags);
- CFRelease(reachability);
- }
+ SCNetworkReachabilityFlags flags; {
+ SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(NULL, "cydia.saurik.com"));
+ SCNetworkReachabilityGetFlags(reachability, &flags);
+ CFRelease(reachability);
+ }
- // XXX: this elaborate mess is what Apple is using to determine this? :(
- // XXX: do we care if the user has to intervene? maybe that's ok?
- bool reachable(
- (flags & kSCNetworkReachabilityFlagsReachable) != 0 && (
- (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || (
- (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 ||
- (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0
- ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 ||
- (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0
- )
- );
+ // XXX: this elaborate mess is what Apple is using to determine this? :(
+ // XXX: do we care if the user has to intervene? maybe that's ok?
+ bool reachable(
+ (flags & kSCNetworkReachabilityFlagsReachable) != 0 && (
+ (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || (
+ (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 ||
+ (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0
+ ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 ||
+ (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0
+ )
+ );
- // If we can reach the server, auto-refresh!
- if (reachable)
- [tabbar_ performSelectorOnMainThread:@selector(setUpdate:) withObject:update waitUntilDone:NO];
+ // If we can reach the server, auto-refresh!
+ if (reachable)
+ [tabbar_ performSelectorOnMainThread:@selector(setUpdate:) withObject:update waitUntilDone:NO];
+ }
[pool release];
}
[NSThread detachNewThreadSelector:@selector(_refreshIfPossible:) toTarget:self withObject:[Metadata_ objectForKey:@"LastUpdate"]];
}
-- (void) _reloadDataWithInvocation:(NSInvocation *)invocation {
+- (void) reloadDataWithInvocation:(NSInvocation *)invocation {
+@synchronized (self) {
UIProgressHUD *hud(loaded_ ? [self addProgressHUD] : nil);
[hud setText:UCLocalize("RELOADING_DATA")];
}
}
- NSLog(@"changes:#%u", changes);
-
UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:2] tabBarItem];
if (changes != 0) {
_trace();
}
[self _updateData];
-
- [self refreshIfPossible];
-}
+} }
- (void) updateData {
[self _updateData];
- (void) update_ {
[database_ update];
-}
-
-- (void) complete {
- @synchronized (self) {
- [self _reloadDataWithInvocation:nil];
- }
+ [self performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}
- (void) disemulate {
[self performSelectorOnMainThread:@selector(repairWithInvocation:) withObject:[NSInvocation invocationWithSelector:selector forTarget:database_] waitUntilDone:YES];
}
+- (void) reloadData {
+ [self reloadDataWithInvocation:nil];
+ if ([database_ progressDelegate] == nil)
+ [self _loaded];
+}
+
- (void) syncData {
[self _saveConfig];
-
- FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w"));
- _assert(file != NULL);
-
- for (NSString *key in [Sources_ allKeys]) {
- NSDictionary *source([Sources_ objectForKey:key]);
-
- fprintf(file, "%s %s %s\n",
- [[source objectForKey:@"Type"] UTF8String],
- [[source objectForKey:@"URI"] UTF8String],
- [[source objectForKey:@"Distribution"] UTF8String]
- );
- }
-
- fclose(file);
-
[self detachNewProgressSelector:@selector(update_) toTarget:self forController:nil title:@"UPDATING_SOURCES"];
-
- [self complete];
}
-- (void) addTrivialSource:(NSString *)href {
- [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys:
- @"deb", @"Type",
- href, @"URI",
- @"./", @"Distribution",
- nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href]];
+- (void) addSource:(NSDictionary *) source {
+ AddSource(source);
+}
- Changed_ = true;
+- (void) addSource:(NSString *)href withDistribution:(NSString *)distribution andSections:(NSArray *)sections {
+ AddSource(href, distribution, sections);
}
-- (void) reloadDataWithInvocation:(NSInvocation *)invocation {
- @synchronized (self) {
- [self _reloadDataWithInvocation:invocation];
- }
+- (void) addTrivialSource:(NSString *)href {
+ AddSource(href, @"./");
}
-- (void) reloadData {
- [self reloadDataWithInvocation:nil];
+- (void) updateValues {
+ Changed_ = true;
}
- (void) resolve {
}
}
+- (void) perform_ {
+ [database_ perform];
+ [self performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
+}
+
- (void) confirmWithNavigationController:(UINavigationController *)navigation {
Queuing_ = false;
++locked_;
- [self detachNewProgressSelector:@selector(perform) toTarget:database_ forController:navigation title:@"RUNNING"];
+ [self detachNewProgressSelector:@selector(perform_) toTarget:self forController:navigation title:@"RUNNING"];
--locked_;
- [self complete];
+ [self refreshIfPossible];
}
- (void) showSettings {
}
}
-- (void) system:(NSString *)command { _pooled
+- (void) system:(NSString *)command {
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
_trace();
system([command UTF8String]);
_trace();
+
+ [pool release];
}
- (void) applicationWillSuspend {
}
- (UIProgressHUD *) addProgressHUD {
- UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window_] autorelease]);
+ UIProgressHUD *hud([[[UIProgressHUD alloc] init] autorelease]);
[hud setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
[window_ setUserInteractionEnabled:NO];
UIView *view([target view]);
[view addSubview:hud];
- [hud show:YES];
+ [hud showInView:[tabbar_ view]];
++locked_;
return hud;
- (void) removeProgressHUD:(UIProgressHUD *)hud {
--locked_;
- [hud show:NO];
+ [hud hide];
[hud removeFromSuperview];
[window_ setUserInteractionEnabled:YES];
}
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];
}
}
[super applicationWillResignActive:application];
}
-- (void) applicationWillTerminate:(UIApplication *)application {
- Changed_ = true;
+- (void) saveState {
[Metadata_ setObject:[tabbar_ navigationURLCollection] forKey:@"InterfaceState"];
[Metadata_ setObject:[NSDate date] forKey:@"LastClosed"];
[Metadata_ setObject:[NSNumber numberWithInt:[tabbar_ selectedIndex]] forKey:@"InterfaceIndex"];
+ Changed_ = true;
[self _saveConfig];
}
+- (void) applicationWillTerminate:(UIApplication *)application {
+ [self saveState];
+}
+
- (void) setConfigurationData:(NSString *)data {
static Pcre conffile_r("^'(.*)' '(.*)' ([01]) ([01])$");
[tabbar_ setUpdateDelegate:self];
}
+- (void) _sendMemoryWarningNotification {
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidReceiveMemoryWarningNotification" object:[UIApplication sharedApplication]];
+}
+
+- (void) _sendMemoryWarningNotifications {
+ while (true) {
+ [self performSelectorOnMainThread:@selector(_sendMemoryWarningNotification) withObject:nil waitUntilDone:NO];
+ usleep(250000);
+ }
+}
+
- (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 setupViewControllers];
- emulated_ = [[[CYEmulatedLoadingController alloc] initWithDatabase:database_] autorelease];
+ emulated_ = [[[CydiaLoadingViewController alloc] init] autorelease];
[window_ addSubview:[emulated_ view]];
[self performSelector:@selector(loadData) withObject:nil afterDelay:0];
[window_ setUserInteractionEnabled:NO];
}
- [self reloadData];
+ [self reloadDataWithInvocation:nil];
+ [self refreshIfPossible];
PrintTimes();
[self disemulate];
NSMutableURLRequest *copy([request mutableCopy]);
NSURL *url([copy URL]);
+
+ NSString *href([url absoluteString]);
NSString *host([url host]);
NSString *scheme([[url scheme] lowercaseString]);
if ([copy respondsToSelector:@selector(setHTTPShouldUsePipelining:)])
if ([PipelinedHosts_ containsObject:host] || [PipelinedHosts_ containsObject:compound])
[copy setHTTPShouldUsePipelining:YES];
+
+ if (NSString *control = [copy valueForHTTPHeaderField:@"Cache-Control"])
+ if ([control isEqualToString:@"max-age=0"])
+ if ([CachedURLs_ containsObject:href]) {
+#if !ForRelease
+ NSLog(@"~~~: %@", href);
+#endif
+
+ [copy setCachePolicy:NSURLRequestReturnCacheDataDontLoad];
+
+ [copy setValue:nil forHTTPHeaderField:@"Cache-Control"];
+ [copy setValue:nil forHTTPHeaderField:@"If-Modified-Since"];
+ [copy setValue:nil forHTTPHeaderField:@"If-None-Match"];
+ }
}
if ((self = _NSURLConnection$init$(self, _cmd, copy, delegate, usesCache, maxContentLength, startImmediately, connectionProperties)) != nil) {
} return self;
}
-int main(int argc, char *argv[]) { _pooled
+int main(int argc, char *argv[]) {
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
_trace();
UpdateExternalStatus(0);
HostConfig_ = [[[NSObject alloc] init] autorelease];
@synchronized (HostConfig_) {
BridgedHosts_ = [NSMutableSet setWithCapacity:4];
+ TokenHosts_ = [NSMutableSet setWithCapacity:4];
+ InsecureHosts_ = [NSMutableSet setWithCapacity:4];
PipelinedHosts_ = [NSMutableSet setWithCapacity:4];
+ CachedURLs_ = [NSMutableSet setWithCapacity:32];
}
UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]);
ChipID_ = [CYHex((NSData *) CYIOGetValue("IODeviceTree:/chosen", @"unique-chip-id"), true) uppercaseString];
BBSNum_ = CYHex((NSData *) CYIOGetValue("IOService:/AppleARMPE/baseband", @"snum"), false);
- UniqueID_ = [[UIDevice currentDevice] uniqueIdentifier];
+ UniqueID_ = [device uniqueIdentifier];
CFStringRef (*$CTSIMSupportCopyMobileSubscriberCountryCode)(CFAllocatorRef);
$CTSIMSupportCopyMobileSubscriberCountryCode = reinterpret_cast<CFStringRef (*)(CFAllocatorRef)>(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode"));
Settings_ = [Metadata_ objectForKey:@"Settings"];
Packages_ = [Metadata_ objectForKey:@"Packages"];
+
+ Values_ = [Metadata_ objectForKey:@"Values"];
Sections_ = [Metadata_ objectForKey:@"Sections"];
Sources_ = [Metadata_ objectForKey:@"Sources"];
Token_ = [Metadata_ objectForKey:@"Token"];
+
+ Version_ = [Metadata_ objectForKey:@"Version"];
+
+ @synchronized (HostConfig_) {
+ CydiaSource_ = [Metadata_ objectForKey:@"CydiaSource"];
+ }
}
if (Settings_ != nil)
Role_ = [Settings_ objectForKey:@"Role"];
+ if (Values_ == nil) {
+ Values_ = [[[NSMutableDictionary alloc] initWithCapacity:4] autorelease];
+ [Metadata_ setObject:Values_ forKey:@"Values"];
+ }
+
if (Sections_ == nil) {
Sections_ = [[[NSMutableDictionary alloc] initWithCapacity:32] autorelease];
[Metadata_ setObject:Sections_ forKey:@"Sections"];
Sources_ = [[[NSMutableDictionary alloc] initWithCapacity:0] autorelease];
[Metadata_ setObject:Sources_ forKey:@"Sources"];
}
+
+ if (Version_ == nil) {
+ Version_ = [NSNumber numberWithUnsignedInt:0];
+ [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/", @"./");
+
+ Version_ = [NSNumber numberWithUnsignedInt:1];
+ [Metadata_ setObject:Version_ forKey:@"Version"];
+
+ [Metadata_ removeObjectForKey:@"LastUpdate"];
+
+ Changed_ = true;
+ }
/* }}} */
+ WriteSources();
+
_trace();
MetaFile_.Open("/var/lib/cydia/metadata.cb0");
_trace();
CGColorSpaceRelease(space_);
CFRelease(Locale_);
+ [pool release];
return value;
}