X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/826318ca9072e3d961df9b3b1a57ae5a487cee7d..f8c9fd4c9a853ca14ac1d1fb123e2e6200879bb4:/MobileCydia.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index 76449115..3ed9cbd7 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -53,18 +53,19 @@ #include #include -#include #include +#include #include #include #include #include -#include +#include "fdstream.hpp" #undef ABS +#include "apt.h" #include #include #include @@ -111,7 +112,6 @@ extern "C" { #include "Substrate.hpp" #include "Menes/Menes.h" -#include "CyteKit/IndirectDelegate.h" #include "CyteKit/RegEx.hpp" #include "CyteKit/TableViewCell.h" #include "CyteKit/TabBarController.h" @@ -238,6 +238,16 @@ union SplitHash { }; // }}} +@implementation NSDictionary (Cydia) +- (id) invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)arguments { + if (false); + else if ([name isEqualToString:@"get"]) + return [self objectForKey:[arguments objectAtIndex:0]]; + else if ([name isEqualToString:@"keys"]) + return [self allKeys]; + return nil; +} @end + static NSString *Colon_; NSString *Elision_; static NSString *Error_; @@ -490,6 +500,10 @@ static _finline CFStringRef CYStringCreate(const char *data, size_t size) { CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast(data), size, kCFStringEncodingISOLatin1, NO, kCFAllocatorNull); } +static _finline CFStringRef CYStringCreate(const std::string &data) { + return CYStringCreate(data.data(), data.size()); +} + static _finline CFStringRef CYStringCreate(const char *data) { return CYStringCreate(data, strlen(data)); } @@ -1119,6 +1133,7 @@ typedef std::map< unsigned long, _H > SourceMap; + (Database *) sharedInstance; - (unsigned) era; +- (bool) hasPackages; - (void) _readCydia:(NSNumber *)fd; - (void) _readStatus:(NSNumber *)fd; @@ -1404,14 +1419,14 @@ struct PackageValue : char version_[8]; char name_[]; -}; +} _packed; struct MetaValue : Cytore::Block { uint32_t active_; Cytore::Offset packages_[1 << 16]; -}; +} _packed; static Cytore::File MetaFile_; // }}} @@ -2503,15 +2518,7 @@ struct PackageNameOrdering : _end _profile(Package$parse$Tagline) - const char *start, *end; - if (parser->ShortDesc(start, end)) { - const char *stop(reinterpret_cast(memchr(start, '\n', end - start))); - if (stop == NULL) - stop = end; - while (stop != start && stop[-1] == '\r') - --stop; - parsed->tagline_.set(pool_, start, stop - start); - } + parsed->tagline_.set(pool_, parser->ShortDesc()); _end _profile(Package$parse$Retain) @@ -2540,7 +2547,7 @@ struct PackageNameOrdering : version_ = version; - pkgCache::PkgIterator iterator(version.ParentPkg()); + pkgCache::PkgIterator iterator(version_.ParentPkg()); iterator_ = iterator; _profile(Package$initWithVersion$Version) @@ -2548,7 +2555,7 @@ struct PackageNameOrdering : _end _profile(Package$initWithVersion$Cache) - name_.set(NULL, iterator.Display()); + name_.set(NULL, version_.Display()); latest_.set(NULL, StripVersion_(version_.VerStr())); @@ -2612,7 +2619,11 @@ struct PackageNameOrdering : } while (false); _end _profile(Package$initWithVersion$Tags) +#ifdef __arm64__ + pkgCache::TagIterator tag(version_.TagList()); +#else pkgCache::TagIterator tag(iterator.TagList()); +#endif if (!tag.end()) { tags_ = [NSMutableArray arrayWithCapacity:8]; @@ -2735,6 +2746,21 @@ struct PackageNameOrdering : return iterator_; } +- (NSArray *) downgrades { + NSMutableArray *versions([NSMutableArray arrayWithCapacity:4]); + + for (auto version(iterator_.VersionList()); !version.end(); ++version) { + if (version == version_) + continue; + Package *package([[[Package allocWithZone:NULL] initWithVersion:version withZone:NULL inPool:NULL database:database_] autorelease]); + if ([package source] == nil) + continue; + [versions addObject:package]; + } + + return versions; +} + - (NSString *) section { if (section$_ == nil) { if (section_ == NULL) @@ -2754,7 +2780,10 @@ struct PackageNameOrdering : } - (NSString *) longSection { - return LocalizeSection([self section]); + if (NSString *section = [self section]) + return LocalizeSection(section); + else + return nil; } - (NSString *) shortSection { @@ -2824,23 +2853,12 @@ struct PackageNameOrdering : @synchronized (database_) { pkgRecords::Parser &parser([database_ records]->Lookup(file_)); - - const char *start, *end; - if (!parser.ShortDesc(start, end)) + std::string value(parser.ShortDesc()); + if (value.empty()) return nil; - - if (end - start > 200) - end = start + 200; - - /* - if (const char *stop = reinterpret_cast(memchr(start, '\n', end - start))) - end = stop; - - while (end != start && end[-1] == '\r') - --end; - */ - - return [(id) CYStringCreate(start, end - start) autorelease]; + if (value.size() > 200) + value.resize(200); + return [(id) CYStringCreate(value) autorelease]; } } - (unichar) index { @@ -3328,6 +3346,9 @@ struct PackageNameOrdering : - (void) clear { @synchronized (database_) { + if ([database_ era] != era_ || file_.end()) + return; + pkgProblemResolver *resolver = [database_ resolver]; resolver->Clear(iterator_); @@ -3338,11 +3359,15 @@ struct PackageNameOrdering : - (void) install { @synchronized (database_) { + if ([database_ era] != era_ || file_.end()) + return; + pkgProblemResolver *resolver = [database_ resolver]; resolver->Clear(iterator_); resolver->Protect(iterator_); pkgCacheFile &cache([database_ cache]); + cache->SetCandidateVersion(version_); cache->SetReInstall(iterator_, false); cache->MarkInstall(iterator_, false); @@ -3353,6 +3378,9 @@ struct PackageNameOrdering : - (void) remove { @synchronized (database_) { + if ([database_ era] != era_ || file_.end()) + return; + pkgProblemResolver *resolver = [database_ resolver]; resolver->Clear(iterator_); resolver->Remove(iterator_); @@ -3494,6 +3522,10 @@ class CydiaLogCleaner : CFArrayRemoveAllValues(packages_); } +- (bool) hasPackages { + return CFArrayGetCount(packages_) != 0; +} + - (void) dealloc { // XXX: actually implement this thing _assert(false); @@ -3503,8 +3535,7 @@ class CydiaLogCleaner : } - (void) _readCydia:(NSNumber *)fd { - __gnu_cxx::stdio_filebuf ib([fd intValue], std::ios::in); - std::istream is(&ib); + boost::fdistream is([fd intValue]); std::string line; static RegEx finish_r("finish:([^:]*)"); @@ -3530,8 +3561,7 @@ class CydiaLogCleaner : } - (void) _readStatus:(NSNumber *)fd { - __gnu_cxx::stdio_filebuf ib([fd intValue], std::ios::in); - std::istream is(&ib); + boost::fdistream is([fd intValue]); std::string line; static RegEx conffile_r("status: [^ ]* : conffile-prompt : (.*?) *"); @@ -3587,8 +3617,7 @@ class CydiaLogCleaner : } - (void) _readOutput:(NSNumber *)fd { - __gnu_cxx::stdio_filebuf ib([fd intValue], std::ios::in); - std::istream is(&ib); + boost::fdistream is([fd intValue]); std::string line; while (std::getline(is, line)) { @@ -3615,7 +3644,11 @@ class CydiaLogCleaner : @synchronized (self) { if (static_cast(cache_) == NULL) return nil; - pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String])); + pkgCache::PkgIterator iterator(cache_->FindPkg([name UTF8String] +#ifdef __arm64__ + , "any" +#endif + )); return iterator.end() ? nil : [Package packageWithIterator:iterator withZone:NULL inPool:NULL database:self]; } } @@ -3839,7 +3872,7 @@ class CydiaLogCleaner : opened = cache_.Open(progress, false); _end if (!opened) { - // XXX: what if there are errors, but Open() == true? this should be merged with popError: + // XXX: this block should probably be merged with popError: in some way while (!_error->empty()) { std::string error; bool warning(!_error->PopMessage(error)); @@ -3867,7 +3900,8 @@ class CydiaLogCleaner : } return; - } + } else if ([self popErrorWithTitle:title forOperation:true]) + return; _trace(); unlink("/tmp/cydia.chk"); @@ -4107,10 +4141,8 @@ class CydiaLogCleaner : NSString *nextended(Cache("extended_states")); struct stat info; - if (stat([nextended UTF8String], &info) != -1 && (info.st_mode & S_IFMT) == S_IFREG) { - system([[NSString stringWithFormat:@"/usr/libexec/cydia/cydo /bin/mv -f %@ %@", ShellEscape(nextended), ShellEscape(oextended)] UTF8String]); - system([[NSString stringWithFormat:@"/usr/libexec/cydia/cydo /bin/chown 0:0 %@", ShellEscape(oextended)] UTF8String]); - } + if (stat([nextended UTF8String], &info) != -1 && (info.st_mode & S_IFMT) == S_IFREG) + system([[NSString stringWithFormat:@"/usr/libexec/cydia/cydo /bin/cp --remove-destination %@ %@", ShellEscape(nextended), ShellEscape(oextended)] UTF8String]); unlink([nextended UTF8String]); symlink([oextended UTF8String], [nextended UTF8String]); @@ -4304,7 +4336,7 @@ static _H Diversions_; _transient id delegate_; } -- (id) initWithDelegate:(IndirectDelegate *)indirect; +- (id) initWithDelegate:(CyteWebViewController *)indirect; @end @@ -4324,9 +4356,9 @@ static _H Diversions_; /* Web Scripting {{{ */ @implementation CydiaObject -- (id) initWithDelegate:(IndirectDelegate *)indirect { +- (id) initWithDelegate:(CyteWebViewController *)indirect { if ((self = [super init]) != nil) { - indirect_ = (CyteWebViewController *) indirect; + indirect_ = indirect; } return self; } @@ -4336,8 +4368,10 @@ static _H Diversions_; + (NSArray *) _attributeKeys { return [NSArray arrayWithObjects: + @"bittage", @"bbsnum", @"build", + @"cells", @"coreFoundationVersionNumber", @"device", @"ecid", @@ -4366,6 +4400,17 @@ static _H Diversions_; return Cydia_; } +- (unsigned) bittage { +#if 0 +#elif defined(__arm64__) + return 64; +#elif defined(__arm__) + return 32; +#else + return 0; +#endif +} + - (NSString *) build { return System_; } @@ -4390,6 +4435,29 @@ static _H Diversions_; return (id) Idiom_ ?: [NSNull null]; } +- (NSArray *) cells { + auto *$_CTServerConnectionCreate(reinterpret_cast(dlsym(RTLD_DEFAULT, "_CTServerConnectionCreate"))); + if ($_CTServerConnectionCreate == NULL) + return nil; + + struct CTResult { int flag; int error; }; + auto *$_CTServerConnectionCellMonitorCopyCellInfo(reinterpret_cast(dlsym(RTLD_DEFAULT, "_CTServerConnectionCellMonitorCopyCellInfo"))); + if ($_CTServerConnectionCellMonitorCopyCellInfo == NULL) + return nil; + + _H connection($_CTServerConnectionCreate(NULL, NULL, NULL), true); + if (connection == nil) + return nil; + + int count(0); + CFArrayRef cells(NULL); + auto result($_CTServerConnectionCellMonitorCopyCellInfo(connection, &count, &cells)); + if (result.flag != 0) + return nil; + + return [(NSArray *) cells autorelease]; +} + - (NSString *) mcc { if (CFStringRef (*$CTSIMSupportCopyMobileSubscriberCountryCode)(CFAllocatorRef) = reinterpret_cast(dlsym(RTLD_DEFAULT, "CTSIMSupportCopyMobileSubscriberCountryCode"))) return [(NSString *) (*$CTSIMSupportCopyMobileSubscriberCountryCode)(kCFAllocatorDefault) autorelease]; @@ -4573,10 +4641,7 @@ static _H Diversions_; } - (NSArray *) getDisplayIdentifiers { - NSSet *set([SBSCopyDisplayIdentifiers() autorelease]); - if (set == nil || ![set isKindOfClass:[NSSet class]]) - return [NSArray array]; - return [set allObjects]; + return SBSCopyApplicationDisplayIdentifiers(false, false); } - (NSString *) getLocalizedNameForDisplayIdentifier:(NSString *)identifier { @@ -4795,10 +4860,16 @@ static _H Diversions_; } - (NSString *) substitutePackageNames:(NSString *)message { + auto database([Database sharedInstance]); + + // XXX: this check is less racy than you'd expect, but this entire concept is a little awkward + if (![database hasPackages]) + return message; + NSMutableArray *words([[[message componentsSeparatedByString:@" "] mutableCopy] autorelease]); for (size_t i(0), e([words count]); i != e; ++i) { NSString *word([words objectAtIndex:i]); - if (Package *package = [[Database sharedInstance] packageWithName:word]) + if (Package *package = [database packageWithName:word]) [words replaceObjectAtIndex:i withObject:[package name]]; } @@ -4906,7 +4977,10 @@ static _H Diversions_; @implementation CydiaWebViewController - (NSURL *) navigationURL { - return request_ == nil ? nil : [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request_ URL] absoluteString]]]; + if (NSURLRequest *request = self.request) + return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://url/%@", [[request URL] absoluteString]]]; + else + return nil; } + (void) _initialize { @@ -5009,7 +5083,7 @@ static _H Diversions_; - (id) init { if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) { - cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease]; + cydia_ = [[[CydiaObject alloc] initWithDelegate:self.indirect] autorelease]; } return self; } @@ -5112,7 +5186,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) complete { if (substrate_) RestartSubstrate_ = true; - [delegate_ confirmWithNavigationController:[self navigationController]]; + [self.delegate confirmWithNavigationController:[self navigationController]]; } - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { @@ -5135,7 +5209,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) _doContinue { - [delegate_ cancelAndClear:NO]; + [self.delegate cancelAndClear:NO]; [self dismissModalViewControllerAnimated:YES]; } @@ -5358,7 +5432,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { #endif - (void) cancelButtonClicked { - [delegate_ cancelAndClear:YES]; + [self.delegate cancelAndClear:YES]; [self dismissModalViewControllerAnimated:YES]; } @@ -5542,7 +5616,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (id) initWithDatabase:(Database *)database delegate:(id)delegate { if ((self = [super init]) != nil) { database_ = database; - delegate_ = delegate; + self.delegate = delegate; [database_ setProgressDelegate:self]; @@ -5551,7 +5625,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/progress/", UI_]]]; - [scroller_ setBackgroundColor:[UIColor blackColor]]; + [self setPageColor:[UIColor blackColor]]; [[self navigationItem] setHidesBackButton:YES]; @@ -5577,19 +5651,19 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UpdateExternalStatus(0); if (Finish_ > 1) - [delegate_ saveState]; + [self.delegate saveState]; switch (Finish_) { case 0: - [delegate_ returnToCydia]; + [self.delegate returnToCydia]; break; case 1: - [delegate_ terminateWithSuccess]; - /*if ([delegate_ respondsToSelector:@selector(suspendWithAnimation:)]) - [delegate_ suspendWithAnimation:YES]; + [self.delegate terminateWithSuccess]; + /*if ([self.delegate respondsToSelector:@selector(suspendWithAnimation:)]) + [self.delegate suspendWithAnimation:YES]; else - [delegate_ suspend];*/ + [self.delegate suspend];*/ break; case 2: @@ -5601,9 +5675,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { goto reload; reload: { - UIProgressHUD *hud([delegate_ addProgressHUD]); + UIProgressHUD *hud([self.delegate addProgressHUD]); [hud setText:UCLocalize("LOADING")]; - [delegate_ performSelector:@selector(reloadSpringBoard) withObject:nil afterDelay:0.5]; + [self.delegate performSelector:@selector(reloadSpringBoard) withObject:nil afterDelay:0.5]; return; } @@ -5801,12 +5875,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UIView *content([self contentView]); CGRect bounds([content bounds]); - content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; - [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [content addSubview:content_]; + self.content = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; + [self.content setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [content addSubview:self.content]; - [content_ setDelegate:self]; - [content_ setOpaque:YES]; + [self.content setDelegate:self]; + [self.content setOpaque:YES]; } return self; } @@ -5825,7 +5899,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { placard_ = nil; if (package == nil) - [content_ setBackgroundColor:[UIColor whiteColor]]; + [self.content setBackgroundColor:[UIColor whiteColor]]; else { [package parse]; @@ -5885,18 +5959,18 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { placard = nil; } - [content_ setBackgroundColor:color]; + [self.content setBackgroundColor:color]; if (placard != nil) placard_ = [UIImage imageAtPath:[NSString stringWithFormat:@"%@/%@.png", App_, placard]]; } [self setNeedsDisplay]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } - (void) drawSummaryContentRect:(CGRect)rect { - bool highlighted(highlighted_); + bool highlighted(self.highlighted); float width([self bounds].size.width); if (icon_ != nil) { @@ -5939,7 +6013,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) drawNormalContentRect:(CGRect)rect { - bool highlighted(highlighted_); + bool highlighted(self.highlighted); float width([self bounds].size.width); if (icon_ != nil) { @@ -6024,12 +6098,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { UIView *content([self contentView]); CGRect bounds([content bounds]); - content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; - [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [content addSubview:content_]; - [content_ setBackgroundColor:[UIColor whiteColor]]; + self.content = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; + [self.content setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [content addSubview:self.content]; + [self.content setBackgroundColor:[UIColor whiteColor]]; - [content_ setDelegate:self]; + [self.content setDelegate:self]; } return self; } @@ -6074,7 +6148,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self setAccessoryType:editing ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator]; [self setSelectionStyle:editing ? UITableViewCellSelectionStyleNone : UITableViewCellSelectionStyleBlue]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } - (void) setFrame:(CGRect)frame { @@ -6089,7 +6163,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) drawContentRect:(CGRect)rect { - bool highlighted(highlighted_ && !editing_); + bool highlighted(self.highlighted && !editing_); [icon_ drawInRect:CGRectMake(7, 7, 32, 32)]; @@ -6217,7 +6291,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { NSString *directory = [stack lastObject]; [stack addObject:[file stringByAppendingString:@"/"]]; [files_ replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%*s%@", - ([stack count] - 2) * 3, "", + int(([stack count] - 2) * 3), "", [file substringFromIndex:[directory length]] ]]; } @@ -6244,7 +6318,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { _H name_; bool commercial_; std::vector, _H>> buttons_; + _H sheet_; _H button_; + _H versions_; } - (id) initWithDatabase:(Database *)database forPackage:(NSString *)name withReferrer:(NSString *)referrer; @@ -6257,22 +6333,44 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://package/%@", (id) name_]]; } +- (void) _clickButtonWithPackage:(Package *)package { + [self.delegate installPackage:package]; +} + - (void) _clickButtonWithName:(NSString *)name { if ([name isEqualToString:@"CLEAR"]) - [delegate_ clearPackage:package_]; - else if ([name isEqualToString:@"INSTALL"]) - [delegate_ installPackage:package_]; - else if ([name isEqualToString:@"REINSTALL"]) - [delegate_ installPackage:package_]; + return [self.delegate clearPackage:package_]; else if ([name isEqualToString:@"REMOVE"]) - [delegate_ removePackage:package_]; - else if ([name isEqualToString:@"UPGRADE"]) - [delegate_ installPackage:package_]; + return [self.delegate removePackage:package_]; + else if ([name isEqualToString:@"DOWNGRADE"]) { + sheet_ = [[[UIActionSheet alloc] + initWithTitle:nil + delegate:self + cancelButtonTitle:nil + destructiveButtonTitle:nil + otherButtonTitles:nil + ] autorelease]; + + for (Package *version in (id) versions_) + [sheet_ addButtonWithTitle:[version latest]]; + [sheet_ setContext:@"version"]; + + [self.delegate showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]]; + return; + } + + else if ([name isEqualToString:@"INSTALL"]); + else if ([name isEqualToString:@"REINSTALL"]); + else if ([name isEqualToString:@"UPGRADE"]); else _assert(false); + + [self.delegate installPackage:package_]; } - (void) actionSheet:(UIActionSheet *)sheet clickedButtonAtIndex:(NSInteger)button { NSString *context([sheet context]); + if (sheet_ == sheet) + sheet_ = nil; if ([context isEqualToString:@"modify"]) { if (button != [sheet cancelButtonIndex]) { @@ -6282,6 +6380,16 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [self _clickButtonWithName:buttons_[button].first]; } + [sheet dismissWithClickedButtonIndex:button animated:YES]; + } else if ([context isEqualToString:@"version"]) { + if (button != [sheet cancelButtonIndex]) { + Package *version([versions_ objectAtIndex:button]); + if (IsWildcat_) + [self performSelector:@selector(_clickButtonWithPackage:) withObject:version afterDelay:0]; + else + [self _clickButtonWithPackage:version]; + } + [sheet dismissWithClickedButtonIndex:button animated:YES]; } } @@ -6292,6 +6400,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { #if !AlwaysReload - (void) _customButtonClicked { + if (commercial_ && [package_ uninstalled]) + return [self reloadURLWithCache:NO]; + size_t count(buttons_.size()); if (count == 0) return; @@ -6303,7 +6414,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { for (const auto &button : buttons_) [buttons addObject:button.second]; - UIActionSheet *sheet = [[[UIActionSheet alloc] + sheet_ = [[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil @@ -6311,23 +6422,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { otherButtonTitles:nil ] autorelease]; - for (NSString *button in buttons) [sheet addButtonWithTitle:button]; - if (!IsWildcat_) { - [sheet addButtonWithTitle:UCLocalize("CANCEL")]; - [sheet setCancelButtonIndex:[sheet numberOfButtons] - 1]; - } - [sheet setContext:@"modify"]; + for (NSString *button in buttons) + [sheet_ addButtonWithTitle:button]; + [sheet_ setContext:@"modify"]; - [delegate_ showActionSheet:sheet fromItem:[[self navigationItem] rightBarButtonItem]]; + [self.delegate showActionSheet:sheet_ fromItem:[[self navigationItem] rightBarButtonItem]]; } } -- (void) reloadButtonClicked { - if (commercial_ && function_ == nil && [package_ uninstalled]) - return; - [self customButtonClicked]; -} - - (void) applyLoadingTitle { // Don't show "Loading" as the title. Ever. } @@ -6352,7 +6454,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) reloadData { [super reloadData]; + [sheet_ dismissWithClickedButtonIndex:[sheet_ cancelButtonIndex] animated:YES]; + sheet_ = nil; + package_ = [database_ packageWithName:name_]; + versions_ = [package_ downgrades]; buttons_.clear(); @@ -6372,6 +6478,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { buttons_.push_back(std::make_pair(@"REINSTALL", UCLocalize("REINSTALL"))); if (![package_ uninstalled]) buttons_.push_back(std::make_pair(@"REMOVE", UCLocalize("REMOVE"))); + if ([versions_ count] != 0) + buttons_.push_back(std::make_pair(@"DOWNGRADE", UCLocalize("DOWNGRADE"))); } NSString *title; @@ -6415,7 +6523,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (id) initWithDatabase:(Database *)database title:(NSString *)title; -- (void) setDelegate:(id)delegate; - (void) resetCursor; - (void) clearData; @@ -6528,7 +6635,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { - (void) didSelectPackage:(Package *)package { CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id] withReferrer:[[self referrerURL] absoluteString]] autorelease]); - [view setDelegate:delegate_]; + [view setDelegate:self.delegate]; [[self navigationController] pushViewController:view animated:YES]; } @@ -6626,10 +6733,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { [super releaseSubviews]; } -- (void) setDelegate:(id)delegate { - delegate_ = delegate; -} - - (bool) shouldYield { return false; } @@ -6662,7 +6765,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (![self shouldBlock]) hud = nil; else { - hud = [delegate_ addProgressHUD]; + hud = [self.delegate addProgressHUD]; [hud setText:UCLocalize("LOADING")]; } @@ -6670,7 +6773,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { packages = [self yieldToSelector:@selector(_reloadPackages)]; if (hud != nil) - [delegate_ removeProgressHUD:hud]; + [self.delegate removeProgressHUD:hud]; } while (reloading_ == 2); } else { packages = [self _reloadPackages]; @@ -7337,7 +7440,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (editing) [list_ reloadData]; else - [delegate_ updateData]; + [self.delegate updateData]; [self updateNavigationItem]; } @@ -7399,7 +7502,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi source:[self source] section:[section name] ] autorelease]; - [controller setDelegate:delegate_]; + [controller setDelegate:self.delegate]; [[self navigationController] pushViewController:controller animated:YES]; } @@ -7544,7 +7647,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) setLeftBarButtonItem { - if ([delegate_ updating]) + if ([self.delegate updating]) [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CANCEL") style:UIBarButtonItemStyleDone @@ -7561,16 +7664,16 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) refreshButtonClicked { - if ([delegate_ requestUpdate]) + if ([self.delegate requestUpdate]) [self setLeftBarButtonItem]; } - (void) cancelButtonClicked { - [delegate_ cancelUpdate]; + [self.delegate cancelUpdate]; } - (void) upgradeButtonClicked { - [delegate_ distUpgrade]; + [self.delegate distUpgrade]; [[self navigationItem] setRightBarButtonItem:nil animated:YES]; } @@ -7915,7 +8018,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi if (package_ == nil) return; if ([package_ setSubscribed:value]) - [delegate_ updateData]; + [self.delegate updateData]; } - (void) _updateIgnored { @@ -7938,7 +8041,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [invocation setTarget:self]; [invocation setSelector:@selector(_updateIgnored)]; - [delegate_ reloadDataWithInvocation:invocation]; + [self.delegate reloadDataWithInvocation:invocation]; } - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -8129,7 +8232,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi #if !AlwaysReload - (void) queueButtonClicked { - [delegate_ queue]; + [self.delegate queue]; } #endif @@ -8179,7 +8282,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi - (void) _setImage:(NSArray *)data { if ([url_ isEqual:[data objectAtIndex:0]]) { icon_ = [data objectAtIndex:1]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } } @@ -8213,7 +8316,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi origin_ = [source name]; label_ = [source rooturi]; - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; url_ = [source iconURL]; [NSThread detachNewThreadSelector:@selector(_setSource:) toTarget:self withObject:url_]; @@ -8226,7 +8329,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi icon_ = [UIImage imageNamed:@"folder.png"]; origin_ = UCLocalize("ALL_SOURCES"); label_ = UCLocalize("ALL_SOURCES_EX"); - [content_ setNeedsDisplay]; + [self.content setNeedsDisplay]; } - (SourceCell *) initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { @@ -8234,19 +8337,19 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi UIView *content([self contentView]); CGRect bounds([content bounds]); - content_ = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; - [content_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; - [content_ setBackgroundColor:[UIColor whiteColor]]; - [content addSubview:content_]; + self.content = [[[CyteTableViewCellContentView alloc] initWithFrame:bounds] autorelease]; + [self.content setAutoresizingMask:UIViewAutoresizingFlexibleBoth]; + [self.content setBackgroundColor:[UIColor whiteColor]]; + [content addSubview:self.content]; - [content_ setDelegate:self]; - [content_ setOpaque:YES]; + [self.content setDelegate:self]; + [self.content setOpaque:YES]; indicator_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGraySmall] autorelease]; [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin];// | UIViewAutoresizingFlexibleBottomMargin]; [content addSubview:indicator_]; - [[content_ layer] setContentsGravity:kCAGravityTopLeft]; + [[self.content layer] setContentsGravity:kCAGravityTopLeft]; } return self; } @@ -8270,7 +8373,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) drawContentRect:(CGRect)rect { - bool highlighted(highlighted_); + bool highlighted(self.highlighted); float width(rect.size.width); if (icon_ != nil) { @@ -8414,7 +8517,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi source:[self sourceAtIndexPath:indexPath] ] autorelease]); - [controller setDelegate:delegate_]; + [controller setDelegate:self.delegate]; [[self navigationController] pushViewController:controller animated:YES]; } @@ -8433,8 +8536,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [Sources_ removeObjectForKey:[source key]]; - [delegate_ _saveConfig]; - [delegate_ reloadDataWithInvocation:nil]; + [self.delegate syncData]; } } @@ -8443,10 +8545,10 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) complete { - [delegate_ addTrivialSource:href_]; + [self.delegate addTrivialSource:href_]; href_ = nil; - [delegate_ syncData]; + [self.delegate syncData]; } - (NSString *) getWarning { @@ -8485,9 +8587,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi ) { NSString *warning(cydia_ ? [self yieldToSelector:@selector(getWarning)] : nil); - [delegate_ releaseNetworkActivityIndicator]; + [self.delegate releaseNetworkActivityIndicator]; - [delegate_ removeProgressHUD:hud_]; + [self.delegate removeProgressHUD:hud_]; hud_ = nil; if (cydia_) { @@ -8604,9 +8706,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi cydia_ = false; // XXX: this is stupid - hud_ = [delegate_ addProgressHUD]; + hud_ = [self.delegate addProgressHUD]; [hud_ setText:UCLocalize("VERIFYING_URL")]; - [delegate_ retainNetworkActivityIndicator]; + [self.delegate retainNetworkActivityIndicator]; } break; case 0: @@ -8646,7 +8748,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi target:self action:@selector(addButtonClicked) ] autorelease] animated:animated]; - else if ([delegate_ updating]) + else if ([self.delegate updating]) [[self navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CANCEL") style:UIBarButtonItemStyleDone @@ -8746,7 +8848,7 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi [alert setNumberOfRows:1]; [alert addTextFieldWithValue:@"http://" label:@""]; - UITextInputTraits *traits = [[alert textField] textInputTraits]; + NSObject *traits = [[alert textField] textInputTraits]; [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; [traits setKeyboardType:UIKeyboardTypeURL]; @@ -8761,12 +8863,12 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi } - (void) refreshButtonClicked { - if ([delegate_ requestUpdate]) + if ([self.delegate requestUpdate]) [self updateButtonsForEditingStatusAnimated:YES]; } - (void) cancelButtonClicked { - [delegate_ cancelUpdate]; + [self.delegate cancelUpdate]; } - (void) editButtonClicked { @@ -9020,9 +9122,9 @@ static void HomeControllerReachabilityCallback(SCNetworkReachabilityRef reachabi - (void) reloadSpringBoard { if (kCFCoreFoundationVersionNumber >= 700) // XXX: iOS 6.x - system("/bin/launchctl stop com.apple.backboardd"); + system("/usr/libexec/cydia/cydo /bin/launchctl stop com.apple.backboardd"); else - system("/bin/launchctl stop com.apple.SpringBoard"); + system("/usr/libexec/cydia/cydo /bin/launchctl stop com.apple.SpringBoard"); sleep(15); system("/usr/bin/killall backboardd SpringBoard"); } @@ -9496,7 +9598,7 @@ _end [super applicationSuspend]; } -- (void) applicationSuspend:(__GSEvent *)event { +- (void) applicationSuspend:(GSEventRef)event { if ([self isSafeToSuspend]) [super applicationSuspend:event]; } @@ -10010,6 +10112,11 @@ _trace(); } - (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item { + if (!IsWildcat_) { + [sheet addButtonWithTitle:UCLocalize("CANCEL")]; + [sheet setCancelButtonIndex:[sheet numberOfButtons] - 1]; + } + if (item != nil && IsWildcat_) { [sheet showFromBarButtonItem:item animated:YES]; } else { @@ -10113,7 +10220,18 @@ static NSMutableDictionary *AutoreleaseDeepMutableCopyOfDictionary(CFTypeRef typ return [(NSMutableDictionary *) copy autorelease]; } +int main_store(int, char *argv[]); + int main(int argc, char *argv[]) { +#ifdef __arm64__ + const char *argv0(argv[0]); + if (const char *slash = strrchr(argv0, '/')) + argv0 = slash + 1; + if (false); + else if (!strcmp(argv0, "store")) + return main_store(argc, argv); +#endif + int fd(open("/tmp/cydia.log", O_WRONLY | O_APPEND | O_CREAT, 0644)); dup2(fd, 2); close(fd); @@ -10190,29 +10308,28 @@ int main(int argc, char *argv[]) { Locale_ = CFLocaleCopyCurrent(); Languages_ = [NSLocale preferredLanguages]; - //CFStringRef locale(CFLocaleGetIdentifier(Locale_)); - //NSLog(@"%@", [Languages_ description]); + std::string languages; + const char *translation(NULL); - const char *lang; + // XXX: this isn't really a language, but this is compatible with older Cydia builds if (Locale_ != NULL) - lang = [(NSString *) CFLocaleGetIdentifier(Locale_) UTF8String]; - 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; - - if (lang != NULL) { - RegEx pattern("([a-z][a-z])(?:-[A-Za-z]*)?(_[A-Z][A-Z])?"); - lang = !pattern(lang) ? NULL : [pattern->*@"%1$@%2$@" UTF8String]; - } + if (const char *language = [(NSString *) CFLocaleGetIdentifier(Locale_) UTF8String]) { + RegEx pattern("([a-z][a-z])(?:-[A-Za-z]*)?(_[A-Z][A-Z])?"); + if (pattern(language)) { + translation = strdup([pattern->*@"%1$@%2$@" UTF8String]); + languages += translation; + languages += ","; + } + } - NSLog(@"Setting Language: %s", lang); + if (Languages_ != nil) + for (NSString *language : Languages_) { + languages += [language UTF8String]; + languages += ","; + } - if (lang != NULL) { - setenv("LANG", lang, true); - std::setlocale(LC_ALL, lang); - } + languages += "en"; + NSLog(@"Setting Language: [%s] %s", translation, languages.c_str()); /* }}} */ /* Index Collation {{{ */ if (Class $UILocalizedIndexedCollation = objc_getClass("UILocalizedIndexedCollation")) { @try { @@ -10293,6 +10410,7 @@ int main(int argc, char *argv[]) { Advanced_ = YES; Cache_ = [[NSString stringWithFormat:@"%@/Library/Caches/com.saurik.Cydia", @"/var/mobile"] retain]; + mkdir([Cache_ UTF8String], 0755); /*Method alloc = class_getClassMethod([NSObject class], @selector(alloc)); alloc_ = alloc->method_imp; @@ -10457,15 +10575,21 @@ int main(int argc, char *argv[]) { _assert(pkgInitConfig(*_config)); _assert(pkgInitSystem(*_config, _system)); - if (lang != NULL) - _config->Set("APT::Acquire::Translation", lang); + _config->Set("Acquire::AllowInsecureRepositories", true); + _config->Set("Acquire::Check-Valid-Until", false); + _config->Set("Dir::Bin::Methods::store", "/Applications/Cydia.app/store"); + + _config->Set("pkgCacheGen::ForceEssential", ""); + + if (translation != NULL) + _config->Set("APT::Acquire::Translation", translation); + _config->Set("Acquire::Languages", languages); // XXX: this timeout might be important :( //_config->Set("Acquire::http::Timeout", 15); _config->Set("Acquire::http::MaxParallel", usermem >= 384 * 1024 * 1024 ? 16 : 3); - mkdir([Cache_ UTF8String], 0755); mkdir([Cache("archives") UTF8String], 0755); mkdir([Cache("archives/partial") UTF8String], 0755); _config->Set("Dir::Cache", [Cache_ UTF8String]); @@ -10480,7 +10604,7 @@ int main(int argc, char *argv[]) { std::string logs("/var/mobile/Library/Logs/Cydia"); mkdir(logs.c_str(), 0755); - _config->Set("Dir::Log::Terminal", logs + "/apt.log"); + _config->Set("Dir::Log", logs); _config->Set("Dir::Bin::dpkg", "/usr/libexec/cydia/cydo"); /* }}} */