#include "CyteKit/UCPlatform.h"
#include "CyteKit/Localize.h"
+#include <unicode/ustring.h>
+#include <unicode/utrans.h>
+
#include <objc/objc.h>
#include <objc/runtime.h>
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;
}
#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)
#define ManualRefresh (1 && !ForRelease)
#define ShowInternals (0 && !ForRelease)
#define AlwaysReload (0 && !ForRelease)
-#define TryIndexedCollation (0 && !ForRelease)
#if !TraceLogging
#undef _trace
/* 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 {{{ */
static _H<NSString> Product_;
static _H<NSString> Safari_;
+static _H<NSLocale> CollationLocale_;
+static _H<NSArray> CollationThumbs_;
+static std::vector<NSInteger> CollationOffset_;
+static _H<NSArray> CollationTitles_;
+static _H<NSArray> CollationStarts_;
+static UTransliterator *CollationTransl_;
+//static Function<NSString *, NSString *> CollationModify_;
+
+typedef std::basic_string<UChar> ustring;
+static ustring CollationString_;
+
+#define CUC const ustring &str(*reinterpret_cast<const ustring *>(rep))
+#define UC ustring &str(*reinterpret_cast<ustring *>(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_;
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))
base_.set(pool, file);
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);
files_.insert(file + ".gz");
files_.insert(file + "Index");
}
+ _end
FileFd fd;
if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly))
database_ = database;
index_ = index;
+ _profile(Source$initWithMetaIndex$setMetaIndex)
[self setMetaIndex:index inPool:pool];
+ _end
} return self;
}
CYString id_;
CYString name_;
+ CYString transform_;
CYString latest_;
CYString installed_;
- time_t updated_;
+ time_t upgraded_;
const char *section_;
_transient NSString *section$_;
return _not(uint32_t) - value.key;
}
+CYString &(*PackageName)(Package *self, SEL sel);
+
uint32_t PackagePrefixRadix(Package *self, void *context) {
size_t offset(reinterpret_cast<size_t>(context));
- CYString &name([self cyname]);
+ CYString &name(PackageName(self, @selector(cyname)));
size_t size(name.size());
if (size == 0)
return OSSwapInt32(*reinterpret_cast<uint32_t *>(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 ? kCFCompareEqualTo : kCFCompareLessThan;
else if (rhn == NULL)
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));
}
_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 :
@"state",
@"support",
@"tags",
+ @"upgraded",
@"warnings",
nil];
}
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<const uint8_t *>(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<UReplaceable *>(&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<char *>(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()) {
memcpy(lower + prefix + size, ".list", 6);
struct stat info;
if (stat(lower, &info) != -1)
- updated_ = info.st_birthtime;
+ upgraded_ = info.st_birthtime;
}
PackageValue *metadata(PackageFind(lower + prefix, size));
bool user = false;
bool _private = false;
bool stash = false;
+ bool dsstore = false;
bool repository = [[self section] isEqualToString:@"Repositories"];
_private = true;
else if (!stash && [file isEqualToString:@"/var/stash"])
stash = true;
+ else if (!dsstore && [file hasSuffix:@"/.DS_Store"])
+ dsstore = true;
/* XXX: this is not sensitive enough. only some folders are valid. */
if (cydia && !repository)
[warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/private"]];
if (stash)
[warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/var/stash"]];
+ if (dsstore)
+ [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @".DS_Store"]];
}
return [warnings count] == 0 ? nil : warnings;
return source_ == (Source *) [NSNull null] ? nil : source_;
}
+- (time_t) upgraded {
+ return upgraded_;
+}
+
+- (uint32_t) recent {
+ return std::numeric_limits<uint32_t>::max() - upgraded_;
+}
+
- (uint32_t) rank {
return rank_;
}
string = [self name];
length = [string length];
+ if (length != 0)
for (NSString *term in query) {
range = [string rangeOfString:term options:MatchCompareOptions_];
if (range.location != NSNotFound)
string = [self id];
length = [string length];
+ if (length != 0)
for (NSString *term in query) {
range = [string rangeOfString:term options:MatchCompareOptions_];
if (range.location != NSNotFound)
length = [string length];
NSUInteger stop(std::min<NSUInteger>(length, 200));
+ if (length != 0)
for (NSString *term in query) {
range = [string rangeOfString:term options:MatchCompareOptions_ range:NSMakeRange(0, stop)];
if (range.location != NSNotFound)
}
- (CYString &) cyname {
- return name_.empty() ? id_ : name_;
+ return !transform_.empty() ? transform_ : !name_.empty() ? name_ : id_;
}
- (uint32_t) compareBySection:(NSArray *)sections {
/* Section Class {{{ */
@interface Section : NSObject {
_H<NSString> name_;
- unichar index_;
size_t row_;
size_t count_;
_H<NSString> localized_;
- (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;
- (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 {
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;
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_) {
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];
packages_ = [[NSArray alloc] initWithObjects:&packages.front() count:packages.size()];
_trace();*/
- [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(16)];
+ _profile(reloadDataWithInvocation$radix$8)
+ [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(8)];
+ _end
+
+ _profile(reloadDataWithInvocation$radix$4)
[(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(4)];
- [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(0)];
+ _end
- /*_trace();
- PrintTimes();
- _trace();*/
+ _profile(reloadDataWithInvocation$radix$0)
+ [(NSMutableArray *) packages_ radixSortUsingFunction:reinterpret_cast<MenesRadixSortFunction>(&PackagePrefixRadix) withContext:reinterpret_cast<void *>(0)];
+ _end
- _trace();
+ _profile(reloadDataWithInvocation$insertion)
+ CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare), NULL);
+ _end
- /*if (!packages.empty())
- CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare_), NULL);*/
- //std::sort(packages.begin(), packages.end(), PackageNameOrdering());
+ /*_profile(reloadDataWithInvocation$CFQSortArray)
+ CFQSortArray(&packages.front(), packages.size(), sizeof(packages.front()), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare_), NULL);
+ _end*/
- //CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare), NULL);
+ /*_profile(reloadDataWithInvocation$stdsort)
+ std::sort(packages.begin(), packages.end(), PackageNameOrdering());
+ _end*/
- CFArrayInsertionSortValues(packages_, CFRangeMake(0, CFArrayGetCount(packages_)), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare), NULL);
+ /*_profile(reloadDataWithInvocation$CFArraySortValues)
+ CFArraySortValues((CFMutableArrayRef) packages_, CFRangeMake(0, [packages_ count]), reinterpret_cast<CFComparatorFunction>(&PackageNameCompare), NULL);
+ _end*/
- //[packages_ sortUsingFunction:reinterpret_cast<NSComparisonResult (*)(id, id, void *)>(&PackageNameCompare) context:NULL];
+ /*_profile(reloadDataWithInvocation$sortUsingFunction)
+ [packages_ sortUsingFunction:reinterpret_cast<NSComparisonResult (*)(id, id, void *)>(&PackageNameCompare) context:NULL];
+ _end*/
- _trace();
size_t count(CFArrayGetCount(packages_));
MetaFile_->active_ = count;
-
for (size_t index(0); index != count; ++index)
[(Package *) CFArrayGetValueAtIndex(packages_, index) setIndex:index];
-
- _trace();
}
} }
_H<NSArray> packages_;
_H<NSArray> sections_;
_H<UITableView, 2> list_;
- _H<NSMutableArray> index_;
+
+ _H<NSArray> thumbs_;
+ std::vector<NSInteger> offset_;
+
_H<NSString> title_;
unsigned reloading_;
}
[[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;
}
- (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 {
packages_ = nil;
sections_ = nil;
- index_ = nil;
+
+ thumbs_ = nil;
+ offset_.clear();
[super releaseSubviews];
}
goto reload;
reloading_ = 0;
+ thumbs_ = nil;
+ offset_.clear();
+
packages_ = packages;
- sections_ = [self sectionsForPackages:packages];
+
+ 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];
+ }
[self updateHeight];
[(UITableView *) list_ setDataSource:self];
[list_ reloadData];
_end
-} }
+}
+
+ PrintTimes();
+}
- (NSArray *) sectionsForPackages:(NSMutableArray *)packages {
+ Section *prefix([[[Section alloc] initWithName:nil row:0 localize:NO] autorelease]);
+ size_t end([packages count]);
+
NSMutableArray *sections([NSMutableArray arrayWithCapacity:16]);
+ Section *section(prefix);
- Section *section = nil;
+ thumbs_ = CollationThumbs_;
+ offset_ = CollationOffset_;
-#if TryIndexedCollation
- if ([[self class] hasIndexedCollation]) {
- index_ = [[objc_getClass("UILocalizedIndexedCollation") currentCollation] sectionIndexTitles];
+ size_t offset(0);
+ size_t offsets([CollationStarts_ count]);
- id collation = [objc_getClass("UILocalizedIndexedCollation") currentCollation];
- NSArray *titles = [collation sectionIndexTitles];
- int secidx = -1;
+ NSString *start([CollationStarts_ objectAtIndex:offset]);
+ size_t length([start length]);
- _profile(PackageTable$reloadData$Section)
- for (size_t offset(0), end([packages count]); offset != end; ++offset) {
- Package *package;
- int index;
+ for (size_t index(0); index != end; ++index) {
+ if (start != nil) {
+ Package *package([packages objectAtIndex:index]);
+ NSString *name(PackageName(package, @selector(cyname)));
- _profile(PackageTable$reloadData$Section$Package)
- package = [packages objectAtIndex:offset];
- index = [collation sectionForObject:package collationStringSelector:@selector(name)];
- _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];
- while (secidx < index) {
- secidx += 1;
-
- _profile(PackageTable$reloadData$Section$Allocate)
- section = [[[Section alloc] initWithName:[titles objectAtIndex:secidx] row:offset localize:NO] autorelease];
- _end
-
- _profile(PackageTable$reloadData$Section$Add)
- [sections addObject:section];
- _end
- }
-
- [section addToCount];
+ start = ++offset == offsets ? nil : [CollationStarts_ objectAtIndex:offset];
+ if (start == nil)
+ break;
+ length = [start length];
}
- _end
- } else
-#endif
- {
- index_ = [NSMutableArray arrayWithCapacity:32];
-
- bool sectioned([self showsSections]);
- if (!sectioned) {
- section = [[[Section alloc] initWithName:nil localize:false] autorelease];
- [sections addObject:section];
}
- _profile(PackageTable$reloadData$Section)
- for (size_t offset(0), end([packages count]); offset != end; ++offset) {
- Package *package;
- unichar index;
-
- _profile(PackageTable$reloadData$Section$Package)
- package = [packages objectAtIndex:offset];
- index = [package index];
- _end
-
- if (sectioned && (section == nil || [section index] != index)) {
- _profile(PackageTable$reloadData$Section$Allocate)
- section = [[[Section alloc] initWithIndex:index row:offset] autorelease];
- _end
-
- [index_ addObject:[section name]];
+ [section addToCount];
+ }
- _profile(PackageTable$reloadData$Section$Add)
- [sections addObject:section];
- _end
- }
+ for (; offset != offsets; ++offset) {
+ NSString *title([CollationTitles_ objectAtIndex:offset]);
+ Section *section([[[Section alloc] initWithName:title row:end localize:NO] autorelease]);
+ [sections addObject:section];
+ }
- [section addToCount];
- }
- _end
+ if ([prefix count] != 0) {
+ Section *suffix([sections lastObject]);
+ [prefix setName:[suffix name]];
+ [suffix setName:nil];
+ [sections insertObject:prefix atIndex:(offsets - 1)];
}
return sections;
} return self;
}
+- (void) viewDidLoad {
+ [super viewDidLoad];
+ [self setLeftBarButtonItem];
+}
+
+- (void) viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+ [self setLeftBarButtonItem];
+}
+
- (void) reloadData {
[self setLeftBarButtonItem];
[super reloadData];
action:@selector(upgradeButtonClicked)
] autorelease]) animated:YES];
- PrintTimes();
return sections;
}
/* Installed Controller {{{ */
@interface InstalledController : FilteredPackageListController {
+ bool sectioned_;
}
- (id) initWithDatabase:(Database *)database;
return [NSURL URLWithString:@"cydia://installed"];
}
+- (void) useRecent {
+ sectioned_ = false;
+
+@synchronized (self) {
+ [self setFilter:[](Package *package) {
+ return ![package uninstalled] && package->role_ < 7;
+ }];
+
+ [self setSorter:[](NSMutableArray *packages) {
+ [packages radixSortUsingSelector:@selector(recent)];
+ }];
+} }
+
- (void) useFilter:(UISegmentedControl *)segmented {
- bool simple([segmented selectedSegmentIndex] == 0);
+ NSInteger selected([segmented selectedSegmentIndex]);
+ if (selected == 2)
+ return [self useRecent];
+ bool simple(selected == 0);
+ sectioned_ = true;
@synchronized (self) {
[self setFilter:[=](Package *package) {
return ![package uninstalled] && package->role_ <= (simple ? 1 : 3);
}];
+
+ [self setSorter:nullptr];
} }
+- (NSArray *) sectionsForPackages:(NSMutableArray *)packages {
+ if (sectioned_)
+ return [super sectionsForPackages:packages];
+
+ CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterLongStyle, kCFDateFormatterNoStyle));
+
+ NSMutableArray *sections([NSMutableArray arrayWithCapacity:16]);
+ Section *section(nil);
+ time_t last(0);
+
+ for (size_t offset(0), count([packages count]); offset != count; ++offset) {
+ Package *package([packages objectAtIndex:offset]);
+
+ time_t upgraded([package upgraded]);
+ if (upgraded < 1168364520)
+ upgraded = 0;
+ else
+ upgraded -= upgraded % (60 * 60 * 24);
+
+ if (section == nil || upgraded != last) {
+ last = upgraded;
+
+ NSString *name;
+ if (upgraded == 0)
+ continue; // XXX: name = UCLocalize("...");
+ else {
+ name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) [NSDate dateWithTimeIntervalSince1970:upgraded]);
+ [name autorelease];
+ }
+
+ section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease];
+ [sections addObject:section];
+ }
+
+ [section addToCount];
+ }
+
+ CFRelease(formatter);
+ return sections;
+}
+
- (id) initWithDatabase:(Database *)database {
if ((self = [super initWithDatabase:database title:UCLocalize("INSTALLED")]) != nil) {
- UISegmentedControl *segmented([[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:UCLocalize("SIMPLE"), UCLocalize("EXPERT"), nil]] autorelease]);
+ 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];
static Pcre href_r("^http(s?)://[^# ]*$");
if (!href_r(href)) {
UIAlertView *alert = [[[UIAlertView alloc]
- initWithTitle:Error_
- message:UCLocalize("INVALID_URL")
+ initWithTitle:[NSString stringWithFormat:Colon_, Error_, UCLocalize("INVALID_URL")]
+ message:UCLocalize("INVALID_URL_EX")
delegate:self
cancelButtonTitle:UCLocalize("OK")
otherButtonTitles:nil
}
- (void) reloadDataWithInvocation:(NSInvocation *)invocation {
+_profile(reloadDataWithInvocation)
@synchronized (self) {
UIProgressHUD *hud(loaded_ ? [self addProgressHUD] : nil);
if (hud != nil)
[essential_ removeAllObjects];
[broken_ removeAllObjects];
+ _profile(reloadDataWithInvocation$Essential)
NSArray *packages([database_ packages]);
for (Package *package in packages) {
if ([package half])
++changes;
}
}
+ _end
UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:2] tabBarItem];
if (changes != 0) {
if (hud != nil)
[self removeProgressHUD:hud];
-} }
+}
+_end
+
+ PrintTimes();
+}
- (void) updateData {
[self _updateData];
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];
}
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?
[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();
[self reloadDataWithInvocation:nil];
[self refreshIfPossible];
- PrintTimes();
-
[self disemulate];
int savedIndex = [[Metadata_ objectForKey:@"InterfaceIndex"] intValue];
// (Try to) show the startup URL.
if (starturl_ != nil) {
- [self openCydiaURL:starturl_ forExternal:NO];
+ [self openCydiaURL:starturl_ forExternal:YES];
starturl_ = nil;
}
}
MSHook(BOOL, CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync, CFXPreferencesPropertyListSource *self, SEL _cmd) {
NSURL *&url(MSHookIvar<NSURL *>(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;
}
MSHook(void *, CFXPreferencesPropertyListSource$createPlistFromDisk, CFXPreferencesPropertyListSource *self, SEL _cmd) {
NSURL *&url(MSHookIvar<NSURL *>(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;
}
PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
MobilizedFiles_ = [NSMutableSet setWithObjects:
+ @"Library/Preferences/.GlobalPreferences.plist",
@"Library/Preferences/com.apple.Accessibility.plist",
@"Library/Preferences/com.apple.preferences.sounds.plist",
nil];
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) {
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<UILocalizedIndexedCollation> collation([[[UILocalizedIndexedCollation alloc] initWithDictionary:dictionary] autorelease]);
+
+ CollationLocale_ = MSHookIvar<NSLocale *>(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<NSArray *>(collation, "_sectionStartStrings");
+
+ NSString *&transform(MSHookIvar<NSString *>(collation, "_transform"));
+ if (&transform != NULL && transform != nil) {
+ /*if ([collation respondsToSelector:@selector(transformedCollationStringForString:)])
+ CollationModify_ = [=](NSString *value) { return [collation transformedCollationStringForString:value]; };*/
+ const UChar *uid(reinterpret_cast<const UChar *>([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<const char * const **>(&argv), NULL);