#include <apt-pkg/cachefile.h>
#include <apt-pkg/clean.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/debindexfile.h>
#include <apt-pkg/debmetaindex.h>
#include <apt-pkg/error.h>
#include <apt-pkg/init.h>
#define ForRelease 0
#define ForSaurik (0 && !ForRelease)
#define LogBrowser (1 && !ForRelease)
+#define TrackResize (0 && !ForRelease)
#define ManualRefresh (1 && !ForRelease)
#define ShowInternals (0 && !ForRelease)
#define IgnoreInstall (0 && !ForRelease)
static const NSString *Safari_ = nil;
CFLocaleRef Locale_;
+NSArray *Languages_;
CGColorSpaceRef space_;
bool bootstrap_;
return [NSString stringWithFormat:@"%s%.1f %s", (negative ? "-" : ""), size, powers_[power]];
}
+NSString *StripVersion(const char *version) {
+ const char *colon(strchr(version, ':'));
+ if (colon != NULL)
+ version = colon + 1;
+ return [NSString stringWithUTF8String:version];
+}
+
NSString *StripVersion(NSString *version) {
NSRange colon = [version rangeOfString:@":"];
if (colon.location != NSNotFound)
}
NSString *LocalizeSection(NSString *section) {
- return section;
+ static Pcre title_r("^(.*?) \\((.*)\\)$");
+ if (title_r(section))
+ return [NSString stringWithFormat:CYLocalize("PARENTHETICAL"),
+ LocalizeSection(title_r[1]),
+ LocalizeSection(title_r[2])
+ ];
+
+ return [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"];
}
NSString *Simplify(NSString *title) {
if (paren_r(data, size))
return Simplify(paren_r[1]);
- static Pcre title_r("^(.*?) \\(.*\\)$");
+ static Pcre title_r("^(.*?) \\((.*)\\)$");
if (title_r(data, size))
return Simplify(title_r[1]);
- (void) updateWithStatus:(Status &)status;
- (void) setDelegate:(id)delegate;
-- (Source *) getSource:(const pkgCache::PkgFileIterator &)file;
+- (Source *) getSource:(pkgCache::PkgFileIterator)file;
@end
/* }}} */
@interface Package : NSObject {
unsigned era_;
+ pkgCache::VerIterator version_;
pkgCache::PkgIterator iterator_;
_transient Database *database_;
- pkgCache::VerIterator version_;
pkgCache::VerFileIterator file_;
Source *source_;
NSMutableDictionary *metadata_;
}
-- (Package *) initWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
+- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
- (pkgCache::PkgIterator) iterator;
if (section$_ != nil)
[section$_ release];
- [latest_ release];
+ if (latest_ != nil)
+ [latest_ release];
if (installed_ != nil)
[installed_ release];
- [id_ release];
+ if (id_ != nil)
+ [id_ release];
if (sponsor$_ != nil)
[sponsor$_ release];
if (author$_ != nil)
return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
-- (Package *) initWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
+- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
if ((self = [super init]) != nil) {
- _profile(Package$initWithIterator)
+ _profile(Package$initWithVersion)
@synchronized (database) {
era_ = [database era];
- iterator_ = iterator;
+ version_ = version;
+ iterator_ = version.ParentPkg();
database_ = database;
- _profile(Package$initWithIterator$Control)
- _end
-
- _profile(Package$initWithIterator$Version)
- version_ = [database_ policy]->GetCandidateVer(iterator_);
- _end
-
- NSString *latest = version_.end() ? nil : [NSString stringWithUTF8String:version_.VerStr()];
-
- _profile(Package$initWithIterator$Latest)
- latest_ = latest == nil ? nil : [StripVersion(latest) retain];
- _end
-
- pkgCache::VerIterator current;
- NSString *installed;
-
- _profile(Package$initWithIterator$Current)
- current = iterator_.CurrentVer();
- installed = current.end() ? nil : [NSString stringWithUTF8String:current.VerStr()];
+ _profile(Package$initWithVersion$Latest)
+ latest_ = [StripVersion(version_.VerStr()) retain];
_end
- _profile(Package$initWithIterator$Installed)
- installed_ = [StripVersion(installed) retain];
- _end
+ pkgCache::VerIterator current(iterator_.CurrentVer());
+ if (!current.end())
+ installed_ = [StripVersion(current.VerStr()) retain];
- _profile(Package$initWithIterator$File)
- if (!version_.end())
- file_ = version_.FileList();
- else {
- pkgCache &cache([database_ cache]);
- file_ = pkgCache::VerFileIterator(cache, cache.VerFileP);
- }
- _end
+ if (!version_.end())
+ file_ = version_.FileList();
+ else {
+ pkgCache &cache([database_ cache]);
+ file_ = pkgCache::VerFileIterator(cache, cache.VerFileP);
+ }
- _profile(Package$initWithIterator$Name)
+ _profile(Package$initWithVersion$Name)
id_ = [[NSString stringWithUTF8String:iterator_.Name()] retain];
_end
if (!file_.end())
- _profile(Package$initWithIterator$Parse)
+ source_ = [database_ getSource:file_.File()];
+ if (source_ != nil)
+ [source_ retain];
+ cached_ = true;
+
+ _profile(Package$initWithVersion$Parse)
pkgRecords::Parser *parser;
- _profile(Package$initWithIterator$Parse$Lookup)
+ _profile(Package$initWithVersion$Parse$Lookup)
parser = &[database_ records]->Lookup(file_);
_end
- const char *begin, *end;
- parser->GetRec(begin, end);
-
CYString website;
CYString tag;
- struct {
- const char *name_;
- CYString *value_;
- } names[] = {
- {"name", &name_},
- {"icon", &icon_},
- {"depiction", &depiction_},
- {"homepage", &homepage_},
- {"website", &website},
- {"support", &support_},
- {"sponsor", &sponsor_},
- {"author", &author_},
- {"tag", &tag},
- };
-
- while (begin != end)
- if (*begin == '\n') {
- ++begin;
- continue;
- } else if (isblank(*begin)) next: {
- begin = static_cast<char *>(memchr(begin + 1, '\n', end - begin - 1));
- if (begin == NULL)
- break;
- } else if (const char *colon = static_cast<char *>(memchr(begin, ':', end - begin))) {
- const char *name(begin);
- size_t size(colon - begin);
-
- begin = static_cast<char *>(memchr(begin, '\n', end - begin));
-
- {
- const char *stop(begin == NULL ? end : begin);
- while (stop[-1] == '\r')
- --stop;
- while (++colon != stop && isblank(*colon));
-
- for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i)
- if (strncasecmp(names[i].name_, name, size) == 0) {
- CYString &value(*names[i].value_);
-
- _profile(Package$initWithIterator$Parse$Value)
- value.set(pool, colon, stop - colon);
- _end
-
- break;
- }
+ _profile(Package$initWithVersion$Parse$Find)
+ struct {
+ const char *name_;
+ CYString *value_;
+ } names[] = {
+ {"name", &name_},
+ {"icon", &icon_},
+ {"depiction", &depiction_},
+ {"homepage", &homepage_},
+ {"website", &website},
+ {"support", &support_},
+ {"sponsor", &sponsor_},
+ {"author", &author_},
+ {"tag", &tag},
+ };
+
+ for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
+ const char *start, *end;
+
+ if (parser->Find(names[i].name_, start, end)) {
+ CYString &value(*names[i].value_);
+ _profile(Package$initWithVersion$Parse$Value)
+ value.set(pool, start, end - start);
+ _end
}
+ }
+ _end
- if (begin == NULL)
- break;
- ++begin;
- } else goto next;
-
- _profile(Package$initWithIterator$Parse$Tagline)
+ _profile(Package$initWithVersion$Parse$Tagline)
tagline_.set(pool, parser->ShortDesc());
_end
- _profile(Package$initWithIterator$Parse$Retain)
+ _profile(Package$initWithVersion$Parse$Retain)
if (!homepage_.empty())
homepage_ = website;
if (homepage_ == depiction_)
_end
_end
- _profile(Package$initWithIterator$Tags)
+ _profile(Package$initWithVersion$Tags)
if (tags_ != nil)
for (NSString *tag in tags_)
if ([tag hasPrefix:@"role::"]) {
}
_end
- NSString *solid(latest == nil ? installed : latest);
bool changed(false);
-
NSString *key([id_ lowercaseString]);
- _profile(Package$initWithIterator$Metadata)
+ _profile(Package$initWithVersion$Metadata)
metadata_ = [Packages_ objectForKey:key];
if (metadata_ == nil) {
metadata_ = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
now_, @"FirstSeen",
nil] mutableCopy];
- if (solid != nil)
- [metadata_ setObject:solid forKey:@"LastVersion"];
+ [metadata_ setObject:latest_ forKey:@"LastVersion"];
changed = true;
} else {
NSDate *first([metadata_ objectForKey:@"FirstSeen"]);
changed = true;
}
- if (solid != nil)
- if (version == nil) {
- [metadata_ setObject:solid forKey:@"LastVersion"];
- changed = true;
- } else if (![version isEqualToString:solid]) {
- [metadata_ setObject:solid forKey:@"LastVersion"];
- last = now_;
- [metadata_ setObject:last forKey:@"LastSeen"];
- changed = true;
- }
+ if (version == nil) {
+ [metadata_ setObject:latest_ forKey:@"LastVersion"];
+ changed = true;
+ } else if (![version isEqualToString:latest_]) {
+ [metadata_ setObject:latest_ forKey:@"LastVersion"];
+ last = now_;
+ [metadata_ setObject:last forKey:@"LastSeen"];
+ changed = true;
+ }
}
metadata_ = [metadata_ retain];
}
_end
- _profile(Package$initWithIterator$Section)
+ _profile(Package$initWithVersion$Section)
section_.set(pool, iterator_.Section());
_end
}
+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
+ pkgCache::VerIterator version;
+
+ _profile(Package$packageWithIterator$GetCandidateVer)
+ version = [database policy]->GetCandidateVer(iterator);
+ _end
+
+ if (version.end())
+ return nil;
+
return [[[Package alloc]
- initWithIterator:iterator
+ initWithVersion:version
withZone:zone
inPool:pool
database:database
NSString *lhs = [self name];
NSString *rhs = [package name];
- /*if ([lhs length] != 0 && [rhs length] != 0) {
+ if ([lhs length] != 0 && [rhs length] != 0) {
unichar lhc = [lhs characterAtIndex:0];
unichar rhc = [rhs characterAtIndex:0];
return NSOrderedDescending;
}
- return [lhs compare:rhs options:LaxCompareOptions_];*/
-
- return [lhs compare:rhs];
+ return [lhs compare:rhs options:LaxCompareOptions_];
}
- (uint32_t) compareBySection:(NSArray *)sections {
name_ = [name retain];
index_ = '\0';
row_ = row;
- localized_ = LocalizeSection(name_);
+ localized_ = [LocalizeSection(name_) retain];
} return self;
}
apr_pool_clear(pool_);
NSRecycleZone(zone_);
+ int chk(creat("/tmp/cydia.chk", 0644));
+ if (chk != -1)
+ close(chk);
+
_trace();
if (!cache_.Open(progress_, true)) {
std::string error;
}
_trace();
+ unlink("/tmp/cydia.chk");
+
now_ = [[NSDate date] retain];
policy_ = new pkgDepCache::Policy();
_assert(pkgMinimizeUpgrade(cache_));
}
- [sources_ removeAllObjects];
- for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
- std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
- for (std::vector<pkgIndexFile *>::const_iterator index = indices->begin(); index != indices->end(); ++index)
- [sources_
- setObject:[[[Source alloc] initWithMetaIndex:*source] autorelease]
- forKey:[NSNumber numberWithLong:reinterpret_cast<uintptr_t>(*index)]
- ];
+ _trace();
+ {
+ std::string lists(_config->FindDir("Dir::State::lists"));
+
+ [sources_ removeAllObjects];
+ for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
+ std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();
+ for (std::vector<pkgIndexFile *>::const_iterator index = indices->begin(); index != indices->end(); ++index)
+ if (debPackagesIndex *packages = dynamic_cast<debPackagesIndex *>(*index))
+ [sources_
+ setObject:[[[Source alloc] initWithMetaIndex:*source] autorelease]
+ forKey:[NSString stringWithFormat:@"%s%s",
+ lists.c_str(),
+ URItoFileName(packages->IndexURI("Packages")).c_str()
+ ]
+ ];
+ }
}
+ _trace();
[packages_ removeAllObjects];
_trace();
progress_.setDelegate(delegate);
}
-- (Source *) getSource:(const pkgCache::PkgFileIterator &)file {
- pkgIndexFile *index(NULL);
- list_->FindIndex(file, index);
- return [sources_ objectForKey:[NSNumber numberWithLong:reinterpret_cast<uintptr_t>(index)]];
+- (Source *) getSource:(pkgCache::PkgFileIterator)file {
+ if (const char *name = file.FileName())
+ if (Source *source = [sources_ objectForKey:[NSString stringWithUTF8String:name]])
+ return source;
+ return nil;
}
@end
from = [NSString stringWithFormat:CYLocalize("PARENTHETICAL"), from, section];
}
- from = [NSString stringWithFormat:CYLocalize("FROM"), label];
+ from = [NSString stringWithFormat:CYLocalize("FROM"), from];
source_ = [from retain];
if (NSString *purpose = [package primaryPurpose])
[super dealloc];
}
-/*- (void) release {
+- (void) release {
if ([self retainCount] == 1)
[delegate_ setPackageView:self];
[super release];
-}*/
+}
/* XXX: this is not safe at all... localization of /fail/ */
- (void) _clickButtonWithName:(NSString *)name {
[self setPopupHook:nil];
WebThreadUnlock();
+ //[self yieldToSelector:@selector(callFunction:) withObject:special_];
[super callFunction:special_];
}
}
[cancel_ addTarget:self action:@selector(_onCancel) forControlEvents:UIControlEventTouchUpInside];
CGRect frame = [cancel_ frame];
- frame.size.width = 65;
frame.origin.x = ovrrect.size.width - frame.size.width - 5;
frame.origin.y = (ovrrect.size.height - frame.size.height) / 2;
[cancel_ setFrame:frame];
}
- (NSString *) sectionList:(UISectionList *)list titleForSection:(int)section {
- NSLog(@"titleForSection:%u", section);
return [[sections_ objectAtIndex:section] name];
}
- (void) setPackageView:(PackageView *)view {
if (package_ == nil)
package_ = [view retain];
- NSLog(@"packageView: %@", package_);
}
- (PackageView *) packageView {
@"home-dn.png", kUIButtonBarButtonSelectedInfo,
[NSNumber numberWithInt:1], kUIButtonBarButtonTag,
self, kUIButtonBarButtonTarget,
- CYLocalize("HOME"), kUIButtonBarButtonTitle,
+ @"Cydia", kUIButtonBarButtonTitle,
@"0", kUIButtonBarButtonType,
nil],
Font18Bold_ = [[UIFont boldSystemFontOfSize:18] retain];
Font22Bold_ = [[UIFont boldSystemFontOfSize:22] retain];
- _assert(pkgInitConfig(*_config));
- _assert(pkgInitSystem(*_config, _system));
-
tag_ = 1;
essential_ = [[NSMutableArray alloc] initWithCapacity:4];
int main(int argc, char *argv[]) { _pooled
_trace();
- Locale_ = CFLocaleCopyCurrent();
+ /* Library Hacks {{{ */
+ class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
- CFStringRef locale(CFLocaleGetIdentifier(Locale_));
- setenv("LANG", [(NSString *) locale UTF8String], true);
+ $WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");
+ Method UIWebDocumentView$_setUIKitDelegate$(class_getInstanceMethod([WebView class], @selector(_setUIKitDelegate:)));
+ if (UIWebDocumentView$_setUIKitDelegate$ != NULL) {
+ _UIWebDocumentView$_setUIKitDelegate$ = reinterpret_cast<void (*)(UIWebDocumentView *, SEL, id)>(method_getImplementation(UIWebDocumentView$_setUIKitDelegate$));
+ method_setImplementation(UIWebDocumentView$_setUIKitDelegate$, reinterpret_cast<IMP>(&$UIWebDocumentView$_setUIKitDelegate$));
+ }
+ /* }}} */
+ /* Set Locale {{{ */
+ Locale_ = CFLocaleCopyCurrent();
+ Languages_ = [NSLocale preferredLanguages];
+ //CFStringRef locale(CFLocaleGetIdentifier(Locale_));
+ //NSLog(@"%@", [Languages_ description]);
+ const char *lang;
+ if (Languages_ == nil || [Languages_ count] == 0)
+ lang = NULL;
+ else
+ lang = [[Languages_ objectAtIndex:0] UTF8String];
+ setenv("LANG", lang, true);
+ //std::setlocale(LC_ALL, lang);
+ NSLog(@"Setting Language: %s", lang);
+ /* }}} */
// XXX: apr_app_initialize?
apr_initialize();
- class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
-
+ /* Parse Arguments {{{ */
bool substrate(false);
if (argc != 0) {
else
fprintf(stderr, "unknown argument: %s\n", args[argi]);
}
-
- App_ = [[NSBundle mainBundle] bundlePath];
- Home_ = NSHomeDirectory();
+ /* }}} */
{
NSString *plist = [Home_ stringByAppendingString:@"/Library/Preferences/com.apple.preferences.sounds.plist"];
Sounds_Keyboard_ = [keyboard boolValue];
}
+ App_ = [[NSBundle mainBundle] bundlePath];
+ Home_ = NSHomeDirectory();
+
setuid(0);
setgid(0);
-#if 1 /* XXX: this costs 1.4s of startup performance */
- if (unlink("/var/cache/apt/pkgcache.bin") == -1)
- _assert(errno == ENOENT);
- if (unlink("/var/cache/apt/srcpkgcache.bin") == -1)
- _assert(errno == ENOENT);
-#endif
-
- $WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");
- Method UIWebDocumentView$_setUIKitDelegate$(class_getInstanceMethod([WebView class], @selector(_setUIKitDelegate:)));
- if (UIWebDocumentView$_setUIKitDelegate$ != NULL) {
- _UIWebDocumentView$_setUIKitDelegate$ = reinterpret_cast<void (*)(UIWebDocumentView *, SEL, id)>(method_getImplementation(UIWebDocumentView$_setUIKitDelegate$));
- method_setImplementation(UIWebDocumentView$_setUIKitDelegate$, reinterpret_cast<IMP>(&$UIWebDocumentView$_setUIKitDelegate$));
- }
-
/*Method alloc = class_getClassMethod([NSObject class], @selector(alloc));
alloc_ = alloc->method_imp;
alloc->method_imp = (IMP) &Alloc_;*/
/*AddPreferences(@"/Applications/Preferences.app/Settings-iPhone.plist");
AddPreferences(@"/Applications/Preferences.app/Settings-iPod.plist");*/
+ /* Load Database {{{ */
_trace();
Metadata_ = [[[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"] autorelease];
_trace();
Sources_ = [[[NSMutableDictionary alloc] initWithCapacity:0] autorelease];
[Metadata_ setObject:Sources_ forKey:@"Sources"];
}
+ /* }}} */
#if RecycleWebViews
Documents_ = [[[NSMutableArray alloc] initWithCapacity:4] autorelease];
error:NULL
]);
+ if (access("/tmp/cydia.chk", F_OK) == 0) {
+ if (unlink("/var/cache/apt/pkgcache.bin") == -1)
+ _assert(errno == ENOENT);
+ if (unlink("/var/cache/apt/srcpkgcache.bin") == -1)
+ _assert(errno == ENOENT);
+ }
+
+ _assert(pkgInitConfig(*_config));
+ _assert(pkgInitSystem(*_config, _system));
+
+ if (lang != NULL)
+ _config->Set("APT::Acquire::Translation", lang);
+
+ /* Color Choices {{{ */
space_ = CGColorSpaceCreateDeviceRGB();
Blue_.Set(space_, 0.2, 0.2, 1.0, 1.0);
//.93
InstallingColor_ = [UIColor colorWithRed:0.88f green:1.00f blue:0.88f alpha:1.00f];
RemovingColor_ = [UIColor colorWithRed:1.00f green:0.88f blue:0.88f alpha:1.00f];
+ /* }}}*/
Finishes_ = [NSArray arrayWithObjects:@"return", @"reopen", @"restart", @"reload", @"reboot", nil];
+ /* UIKit Configuration {{{ */
void (*$GSFontSetUseLegacyFontMetrics)(BOOL)(reinterpret_cast<void (*)(BOOL)>(dlsym(RTLD_DEFAULT, "GSFontSetUseLegacyFontMetrics")));
if ($GSFontSetUseLegacyFontMetrics != NULL)
$GSFontSetUseLegacyFontMetrics(YES);
UIKeyboardDisableAutomaticAppearance();
+ /* }}} */
_trace();
int value = UIApplicationMain(argc, argv, @"Cydia", @"Cydia");