summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2011-03-10 20:50:41 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2011-03-10 20:50:41 -0800
commitaec64d4664f94bca5a577575411ed1b892f1f5cb (patch)
tree846e74380d7957cfa87b6a95a1fb093e209cca4e
parent5ad3e6d9a0a9a6972b5fb8fea108ea7168757ea5 (diff)
Add source.getField().
-rw-r--r--MobileCydia.mm43
1 files changed, 40 insertions, 3 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm
index a54c7b7..b359380 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -1316,6 +1316,10 @@ static void PackageImport(const void *key, const void *value, void *context) {
/* Source Class {{{ */
@interface Source : NSObject {
+ unsigned era_;
+ Database *database_;
+ metaIndex *index_;
+
CYString depiction_;
CYString description_;
CYString label_;
@@ -1337,7 +1341,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
BOOL trusted_;
}
-- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool;
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool;
- (NSComparisonResult) compareByNameAndType:(Source *)source;
@@ -1392,6 +1396,8 @@ static void PackageImport(const void *key, const void *value, void *context) {
if (false);
else if (selector == @selector(addSection:))
return @"addSection";
+ else if (selector == @selector(getField:))
+ return @"getField";
else if (selector == @selector(removeSection:))
return @"removeSection";
else if (selector == @selector(remove))
@@ -1489,12 +1495,43 @@ static void PackageImport(const void *key, const void *value, void *context) {
authority_ = [url path];
}
-- (Source *) initWithMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool {
if ((self = [super init]) != nil) {
+ era_ = [database era];
+ database_ = database;
+ index_ = index;
+
[self setMetaIndex:index inPool:pool];
} return self;
}
+- (NSString *) getField:(NSString *)name {
+@synchronized (database_) {
+ if ([database_ era] != era_ || index_ == NULL)
+ return nil;
+
+ debReleaseIndex *dindex(dynamic_cast<debReleaseIndex *>(index_));
+ if (dindex == NULL)
+ return nil;
+
+ FileFd fd;
+ if (!fd.Open(dindex->MetaIndexFile("Release"), FileFd::ReadOnly)) {
+ _error->Discard();
+ return nil;
+ }
+
+ pkgTagFile tags(&fd);
+
+ pkgTagSection section;
+ tags.Step(section);
+
+ const char *start, *end;
+ if (!section.Find([name UTF8String], start, end))
+ return (NSString *) [NSNull null];
+
+ return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]];
+} }
+
- (NSComparisonResult) compareByNameAndType:(Source *)source {
NSDictionary *lhr = [self record];
NSDictionary *rhr = [source record];
@@ -3539,7 +3576,7 @@ class CydiaLogCleaner :
}
for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
- Source *object([[[Source alloc] initWithMetaIndex:*source inPool:pool_] autorelease]);
+ Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:pool_] autorelease]);
[sourceList_ addObject:object];
std::vector<pkgIndexFile *> *indices = (*source)->GetIndexFiles();