]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
More correctly handle a couple (impossible) corner cases of the new Cytore import...
[cydia.git] / MobileCydia.mm
index 196b9c02cc45123a9212a6a1f6cbbddfe8707c5b..932b4714a00298a7624e6e3d89515f966489a228 100644 (file)
 #include <sys/sysctl.h>
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/sysctl.h>
 #include <sys/param.h>
 #include <sys/mount.h>
+#include <sys/reboot.h>
 
 #include <fcntl.h>
 #include <notify.h>
 
 #include <fcntl.h>
 #include <notify.h>
@@ -1011,9 +1012,6 @@ class CYColor {
 
 /* Random Global Variables {{{ */
 static const int PulseInterval_ = 50000;
 
 /* Random Global Variables {{{ */
 static const int PulseInterval_ = 50000;
-static const int ButtonBarWidth_ = 60;
-static const int ButtonBarHeight_ = 48;
-static const float KeyboardTime_ = 0.3f;
 
 static int Finish_;
 static NSArray *Finishes_;
 
 static int Finish_;
 static NSArray *Finishes_;
@@ -1493,7 +1491,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
     NSDictionary *package((NSDictionary *) value);
 
     if (NSNumber *subscribed = [package objectForKey:@"IsSubscribed"])
     NSDictionary *package((NSDictionary *) value);
 
     if (NSNumber *subscribed = [package objectForKey:@"IsSubscribed"])
-        if ([subscribed boolValue])
+        if ([subscribed boolValue] && !metadata->subscribed_)
             metadata->subscribed_ = true;
 
     if (NSDate *date = [package objectForKey:@"FirstSeen"]) {
             metadata->subscribed_ = true;
 
     if (NSDate *date = [package objectForKey:@"FirstSeen"]) {
@@ -1502,22 +1500,12 @@ static void PackageImport(const void *key, const void *value, void *context) {
             metadata->first_ = time;
     }
 
             metadata->first_ = time;
     }
 
-    bool versioned(false);
+    NSDate *date([package objectForKey:@"LastSeen"]);
+    NSString *version([package objectForKey:@"LastVersion"]);
 
 
-    if (NSDate *date = [package objectForKey:@"LastSeen"]) {
+    if (date != nil && version != nil) {
         time_t time([date timeIntervalSince1970]);
         time_t time([date timeIntervalSince1970]);
-        if (metadata->last_ < time || metadata->last_ == 0) {
-            metadata->last_ = time;
-            versioned = true;
-        }
-    } else if (metadata->last_ == 0) {
-        metadata->last_ = metadata->first_;
-        if (metadata->version_[0] == '\0')
-            versioned = true;
-    }
-
-    if (versioned)
-        if (NSString *version = [package objectForKey:@"LastVersion"])
+        if (metadata->last_ < time || metadata->last_ == 0)
             if (CFStringGetCString((CFStringRef) version, buffer, sizeof(buffer), kCFStringEncodingUTF8)) {
                 size_t length(strlen(buffer));
                 uint16_t vhash(hashlittle(buffer, length));
             if (CFStringGetCString((CFStringRef) version, buffer, sizeof(buffer), kCFStringEncodingUTF8)) {
                 size_t length(strlen(buffer));
                 uint16_t vhash(hashlittle(buffer, length));
@@ -1527,7 +1515,10 @@ static void PackageImport(const void *key, const void *value, void *context) {
 
                 strncpy(metadata->version_, latest, sizeof(metadata->version_));
                 metadata->vhash_ = vhash;
 
                 strncpy(metadata->version_, latest, sizeof(metadata->version_));
                 metadata->vhash_ = vhash;
+
+                metadata->last_ = time;
             }
             }
+    }
 }
 // }}}
 
 }
 // }}}
 
@@ -2267,15 +2258,12 @@ struct PackageNameOrdering :
             if (metadata->first_ == 0)
                 metadata->first_ = now_;
 
             if (metadata->first_ == 0)
                 metadata->first_ = now_;
 
-            if (metadata->last_ == 0)
-                metadata->last_ = metadata->first_;
-
             if (metadata->vhash_ != vhash || strncmp(metadata->version_, latest, sizeof(metadata->version_)) != 0) {
             if (metadata->vhash_ != vhash || strncmp(metadata->version_, latest, sizeof(metadata->version_)) != 0) {
-                if (metadata->version_[0] != '\0')
-                    metadata->last_ = now_;
                 strncpy(metadata->version_, latest, sizeof(metadata->version_));
                 metadata->vhash_ = vhash;
                 strncpy(metadata->version_, latest, sizeof(metadata->version_));
                 metadata->vhash_ = vhash;
-            }
+                metadata->last_ = now_;
+            } else if (metadata->last_ == 0)
+                metadata->last_ = metadata->first_;
         _end
 
         _profile(Package$initWithVersion$Section)
         _end
 
         _profile(Package$initWithVersion$Section)
@@ -3510,7 +3498,9 @@ static NSString *Warning_;
 
 - (void) configure {
     NSString *dpkg = [NSString stringWithFormat:@"dpkg --configure -a --status-fd %u", statusfd_];
 
 - (void) configure {
     NSString *dpkg = [NSString stringWithFormat:@"dpkg --configure -a --status-fd %u", statusfd_];
+    _trace();
     system([dpkg UTF8String]);
     system([dpkg UTF8String]);
+    _trace();
 }
 
 - (bool) clean {
 }
 
 - (bool) clean {
@@ -4444,15 +4434,24 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         break;
 
         case 2:
         break;
 
         case 2:
-            system("launchctl stop com.apple.SpringBoard");
-        break;
+            _trace();
+            goto reload;
 
         case 3:
 
         case 3:
-            system("launchctl unload "SpringBoard_"; launchctl load "SpringBoard_);
+            _trace();
+            goto reload;
+
+        reload:
+            system("/usr/bin/sbreload");
+            _trace();
         break;
 
         case 4:
         break;
 
         case 4:
-            system("reboot");
+            _trace();
+            if (void (*SBReboot)(mach_port_t) = reinterpret_cast<void (*)(mach_port_t)>(dlsym(RTLD_DEFAULT, "SBReboot")))
+                SBReboot(SBSSpringBoardServerPort());
+            else
+                reboot2(RB_AUTOBOOT);
         break;
     }
 }
         break;
     }
 }
@@ -4501,7 +4500,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         case 4: [close_ setTitle:UCLocalize("REBOOT_DEVICE")]; break;
     }
 
         case 4: [close_ setTitle:UCLocalize("REBOOT_DEVICE")]; break;
     }
 
+    _trace();
     system("su -c /usr/bin/uicache mobile");
     system("su -c /usr/bin/uicache mobile");
+    _trace();
 
     UpdateExternalStatus(Finish_ == 0 ? 2 : 0);
 
 
     UpdateExternalStatus(Finish_ == 0 ? 2 : 0);
 
@@ -6544,6 +6545,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) positionViews {
     CGRect frame = [cancel_ frame];
 
 - (void) positionViews {
     CGRect frame = [cancel_ frame];
+    frame.size = [cancel_ sizeThatFits:frame.size];
     frame.origin.x = [self frame].size.width - frame.size.width - 5;
     frame.origin.y = ([self frame].size.height - frame.size.height) / 2;
     [cancel_ setFrame:frame];
     frame.origin.x = [self frame].size.width - frame.size.width - 5;
     frame.origin.y = ([self frame].size.height - frame.size.height) / 2;
     [cancel_ setFrame:frame];
@@ -6578,7 +6580,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if ((self = [super initWithFrame:frame])) {
         [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
 
     if ((self = [super initWithFrame:frame])) {
         [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
 
-        [self setTintColor:[UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:1]];
         [self setBarStyle:UIBarStyleBlack];
 
         UIBarStyle barstyle([self _barStyle:NO]);
         [self setBarStyle:UIBarStyleBlack];
 
         UIBarStyle barstyle([self _barStyle:NO]);
@@ -7575,7 +7576,7 @@ freeing the view controllers on tab change */
 @end
 /* }}} */
 /* Settings Controller {{{ */
 @end
 /* }}} */
 /* Settings Controller {{{ */
-@interface SettingsController : CYViewController <
+@interface CYPackageSettingsController : CYViewController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -7593,7 +7594,7 @@ freeing the view controllers on tab change */
 
 @end
 
 
 @end
 
-@implementation SettingsController
+@implementation CYPackageSettingsController
 
 - (void) dealloc {
     [name_ release];
 
 - (void) dealloc {
     [name_ release];
@@ -7742,7 +7743,7 @@ freeing the view controllers on tab change */
 /* }}} */
 
 /* Role Controller {{{ */
 /* }}} */
 
 /* Role Controller {{{ */
-@interface RoleController : CYViewController <
+@interface CYSettingsController : CYViewController <
     UITableViewDataSource,
     UITableViewDelegate
 > {
     UITableViewDataSource,
     UITableViewDelegate
 > {
@@ -7759,7 +7760,7 @@ freeing the view controllers on tab change */
 
 @end
 
 
 @end
 
-@implementation RoleController
+@implementation CYSettingsController
 - (void) dealloc {
     [table_ release];
     [segment_ release];
 - (void) dealloc {
     [table_ release];
     [segment_ release];
@@ -7947,7 +7948,7 @@ freeing the view controllers on tab change */
         captrect.origin.x = 0;
         captrect.origin.y = ([[self view] frame].size.height / 2) - (captrect.size.height * 2);
         caption_ = [[[UILabel alloc] initWithFrame:captrect] autorelease];
         captrect.origin.x = 0;
         captrect.origin.y = ([[self view] frame].size.height / 2) - (captrect.size.height * 2);
         caption_ = [[[UILabel alloc] initWithFrame:captrect] autorelease];
-        [caption_ setText:@"Initializing Filesystem"];
+        [caption_ setText:UCLocalize("PREPARING_FILESYSTEM")];
         [caption_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
         [caption_ setFont:[UIFont boldSystemFontOfSize:28.0f]];
         [caption_ setTextColor:[UIColor whiteColor]];
         [caption_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
         [caption_ setFont:[UIFont boldSystemFontOfSize:28.0f]];
         [caption_ setTextColor:[UIColor whiteColor]];
@@ -7963,7 +7964,7 @@ freeing the view controllers on tab change */
         statusrect.origin.y = ([[self view] frame].size.height / 2) - statusrect.size.height;
         status_ = [[[UILabel alloc] initWithFrame:statusrect] autorelease];
         [status_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
         statusrect.origin.y = ([[self view] frame].size.height / 2) - statusrect.size.height;
         status_ = [[[UILabel alloc] initWithFrame:statusrect] autorelease];
         [status_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
-        [status_ setText:@"(Cydia will exit when complete.)"];
+        [status_ setText:UCLocalize("EXIT_WHEN_COMPLETE")];
         [status_ setFont:[UIFont systemFontOfSize:16.0f]];
         [status_ setTextColor:[UIColor whiteColor]];
         [status_ setBackgroundColor:[UIColor clearColor]];
         [status_ setFont:[UIFont systemFontOfSize:16.0f]];
         [status_ setTextColor:[UIColor whiteColor]];
         [status_ setBackgroundColor:[UIColor clearColor]];
@@ -8213,24 +8214,20 @@ static _finline void _setHomePage(Cydia *self) {
         }
     }
 
         }
     }
 
+    NSLog(@"changes:#%u", changes);
+
     UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem];
     if (changes != 0) {
     UITabBarItem *changesItem = [[[tabbar_ viewControllers] objectAtIndex:[self indexOfTabWithTag:kChangesTag]] tabBarItem];
     if (changes != 0) {
+        _trace();
         NSString *badge([[NSNumber numberWithInt:changes] stringValue]);
         [changesItem setBadgeValue:badge];
         [changesItem setAnimatedBadge:([essential_ count] > 0)];
         NSString *badge([[NSNumber numberWithInt:changes] stringValue]);
         [changesItem setBadgeValue:badge];
         [changesItem setAnimatedBadge:([essential_ count] > 0)];
-
-        if ([self respondsToSelector:@selector(setApplicationBadge:)])
-            [self setApplicationBadge:badge];
-        else
-            [self setApplicationBadgeString:badge];
+        [self setApplicationIconBadgeNumber:changes];
     } else {
     } else {
+        _trace();
         [changesItem setBadgeValue:nil];
         [changesItem setAnimatedBadge:NO];
         [changesItem setBadgeValue:nil];
         [changesItem setAnimatedBadge:NO];
-
-        if ([self respondsToSelector:@selector(removeApplicationBadge)])
-            [self removeApplicationBadge];
-        else // XXX: maybe use setApplicationBadgeString also?
-            [self setApplicationIconBadgeNumber:0];
+        [self setApplicationIconBadgeNumber:0];
     }
 
     [self _updateData];
     }
 
     [self _updateData];
@@ -8481,7 +8478,7 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) showSettings {
 }
 
 - (void) showSettings {
-    RoleController *role = [[[RoleController alloc] initWithDatabase:database_ delegate:self] autorelease];
+    CYSettingsController *role = [[[CYSettingsController alloc] initWithDatabase:database_ delegate:self] autorelease];
     CYNavigationController *nav = [[[CYNavigationController alloc] initWithRootViewController:role] autorelease];
     if (IsWildcat_)
         [nav setModalPresentationStyle:UIModalPresentationFormSheet];
     CYNavigationController *nav = [[[CYNavigationController alloc] initWithRootViewController:role] autorelease];
     if (IsWildcat_)
         [nav setModalPresentationStyle:UIModalPresentationFormSheet];
@@ -8579,7 +8576,9 @@ static _finline void _setHomePage(Cydia *self) {
 }
 
 - (void) system:(NSString *)command { _pooled
 }
 
 - (void) system:(NSString *)command { _pooled
+    _trace();
     system([command UTF8String]);
     system([command UTF8String]);
+    _trace();
 }
 
 - (void) applicationWillSuspend {
 }
 
 - (void) applicationWillSuspend {
@@ -8681,7 +8680,7 @@ static _finline void _setHomePage(Cydia *self) {
     else if ([path hasPrefix:@"/launch/"])
         [self launchApplicationWithIdentifier:[path substringFromIndex:8] suspended:NO];
     else if ([path hasPrefix:@"/package-settings/"])
     else if ([path hasPrefix:@"/launch/"])
         [self launchApplicationWithIdentifier:[path substringFromIndex:8] suspended:NO];
     else if ([path hasPrefix:@"/package-settings/"])
-        return [[[SettingsController alloc] initWithDatabase:database_ package:[path substringFromIndex:18]] autorelease];
+        return [[[CYPackageSettingsController alloc] initWithDatabase:database_ package:[path substringFromIndex:18]] autorelease];
     else if ([path hasPrefix:@"/package-signature/"])
         return [[[SignatureController alloc] initWithDatabase:database_ package:[path substringFromIndex:19]] autorelease];
     else if ([path hasPrefix:@"/package/"])
     else if ([path hasPrefix:@"/package-signature/"])
         return [[[SignatureController alloc] initWithDatabase:database_ package:[path substringFromIndex:19]] autorelease];
     else if ([path hasPrefix:@"/package/"])