From: Grant Paul Date: Fri, 18 Feb 2011 09:25:29 +0000 (-0800) Subject: Factor out source discovery. X-Git-Url: https://git.saurik.com/cydia.git/commitdiff_plain/3e32cf86a51acc7d605610a39fa4acf983d9a4fd?ds=inline Factor out source discovery. --- diff --git a/MobileCydia.mm b/MobileCydia.mm index 4d9fe2e5..3d2e83db 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -1329,6 +1329,7 @@ typedef std::map< unsigned long, _H > SourceMap; - (pkgSourceList &) list; - (NSArray *) packages; - (NSArray *) sources; +- (Source *) sourceWithKey:(NSString *)key; - (void) reloadData; - (void) configure; @@ -3201,6 +3202,13 @@ static NSString *Warning_; return sources; } +- (Source *) sourceWithKey:(NSString *)key { + for (Source *source in [self sources]) { + if ([[source key] isEqualToString:key]) + return source; + } return nil; +} + - (bool) popErrorWithTitle:(NSString *)title { bool fatal(false); std::string message; @@ -7666,16 +7674,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) reloadData { - NSArray *sources = [database_ sources]; - for (Source *source in sources) { - if ([[source key] isEqual:key_]) { - source_ = source; - [key_ release]; - key_ = [[source key] retain]; - break; - } - } - + source_ = [database_ sourceWithKey:key_]; + [key_ release]; + key_ = [[source_ key] retain]; [self setObject:source_]; [super reloadData]; @@ -9007,13 +9008,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { controller = [[[SourcesController alloc] initWithDatabase:database_] autorelease]; [(SourcesController *)controller showAddSourcePrompt]; } else { - NSArray *sources = [database_ sources]; - for (Source *source in sources) { - if ([[source key] isEqual:argument]) { - controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease]; - break; - } - } + Source *source = [database_ sourceWithKey:argument]; + controller = [[[SourceController alloc] initWithDatabase:database_ source:source] autorelease]; } }