]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Remove obsolete CydiaSettings.bundle.
[cydia.git] / MobileCydia.mm
index 0648e4c104ed4a76e595314412c2649fdfef1624..9ef5db99ae0532225e4581d24e806bb091cb76da 100644 (file)
@@ -41,8 +41,8 @@
 #define USE_SYSTEM_MALLOC 1
 
 /* #include Directives {{{ */
-#include "UICaboodle/UCPlatform.h"
-#include "UICaboodle/UCLocalize.h"
+#include "CyteKit/UCPlatform.h"
+#include "CyteKit/CyteLocalize.h"
 
 #include <objc/objc.h>
 #include <objc/runtime.h>
@@ -117,14 +117,17 @@ extern "C" {
 #include <cstring>
 
 #include <errno.h>
-#include <pcre.h>
 
 #include <Cytore.hpp>
 
-#include "UICaboodle/BrowserView.h"
+#include "CyteKit/CyteWebViewController.h"
+#include "CyteKit/NSString-Cyte.h"
+#include "CyteKit/PerlCompatibleRegEx.hpp"
+#include "CyteKit/WebScriptObject-Cyte.h"
+
 #include "SDURLCache/SDURLCache.h"
 
-#include "substrate.h"
+#include <CydiaSubstrate/CydiaSubstrate.h>
 /* }}} */
 
 /* Profiler {{{ */
@@ -585,23 +588,6 @@ void CFArrayInsertionSortValues(CFMutableArrayRef array, CFRange range, CFCompar
 
 @end
 
-@implementation WebScriptObject (NSFastEnumeration)
-
-- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count {
-    size_t length([self count] - state->state);
-    if (length <= 0)
-        return 0;
-    else if (length > count)
-        length = count;
-    for (size_t i(0); i != length; ++i)
-        objects[i] = [self objectAtIndex:state->state++];
-    state->itemsPtr = objects;
-    state->mutationsPtr = (unsigned long *) self;
-    return length;
-}
-
-@end
-
 NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
     size_t length([self length] - state->state);
     if (length <= 0)
@@ -617,9 +603,6 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s
 
 /* Cydia NSString Additions {{{ */
 @interface NSString (Cydia)
-+ (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length;
-+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length withZone:(NSZone *)zone inPool:(apr_pool_t *)pool;
-+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length;
 - (NSComparisonResult) compareByPath:(NSString *)other;
 - (NSString *) stringByCachingURLWithCurrentCDN;
 - (NSString *) stringByAddingPercentEscapesIncludingReserved;
@@ -627,20 +610,6 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s
 
 @implementation NSString (Cydia)
 
-+ (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length {
-    return [[[NSString alloc] initWithBytesNoCopy:const_cast<char *>(bytes) length:length encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease];
-}
-
-+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length withZone:(NSZone *)zone inPool:(apr_pool_t *)pool {
-    char *data(reinterpret_cast<char *>(apr_palloc(pool, length)));
-    memcpy(data, bytes, length);
-    return [[[NSString allocWithZone:zone] initWithBytesNoCopy:data length:length encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease];
-}
-
-+ (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length {
-    return [[[NSString alloc] initWithBytes:bytes length:length encoding:NSUTF8StringEncoding] autorelease];
-}
-
 - (NSComparisonResult) compareByPath:(NSString *)other {
     NSString *prefix = [self commonPrefixWithString:other options:0];
     size_t length = [prefix length];
@@ -834,77 +803,6 @@ struct NSStringMapEqual :
 };
 /* }}} */
 
-/* Perl-Compatible RegEx {{{ */
-class Pcre {
-  private:
-    pcre *code_;
-    pcre_extra *study_;
-    int capture_;
-    int *matches_;
-    const char *data_;
-
-  public:
-    Pcre() :
-        code_(NULL),
-        study_(NULL)
-    {
-    }
-
-    Pcre(const char *regex) :
-        code_(NULL),
-        study_(NULL)
-    {
-        this->operator =(regex);
-    }
-
-    void operator =(const char *regex) {
-        _assert(code_ == NULL);
-
-        const char *error;
-        int offset;
-        code_ = pcre_compile(regex, 0, &error, &offset, NULL);
-
-        if (code_ == NULL) {
-            lprintf("%d:%s\n", offset, error);
-            _assert(false);
-        }
-
-        pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_);
-        matches_ = new int[(capture_ + 1) * 3];
-    }
-
-    ~Pcre() {
-        pcre_free(code_);
-        delete matches_;
-    }
-
-    NSString *operator [](size_t match) const {
-        return [NSString stringWithUTF8Bytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2])];
-    }
-
-    _finline bool operator ()(NSString *data) {
-        // XXX: length is for characters, not for bytes
-        return operator ()([data UTF8String], [data length]);
-    }
-
-    _finline bool operator ()(const char *data) {
-        return operator ()(data, strlen(data));
-    }
-
-    bool operator ()(const char *data, size_t size) {
-        data_ = data;
-        return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
-    }
-
-    NSString *operator ->*(NSString *format) const {
-        id values[capture_];
-        for (int i(0); i != capture_; ++i)
-            values[i] = this->operator [](i + 1);
-
-        return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast<va_list>(values)] autorelease];
-    }
-};
-/* }}} */
 /* Mime Addresses {{{ */
 @interface Address : NSObject {
     NSString *name_;
@@ -3116,7 +3014,10 @@ struct PackageNameOrdering :
 
     [self parse];
 
-    range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_];
+    NSString *description([self shortDescription]);
+    NSUInteger length([description length]);
+
+    range = [[self shortDescription] rangeOfString:text options:MatchCompareOptions_ range:NSMakeRange(0, std::min<NSUInteger>(length, 100))];
     if (range.location != NSNotFound)
         return YES;
 
@@ -4097,6 +3998,9 @@ static NSMutableSet *Diversions_;
 
     for (Diversion *diversion in Diversions_)
         if (NSString *diverted = [diversion divert:href]) {
+#if !ForRelease
+            NSLog(@"div: %@", diverted);
+#endif
             url = [NSURL URLWithString:diverted];
             goto divert;
         }
@@ -4245,6 +4149,10 @@ static NSMutableSet *Diversions_;
         return @"getKernelString";
     else if (selector == @selector(getInstalledPackages))
         return @"getInstalledPackages";
+    else if (selector == @selector(getLocaleIdentifier))
+        return @"getLocaleIdentifier";
+    else if (selector == @selector(getPreferredLanguages))
+        return @"getPreferredLanguages";
     else if (selector == @selector(getPackageById:))
         return @"getPackageById";
     else if (selector == @selector(getSessionValue:))
@@ -4267,6 +4175,8 @@ static NSMutableSet *Diversions_;
         return @"scrollToBottom";
     else if (selector == @selector(setAllowsNavigationAction:))
         return @"setAllowsNavigationAction";
+    else if (selector == @selector(setBadgeValue:))
+        return @"setBadgeValue";
     else if (selector == @selector(setButtonImage:withStyle:toFunction:))
         return @"setButtonImage";
     else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
@@ -4279,8 +4189,10 @@ static NSMutableSet *Diversions_;
         return @"setNavigationBarStyle";
     else if (selector == @selector(setNavigationBarTintRed:green:blue:alpha:))
         return @"setNavigationBarTintColor";
-    else if (selector == @selector(setPopupHook:))
-        return @"setPopupHook";
+    else if (selector == @selector(setPasteboardString:))
+        return @"setPasteboardString";
+    else if (selector == @selector(setPasteboardURL:))
+        return @"setPasteboardURL";
     else if (selector == @selector(setToken:))
         return @"setToken";
     else if (selector == @selector(setViewportWidth:))
@@ -4402,6 +4314,14 @@ static NSMutableSet *Diversions_;
         return (Package *) [NSNull null];
 }
 
+- (NSString *) getLocaleIdentifier {
+    return Locale_ == NULL ? (NSString *) [NSNull null] : (NSString *) CFLocaleGetIdentifier(Locale_);
+}
+
+- (NSArray *) getPreferredLanguages {
+    return Languages_;
+}
+
 - (NSArray *) statfs:(NSString *)path {
     struct statfs stat;
 
@@ -4490,6 +4410,10 @@ static NSMutableSet *Diversions_;
     [indirect_ setButtonTitle:button withStyle:style toFunction:function];
 }
 
+- (void) setBadgeValue:(id)value {
+    [indirect_ performSelectorOnMainThread:@selector(setBadgeValue:) withObject:value waitUntilDone:NO];
+}
+
 - (void) setAllowsNavigationAction:(NSString *)value {
     [indirect_ performSelectorOnMainThread:@selector(setAllowsNavigationActionByNumber:) withObject:value waitUntilDone:NO];
 }
@@ -4512,6 +4436,14 @@ static NSMutableSet *Diversions_;
     [indirect_ performSelectorOnMainThread:@selector(setNavigationBarTintColor:) withObject:color waitUntilDone:NO];
 }
 
+- (void) setPasteboardString:(NSString *)value {
+    [[objc_getClass("UIPasteboard") generalPasteboard] setString:value];
+}
+
+- (void) setPasteboardURL:(NSString *)value {
+    [[objc_getClass("UIPasteboard") generalPasteboard] setURL:[NSURL URLWithString:value]];
+}
+
 - (void) _setToken:(NSString *)token {
     Token_ = token;
 
@@ -4527,10 +4459,6 @@ static NSMutableSet *Diversions_;
     [self performSelectorOnMainThread:@selector(_setToken:) withObject:token waitUntilDone:NO];
 }
 
-- (void) setPopupHook:(id)function {
-    [indirect_ setPopupHook:function];
-}
-
 - (void) scrollToBottom:(NSNumber *)animated {
     [indirect_ performSelectorOnMainThread:@selector(scrollToBottomAnimated:) withObject:animated waitUntilDone:NO];
 }
@@ -4717,11 +4645,13 @@ static NSMutableSet *Diversions_;
         [window setValue:cydia_ forKey:@"cydia"];
 }
 
+- (NSURL *) URLWithURL:(NSURL *)url {
+    return [Diversion divertURL:url];
+}
+
 - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
     NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]);
 
-    [copy setURL:[Diversion divertURL:[copy URL]]];
-
     if (System_ != NULL)
         [copy setValue:System_ forHTTPHeaderField:@"X-System"];
     if (Machine_ != NULL)
@@ -4988,13 +4918,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
             if (state.NewInstall())
                 [installs addObject:name];
+            // XXX: else if (state.Install())
             else if (!state.Delete() && (state.iFlags & pkgDepCache::ReInstall) == pkgDepCache::ReInstall)
                 [reinstalls addObject:name];
+            // XXX: move before previous if
             else if (state.Upgrade())
                 [upgrades addObject:name];
             else if (state.Downgrade())
                 [downgrades addObject:name];
             else if (!state.Delete())
+                // XXX: _assert(state.Keep());
                 continue;
             else if (special_r(name))
                 [issues_ addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@@ -5993,6 +5926,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setTitle:UCLocalize("INSTALLED_FILES")];
 }
 
@@ -6609,6 +6544,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 - (id) init {
     if ((self = [super init]) != nil) {
         [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/home/", UI_]]];
+        [self reloadData];
     } return self;
 }
 
@@ -6634,6 +6570,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
         initWithTitle:UCLocalize("ABOUT")
         style:UIBarButtonItemStylePlain
@@ -6642,6 +6580,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     ] autorelease]];
 }
 
+- (void) unloadData {
+    [super unloadData];
+    [self reloadData];
+}
+
 @end
 /* }}} */
 /* Manage Controller {{{ */
@@ -6665,6 +6608,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
         initWithTitle:UCLocalize("SETTINGS")
         style:UIBarButtonItemStylePlain
@@ -7445,6 +7390,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setTitle:UCLocalize("SECTIONS")];
 }
 
@@ -7633,6 +7580,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setTitle:UCLocalize("CHANGES")];
 }
 
@@ -8012,6 +7961,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setTitle:UCLocalize("SETTINGS")];
 }
 
@@ -8597,6 +8548,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setTitle:UCLocalize("SOURCES")];
     [self updateButtonsForEditingStatus:NO animated:NO];
 }
@@ -8753,6 +8706,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewDidLoad {
+    [super viewDidLoad];
+
     [[self navigationItem] setTitle:UCLocalize("WHO_ARE_YOU")];
 
     int index = -1;