+ _profile(Package$initWithIterator$File)
+ if (!version_.end())
+ file_ = version_.FileList();
+ else {
+ pkgCache &cache([database_ cache]);
+ file_ = pkgCache::VerFileIterator(cache, cache.VerFileP);
+ }
+ _end
+
+ _profile(Package$initWithIterator$Name)
+ id_ = [[NSString stringWithUTF8String:iterator_.Name()] retain];
+ _end
+
+ if (!file_.end())
+ _profile(Package$initWithIterator$Parse)
+ pkgRecords::Parser *parser;
+
+ _profile(Package$initWithIterator$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;
+ }
+ }
+
+ if (begin == NULL)
+ break;
+ ++begin;
+ } else goto next;
+
+ _profile(Package$initWithIterator$Parse$Tagline)
+ tagline_.set(pool, parser->ShortDesc());
+ _end
+
+ _profile(Package$initWithIterator$Parse$Retain)
+ if (!homepage_.empty())
+ homepage_ = website;
+ if (homepage_ == depiction_)
+ homepage_.clear();
+ if (!tag.empty())
+ tags_ = [[tag componentsSeparatedByString:@", "] retain];
+ _end
+ _end
+
+ _profile(Package$initWithIterator$Tags)
+ if (tags_ != nil)
+ for (NSString *tag in tags_)
+ if ([tag hasPrefix:@"role::"]) {
+ role_ = [[tag substringFromIndex:6] retain];
+ break;
+ }
+ _end
+
+ NSString *solid(latest == nil ? installed : latest);
+ bool changed(false);
+
+ NSString *key([id_ lowercaseString]);
+
+ _profile(Package$initWithIterator$Metadata)
+ metadata_ = [Packages_ objectForKey:key];
+ if (metadata_ == nil) {
+ metadata_ = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
+ now_, @"FirstSeen",
+ nil] mutableCopy];
+
+ if (solid != nil)
+ [metadata_ setObject:solid forKey:@"LastVersion"];
+ changed = true;
+ } else {
+ NSDate *first([metadata_ objectForKey:@"FirstSeen"]);
+ NSDate *last([metadata_ objectForKey:@"LastSeen"]);
+ NSString *version([metadata_ objectForKey:@"LastVersion"]);
+
+ if (first == nil) {
+ first = last == nil ? now_ : last;
+ [metadata_ setObject:first forKey:@"FirstSeen"];
+ changed = true;