]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Centralize addCydiaHost: to Cydia delegate_.
[cydia.git] / MobileCydia.mm
index c0c970524f7cfcb746b3086e2175dd79e215a662..617562f6d68f8d63e4c99c474237ebe6ff7d6c64 100644 (file)
@@ -1066,6 +1066,8 @@ static time_t now_;
 bool IsWildcat_;
 static CGFloat ScreenScale_;
 static NSString *Idiom_;
+
+static NSMutableSet *CydiaHosts_;
 /* }}} */
 
 /* Display Helpers {{{ */
@@ -1168,6 +1170,7 @@ bool isSectionVisible(NSString *section) {
 - (CYViewController *) pageForPackage:(NSString *)name;
 - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
 - (void) reloadDataWithInvocation:(NSInvocation *)invocation;
+- (void) addCydiaHost:(NSString *)host;
 @end
 /* }}} */
 
@@ -1776,7 +1779,8 @@ static void PackageImport(const void *key, const void *value, void *context) {
         host_ = [host_ lowercaseString];
 
     if (host_ != nil)
-        authority_ = host_;
+        // XXX: this is due to a bug in _H<>
+        authority_ = (id) host_;
     else
         authority_ = [url path];
 }
@@ -2359,13 +2363,16 @@ struct PackageNameOrdering :
         @"purposes",
         @"relations",
         @"section",
+        @"selection",
         @"shortDescription",
         @"shortSection",
         @"simpleSection",
         @"size",
         @"source",
         @"sponsor",
+        @"state",
         @"support",
+        @"tags",
         @"warnings",
     nil];
 }
@@ -2914,6 +2921,54 @@ struct PackageNameOrdering :
     return files;
 }
 
+- (NSString *) state {
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
+        return nil;
+
+    switch (iterator_->CurrentState) {
+        case pkgCache::State::NotInstalled:
+            return @"NotInstalled";
+        case pkgCache::State::UnPacked:
+            return @"UnPacked";
+        case pkgCache::State::HalfConfigured:
+            return @"HalfConfigured";
+        case pkgCache::State::HalfInstalled:
+            return @"HalfInstalled";
+        case pkgCache::State::ConfigFiles:
+            return @"ConfigFiles";
+        case pkgCache::State::Installed:
+            return @"Installed";
+        case pkgCache::State::TriggersAwaited:
+            return @"TriggersAwaited";
+        case pkgCache::State::TriggersPending:
+            return @"TriggersPending";
+    }
+
+    return (NSString *) [NSNull null];
+} }
+
+- (NSString *) selection {
+@synchronized (database_) {
+    if ([database_ era] != era_ || file_.end())
+        return nil;
+
+    switch (iterator_->SelectedState) {
+        case pkgCache::State::Unknown:
+            return @"Unknown";
+        case pkgCache::State::Install:
+            return @"Install";
+        case pkgCache::State::Hold:
+            return @"Hold";
+        case pkgCache::State::DeInstall:
+            return @"DeInstall";
+        case pkgCache::State::Purge:
+            return @"Purge";
+    }
+
+    return (NSString *) [NSNull null];
+} }
+
 - (NSArray *) warnings {
     NSMutableArray *warnings([NSMutableArray arrayWithCapacity:4]);
     const char *name(iterator_.Name());
@@ -3052,6 +3107,10 @@ struct PackageNameOrdering :
     _assert(false);
 }
 
+- (NSArray *) tags {
+    return tags_;
+}
+
 - (BOOL) hasTag:(NSString *)tag {
     return tags_ == nil ? NO : [tags_ containsObject:tag];
 }
@@ -4071,6 +4130,8 @@ static NSString *Warning_;
 
 + (NSString *) webScriptNameForSelector:(SEL)selector {
     if (false);
+    else if (selector == @selector(addCydiaHost:))
+        return @"addCydiaHost";
     else if (selector == @selector(addTrivialSource:))
         return @"addTrivialSource";
     else if (selector == @selector(close))
@@ -4171,6 +4232,10 @@ static NSString *Warning_;
     return [NSString stringWithCString:value];
 }
 
+- (void) addCydiaHost:(NSString *)host {
+    [delegate_ performSelectorOnMainThread:@selector(addCydiaHost:) withObject:host waitUntilDone:NO];
+}
+
 - (void) addTrivialSource:(NSString *)href {
     [delegate_ performSelectorOnMainThread:@selector(addTrivialSource:) withObject:href waitUntilDone:NO];
 }
@@ -4507,7 +4572,7 @@ static NSString *Warning_;
     NSURLResponse *response([source response]);
 
     NSURL *url([response URL]);
-    NSString *scheme([url scheme]);
+    //NSString *scheme([url scheme]);
     NSString *host([url host]);
 
     if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
@@ -4516,11 +4581,7 @@ static NSString *Warning_;
         [self setHeaders:headers forHost:host];
     }
 
-    if (
-        [host isEqualToString:@"cydia.saurik.com"] ||
-        [host hasSuffix:@".cydia.saurik.com"] ||
-        [scheme isEqualToString:@"file"]
-    )
+    if ([CydiaHosts_ containsObject:host])
         [window setValue:cydia_ forKey:@"cydia"];
 }
 
@@ -9086,7 +9147,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) repairWithInvocation:(NSInvocation *)invocation {
     _trace();
-    [self invokeNewProgress:invocation forController:nil withTitle:UCLocalize("REPAIRING")];
+    [self invokeNewProgress:invocation forController:nil withTitle:@"REPAIRING"];
     _trace();
 }
 
@@ -9112,7 +9173,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     fclose(file);
 
-    [self detachNewProgressSelector:@selector(update_) toTarget:self forController:nil title:UCLocalize("UPDATING_SOURCES")];
+    [self detachNewProgressSelector:@selector(update_) toTarget:self forController:nil title:@"UPDATING_SOURCES"];
 
     [self complete];
 }
@@ -9218,7 +9279,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (void) confirmWithNavigationController:(UINavigationController *)navigation {
     Queuing_ = false;
     ++locked_;
-    [self detachNewProgressSelector:@selector(perform) toTarget:database_ forController:navigation title:UCLocalize("RUNNING")];
+    [self detachNewProgressSelector:@selector(perform) toTarget:database_ forController:navigation title:@"RUNNING"];
     --locked_;
     [self complete];
 }
@@ -9603,11 +9664,17 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [tabbar_ setUpdateDelegate:self];
 }
 
+- (void) addCydiaHost:(NSString *)host {
+    [CydiaHosts_ addObject:host];
+}
+
 - (void) applicationDidFinishLaunching:(id)unused {
 _trace();
     if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
         [self setApplicationSupportsShakeToEdit:NO];
 
+    [self addCydiaHost:[[NSURL URLWithString:CydiaURL(@"")] host]];
+
     [NSURLCache setSharedURLCache:[[[SDURLCache alloc]
         initWithMemoryCapacity:524288
         diskCapacity:10485760
@@ -9868,6 +9935,8 @@ int main(int argc, char *argv[]) { _pooled
             NSLog(@"unknown UIUserInterfaceIdiom!");
     }
 
+    CydiaHosts_ = [NSMutableSet setWithCapacity:2];
+
     UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]);
 
     PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
@@ -10100,7 +10169,7 @@ int main(int argc, char *argv[]) { _pooled
     if (access("/tmp/.cydia.fw", F_OK) == 0) {
         unlink("/tmp/.cydia.fw");
         goto firmware;
-    } else if (access("/User", F_OK) != 0 || version < 2) {
+    } else if (access("/User", F_OK) != 0 || version < 4) {
       firmware:
         _trace();
         system("/usr/libexec/cydia/firmware.sh");