X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/2595e4c379a0a75854a02dd9fc68dae99c274434..7d7000357dfc9fbba18cb60b3c4021d8db8351b1:/MobileCydia.mm?ds=sidebyside diff --git a/MobileCydia.mm b/MobileCydia.mm index b8504f4b..18737029 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -26,6 +26,9 @@ #include "CyteKit/UCPlatform.h" #include "CyteKit/Localize.h" +#include +#include + #include #include @@ -38,7 +41,6 @@ #include #endif -#include #include #include @@ -160,7 +162,7 @@ class ProfileTime { void Print() { if (total_ != 0) - std::cerr << std::setw(5) << count_ << ", " << std::setw(7) << total_ << " : " << name_ << std::endl; + std::cerr << std::setw(7) << count_ << ", " << std::setw(8) << total_ << " : " << name_ << std::endl; total_ = 0; count_ = 0; } @@ -206,7 +208,7 @@ extern NSString *Cydia_; #define ForRelease 1 #define TraceLogging (1 && !ForRelease) -#define HistogramInsertionSort (!ForRelease ? 0 : 0) +#define HistogramInsertionSort (0 && !ForRelease) #define ProfileTimes (0 && !ForRelease) #define ForSaurik (0 && !ForRelease) #define LogBrowser (0 && !ForRelease) @@ -214,7 +216,6 @@ extern NSString *Cydia_; #define ManualRefresh (1 && !ForRelease) #define ShowInternals (0 && !ForRelease) #define AlwaysReload (0 && !ForRelease) -#define TryIndexedCollation (0 && !ForRelease) #if !TraceLogging #undef _trace @@ -315,7 +316,7 @@ static CGFloat CYStatusBarHeight() { /* 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; +static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareNumerically | kCFCompareWidthInsensitive | kCFCompareForcedOrdering; /* Insertion Sort {{{ */ @@ -721,6 +722,56 @@ static _H UserAgent_; static _H Product_; static _H Safari_; +static _H CollationLocale_; +static _H CollationThumbs_; +static std::vector CollationOffset_; +static _H CollationTitles_; +static _H CollationStarts_; +static UTransliterator *CollationTransl_; +//static Function CollationModify_; + +typedef std::basic_string ustring; +static ustring CollationString_; + +#define CUC const ustring &str(*reinterpret_cast(rep)) +#define UC ustring &str(*reinterpret_cast(rep)) +static struct UReplaceableCallbacks CollationUCalls_ = { + .length = [](const UReplaceable *rep) -> int32_t { CUC; + return str.size(); + }, + + .charAt = [](const UReplaceable *rep, int32_t offset) -> UChar { CUC; + //fprintf(stderr, "charAt(%d) : %d\n", offset, str.size()); + if (offset >= str.size()) + return 0xffff; + return str[offset]; + }, + + .char32At = [](const UReplaceable *rep, int32_t offset) -> UChar32 { CUC; + //fprintf(stderr, "char32At(%d) : %d\n", offset, str.size()); + if (offset >= str.size()) + return 0xffff; + UChar32 c; + U16_GET(str.data(), 0, offset, str.size(), c); + return c; + }, + + .replace = [](UReplaceable *rep, int32_t start, int32_t limit, const UChar *text, int32_t length) -> void { UC; + //fprintf(stderr, "replace(%d, %d, %d) : %d\n", start, limit, length, str.size()); + str.replace(start, limit - start, text, length); + }, + + .extract = [](UReplaceable *rep, int32_t start, int32_t limit, UChar *dst) -> void { UC; + //fprintf(stderr, "extract(%d, %d) : %d\n", start, limit, str.size()); + str.copy(dst, limit - start, start); + }, + + .copy = [](UReplaceable *rep, int32_t start, int32_t limit, int32_t dest) -> void { UC; + //fprintf(stderr, "copy(%d, %d, %d) : %d\n", start, limit, dest, str.size()); + str.replace(dest, 0, str, start, limit - start); + }, +}; + static CFLocaleRef Locale_; static NSArray *Languages_; static CGColorSpaceRef space_; @@ -783,7 +834,7 @@ NSString *LocalizeSection(NSString *section) { NSString *Simplify(NSString *title) { const char *data = [title UTF8String]; - size_t size = [title length]; + size_t size = [title lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; static Pcre square_r("^\\[(.*)\\]$"); if (square_r(data, size)) @@ -1305,7 +1356,7 @@ static PackageValue *PackageFind(const char *name, size_t length, bool *fail = N PackageValue *metadata; Cytore::Offset *offset(&MetaFile_->packages_[nhash.u16[0]]); - offset: if (offset->IsNull()) { + for (;; offset = &metadata->next_) { if (offset->IsNull()) { *offset = MetaFile_.New(length + 1); metadata = &MetaFile_.Get(*offset); @@ -1317,16 +1368,18 @@ static PackageValue *PackageFind(const char *name, size_t length, bool *fail = N memset(metadata, 0, sizeof(*metadata)); } - memcpy(metadata->name_, name, length + 1); + memcpy(metadata->name_, name, length); + metadata->name_[length] = '\0'; metadata->nhash_ = nhash.u16[1]; } else { metadata = &MetaFile_.Get(*offset); - - if (metadata->nhash_ != nhash.u16[1] || strncmp(metadata->name_, name, length + 1) != 0) { - offset = &metadata->next_; - goto offset; - } - } + if (metadata->nhash_ != nhash.u16[1]) + continue; + if (strncmp(metadata->name_, name, length) != 0) + continue; + if (metadata->name_[length] != '\0') + continue; + } break; } return metadata; } @@ -1499,18 +1552,24 @@ static void PackageImport(const void *key, const void *value, void *context) { debReleaseIndex *dindex(dynamic_cast(index)); if (dindex != NULL) { std::string file(dindex->MetaIndexURI("")); - files_.insert(file + "Release.gpg"); - files_.insert(file + "Release"); base_.set(pool, file); - std::vector *targets(dindex->ComputeIndexTargets()); - for (std::vector::const_iterator target(targets->begin()); target != targets->end(); ++target) { - std::string file((*target)->URI); + pkgAcquire acquire; + _profile(Source$setMetaIndex$GetIndexes) + dindex->GetIndexes(&acquire, true); + _end + _profile(Source$setMetaIndex$DescURI) + for (pkgAcquire::ItemIterator item(acquire.ItemsBegin()); item != acquire.ItemsEnd(); item++) { + std::string file((*item)->DescURI()); + files_.insert(file); + if (file.length() < sizeof("Packages.bz2") || file.substr(file.length() - sizeof("Packages.bz2")) != "/Packages.bz2") + continue; + file = file.substr(0, file.length() - 4); files_.insert(file); files_.insert(file + ".gz"); - files_.insert(file + ".bz2"); files_.insert(file + "Index"); - } delete targets; + } + _end FileFd fd; if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly)) @@ -1565,7 +1624,9 @@ static void PackageImport(const void *key, const void *value, void *context) { database_ = database; index_ = index; + _profile(Source$initWithMetaIndex$setMetaIndex) [self setMetaIndex:index inPool:pool]; + _end } return self; } @@ -1946,7 +2007,7 @@ struct ParsedPackage { @interface Package : NSObject { uint32_t era_ : 25; - uint32_t role_ : 3; + @public uint32_t role_ : 3; uint32_t essential_ : 1; uint32_t obsolete_ : 1; uint32_t ignored_ : 1; @@ -1964,9 +2025,11 @@ struct ParsedPackage { CYString id_; CYString name_; + CYString transform_; CYString latest_; CYString installed_; + time_t updated_; const char *section_; _transient NSString *section$_; @@ -2056,12 +2119,6 @@ struct ParsedPackage { - (void) install; - (void) remove; -- (bool) isUnfilteredAndSearchedForBy:(NSArray *)query; -- (bool) isUnfilteredAndSelectedForBy:(NSString *)search; -- (bool) isInstalledAndUnfiltered:(NSNumber *)number; -- (bool) isVisibleInSection:(NSString *)section source:(Source *)source; -- (bool) isVisibleInSource:(Source *)source; - @end uint32_t PackageChangesRadix(Package *self, void *) { @@ -2091,9 +2148,11 @@ uint32_t PackageChangesRadix(Package *self, void *) { return _not(uint32_t) - value.key; } +CYString &(*PackageName)(Package *self, SEL sel); + uint32_t PackagePrefixRadix(Package *self, void *context) { size_t offset(reinterpret_cast(context)); - CYString &name([self cyname]); + CYString &name(PackageName(self, @selector(cyname))); size_t size(name.size()); if (size == 0) @@ -2146,46 +2205,50 @@ uint32_t PackagePrefixRadix(Package *self, void *context) { return OSSwapInt32(*reinterpret_cast(data)); } -CYString &(*PackageName)(Package *self, SEL sel); - -CFComparisonResult PackageNameCompare(Package *lhs, Package *rhs, void *arg) { +CFComparisonResult StringNameCompare(CFStringRef lhn, CFStringRef rhn, size_t length) { _profile(PackageNameCompare) - CYString &lhi(PackageName(lhs, @selector(cyname))); - CYString &rhi(PackageName(rhs, @selector(cyname))); - CFStringRef lhn(lhi), rhn(rhi); - if (lhn == NULL) - return rhn == NULL ? NSOrderedSame : NSOrderedAscending; + return rhn == NULL ? kCFCompareEqualTo : kCFCompareLessThan; else if (rhn == NULL) - return NSOrderedDescending; + return kCFCompareGreaterThan; + + CFIndex length(CFStringGetLength(lhn)); _profile(PackageNameCompare$NumbersLast) - if (!lhi.empty() && !rhi.empty()) { + 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; + return lha ? kCFCompareLessThan : kCFCompareGreaterThan; } _end - CFIndex length = CFStringGetLength(lhn); - _profile(PackageNameCompare$Compare) - return CFStringCompareWithOptionsAndLocale(lhn, rhn, CFRangeMake(0, length), LaxCompareFlags_, Locale_); + return CFStringCompareWithOptionsAndLocale(lhn, rhn, CFRangeMake(0, length), LaxCompareFlags_, (CFLocaleRef) (id) CollationLocale_); _end _end } -CFComparisonResult PackageNameCompare_(Package **lhs, Package **rhs, void *context) { - return PackageNameCompare(*lhs, *rhs, context); +_finline CFComparisonResult StringNameCompare(NSString *lhn, NSString*rhn, size_t length) { + return StringNameCompare((CFStringRef) lhn, (CFStringRef) rhn, length); +} + +CFComparisonResult PackageNameCompare(Package *lhs, Package *rhs, void *arg) { + CYString &lhn(PackageName(lhs, @selector(cyname))); + NSString *rhn(PackageName(rhs, @selector(cyname))); + return StringNameCompare(lhn, rhn, lhn.size()); +} + +CFComparisonResult PackageNameCompare_(Package **lhs, Package **rhs, void *arg) { + return PackageNameCompare(*lhs, *rhs, arg); } struct PackageNameOrdering : std::binary_function { _finline bool operator ()(Package *lhs, Package *rhs) const { - return PackageNameCompare(lhs, rhs, NULL) == NSOrderedAscending; + return PackageNameCompare(lhs, rhs, NULL) == kCFCompareLessThan; } }; @@ -2416,6 +2479,60 @@ struct PackageNameOrdering : installed_.set(NULL, StripVersion_(current.VerStr())); _end + _profile(Package$initWithVersion$Transliterate) do { + if (CollationTransl_ == NULL) + break; + if (name_.empty()) + break; + + _profile(Package$initWithVersion$Transliterate$utf8) + const uint8_t *data(reinterpret_cast(name_.data())); + for (size_t i(0), e(name_.size()); i != e; ++i) + if (data[i] >= 0x80) + goto extended; + break; extended:; + _end + + UErrorCode code(U_ZERO_ERROR); + int32_t length; + + _profile(Package$initWithVersion$Transliterate$u_strFromUTF8WithSub) + CollationString_.resize(name_.size()); + u_strFromUTF8WithSub(&CollationString_[0], CollationString_.size(), &length, name_.data(), name_.size(), 0xfffd, NULL, &code); + if (!U_SUCCESS(code)) + break; + CollationString_.resize(length); + _end + + _profile(Package$initWithVersion$Transliterate$utrans_trans) + length = CollationString_.size(); + utrans_trans(CollationTransl_, reinterpret_cast(&CollationString_), &CollationUCalls_, 0, &length, &code); + if (!U_SUCCESS(code)) + break; + _assert(CollationString_.size() == length); + _end + + _profile(Package$initWithVersion$Transliterate$u_strToUTF8WithSub$preflight) + u_strToUTF8WithSub(NULL, 0, &length, CollationString_.data(), CollationString_.size(), 0xfffd, NULL, &code); + if (code == U_BUFFER_OVERFLOW_ERROR) + code = U_ZERO_ERROR; + else if (!U_SUCCESS(code)) + break; + _end + + char *transform; + _profile(Package$initWithVersion$Transliterate$apr_palloc) + transform = static_cast(apr_palloc(pool_, length)); + _end + _profile(Package$initWithVersion$Transliterate$u_strToUTF8WithSub$transform) + u_strToUTF8WithSub(transform, length, NULL, CollationString_.data(), CollationString_.size(), 0xfffd, NULL, &code); + if (!U_SUCCESS(code)) + break; + _end + + transform_.set(NULL, transform, length); + } while (false); _end + _profile(Package$initWithVersion$Tags) pkgCache::TagIterator tag(iterator.TagList()); if (!tag.end()) { @@ -2455,13 +2572,21 @@ struct PackageNameOrdering : _profile(Package$initWithVersion$Metadata) const char *mixed(iterator.Name()); size_t size(strlen(mixed)); - char lower[size + 1]; + static const size_t prefix(sizeof("/var/lib/dpkg/info/") - 1); + char lower[prefix + size + 5 + 1]; for (size_t i(0); i != size; ++i) - lower[i] = mixed[i] | 0x20; - lower[size] = '\0'; + lower[prefix + i] = mixed[i] | 0x20; + + if (!installed_.empty()) { + memcpy(lower, "/var/lib/dpkg/info/", prefix); + memcpy(lower + prefix + size, ".list", 6); + struct stat info; + if (stat(lower, &info) != -1) + updated_ = info.st_birthtime; + } - PackageValue *metadata(PackageFind(lower, size)); + PackageValue *metadata(PackageFind(lower + prefix, size)); metadata_ = metadata; id_.set(NULL, metadata->name_, size); @@ -2759,7 +2884,7 @@ struct PackageNameOrdering : - (BOOL) hasMode { @synchronized (database_) { if ([database_ era] != era_ || iterator_.end()) - return nil; + return NO; pkgDepCache::StateCache &state([database_ cache][iterator_]); return state.Mode != pkgDepCache::ModeKeep; @@ -3007,6 +3132,10 @@ struct PackageNameOrdering : return source_ == (Source *) [NSNull null] ? nil : source_; } +- (uint32_t) updated { + return std::numeric_limits::max() - updated_; +} + - (uint32_t) rank { return rank_; } @@ -3087,7 +3216,7 @@ struct PackageNameOrdering : } - (CYString &) cyname { - return name_.empty() ? id_ : name_; + return !transform_.empty() ? transform_ : !name_.empty() ? name_ : id_; } - (uint32_t) compareBySection:(NSArray *)sections { @@ -3137,68 +3266,11 @@ struct PackageNameOrdering : cache->MarkDelete(iterator_, true); } } -- (bool) isUnfilteredAndSearchedForBy:(NSArray *)query { - _profile(Package$isUnfilteredAndSearchedForBy) - bool value(true); - - _profile(Package$isUnfilteredAndSearchedForBy$Unfiltered) - value &= [self unfiltered]; - _end - - _profile(Package$isUnfilteredAndSearchedForBy$Match) - value &= [self matches:query]; - _end - - return value; - _end -} - -- (bool) isUnfilteredAndSelectedForBy:(NSString *)search { - if ([search length] == 0) - return false; - - _profile(Package$isUnfilteredAndSelectedForBy) - bool value(true); - - _profile(Package$isUnfilteredAndSelectedForBy$Unfiltered) - value &= [self unfiltered]; - _end - - _profile(Package$isUnfilteredAndSelectedForBy$Match) - value &= [[self name] compare:search options:MatchCompareOptions_ range:NSMakeRange(0, [search length])] == NSOrderedSame; - _end - - return value; - _end -} - -- (bool) isInstalledAndUnfiltered:(NSNumber *)number { - return ![self uninstalled] && (![number boolValue] && role_ != 7 || [self unfiltered]); -} - -- (bool) isVisibleInSection:(NSString *)name source:(Source *)source { - NSString *section([self section]); - - return ( - name == nil || - section == nil && [name length] == 0 || - [name isEqualToString:section] - ) && ( - source == nil || - [self source] == source - ) && [self visible]; -} - -- (bool) isVisibleInSource:(Source *)source { - return [self source] == source && [self visible]; -} - @end /* }}} */ /* Section Class {{{ */ @interface Section : NSObject { _H name_; - unichar index_; size_t row_; size_t count_; _H localized_; @@ -3208,9 +3280,9 @@ struct PackageNameOrdering : - (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) setName:(NSString *)name; - (size_t) row; - (size_t) count; @@ -3256,28 +3328,18 @@ struct PackageNameOrdering : - (Section *) initWithName:(NSString *)name row:(size_t)row localize:(BOOL)localize { if ((self = [super init]) != nil) { name_ = name; - index_ = '\0'; row_ = row; if (localize) localized_ = LocalizeSection(name_); } return self; } -/* XXX: localize the index thingees */ -- (Section *) initWithIndex:(unichar)index row:(size_t)row { - if ((self = [super init]) != nil) { - name_ = [NSString stringWithCharacters:&index length:1]; - index_ = index; - row_ = row; - } return self; -} - - (NSString *) name { return name_; } -- (unichar) index { - return index_; +- (void) setName:(NSString *)name { + name_ = name; } - (size_t) row { @@ -3635,18 +3697,26 @@ class CydiaLogCleaner : NSString *title(UCLocalize("DATABASE")); list_ = new pkgSourceList(); + _profile(reloadDataWithInvocation$ReadMainList) if ([self popErrorWithTitle:title forOperation:list_->ReadMainList()]) return; + _end + _profile(reloadDataWithInvocation$Source$initWithMetaIndex) for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) { Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:pool_] autorelease]); [sourceList_ addObject:object]; } + _end _trace(); OpProgress progress; + bool opened; open: - if (!cache_.Open(progress, true)) { + _profile(reloadDataWithInvocation$pkgCacheFile) + opened = cache_.Open(progress, true); + _end + if (!opened) { // XXX: what if there are errors, but Open() == true? this should be merged with popError: while (!_error->empty()) { std::string error; @@ -3693,20 +3763,26 @@ class CydiaLogCleaner : return; } + _profile(reloadDataWithInvocation$pkgApplyStatus) if ([self popErrorWithTitle:title forOperation:pkgApplyStatus(cache_)]) return; + _end if (cache_->BrokenCount() != 0) { + _profile(pkgApplyStatus$pkgFixBroken) if ([self popErrorWithTitle:title forOperation:pkgFixBroken(cache_)]) return; + _end if (cache_->BrokenCount() != 0) { [delegate_ addProgressEventOnMainThread:[CydiaProgressEvent eventWithMessage:UCLocalize("STILL_BROKEN_EX") ofType:kCydiaProgressEventTypeError] forTask:title]; return; } + _profile(pkgApplyStatus$pkgMinimizeUpgrade) if ([self popErrorWithTitle:title forOperation:pkgMinimizeUpgrade(cache_)]) return; + _end } for (Source *object in (id) sourceList_) { @@ -3726,14 +3802,13 @@ class CydiaLogCleaner : packages.reserve(std::max(10000U, [packages_ count] + 1000)); packages_ = nil;*/ - _trace(); - + _profile(reloadDataWithInvocation$packageWithIterator) 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); CFArrayAppendValue(packages_, CFRetain(package)); + _end - _trace(); /*if (packages.empty()) packages_ = [[NSArray alloc] init]; @@ -3741,35 +3816,43 @@ class CydiaLogCleaner : packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()]; _trace();*/ - [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(16)]; + _profile(reloadDataWithInvocation$radix$8) + [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(8)]; + _end + + _profile(reloadDataWithInvocation$radix$4) [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(4)]; + _end + + _profile(reloadDataWithInvocation$radix$0) [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast(&PackagePrefixRadix) withContext:reinterpret_cast(0)]; + _end - /*_trace(); - PrintTimes(); - _trace();*/ + _profile(reloadDataWithInvocation$insertion) + CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&PackageNameCompare), NULL); + _end - _trace(); + /*_profile(reloadDataWithInvocation$CFQSortArray) + CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast(&PackageNameCompare_), NULL); + _end*/ - /*if (!packages.empty()) - CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast(&PackageNameCompare_), NULL);*/ - //std::sort(packages.begin(), packages.end(), PackageNameOrdering()); + /*_profile(reloadDataWithInvocation$stdsort) + std::sort(packages.begin(), packages.end(), PackageNameOrdering()); + _end*/ - //CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast(&PackageNameCompare), NULL); + /*_profile(reloadDataWithInvocation$CFArraySortValues) + CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast(&PackageNameCompare), NULL); + _end*/ - CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast(&PackageNameCompare), NULL); + /*_profile(reloadDataWithInvocation$sortUsingFunction) + [packages_ sortUsingFunction:reinterpret_cast(&PackageNameCompare) context:NULL]; + _end*/ - //[packages_ sortUsingFunction:reinterpret_cast(&PackageNameCompare) context:NULL]; - - _trace(); size_t count(CFArrayGetCount(packages_)); MetaFile_->active_ = count; - for (size_t index(0); index != count; ++index) [(Package *) CFArrayGetValueAtIndex(packages_, index) setIndex:index]; - - _trace(); } } } @@ -5024,7 +5107,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { reason = @"virtual"; } - NSDictionary *version(start.TargetVer() == 0 ? [NSNull null] : [NSDictionary dictionaryWithObjectsAndKeys: + NSDictionary *version(start.TargetVer() == 0 ? (NSDictionary *) [NSNull null] : [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithUTF8String:start.CompType()], @"operator", [NSString stringWithUTF8String:start.TargetVer()], @"value", nil]); @@ -5759,7 +5842,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (!highlighted) UISetColor(commercial_ ? Purple_ : Black_); - [name_ drawAtPoint:CGPointMake(36, 8) forWidth:(width - (placard_ == nil ? 68 : 94)) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation]; + [name_ drawAtPoint:CGPointMake(36, 8) forWidth:(width - (placard_ == nil ? 68 : 94)) withFont:Font18Bold_ lineBreakMode:NSLineBreakByTruncatingTail]; if (placard_ != nil) [placard_ drawAtPoint:CGPointMake(width - 52, 11)]; @@ -5802,12 +5885,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (!highlighted) UISetColor(commercial_ ? Purple_ : Black_); - [name_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - (placard_ == nil ? 80 : 106)) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation]; - [source_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation]; + [name_ drawAtPoint:CGPointMake(48, 8) forWidth:(width - (placard_ == nil ? 80 : 106)) withFont:Font18Bold_ lineBreakMode:NSLineBreakByTruncatingTail]; + [source_ drawAtPoint:CGPointMake(58, 29) forWidth:(width - 95) withFont:Font12_ lineBreakMode:NSLineBreakByTruncatingTail]; if (!highlighted) UISetColor(commercial_ ? Purplish_ : Gray_); - [description_ drawAtPoint:CGPointMake(12, 46) forWidth:(width - 46) withFont:Font14_ lineBreakMode:UILineBreakModeTailTruncation]; + [description_ drawAtPoint:CGPointMake(12, 46) forWidth:(width - 46) withFont:Font14_ lineBreakMode:NSLineBreakByTruncatingTail]; if (placard_ != nil) [placard_ drawAtPoint:CGPointMake(width - 52, 9)]; @@ -5893,7 +5976,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { section_ = [section localized]; name_ = section_ == nil || [section_ length] == 0 ? UCLocalize("NO_SECTION") : (NSString *) section_; - count_ = [NSString stringWithFormat:@"%d", [section count]]; + count_ = [NSString stringWithFormat:@"%zd", [section count]]; if (editing_) [switch_ setOn:(isSectionVisible(basic_) ? 1 : 0) animated:NO]; @@ -5930,7 +6013,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (!highlighted) UISetColor(Black_); - [name_ drawAtPoint:CGPointMake(48, 12) forWidth:(width - 58) withFont:Font18_ lineBreakMode:UILineBreakModeTailTruncation]; + [name_ drawAtPoint:CGPointMake(48, 12) forWidth:(width - 58) withFont:Font18_ lineBreakMode:NSLineBreakByTruncatingTail]; CGSize size = [count_ sizeWithFont:Font14_]; @@ -6227,10 +6310,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _transient Database *database_; unsigned era_; _H packages_; - _H sections_; + _H sections_; _H list_; - _H index_; - _H indices_; + + _H thumbs_; + std::vector offset_; + _H title_; unsigned reloading_; } @@ -6240,6 +6325,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) resetCursor; - (void) clearData; +- (NSArray *) sectionsForPackages:(NSMutableArray *)packages; + @end @implementation PackageListController @@ -6351,12 +6438,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [[self navigationController] pushViewController:view animated:YES]; } -#if TryIndexedCollation -+ (BOOL) hasIndexedCollation { - return NO; // XXX: objc_getClass("UILocalizedIndexedCollation") != nil; -} -#endif - - (NSInteger) numberOfSectionsInTableView:(UITableView *)list { NSInteger count([sections_ count]); return count == 0 ? 1 : count; @@ -6402,20 +6483,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (NSArray *) sectionIndexTitlesForTableView:(UITableView *)tableView { - if (![self showsSections]) - return nil; - - return index_; + return thumbs_; } - (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { -#if TryIndexedCollation - if ([[self class] hasIndexedCollation]) { - return [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionForSectionIndexTitleAtIndex:index]; - } -#endif - - return index; + return offset_[index]; } - (void) updateHeight { @@ -6453,8 +6525,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { packages_ = nil; sections_ = nil; - index_ = nil; - indices_ = nil; + + thumbs_ = nil; + offset_.clear(); [super releaseSubviews]; } @@ -6485,7 +6558,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return; } - NSArray *packages; + NSMutableArray *packages; reload: if ([self shouldYield]) { @@ -6514,92 +6587,82 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { goto reload; reloading_ = 0; - packages_ = packages; - - indices_ = [NSMutableDictionary dictionaryWithCapacity:32]; - sections_ = [NSMutableArray arrayWithCapacity:16]; + thumbs_ = nil; + offset_.clear(); - Section *section = nil; - -#if TryIndexedCollation - if ([[self class] hasIndexedCollation]) { - index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles]; + packages_ = packages; - id collation = [objc_getClass("UILocalizedIndexedCollation") currentCollation]; - NSArray *titles = [collation sectionIndexTitles]; - int secidx = -1; + if ([self showsSections]) + sections_ = [self sectionsForPackages:packages]; + else { + Section *section([[[Section alloc] initWithName:nil row:0 localize:NO] autorelease]); + [section setCount:[packages_ count]]; + sections_ = [NSArray arrayWithObject:section]; + } - _profile(PackageTable$reloadData$Section) - for (size_t offset(0), end([packages_ count]); offset != end; ++offset) { - Package *package; - int index; + [self updateHeight]; - _profile(PackageTable$reloadData$Section$Package) - package = [packages_ objectAtIndex:offset]; - index = [collation sectionForObject:package collationStringSelector:@selector(name)]; - _end + _profile(PackageTable$reloadData$List) + [(UITableView *) list_ setDataSource:self]; + [list_ reloadData]; + _end +} - while (secidx < index) { - secidx += 1; + PrintTimes(); +} - _profile(PackageTable$reloadData$Section$Allocate) - section = [[[Section alloc] initWithName:[titles objectAtIndex:secidx] row:offset localize:NO] autorelease]; - _end +- (NSArray *) sectionsForPackages:(NSMutableArray *)packages { + Section *prefix([[[Section alloc] initWithName:nil row:0 localize:NO] autorelease]); + size_t end([packages count]); - _profile(PackageTable$reloadData$Section$Add) - [sections_ addObject:section]; - _end - } + NSMutableArray *sections([NSMutableArray arrayWithCapacity:16]); + Section *section(prefix); - [section addToCount]; - } - _end - } else -#endif - { - index_ = [NSMutableArray arrayWithCapacity:32]; + thumbs_ = CollationThumbs_; + offset_ = CollationOffset_; - bool sectioned([self showsSections]); - if (!sectioned) { - section = [[[Section alloc] initWithName:nil localize:false] autorelease]; - [sections_ addObject:section]; - } + size_t offset(0); + size_t offsets([CollationStarts_ count]); - _profile(PackageTable$reloadData$Section) - for (size_t offset(0), end([packages_ count]); offset != end; ++offset) { - Package *package; - unichar index; + NSString *start([CollationStarts_ objectAtIndex:offset]); + size_t length([start length]); - _profile(PackageTable$reloadData$Section$Package) - package = [packages_ objectAtIndex:offset]; - index = [package index]; - _end + for (size_t index(0); index != end; ++index) { + if (start != nil) { + Package *package([packages objectAtIndex:index]); + NSString *name(PackageName(package, @selector(cyname))); - if (sectioned && (section == nil || [section index] != index)) { - _profile(PackageTable$reloadData$Section$Allocate) - section = [[[Section alloc] initWithIndex:index row:offset] autorelease]; - _end + //while ([start compare:name options:NSNumericSearch range:NSMakeRange(0, length) locale:CollationLocale_] != NSOrderedDescending) { + while (StringNameCompare(start, name, length) != kCFCompareGreaterThan) { + NSString *title([CollationTitles_ objectAtIndex:offset]); + section = [[[Section alloc] initWithName:title row:index localize:NO] autorelease]; + [sections addObject:section]; - [index_ addObject:[section name]]; - //[indices_ setObject:[NSNumber numberForInt:[sections_ count]] forKey:index]; + start = ++offset == offsets ? nil : [CollationStarts_ objectAtIndex:offset]; + if (start == nil) + break; + length = [start length]; + } + } - _profile(PackageTable$reloadData$Section$Add) - [sections_ addObject:section]; - _end - } + [section addToCount]; + } - [section addToCount]; - } - _end + for (; offset != offsets; ++offset) { + NSString *title([CollationTitles_ objectAtIndex:offset]); + Section *section([[[Section alloc] initWithName:title row:end localize:NO] autorelease]); + [sections addObject:section]; } - [self updateHeight]; + if ([prefix count] != 0) { + Section *suffix([sections lastObject]); + [prefix setName:[suffix name]]; + [suffix setName:nil]; + [sections insertObject:prefix atIndex:(offsets - 1)]; + } - _profile(PackageTable$reloadData$List) - [(UITableView *) list_ setDataSource:self]; - [list_ reloadData]; - _end -} } + return sections; +} - (void) reloadData { [super reloadData]; @@ -6626,113 +6689,61 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ /* Filtered Package List Controller {{{ */ +typedef Function PackageFilter; +typedef Function PackageSorter; @interface FilteredPackageListController : PackageListController { - SEL filter_; - IMP imp_; - _H object_; - _H stuff_; + PackageFilter filter_; + PackageSorter sorter_; } -- (void) setObject:(id)object; -- (void) setStuff:(id)object; -- (void) setObject:(id)object andStuff:(id)stuff; - -- (void) setObject:(id)object forFilter:(SEL)filter; -- (void) setObject:(id)object andStuff:(id)stuff forFilter:(SEL)filter; - -- (SEL) filter; -- (void) setFilter:(SEL)filter; +- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(PackageFilter)filter; -- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object; +- (void) setFilter:(PackageFilter)filter; +- (void) setSorter:(PackageSorter)sorter; @end @implementation FilteredPackageListController -- (SEL) filter { - return filter_; -} - -- (void) setFilter:(SEL)filter { +- (void) setFilter:(PackageFilter)filter { @synchronized (self) { filter_ = filter; - - /* 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); -} } - -- (void) setObject:(id)object { -@synchronized (self) { - object_ = object; -} } - -- (void) setStuff:(id)stuff { -@synchronized (self) { - stuff_ = stuff; } } -- (void) setObject:(id)object andStuff:(id)stuff { +- (void) setSorter:(PackageSorter)sorter { @synchronized (self) { - object_ = object; - stuff_ = stuff; -} } - -- (void) setObject:(id)object forFilter:(SEL)filter { -@synchronized (self) { - [self setFilter:filter]; - object_ = object; -} } - -- (void) setObject:(id)object andStuff:(id)stuff forFilter:(SEL)filter { -@synchronized (self) { - [self setFilter:filter]; - object_ = object; - stuff_ = stuff; + sorter_ = sorter; } } - (NSMutableArray *) _reloadPackages { @synchronized (database_) { era_ = [database_ era]; - NSArray *packages([database_ packages]); + NSArray *packages([database_ packages]); NSMutableArray *filtered([NSMutableArray arrayWithCapacity:[packages count]]); - IMP imp; - SEL filter; - _H object; - _H stuff; + PackageFilter filter; + PackageSorter sorter; @synchronized (self) { - imp = imp_; filter = filter_; - object = object_; - stuff = stuff_; + sorter = sorter_; } _profile(PackageTable$reloadData$Filter) for (Package *package in packages) - if ([package valid] && (*reinterpret_cast(imp))(package, filter, object, stuff)) + if ([package valid] && filter(package)) [filtered addObject:package]; _end + if (sorter) + sorter(filtered); return filtered; } } -- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object { - if ((self = [super initWithDatabase:database title:title]) != nil) { - [self setFilter:filter]; - object_ = object; - } return self; -} - -- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object with:(id)stuff { +- (id) initWithDatabase:(Database *)database title:(NSString *)title filter:(PackageFilter)filter { if ((self = [super initWithDatabase:database title:title]) != nil) { [self setFilter:filter]; - object_ = object; - stuff_ = stuff; } return self; } @@ -6872,6 +6883,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) beginUpdate { + if (updating_) + return; + UIViewController *controller([[self viewControllers] objectAtIndex:1]); UITabBarItem *item([controller tabBarItem]); @@ -7143,14 +7157,29 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi else title = UCLocalize("NO_SECTION"); - if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:source:) with:section with:source]) != nil) { + if ((self = [super initWithDatabase:database title:title]) != nil) { key_ = [source key]; section_ = section; } return self; } - (void) reloadData { - [super setStuff:[database_ sourceWithKey:key_]]; + Source *source([database_ sourceWithKey:key_]); + _H name(section_); + + [self setFilter:[=](Package *package) { + NSString *section([package section]); + + return ( + name == nil || + section == nil && [name length] == 0 || + [name isEqualToString:section] + ) && ( + source == nil || + [package source] == source + ) && [package visible]; + }]; + [super reloadData]; } @@ -7372,15 +7401,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi /* }}} */ /* Changes Controller {{{ */ -@interface ChangesController : CyteViewController < - UITableViewDataSource, - UITableViewDelegate -> { - _transient Database *database_; - unsigned era_; - _H packages_; - _H sections_; - _H list_; +@interface ChangesController : FilteredPackageListController { unsigned upgrades_; } @@ -7390,30 +7411,12 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi @implementation ChangesController -- (NSURL *) navigationURL { - return [NSURL URLWithString:@"cydia://changes"]; -} - -- (void) viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated]; -} - -- (NSInteger) numberOfSectionsInTableView:(UITableView *)list { - NSInteger count([sections_ count]); - return count == 0 ? 1 : count; -} - -- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section { - if ([sections_ count] == 0) - return nil; - return [[sections_ objectAtIndex:section] name]; +- (NSURL *) referrerURL { + return [NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/changes/", UI_]]; } -- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section { - if ([sections_ count] == 0) - return 0; - return [[sections_ objectAtIndex:section] count]; +- (NSURL *) navigationURL { + return [NSURL URLWithString:@"cydia://changes"]; } - (Package *) packageAtIndexPath:(NSIndexPath *)path { @@ -7429,24 +7432,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi 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]; - - Package *package([database_ packageWithName:[[self packageAtIndexPath:path] id]]); - [cell setPackage:package asSummary:false]; - return cell; -} - -- (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path { - Package *package([self packageAtIndexPath:path]); - CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id] withReferrer:[NSString stringWithFormat:@"%@/#!/changes/", UI_]] autorelease]); - [view setDelegate:delegate_]; - [[self navigationController] pushViewController:view animated:YES]; - return path; -} - - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { NSString *context([alert context]); @@ -7485,84 +7470,48 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [[self navigationItem] setRightBarButtonItem:nil animated:YES]; } -- (void) loadView { - UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]); - [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; - [self setView:view]; - - list_ = [[[UITableView alloc] initWithFrame:[view bounds] style:UITableViewStylePlain] autorelease]; - [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [list_ setRowHeight:73]; - [(UITableView *) list_ setDataSource:self]; - [list_ setDelegate:self]; - [view addSubview:list_]; +- (bool) shouldYield { + return true; } -- (void) viewDidLoad { - [super viewDidLoad]; - - [[self navigationItem] setTitle:UCLocalize("CHANGES")]; +- (bool) shouldBlock { + return true; } -- (void) releaseSubviews { - list_ = nil; - - packages_ = nil; - sections_ = nil; +- (void) useFilter { +@synchronized (self) { + [self setFilter:[](Package *package) { + return [package upgradableAndEssential:YES] || [package visible]; + }]; - [super releaseSubviews]; -} + [self setSorter:[](NSMutableArray *packages) { + [packages radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; + }]; +} } - (id) initWithDatabase:(Database *)database { - if ((self = [super init]) != nil) { - database_ = database; + if ((self = [super initWithDatabase:database title:UCLocalize("CHANGES")]) != nil) { + [self useFilter]; } return self; } -- (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((CFMutableArrayRef) filtered, package); - _end - _trace(); - _profile(ChangesController$_reloadPackages$radixSort) - [filtered radixSortUsingFunction:reinterpret_cast(&PackageChangesRadix) withContext:NULL]; - _end - _trace(); - - return filtered; -} } - -- (void) _reloadData { +- (void) viewDidLoad { + [super viewDidLoad]; [self setLeftBarButtonItem]; +} - NSMutableArray *packages; - - 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]; - } +- (void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + [self setLeftBarButtonItem]; +} -@synchronized (database_) { - if (era_ != [database_ era]) - goto reload; +- (void) reloadData { + [self setLeftBarButtonItem]; + [super reloadData]; +} - packages_ = packages; - sections_ = [NSMutableArray arrayWithCapacity:16]; +- (NSArray *) sectionsForPackages:(NSMutableArray *)packages { + NSMutableArray *sections([NSMutableArray arrayWithCapacity:16]); Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease]; Section *ignored = nil; @@ -7574,8 +7523,8 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle)); - for (size_t offset = 0, count = [packages_ count]; offset != count; ++offset) { - Package *package = [packages_ objectAtIndex:offset]; + for (size_t offset = 0, count = [packages count]; offset != count; ++offset) { + Package *package = [packages objectAtIndex:offset]; BOOL uae = [package upgradableAndEssential:YES]; @@ -7593,7 +7542,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi _profile(ChangesController$reloadData$Allocate) name = [NSString stringWithFormat:UCLocalize("NEW_AT"), name]; section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease]; - [sections_ addObject:section]; + [sections addObject:section]; _end } @@ -7613,16 +7562,16 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi CFRelease(formatter); if (unseens) { - Section *last = [sections_ lastObject]; + Section *last = [sections lastObject]; size_t count = [last count]; - [packages_ removeObjectsInRange:NSMakeRange([packages_ count] - count, count)]; - [sections_ removeLastObject]; + [packages removeObjectsInRange:NSMakeRange([packages count] - count, count)]; + [sections removeLastObject]; } if ([ignored count] != 0) - [sections_ insertObject:ignored atIndex:0]; + [sections insertObject:ignored atIndex:0]; if (upgrades_ != 0) - [sections_ insertObject:upgradable atIndex:0]; + [sections insertObject:upgradable atIndex:0]; [list_ reloadData]; @@ -7633,12 +7582,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi action:@selector(upgradeButtonClicked) ] autorelease]) animated:YES]; - PrintTimes(); -} } - -- (void) reloadData { - [super reloadData]; - [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0]; + return sections; } @end @@ -7649,6 +7593,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi > { _H search_; BOOL searchloaded_; + bool summary_; } - (id) initWithDatabase:(Database *)database query:(NSString *)query; @@ -7679,15 +7624,51 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) useSearch { - [self setObject:[self termsForQuery:[search_ text]] forFilter:@selector(isUnfilteredAndSearchedForBy:)]; + _H query([self termsForQuery:[search_ text]]); + summary_ = false; + +@synchronized (self) { + [self setFilter:[=](Package *package) { + if (![package unfiltered]) + return false; + if (![package matches:query]) + return false; + return true; + }]; + + [self setSorter:[](NSMutableArray *packages) { + [packages radixSortUsingSelector:@selector(rank)]; + }]; +} + [self clearData]; [self reloadData]; } +- (void) usePrefix:(NSString *)prefix { + _H query(prefix); + summary_ = true; + +@synchronized (self) { + [self setFilter:[=](Package *package) { + if ([query length] == 0) + return false; + if (![package unfiltered]) + return false; + if ([[package name] compare:query options:MatchCompareOptions_ range:NSMakeRange(0, [query length])] != NSOrderedSame) + return false; + return true; + }]; + + [self setSorter:nullptr]; +} + + [self reloadData]; +} + - (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar { - [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSelectedForBy:)]; [self clearData]; - [self reloadData]; + [self usePrefix:[search_ text]]; } - (void) searchBarButtonClicked:(UISearchBar *)searchBar { @@ -7705,8 +7686,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)text { - [self setObject:text forFilter:@selector(isUnfilteredAndSelectedForBy:)]; - [self reloadData]; + [self usePrefix:text]; } - (bool) shouldYield { @@ -7714,31 +7694,36 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (bool) shouldBlock { - return [self filter] == @selector(isUnfilteredAndSearchedForBy:); + return !summary_; } - (bool) isSummarized { - return [self filter] == @selector(isUnfilteredAndSelectedForBy:); + return summary_; } - (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:[self termsForQuery:query]])) { + if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH")])) { search_ = [[[UISearchBar alloc] init] autorelease]; + [search_ setPlaceholder:UCLocalize("SEARCH_EX")]; [search_ setDelegate:self]; + UITextField *textField; + if ([search_ respondsToSelector:@selector(searchField)]) + textField = [search_ searchField]; + else + textField = MSHookIvar(search_, "_searchField"); + + [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; + [textField setEnablesReturnKeyAutomatically:NO]; + [[self navigationItem] setTitleView:textField]; + if (query != nil) [search_ setText:query]; + [self useSearch]; } return self; } @@ -7749,17 +7734,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi searchloaded_ = YES; [search_ setFrame:CGRectMake(0, 0, [[self view] bounds].size.width, 44.0f)]; [search_ layoutSubviews]; - [search_ setPlaceholder:UCLocalize("SEARCH_EX")]; - - UITextField *textField; - if ([search_ respondsToSelector:@selector(searchField)]) - textField = [search_ searchField]; - else - textField = MSHookIvar(search_, "_searchField"); - - [textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin]; - [textField setEnablesReturnKeyAutomatically:NO]; - [[self navigationItem] setTitleView:textField]; } if ([self isSummarized]) @@ -7767,13 +7741,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) reloadData { - id object([search_ text]); - if ([self filter] == @selector(isUnfilteredAndSearchedForBy:)) - object = [self termsForQuery:object]; - - [self setObject:object]; [self resetCursor]; - [super reloadData]; } @@ -7959,6 +7927,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi /* Installed Controller {{{ */ @interface InstalledController : FilteredPackageListController { + bool sectioned_; } - (id) initWithDatabase:(Database *)database; @@ -7976,14 +7945,47 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi return [NSURL URLWithString:@"cydia://installed"]; } +- (bool) showsSections { + return sectioned_; +} + +- (void) useUpdated { + sectioned_ = false; + +@synchronized (self) { + [self setFilter:[](Package *package) { + return ![package uninstalled] && package->role_ < 7; + }]; + + [self setSorter:[](NSMutableArray *packages) { + [packages radixSortUsingSelector:@selector(updated)]; + }]; +} } + +- (void) useFilter:(UISegmentedControl *)segmented { + NSInteger selected([segmented selectedSegmentIndex]); + if (selected == 2) + return [self useUpdated]; + bool simple(selected == 0); + sectioned_ = true; + +@synchronized (self) { + [self setFilter:[=](Package *package) { + return ![package uninstalled] && package->role_ <= (simple ? 1 : 3); + }]; + + [self setSorter:nullptr]; +} } + - (id) initWithDatabase:(Database *)database { - if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED") filter:@selector(isInstalledAndUnfiltered:) with:[NSNumber numberWithBool:YES]]) != nil) { - UISegmentedControl *segmented([[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:UCLocalize("SIMPLE"), UCLocalize("EXPERT"), nil]] autorelease]); + if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED")]) != nil) { + UISegmentedControl *segmented([[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:UCLocalize("USER"), UCLocalize("EXPERT"), UCLocalize("RECENT"), nil]] autorelease]); [segmented setSelectedSegmentIndex:0]; [segmented setSegmentedControlStyle:UISegmentedControlStyleBar]; [[self navigationItem] setTitleView:segmented]; [segmented addTarget:self action:@selector(modeChanged:) forEvents:UIControlEventValueChanged]; + [self useFilter:segmented]; [self queueStatusDidChange]; } return self; @@ -8011,8 +8013,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) modeChanged:(UISegmentedControl *)segmented { - bool simple([segmented selectedSegmentIndex] == 0); - [self setObject:[NSNumber numberWithBool:simple]]; + [self useFilter:segmented]; [self reloadData]; } @@ -8156,11 +8157,11 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (!highlighted) UISetColor(Black_); - [origin_ drawAtPoint:CGPointMake(52, 8) forWidth:(width - 61) withFont:Font18Bold_ lineBreakMode:UILineBreakModeTailTruncation]; + [origin_ drawAtPoint:CGPointMake(52, 8) forWidth:(width - 61) withFont:Font18Bold_ lineBreakMode:NSLineBreakByTruncatingTail]; if (!highlighted) UISetColor(Gray_); - [label_ drawAtPoint:CGPointMake(52, 29) forWidth:(width - 61) withFont:Font12_ lineBreakMode:UILineBreakModeTailTruncation]; + [label_ drawAtPoint:CGPointMake(52, 29) forWidth:(width - 61) withFont:Font12_ lineBreakMode:NSLineBreakByTruncatingTail]; } - (void) setFetch:(NSNumber *)fetch { @@ -8302,6 +8303,10 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } } +- (void) tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { + [self updateButtonsForEditingStatusAnimated:YES]; +} + - (void) complete { [delegate_ addTrivialSource:href_]; href_ = nil; @@ -8693,7 +8698,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [caption_ setTextColor:[UIColor whiteColor]]; [caption_ setBackgroundColor:[UIColor clearColor]]; [caption_ setShadowColor:[UIColor blackColor]]; - [caption_ setTextAlignment:UITextAlignmentCenter]; + [caption_ setTextAlignment:NSTextAlignmentCenter]; [view addSubview:caption_]; CGRect statusrect; @@ -8708,7 +8713,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [status_ setTextColor:[UIColor whiteColor]]; [status_ setBackgroundColor:[UIColor clearColor]]; [status_ setShadowColor:[UIColor blackColor]]; - [status_ setTextAlignment:UITextAlignmentCenter]; + [status_ setTextAlignment:NSTextAlignmentCenter]; [view addSubview:status_]; } @@ -8977,6 +8982,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) reloadDataWithInvocation:(NSInvocation *)invocation { +_profile(reloadDataWithInvocation) @synchronized (self) { UIProgressHUD *hud(loaded_ ? [self addProgressHUD] : nil); if (hud != nil) @@ -8989,6 +8995,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [essential_ removeAllObjects]; [broken_ removeAllObjects]; + _profile(reloadDataWithInvocation$Essential) NSArray *packages([database_ packages]); for (Package *package in packages) { if ([package half]) @@ -8999,6 +9006,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi ++changes; } } + _end UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:2] tabBarItem]; if (changes != 0) { @@ -9018,7 +9026,11 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (hud != nil) [self removeProgressHUD:hud]; -} } +} +_end + + PrintTimes(); +} - (void) updateData { [self _updateData]; @@ -9039,10 +9051,13 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (emulated_ == nil) return; - [window_ addSubview:[tabbar_ view]]; if ([window_ respondsToSelector:@selector(setRootViewController:)]) [window_ setRootViewController:tabbar_]; - [[emulated_ view] removeFromSuperview]; + else { + [window_ addSubview:[tabbar_ view]]; + [[emulated_ view] removeFromSuperview]; + } + emulated_ = nil; [window_ setUserInteractionEnabled:YES]; } @@ -9329,6 +9344,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi return false; } + if ([tabbar_ modalViewController] != nil) + return false; + // Use external process status API internally. // This is probably a really bad idea. // XXX: what is the point of this? does this solve anything at all? @@ -9732,9 +9750,10 @@ _trace(); [self setupViewControllers]; emulated_ = [[[CydiaLoadingViewController alloc] init] autorelease]; - [window_ addSubview:[emulated_ view]]; if ([window_ respondsToSelector:@selector(setRootViewController:)]) [window_ setRootViewController:emulated_]; + else + [window_ addSubview:[emulated_ view]]; [self performSelector:@selector(loadData) withObject:nil afterDelay:0]; _trace(); @@ -9758,8 +9777,6 @@ _trace(); [self reloadDataWithInvocation:nil]; [self refreshIfPossible]; - PrintTimes(); - [self disemulate]; int savedIndex = [[Metadata_ objectForKey:@"InterfaceIndex"] intValue]; @@ -9822,7 +9839,7 @@ _trace(); // (Try to) show the startup URL. if (starturl_ != nil) { - [self openCydiaURL:starturl_ forExternal:NO]; + [self openCydiaURL:starturl_ forExternal:YES]; starturl_ = nil; } } @@ -9886,10 +9903,15 @@ Class $CFXPreferencesPropertyListSource; MSHook(BOOL, CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync, CFXPreferencesPropertyListSource *self, SEL _cmd) { NSURL *&url(MSHookIvar(self, "_url")), *old(url); NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); + url = MobilizeURL(url); - BOOL value(_CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync(self, _cmd)); - //NSLog(@"%@ %s", [url absoluteString], value ? "YES" : "NO"); - url = old; + BOOL value; @try { + value = _CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync(self, _cmd); + //NSLog(@"CFX %@ %s", [url absoluteString], value ? "YES" : "NO"); + } @finally { + url = old; + } + [pool release]; return value; } @@ -9897,10 +9919,15 @@ MSHook(BOOL, CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync, MSHook(void *, CFXPreferencesPropertyListSource$createPlistFromDisk, CFXPreferencesPropertyListSource *self, SEL _cmd) { NSURL *&url(MSHookIvar(self, "_url")), *old(url); NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); + url = MobilizeURL(url); - void *value(_CFXPreferencesPropertyListSource$createPlistFromDisk(self, _cmd)); - //NSLog(@"%@ %@", [url absoluteString], value); - url = old; + void *value; @try { + value = _CFXPreferencesPropertyListSource$createPlistFromDisk(self, _cmd); + //NSLog(@"CFX %@ %@", [url absoluteString], value); + } @finally { + url = old; + } + [pool release]; return value; } @@ -10020,7 +10047,9 @@ int main(int argc, char *argv[]) { if (Method method = class_getInstanceMethod($WAKWindow, @selector(screenSize))) method_setImplementation(method, (IMP) &$WAKWindow$screenSize); - $CFXPreferencesPropertyListSource = objc_getClass("CFXPreferencesPropertyListSource"); + $CFXPreferencesPropertyListSource = objc_getClass("CFXPreferencesPropertyListSourceSynchronizer"); + if ($CFXPreferencesPropertyListSource == Nil) + $CFXPreferencesPropertyListSource = objc_getClass("CFXPreferencesPropertyListSource"); Method CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync(class_getInstanceMethod($CFXPreferencesPropertyListSource, @selector(_backingPlistChangedSinceLastSync))); if (CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync != NULL) { @@ -10076,6 +10105,44 @@ int main(int argc, char *argv[]) { std::setlocale(LC_ALL, lang); } /* }}} */ + /* Index Collation {{{ */ + if (Class $UILocalizedIndexedCollation = objc_getClass("UILocalizedIndexedCollation")) { + NSBundle *bundle([NSBundle bundleForClass:$UILocalizedIndexedCollation]); + NSString *path([bundle pathForResource:@"UITableViewLocalizedSectionIndex" ofType:@"plist"]); + //path = @"/System/Library/Frameworks/UIKit.framework/.lproj/UITableViewLocalizedSectionIndex.plist"; + NSDictionary *dictionary([NSDictionary dictionaryWithContentsOfFile:path]); + _H collation([[[UILocalizedIndexedCollation alloc] initWithDictionary:dictionary] autorelease]); + + CollationLocale_ = MSHookIvar(collation, "_locale"); + + CollationThumbs_ = [collation sectionIndexTitles]; + for (size_t index(0), end([CollationThumbs_ count]); index != end; ++index) + CollationOffset_.push_back([collation sectionForSectionIndexTitleAtIndex:index]); + + CollationTitles_ = [collation sectionTitles]; + CollationStarts_ = MSHookIvar(collation, "_sectionStartStrings"); + + NSString *&transform(MSHookIvar(collation, "_transform")); + if (&transform != NULL && transform != nil) { + /*if ([collation respondsToSelector:@selector(transformedCollationStringForString:)]) + CollationModify_ = [=](NSString *value) { return [collation transformedCollationStringForString:value]; };*/ + const UChar *uid(reinterpret_cast([transform cStringUsingEncoding:NSUnicodeStringEncoding])); + UErrorCode code(U_ZERO_ERROR); + CollationTransl_ = utrans_openU(uid, -1, UTRANS_FORWARD, NULL, 0, NULL, &code); + if (!U_SUCCESS(code)) + NSLog(@"%s", u_errorName(code)); + } + } else { + CollationLocale_ = [[[NSLocale alloc] initWithLocaleIdentifier:@"en@collation=dictionary"] autorelease]; + + CollationThumbs_ = [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#",nil]; + for (NSInteger offset(0); offset != 28; ++offset) + CollationOffset_.push_back(offset); + + CollationTitles_ = [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#",nil]; + CollationStarts_ = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",@"ʒ",nil]; + } + /* }}} */ apr_app_initialize(&argc, const_cast(&argv), NULL);