#include <sys/sysctl.h>
#include <sys/param.h>
#include <sys/mount.h>
+#include <sys/reboot.h>
#include <fcntl.h>
#include <notify.h>
/* 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_;
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->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]);
- 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));
strncpy(metadata->version_, latest, sizeof(metadata->version_));
metadata->vhash_ = vhash;
+
+ metadata->last_ = time;
}
+ }
}
// }}}
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->version_[0] != '\0')
- metadata->last_ = now_;
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)
- (void) configure {
NSString *dpkg = [NSString stringWithFormat:@"dpkg --configure -a --status-fd %u", statusfd_];
+ _trace();
system([dpkg UTF8String]);
+ _trace();
}
- (bool) clean {
break;
case 2:
- system("launchctl stop com.apple.SpringBoard");
- break;
+ _trace();
+ goto reload;
case 3:
- system("launchctl unload "SpringBoard_"; launchctl load "SpringBoard_);
+ _trace();
+ goto reload;
+
+ reload:
+ system("/usr/bin/sbreload");
+ _trace();
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;
}
}
case 4: [close_ setTitle:UCLocalize("REBOOT_DEVICE")]; break;
}
+ _trace();
system("su -c /usr/bin/uicache mobile");
+ _trace();
UpdateExternalStatus(Finish_ == 0 ? 2 : 0);
- (void) _addProgressOutput:(NSString *)output {
[output_ setText:[NSString stringWithFormat:@"%@\n%@", [output_ text], output]];
CGSize size = [output_ contentSize];
- CGRect rect = {{0, size.height}, {size.width, 0}};
- [output_ scrollRectToVisible:rect animated:YES];
+ CGPoint offset = [output_ contentOffset];
+ if (size.height - offset.y < [output_ frame].size.height + 20.f) {
+ CGRect rect = {{0, size.height-1}, {size.width, 1}};
+ [output_ scrollRectToVisible:rect animated:YES];
+ }
}
- (BOOL) isRunning {
- (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];
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]);
/* }}} */
/* Sections Controller {{{ */
-@interface SectionsController : CYViewController <
+@interface CYSectionsController : CYViewController <
UITableViewDataSource,
UITableViewDelegate
> {
@end
-@implementation SectionsController
+@implementation CYSectionsController
- (void) dealloc {
[list_ setDataSource:nil];
[super dealloc];
}
+- (void) setEditing:(BOOL)editing {
+ if ((editing_ = editing))
+ [list_ reloadData];
+ else
+ [delegate_ updateData];
+
+ [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")];
+ [[[self navigationItem] rightBarButtonItem] setTitle:[sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT")];
+ [[[self navigationItem] rightBarButtonItem] setStyle:editing_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain];
+}
+
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
}
+- (void) viewWillDisappear:(BOOL)animated {
+ [super viewWillDisappear:animated];
+ if (editing_) [self setEditing:NO];
+}
+
- (Section *) sectionAtIndexPath:(NSIndexPath *)indexPath {
Section *section = (editing_ ? [sections_ objectAtIndex:[indexPath row]] : ([indexPath row] == 0 ? nil : [filtered_ objectAtIndex:([indexPath row] - 1)]));
return section;
[self editButtonClicked];
}
-- (void) editButtonClicked {
- if ((editing_ = !editing_))
- [list_ reloadData];
- else
- [delegate_ updateData];
-
- [[self navigationItem] setTitle:editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("SECTIONS")];
- [[[self navigationItem] rightBarButtonItem] setTitle:[sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT")];
- [[[self navigationItem] rightBarButtonItem] setStyle:editing_ ? UIBarButtonItemStyleDone : UIBarButtonItemStylePlain];
+- (void)editButtonClicked {
+ [self setEditing:!editing_];
}
- (UIView *) accessoryView {
@end
/* }}} */
/* Settings Controller {{{ */
-@interface SettingsController : CYViewController <
+@interface CYPackageSettingsController : CYViewController <
UITableViewDataSource,
UITableViewDelegate
> {
@end
-@implementation SettingsController
+@implementation CYPackageSettingsController
- (void) dealloc {
[name_ release];
/* }}} */
/* Role Controller {{{ */
-@interface RoleController : CYViewController <
+@interface CYSettingsController : CYViewController <
UITableViewDataSource,
UITableViewDelegate
> {
@end
-@implementation RoleController
+@implementation CYSettingsController
- (void) dealloc {
[table_ release];
[segment_ release];
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]];
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]];
unsigned locked_;
unsigned activity_;
- SectionsController *sections_;
+ CYSectionsController *sections_;
ChangesController *changes_;
ManageController *manage_;
SearchController *search_;
- (void) _updateData {
[self _saveConfig];
- /* XXX: this is just stupid */
- if (tag_ != 1 && sections_ != nil)
- [sections_ reloadData];
- if (tag_ != 2 && changes_ != nil)
- [changes_ reloadData];
- if (tag_ != 4 && search_ != nil)
- [search_ reloadData];
+ NSMutableSet *tabs([[[NSMutableSet alloc] initWithCapacity:10] autorelease]);
+
+ [tabs addObject:[tabbar_ selectedViewController]];
- [(CYNavigationController *)[tabbar_ selectedViewController] reloadData];
+ if (sections_ != nil)
+ [tabs addObject:sections_];
+ if (changes_ != nil)
+ [tabs addObject:changes_];
+ if (manage_ != nil)
+ [tabs addObject:manage_];
+ if (search_ != nil)
+ [tabs addObject:search_];
+ if (sources_ != nil)
+ [tabs addObject:sources_];
+ if (installed_ != nil)
+ [tabs addObject:installed_];
+
+ for (CYNavigationController *tab in tabs)
+ [tab reloadData];
[queueDelegate_ queueStatusDidChange];
[[[self queueBadgeController] tabBarItem] setBadgeValue:(Queuing_ ? UCLocalize("Q_D") : nil)];
}
}
+ NSLog(@"changes:#%u", changes);
+
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)];
-
- if ([self respondsToSelector:@selector(setApplicationBadge:)])
- [self setApplicationBadge:badge];
- else
- [self setApplicationBadgeString:badge];
+ [self setApplicationIconBadgeNumber:changes];
} else {
+ _trace();
[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];
return browser;
}
-- (SectionsController *) sectionsController {
+- (CYSectionsController *) sectionsController {
if (sections_ == nil)
- sections_ = [[SectionsController alloc] initWithDatabase:database_];
+ sections_ = [[CYSectionsController alloc] initWithDatabase:database_];
return sections_;
}
}
- (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];
}
- (void) system:(NSString *)command { _pooled
+ _trace();
system([command UTF8String]);
+ _trace();
}
- (void) applicationWillSuspend {
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/"])