#include <GraphicsServices/GraphicsServices.h>
#include <Foundation/Foundation.h>
+#if 0
+#define DEPLOYMENT_TARGET_MACOSX 1
+#define CF_BUILDING_CF 1
+#include <CoreFoundation/CFInternal.h>
+#endif
+
+#include <CoreFoundation/CFPriv.h>
+#include <CoreFoundation/CFUniChar.h>
+
#import <QuartzCore/CALayer.h>
#import <UIKit/UIKit.h>
#include <WebCore/WebCoreThread.h>
#import <WebKit/WebDefaultUIKitDelegate.h>
+#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/clean.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/debindexfile.h>
#include <apt-pkg/debmetaindex.h>
#include <apt-pkg/error.h>
#include <apt-pkg/init.h>
/* XXX: deal with exceptions */
id value([self performSelector:selector withObject:object]);
+ NSMethodSignature *signature([self methodSignatureForSelector:selector]);
[context removeAllObjects];
- if (value != nil)
+ if ([signature methodReturnLength] != 0 && value != nil)
[context addObject:value];
stopped = true;
/* NSForcedOrderingSearch doesn't work on the iPhone */
static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch;
-static const NSStringCompareOptions BaseCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch;
-static const NSStringCompareOptions ForcedCompareOptions_ = BaseCompareOptions_;
-static const NSStringCompareOptions LaxCompareOptions_ = BaseCompareOptions_ | NSCaseInsensitiveSearch;
+static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch;
+static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive | kCFCompareNonliteral | kCFCompareLocalized | kCFCompareNumerically | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
/* iPhoneOS 2.0 Compatibility {{{ */
#ifdef __OBJC2__
#define ForRelease 0
#define ForSaurik (0 && !ForRelease)
-#define LogBrowser (1 && !ForRelease)
+#define LogBrowser (0 && !ForRelease)
+#define TrackResize (0 && !ForRelease)
#define ManualRefresh (1 && !ForRelease)
#define ShowInternals (0 && !ForRelease)
#define IgnoreInstall (0 && !ForRelease)
@implementation NSMutableArray (Radix)
- (void) radixSortUsingSelector:(SEL)selector withObject:(id)object {
+ size_t count([self count]);
+ if (count == 0)
+ return;
+
+#if 0
NSInvocation *invocation([NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:"L12@0:4@8"]]);
[invocation setSelector:selector];
[invocation setArgument:&object atIndex:2];
+#else
+ /* XXX: this is an unsafe optimization of doomy hell */
+ Method method(class_getInstanceMethod([[self objectAtIndex:0] class], selector));
+ _assert(method != NULL);
+ uint32_t (*imp)(id, SEL, id) = reinterpret_cast<uint32_t (*)(id, SEL, id)>(method_getImplementation(method));
+ _assert(imp != NULL);
+#endif
- size_t count([self count]);
struct RadixItem_ *swap(new RadixItem_[count * 2]);
for (size_t i(0); i != count; ++i) {
item.index = i;
id object([self objectAtIndex:i]);
- [invocation setTarget:object];
+#if 0
+ [invocation setTarget:object];
[invocation invoke];
[invocation getReturnValue:&item.key];
+#else
+ item.key = imp(object, selector, object);
+#endif
}
RadixSort_(self, count, swap);
}
@end
+/* }}} */
+/* Insertion Sort {{{ */
+
+CFIndex CFBSearch_(const void *element, CFIndex elementSize, const void *list, CFIndex count, CFComparatorFunction comparator, void *context) {
+ const char *ptr = (const char *)list;
+ while (0 < count) {
+ CFIndex half = count / 2;
+ const char *probe = ptr + elementSize * half;
+ CFComparisonResult cr = comparator(element, probe, context);
+ if (0 == cr) return (probe - (const char *)list) / elementSize;
+ ptr = (cr < 0) ? ptr : probe + elementSize;
+ count = (cr < 0) ? half : (half + (count & 1) - 1);
+ }
+ return (ptr - (const char *)list) / elementSize;
+}
+
+void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFComparatorFunction comparator, void *context) {
+ if (range.length == 0)
+ return;
+ const void **values(new const void *[range.length]);
+ CFArrayGetValues(array, range, values);
+
+ for (CFIndex index(1); index != range.length; ++index) {
+ const void *value(values[index]);
+ CFIndex correct(CFBSearch_(&value, sizeof(const void *), values, index, comparator, context));
+ //NSLog(@"%u %u", index, correct);
+ if (correct != index) {
+ memmove(values + correct + 1, values + correct, sizeof(const void *) * (index - correct));
+ values[correct] = value;
+ }
+ }
+
+ CFArrayReplaceValues(array, range, values, range.length);
+ delete [] values;
+}
+
/* }}} */
/* Apple Bug Fixes {{{ */
else {
clear_();
- char *temp(reinterpret_cast<char *>(apr_palloc(pool, size)));
+ char *temp(reinterpret_cast<char *>(apr_palloc(pool, size + 1)));
memcpy(temp, data, size);
+ temp[size] = '\0';
data_ = temp;
size_ = size;
}
static const NSString *Safari_ = nil;
CFLocaleRef Locale_;
+NSArray *Languages_;
CGColorSpaceRef space_;
bool bootstrap_;
return [NSString stringWithFormat:@"%s%.1f %s", (negative ? "-" : ""), size, powers_[power]];
}
+NSString *StripVersion(const char *version) {
+ const char *colon(strchr(version, ':'));
+ if (colon != NULL)
+ version = colon + 1;
+ return [NSString stringWithUTF8String:version];
+}
+
NSString *StripVersion(NSString *version) {
NSRange colon = [version rangeOfString:@":"];
if (colon.location != NSNotFound)
}
NSString *LocalizeSection(NSString *section) {
- return section;
+ static Pcre title_r("^(.*?) \\((.*)\\)$");
+ if (title_r(section)) {
+ NSString *parent(title_r[1]);
+ NSString *child(title_r[2]);
+
+ return [NSString stringWithFormat:CYLocalize("PARENTHETICAL"),
+ LocalizeSection(parent),
+ LocalizeSection(child)
+ ];
+ }
+
+ return [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"];
}
NSString *Simplify(NSString *title) {
if (paren_r(data, size))
return Simplify(paren_r[1]);
- static Pcre title_r("^(.*?) \\(.*\\)$");
+ static Pcre title_r("^(.*?) \\((.*)\\)$");
if (title_r(data, size))
return Simplify(title_r[1]);
return title;
}
+
+_finline static void Stifle(char &value) {
+ value = (value & 0xdf) ^ 0x40;
+}
/* }}} */
bool isSectionVisible(NSString *section) {
- NSDictionary *metadata = [Sections_ objectForKey:section];
- NSNumber *hidden = metadata == nil ? nil : [metadata objectForKey:@"Hidden"];
+ NSDictionary *metadata([Sections_ objectForKey:section]);
+ NSNumber *hidden(metadata == nil ? nil : [metadata objectForKey:@"Hidden"]);
return hidden == nil || ![hidden boolValue];
}
- (void) updateWithStatus:(Status &)status;
- (void) setDelegate:(id)delegate;
-- (Source *) getSource:(const pkgCache::PkgFileIterator &)file;
+- (Source *) getSource:(pkgCache::PkgFileIterator)file;
@end
/* }}} */
@interface Package : NSObject {
unsigned era_;
+ pkgCache::VerIterator version_;
pkgCache::PkgIterator iterator_;
_transient Database *database_;
- pkgCache::VerIterator version_;
pkgCache::VerFileIterator file_;
Source *source_;
CYString section_;
NSString *section$_;
bool essential_;
+ bool visible_;
NSString *latest_;
NSString *installed_;
- NSString *id_;
+ CYString id_;
CYString name_;
CYString tagline_;
CYString icon_;
NSString *role_;
NSArray *relationships_;
+
NSMutableDictionary *metadata_;
+ _transient NSDate *firstSeen_;
+ _transient NSDate *lastSeen_;
+ bool subscribed_;
}
-- (Package *) initWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
+- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
- (pkgCache::PkgIterator) iterator;
- (Address *) maintainer;
- (size_t) size;
-- (NSString *) description;
+- (NSString *) longDescription;
+- (NSString *) shortDescription;
- (unichar) index;
- (NSMutableDictionary *) metadata;
- (NSString *) id;
- (NSString *) name;
-- (NSString *) tagline;
- (UIImage *) icon;
- (NSString *) homepage;
- (NSString *) depiction;
- (bool) isCommercial;
- (uint32_t) compareByPrefix;
-- (NSComparisonResult) compareByName:(Package *)package;
- (uint32_t) compareBySection:(NSArray *)sections;
- (uint32_t) compareForChanges;
return _not(uint32_t) - value.key;
}
+CFStringRef (*PackageName)(Package *self, SEL sel);
+
+CFComparisonResult PackageNameCompare(Package *lhs, Package *rhs, void *arg) {
+ _profile(PackageNameCompare)
+ CFStringRef lhn, rhn;
+ CFIndex length;
+
+ _profile(PackageNameCompare$Setup)
+ lhn = PackageName(lhs, @selector(name));
+ rhn = PackageName(rhs, @selector(name));
+ _end
+
+ _profile(PackageNameCompare$Nothing)
+ _end
+
+ _profile(PackageNameCompare$Length)
+ length = CFStringGetLength(lhn);
+ _end
+
+ _profile(PackageNameCompare$NumbersLast)
+ if (length != 0 && CFStringGetLength(rhn) != 0) {
+ UniChar lhc(CFStringGetCharacterAtIndex(lhn, 0));
+ UniChar rhc(CFStringGetCharacterAtIndex(rhn, 0));
+ bool lha(CFUniCharIsMemberOf(lhc, kCFUniCharLetterCharacterSet));
+ if (lha != CFUniCharIsMemberOf(rhc, kCFUniCharLetterCharacterSet))
+ return lha ? NSOrderedAscending : NSOrderedDescending;
+ }
+ _end
+
+ _profile(PackageNameCompare$Compare)
+ return CFStringCompareWithOptionsAndLocale(lhn, rhn, CFRangeMake(0, length), LaxCompareFlags_, Locale_);
+ _end
+ _end
+}
+
+CFComparisonResult PackageNameCompare_(Package **lhs, Package **rhs, void *context) {
+ return PackageNameCompare(*lhs, *rhs, context);
+}
+
+struct PackageNameOrdering :
+ std::binary_function<Package *, Package *, bool>
+{
+ _finline bool operator ()(Package *lhs, Package *rhs) const {
+ return PackageNameCompare(lhs, rhs, NULL) == NSOrderedAscending;
+ }
+};
+
@implementation Package
- (void) dealloc {
if (section$_ != nil)
[section$_ release];
- [latest_ release];
+ if (latest_ != nil)
+ [latest_ release];
if (installed_ != nil)
[installed_ release];
- [id_ release];
if (sponsor$_ != nil)
[sponsor$_ release];
if (author$_ != nil)
}
+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:@"applications", @"author", @"depiction", @"description", @"essential", @"homepage", @"icon", @"id", @"installed", @"latest", @"longSection", @"maintainer", @"mode", @"name", @"purposes", @"section", @"shortSection", @"simpleSection", @"size", @"source", @"sponsor", @"support", @"tagline", @"warnings", nil];
+ return [NSArray arrayWithObjects:@"applications", @"author", @"depiction", @"longDescription", @"essential", @"homepage", @"icon", @"id", @"installed", @"latest", @"longSection", @"maintainer", @"mode", @"name", @"purposes", @"section", @"shortDescription", @"shortSection", @"simpleSection", @"size", @"source", @"sponsor", @"support", @"warnings", nil];
}
- (NSArray *) attributeKeys {
return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
-- (Package *) initWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
+- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
if ((self = [super init]) != nil) {
- _profile(Package$initWithIterator)
+ _profile(Package$initWithVersion)
@synchronized (database) {
era_ = [database era];
- iterator_ = iterator;
+ version_ = version;
+ iterator_ = version.ParentPkg();
database_ = database;
- _profile(Package$initWithIterator$Control)
- _end
-
- _profile(Package$initWithIterator$Version)
- version_ = [database_ policy]->GetCandidateVer(iterator_);
- _end
-
- NSString *latest = version_.end() ? nil : [NSString stringWithUTF8String:version_.VerStr()];
-
- _profile(Package$initWithIterator$Latest)
- latest_ = latest == nil ? nil : [StripVersion(latest) retain];
+ _profile(Package$initWithVersion$Latest)
+ latest_ = [StripVersion(version_.VerStr()) retain];
_end
- pkgCache::VerIterator current;
- NSString *installed;
+ pkgCache::VerIterator current(iterator_.CurrentVer());
+ if (!current.end())
+ installed_ = [StripVersion(current.VerStr()) retain];
- _profile(Package$initWithIterator$Current)
- current = iterator_.CurrentVer();
- installed = current.end() ? nil : [NSString stringWithUTF8String:current.VerStr()];
- _end
-
- _profile(Package$initWithIterator$Installed)
- installed_ = [StripVersion(installed) retain];
- _end
-
- _profile(Package$initWithIterator$File)
- if (!version_.end())
- file_ = version_.FileList();
- else {
- pkgCache &cache([database_ cache]);
- file_ = pkgCache::VerFileIterator(cache, cache.VerFileP);
- }
- _end
+ if (!version_.end())
+ file_ = version_.FileList();
+ else {
+ pkgCache &cache([database_ cache]);
+ file_ = pkgCache::VerFileIterator(cache, cache.VerFileP);
+ }
- _profile(Package$initWithIterator$Name)
- id_ = [[NSString stringWithUTF8String:iterator_.Name()] retain];
+ _profile(Package$initWithVersion$Name)
+ id_.set(pool, iterator_.Name());
_end
if (!file_.end())
- _profile(Package$initWithIterator$Parse)
+ source_ = [database_ getSource:file_.File()];
+ if (source_ != nil)
+ [source_ retain];
+ cached_ = true;
+
+ _profile(Package$initWithVersion$Parse)
pkgRecords::Parser *parser;
- _profile(Package$initWithIterator$Parse$Lookup)
+ _profile(Package$initWithVersion$Parse$Lookup)
parser = &[database_ records]->Lookup(file_);
_end
- const char *begin, *end;
- parser->GetRec(begin, end);
-
CYString website;
CYString tag;
- struct {
- const char *name_;
- CYString *value_;
- } names[] = {
- {"name", &name_},
- {"icon", &icon_},
- {"depiction", &depiction_},
- {"homepage", &homepage_},
- {"website", &website},
- {"support", &support_},
- {"sponsor", &sponsor_},
- {"author", &author_},
- {"tag", &tag},
- };
-
- while (begin != end)
- if (*begin == '\n') {
- ++begin;
- continue;
- } else if (isblank(*begin)) next: {
- begin = static_cast<char *>(memchr(begin + 1, '\n', end - begin - 1));
- if (begin == NULL)
- break;
- } else if (const char *colon = static_cast<char *>(memchr(begin, ':', end - begin))) {
- const char *name(begin);
- size_t size(colon - begin);
-
- begin = static_cast<char *>(memchr(begin, '\n', end - begin));
-
- {
- const char *stop(begin == NULL ? end : begin);
- while (stop[-1] == '\r')
- --stop;
- while (++colon != stop && isblank(*colon));
-
- for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i)
- if (strncasecmp(names[i].name_, name, size) == 0) {
- CYString &value(*names[i].value_);
-
- _profile(Package$initWithIterator$Parse$Value)
- value.set(pool, colon, stop - colon);
- _end
-
- break;
- }
+ _profile(Package$initWithVersion$Parse$Find)
+ struct {
+ const char *name_;
+ CYString *value_;
+ } names[] = {
+ {"name", &name_},
+ {"icon", &icon_},
+ {"depiction", &depiction_},
+ {"homepage", &homepage_},
+ {"website", &website},
+ {"support", &support_},
+ {"sponsor", &sponsor_},
+ {"author", &author_},
+ {"tag", &tag},
+ };
+
+ for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
+ const char *start, *end;
+
+ if (parser->Find(names[i].name_, start, end)) {
+ CYString &value(*names[i].value_);
+ _profile(Package$initWithVersion$Parse$Value)
+ value.set(pool, start, end - start);
+ _end
}
+ }
+ _end
- if (begin == NULL)
- break;
- ++begin;
- } else goto next;
-
- _profile(Package$initWithIterator$Parse$Tagline)
+ _profile(Package$initWithVersion$Parse$Tagline)
tagline_.set(pool, parser->ShortDesc());
_end
- _profile(Package$initWithIterator$Parse$Retain)
+ _profile(Package$initWithVersion$Parse$Retain)
if (!homepage_.empty())
homepage_ = website;
if (homepage_ == depiction_)
_end
_end
- _profile(Package$initWithIterator$Tags)
+ _profile(Package$initWithVersion$Tags)
if (tags_ != nil)
for (NSString *tag in tags_)
if ([tag hasPrefix:@"role::"]) {
}
_end
- NSString *solid(latest == nil ? installed : latest);
bool changed(false);
-
NSString *key([id_ lowercaseString]);
- _profile(Package$initWithIterator$Metadata)
+ _profile(Package$initWithVersion$Metadata)
metadata_ = [Packages_ objectForKey:key];
+
if (metadata_ == nil) {
+ firstSeen_ = [now_ retain];
+
metadata_ = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
- now_, @"FirstSeen",
+ firstSeen_, @"FirstSeen",
+ latest_, @"LastVersion",
nil] mutableCopy];
- if (solid != nil)
- [metadata_ setObject:solid forKey:@"LastVersion"];
changed = true;
} else {
- NSDate *first([metadata_ objectForKey:@"FirstSeen"]);
- NSDate *last([metadata_ objectForKey:@"LastSeen"]);
+ firstSeen_ = [metadata_ objectForKey:@"FirstSeen"];
+ lastSeen_ = [metadata_ objectForKey:@"LastSeen"];
+
+ if (NSNumber *subscribed = [metadata_ objectForKey:@"IsSubscribed"])
+ subscribed_ = [subscribed boolValue];
+
NSString *version([metadata_ objectForKey:@"LastVersion"]);
- if (first == nil) {
- first = last == nil ? now_ : last;
- [metadata_ setObject:first forKey:@"FirstSeen"];
+ if (firstSeen_ == nil) {
+ firstSeen_ = lastSeen_ == nil ? now_ : lastSeen_;
+ [metadata_ setObject:firstSeen_ forKey:@"FirstSeen"];
changed = true;
}
- if (solid != nil)
- if (version == nil) {
- [metadata_ setObject:solid forKey:@"LastVersion"];
- changed = true;
- } else if (![version isEqualToString:solid]) {
- [metadata_ setObject:solid forKey:@"LastVersion"];
- last = now_;
- [metadata_ setObject:last forKey:@"LastSeen"];
- changed = true;
- }
+ if (version == nil) {
+ [metadata_ setObject:latest_ forKey:@"LastVersion"];
+ changed = true;
+ } else if (![version isEqualToString:latest_]) {
+ [metadata_ setObject:latest_ forKey:@"LastVersion"];
+ lastSeen_ = now_;
+ [metadata_ setObject:lastSeen_ forKey:@"LastSeen"];
+ changed = true;
+ }
}
metadata_ = [metadata_ retain];
}
_end
- _profile(Package$initWithIterator$Section)
+ _profile(Package$initWithVersion$Section)
section_.set(pool, iterator_.Section());
_end
essential_ = ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES) || [self hasTag:@"cydia::essential"];
+ visible_ = [self hasSupportingRole] && [self unfiltered];
} _end } return self;
}
+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
+ pkgCache::VerIterator version;
+
+ _profile(Package$packageWithIterator$GetCandidateVer)
+ version = [database policy]->GetCandidateVer(iterator);
+ _end
+
+ if (version.end())
+ return nil;
+
return [[[Package alloc]
- initWithIterator:iterator
+ initWithVersion:version
withZone:zone
inPool:pool
database:database
return version_.end() ? 0 : version_->InstalledSize;
}
-- (NSString *) description {
+- (NSString *) longDescription {
if (file_.end())
return nil;
pkgRecords::Parser *parser = &[database_ records]->Lookup(file_);
return [trimmed componentsJoinedByString:@"\n"];
}
+- (NSString *) shortDescription {
+ return tagline_;
+}
+
- (unichar) index {
_profile(Package$index)
- NSString *name([self name]);
- if ([name length] == 0)
+ CFStringRef name((CFStringRef) [self name]);
+ if (CFStringGetLength(name) == 0)
return '#';
- unichar character([name characterAtIndex:0]);
- if (!isalpha(character))
+ UniChar character(CFStringGetCharacterAtIndex(name, 0));
+ if (!CFUniCharIsMemberOf(character, kCFUniCharLetterCharacterSet))
return '#';
return toupper(character);
_end
}
- (NSMutableDictionary *) metadata {
- if (metadata_ == nil)
- metadata_ = [[Packages_ objectForKey:[id_ lowercaseString]] retain];
return metadata_;
}
- (NSDate *) seen {
- NSDictionary *metadata([self metadata]);
- if ([self subscribed])
- if (NSDate *last = [metadata objectForKey:@"LastSeen"])
- return last;
- return [metadata objectForKey:@"FirstSeen"];
+ if (subscribed_ && lastSeen_ != nil)
+ return lastSeen_;
+ return firstSeen_;
}
- (BOOL) subscribed {
- NSDictionary *metadata([self metadata]);
- if (NSNumber *subscribed = [metadata objectForKey:@"IsSubscribed"])
- return [subscribed boolValue];
- else
- return false;
+ return subscribed_;
}
- (BOOL) ignored {
}
- (BOOL) upgradableAndEssential:(BOOL)essential {
- pkgCache::VerIterator current = iterator_.CurrentVer();
-
- bool value;
- if (current.end())
- value = essential && [self essential] && [self visible];
- else
- value = !version_.end() && version_ != current;// && (!essential || ![database_ cache][iterator_].Keep());
- return value;
+ _profile(Package$upgradableAndEssential)
+ pkgCache::VerIterator current(iterator_.CurrentVer());
+ if (current.end())
+ return essential && essential_ && visible_;
+ else
+ return !version_.end() && version_ != current;// && (!essential || ![database_ cache][iterator_].Keep());
+ _end
}
- (BOOL) essential {
}
- (BOOL) unfiltered {
- NSString *section = [self section];
+ NSString *section([self section]);
return section == nil || isSectionVisible(section);
}
- (BOOL) visible {
- return [self hasSupportingRole] && [self unfiltered];
+ return visible_;
}
- (BOOL) half {
- unsigned char current = iterator_->CurrentState;
+ unsigned char current(iterator_->CurrentState);
return current == pkgCache::State::HalfConfigured || current == pkgCache::State::HalfInstalled;
}
}
- (NSString *) name {
- return name_ == nil ? id_ : name_;
-}
-
-- (NSString *) tagline {
- return tagline_;
+ return name_.empty() ? id_ : name_;
}
- (UIImage *) icon {
}
- (NSArray *) files {
- NSString *path = [NSString stringWithFormat:@"/var/lib/dpkg/info/%@.list", id_];
+ NSString *path = [NSString stringWithFormat:@"/var/lib/dpkg/info/%@.list", static_cast<NSString *>(id_)];
NSMutableArray *files = [NSMutableArray arrayWithCapacity:128];
std::ifstream fin;
if (range.location != NSNotFound)
return YES;
- range = [[self tagline] rangeOfString:text options:MatchCompareOptions_];
+ range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_];
if (range.location != NSNotFound)
return YES;
}
- (uint32_t) compareByPrefix {
- return 0;
-}
-
-- (NSComparisonResult) compareByName:(Package *)package {
- NSString *lhs = [self name];
- NSString *rhs = [package name];
+ size_t offset(0);
- /*if ([lhs length] != 0 && [rhs length] != 0) {
- unichar lhc = [lhs characterAtIndex:0];
- unichar rhc = [rhs characterAtIndex:0];
+ CYString &name(name_.empty() ? id_ : name_);
+ if (name.size() <= offset)
+ return 0;
+ size_t size(name.size() - offset);
- if (isalpha(lhc) && !isalpha(rhc))
- return NSOrderedAscending;
- else if (!isalpha(lhc) && isalpha(rhc))
- return NSOrderedDescending;
+ char data[4];
+ if (size >= 4)
+ memcpy(data, name.data() + offset, 4);
+ else {
+ memcpy(data, name.data() + offset, size);
+ memset(data + size, 0, 4 - size);
}
- return [lhs compare:rhs options:LaxCompareOptions_];*/
+ Stifle(data[0]);
+ Stifle(data[1]);
+ Stifle(data[2]);
+ Stifle(data[3]);
- return [lhs compare:rhs];
+ /* XXX: ntohl may be more honest */
+ return OSSwapInt32(*reinterpret_cast<uint32_t *>(data));
}
- (uint32_t) compareBySection:(NSArray *)sections {
NSString *localized_;
}
-- (NSComparisonResult) compareByName:(Section *)section;
-- (Section *) initWithName:(NSString *)name;
-- (Section *) initWithName:(NSString *)name row:(size_t)row;
+- (NSComparisonResult) compareByLocalized:(Section *)section;
+- (Section *) initWithName:(NSString *)name localized:(NSString *)localized;
+- (Section *) initWithName:(NSString *)name localize:(BOOL)localize;
+- (Section *) initWithName:(NSString *)name row:(size_t)row localize:(BOOL)localize;
- (Section *) initWithIndex:(unichar)index row:(size_t)row;
- (NSString *) name;
- (unichar) index;
- (void) addToCount;
- (void) setCount:(size_t)count;
+- (NSString *) localized;
@end
[super dealloc];
}
-- (NSComparisonResult) compareByName:(Section *)section {
- NSString *lhs = [self name];
- NSString *rhs = [section name];
+- (NSComparisonResult) compareByLocalized:(Section *)section {
+ NSString *lhs(localized_);
+ NSString *rhs([section localized]);
- if ([lhs length] != 0 && [rhs length] != 0) {
+ /*if ([lhs length] != 0 && [rhs length] != 0) {
unichar lhc = [lhs characterAtIndex:0];
unichar rhc = [rhs characterAtIndex:0];
return NSOrderedAscending;
else if (!isalpha(lhc) && isalpha(rhc))
return NSOrderedDescending;
- }
+ }*/
return [lhs compare:rhs options:LaxCompareOptions_];
}
-- (Section *) initWithName:(NSString *)name {
- return [self initWithName:name row:0];
+- (Section *) initWithName:(NSString *)name localized:(NSString *)localized {
+ if ((self = [self initWithName:name localize:NO]) != nil) {
+ if (localized != nil)
+ localized_ = [localized retain];
+ } return self;
+}
+
+- (Section *) initWithName:(NSString *)name localize:(BOOL)localize {
+ return [self initWithName:name row:0 localize:localize];
}
-- (Section *) initWithName:(NSString *)name row:(size_t)row {
+- (Section *) initWithName:(NSString *)name row:(size_t)row localize:(BOOL)localize {
if ((self = [super init]) != nil) {
name_ = [name retain];
index_ = '\0';
row_ = row;
- localized_ = LocalizeSection(name_);
+ if (localize)
+ localized_ = [LocalizeSection(name_) retain];
} return self;
}
apr_pool_create(&pool_, NULL);
sources_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
- packages_ = [[NSMutableArray arrayWithCapacity:16] retain];
+ packages_ = [[NSMutableArray alloc] init];
int fds[2];
apr_pool_clear(pool_);
NSRecycleZone(zone_);
+ int chk(creat("/tmp/cydia.chk", 0644));
+ if (chk != -1)
+ close(chk);
+
_trace();
if (!cache_.Open(progress_, true)) {
std::string error;
}
_trace();
+ unlink("/tmp/cydia.chk");
+
now_ = [[NSDate date] retain];
policy_ = new pkgDepCache::Policy();
_assert(pkgMinimizeUpgrade(cache_));
}
- [sources_ removeAllObjects];
- for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
- std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
- for (std::vector<pkgIndexFile *>::const_iterator index = indices->begin(); index != indices->end(); ++index)
- [sources_
- setObject:[[[Source alloc] initWithMetaIndex:*source] autorelease]
- forKey:[NSNumber numberWithLong:reinterpret_cast<uintptr_t>(*index)]
- ];
- }
-
- [packages_ removeAllObjects];
- _trace();
- for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator)
- if (Package *package = [Package packageWithIterator:iterator withZone:zone_ inPool:pool_ database:self])
- [packages_ addObject:package];
_trace();
- [packages_ sortUsingSelector:@selector(compareByName:)];
+ {
+ std::string lists(_config->FindDir("Dir::State::lists"));
+
+ [sources_ removeAllObjects];
+ for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
+ std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
+ for (std::vector<pkgIndexFile *>::const_iterator index = indices->begin(); index != indices->end(); ++index)
+ if (debPackagesIndex *packages = dynamic_cast<debPackagesIndex *>(*index))
+ [sources_
+ setObject:[[[Source alloc] initWithMetaIndex:*source] autorelease]
+ forKey:[NSString stringWithFormat:@"%s%s",
+ lists.c_str(),
+ URItoFileName(packages->IndexURI("Packages")).c_str()
+ ]
+ ];
+ }
+ }
_trace();
- _config->Set("Acquire::http::Timeout", 15);
- _config->Set("Acquire::http::MaxParallel", 4);
+ {
+ /*std::vector<Package *> packages;
+ packages.reserve(std::max(10000U, [packages_ count] + 1000));
+ [packages_ release];
+ packages_ = nil;*/
+
+ [packages_ removeAllObjects];
+
+ _trace();
+
+ for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator)
+ if (Package *package = [Package packageWithIterator:iterator withZone:zone_ inPool:pool_ database:self])
+ //packages.push_back(package);
+ [packages_ addObject:package];
+
+ _trace();
+
+ /*if (packages.empty())
+ packages_ = [[NSArray alloc] init];
+ else
+ packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()];
+ _trace();*/
+
+ [packages_ radixSortUsingSelector:@selector(compareByPrefix) withObject:NULL];
+
+ /*_trace();
+ PrintTimes();
+ _trace();*/
+
+ _trace();
+
+ /*if (!packages.empty())
+ CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare_), NULL);*/
+ //std::sort(packages.begin(), packages.end(), PackageNameOrdering());
+
+ //CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare), NULL);
+
+ CFArrayInsertionSortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare_), NULL);
+
+ //[packages_ sortUsingFunction:reinterpret_cast<NSComparisonResult (*)(id, id, void *)>(&PackageNameCompare) context:NULL];
+
+ _trace();
+ }
}
- (void) configure {
progress_.setDelegate(delegate);
}
-- (Source *) getSource:(const pkgCache::PkgFileIterator &)file {
- pkgIndexFile *index(NULL);
- list_->FindIndex(file, index);
- return [sources_ objectForKey:[NSNumber numberWithLong:reinterpret_cast<uintptr_t>(index)]];
+- (Source *) getSource:(pkgCache::PkgFileIterator)file {
+ if (const char *name = file.FileName())
+ if (Source *source = [sources_ objectForKey:[NSString stringWithUTF8String:name]])
+ return source;
+ return nil;
}
@end
icon_ = [[package icon] retain];
name_ = [[package name] retain];
- description_ = [[package tagline] retain];
+ description_ = [[package shortDescription] retain];
commercial_ = [package isCommercial];
package_ = [package retain];
from = [NSString stringWithFormat:CYLocalize("PARENTHETICAL"), from, section];
}
- from = [NSString stringWithFormat:CYLocalize("FROM"), label];
+ from = [NSString stringWithFormat:CYLocalize("FROM"), from];
source_ = [from retain];
if (NSString *purpose = [package primaryPurpose])
}
+ (int) heightForPackage:(Package *)package {
- NSString *tagline([package tagline]);
+ NSString *tagline([package shortDescription]);
int height = tagline == nil || [tagline length] == 0 ? -17 : 0;
#ifdef USE_BADGES
if ([package hasMode] || [package half])
name_ = [CYLocalize("ALL_PACKAGES") retain];
count_ = nil;
} else {
- section_ = [section name];
+ section_ = [section localized];
if (section_ != nil)
section_ = [section_ retain];
name_ = [(section_ == nil ? CYLocalize("NO_SECTION") : section_) retain];
[super dealloc];
}
-/*- (void) release {
+- (void) release {
if ([self retainCount] == 1)
[delegate_ setPackageView:self];
[super release];
-}*/
+}
/* XXX: this is not safe at all... localization of /fail/ */
- (void) _clickButtonWithName:(NSString *)name {
[self setPopupHook:nil];
WebThreadUnlock();
+ //[self yieldToSelector:@selector(callFunction:) withObject:special_];
[super callFunction:special_];
}
}
/* XXX: this is an unsafe optimization of doomy hell */
Method method = class_getInstanceMethod([Package class], filter);
+ _assert(method != NULL);
imp_ = method_getImplementation(method);
_assert(imp_ != NULL);
[cancel_ addTarget:self action:@selector(_onCancel) forControlEvents:UIControlEventTouchUpInside];
CGRect frame = [cancel_ frame];
- frame.size.width = 65;
frame.origin.x = ovrrect.size.width - frame.size.width - 5;
frame.origin.y = (ovrrect.size.height - frame.size.height) / 2;
[cancel_ setFrame:frame];
}
- (void) setProgressError:(NSString *)error forPackage:(NSString *)id {
- [prompt_ setText:[NSString stringWithFormat:CYLocalize("ERROR_MESSAGE"), error]];
+ [prompt_ setText:[NSString stringWithFormat:CYLocalize("COLON_DELIMITED"), CYLocalize("ERROR"), error]];
}
- (void) setProgressTitle:(NSString *)title {
section = §ions[key];
if (*section == nil) {
_profile(SectionsView$reloadData$Section$Allocate)
- *section = [[[Section alloc] initWithName:name] autorelease];
+ *section = [[[Section alloc] initWithName:name localize:YES] autorelease];
_end
}
_end
section = [sections objectForKey:key];
if (section == nil) {
_profile(SectionsView$reloadData$Section$Allocate)
- section = [[[Section alloc] initWithName:name] autorelease];
+ section = [[[Section alloc] initWithName:name localize:YES] autorelease];
[sections setObject:section forKey:key];
_end
}
[sections_ addObjectsFromArray:[sections allValues]];
#endif
- [sections_ sortUsingSelector:@selector(compareByName:)];
+ [sections_ sortUsingSelector:@selector(compareByLocalized:)];
for (Section *section in sections_) {
size_t count([section row]);
- if ([section row] == 0)
+ if (count == 0)
continue;
- section = [[[Section alloc] initWithName:[section name]] autorelease];
+ section = [[[Section alloc] initWithName:[section name] localized:[section localized]] autorelease];
[section setCount:count];
[filtered_ addObject:section];
}
}
- (NSString *) sectionList:(UISectionList *)list titleForSection:(int)section {
- NSLog(@"titleForSection:%u", section);
return [[sections_ objectAtIndex:section] name];
}
[packages_ radixSortUsingFunction:reinterpret_cast<uint32_t (*)(id, void *)>(&PackageChangesRadix) withArgument:NULL];
_trace();
- Section *upgradable = [[[Section alloc] initWithName:CYLocalize("AVAILABLE_UPGRADES")] autorelease];
- Section *ignored = [[[Section alloc] initWithName:CYLocalize("IGNORED_UPGRADES")] autorelease];
+ Section *upgradable = [[[Section alloc] initWithName:CYLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
+ Section *ignored = [[[Section alloc] initWithName:CYLocalize("IGNORED_UPGRADES") localize:NO] autorelease];
Section *section = nil;
NSDate *last = nil;
upgrades_ = 0;
bool unseens = false;
- CFDateFormatterRef formatter = CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle);
+ CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle));
- _trace();
for (size_t offset = 0, count = [packages_ count]; offset != count; ++offset) {
Package *package = [packages_ objectAtIndex:offset];
- BOOL uae;
- _profile(ChangesView$reloadData$Upgrade)
- uae = [package upgradableAndEssential:YES];
- _end
+ BOOL uae = [package upgradableAndEssential:YES];
if (!uae) {
unseens = true;
seen = [package seen];
_end
- bool different;
- _profile(ChangesView$reloadData$Compare)
- different = section == nil || last != seen && (seen == nil || [seen compare:last] != NSOrderedSame);
- _end
-
- if (different) {
+ if (section == nil || last != seen && (seen == nil || [seen compare:last] != NSOrderedSame)) {
last = seen;
NSString *name;
if (seen == nil)
name = CYLocalize("UNKNOWN");
else {
- _profile(ChangesView$reloadData$Format)
- name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) seen);
- _end
-
+ name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) seen);
[name autorelease];
}
_profile(ChangesView$reloadData$Allocate)
name = [NSString stringWithFormat:CYLocalize("NEW_AT"), name];
- section = [[[Section alloc] initWithName:name row:offset] autorelease];
+ section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease];
[sections_ addObject:section];
_end
}
- (void) setPackageView:(PackageView *)view {
if (package_ == nil)
package_ = [view retain];
- NSLog(@"packageView: %@", package_);
}
- (PackageView *) packageView {
@"home-dn.png", kUIButtonBarButtonSelectedInfo,
[NSNumber numberWithInt:1], kUIButtonBarButtonTag,
self, kUIButtonBarButtonTarget,
- CYLocalize("HOME"), kUIButtonBarButtonTitle,
+ @"Cydia", kUIButtonBarButtonTitle,
@"0", kUIButtonBarButtonType,
nil],
Font18Bold_ = [[UIFont boldSystemFontOfSize:18] retain];
Font22Bold_ = [[UIFont boldSystemFontOfSize:22] retain];
- _assert(pkgInitConfig(*_config));
- _assert(pkgInitSystem(*_config, _system));
-
tag_ = 1;
essential_ = [[NSMutableArray alloc] initWithCapacity:4];
int main(int argc, char *argv[]) { _pooled
_trace();
- Locale_ = CFLocaleCopyCurrent();
+ PackageName = reinterpret_cast<CFStringRef (*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(name))));
+
+ /* Library Hacks {{{ */
+ class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
- CFStringRef locale(CFLocaleGetIdentifier(Locale_));
- setenv("LANG", [(NSString *) locale UTF8String], true);
+ $WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");
+ Method UIWebDocumentView$_setUIKitDelegate$(class_getInstanceMethod([WebView class], @selector(_setUIKitDelegate:)));
+ if (UIWebDocumentView$_setUIKitDelegate$ != NULL) {
+ _UIWebDocumentView$_setUIKitDelegate$ = reinterpret_cast<void (*)(UIWebDocumentView *, SEL, id)>(method_getImplementation(UIWebDocumentView$_setUIKitDelegate$));
+ method_setImplementation(UIWebDocumentView$_setUIKitDelegate$, reinterpret_cast<IMP>(&$UIWebDocumentView$_setUIKitDelegate$));
+ }
+ /* }}} */
+ /* Set Locale {{{ */
+ Locale_ = CFLocaleCopyCurrent();
+ Languages_ = [NSLocale preferredLanguages];
+ //CFStringRef locale(CFLocaleGetIdentifier(Locale_));
+ //NSLog(@"%@", [Languages_ description]);
+ const char *lang;
+ if (Languages_ == nil || [Languages_ count] == 0)
+ lang = NULL;
+ else
+ lang = [[Languages_ objectAtIndex:0] UTF8String];
+ setenv("LANG", lang, true);
+ //std::setlocale(LC_ALL, lang);
+ NSLog(@"Setting Language: %s", lang);
+ /* }}} */
// XXX: apr_app_initialize?
apr_initialize();
- class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
-
+ /* Parse Arguments {{{ */
bool substrate(false);
if (argc != 0) {
else
fprintf(stderr, "unknown argument: %s\n", args[argi]);
}
-
- App_ = [[NSBundle mainBundle] bundlePath];
- Home_ = NSHomeDirectory();
+ /* }}} */
{
NSString *plist = [Home_ stringByAppendingString:@"/Library/Preferences/com.apple.preferences.sounds.plist"];
Sounds_Keyboard_ = [keyboard boolValue];
}
+ App_ = [[NSBundle mainBundle] bundlePath];
+ Home_ = NSHomeDirectory();
+
setuid(0);
setgid(0);
-#if 1 /* XXX: this costs 1.4s of startup performance */
- if (unlink("/var/cache/apt/pkgcache.bin") == -1)
- _assert(errno == ENOENT);
- if (unlink("/var/cache/apt/srcpkgcache.bin") == -1)
- _assert(errno == ENOENT);
-#endif
-
- $WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");
- Method UIWebDocumentView$_setUIKitDelegate$(class_getInstanceMethod([WebView class], @selector(_setUIKitDelegate:)));
- if (UIWebDocumentView$_setUIKitDelegate$ != NULL) {
- _UIWebDocumentView$_setUIKitDelegate$ = reinterpret_cast<void (*)(UIWebDocumentView *, SEL, id)>(method_getImplementation(UIWebDocumentView$_setUIKitDelegate$));
- method_setImplementation(UIWebDocumentView$_setUIKitDelegate$, reinterpret_cast<IMP>(&$UIWebDocumentView$_setUIKitDelegate$));
- }
-
/*Method alloc = class_getClassMethod([NSObject class], @selector(alloc));
alloc_ = alloc->method_imp;
alloc->method_imp = (IMP) &Alloc_;*/
/*AddPreferences(@"/Applications/Preferences.app/Settings-iPhone.plist");
AddPreferences(@"/Applications/Preferences.app/Settings-iPod.plist");*/
+ /* Load Database {{{ */
_trace();
Metadata_ = [[[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"] autorelease];
_trace();
Sources_ = [[[NSMutableDictionary alloc] initWithCapacity:0] autorelease];
[Metadata_ setObject:Sources_ forKey:@"Sources"];
}
+ /* }}} */
#if RecycleWebViews
Documents_ = [[[NSMutableArray alloc] initWithCapacity:4] autorelease];
error:NULL
]);
+ if (access("/tmp/cydia.chk", F_OK) == 0) {
+ if (unlink("/var/cache/apt/pkgcache.bin") == -1)
+ _assert(errno == ENOENT);
+ if (unlink("/var/cache/apt/srcpkgcache.bin") == -1)
+ _assert(errno == ENOENT);
+ }
+
+ _assert(pkgInitConfig(*_config));
+ _assert(pkgInitSystem(*_config, _system));
+
+ if (lang != NULL)
+ _config->Set("APT::Acquire::Translation", lang);
+ _config->Set("Acquire::http::Timeout", 15);
+ _config->Set("Acquire::http::MaxParallel", 4);
+
+ /* Color Choices {{{ */
space_ = CGColorSpaceCreateDeviceRGB();
Blue_.Set(space_, 0.2, 0.2, 1.0, 1.0);
//.93
InstallingColor_ = [UIColor colorWithRed:0.88f green:1.00f blue:0.88f alpha:1.00f];
RemovingColor_ = [UIColor colorWithRed:1.00f green:0.88f blue:0.88f alpha:1.00f];
+ /* }}}*/
Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];
+ /* UIKit Configuration {{{ */
void (*$GSFontSetUseLegacyFontMetrics)(BOOL)(reinterpret_cast<void (*)(BOOL)>(dlsym(RTLD_DEFAULT, "GSFontSetUseLegacyFontMetrics")));
if ($GSFontSetUseLegacyFontMetrics != NULL)
$GSFontSetUseLegacyFontMetrics(YES);
UIKeyboardDisableAutomaticAppearance();
+ /* }}} */
_trace();
int value = UIApplicationMain(argc, argv, @"Cydia", @"Cydia");