/* #include Directives {{{ */
#include <Foundation/NSURL.h>
#include <UIKit/UIKit.h>
-#import <GraphicsServices/GraphicsServices.h>
+#include <GraphicsServices/GraphicsServices.h>
+
+#include <objc/objc.h>
#include <sstream>
#include <ext/stdio_filebuf.h>
#include <mach-o/nlist.h>
}
-#include <objc/objc-class.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <errno.h>
#include <pcre.h>
@end
/* }}} */
+#ifdef SRK_ASPEN
+#define UITable UITableView
+#endif
+
+OBJC_EXPORT const char *class_getName(Class cls);
+
/* Reset View (UIView) {{{ */
@interface UIView (CYResetView)
- (void) resetViewAnimated:(BOOL)animated;
@implementation UIView (CYResetView)
- (void) resetViewAnimated:(BOOL)animated {
- fprintf(stderr, "%s\n", self->isa->name);
+ fprintf(stderr, "%s\n", class_getName(self->isa));
_assert(false);
}
pkgSourceList *list_;
NSMutableDictionary *sources_;
+ NSMutableArray *packages_;
id delegate_;
Status status_;
- (pkgRecords *) records;
- (pkgProblemResolver *) resolver;
- (pkgAcquire &) fetcher;
+- (NSArray *) packages;
- (void) reloadData;
- (void) prepare;
- (NSString *) latest;
- (NSString *) installed;
- (BOOL) upgradable;
+- (BOOL) essential;
+- (BOOL) broken;
- (NSString *) id;
- (NSString *) name;
source_ = [[database_ getSource:file_.File()] retain];
NSMutableDictionary *metadata = [Packages_ objectForKey:id_];
- if (metadata == nil) {
+ if (metadata == nil || [metadata count] == 0) {
metadata = [NSMutableDictionary dictionaryWithObjectsAndKeys:
now_, @"FirstSeen",
nil];
}
- (BOOL) upgradable {
- NSString *installed = [self installed];
- return installed != nil && [[self latest] compare:installed] != NSOrderedSame ? YES : NO;
+ if (NSString *installed = [self installed])
+ return [[self latest] compare:installed] != NSOrderedSame ? YES : NO;
+ else
+ return [self essential];
+}
+
+- (BOOL) essential {
+ return (iterator_->Flags & pkgCache::Flag::Essential) == 0 ? NO : YES;
+}
+
+- (BOOL) broken {
+ return (*[database_ cache])[iterator_].InstBroken();
}
- (NSString *) id {
lock_ = NULL;
sources_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
+ packages_ = [[NSMutableArray arrayWithCapacity:16] retain];
int fds[2];
return *fetcher_;
}
+- (NSArray *) packages {
+ return packages_;
+}
+
- (void) reloadData {
_error->Discard();
delete list_;
_assert(cache_.Open(progress_, true));
}
+ now_ = [NSDate date];
+
records_ = new pkgRecords(cache_);
resolver_ = new pkgProblemResolver(cache_);
fetcher_ = new pkgAcquire(&status_);
forKey:[NSNumber numberWithLong:reinterpret_cast<uintptr_t>(*index)]
];
}
+
+ [packages_ removeAllObjects];
+ for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator)
+ if (Package *package = [Package packageWithIterator:iterator database:self])
+ if ([package source] != nil || [package installed] != nil)
+ [packages_ addObject:package];
}
- (void) prepare {
else {
NSDate *seen = [package seen];
- CFLocaleRef locale = CFLocaleCopyCurrent();
- CFDateFormatterRef formatter = CFDateFormatterCreate(NULL, locale, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle);
- CFStringRef formatted = CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) seen);
-
- NSString *name = (NSString *) formatted;
+ NSString *name;
+ CFStringRef formatted = NULL;
+
+ if (seen == nil)
+ name = @"n/a ?";
+ else {
+ CFLocaleRef locale = CFLocaleCopyCurrent();
+ CFDateFormatterRef formatter = CFDateFormatterCreate(NULL, locale, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle);
+ formatted = CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) seen);
+ name = (NSString *) formatted;
+ CFRelease(formatter);
+ CFRelease(locale);
+ }
if (section == nil || ![[section name] isEqual:name]) {
section = [[[Section alloc] initWithName:name row:offset] autorelease];
[section addPackage:package];
- CFRelease(formatter);
- CFRelease(formatted);
- CFRelease(locale);
+ if (formatted != NULL)
+ CFRelease(formatted);
}
}
[Metadata_ setObject:Packages_ forKey:@"Packages"];
}
- now_ = [NSDate date];
-
- NSMutableArray *packages = [NSMutableArray arrayWithCapacity:count];
- for (pkgCache::PkgIterator iterator = [database_ cache]->PkgBegin(); !iterator.end(); ++iterator)
- if (Package *package = [Package packageWithIterator:iterator database:database_])
- [packages addObject:package];
+ NSArray *packages = [database_ packages];
[install_ setPackages:packages];
[changes_ setPackages:packages];
- (void) perform {
[database_ prepare];
- confirm_ = [[ConfirmationView alloc] initWithView:underlay_ database:database_ delegate:self];
+
+ if ([database_ cache]->BrokenCount() == 0)
+ confirm_ = [[ConfirmationView alloc] initWithView:underlay_ database:database_ delegate:self];
+ else {
+ NSMutableArray *broken = [NSMutableArray arrayWithCapacity:16];
+ NSArray *packages = [database_ packages];
+
+ for (size_t i(0); i != [packages count]; ++i) {
+ Package *package = [packages objectAtIndex:i];
+ if ([package broken])
+ [broken addObject:[package name]];
+ }
+
+ UIAlertSheet *sheet = [[[UIAlertSheet alloc]
+ initWithTitle:[NSString stringWithFormat:@"%d Broken Packages", [database_ cache]->BrokenCount()]
+ buttons:[NSArray arrayWithObjects:@"Okay", nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:self
+ ] autorelease];
+
+ [sheet setBodyText:[NSString stringWithFormat:@"The following packages have unmet dependencies:\n\n%@", [broken componentsJoinedByString:@"\n"]]];
+ [sheet popupAlertAnimated:YES];
+
+ [self reloadData:NO];
+ }
}
- (void) upgrade {