static _finline const char *StripVersion_(const char *version) {
const char *colon(strchr(version, ':'));
- if (colon != NULL)
- version = colon + 1;
- return version;
+ return colon == NULL ? version : colon + 1;
}
NSString *LocalizeSection(NSString *section) {
struct PackageValue :
Cytore::Block
{
- Cytore::Offset<void> reserved_;
Cytore::Offset<PackageValue> next_;
uint32_t index_ : 23;
struct MetaValue :
Cytore::Block
{
- Cytore::Offset<void> reserved_;
Cytore::Offset<PackageValue> packages_[1 << 16];
};
static Cytore::File<MetaValue> MetaFile_;
// }}}
// Cytore Helper Functions {{{
-static PackageValue *PackageFind(const char *name, size_t length, Cytore::Offset<PackageValue> *cache = NULL) {
+static PackageValue *PackageFind(const char *name, size_t length) {
SplitHash nhash = { hashlittle(name, length) };
PackageValue *metadata;
}
}
- if (cache != NULL)
- *cache = *offset;
-
return metadata;
}
};
@interface Package : NSObject {
- unsigned era_;
+ uint32_t era_ : 29;
+ uint32_t essential_ : 1;
+ uint32_t obsolete_ : 1;
+ uint32_t ignored_ : 1;
+
apr_pool_t *pool_;
+ _transient Database *database_;
+
pkgCache::VerIterator version_;
pkgCache::PkgIterator iterator_;
- _transient Database *database_;
pkgCache::VerFileIterator file_;
- Source *source_;
- ParsedPackage *parsed_;
+ CYString id_;
+ CYString name_;
+
+ CYString latest_;
+ CYString installed_;
CYString section_;
_transient NSString *section$_;
- bool essential_;
- bool obsolete_;
- CYString latest_;
- CYString installed_;
+ Source *source_;
- CYString id_;
- CYString name_;
+ PackageValue *metadata_;
+ ParsedPackage *parsed_;
NSMutableArray *tags_;
NSString *role_;
-
- Cytore::Offset<PackageValue> metadata_;
-
- bool ignored_;
}
- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
- (NSArray *) purposes;
- (bool) isCommercial;
+- (void) setIndex:(size_t)index;
+
- (CYString &) cyname;
- (uint32_t) compareBySection:(NSArray *)sections;
- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
if ((self = [super init]) != nil) {
_profile(Package$initWithVersion)
- era_ = [database era];
pool_ = pool;
- version_ = version;
-
- _profile(Package$initWithVersion$ParentPkg)
- iterator_ = version.ParentPkg();
- _end
-
database_ = database;
+ era_ = [database era];
- _profile(Package$initWithVersion$Latest)
- latest_.set(NULL, StripVersion_(version_.VerStr()));
- _end
+ version_ = version;
- pkgCache::VerIterator current;
- _profile(Package$initWithVersion$Versions)
- current = iterator_.CurrentVer();
- if (!current.end())
- installed_.set(NULL, StripVersion_(current.VerStr()));
+ pkgCache::PkgIterator iterator(version.ParentPkg());
+ iterator_ = iterator;
+ _profile(Package$initWithVersion$Version)
if (!version_.end())
file_ = version_.FileList();
else {
}
_end
- _profile(Package$initWithVersion$Name)
- id_.set(NULL, iterator_.Name());
- name_.set(NULL, iterator_.Display());
+ _profile(Package$initWithVersion$Cache)
+ id_.set(NULL, iterator.Name());
+ name_.set(NULL, iterator.Display());
+
+ latest_.set(NULL, StripVersion_(version_.VerStr()));
+
+ pkgCache::VerIterator current(iterator.CurrentVer());
+ if (!current.end())
+ installed_.set(NULL, StripVersion_(current.VerStr()));
_end
- _profile(Package$initWithVersion$lowercaseString)
+ _profile(Package$initWithVersion$Lower)
// XXX: do not use tolower() as this is not locale-specific? :(
char *data(id_.data());
for (size_t i(0), e(id_.size()); i != e; ++i)
_end
_profile(Package$initWithVersion$Tags)
- pkgCache::TagIterator tag(iterator_.TagList());
+ pkgCache::TagIterator tag(iterator.TagList());
if (!tag.end()) {
tags_ = [[NSMutableArray alloc] initWithCapacity:8];
do {
_end
_profile(Package$initWithVersion$Metadata)
- PackageValue *metadata(PackageFind(id_.data(), id_.size(), &metadata_));
+ PackageValue *metadata(PackageFind(id_.data(), id_.size()));
+ metadata_ = metadata;
const char *latest(version_.VerStr());
size_t length(strlen(latest));
_end
_profile(Package$initWithVersion$Section)
- section_.set(NULL, iterator_.Section());
+ section_.set(NULL, iterator.Section());
_end
- _profile(Package$initWithVersion$hasTag)
- essential_ |= ((iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES);
+ _profile(Package$initWithVersion$Flags)
+ essential_ |= ((iterator->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES);
+ ignored_ = iterator->SelectedState == pkgCache::State::Hold;
_end
-
- ignored_ = iterator_->SelectedState == pkgCache::State::Hold;
_end } return self;
}
if (version.end())
return nil;
- return [[[Package alloc]
- initWithVersion:version
- withZone:zone
- inPool:pool
- database:database
- ] autorelease];
+ Package *package;
+
+ _profile(Package$packageWithIterator$Allocate)
+ package = [Package allocWithZone:zone];
+ _end
+
+ _profile(Package$packageWithIterator$Initialize)
+ package = [package
+ initWithVersion:version
+ withZone:zone
+ inPool:pool
+ database:database
+ ];
+ _end
+
+ _profile(Package$packageWithIterator$Autorelease)
+ package = [package autorelease];
+ _end
+
+ return package;
}
- (pkgCache::PkgIterator) iterator {
}
- (PackageValue *) metadata {
- return &MetaFile_.Get(metadata_);
+ return metadata_;
}
- (time_t) seen {
return [self hasTag:@"cydia::commercial"];
}
+- (void) setIndex:(size_t)index {
+ if (metadata_->index_ != index)
+ metadata_->index_ = index;
+}
+
- (CYString &) cyname {
return name_.empty() ? id_ : name_;
}
//[packages_ sortUsingFunction:reinterpret_cast<NSComparisonResult (*)(id, id, void *)>(&PackageNameCompare) context:NULL];
_trace();
+
+ size_t count(CFArrayGetCount(packages_));
+ for (size_t index(0); index != count; ++index)
+ [(Package *) CFArrayGetValueAtIndex(packages_, index) setIndex:index];
+
+ _trace();
}
} } CYPoolEnd() _trace(); }
}
- (void) onSwitch:(id)sender {
- NSMutableDictionary *metadata = [Sections_ objectForKey:basic_];
+ NSMutableDictionary *metadata([Sections_ objectForKey:basic_]);
if (metadata == nil) {
metadata = [NSMutableDictionary dictionaryWithCapacity:2];
[Sections_ setObject:metadata forKey:basic_];
}
- Changed_ = true;
[metadata setObject:[NSNumber numberWithBool:([switch_ isOn] == NO)] forKey:@"Hidden"];
+ Changed_ = true;
}
- (void) setSection:(Section *)section editing:(BOOL)editing {
nil];
[Metadata_ setObject:Settings_ forKey:@"Settings"];
-
Changed_ = true;
if (rolling)
}
- (void) _saveConfig {
+ _trace();
+ MetaFile_.Sync();
+ _trace();
+
if (Changed_) {
- _trace();
NSString *error(nil);
+
if (NSData *data = [NSPropertyListSerialization dataFromPropertyList:Metadata_ format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error]) {
_trace();
NSError *error(nil);
if (![data writeToFile:@"/var/lib/cydia/metadata.plist" options:NSAtomicWrite error:&error])
NSLog(@"failure to save metadata data: %@", error);
_trace();
+
+ Changed_ = false;
} else {
NSLog(@"failure to serialize metadata: %@", error);
- return;
}
-
- Changed_ = false;
}
}
}
- (void) applicationDidFinishLaunching:(id)unused {
+_trace();
[CYBrowserController _initialize];
[NSURLProtocol registerClass:[CydiaURLProtocol class]];