From 2517c95f6a439390cb5d94a841781999e71accad Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 31 Dec 2008 09:04:06 +0000 Subject: [PATCH 01/16] I think the future is now. --- Cydia.app/Sections.plist | 6 ++++++ UICaboodle/BrowserView.m | 4 +++- control | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cydia.app/Sections.plist b/Cydia.app/Sections.plist index e321b681..6744f6ce 100644 --- a/Cydia.app/Sections.plist +++ b/Cydia.app/Sections.plist @@ -33,6 +33,12 @@ Carrier_Bundles + Messageing + + Rename + Messaging + + Network Rename diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index 5cf07c85..1fd14221 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -293,9 +293,9 @@ } - (void) pushPage:(RVPage *)page { - [self setBackButtonTitle:title_]; [page setDelegate:delegate_]; [book_ pushPage:page]; + [self setBackButtonTitle:title_]; } - (BOOL) getSpecial:(NSURL *)url { @@ -787,6 +787,8 @@ - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { if ([frame parentFrame] != nil) return; + if (reloading_) + return; [self _finishLoading]; [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", diff --git a/control b/control index 35f6c571..36b90336 100644 --- a/control +++ b/control @@ -4,7 +4,7 @@ Priority: required Section: Packaging Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 1.0.2682-38 +Version: 1.0.2683-38 Replaces: com.sosiphone.addcydia Depends: apt, darwintools, pcre, shell-cmds Conflicts: com.sosiphone.addcydia -- 2.45.2 From 81bf90f6b33e7d58719923c8e1260bd2b4ff9907 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 31 Dec 2008 09:40:31 +0000 Subject: [PATCH 02/16] I hate EdgeCast so very bad. --- Cydia.app/package.js | 32 ++++++++++++++++++-------------- Cydia.mm | 2 +- control | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Cydia.app/package.js b/Cydia.app/package.js index de1343c6..1f4939cb 100644 --- a/Cydia.app/package.js +++ b/Cydia.app/package.js @@ -63,33 +63,37 @@ $(function () { $("#name").html(name); space("#latest", package.latest, 96); - $.xhr(api + 'package/' + idc, 'GET', {}, null, { + $.xhr(cache(api + 'package/' + idc), 'GET', {}, null, { success: function (value) { value = eval(value); - $("#rating-load").remove(); + if (typeof value.rating == "undefined") + $(".rating").remove(); + else { + $("#rating-load").remove(); + $("#rating-href").href(value.reviews); - var href = $("#rating-href"); - href.href(value.reviews); + var none = $("#rating-none"); + var done = $("#rating-done"); - var none = $("#rating-none"); - var done = $("#rating-done"); + if (value.rating == null) { + done.remove(); + none.css("display", "block"); + } else { + none.remove(); + done.css("display", "block"); - if (value.rating == null) { - done.remove(); - none.css("display", "block"); - } else { - none.remove(); - done.css("display", "block"); - - $("#rating-value").css('width', 16 * value.rating); + $("#rating-value").css('width', 16 * value.rating); + } } if (typeof value.icon != "undefined" && value.icon != null) { var icon = $("#icon"); var thumb = $("#thumb"); + icon[0].className = 'flip-180'; thumb[0].className = 'flip-360'; + thumb.css("background-image", 'url("' + value.icon + '")'); setTimeout(function () { diff --git a/Cydia.mm b/Cydia.mm index 467fcd64..a4b2e600 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -257,7 +257,7 @@ extern NSString * const kCAFilterNearest; #define lprintf(args...) fprintf(stderr, args) -#define ForRelease 0 +#define ForRelease 1 #define ForSaurik (1 && !ForRelease) #define IgnoreInstall (0 && !ForRelease) #define RecycleWebViews 0 diff --git a/control b/control index 36b90336..81f29b7c 100644 --- a/control +++ b/control @@ -4,7 +4,7 @@ Priority: required Section: Packaging Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 1.0.2683-38 +Version: 1.0.2684-39 Replaces: com.sosiphone.addcydia Depends: apt, darwintools, pcre, shell-cmds Conflicts: com.sosiphone.addcydia -- 2.45.2 From 7398a38978644e7d9123ec01f0403ce15d9c821e Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 21 Jan 2009 13:10:03 +0000 Subject: [PATCH 03/16] Limited parallelism, fixed nil storage, updated style, and added progress huds. --- Cydia.app/menes/style.css | 120 ++++++++++++++++++++++++++++++++------ Cydia.app/storage.js | 2 + Cydia.mm | 118 ++++++++++++++++++++++++------------- control | 2 +- 4 files changed, 182 insertions(+), 60 deletions(-) diff --git a/Cydia.app/menes/style.css b/Cydia.app/menes/style.css index d9915c98..cf664140 100644 --- a/Cydia.app/menes/style.css +++ b/Cydia.app/menes/style.css @@ -252,31 +252,67 @@ list > fieldset > textarea { border-bottom: 1px solid #e0e0e0; } -fieldset > a, +fieldset > a:not([type="ad"]), fieldset > div, fieldset > textarea { - min-height: 42px; /* XXX: small differences due to font bugs */ padding: 13px 14px 11px 14px; } -panel > fieldset > a.thumb:first-child > div:first-of-type { +fieldset > a[type="ad"] { + /* XXX: small differences due to font bugs */ + padding: 4px 4px 2px 5px; +} + +panel > fieldset > a[type="ad"]:first-child > div:first-of-type, +panel > fieldset > a[type="thumb"]:first-child > div:first-of-type { -webkit-border-top-left-radius: 9px; } -panel > fieldset > a.thumb:last-child > div:first-of-type { +panel > fieldset > a[type="ad"]:last-child > div:first-of-type, +panel > fieldset > a[type="thumb"]:last-child > div:first-of-type { -webkit-border-bottom-left-radius: 9px; } -list > fieldset > a.thumb > div:first-of-type { +fieldset > a[type="ad"] > div:first-of-type { + border: 1px solid #999999; +} + +list > fieldset > a[type="thumb"] > div:first-of-type { border: 1px solid #e0e0e0; } -panel > fieldset > a.thumb > div:first-of-type { +panel > fieldset > a[type="thumb"] > div:first-of-type { border: 1px solid #999999; } -fieldset > a.thumb > div:first-of-type { +div[tile] { + float: right; + height: 30px; + width: 30px; +} + +div[tile="app"] { background-image: url(http://cache.saurik.com/cydia/tile/app.png); } +div[tile="call"] { background-image: url(http://cache.saurik.com/cydia/tile/call.png); } +div[tile="map"] { background-image: url(http://cache.saurik.com/cydia/tile/map.png); } +div[tile="media"] { background-image: url(http://cache.saurik.com/cydia/tile/media.png); } +div[tile="music"] { background-image: url(http://cache.saurik.com/cydia/tile/video.png); } +div[tile="site"] { background-image: url(http://cache.saurik.com/cydia/tile/site.png); } + +fieldset > a[type="ad"] > div:first-of-type { + background-repeat: no-repeat; + background-position: center center; + border-right: none; + display: inline-block; + height: 40px; + line-height: 38px; + /* XXX: small differences due to font bugs */ + /* XXX: 1px difference due to border stupidity */ + margin: -5px 5px -3px -6px; + width: 40px; +} + +fieldset > a[type="thumb"] > div:first-of-type { background-repeat: no-repeat; background-position: center center; display: inline-block; @@ -337,7 +373,7 @@ fieldset > div > select { /* Chevrons {{{ */ -fieldset > a[href], +fieldset > a[href]:not([type="ad"]), fieldset > div > select { background-repeat: no-repeat; background-image: url(chevron.png); @@ -417,7 +453,11 @@ fieldset > div > div { width: 273px; } -fieldset > a:not(.thumb) > div { +fieldset > a[type="ad"] > div:nth-of-type(2) { + width: 218px; +} + +fieldset > a:not([type]) > div { width: 250px; } @@ -429,17 +469,17 @@ fieldset > a > img.icon + div { width: 221px; } -fieldset > a.thumb > div:nth-of-type(2) > label:only-of-type { +fieldset > a[type="thumb"] > div:nth-of-type(2) > label:only-of-type { position: relative; top: 10px; } -fieldset > a.thumb > div:nth-of-type(2) > label:nth-of-type(2) { +fieldset > a[type="thumb"] > div:nth-of-type(2) > label:nth-of-type(2) { display: block; margin-top: 2px; } -fieldset > a.thumb > div:nth-of-type(2) { +fieldset > a[type="thumb"] > div:nth-of-type(2) { vertical-align: top; width: 193px; } @@ -451,12 +491,12 @@ fieldset > div > div > label:first-of-type { font-weight: bold; } -list > fieldset > a:not(.thumb) > div > label:nth-of-type(2), +list > fieldset > a:not([type]) > div > label:nth-of-type(2), list > fieldset > div > div > label:nth-of-type(2) { margin-left: 94px; } -panel > fieldset > a:not(.thumb) > div > label:nth-of-type(2), +panel > fieldset > a:not([type]) > div > label:nth-of-type(2), panel > fieldset > div > div > label:nth-of-type(2) { float: right; text-align: right; @@ -469,15 +509,61 @@ panel > img { width: 300px; } -fieldset > a.thumb:first-child > back { +fieldset > a[type="ad"] { +} + +fieldset > a[type="ad"] > div:nth-of-type(2) { + position: relative; + vertical-align: top; +} + +fieldset > a[type="ad"] > div > label:nth-of-type(1) { + color: #2d2d50; + font-size: 13px; + font-weight: bold; + line-height: 15px; +} + +fieldset > a[type="ad"] > div > label:nth-of-type(2) { + position: absolute; + top: 17px; + left: 156px; + font-size: 9.5px; + font-weight: normal; +} + +fieldset.half > a { + background: none; + background-position-x: 120px; +} + +fieldset.half > a > img.icon + div { + width: 65px; +} + +fieldset.right { + float: right; + margin-left: 10px; +} + +block + fieldset.right, +fieldset + fieldset.right { + margin-top: 0; +} + +fieldset.half { + width: 146px; +} + +fieldset > a[type="thumb"]:first-child > back { -webkit-border-top-right-radius: 9px; } -fieldset > a.thumb:last-child > back { +fieldset > a[type="thumb"]:last-child > back { -webkit-border-bottom-right-radius: 9px; } -fieldset > a.thumb > back { +fieldset > a[type="thumb"] > back { background-repeat: no-repeat; border: 1px solid #999999; display: block; diff --git a/Cydia.app/storage.js b/Cydia.app/storage.js index 02dc51b7..73d5de7b 100644 --- a/Cydia.app/storage.js +++ b/Cydia.app/storage.js @@ -57,6 +57,8 @@ var setup = function (name, root, folders) { for (var i = 0; i != folders.length; ++i) { var folder = folders[i]; var usage = cydia.du(folder[1]); + if (usage == null) + usage = 0; var color = colors[i + 2]; var percent = usage / kb; list(legend, color, folder[0], percent); diff --git a/Cydia.mm b/Cydia.mm index a4b2e600..f64b9e4d 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -172,6 +172,56 @@ void NSLogRect(const char *fix, const CGRect &rect) { NSLog(@"%s(%g,%g)+(%g,%g)", fix, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); } +@interface NSObject (Cydia) +- (void) yieldToSelector:(SEL)selector withObject:(id)object; +@end + +@implementation NSObject (Cydia) + +- (void) doNothing { +} + +- (void) _yieldToContext:(NSArray *)context { _pooled + SEL selector(reinterpret_cast([[context objectAtIndex:0] pointerValue])); + id object([[context objectAtIndex:1] nonretainedObjectValue]); + volatile bool &stopped(*reinterpret_cast([[context objectAtIndex:2] pointerValue])); + + [self performSelector:selector withObject:object]; + + stopped = true; + + [self + performSelectorOnMainThread:@selector(doNothing) + withObject:nil + waitUntilDone:NO + ]; +} + +- (void) yieldToSelector:(SEL)selector withObject:(id)object { + volatile bool stopped(false); + + NSArray *context([NSArray arrayWithObjects: + [NSValue valueWithPointer:selector], + [NSValue valueWithNonretainedObject:object], + [NSValue valueWithPointer:const_cast(&stopped)], + nil]); + + NSThread *thread([[[NSThread alloc] + initWithTarget:self + selector:@selector(_yieldToContext:) + object:context + ] autorelease]); + + [thread start]; + + NSRunLoop *loop([NSRunLoop currentRunLoop]); + NSDate *future([NSDate distantFuture]); + + while (!stopped && [loop runMode:NSDefaultRunLoopMode beforeDate:future]); +} + +@end + /* NSForcedOrderingSearch doesn't work on the iPhone */ static const NSStringCompareOptions BaseCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch; static const NSStringCompareOptions ForcedCompareOptions_ = BaseCompareOptions_; @@ -759,6 +809,7 @@ bool isSectionVisible(NSString *section) { - (void) syncData; - (void) askForSettings; - (UIProgressHUD *) addProgressHUD; +- (void) removeProgressHUD:(UIProgressHUD *)hud; - (RVPage *) pageForURL:(NSURL *)url hasTag:(int *)tag; - (RVPage *) pageForPackage:(NSString *)name; - (void) openMailToURL:(NSURL *)url; @@ -1604,7 +1655,7 @@ class Progress : bool value; if (current.end()) - value = essential && [self essential]; + value = essential && [self essential] && [self visible]; else value = !version_.end() && version_ != current;// && (!essential || ![database_ cache][iterator_].Keep()); return value; @@ -2331,7 +2382,7 @@ static NSArray *Finishes_; return issues; } -- (void) reloadData { +- (void) reloadData { _pooled _error->Discard(); delete list_; @@ -2410,6 +2461,9 @@ static NSArray *Finishes_; _trace(); [packages_ sortUsingSelector:@selector(compareByName:)]; _trace(); + + _config->Set("Acquire::http::Timeout", 15); + _config->Set("Acquire::http::MaxParallel", 4); } - (void) configure { @@ -2970,8 +3024,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { SHA1SumValue springlist_; SHA1SumValue notifyconf_; SHA1SumValue sandplate_; - size_t received_; - NSTimeInterval last_; } - (void) transitionViewDidComplete:(UITransitionView*)view fromView:(UIView*)from toView:(UIView*)to; @@ -3281,9 +3333,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [output_ setText:@""]; [progress_ setProgress:0]; - received_ = 0; - last_ = 0;//[NSDate timeIntervalSinceReferenceDate]; - [close_ removeFromSuperview]; [overlay_ addSubview:progress_]; [overlay_ addSubview:status_]; @@ -3377,7 +3426,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) startProgress { - last_ = [NSDate timeIntervalSinceReferenceDate]; } - (void) addProgressOutput:(NSString *)output { @@ -3389,15 +3437,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (bool) isCancelling:(size_t)received { - if (last_ != 0) { - NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; - if (received_ != received) { - received_ = received; - last_ = now; - } else if (now - last_ > 30) - return true; - } - return false; } @@ -4463,9 +4502,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { trivial_gz_ == nil ) { [delegate_ setStatusBarShowsProgress:NO]; + [delegate_ removeProgressHUD:hud_]; - [hud_ show:NO]; - [hud_ removeFromSuperview]; [hud_ autorelease]; hud_ = nil; @@ -4563,7 +4601,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { trivial_ = false; - hud_ = [delegate_ addProgressHUD]; + hud_ = [[delegate_ addProgressHUD] retain]; [hud_ setText:@"Verifying URL"]; } break; @@ -4862,8 +4900,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UIProgressBar *progress_; UINavigationButton *cancel_; bool updating_; - size_t received_; - NSTimeInterval last_; } - (id) initWithFrame:(CGRect)frame database:(Database *)database; @@ -4913,8 +4949,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [prompt_ setText:@"Updating Database"]; [progress_ setProgress:0]; - received_ = 0; - last_ = [NSDate timeIntervalSinceReferenceDate]; updating_ = true; [overlay_ addSubview:cancel_]; @@ -5078,12 +5112,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (bool) isCancelling:(size_t)received { - NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; - if (received_ != received) { - received_ = received; - last_ = now; - } else if (now - last_ > 15) - return true; return !updating_; } @@ -6193,12 +6221,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) _reloadData { - /*UIProgressHUD *hud = [[UIProgressHUD alloc] initWithWindow:window_]; + UIView *block(); + + UIProgressHUD *hud([self addProgressHUD]); [hud setText:@"Reloading Data"]; - [overlay_ addSubview:hud]; - [hud show:YES];*/ - [database_ reloadData]; + [database_ yieldToSelector:@selector(reloadData) withObject:nil]; + _trace(); + + [self removeProgressHUD:hud]; size_t changes(0); @@ -6246,9 +6277,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [book_ update]; } - - /*[hud show:NO]; - [hud removeFromSuperview];*/ } - (void) _saveConfig { @@ -6476,9 +6504,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) finish { if (hud_ != nil) { [self setStatusBarShowsProgress:NO]; + [self removeProgressHUD:hud_]; - [hud_ show:NO]; - [hud_ removeFromSuperview]; [hud_ autorelease]; hud_ = nil; @@ -6724,12 +6751,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (UIProgressHUD *) addProgressHUD { - UIProgressHUD *hud = [[UIProgressHUD alloc] initWithWindow:window_]; + UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window_] autorelease]); + [window_ setUserInteractionEnabled:NO]; [hud show:YES]; - [underlay_ addSubview:hud]; + [progress_ addSubview:hud]; return hud; } +- (void) removeProgressHUD:(UIProgressHUD *)hud { + [hud show:NO]; + [hud removeFromSuperview]; + [window_ setUserInteractionEnabled:YES]; +} + - (void) openMailToURL:(NSURL *)url { // XXX: this makes me sad #if 0 @@ -6867,7 +6901,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { ) { [self setIdleTimerDisabled:YES]; - hud_ = [self addProgressHUD]; + hud_ = [[self addProgressHUD] retain]; [hud_ setText:@"Reorganizing\n\nWill Automatically\nClose When Done"]; [self setStatusBarShowsProgress:YES]; diff --git a/control b/control index 81f29b7c..e036c0e9 100644 --- a/control +++ b/control @@ -4,7 +4,7 @@ Priority: required Section: Packaging Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 1.0.2684-39 +Version: 1.0.2698-41 Replaces: com.sosiphone.addcydia Depends: apt, darwintools, pcre, shell-cmds Conflicts: com.sosiphone.addcydia -- 2.45.2 From b7ad9c68454193574bf8847f08c668a931955b1d Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 21 Jan 2009 13:48:25 +0000 Subject: [PATCH 04/16] I finally found where all the time is going. --- Cydia.mm | 10 +++++++--- control | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index f64b9e4d..61a1f7f3 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -902,8 +902,8 @@ class Progress : protected: virtual void Update() { - [delegate_ setProgressTitle:[NSString stringWithUTF8String:Op.c_str()]]; - [delegate_ setProgressPercent:(Percent / 100)]; + /*[delegate_ setProgressTitle:[NSString stringWithUTF8String:Op.c_str()]]; + [delegate_ setProgressPercent:(Percent / 100)];*/ } public: @@ -917,7 +917,7 @@ class Progress : } virtual void Done() { - [delegate_ setProgressPercent:1]; + //[delegate_ setProgressPercent:1]; } }; /* }}} */ @@ -3123,6 +3123,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [status_ setCentersHorizontally:YES]; //[status_ setFont:font]; + _trace(); output_ = [[UITextView alloc] initWithFrame:CGRectMake( 10, @@ -3130,6 +3131,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { bounds.size.width - 20, bounds.size.height - navsize.height - 62 - navrect.size.height )]; + _trace(); //[output_ setTextFont:@"Courier New"]; [output_ setTextSize:12]; @@ -6523,6 +6525,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return; } + _trace(); overlay_ = [[UIView alloc] initWithFrame:[underlay_ bounds]]; CGRect screenrect = [UIHardware fullScreenApplicationContentRect]; @@ -6857,6 +6860,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) applicationDidFinishLaunching:(id)unused { + _trace(); Font12_ = [[UIFont systemFontOfSize:12] retain]; Font12Bold_ = [[UIFont boldSystemFontOfSize:12] retain]; Font14_ = [[UIFont systemFontOfSize:14] retain]; diff --git a/control b/control index e036c0e9..9a3a92d8 100644 --- a/control +++ b/control @@ -4,7 +4,7 @@ Priority: required Section: Packaging Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 1.0.2698-41 +Version: 1.0.2699-41 Replaces: com.sosiphone.addcydia Depends: apt, darwintools, pcre, shell-cmds Conflicts: com.sosiphone.addcydia -- 2.45.2 From 3bddda52c2e0a47738848f9189f32c0006a9989d Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 22 Jan 2009 05:04:25 +0000 Subject: [PATCH 05/16] Recovered a sixth of a second per keypress in SearchView. --- Cydia.mm | 472 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 312 insertions(+), 160 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index 61a1f7f3..7970cd99 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -55,6 +55,7 @@ // XXX: remove #import +#include #include #include @@ -114,14 +115,68 @@ bool _itv; exit(0); \ } while (false) -static uint64_t profile_; - #define _timestamp ({ \ struct timeval tv; \ gettimeofday(&tv, NULL); \ tv.tv_sec * 1000000 + tv.tv_usec; \ }) +typedef std::vector TimeList; +TimeList times_; + +class ProfileTime { + private: + const char *name_; + uint64_t total_; + + public: + ProfileTime(const char *name) : + name_(name), + total_(0) + { + times_.push_back(this); + } + + void AddTime(uint64_t time) { + total_ += time; + } + + void Print() { + if (total_ != 0) + std::cerr << std::setw(7) << total_ << " : " << name_ << std::endl; + total_ = 0; + } +}; + +class ProfileTimer { + private: + ProfileTime &time_; + uint64_t start_; + + public: + ProfileTimer(ProfileTime &time) : + time_(time), + start_(_timestamp) + { + } + + ~ProfileTimer() { + time_.AddTime(_timestamp - start_); + } +}; + +void PrintTimes() { + for (TimeList::const_iterator i(times_.begin()); i != times_.end(); ++i) + (*i)->Print(); + std::cerr << "========" << std::endl; +} + +#define _profile(name) { \ + static ProfileTime name(#name); \ + ProfileTimer _ ## name(name); + +#define _end } + /* Objective-C Handle<> {{{ */ template class _H { @@ -198,6 +253,9 @@ void NSLogRect(const char *fix, const CGRect &rect) { } - (void) yieldToSelector:(SEL)selector withObject:(id)object { + [self performSelector:selector withObject:object]; + return; + volatile bool stopped(false); NSArray *context([NSArray arrayWithObjects: @@ -223,6 +281,7 @@ void NSLogRect(const char *fix, const CGRect &rect) { @end /* NSForcedOrderingSearch doesn't work on the iPhone */ +static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch; static const NSStringCompareOptions BaseCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch; static const NSStringCompareOptions ForcedCompareOptions_ = BaseCompareOptions_; static const NSStringCompareOptions LaxCompareOptions_ = BaseCompareOptions_ | NSCaseInsensitiveSearch; @@ -307,8 +366,9 @@ extern NSString * const kCAFilterNearest; #define lprintf(args...) fprintf(stderr, args) -#define ForRelease 1 +#define ForRelease 0 #define ForSaurik (1 && !ForRelease) +#define ShowInternals (0 && !ForRelease) #define IgnoreInstall (0 && !ForRelease) #define RecycleWebViews 0 #define AlwaysReload (1 && !ForRelease) @@ -316,6 +376,10 @@ extern NSString * const kCAFilterNearest; #if ForRelease #undef _trace #define _trace(args...) +#undef _profile +#define _profile(name) +#undef _end +#define _end #endif /* Radix Sort {{{ */ @@ -453,12 +517,17 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s @end @interface NSString (Cydia) ++ (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length; + (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length; - (NSComparisonResult) compareByPath:(NSString *)other; @end @implementation NSString (Cydia) ++ (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length { + return [[[NSString alloc] initWithBytesNoCopy:const_cast(bytes) 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]; } @@ -1256,7 +1325,7 @@ class Progress : - (Address *) maintainer; - (size_t) size; - (NSString *) description; -- (NSString *) index; +- (unichar) index; - (NSMutableDictionary *) metadata; - (NSDate *) seen; @@ -1368,157 +1437,196 @@ class Progress : } - (Package *) initWithIterator:(pkgCache::PkgIterator)iterator database:(Database *)database { - if ((self = [super init]) != nil) { + if ((self = [super init]) != nil) { _profile(Package$initWithIterator) iterator_ = iterator; database_ = database; - version_ = [database_ policy]->GetCandidateVer(iterator_); + _profile(Package$initWithIterator$Control) + _end + + _profile(Package$initWithIterator$Version) + version_ = [database_ policy]->GetCandidateVer(iterator_); + _end + NSString *latest = version_.end() ? nil : [NSString stringWithUTF8String:version_.VerStr()]; - latest_ = latest == nil ? nil : [StripVersion(latest) retain]; - pkgCache::VerIterator current = iterator_.CurrentVer(); - NSString *installed = current.end() ? nil : [NSString stringWithUTF8String:current.VerStr()]; - installed_ = [StripVersion(installed) retain]; + _profile(Package$initWithIterator$Latest) + latest_ = latest == nil ? nil : [StripVersion(latest) retain]; + _end - if (!version_.end()) - file_ = version_.FileList(); - else { - pkgCache &cache([database_ cache]); - file_ = pkgCache::VerFileIterator(cache, cache.VerFileP); - } + pkgCache::VerIterator current; + NSString *installed; - id_ = [[NSString stringWithUTF8String:iterator_.Name()] retain]; - - if (!file_.end()) { - pkgRecords::Parser *parser = &[database_ records]->Lookup(file_); - - const char *begin, *end; - parser->GetRec(begin, end); - - NSString *website(nil); - NSString *sponsor(nil); - NSString *author(nil); - NSString *tag(nil); - - struct { - const char *name_; - NSString **value_; - } names[] = { - {"name", &name_}, - {"icon", &icon_}, - {"depiction", &depiction_}, - {"homepage", &homepage_}, - {"website", &website}, - {"sponsor", &sponsor}, - {"author", &author}, - {"tag", &tag}, - }; - - while (begin != end) - if (*begin == '\n') { - ++begin; - continue; - } else if (isblank(*begin)) next: { - begin = static_cast(memchr(begin + 1, '\n', end - begin - 1)); - if (begin == NULL) - break; - } else if (const char *colon = static_cast(memchr(begin, ':', end - begin))) { - const char *name(begin); - size_t size(colon - begin); - - begin = static_cast(memchr(begin, '\n', end - begin)); - - { - const char *stop(begin == NULL ? end : begin); - while (stop[-1] == '\r') - --stop; - while (++colon != stop && isblank(*colon)); - - for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) - if (strncasecmp(names[i].name_, name, size) == 0) { - NSString *value([NSString stringWithUTF8Bytes:colon length:(stop - colon)]); - *names[i].value_ = value; - break; - } - } + _profile(Package$initWithIterator$Current) + current = iterator_.CurrentVer(); + installed = current.end() ? nil : [NSString stringWithUTF8String:current.VerStr()]; + _end - if (begin == NULL) - break; - ++begin; - } else goto next; - - if (name_ != nil) - name_ = [name_ retain]; - tagline_ = [[NSString stringWithUTF8String:parser->ShortDesc().c_str()] retain]; - if (icon_ != nil) - icon_ = [icon_ retain]; - if (depiction_ != nil) - depiction_ = [depiction_ retain]; - if (homepage_ == nil) - homepage_ = website; - if ([homepage_ isEqualToString:depiction_]) - homepage_ = nil; - if (homepage_ != nil) - homepage_ = [homepage_ retain]; - if (sponsor != nil) - sponsor_ = [[Address addressWithString:sponsor] retain]; - if (author != nil) - author_ = [[Address addressWithString:author] retain]; - if (tag != nil) - tags_ = [[tag componentsSeparatedByString:@", "] retain]; - } + _profile(Package$initWithIterator$Installed) + installed_ = [StripVersion(installed) retain]; + _end - if (tags_ != nil) - for (int i(0), e([tags_ count]); i != e; ++i) { - NSString *tag = [tags_ objectAtIndex:i]; - if ([tag hasPrefix:@"role::"]) { - role_ = [[tag substringFromIndex:6] retain]; - break; - } + _profile(Package$initWithIterator$File) + if (!version_.end()) + file_ = version_.FileList(); + else { + pkgCache &cache([database_ cache]); + file_ = pkgCache::VerFileIterator(cache, cache.VerFileP); } + _end + + _profile(Package$initWithIterator$Name) + id_ = [[NSString stringWithUTF8String:iterator_.Name()] retain]; + _end + + if (!file_.end()) + _profile(Package$initWithIterator$Parse) + pkgRecords::Parser *parser; + + _profile(Package$initWithIterator$Parse$Lookup) + parser = &[database_ records]->Lookup(file_); + _end + + const char *begin, *end; + parser->GetRec(begin, end); + + NSString *website(nil); + NSString *sponsor(nil); + NSString *author(nil); + NSString *tag(nil); + + struct { + const char *name_; + NSString **value_; + } names[] = { + {"name", &name_}, + {"icon", &icon_}, + {"depiction", &depiction_}, + {"homepage", &homepage_}, + {"website", &website}, + {"sponsor", &sponsor}, + {"author", &author}, + {"tag", &tag}, + }; + + while (begin != end) + if (*begin == '\n') { + ++begin; + continue; + } else if (isblank(*begin)) next: { + begin = static_cast(memchr(begin + 1, '\n', end - begin - 1)); + if (begin == NULL) + break; + } else if (const char *colon = static_cast(memchr(begin, ':', end - begin))) { + const char *name(begin); + size_t size(colon - begin); + + begin = static_cast(memchr(begin, '\n', end - begin)); + + { + const char *stop(begin == NULL ? end : begin); + while (stop[-1] == '\r') + --stop; + while (++colon != stop && isblank(*colon)); + + for (size_t i(0); i != sizeof(names) / sizeof(names[0]); ++i) + if (strncasecmp(names[i].name_, name, size) == 0) { + NSString *value; + + _profile(Package$initWithIterator$Parse$Value) + value = [NSString stringWithUTF8Bytes:colon length:(stop - colon)]; + _end + + *names[i].value_ = value; + break; + } + } + + if (begin == NULL) + break; + ++begin; + } else goto next; + + _profile(Package$initWithIterator$Parse$Retain) + if (name_ != nil) + name_ = [name_ retain]; + _profile(Package$initWithIterator$Parse$Tagline) + tagline_ = [[NSString stringWithUTF8String:parser->ShortDesc().c_str()] retain]; + _end + if (icon_ != nil) + icon_ = [icon_ retain]; + if (depiction_ != nil) + depiction_ = [depiction_ retain]; + if (homepage_ == nil) + homepage_ = website; + if ([homepage_ isEqualToString:depiction_]) + homepage_ = nil; + if (homepage_ != nil) + homepage_ = [homepage_ retain]; + if (sponsor != nil) + sponsor_ = [[Address addressWithString:sponsor] retain]; + if (author != nil) + author_ = [[Address addressWithString:author] retain]; + if (tag != nil) + tags_ = [[tag componentsSeparatedByString:@", "] retain]; + _end + _end + + _profile(Package$initWithIterator$Tags) + if (tags_ != nil) + for (int i(0), e([tags_ count]); i != e; ++i) { + NSString *tag = [tags_ objectAtIndex:i]; + if ([tag hasPrefix:@"role::"]) { + role_ = [[tag substringFromIndex:6] retain]; + break; + } + } + _end NSString *solid(latest == nil ? installed : latest); bool changed(false); NSString *key([id_ lowercaseString]); - NSMutableDictionary *metadata = [Packages_ objectForKey:key]; - if (metadata == nil) { - metadata = [[NSMutableDictionary dictionaryWithObjectsAndKeys: - now_, @"FirstSeen", - nil] mutableCopy]; - - if (solid != nil) - [metadata setObject:solid forKey:@"LastVersion"]; - changed = true; - } else { - NSDate *first([metadata objectForKey:@"FirstSeen"]); - NSDate *last([metadata objectForKey:@"LastSeen"]); - NSString *version([metadata objectForKey:@"LastVersion"]); - - if (first == nil) { - first = last == nil ? now_ : last; - [metadata setObject:first forKey:@"FirstSeen"]; - changed = true; - } + _profile(Package$initWithIterator$Metadata) + NSMutableDictionary *metadata = [Packages_ objectForKey:key]; + if (metadata == nil) { + metadata = [[NSMutableDictionary dictionaryWithObjectsAndKeys: + now_, @"FirstSeen", + nil] mutableCopy]; - if (solid != nil) - if (version == nil) { - [metadata setObject:solid forKey:@"LastVersion"]; - changed = true; - } else if (![version isEqualToString:solid]) { + if (solid != nil) [metadata setObject:solid forKey:@"LastVersion"]; - last = now_; - [metadata setObject:last forKey:@"LastSeen"]; + changed = true; + } else { + NSDate *first([metadata objectForKey:@"FirstSeen"]); + NSDate *last([metadata objectForKey:@"LastSeen"]); + NSString *version([metadata objectForKey:@"LastVersion"]); + + if (first == nil) { + first = last == nil ? now_ : last; + [metadata setObject:first forKey:@"FirstSeen"]; changed = true; } - } - if (changed) { - [Packages_ setObject:metadata forKey:key]; - Changed_ = true; - } - } return self; + if (solid != nil) + if (version == nil) { + [metadata setObject:solid forKey:@"LastVersion"]; + changed = true; + } else if (![version isEqualToString:solid]) { + [metadata setObject:solid forKey:@"LastVersion"]; + last = now_; + [metadata setObject:last forKey:@"LastSeen"]; + changed = true; + } + } + + if (changed) { + [Packages_ setObject:metadata forKey:key]; + Changed_ = true; + } + _end + _end } return self; } + (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator database:(Database *)database { @@ -1605,9 +1713,16 @@ class Progress : return [trimmed componentsJoinedByString:@"\n"]; } -- (NSString *) index { - NSString *index = [[[self name] substringToIndex:1] uppercaseString]; - return [index length] != 0 && isalpha([index characterAtIndex:0]) ? index : @"123"; +- (unichar) index { + _profile(Package$index) + NSString *name([self name]); + if ([name length] == 0) + return '#'; + unichar character([name characterAtIndex:0]); + if (!isalpha(character)) + return '#'; + return character; + _end } - (NSMutableDictionary *) metadata { @@ -1893,15 +2008,15 @@ class Progress : NSRange range; - range = [[self id] rangeOfString:text options:NSCaseInsensitiveSearch]; + range = [[self id] rangeOfString:text options:MatchCompareOptions_]; if (range.location != NSNotFound) return YES; - range = [[self name] rangeOfString:text options:NSCaseInsensitiveSearch]; + range = [[self name] rangeOfString:text options:MatchCompareOptions_]; if (range.location != NSNotFound) return YES; - range = [[self tagline] rangeOfString:text options:NSCaseInsensitiveSearch]; + range = [[self tagline] rangeOfString:text options:MatchCompareOptions_]; if (range.location != NSNotFound) return YES; @@ -2025,9 +2140,19 @@ class Progress : } - (NSNumber *) isUnfilteredAndSearchedForBy:(NSString *)search { - return [NSNumber numberWithBool:( - [self unfiltered] && [self matches:search] - )]; + _profile(Package$isUnfilteredAndSearchedForBy) + bool value(true); + + _profile(Package$isUnfilteredAndSearchedForBy$Unfiltered) + value &= [self unfiltered]; + _end + + _profile(Package$isUnfilteredAndSearchedForBy$Match) + value &= [self matches:search]; + _end + + return [NSNumber numberWithBool:value]; + _end } - (NSNumber *) isInstalledAndVisible:(NSNumber *)number { @@ -2058,6 +2183,7 @@ class Progress : /* Section Class {{{ */ @interface Section : NSObject { NSString *name_; + unichar index_; size_t row_; size_t count_; } @@ -2065,7 +2191,9 @@ class Progress : - (NSComparisonResult) compareByName:(Section *)section; - (Section *) initWithName:(NSString *)name; - (Section *) initWithName:(NSString *)name row:(size_t)row; +- (Section *) initWithIndex:(unichar)index row:(size_t)row; - (NSString *) name; +- (unichar) index; - (size_t) row; - (size_t) count; - (void) addToCount; @@ -2103,6 +2231,15 @@ class Progress : - (Section *) initWithName:(NSString *)name row:(size_t)row { if ((self = [super init]) != nil) { name_ = [name retain]; + index_ = '\0'; + row_ = row; + } return self; +} + +- (Section *) initWithIndex:(unichar)index row:(size_t)row { + if ((self = [super init]) != nil) { + name_ = [[NSString stringWithCharacters:&index length:1] retain]; + index_ = index; row_ = row; } return self; } @@ -2111,6 +2248,10 @@ class Progress : return name_; } +- (unichar) index { + return index_; +} + - (size_t) row { return row_; } @@ -2454,7 +2595,6 @@ static NSArray *Finishes_; [packages_ removeAllObjects]; _trace(); - profile_ = 0; for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator) if (Package *package = [Package packageWithIterator:iterator database:self]) [packages_ addObject:package]; @@ -4178,25 +4318,32 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [packages_ removeAllObjects]; [sections_ removeAllObjects]; - for (size_t i(0); i != [packages count]; ++i) { - Package *package([packages objectAtIndex:i]); - if ([self hasPackage:package]) - [packages_ addObject:package]; - } + _profile(PackageTable$reloadData$Filter) + for (size_t i(0); i != [packages count]; ++i) { + Package *package([packages objectAtIndex:i]); + if ([self hasPackage:package]) + [packages_ addObject:package]; + } + _end Section *section = nil; - for (size_t offset(0); offset != [packages_ count]; ++offset) { - Package *package = [packages_ objectAtIndex:offset]; - NSString *name = [package index]; + _profile(PackageTable$reloadData$Section) + for (size_t offset(0); offset != [packages_ count]; ++offset) { + Package *package = [packages_ objectAtIndex:offset]; + unichar index = [package index]; - if (section == nil || ![[section name] isEqualToString:name]) { - section = [[[Section alloc] initWithName:name row:offset] autorelease]; - [sections_ addObject:section]; - } + if (section == nil || [section index] != index) { + _profile(PackageTable$reloadData$Section$Allocate) + section = [[[Section alloc] initWithIndex:index row:offset] autorelease]; + _end - [section addToCount]; - } + [sections_ addObject:section]; + } + + [section addToCount]; + } + _end [list_ reloadData]; } @@ -5894,7 +6041,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (flipped_) [self flipPage]; [table_ setObject:[field_ text]]; - [table_ reloadData]; + _profile(SearchView$reloadData) + [table_ reloadData]; + _end + PrintTimes(); [table_ resetCursor]; } @@ -6635,6 +6785,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { withClass:[ManageView class] ] retain]; + PrintTimes(); + if (bootstrap_) [self bootstrap]; else @@ -7047,7 +7199,7 @@ int main(int argc, char *argv[]) { _pooled setuid(0); setgid(0); -#if 1 /* XXX: this costs 1.4s of startup performance */ +#if 0 /* XXX: this costs 1.4s of startup performance */ if (unlink("/var/cache/apt/pkgcache.bin") == -1) _assert(errno == ENOENT); if (unlink("/var/cache/apt/srcpkgcache.bin") == -1) -- 2.45.2 From 9fdd37d07d59a4c976232b53f0170844ebf37247 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 22 Jan 2009 05:40:07 +0000 Subject: [PATCH 06/16] Refactored to foreach everywhere. --- Cydia.mm | 56 +++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index 7970cd99..86453542 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -1574,13 +1574,11 @@ class Progress : _profile(Package$initWithIterator$Tags) if (tags_ != nil) - for (int i(0), e([tags_ count]); i != e; ++i) { - NSString *tag = [tags_ objectAtIndex:i]; + for (NSString *tag in tags_) if ([tag hasPrefix:@"role::"]) { role_ = [[tag substringFromIndex:6] retain]; break; } - } _end NSString *solid(latest == nil ? installed : latest); @@ -1705,7 +1703,7 @@ class Progress : return nil; NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet]; - for (size_t i(1); i != [lines count]; ++i) { + for (size_t i(1), e([lines count]); i != e; ++i) { NSString *trim = [[lines objectAtIndex:i] stringByTrimmingCharactersInSet:whitespace]; [trimmed addObject:trim]; } @@ -2991,8 +2989,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { pkgCacheFile &cache([database_ cache]); NSArray *packages = [database_ packages]; - for (size_t i(0), e = [packages count]; i != e; ++i) { - Package *package = [packages objectAtIndex:i]; + for (Package *package in packages) { pkgCache::PkgIterator iterator = [package iterator]; pkgDepCache::StateCache &state(cache[iterator]); @@ -4319,33 +4316,40 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sections_ removeAllObjects]; _profile(PackageTable$reloadData$Filter) - for (size_t i(0); i != [packages count]; ++i) { - Package *package([packages objectAtIndex:i]); + for (Package *package in packages) if ([self hasPackage:package]) [packages_ addObject:package]; - } _end Section *section = nil; _profile(PackageTable$reloadData$Section) - for (size_t offset(0); offset != [packages_ count]; ++offset) { - Package *package = [packages_ objectAtIndex:offset]; - unichar index = [package index]; + for (size_t offset(0), end([packages_ count]); offset != end; ++offset) { + Package *package; + unichar index; + + _profile(PackageTable$reloadData$Section$Package) + package = [packages_ objectAtIndex:offset]; + index = [package index]; + _end if (section == nil || [section index] != index) { _profile(PackageTable$reloadData$Section$Allocate) section = [[[Section alloc] initWithIndex:index row:offset] autorelease]; _end - [sections_ addObject:section]; + _profile(PackageTable$reloadData$Section$Add) + [sections_ addObject:section]; + _end } [section addToCount]; } _end - [list_ reloadData]; + _profile(PackageTable$reloadData$List) + [list_ reloadData]; + _end } - (NSString *) title { @@ -5519,8 +5523,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSMutableDictionary *sections = [NSMutableDictionary dictionaryWithCapacity:32]; _trace(); - for (size_t i(0); i != [packages count]; ++i) { - Package *package([packages objectAtIndex:i]); + for (Package *package in packages) { NSString *name([package section]); if (name != nil) { @@ -5544,8 +5547,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _trace(); Section *section = nil; - for (size_t offset = 0, count = [filtered count]; offset != count; ++offset) { - Package *package = [filtered objectAtIndex:offset]; + for (Package *package in filtered) { NSString *name = [package section]; if (section == nil || name != nil && ![[section name] isEqualToString:name]) { @@ -5720,15 +5722,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sections_ removeAllObjects]; _trace(); - for (size_t i(0); i != [packages count]; ++i) { - Package *package([packages objectAtIndex:i]); - + for (Package *package in packages) if ( [package installed] == nil && [package valid] && [package visible] || [package upgradableAndEssential:YES] ) [packages_ addObject:package]; - } _trace(); [packages_ radixSortUsingSelector:@selector(compareForChanges) withObject:nil]; @@ -6464,8 +6463,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSArray *keys = [Sources_ allKeys]; - for (int i(0), e([keys count]); i != e; ++i) { - NSString *key = [keys objectAtIndex:i]; + for (NSString *key in keys) { NSDictionary *source = [Sources_ objectForKey:key]; fprintf(file, "%s %s %s\n", @@ -6802,8 +6800,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { switch (button) { case 1: @synchronized (self) { - for (int i = 0, e = [broken_ count]; i != e; ++i) { - Package *broken = [broken_ objectAtIndex:i]; + for (Package *broken in broken_) { [broken remove]; NSString *id = [broken id]; @@ -6859,10 +6856,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { switch (button) { case 1: @synchronized (self) { - for (int i = 0, e = [essential_ count]; i != e; ++i) { - Package *essential = [essential_ objectAtIndex:i]; + for (Package *essential in essential_) [essential install]; - } [self resolve]; [self perform]; @@ -7113,8 +7108,7 @@ void AddPreferences(NSString *plist) { _pooled bool cydia(false); - for (size_t i(0); i != [items count]; ++i) { - NSMutableDictionary *item([items objectAtIndex:i]); + for (NSMutableDictionary *item in items) { NSString *label = [item objectForKey:@"label"]; if (label != nil && [label isEqualToString:@"Cydia"]) { cydia = true; -- 2.45.2 From 7cf548365dc146eab87c5d82c295d7e0287a4f84 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 22 Jan 2009 05:47:36 +0000 Subject: [PATCH 07/16] Removed a core usage of performSelector. --- Cydia.mm | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index 86453542..758a99e7 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -41,6 +41,7 @@ /* #include Directives {{{ */ #import "UICaboodle.h" +#include #include #include @@ -1379,10 +1380,10 @@ class Progress : - (void) install; - (void) remove; -- (NSNumber *) isUnfilteredAndSearchedForBy:(NSString *)search; -- (NSNumber *) isInstalledAndVisible:(NSNumber *)number; -- (NSNumber *) isVisiblyUninstalledInSection:(NSString *)section; -- (NSNumber *) isVisibleInSource:(Source *)source; +- (bool) isUnfilteredAndSearchedForBy:(NSString *)search; +- (bool) isInstalledAndVisible:(NSNumber *)number; +- (bool) isVisiblyUninstalledInSection:(NSString *)section; +- (bool) isVisibleInSource:(Source *)source; @end @@ -2137,7 +2138,7 @@ class Progress : [database_ cache]->MarkDelete(iterator_, true); } -- (NSNumber *) isUnfilteredAndSearchedForBy:(NSString *)search { +- (bool) isUnfilteredAndSearchedForBy:(NSString *)search { _profile(Package$isUnfilteredAndSearchedForBy) bool value(true); @@ -2149,31 +2150,28 @@ class Progress : value &= [self matches:search]; _end - return [NSNumber numberWithBool:value]; + return value; _end } -- (NSNumber *) isInstalledAndVisible:(NSNumber *)number { - return [NSNumber numberWithBool:( - (![number boolValue] || [self visible]) && [self installed] != nil - )]; +- (bool) isInstalledAndVisible:(NSNumber *)number { + return (![number boolValue] || [self visible]) && [self installed] != nil; } -- (NSNumber *) isVisiblyUninstalledInSection:(NSString *)name { +- (bool) isVisiblyUninstalledInSection:(NSString *)name { NSString *section = [self section]; - return [NSNumber numberWithBool:( + return [self visible] && [self installed] == nil && ( name == nil || section == nil && [name length] == 0 || [name isEqualToString:section] - ) - )]; + ); } -- (NSNumber *) isVisibleInSource:(Source *)source { - return [NSNumber numberWithBool:([self source] == source && [self visible])]; +- (bool) isVisibleInSource:(Source *)source { + return [self source] == source && [self visible]; } @end @@ -4404,7 +4402,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (bool) hasPackage:(Package *)package { - return [package valid] && [[package performSelector:filter_ withObject:object_] boolValue]; + return [package valid] && (*reinterpret_cast(&objc_msgSend))(package, filter_, object_); } - (id) initWithBook:(RVBook *)book database:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object { -- 2.45.2 From 142bd2db7f2ea88a8e2d35227005c14092e19d38 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 22 Jan 2009 06:02:46 +0000 Subject: [PATCH 08/16] Welcome to unsafe optimizations. --- Cydia.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index 758a99e7..7e4f33fe 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -129,6 +129,7 @@ class ProfileTime { private: const char *name_; uint64_t total_; + uint64_t count_; public: ProfileTime(const char *name) : @@ -140,12 +141,14 @@ class ProfileTime { void AddTime(uint64_t time) { total_ += time; + ++count_; } void Print() { if (total_ != 0) - std::cerr << std::setw(7) << total_ << " : " << name_ << std::endl; + std::cerr << std::setw(5) << count_ << ", " << std::setw(7) << total_ << " : " << name_ << std::endl; total_ = 0; + count_ = 0; } }; @@ -4375,6 +4378,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { /* Filtered Package Table {{{ */ @interface FilteredPackageTable : PackageTable { SEL filter_; + IMP imp_; id object_; } @@ -4402,7 +4406,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (bool) hasPackage:(Package *)package { - return [package valid] && (*reinterpret_cast(&objc_msgSend))(package, filter_, object_); + _profile(FilteredPackageTable$hasPackage) + return [package valid] && (*reinterpret_cast(imp_))(package, filter_, object_); + _end } - (id) initWithBook:(RVBook *)book database:(Database *)database title:(NSString *)title filter:(SEL)filter with:(id)object { @@ -4410,6 +4416,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { filter_ = filter; object_ = object == nil ? nil : [object retain]; + /* XXX: this is an unsafe optimization of doomy hell */ + Method method = class_getInstanceMethod([Package class], filter); + imp_ = method_getImplementation(method); + _assert(imp_ != NULL); + [self reloadData]; } return self; } -- 2.45.2 From b4dff19ac34e5c1a68af90e1c922fe3908b30979 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 23 Jan 2009 09:07:12 +0000 Subject: [PATCH 09/16] Probably finished repository tagging. --- Cydia.mm | 113 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 98 insertions(+), 15 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index 7e4f33fe..131c0eed 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -232,7 +232,8 @@ void NSLogRect(const char *fix, const CGRect &rect) { } @interface NSObject (Cydia) -- (void) yieldToSelector:(SEL)selector withObject:(id)object; +- (id) yieldToSelector:(SEL)selector withObject:(id)object; +- (id) yieldToSelector:(SEL)selector; @end @implementation NSObject (Cydia) @@ -240,12 +241,17 @@ void NSLogRect(const char *fix, const CGRect &rect) { - (void) doNothing { } -- (void) _yieldToContext:(NSArray *)context { _pooled +- (void) _yieldToContext:(NSMutableArray *)context { _pooled SEL selector(reinterpret_cast([[context objectAtIndex:0] pointerValue])); id object([[context objectAtIndex:1] nonretainedObjectValue]); volatile bool &stopped(*reinterpret_cast([[context objectAtIndex:2] pointerValue])); - [self performSelector:selector withObject:object]; + /* XXX: deal with exceptions */ + id value([self performSelector:selector withObject:object]); + + [context removeAllObjects]; + if (value != nil) + [context addObject:value]; stopped = true; @@ -256,13 +262,13 @@ void NSLogRect(const char *fix, const CGRect &rect) { ]; } -- (void) yieldToSelector:(SEL)selector withObject:(id)object { - [self performSelector:selector withObject:object]; - return; +- (id) yieldToSelector:(SEL)selector withObject:(id)object { + /*[self performSelector:selector withObject:object]; + return;*/ volatile bool stopped(false); - NSArray *context([NSArray arrayWithObjects: + NSMutableArray *context([NSMutableArray arrayWithObjects: [NSValue valueWithPointer:selector], [NSValue valueWithNonretainedObject:object], [NSValue valueWithPointer:const_cast(&stopped)], @@ -280,6 +286,12 @@ void NSLogRect(const char *fix, const CGRect &rect) { NSDate *future([NSDate distantFuture]); while (!stopped && [loop runMode:NSDefaultRunLoopMode beforeDate:future]); + + return [context count] == 0 ? nil : [context objectAtIndex:0]; +} + +- (id) yieldToSelector:(SEL)selector { + return [self yieldToSelector:selector withObject:nil]; } @end @@ -384,6 +396,7 @@ extern NSString * const kCAFilterNearest; #define _profile(name) #undef _end #define _end +#define PrintTimes() do {} while (false) #endif /* Radix Sort {{{ */ @@ -524,6 +537,8 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s + (NSString *) stringWithUTF8BytesNoCopy:(const char *)bytes length:(int)length; + (NSString *) stringWithUTF8Bytes:(const char *)bytes length:(int)length; - (NSComparisonResult) compareByPath:(NSString *)other; +- (NSString *) stringByCachingURLWithCurrentCDN; +- (NSString *) stringByAddingPercentEscapesIncludingReserved; @end @implementation NSString (Cydia) @@ -566,6 +581,26 @@ NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *s return result == NSOrderedSame ? value : result; } +- (NSString *) stringByCachingURLWithCurrentCDN { + return [self + stringByReplacingOccurrencesOfString:@"://" + withString:@"://ne.edgecastcdn.net/8003A4/" + options:0 + /* XXX: this is somewhat inaccurate */ + range:NSMakeRange(0, 10) + ]; +} + +- (NSString *) stringByAddingPercentEscapesIncludingReserved { + return [(id)CFURLCreateStringByAddingPercentEscapes( + kCFAllocatorDefault, + (CFStringRef) self, + NULL, + CFSTR(";/?:@&=+$,"), + kCFStringEncodingUTF8 + ) autorelease]; +} + @end /* Perl-Compatible RegEx {{{ */ @@ -4649,6 +4684,31 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [delegate_ syncData]; } +- (void) complete { + [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys: + @"deb", @"Type", + href_, @"URI", + @"./", @"Distribution", + nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href_]]; + + [delegate_ syncData]; +} + +- (NSString *) getWarning { + NSString *href([href_ stringByAddingPercentEscapesIncludingReserved]); + href = [@"http://cydia.saurik.com/api/repotag/" stringByAppendingString:href]; + href = [href stringByCachingURLWithCurrentCDN]; + + NSURL *url([NSURL URLWithString:href]); + + NSStringEncoding encoding; + NSError *error(nil); + + if (NSString *warning = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error]) + return [warning length] == 0 ? nil : warning; + return nil; +} + - (void) _endConnection:(NSURLConnection *)connection { NSURLConnection **field = NULL; if (connection == trivial_bz2_) @@ -4670,13 +4730,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { hud_ = nil; if (trivial_) { - [Sources_ setObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"deb", @"Type", - href_, @"URI", - @"./", @"Distribution", - nil] forKey:[NSString stringWithFormat:@"deb:%@:./", href_]]; - - [delegate_ syncData]; + if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) { + UIActionSheet *sheet = [[[UIActionSheet alloc] + initWithTitle:@"Repository Warning" + buttons:[NSArray arrayWithObjects:@"Add Source", @"Cancel", nil] + defaultButtonIndex:0 + delegate:self + context:@"warning" + ] autorelease]; + + [sheet setNumberOfRows:1]; + + [sheet setBodyText:warning]; + [sheet popupAlertAnimated:YES]; + } else + [self complete]; } else if (error_ != nil) { UIActionSheet *sheet = [[[UIActionSheet alloc] initWithTitle:@"Verification Error" @@ -4779,6 +4847,21 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sheet dismiss]; else if ([context isEqualToString:@"urlerror"]) [sheet dismiss]; + else if ([context isEqualToString:@"warning"]) { + switch (button) { + case 1: + [self complete]; + break; + + case 2: + break; + + default: + _assert(false); + } + + [sheet dismiss]; + } } - (id) initWithBook:(RVBook *)book database:(Database *)database { @@ -7202,7 +7285,7 @@ int main(int argc, char *argv[]) { _pooled setuid(0); setgid(0); -#if 0 /* XXX: this costs 1.4s of startup performance */ +#if 1 /* XXX: this costs 1.4s of startup performance */ if (unlink("/var/cache/apt/pkgcache.bin") == -1) _assert(errno == ENOENT); if (unlink("/var/cache/apt/srcpkgcache.bin") == -1) -- 2.45.2 From 5a5c1e4bab8fcfdab5b6ee3046be06b0bc3df8f9 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 23 Jan 2009 11:39:31 +0000 Subject: [PATCH 10/16] Fixed some bugs in new window opening. --- UICaboodle/BrowserView.h | 1 + UICaboodle/BrowserView.m | 42 +++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index 632528da..09680e35 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -68,6 +68,7 @@ - (void) reloadURL; - (WebView *) webView; +- (UIWebDocumentView *) documentView; - (id) initWithBook:(RVBook *)book; diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index 1fd14221..08165235 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -168,11 +168,13 @@ @implementation BrowserView -#if ForSaurik +#if ShowInternals #include "Internals.h" #endif - (void) dealloc { + NSLog(@"deallocating WebView"); + if (challenge_ != nil) [challenge_ release]; @@ -260,7 +262,6 @@ } - (void) reloadURL { - NSLog(@"rlu:%@", request_); if (request_ == nil) return; @@ -284,6 +285,10 @@ return [webview_ webView]; } +- (UIWebDocumentView *) documentView { + return webview_; +} + - (void) view:(UIView *)sender didSetFrame:(CGRect)frame { [scroller_ setContentSize:frame.size]; } @@ -294,8 +299,8 @@ - (void) pushPage:(RVPage *)page { [page setDelegate:delegate_]; - [book_ pushPage:page]; [self setBackButtonTitle:title_]; + [book_ pushPage:page]; } - (BOOL) getSpecial:(NSURL *)url { @@ -318,6 +323,9 @@ return true; } +- (void) webViewShow:(WebView *)sender { +} + - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { UIActionSheet *sheet = [[[UIActionSheet alloc] initWithTitle:nil @@ -395,9 +403,10 @@ } - (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id)listener { + NSLog(@"nwa:%@", name); + if (NSURL *url = [request URL]) { if (name == nil) unknown: { - NSLog(@"win:%@:%@", url, [action description]); if (![self getSpecial:url]) { NSString *scheme([[url scheme] lowercaseString]); if ([scheme isEqualToString:@"mailto"]) @@ -411,6 +420,10 @@ RVPage *page([delegate_ pageForURL:url hasTag:NULL]); if (page == nil) { + /* XXX: call createWebViewWithRequest instead */ + + [self setBackButtonTitle:title_]; + BrowserView *browser([[[BrowserView alloc] initWithBook:book] autorelease]); [browser loadURL:url]; page = browser; @@ -630,26 +643,19 @@ return [self _addHeadersToRequest:request]; } -- (WebView *) _createWebViewWithRequest:(NSURLRequest *)request pushed:(BOOL)pushed { - [self setBackButtonTitle:title_]; +- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features { +#if ForSaurik + NSLog(@"cwv:%@ (%@)", request, title_); +#endif BrowserView *browser = [[[BrowserView alloc] initWithBook:book_] autorelease]; - [browser setDelegate:delegate_]; - - if (pushed) { - [browser loadRequest:request]; - [book_ pushPage:browser]; - } - + [self pushPage:browser]; + [browser loadRequest:request]; return [browser webView]; } - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request { - return [self _createWebViewWithRequest:request pushed:(request != nil)]; -} - -- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features { - return [self _createWebViewWithRequest:request pushed:YES]; + return [self webView:sender createWebViewWithRequest:request windowFeatures:nil]; } - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { -- 2.45.2 From a55054a22e40e78286803276227838d44a45530a Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 23 Jan 2009 12:15:00 +0000 Subject: [PATCH 11/16] Fixing more bugs in window opening. --- UICaboodle/BrowserView.m | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index 08165235..8c484253 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -303,7 +303,19 @@ [book_ pushPage:page]; } +- (void) _pushPage { + if (pushed_) + return; + [self autorelease]; + pushed_ = true; + [book_ pushPage:self]; +} + - (BOOL) getSpecial:(NSURL *)url { +#if ForSaurik + NSLog(@"getSpecial:%@", url); +#endif + NSString *href([url absoluteString]); NSString *scheme([[url scheme] lowercaseString]); @@ -471,6 +483,8 @@ } [listener use]; + /* XXX: maybe only the main frame? */ + [self _pushPage]; return; } #if ForSaurik @@ -526,13 +540,6 @@ //lprintf("Status:%s\n", [text UTF8String]); } -- (void) _pushPage { - if (pushed_) - return; - pushed_ = true; - [book_ pushPage:self]; -} - - (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button { NSString *context([sheet context]); @@ -636,10 +643,6 @@ } - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source { - NSURL *url = [request URL]; - if ([self getSpecial:url]) - return nil; - [self _pushPage]; return [self _addHeadersToRequest:request]; } @@ -649,8 +652,16 @@ #endif BrowserView *browser = [[[BrowserView alloc] initWithBook:book_] autorelease]; - [self pushPage:browser]; - [browser loadRequest:request]; + + if (request == nil) { + [self setBackButtonTitle:title_]; + [browser setDelegate:delegate_]; + [browser retain]; + } else { + [self pushPage:browser]; + [browser loadRequest:request]; + } + return [browser webView]; } -- 2.45.2 From 5b2d5cf313b67cf30bf6a916d7de2bc236ddeede Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 23 Jan 2009 12:20:28 +0000 Subject: [PATCH 12/16] I hate working on this project. --- UICaboodle/BrowserView.m | 1 + 1 file changed, 1 insertion(+) diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index 8c484253..fa41f2e9 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -336,6 +336,7 @@ } - (void) webViewShow:(WebView *)sender { + /* XXX: this is where I cry myself to sleep */ } - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { -- 2.45.2 From 7b00c562208237a0ab710c64a94f85f749e84be1 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 26 Jan 2009 10:31:46 +0000 Subject: [PATCH 13/16] Polished browser and finished repotagging. --- Cydia.mm | 58 +++++++++++++++++++-------- UICaboodle/BrowserView.h | 6 +++ UICaboodle/BrowserView.m | 84 ++++++++++++++++++++++++++++++++++------ control | 2 +- 4 files changed, 121 insertions(+), 29 deletions(-) diff --git a/Cydia.mm b/Cydia.mm index 131c0eed..92f58229 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -263,8 +263,7 @@ void NSLogRect(const char *fix, const CGRect &rect) { } - (id) yieldToSelector:(SEL)selector withObject:(id)object { - /*[self performSelector:selector withObject:object]; - return;*/ + /*return [self performSelector:selector withObject:object];*/ volatile bool stopped(false); @@ -382,9 +381,9 @@ extern NSString * const kCAFilterNearest; #define lprintf(args...) fprintf(stderr, args) -#define ForRelease 0 +#define ForRelease 1 #define ForSaurik (1 && !ForRelease) -#define ShowInternals (0 && !ForRelease) +#define ShowInternals (1 && !ForRelease) #define IgnoreInstall (0 && !ForRelease) #define RecycleWebViews 0 #define AlwaysReload (1 && !ForRelease) @@ -393,9 +392,9 @@ extern NSString * const kCAFilterNearest; #undef _trace #define _trace(args...) #undef _profile -#define _profile(name) +#define _profile(name) { #undef _end -#define _end +#define _end } #define PrintTimes() do {} while (false) #endif @@ -787,6 +786,8 @@ static UIFont *Font22Bold_; static const char *Machine_ = NULL; static const NSString *UniqueID_ = nil; static const NSString *Build_ = nil; +static const NSString *Product_ = nil; +static const NSString *Safari_ = nil; CFLocaleRef Locale_; CGColorSpaceRef space_; @@ -4145,6 +4146,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super webView:sender didClearWindowObject:window forFrame:frame]; } +- (bool) _allowJavaScriptPanel { + return false; +} + #if !AlwaysReload - (void) _rightButtonClicked { /*[super _rightButtonClicked]; @@ -4695,7 +4700,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (NSString *) getWarning { - NSString *href([href_ stringByAddingPercentEscapesIncludingReserved]); + NSString *href(href_); + NSRange colon([href rangeOfString:@"://"]); + if (colon.location != NSNotFound) + href = [href substringFromIndex:(colon.location + 3)]; + href = [href stringByAddingPercentEscapes]; href = [@"http://cydia.saurik.com/api/repotag/" stringByAppendingString:href]; href = [href stringByCachingURLWithCurrentCDN]; @@ -4723,17 +4732,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { trivial_bz2_ == nil && trivial_gz_ == nil ) { - [delegate_ setStatusBarShowsProgress:NO]; - [delegate_ removeProgressHUD:hud_]; - - [hud_ autorelease]; - hud_ = nil; + bool defer(false); if (trivial_) { if (NSString *warning = [self yieldToSelector:@selector(getWarning)]) { + defer = true; + UIActionSheet *sheet = [[[UIActionSheet alloc] - initWithTitle:@"Repository Warning" - buttons:[NSArray arrayWithObjects:@"Add Source", @"Cancel", nil] + initWithTitle:@"Source Warning" + buttons:[NSArray arrayWithObjects:@"Add Anyway", @"Cancel", nil] defaultButtonIndex:0 delegate:self context:@"warning" @@ -4769,8 +4776,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [sheet popupAlertAnimated:YES]; } - [href_ release]; - href_ = nil; + [delegate_ setStatusBarShowsProgress:NO]; + [delegate_ removeProgressHUD:hud_]; + + [hud_ autorelease]; + hud_ = nil; + + if (!defer) { + [href_ release]; + href_ = nil; + } if (error_ != nil) { [error_ release]; @@ -4860,6 +4875,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _assert(false); } + [href_ release]; + href_ = nil; + [sheet dismiss]; } } @@ -6466,8 +6484,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) _reloadData { UIView *block(); + static bool loaded(false); UIProgressHUD *hud([self addProgressHUD]); - [hud setText:@"Reloading Data"]; + [hud setText:(loaded ? @"Reloading Data" : @"Loading Data")]; + loaded = true; [database_ yieldToSelector:@selector(reloadData) withObject:nil]; _trace(); @@ -7323,6 +7343,10 @@ int main(int argc, char *argv[]) { _pooled if (NSDictionary *system = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]) Build_ = [system objectForKey:@"ProductBuildVersion"]; + if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) { + Product_ = [info objectForKey:@"SafariProductVersion"]; + Safari_ = [info objectForKey:@"CFBundleVersion"]; + } /*AddPreferences(@"/Applications/Preferences.app/Settings-iPhone.plist"); AddPreferences(@"/Applications/Preferences.app/Settings-iPod.plist");*/ diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index 09680e35..cbb407f7 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -57,6 +57,9 @@ WebScriptObject *function_; bool pushed_; + + float width_; + bool popup_; } - (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button; @@ -71,8 +74,11 @@ - (UIWebDocumentView *) documentView; - (id) initWithBook:(RVBook *)book; +- (id) initWithBook:(RVBook *)book forWidth:(float)width; - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame; - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame; ++ (float) defaultWidth; + @end diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index fa41f2e9..d2a97c84 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -73,6 +73,8 @@ + (NSString *) webScriptNameForSelector:(SEL)selector { if (selector == @selector(getPackageById:)) return @"getPackageById"; + else if (selector == @selector(setAutoPopup:)) + return @"setAutoPopup"; else if (selector == @selector(setButtonImage:withStyle:toFunction:)) return @"setButtonImage"; else if (selector == @selector(setButtonTitle:withStyle:toFunction:)) @@ -155,6 +157,10 @@ return value; } +- (void) setAutoPopup:(BOOL)popup { + [indirect_ setAutoPopup:popup]; +} + - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { [indirect_ setButtonImage:button withStyle:style toFunction:function]; } @@ -173,7 +179,9 @@ #endif - (void) dealloc { - NSLog(@"deallocating WebView"); +#if ForSaurik + NSLog(@"[BrowserView dealloc]"); +#endif if (challenge_ != nil) [challenge_ release]; @@ -339,7 +347,14 @@ /* XXX: this is where I cry myself to sleep */ } +- (bool) _allowJavaScriptPanel { + return true; +} + - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { + if ([self _allowJavaScriptPanel]) + return; + UIActionSheet *sheet = [[[UIActionSheet alloc] initWithTitle:nil buttons:[NSArray arrayWithObjects:@"OK", nil] @@ -353,6 +368,9 @@ } - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { + if (![self _allowJavaScriptPanel]) + return NO; + UIActionSheet *sheet = [[[UIActionSheet alloc] initWithTitle:nil buttons:[NSArray arrayWithObjects:@"OK", @"Cancel", nil] @@ -375,6 +393,10 @@ return [confirm boolValue]; } +- (void) setAutoPopup:(BOOL)popup { + popup_ = popup; +} + - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { if (button_ != nil) [button_ autorelease]; @@ -416,7 +438,9 @@ } - (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id)listener { +#if ForSaurik NSLog(@"nwa:%@", name); +#endif if (NSURL *url = [request URL]) { if (name == nil) unknown: { @@ -433,7 +457,7 @@ RVPage *page([delegate_ pageForURL:url hasTag:NULL]); if (page == nil) { - /* XXX: call createWebViewWithRequest instead */ + /* XXX: call createWebViewWithRequest instead? */ [self setBackButtonTitle:title_]; @@ -505,7 +529,10 @@ int store(_not(int)); if (NSURL *itms = [url itmsURL:&store]) { +#if ForSaurik NSLog(@"itms#%@#%u#%@", url, store, itms); +#endif + if ( store == 1 && [capability containsObject:@"com.apple.MobileStore"] || store == 2 && [capability containsObject:@"com.apple.AppStore"] @@ -648,13 +675,29 @@ } - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features { +//- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request userGesture:(BOOL)gesture { #if ForSaurik - NSLog(@"cwv:%@ (%@)", request, title_); + NSLog(@"cwv:%@ (%@): %@", request, title_, features == nil ? @"{}" : [features description]); + //NSLog(@"cwv:%@ (%@): %@", request, title_, gesture ? @"Yes" : @"No"); #endif - BrowserView *browser = [[[BrowserView alloc] initWithBook:book_] autorelease]; + NSNumber *value([features objectForKey:@"width"]); + float width(value == nil ? [BrowserView defaultWidth] : [value floatValue]); + + RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]); + + /* XXX: deal with cydia:// pages */ + BrowserView *browser([[[BrowserView alloc] initWithBook:book forWidth:width] autorelease]); + + if (features == nil && popup_) { + [book setDelegate:delegate_]; + [browser setDelegate:delegate_]; + + [browser loadRequest:request]; - if (request == nil) { + [book setPage:browser]; + [book_ pushBook:book]; + } else if (request == nil) { [self setBackButtonTitle:title_]; [browser setDelegate:delegate_]; [browser retain]; @@ -668,6 +711,7 @@ - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request { return [self webView:sender createWebViewWithRequest:request windowFeatures:nil]; + //return [self webView:sender createWebViewWithRequest:request userGesture:YES]; } - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { @@ -823,9 +867,11 @@ #endif } -- (id) initWithBook:(RVBook *)book { +- (id) initWithBook:(RVBook *)book forWidth:(float)width { if ((self = [super initWithBook:book]) != nil) { loading_ = false; + width_ = width; + popup_ = false; struct CGRect bounds = [self bounds]; @@ -878,12 +924,13 @@ [webview_ setAutoresizes:YES]; [webview_ setMinimumScale:0.25f forDocumentTypes:0x10]; + [webview_ setMaximumScale:5.00f forDocumentTypes:0x10]; [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10]; - [webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; + //[webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2]; - [webview_ setMinimumScale:1.0f forDocumentTypes:0x8]; + [webview_ setMinimumScale:1.00f forDocumentTypes:0x8]; [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8]; [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8]; @@ -896,12 +943,15 @@ [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller]; [webview_ setSmoothsFonts:YES]; - + [webview_ setAllowsImageSheet:YES]; [webview _setUsesLoaderCache:YES]; - [webview setGroupName:@"Cydia"]; + + [webview setGroupName:@"CydiaGroup"]; [webview _setLayoutInterval:0]; } + [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; + [webview_ setDelegate:self]; [webview_ setGestureDelegate:self]; [scroller_ addSubview:webview_]; @@ -918,8 +968,12 @@ [package installed] ]; + if (Product_ != nil) + application = [NSString stringWithFormat:@"%@ Version/%@", application, Product_]; if (Build_ != nil) - application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application]; + application = [NSString stringWithFormat:@"%@ Mobile/%@", application, Build_]; + if (Safari_ != nil) + application = [NSString stringWithFormat:@"%@ Safari/%@", application, Safari_]; /* XXX: lookup application directory? */ /*if (NSDictionary *safari = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) @@ -942,6 +996,10 @@ } return self; } +- (id) initWithBook:(RVBook *)book { + return [self initWithBook:book forWidth:[[self class] defaultWidth]]; +} + - (void) didFinishGesturesInView:(UIView *)view forEvent:(id)event { [webview_ redrawScaledDocument]; } @@ -1020,4 +1078,8 @@ pushed_ = pushed; } ++ (float) defaultWidth { + return 980; +} + @end diff --git a/control b/control index 9a3a92d8..92b20a26 100644 --- a/control +++ b/control @@ -4,7 +4,7 @@ Priority: required Section: Packaging Maintainer: Jay Freeman (saurik) Architecture: iphoneos-arm -Version: 1.0.2699-41 +Version: 1.0.2705-41 Replaces: com.sosiphone.addcydia Depends: apt, darwintools, pcre, shell-cmds Conflicts: com.sosiphone.addcydia -- 2.45.2 From 263b91b496228fdb5d0d0b0866b933630dd691fb Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 26 Jan 2009 10:52:31 +0000 Subject: [PATCH 14/16] Stupid typo of doomish hell. --- UICaboodle/BrowserView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index d2a97c84..e7dd58be 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -352,7 +352,7 @@ } - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - if ([self _allowJavaScriptPanel]) + if (![self _allowJavaScriptPanel]) return; UIActionSheet *sheet = [[[UIActionSheet alloc] -- 2.45.2 From c46df2040becab3fdecdacdb6f5aa0ddd689c540 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 26 Jan 2009 13:03:31 +0000 Subject: [PATCH 15/16] Fix the new indexing bug. --- Cydia.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cydia.mm b/Cydia.mm index 92f58229..2afe6eee 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -1759,7 +1759,7 @@ class Progress : unichar character([name characterAtIndex:0]); if (!isalpha(character)) return '#'; - return character; + return toupper(character); _end } -- 2.45.2 From 7f96382b0182971b80c46c1c83f1c720c56eb39c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 26 Jan 2009 13:13:30 +0000 Subject: [PATCH 16/16] Forgot to fix the other half of indexing. --- Cydia.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cydia.mm b/Cydia.mm index 2afe6eee..aba5704b 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -2273,7 +2273,7 @@ class Progress : - (Section *) initWithIndex:(unichar)index row:(size_t)row { if ((self = [super init]) != nil) { - name_ = [[NSString stringWithCharacters:&index length:1] retain]; + name_ = [(index == '#' ? @"123" : [NSString stringWithCharacters:&index length:1]) retain]; index_ = index; row_ = row; } return self; -- 2.45.2