diff options
author | Grant Paul <chpwn@chpwn.com> | 2011-02-26 22:43:11 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-07 02:41:22 -0800 |
commit | d3a28a81bdff6e1ed62f372ec09345d3e81ccac6 (patch) | |
tree | c73791c94b089ed7a2156f08369858fb726a9445 | |
parent | 3df90eb139dfdc349166d1910462e337ce53cd01 (diff) |
Ensure saved state has at least somewhat proper base set of controllers before using it.
-rw-r--r-- | MobileCydia.mm | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index 662c08b..49218cb 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -9821,6 +9821,21 @@ _trace(); _trace(); } +- (NSArray *) defaultStartPages { + NSMutableArray *standard = [NSMutableArray array]; + [standard addObject:[NSArray arrayWithObject:@"cydia://home"]]; + [standard addObject:[NSArray arrayWithObject:@"cydia://sections"]]; + [standard addObject:[NSArray arrayWithObject:@"cydia://changes"]]; + if (!IsWildcat_) { + [standard addObject:[NSArray arrayWithObject:@"cydia://manage"]]; + } else { + [standard addObject:[NSArray arrayWithObject:@"cydia://installed"]]; + [standard addObject:[NSArray arrayWithObject:@"cydia://sources"]]; + } + [standard addObject:[NSArray arrayWithObject:@"cydia://search"]]; + return standard; +} + - (void) loadData { _trace(); if (Role_ == nil) { @@ -9838,42 +9853,48 @@ _trace(); [self disemulate]; - int selectedIndex = 0; - NSMutableArray *items = nil; + int savedIndex = [[Metadata_ objectForKey:@"InterfaceIndex"] intValue]; + NSArray *saved = [[Metadata_ objectForKey:@"InterfaceState"] mutableCopy]; + int standardIndex = 0; + NSArray *standard = [self defaultStartPages]; - bool recently = false; - NSDate *closed([Metadata_ objectForKey:@"LastClosed"]); - if (closed != nil) { + BOOL valid = YES; + + if (saved == nil) + valid = NO; + + NSDate *closed = [Metadata_ objectForKey:@"LastClosed"]; + if (valid && closed != nil) { NSTimeInterval interval([closed timeIntervalSinceNow]); // XXX: Is 15 minutes the optimal time here? - if (interval <= 0 && interval > -(15*60)) - recently = true; + if (interval > 0 && interval <= -(15*60)) + valid = NO; } - items = [[Metadata_ objectForKey:@"InterfaceState"] mutableCopy]; - selectedIndex = [[Metadata_ objectForKey:@"InterfaceIndex"] intValue]; + if (valid && [saved count] != [standard count]) + valid = NO; - BOOL enough = YES; - for (NSArray *entry in items) - if ([entry count] <= 0) - enough = NO; - - if (!recently || !items || !enough) { - selectedIndex = 0; - items = [NSMutableArray array]; - [items addObject:[NSArray arrayWithObject:@"cydia://home"]]; - [items addObject:[NSArray arrayWithObject:@"cydia://sections"]]; - [items addObject:[NSArray arrayWithObject:@"cydia://changes"]]; - if (!IsWildcat_) { - [items addObject:[NSArray arrayWithObject:@"cydia://manage"]]; - } else { - [items addObject:[NSArray arrayWithObject:@"cydia://installed"]]; - [items addObject:[NSArray arrayWithObject:@"cydia://sources"]]; + if (valid) { + for (unsigned int i = 0; i < [standard count]; i++) { + NSArray *std = [standard objectAtIndex:i], *sav = [saved objectAtIndex:i]; + // XXX: The "hasPrefix" sanity check here could be, in theory, fooled, + // but it's good enough for now. + if ([sav count] == 0 || ![[sav objectAtIndex:0] hasPrefix:[std objectAtIndex:0]]) { + valid = NO; + break; + } } - [items addObject:[NSArray arrayWithObject:@"cydia://search"]]; } - [tabbar_ setSelectedIndex:selectedIndex]; + NSArray *items = nil; + if (valid) { + [tabbar_ setSelectedIndex:savedIndex]; + items = saved; + } else { + [tabbar_ setSelectedIndex:standardIndex]; + items = standard; + } + for (unsigned int tab = 0; tab < [[tabbar_ viewControllers] count]; tab++) { NSArray *stack = [items objectAtIndex:tab]; CYNavigationController *navigation = [[tabbar_ viewControllers] objectAtIndex:tab]; |