delete matches_;
}
- NSString *operator [](size_t match) {
+ NSString *operator [](size_t match) const {
return [NSString stringWithUTF8Bytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2])];
}
- bool operator ()(NSString *data) {
+ _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;
}
- _finline size_t size() const {
- return capture_;
+ 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];
}
};
/* }}} */
- (NSString *) host;
- (NSString *) name;
-- (NSString *) description;
+- (NSString *) shortDescription;
- (NSString *) label;
- (NSString *) origin;
- (NSString *) version;
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:
- @"description",
@"distribution",
@"host",
@"key",
@"label",
@"name",
@"origin",
+ @"shortDescription",
@"trusted",
@"type",
@"uri",
return origin_.empty() ? (id) authority_ : origin_;
}
-- (NSString *) description {
+- (NSString *) shortDescription {
return description_;
}
}
- (NSString *) divert:(NSString *)url {
- if (!pattern_(url))
- return nil;
-
- size_t count(pattern_.size());
- id values[count];
- for (size_t i(0); i != count; ++i)
- values[i] = pattern_[i + 1];
-
- return [[[NSString alloc] initWithFormat:format_ arguments:reinterpret_cast<va_list>(values)] autorelease];
+ return !pattern_(url) ? nil : pattern_->*format_;
}
- (NSString *) key {
}
- (void) viewWillAppear:(BOOL)animated {
- if (![self hasLoaded])
- [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlack];
-
+ [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlack];
[super viewWillAppear:animated];
}
}
- (void) reloadData {
+ [super reloadData];
+
package_ = [database_ packageWithName:name_];
[buttons_ removeAllObjects];
target:self
action:@selector(customButtonClicked)
] autorelease];
-
- [super reloadData];
}
- (bool) isLoading {
@end
/* }}} */
-@class CYNavigationController;
+/* Cydia Navigation Controller Interface {{{ */
+@interface CYNavigationController : UINavigationController {
+ _transient Database *database_;
+ _transient id<UINavigationControllerDelegate> delegate_;
+}
+
+- (NSArray *) navigationURLCollection;
+- (id) initWithDatabase:(Database *)database;
+- (void) unloadData:(BOOL)selected;
+
+@end
+/* }}} */
/* Cydia Tab Bar Controller {{{ */
@interface CYTabBarController : UITabBarController <
- (void) beginUpdate;
- (void) raiseBar:(BOOL)animated;
- (BOOL) updating;
+- (void) unloadData;
@end
return items;
}
-- (void) reloadData {
- for (CYViewController *controller in [self viewControllers])
- [controller reloadData];
+- (void) unloadData {
+ CYNavigationController *selected((CYNavigationController *) [self selectedViewController]);
+ for (CYNavigationController *controller in [self viewControllers])
+ [controller unloadData:(controller == selected)];
- [(CYNavigationController *)[self unselectedViewController] reloadData];
+ if (CYNavigationController *unselected = (CYNavigationController *) [self unselectedViewController])
+ [unselected unloadData:YES];
}
- (void) dealloc {
@end
/* }}} */
-/* Cydia Navigation Controller {{{ */
-@interface CYNavigationController : UINavigationController {
- _transient Database *database_;
- _transient id<UINavigationControllerDelegate> delegate_;
-}
-
-- (NSArray *) navigationURLCollection;
-- (id) initWithDatabase:(Database *)database;
-- (void) reloadData;
-
-@end
-
+/* Cydia Navigation Controller Implementation {{{ */
@implementation CYNavigationController
- (NSArray *) navigationURLCollection {
return stack;
}
-- (void) reloadData {
+- (void) unloadData:(BOOL)selected {
+ CYViewController *top((CYViewController *) [self topViewController]);
+ bool loaded([top hasLoaded]);
+
for (CYViewController *page in [self viewControllers]) {
- // Only reload controllers that have already loaded.
- // This prevents a page from accidentally loading too
- // early if it hasn't been shown on the screen yet.
- if ([page hasLoaded])
- [page reloadData];
+ NSLog(@"%@ %@", page, top);
+ if (!selected || page != top)
+ [page unloadData];
}
+
+ if (selected && loaded)
+ [top reloadData];
}
- (void) setDelegate:(id<UINavigationControllerDelegate>)delegate {
NSMutableArray *sections_;
UITableView *list_;
unsigned upgrades_;
- BOOL hasSentFirstLoad_;
}
- (id) initWithDatabase:(Database *)database;
return [NSURL URLWithString:@"cydia://changes"];
}
-- (void) viewWillAppear:(BOOL)animated {
- // Loads after it appears, so don't load beforehand.
- loaded_ = YES;
- [super viewWillAppear:animated];
-}
-
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
-
- if (!hasSentFirstLoad_) {
- hasSentFirstLoad_ = YES;
- [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.0];
- } else {
- [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
- }
+ [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
_trace();
}
-- (void) reloadData {
+- (void) _reloadData {
@synchronized (database_) {
era_ = [database_ era];
NSArray *packages = [database_ packages];
PrintTimes();
} }
+- (void) reloadData {
+ [super reloadData];
+ [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0];
+}
+
@end
/* }}} */
/* Search Controller {{{ */
- (void) reloadData {
[self setObject:[search_ text]];
- [super reloadData];
[self resetCursor];
+
+ [super reloadData];
}
- (void) didSelectPackage:(Package *)package {
[key_ release];
key_ = [[source_ key] retain];
[self setObject:source_];
+
[[self navigationItem] setTitle:[source_ label]];
[super reloadData];
- (void) reloadData {
[super reloadData];
+
[table_ reloadData];
}
- (void) _updateData {
[self _saveConfig];
- [tabbar_ reloadData];
+ [tabbar_ unloadData];
CYNavigationController *navigation = [self queueNavigationController];
essential_ = [[NSMutableArray alloc] initWithCapacity:4];
broken_ = [[NSMutableArray alloc] initWithCapacity:4];
+ // XXX: I really need this thing... like, seriously... I'm sorry
+ [[[CYBrowserController alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/appcache/", UI_]]] reloadData];
+
window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window_ orderFront:self];
[window_ makeKey:self];
return _UIWebDocumentView$_setUIKitDelegate$(self, _cmd, delegate);
}
-static NSNumber *shouldPlayKeyboardSounds;
-
-Class $UIHardware;
+static NSSet *MobilizedFiles_;
-MSHook(void, UIHardware$_playSystemSound$, Class self, SEL _cmd, int sound) {
- switch (sound) {
- case 1104: // Keyboard Button Clicked
- case 1105: // Keyboard Delete Repeated
- if (shouldPlayKeyboardSounds == nil) {
- NSDictionary *dict([[[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.preferences.sounds.plist"] autorelease]);
- shouldPlayKeyboardSounds = [([dict objectForKey:@"keyboard"] ?: (id) kCFBooleanTrue) retain];
- }
-
- if (![shouldPlayKeyboardSounds boolValue])
- break;
-
- default:
- _UIHardware$_playSystemSound$(self, _cmd, sound);
+static NSURL *MobilizeURL(NSURL *url) {
+ NSString *path([url path]);
+ if ([path hasPrefix:@"/var/root/"]) {
+ NSString *file([path substringFromIndex:10]);
+ if ([MobilizedFiles_ containsObject:file])
+ url = [NSURL fileURLWithPath:[@"/var/mobile/" stringByAppendingString:file] isDirectory:NO];
}
-}
-
-Class $UIApplication;
-MSHook(void, UIApplication$_updateApplicationAccessibility, UIApplication *self, SEL _cmd) {
- static BOOL initialized = NO;
- static BOOL started = NO;
+ return url;
+}
- NSDictionary *dict([[[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.Accessibility.plist"] autorelease]);
- BOOL enabled = [[dict objectForKey:@"VoiceOverTouchEnabled"] boolValue] || [[dict objectForKey:@"VoiceOverTouchEnabledByiTunes"] boolValue];
+Class $CFXPreferencesPropertyListSource;
+@class CFXPreferencesPropertyListSource;
- if ([self respondsToSelector:@selector(_accessibilityBundlePrincipalClass)]) {
- id bundle = [self performSelector:@selector(_accessibilityBundlePrincipalClass)];
- if (![bundle respondsToSelector:@selector(_accessibilityStopServer)]) return;
- if (![bundle respondsToSelector:@selector(_accessibilityStartServer)]) return;
+MSHook(BOOL, CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync, CFXPreferencesPropertyListSource *self, SEL _cmd) {
+ NSURL *&url(MSHookIvar<NSURL *>(self, "_url")), *old(url);
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+ url = MobilizeURL(url);
+ BOOL value(_CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync(self, _cmd));
+ //NSLog(@"%@ %s", [url absoluteString], value ? "YES" : "NO");
+ url = old;
+ [pool release];
+ return value;
+}
- if (initialized && !enabled) {
- initialized = NO;
- [bundle performSelector:@selector(_accessibilityStopServer)];
- } else if (enabled) {
- initialized = YES;
- if (!started) {
- started = YES;
- [bundle performSelector:@selector(_accessibilityStartServer)];
- }
- }
- }
+MSHook(void *, CFXPreferencesPropertyListSource$createPlistFromDisk, CFXPreferencesPropertyListSource *self, SEL _cmd) {
+ NSURL *&url(MSHookIvar<NSURL *>(self, "_url")), *old(url);
+ NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+ url = MobilizeURL(url);
+ void *value(_CFXPreferencesPropertyListSource$createPlistFromDisk(self, _cmd));
+ //NSLog(@"%@ %@", [url absoluteString], value);
+ url = old;
+ [pool release];
+ return value;
}
Class $NSURLConnection;
PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
+ MobilizedFiles_ = [NSMutableSet setWithObjects:
+ @"Library/Preferences/com.apple.Accessibility.plist",
+ @"Library/Preferences/com.apple.preferences.sounds.plist",
+ nil];
+
/* Library Hacks {{{ */
class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
+ $CFXPreferencesPropertyListSource = objc_getClass("CFXPreferencesPropertyListSource");
+
+ Method CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync(class_getInstanceMethod($CFXPreferencesPropertyListSource, @selector(_backingPlistChangedSinceLastSync)));
+ if (CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync != NULL) {
+ _CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync = reinterpret_cast<BOOL (*)(CFXPreferencesPropertyListSource *, SEL)>(method_getImplementation(CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync));
+ method_setImplementation(CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync, reinterpret_cast<IMP>(&$CFXPreferencesPropertyListSource$_backingPlistChangedSinceLastSync));
+ }
+
+ Method CFXPreferencesPropertyListSource$createPlistFromDisk(class_getInstanceMethod($CFXPreferencesPropertyListSource, @selector(createPlistFromDisk)));
+ if (CFXPreferencesPropertyListSource$createPlistFromDisk != NULL) {
+ _CFXPreferencesPropertyListSource$createPlistFromDisk = reinterpret_cast<void *(*)(CFXPreferencesPropertyListSource *, SEL)>(method_getImplementation(CFXPreferencesPropertyListSource$createPlistFromDisk));
+ method_setImplementation(CFXPreferencesPropertyListSource$createPlistFromDisk, reinterpret_cast<IMP>(&$CFXPreferencesPropertyListSource$createPlistFromDisk));
+ }
+
$WebDefaultUIKitDelegate = objc_getClass("WebDefaultUIKitDelegate");
Method UIWebDocumentView$_setUIKitDelegate$(class_getInstanceMethod([WebView class], @selector(_setUIKitDelegate:)));
if (UIWebDocumentView$_setUIKitDelegate$ != NULL) {
_NSURLConnection$init$ = reinterpret_cast<id (*)(NSURLConnection *, SEL, NSURLRequest *, id, BOOL, int64_t, BOOL, NSDictionary *)>(method_getImplementation(NSURLConnection$init$));
method_setImplementation(NSURLConnection$init$, reinterpret_cast<IMP>(&$NSURLConnection$init$));
}
-
- $UIHardware = objc_getClass("UIHardware");
- Method UIHardware$_playSystemSound$(class_getClassMethod($UIHardware, @selector(_playSystemSound:)));
- if (UIHardware$_playSystemSound$ != NULL) {
- _UIHardware$_playSystemSound$ = reinterpret_cast<void (*)(Class, SEL, int)>(method_getImplementation(UIHardware$_playSystemSound$));
- method_setImplementation(UIHardware$_playSystemSound$, reinterpret_cast<IMP>(&$UIHardware$_playSystemSound$));
- }
-
- $UIApplication = objc_getClass("UIApplication");
- Method UIApplication$_updateApplicationAccessibility(class_getInstanceMethod($UIApplication, @selector(_updateApplicationAccessibility)));
- if (UIApplication$_updateApplicationAccessibility != NULL) {
- _UIApplication$_updateApplicationAccessibility = reinterpret_cast<void (*)(UIApplication *, SEL)>(method_getImplementation(UIApplication$_updateApplicationAccessibility));
- method_setImplementation(UIApplication$_updateApplicationAccessibility, reinterpret_cast<IMP>(&$UIApplication$_updateApplicationAccessibility));
- }
/* }}} */
/* Set Locale {{{ */
Locale_ = CFLocaleCopyCurrent();
const char *lang;
if (Locale_ != NULL)
lang = [(NSString *) CFLocaleGetIdentifier(Locale_) UTF8String];
- else if (Languages_ == nil || [Languages_ count] == 0)
+ else if (Languages_ != nil && [Languages_ count] != 0)
+ lang = [[Languages_ objectAtIndex:0] UTF8String];
+ else
// XXX: consider just setting to C and then falling through?
lang = NULL;
- else {
- lang = [[Languages_ objectAtIndex:0] UTF8String];
- setenv("LANG", lang, true);
- std::setlocale(LC_ALL, lang);
+
+ if (lang != NULL) {
+ Pcre pattern("^([a-z][a-z])(?:-[A-Za-z]*)?(_[A-Z][A-Z])?$");
+ lang = !pattern(lang) ? NULL : [pattern->*@"%1$@%2$@" UTF8String];
}
NSLog(@"Setting Language: %s", lang);
+
+ if (lang != NULL) {
+ setenv("LANG", lang, true);
+ std::setlocale(LC_ALL, lang);
+ }
/* }}} */
apr_app_initialize(&argc, const_cast<const char * const **>(&argv), NULL);