]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Better consider preinst in makefile.
[cydia.git] / MobileCydia.mm
index 0fb9d49457b3b0eed2c960a73633c5ab346ce4a4..fb483a8623e92064de311e90d1e7abe71d13babe 100644 (file)
@@ -1351,7 +1351,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 
 - (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool;
 
-- (NSComparisonResult) compareByNameAndType:(Source *)source;
+- (NSComparisonResult) compareByName:(Source *)source;
 
 - (NSString *) depictionForPackage:(NSString *)package;
 - (NSString *) supportForPackage:(NSString *)package;
@@ -1359,12 +1359,10 @@ static void PackageImport(const void *key, const void *value, void *context) {
 - (NSDictionary *) record;
 - (BOOL) trusted;
 
-- (NSString *) uri;
+- (NSString *) rooturi;
 - (NSString *) distribution;
 - (NSString *) type;
 
-- (NSString *) base;
-
 - (NSString *) key;
 - (NSString *) host;
 
@@ -1375,6 +1373,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 - (NSString *) version;
 
 - (NSString *) defaultIcon;
+- (NSURL *) iconURL;
 
 @end
 
@@ -1420,17 +1419,19 @@ static void PackageImport(const void *key, const void *value, void *context) {
 
 + (NSArray *) _attributeKeys {
     return [NSArray arrayWithObjects:
+        @"baseuri",
         @"distribution",
         @"host",
         @"key",
+        @"iconuri",
         @"label",
         @"name",
         @"origin",
+        @"rooturi",
         @"sections",
         @"shortDescription",
         @"trusted",
         @"type",
-        @"uri",
         @"version",
     nil];
 }
@@ -1540,13 +1541,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
     return [NSString stringWithString:[(NSString *) CYStringCreate(start, end - start) autorelease]];
 } }
 
-- (NSComparisonResult) compareByNameAndType:(Source *)source {
-    NSDictionary *lhr = [self record];
-    NSDictionary *rhr = [source record];
-
-    if ((lhr == nil) != (rhr == nil))
-        return lhr == nil ? NSOrderedDescending : NSOrderedAscending;
-
+- (NSComparisonResult) compareByName:(Source *)source {
     NSString *lhs = [self name];
     NSString *rhs = [source name];
 
@@ -1635,7 +1630,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
     return trusted_;
 }
 
-- (NSString *) uri {
+- (NSString *) rooturi {
     return uri_;
 }
 
@@ -1647,8 +1642,21 @@ static void PackageImport(const void *key, const void *value, void *context) {
     return type_;
 }
 
-- (NSString *) base {
-    return base_;
+- (NSString *) baseuri {
+    return base_.empty() ? nil : (id) base_;
+}
+
+- (NSString *) iconuri {
+    if (NSString *base = [self baseuri])
+        return [base stringByAppendingString:@"CydiaIcon.png"];
+
+    return nil;
+}
+
+- (NSURL *) iconURL {
+    if (NSString *uri = [self iconuri])
+        return [NSURL URLWithString:uri];
+    return nil;
 }
 
 - (NSString *) key {
@@ -1843,6 +1851,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 /* }}} */
 /* Package Class {{{ */
 struct ParsedPackage {
+    CYString md5sum_;
     CYString tagline_;
 
     CYString architecture_;
@@ -1859,11 +1868,12 @@ struct ParsedPackage {
 };
 
 @interface Package : NSObject {
-    uint32_t era_ : 26;
+    uint32_t era_ : 25;
     uint32_t role_ : 3;
     uint32_t essential_ : 1;
     uint32_t obsolete_ : 1;
     uint32_t ignored_ : 1;
+    uint32_t pooled_ : 1;
 
     apr_pool_t *pool_;
 
@@ -2110,6 +2120,8 @@ struct PackageNameOrdering :
 }
 
 - (void) dealloc {
+    if (!pooled_)
+        apr_pool_destroy(pool_);
     if (parsed_ != NULL)
         delete parsed_;
     [super dealloc];
@@ -2150,6 +2162,7 @@ struct PackageNameOrdering :
         @"longDescription",
         @"longSection",
         @"maintainer",
+        @"md5sum",
         @"mode",
         @"name",
         @"purposes",
@@ -2238,6 +2251,7 @@ struct PackageNameOrdering :
                 {"support", &parsed->support_},
                 {"sponsor", &parsed->sponsor_},
                 {"author", &parsed->author_},
+                {"md5sum", &parsed->md5sum_},
             };
 
             for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) {
@@ -2276,7 +2290,12 @@ struct PackageNameOrdering :
 - (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
     if ((self = [super init]) != nil) {
     _profile(Package$initWithVersion)
-        pool_ = pool;
+        if (pool == NULL)
+            apr_pool_create(&pool_, NULL);
+        else {
+            pool_ = pool;
+            pooled_ = true;
+        }
 
         database_ = database;
         era_ = [database era];
@@ -2467,6 +2486,10 @@ struct PackageNameOrdering :
     return maintainer.empty() ? nil : [MIMEAddress addressWithString:[NSString stringWithUTF8String:maintainer.c_str()]];
 } }
 
+- (NSString *) md5sum {
+    return parsed_ == NULL ? nil : (id) parsed_->md5sum_;
+}
+
 - (size_t) size {
 @synchronized (database_) {
     if ([database_ era] != era_ || version_.end())
@@ -3350,7 +3373,7 @@ class CydiaLogCleaner :
     if (static_cast<pkgDepCache *>(cache_) == NULL)
         return nil;
     pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String]));
-    return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:pool_ database:self];
+    return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:NULL database:self];
 } }
 
 - (id) init {
@@ -4585,6 +4608,8 @@ static _H<NSMutableSet> Diversions_;
     if ([url isCydiaSecure] && token) {
         if (Token_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Token"] == nil)
             [copy setValue:Token_ forHTTPHeaderField:@"X-Cydia-Token"];
+        if (UniqueID_ != nil && [copy valueForHTTPHeaderField:@"X-Cydia-Id"] == nil)
+            [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
     }
 
     return copy;
@@ -5506,8 +5531,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         CGRect rect;
         rect.size = [(UIImage *) icon_ size];
 
-        rect.size.width /= 4;
-        rect.size.height /= 4;
+        while (rect.size.width > 32 || rect.size.height > 32) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
 
         rect.origin.x = 14 - rect.size.width / 4;
         rect.origin.y = 14 - rect.size.height / 4;
@@ -5547,8 +5574,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         CGRect rect;
         rect.size = [(UIImage *) icon_ size];
 
-        rect.size.width /= 2;
-        rect.size.height /= 2;
+        while (rect.size.width > 64 || rect.size.height > 64) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
 
         rect.origin.x = 25 - rect.size.width / 2;
         rect.origin.y = 25 - rect.size.height / 2;
@@ -7099,15 +7128,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [package parse];
         UIImage *icon([package icon]);
         [self _returnPNGWithImage:icon forRequest:request];
-    } else if ([command isEqualToString:@"source-icon"]) {
-        if (path == nil)
-            goto fail;
-        path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-        NSString *source(Simplify(path));
-        UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sources/%@.png", App_, source]]);
-        if (icon == nil)
-            icon = [UIImage applicationImageNamed:@"unknown.png"];
-        [self _returnPNGWithImage:icon forRequest:request];
     } else if ([command isEqualToString:@"uikit-image"]) {
         if (path == nil)
             goto fail;
@@ -8021,26 +8041,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [content_ setNeedsDisplay];
 }
 
-- (void) _setSource:(Source *)source {
+- (void) _setSource:(NSURL *) url {
     NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
 
-    if (NSString *base = [source base])
-        if ([base length] != 0) {
-            NSURL *url([NSURL URLWithString:[base stringByAppendingString:@"CydiaIcon.png"]]);
-
-            if (NSData *data = [NSURLConnection
-                sendSynchronousRequest:[NSURLRequest
-                    requestWithURL:url
-                    //cachePolicy:NSURLRequestUseProtocolCachePolicy
-                    //timeoutInterval:5
-                ]
-
-                returningResponse:NULL
-                error:NULL
-            ])
-                if (UIImage *image = [UIImage imageWithData:data])
-                    [self performSelectorOnMainThread:@selector(_setImage:) withObject:image waitUntilDone:NO];
-        }
+    if (NSData *data = [NSURLConnection
+        sendSynchronousRequest:[NSURLRequest
+            requestWithURL:url
+            //cachePolicy:NSURLRequestUseProtocolCachePolicy
+            //timeoutInterval:5
+        ]
+
+        returningResponse:NULL
+        error:NULL
+    ])
+        if (UIImage *image = [UIImage imageWithData:data])
+            [self performSelectorOnMainThread:@selector(_setImage:) withObject:image waitUntilDone:NO];
 
     [pool release];
 }
@@ -8049,11 +8064,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     icon_ = [UIImage applicationImageNamed:@"unknown.png"];
 
     origin_ = [source name];
-    label_ = [source uri];
+    label_ = [source rooturi];
 
     [content_ setNeedsDisplay];
 
-    [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:source];
+    if (NSURL *url = [source iconURL])
+        [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:url];
 }
 
 - (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
@@ -8191,37 +8207,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
-    return offset_ == 0 ? 1 : 2;
+    return 1;
 }
 
 - (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
-    switch (section + (offset_ == 0 ? 1 : 0)) {
-        case 0: return UCLocalize("ENTERED_BY_USER");
-        case 1: return UCLocalize("INSTALLED_BY_PACKAGE");
-
-        _nodefault
-    }
+    return nil;
 }
 
 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    int count = [sources_ count];
-    switch (section) {
-        case 0: return (offset_ == 0 ? count : offset_);
-        case 1: return count - offset_;
-
-        _nodefault
-    }
+    return [sources_ count];
 }
 
 - (Source *) sourceAtIndexPath:(NSIndexPath *)indexPath {
-    unsigned idx = 0;
-    switch (indexPath.section) {
-        case 0: idx = indexPath.row; break;
-        case 1: idx = indexPath.row + offset_; break;
-
-        _nodefault
-    }
-    return [sources_ objectAtIndex:idx];
+    return [sources_ objectAtIndex:[indexPath row]];
 }
 
 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -8391,8 +8389,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
 
     if ([url isCydiaSecure]) {
-        if (UniqueID_ != nil)
+        if (UniqueID_ != nil) {
             [request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+            [request setValue:UniqueID_ forHTTPHeaderField:@"X-Cydia-Id"];
+        }
     }
 
     return [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
@@ -8497,7 +8497,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     sources_ = [NSMutableArray arrayWithCapacity:16];
     [sources_ addObjectsFromArray:[database_ sources]];
     _trace();
-    [sources_ sortUsingSelector:@selector(compareByNameAndType:)];
+    [sources_ sortUsingSelector:@selector(compareByName:)];
     _trace();
 
     int count([sources_ count]);