]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Add -[CyteWebViewDelegate webView:didCommitLoadForFrame:].
[cydia.git] / MobileCydia.mm
index 18015b908582e96ec85b7ed096a4e464a2a538f3..92f5a0aec2a0d64cbd18fab419608be636def17b 100644 (file)
@@ -121,6 +121,7 @@ extern "C" {
 #include <errno.h>
 
 #include <Cytore.hpp>
+#include "Sources.h"
 
 #include <CydiaSubstrate/CydiaSubstrate.h>
 #include "Menes/Menes.h"
@@ -705,16 +706,16 @@ static _transient NSString *Role_;
 static _transient NSMutableDictionary *Packages_;
 static _transient NSMutableDictionary *Values_;
 static _transient NSMutableDictionary *Sections_;
-static _transient NSMutableDictionary *Sources_;
+_H<NSMutableDictionary> Sources_;
 static _transient NSNumber *Version_;
-static _transient _H<NSString> CydiaSource_;
-static bool Changed_;
+_H<NSString> CydiaSource_;
+bool Changed_;
 static time_t now_;
 
 bool IsWildcat_;
 static CGFloat ScreenScale_;
 static NSString *Idiom_;
-static NSString *Firmware_;
+_H<NSString> Firmware_;
 static NSString *Major_;
 
 static _H<NSMutableDictionary> SessionData_;
@@ -731,50 +732,6 @@ static NSString *kCydiaProgressEventTypeStatus = @"Status";
 static NSString *kCydiaProgressEventTypeWarning = @"Warning";
 /* }}} */
 
-static void AddSource(NSDictionary *source) {
-    [Sources_ setObject:source forKey:[NSString stringWithFormat:@"%@:%@:%@", [source objectForKey:@"Type"], [source objectForKey:@"URI"], [source objectForKey:@"Distribution"]]];
-    Changed_ = true;
-}
-
-static void AddSource(NSString *href, NSString *distribution, NSArray *sections = nil) {
-    AddSource([NSMutableDictionary dictionaryWithObjectsAndKeys:
-        @"deb", @"Type",
-        href, @"URI",
-        distribution, @"Distribution",
-        sections ?: [NSMutableArray array], @"Sections",
-    nil]);
-}
-
-static void WriteSources() {
-    FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w"));
-    _assert(file != NULL);
-
-    NSString *distribution(@"ios");
-    if (Firmware_ != nil)
-        distribution = [distribution stringByAppendingString:[NSString stringWithFormat:@"-%@", Firmware_]];
-
-    fprintf(file, "deb http://%s/ %s main\n",
-        [CydiaSource_ UTF8String],
-        [distribution UTF8String]
-    );
-
-    for (NSString *key in [Sources_ allKeys]) {
-        NSDictionary *source([Sources_ objectForKey:key]);
-
-        NSArray *sections([source objectForKey:@"Sections"] ?: [NSArray array]);
-
-        fprintf(file, "%s %s %s%s%s\n",
-            [[source objectForKey:@"Type"] UTF8String],
-            [[source objectForKey:@"URI"] UTF8String],
-            [[source objectForKey:@"Distribution"] UTF8String],
-            [sections count] == 0 ? "" : " ",
-            [[sections componentsJoinedByString:@" "] UTF8String]
-        );
-    }
-
-    fclose(file);
-}
-
 /* Display Helpers {{{ */
 inline float Interpolate(float begin, float end, float fraction) {
     return (end - begin) * fraction + begin;
@@ -1359,12 +1316,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 +1330,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
 - (NSString *) version;
 
 - (NSString *) defaultIcon;
+- (NSURL *) iconURL;
 
 @end
 
@@ -1420,17 +1376,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];
 }
@@ -1629,7 +1587,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
     return trusted_;
 }
 
-- (NSString *) uri {
+- (NSString *) rooturi {
     return uri_;
 }
 
@@ -1641,8 +1599,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 {
@@ -4594,6 +4565,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;
@@ -5515,11 +5488,13 @@ 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 > 16 || rect.size.height > 16) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
 
-        rect.origin.x = 14 - rect.size.width / 4;
-        rect.origin.y = 14 - rect.size.height / 4;
+        rect.origin.x = 18 - rect.size.width / 2;
+        rect.origin.y = 18 - rect.size.height / 2;
 
         [icon_ drawInRect:rect];
     }
@@ -5531,8 +5506,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         rect.size.width /= 4;
         rect.size.height /= 4;
 
-        rect.origin.x = 20 - rect.size.width / 4;
-        rect.origin.y = 20 - rect.size.height / 4;
+        rect.origin.x = 23 - rect.size.width / 2;
+        rect.origin.y = 23 - rect.size.height / 2;
 
         [badge_ drawInRect:rect];
     }
@@ -5556,8 +5531,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 > 32 || rect.size.height > 32) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
 
         rect.origin.x = 25 - rect.size.width / 2;
         rect.origin.y = 25 - rect.size.height / 2;
@@ -6786,6 +6763,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return items;
 }
 
+- (void) dismissModalViewControllerAnimated:(BOOL)animated {
+    if ([self modalViewController] == nil && [self unselectedViewController] != nil)
+        [self setUnselectedViewController:nil];
+    else
+        [super dismissModalViewControllerAnimated:YES];
+}
+
 - (void) unloadData {
     [super unloadData];
 
@@ -7108,15 +7092,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;
@@ -8030,26 +8005,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];
 }
@@ -8058,11 +8028,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 {
@@ -8090,8 +8061,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     bool highlighted(highlighted_);
     float width(rect.size.width);
 
-    if (icon_ != nil)
-        [icon_ drawInRect:CGRectMake(10, 10, 30, 30)];
+    if (icon_ != nil) {
+        CGRect rect;
+        rect.size = [(UIImage *) icon_ size];
+
+        while (rect.size.width > 32 || rect.size.height > 32) {
+            rect.size.width /= 2;
+            rect.size.height /= 2;
+        }
+
+        rect.origin.x = 25 - rect.size.width / 2;
+        rect.origin.y = 25 - rect.size.height / 2;
+
+        [icon_ drawInRect:rect];
+    }
 
     if (highlighted)
         UISetColor(White_);
@@ -8300,12 +8283,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         [delegate_ removeProgressHUD:hud_];
         hud_ = nil;
 
-        bool defer(false);
-
         if (cydia_) {
             if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) {
-                defer = true;
-
                 UIAlertView *alert = [[[UIAlertView alloc]
                     initWithTitle:UCLocalize("SOURCE_WARNING")
                     message:warning
@@ -8319,8 +8298,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
                 [alert setContext:@"warning"];
                 [alert setNumberOfRows:1];
                 [alert show];
-            } else
-                [self complete];
+
+                // XXX: there used to be this great mechanism called yieldToPopup... who deleted it?
+                error_ = nil;
+                return;
+            }
+
+            [self complete];
         } else if (error_ != nil) {
             UIAlertView *alert = [[[UIAlertView alloc]
                 initWithTitle:UCLocalize("VERIFICATION_ERROR")
@@ -8382,8 +8366,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];
@@ -8606,6 +8592,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         UCLocalize("DEVELOPER"),
     nil];
     segment_ = [[[UISegmentedControl alloc] initWithItems:items] autorelease];
+    [segment_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin)];
     container_ = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, [[self view] frame].size.width, 44.0f)] autorelease];
     [container_ addSubview:segment_];
 }
@@ -8976,7 +8963,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         }
     }
 
-    WriteSources();
+    CydiaWriteSources();
 }
 
 // Navigation controller for the queuing badge.
@@ -9174,15 +9161,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) addSource:(NSDictionary *) source {
-    AddSource(source);
+    CydiaAddSource(source);
 }
 
 - (void) addSource:(NSString *)href withDistribution:(NSString *)distribution andSections:(NSArray *)sections {
-    AddSource(href, distribution, sections);
+    CydiaAddSource(href, distribution, sections);
 }
 
 - (void) addTrivialSource:(NSString *)href {
-    AddSource(href, @"./");
+    CydiaAddSource(href, @"./");
 }
 
 - (void) updateValues {
@@ -10267,10 +10254,10 @@ int main(int argc, char *argv[]) {
     }
 
     if ([Version_ unsignedIntValue] == 0) {
-        AddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
-        AddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
-        AddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
-        AddSource(@"http://repo666.ultrasn0w.com/", @"./");
+        CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+        CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+        CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]);
+        CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./");
 
         Version_ = [NSNumber numberWithUnsignedInt:1];
         [Metadata_ setObject:Version_ forKey:@"Version"];
@@ -10281,7 +10268,7 @@ int main(int argc, char *argv[]) {
     }
     /* }}} */
 
-    WriteSources();
+    CydiaWriteSources();
 
     _trace();
     MetaFile_.Open("/var/lib/cydia/metadata.cb0");