]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Ignore .dSYM folders I am suddenly ending up with.
[cydia.git] / MobileCydia.mm
index 0d0ac83fd7a09a6c0fcd50c305fc40428f1a1920..b359a279475984d12bef04508e05de8259b80360 100644 (file)
@@ -272,11 +272,6 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) {
     notify_post("com.saurik.Cydia.status");
 }
 
-static CGFloat CYStatusBarHeight() {
-    CGSize size([[UIApplication sharedApplication] statusBarFrame].size);
-    return UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ? size.height : size.width;
-}
-
 /* NSForcedOrderingSearch doesn't work on the iPhone */
 static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch;
 static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch;
@@ -707,30 +702,6 @@ static NSString *kCydiaProgressEventTypeWarning = @"Warning";
 /* }}} */
 
 /* Display Helpers {{{ */
-inline float Interpolate(float begin, float end, float fraction) {
-    return (end - begin) * fraction + begin;
-}
-
-static inline double Retina(double value) {
-    value *= ScreenScale_;
-    value = round(value);
-    value /= ScreenScale_;
-    return value;
-}
-
-static inline CGRect Retina(CGRect value) {
-    value.origin.x *= ScreenScale_;
-    value.origin.y *= ScreenScale_;
-    value.size.width *= ScreenScale_;
-    value.size.height *= ScreenScale_;
-    value = CGRectIntegral(value);
-    value.origin.x /= ScreenScale_;
-    value.origin.y /= ScreenScale_;
-    value.size.width /= ScreenScale_;
-    value.size.height /= ScreenScale_;
-    return value;
-}
-
 static _finline const char *StripVersion_(const char *version) {
     const char *colon(strchr(version, ':'));
     return colon == NULL ? version : colon + 1;
@@ -5366,14 +5337,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (PackageCell *) init {
     CGRect frame(CGRectMake(0, 0, 320, 74));
     if ((self = [super initWithFrame:frame reuseIdentifier:@"Package"]) != nil) {
-        UIView *content([self contentView]);
-        CGRect bounds([content bounds]);
-
-        self.content = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease];
-        [self.content setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-        [content addSubview:self.content];
-
-        [self.content setDelegate:self];
         [self.content setOpaque:YES];
     } return self;
 }
@@ -5589,15 +5552,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         switch_ = [[[UISwitch alloc] initWithFrame:CGRectMake(218, 9, 60, 25)] autorelease];
         [switch_ addTarget:self action:@selector(onSwitch:) forEvents:UIControlEventValueChanged];
 
-        UIView *content([self contentView]);
-        CGRect bounds([content bounds]);
-
-        self.content = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease];
-        [self.content setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-        [content addSubview:self.content];
         [self.content setBackgroundColor:[UIColor whiteColor]];
-
-        [self.content setDelegate:self];
     } return self;
 }
 
@@ -5683,7 +5638,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 /* }}} */
 
 /* File Table {{{ */
-@interface FileTable : CyteViewController <
+@interface FileTable : CyteListController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -5691,11 +5646,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     _H<Package> package_;
     _H<NSString> name_;
     _H<NSMutableArray> files_;
-    _H<UITableView, 2> list_;
 }
 
-- (id) initWithDatabase:(Database *)database;
-- (void) setPackage:(Package *)package;
+- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name;
 
 @end
 
@@ -5727,47 +5680,36 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@/files", [package_ id]]];
 }
 
-- (void) loadView {
-    list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
-    [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-    [list_ setRowHeight:24.0f];
-    [(UITableView *) list_ setDataSource:self];
-    [list_ setDelegate:self];
-    [self setView:list_];
-}
-
-- (void) viewDidLoad {
-    [super viewDidLoad];
-
-    [[self navigationItem] setTitle:UCLocalize("INSTALLED_FILES")];
+- (CGFloat) rowHeight {
+    return 24;
 }
 
 - (void) releaseSubviews {
-    list_ = nil;
-
     package_ = nil;
     files_ = nil;
 
     [super releaseSubviews];
 }
 
-- (id) initWithDatabase:(Database *)database {
-    if ((self = [super init]) != nil) {
+- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name {
+    if ((self = [super initWithTitle:UCLocalize("INSTALLED_FILES")]) != nil) {
         database_ = database;
+        name_ = name;
     } return self;
 }
 
-- (void) setPackage:(Package *)package {
-    package_ = nil;
-    name_ = nil;
+- (bool) shouldYield {
+    return false;
+}
 
-    files_ = [NSMutableArray arrayWithCapacity:32];
+- (void) _reloadData {
+    files_ = nil;
 
-    if (package != nil) {
-        package_ = package;
-        name_ = [package id];
+    package_ = [database_ packageWithName:name_];
+    if (package_ != nil) {
+        files_ = [NSMutableArray arrayWithCapacity:32];
 
-        if (NSArray *files = [package files])
+        if (NSArray *files = [package_ files])
             [files_ addObjectsFromArray:files];
 
         if ([files_ count] != 0) {
@@ -5792,13 +5734,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         }
     }
 
-    [list_ reloadData];
-}
-
-- (void) reloadData {
-    [super reloadData];
-
-    [self setPackage:[database_ packageWithName:name_]];
+    [super _reloadData];
 }
 
 @end
@@ -5999,7 +5935,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 /* }}} */
 
 /* Package List Controller {{{ */
-@interface PackageListController : CyteViewController <
+@interface PackageListController : CyteListController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -6007,18 +5943,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     unsigned era_;
     _H<NSArray> packages_;
     _H<NSArray> sections_;
-    _H<UITableView, 2> list_;
 
     _H<NSArray> thumbs_;
     std::vector<NSInteger> offset_;
 
-    _H<NSString> title_;
     unsigned reloading_;
 }
 
 - (id) initWithDatabase:(Database *)database title:(NSString *)title;
-- (void) resetCursor;
-- (void) clearData;
 
 - (NSArray *) sectionsForPackages:(NSMutableArray *)packages;
 
@@ -6038,93 +5970,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return true;
 }
 
-- (void) deselectWithAnimation:(BOOL)animated {
-    [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
-}
-
-- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve {
-    CGRect base = [[self view] bounds];
-    base.size.height -= bounds.size.height;
-    base.origin = [list_ frame].origin;
-
-    [UIView beginAnimations:nil context:NULL];
-    [UIView setAnimationBeginsFromCurrentState:YES];
-    [UIView setAnimationCurve:curve];
-    [UIView setAnimationDuration:duration];
-    [list_ setFrame:base];
-    [UIView commitAnimations];
-}
-
-- (void) resizeForKeyboardBounds:(CGRect)bounds duration:(NSTimeInterval)duration {
-    [self resizeForKeyboardBounds:bounds duration:duration curve:UIViewAnimationCurveLinear];
-}
-
-- (void) resizeForKeyboardBounds:(CGRect)bounds {
-    [self resizeForKeyboardBounds:bounds duration:0];
-}
-
-- (void) getKeyboardCurve:(UIViewAnimationCurve *)curve duration:(NSTimeInterval *)duration forNotification:(NSNotification *)notification {
-    if (&UIKeyboardAnimationCurveUserInfoKey == NULL)
-        *curve = UIViewAnimationCurveEaseInOut;
-    else
-        [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:curve];
-
-    if (&UIKeyboardAnimationDurationUserInfoKey == NULL)
-        *duration = 0.3;
-    else
-        [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:duration];
-}
-
-- (void) keyboardWillShow:(NSNotification *)notification {
-    CGRect bounds;
-    CGPoint center;
-    [[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&bounds];
-    [[[notification userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey] getValue:&center];
-
-    NSTimeInterval duration;
-    UIViewAnimationCurve curve;
-    [self getKeyboardCurve:&curve duration:&duration forNotification:notification];
-
-    CGRect kbframe = CGRectMake(Retina(center.x - bounds.size.width / 2), Retina(center.y - bounds.size.height / 2), bounds.size.width, bounds.size.height);
-    UIViewController *base([self rootViewController]);
-    CGRect viewframe = [[base view] convertRect:[list_ frame] fromView:[list_ superview]];
-    CGRect intersection = CGRectIntersection(viewframe, kbframe);
-
-    if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) // XXX: _UIApplicationLinkedOnOrAfter(4)
-        intersection.size.height += CYStatusBarHeight();
-
-    [self resizeForKeyboardBounds:intersection duration:duration curve:curve];
-}
-
-- (void) keyboardWillHide:(NSNotification *)notification {
-    NSTimeInterval duration;
-    UIViewAnimationCurve curve;
-    [self getKeyboardCurve:&curve duration:&duration forNotification:notification];
-
-    [self resizeForKeyboardBounds:CGRectZero duration:duration curve:curve];
-}
-
-- (void) viewWillAppear:(BOOL)animated {
-    [super viewWillAppear:animated];
-
-    [self resizeForKeyboardBounds:CGRectZero];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
-}
-
-- (void) viewWillDisappear:(BOOL)animated {
-    [super viewWillDisappear:animated];
-
-    [self resizeForKeyboardBounds:CGRectZero];
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
-}
-
-- (void) viewDidAppear:(BOOL)animated {
-    [super viewDidAppear:animated];
-    [self deselectWithAnimation:animated];
-}
-
 - (void) didSelectPackage:(Package *)package {
     CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id] withReferrer:[[self referrerURL] absoluteString]] autorelease]);
     [view setDelegate:self.delegate];
@@ -6183,39 +6028,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return offset_[index];
 }
 
-- (void) updateHeight {
-    [list_ setRowHeight:([self isSummarized] ? 38 : 73)];
+- (CGFloat) rowHeight {
+    return [self isSummarized] ? 38 : 73;
 }
 
 - (id) initWithDatabase:(Database *)database title:(NSString *)title {
-    if ((self = [super init]) != nil) {
+    if ((self = [super initWithTitle:title]) != nil) {
         database_ = database;
-        title_ = [title copy];
-        [[self navigationItem] setTitle:title_];
     } return self;
 }
 
-- (void) loadView {
-    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
-    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-    [self setView:view];
-
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
-    [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-    [view addSubview:list_];
-
-    // XXX: is 20 the most optimal number here?
-    [list_ setSectionIndexMinimumDisplayRowCount:20];
-
-    [(UITableView *) list_ setDataSource:self];
-    [list_ setDelegate:self];
-
-    [self updateHeight];
-}
-
 - (void) releaseSubviews {
-    list_ = nil;
-
     packages_ = nil;
     sections_ = nil;
 
@@ -6225,10 +6048,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [super releaseSubviews];
 }
 
-- (bool) shouldYield {
-    return false;
-}
-
 - (bool) shouldBlock {
     return false;
 }
@@ -6289,12 +6108,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         sections_ = [NSArray arrayWithObject:section];
     }
 
-    [self updateHeight];
-
-    _profile(PackageTable$reloadData$List)
-        [(UITableView *) list_ setDataSource:self];
-        [list_ reloadData];
-    _end
+    [super _reloadData];
 }
 
     PrintTimes();
@@ -6353,28 +6167,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return sections;
 }
 
-- (void) reloadData {
-    [super reloadData];
-
-    if ([self shouldYield])
-        [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0];
-    else
-        [self _reloadData];
-}
-
-- (void) resetCursor {
-    [list_ scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
-}
-
-- (void) clearData {
-    [self updateHeight];
-
-    [list_ setDataSource:nil];
-    [list_ reloadData];
-
-    [self resetCursor];
-}
-
 @end
 /* }}} */
 /* Filtered Package List Controller {{{ */
@@ -6631,61 +6423,18 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi
 /* }}} */
 
 /* Cydia:// Protocol {{{ */
-@interface CydiaURLProtocol : NSURLProtocol {
+@interface CydiaURLProtocol : CyteURLProtocol {
 }
 
 @end
 
 @implementation CydiaURLProtocol
 
-+ (BOOL) canInitWithRequest:(NSURLRequest *)request {
-    NSURL *url([request URL]);
-    if (url == nil)
-        return NO;
-
-    NSString *scheme([[url scheme] lowercaseString]);
-    if (scheme != nil && [scheme isEqualToString:@"cydia"])
-        return YES;
-    if ([[url absoluteString] hasPrefix:@"about:cydia-"])
-        return YES;
-
-    return NO;
-}
-
-+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
-    return request;
-}
-
-- (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request {
-    id<NSURLProtocolClient> client([self client]);
-    if (icon == nil)
-        [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
-    else {
-        NSData *data(UIImagePNGRepresentation(icon));
-
-        NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
-        [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
-        [client URLProtocol:self didLoadData:data];
-        [client URLProtocolDidFinishLoading:self];
-    }
++ (NSString *) scheme {
+    return @"cydia";
 }
 
-- (void) startLoading {
-    id<NSURLProtocolClient> client([self client]);
-    NSURLRequest *request([self request]);
-
-    NSURL *url([request URL]);
-    NSString *href([url absoluteString]);
-    NSString *scheme([[url scheme] lowercaseString]);
-
-    NSString *path;
-
-    if ([scheme isEqualToString:@"cydia"])
-        path = [href substringFromIndex:8];
-    else if ([scheme isEqualToString:@"about"])
-        path = [href substringFromIndex:12];
-    else _assert(false);
-
+- (bool) loadForPath:(NSString *)path ofRequest:(NSURLRequest *)request {
     NSRange slash([path rangeOfString:@"/"]);
 
     NSString *command;
@@ -6745,11 +6494,10 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi
             icon = [UIImage imageNamed:@"unknown.png"];
         [self _returnPNGWithImage:icon forRequest:request];
     } else fail: {
-        [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
+        return [super loadForPath:path ofRequest:request];
     }
-}
 
-- (void) stopLoading {
+    return true;
 }
 
 @end
@@ -7208,8 +6956,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi
     if (upgrades_ != 0)
         [sections insertObject:upgradable atIndex:0];
 
-    [list_ reloadData];
-
     [[self navigationItem] setRightBarButtonItem:(upgrades_ == 0 ? nil : [[[UIBarButtonItem alloc]
         initWithTitle:[NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]]
         style:UIBarButtonItemStylePlain
@@ -7762,20 +7508,12 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi
 
 - (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
     if ((self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) != nil) {
-        UIView *content([self contentView]);
-        CGRect bounds([content bounds]);
-
-        self.content = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease];
-        [self.content setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
         [self.content setBackgroundColor:[UIColor whiteColor]];
-        [content addSubview:self.content];
-
-        [self.content setDelegate:self];
         [self.content setOpaque:YES];
 
         indicator_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGraySmall] autorelease];
         [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin];// | UIViewAutoresizingFlexibleBottomMargin];
-        [content addSubview:indicator_];
+        [[self contentView] addSubview:indicator_];
 
         [[self.content layer] setContentsGravity:kCAGravityTopLeft];
     } return self;
@@ -8394,7 +8132,6 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi
     _H<NSURL> starturl_;
 
     unsigned locked_;
-    unsigned activity_;
 
     _H<StashController> stash_;
 
@@ -8815,25 +8552,6 @@ _end
     [self unlockSuspend];
 }
 
-- (void) retainNetworkActivityIndicator {
-    if (activity_++ == 0)
-        [self setNetworkActivityIndicatorVisible:YES];
-
-#if TraceLogging
-    NSLog(@"retainNetworkActivityIndicator->%d", activity_);
-#endif
-}
-
-- (void) releaseNetworkActivityIndicator {
-    if (--activity_ == 0)
-        [self setNetworkActivityIndicatorVisible:NO];
-
-#if TraceLogging
-    NSLog(@"releaseNetworkActivityIndicator->%d", activity_);
-#endif
-
-}
-
 - (void) cancelAndClear:(bool)clear {
     @synchronized (self) {
         if (clear) {
@@ -9096,10 +8814,7 @@ _end
             if ([arg2 isEqualToString:@"settings"]) {
                 controller = [[[PackageSettingsController alloc] initWithDatabase:database_ package:arg1] autorelease];
             } else if ([arg2 isEqualToString:@"files"]) {
-                if (Package *package = [database_ packageWithName:arg1]) {
-                    controller = [[[FileTable alloc] initWithDatabase:database_] autorelease];
-                    [(FileTable *)controller setPackage:package];
-                }
+                controller = [[[FileTable alloc] initWithDatabase:database_ forPackage:arg1] autorelease];
             }
         }
 
@@ -9476,17 +9191,47 @@ static NSMutableDictionary *AutoreleaseDeepMutableCopyOfDictionary(CFTypeRef typ
     return [(NSMutableDictionary *) copy autorelease];
 }
 
+int main_copy();
+int main_file();
+int main_gpgv();
+int main_rred(int, char *argv[]);
+
+int main_gzip(int, char *argv[]);
+
 int main_store(int, char *argv[]);
 
+int main_http();
+
 int main(int argc, char *argv[]) {
-#ifdef __arm64__
     const char *argv0(argv[0]);
     if (const char *slash = strrchr(argv0, '/'))
         argv0 = slash + 1;
     if (false);
+    else if (!strcmp(argv0, "copy"))
+        return main_copy();
+    else if (!strcmp(argv0, "file"))
+        return main_file();
+    else if (!strcmp(argv0, "gpgv"))
+        return main_gpgv();
+    else if (!strcmp(argv0, "rred"))
+        return main_rred(argc, argv);
+#ifdef __arm__
+    else if (!strcmp(argv0, "bzip2"))
+        return main_gzip(argc, argv);
+    else if (!strcmp(argv0, "gzip"))
+        return main_gzip(argc, argv);
+    else if (!strcmp(argv0, "lzma"))
+        return main_gzip(argc, argv);
+#endif
+#ifdef __arm64__
     else if (!strcmp(argv0, "store"))
         return main_store(argc, argv);
 #endif
+    else if (!strcmp(argv0, "http"))
+        return main_http();
+    else if (!strcmp(argv0, "https"))
+        return main_http();
+    else {}
 
     int fd(open("/tmp/cydia.log", O_WRONLY | O_APPEND | O_CREAT, 0644));
     dup2(fd, 2);
@@ -9496,7 +9241,7 @@ int main(int argc, char *argv[]) {
 
     _trace();
 
-    CyteInitialize(@"Cydia", Cydia_);
+    CyteInitialize([NSString stringWithFormat:@"Cydia/%@", Cydia_]);
     UpdateExternalStatus(0);
 
     SessionData_ = [NSMutableDictionary dictionaryWithCapacity:4];
@@ -9720,7 +9465,8 @@ int main(int argc, char *argv[]) {
 
     _config->Set("Acquire::AllowInsecureRepositories", true);
     _config->Set("Acquire::Check-Valid-Until", false);
-    _config->Set("Dir::Bin::Methods::store", "/Applications/Cydia.app/store");
+
+    _config->Set("Dir::Bin::Methods", "/Applications/Cydia.app");
 
     _config->Set("pkgCacheGen::ForceEssential", "");