X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/19f2d77f02510fd14320166f45a33e6aa77cb396..a09f7a4894d2dde0ac8820993f3d51ba0fe36810:/MobileCydia.mm?ds=inline
diff --git a/MobileCydia.mm b/MobileCydia.mm
index a011b9e0..b95389ac 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -1,40 +1,22 @@
/* Cydia - iPhone UIKit Front-End for Debian APT
- * Copyright (C) 2008-2011 Jay Freeman (saurik)
+ * Copyright (C) 2008-2014 Jay Freeman (saurik)
*/
-/* Modified BSD License {{{ */
+/* GNU General Public License, Version 3 {{{ */
/*
- * Redistribution and use in source and binary
- * forms, with or without modification, are permitted
- * provided that the following conditions are met:
+ * Cydia is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
*
- * 1. Redistributions of source code must retain the
- * above copyright notice, this list of conditions
- * and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions
- * and the following disclaimer in the documentation
- * and/or other materials provided with the
- * distribution.
- * 3. The name of the author may not be used to endorse
- * or promote products derived from this software
- * without specific prior written permission.
+ * Cydia is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+ * You should have received a copy of the GNU General Public License
+ * along with Cydia. If not, see .
+**/
/* }}} */
// XXX: wtf/FastMalloc.h... wtf?
@@ -44,6 +26,9 @@
#include "CyteKit/UCPlatform.h"
#include "CyteKit/Localize.h"
+#include
+#include
+
#include
#include
@@ -56,7 +41,6 @@
#include
#endif
-#include
#include
#include
@@ -69,9 +53,11 @@
#include
#include
+#include
#include
#include
+#include
#include
#include
@@ -123,12 +109,13 @@ extern "C" {
#include
#include "Sources.h"
-#include
+#include "Substrate.hpp"
#include "Menes/Menes.h"
#include "CyteKit/IndirectDelegate.h"
#include "CyteKit/PerlCompatibleRegEx.hpp"
#include "CyteKit/TableViewCell.h"
+#include "CyteKit/TabBarController.h"
#include "CyteKit/WebScriptObject-Cyte.h"
#include "CyteKit/WebViewController.h"
#include "CyteKit/WebViewTableViewCell.h"
@@ -175,7 +162,7 @@ class ProfileTime {
void Print() {
if (total_ != 0)
- std::cerr << std::setw(5) << count_ << ", " << std::setw(7) << total_ << " : " << name_ << std::endl;
+ std::cerr << std::setw(7) << count_ << ", " << std::setw(8) << total_ << " : " << name_ << std::endl;
total_ = 0;
count_ = 0;
}
@@ -221,7 +208,7 @@ extern NSString *Cydia_;
#define ForRelease 1
#define TraceLogging (1 && !ForRelease)
-#define HistogramInsertionSort (!ForRelease ? 0 : 0)
+#define HistogramInsertionSort (0 && !ForRelease)
#define ProfileTimes (0 && !ForRelease)
#define ForSaurik (0 && !ForRelease)
#define LogBrowser (0 && !ForRelease)
@@ -229,7 +216,6 @@ extern NSString *Cydia_;
#define ManualRefresh (1 && !ForRelease)
#define ShowInternals (0 && !ForRelease)
#define AlwaysReload (0 && !ForRelease)
-#define TryIndexedCollation (0 && !ForRelease)
#if !TraceLogging
#undef _trace
@@ -253,14 +239,54 @@ union SplitHash {
};
// }}}
-static bool ShowPromoted_;
+static void setreugid(uid_t uid, gid_t gid) {
+ _assert(setreuid(uid, uid) != -1);
+ _assert(setregid(gid, gid) != -1);
+}
+
+static void setreguid(gid_t gid, uid_t uid) {
+ _assert(setregid(gid, gid) != -1);
+ _assert(setreuid(uid, uid) != -1);
+}
+
+struct Root {
+ Root() {
+ _trace();
+ setreugid(0, 0);
+ _assert(pthread_setugid_np(0, 0) != -1);
+ setreguid(501, 501);
+ }
+
+ ~Root() {
+ _trace();
+ setreugid(0, 0);
+ _assert(pthread_setugid_np(KAUTH_UID_NONE, KAUTH_GID_NONE) != -1);
+ setreguid(501, 501);
+ }
+};
+
+#define _root(code) \
+ ({ Root _root; code; })
static NSString *Colon_;
NSString *Elision_;
static NSString *Error_;
static NSString *Warning_;
-static bool AprilFools_;
+static NSString *Cache_;
+#define Cache(file) \
+ [NSString stringWithFormat:@"%@/%s", Cache_, file]
+
+static void (*$SBSSetInterceptsMenuButtonForever)(bool);
+
+static CFStringRef (*$MGCopyAnswer)(CFStringRef);
+
+static NSString *UniqueIdentifier(UIDevice *device = nil) {
+ if (kCFCoreFoundationVersionNumber < 800) // iOS 7.x
+ return [device ?: [UIDevice currentDevice] uniqueIdentifier];
+ else
+ return [(id)$MGCopyAnswer(CFSTR("UniqueDeviceID")) autorelease];
+}
static bool IsReachable(const char *name) {
SCNetworkReachabilityFlags flags; {
@@ -321,7 +347,7 @@ static CGFloat CYStatusBarHeight() {
/* NSForcedOrderingSearch doesn't work on the iPhone */
static const NSStringCompareOptions MatchCompareOptions_ = NSLiteralSearch | NSCaseInsensitiveSearch;
static const NSStringCompareOptions LaxCompareOptions_ = NSNumericSearch | NSDiacriticInsensitiveSearch | NSWidthInsensitiveSearch | NSCaseInsensitiveSearch;
-static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareCaseInsensitive | kCFCompareNonliteral | kCFCompareLocalized | kCFCompareNumerically | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
+static const CFStringCompareFlags LaxCompareFlags_ = kCFCompareNumerically | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
/* Insertion Sort {{{ */
@@ -683,6 +709,7 @@ static const NSString *UI_;
static int Finish_;
static bool RestartSubstrate_;
+static bool UpgradeCydia_;
static NSArray *Finishes_;
#define SpringBoard_ "/System/Library/LaunchDaemons/com.apple.SpringBoard.plist"
@@ -693,6 +720,7 @@ static bool Queuing_;
static CYColor Blue_;
static CYColor Blueish_;
static CYColor Black_;
+static CYColor Folder_;
static CYColor Off_;
static CYColor White_;
static CYColor Gray_;
@@ -711,6 +739,7 @@ static BOOL Ignored_;
static _H Font12_;
static _H Font12Bold_;
static _H Font14_;
+static _H Font18_;
static _H Font18Bold_;
static _H Font22Bold_;
@@ -720,11 +749,61 @@ static NSString *SerialNumber_ = nil;
static NSString *ChipID_ = nil;
static NSString *BBSNum_ = nil;
static _H Token_;
-static NSString *UniqueID_ = nil;
+static _H UniqueID_;
static _H UserAgent_;
static _H Product_;
static _H Safari_;
+static _H CollationLocale_;
+static _H CollationThumbs_;
+static std::vector CollationOffset_;
+static _H CollationTitles_;
+static _H CollationStarts_;
+static UTransliterator *CollationTransl_;
+//static Function CollationModify_;
+
+typedef std::basic_string ustring;
+static ustring CollationString_;
+
+#define CUC const ustring &str(*reinterpret_cast(rep))
+#define UC ustring &str(*reinterpret_cast(rep))
+static struct UReplaceableCallbacks CollationUCalls_ = {
+ .length = [](const UReplaceable *rep) -> int32_t { CUC;
+ return str.size();
+ },
+
+ .charAt = [](const UReplaceable *rep, int32_t offset) -> UChar { CUC;
+ //fprintf(stderr, "charAt(%d) : %d\n", offset, str.size());
+ if (offset >= str.size())
+ return 0xffff;
+ return str[offset];
+ },
+
+ .char32At = [](const UReplaceable *rep, int32_t offset) -> UChar32 { CUC;
+ //fprintf(stderr, "char32At(%d) : %d\n", offset, str.size());
+ if (offset >= str.size())
+ return 0xffff;
+ UChar32 c;
+ U16_GET(str.data(), 0, offset, str.size(), c);
+ return c;
+ },
+
+ .replace = [](UReplaceable *rep, int32_t start, int32_t limit, const UChar *text, int32_t length) -> void { UC;
+ //fprintf(stderr, "replace(%d, %d, %d) : %d\n", start, limit, length, str.size());
+ str.replace(start, limit - start, text, length);
+ },
+
+ .extract = [](UReplaceable *rep, int32_t start, int32_t limit, UChar *dst) -> void { UC;
+ //fprintf(stderr, "extract(%d, %d) : %d\n", start, limit, str.size());
+ str.copy(dst, limit - start, start);
+ },
+
+ .copy = [](UReplaceable *rep, int32_t start, int32_t limit, int32_t dest) -> void { UC;
+ //fprintf(stderr, "copy(%d, %d, %d) : %d\n", start, limit, dest, str.size());
+ str.replace(dest, 0, str, start, limit - start);
+ },
+};
+
static CFLocaleRef Locale_;
static NSArray *Languages_;
static CGColorSpaceRef space_;
@@ -732,7 +811,6 @@ static CGColorSpaceRef space_;
static NSDictionary *SectionMap_;
static NSMutableDictionary *Metadata_;
static _transient NSMutableDictionary *Settings_;
-static _transient NSString *Role_;
static _transient NSMutableDictionary *Packages_;
static _transient NSMutableDictionary *Values_;
static _transient NSMutableDictionary *Sections_;
@@ -742,7 +820,7 @@ bool Changed_;
static time_t now_;
bool IsWildcat_;
-static CGFloat ScreenScale_;
+CGFloat ScreenScale_;
static NSString *Idiom_;
static _H Firmware_;
static NSString *Major_;
@@ -766,6 +844,26 @@ inline float Interpolate(float begin, float end, float fraction) {
return (end - begin) * fraction + begin;
}
+static inline double Retina(double value) {
+ value *= ScreenScale_;
+ value = round(value);
+ value /= ScreenScale_;
+ return value;
+}
+
+static inline CGRect Retina(CGRect value) {
+ value.origin.x *= ScreenScale_;
+ value.origin.y *= ScreenScale_;
+ value.size.width *= ScreenScale_;
+ value.size.height *= ScreenScale_;
+ value = CGRectIntegral(value);
+ value.origin.x /= ScreenScale_;
+ value.origin.y /= ScreenScale_;
+ value.size.width /= ScreenScale_;
+ value.size.height /= ScreenScale_;
+ return value;
+}
+
static _finline const char *StripVersion_(const char *version) {
const char *colon(strchr(version, ':'));
return colon == NULL ? version : colon + 1;
@@ -788,7 +886,7 @@ NSString *LocalizeSection(NSString *section) {
NSString *Simplify(NSString *title) {
const char *data = [title UTF8String];
- size_t size = [title length];
+ size_t size = [title lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
static Pcre square_r("^\\[(.*)\\]$");
if (square_r(data, size))
@@ -869,6 +967,16 @@ static NSString *CYHex(NSData *data, bool reverse = false) {
@class CYPackageController;
+@protocol SourceDelegate
+- (void) setFetch:(NSNumber *)fetch;
+@end
+
+@protocol FetchDelegate
+- (bool) isSourceCancelled;
+- (void) startSourceFetch:(NSString *)uri;
+- (void) stopSourceFetch:(NSString *)uri;
+@end
+
@protocol CydiaDelegate
- (void) returnToCydia;
- (void) saveState;
@@ -880,6 +988,7 @@ static NSString *CYHex(NSData *data, bool reverse = false) {
- (void) removePackage:(Package *)package;
- (void) beginUpdate;
- (BOOL) updating;
+- (bool) requestUpdate;
- (void) distUpgrade;
- (void) loadData;
- (void) updateData;
@@ -887,7 +996,6 @@ static NSString *CYHex(NSData *data, bool reverse = false) {
- (void) syncData;
- (void) addSource:(NSDictionary *)source;
- (void) addTrivialSource:(NSString *)href;
-- (void) showSettings;
- (UIProgressHUD *) addProgressHUD;
- (void) removeProgressHUD:(UIProgressHUD *)hud;
- (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
@@ -895,67 +1003,88 @@ static NSString *CYHex(NSData *data, bool reverse = false) {
@end
/* }}} */
-/* Status Delegation {{{ */
-class Status :
+/* CancelStatus {{{ */
+class CancelStatus :
public pkgAcquireStatus
{
private:
- _transient NSObject *delegate_;
bool cancelled_;
public:
- Status() :
- delegate_(nil),
+ CancelStatus() :
cancelled_(false)
{
}
- void setDelegate(NSObject *delegate) {
- delegate_ = delegate;
+ virtual bool MediaChange(std::string media, std::string drive) {
+ return false;
}
- NSObject *getDelegate() const {
- return delegate_;
+ virtual void IMSHit(pkgAcquire::ItemDesc &desc) {
+ Done(desc);
}
- virtual bool MediaChange(std::string media, std::string drive) {
- return false;
+ virtual bool Pulse_(pkgAcquire *Owner) = 0;
+
+ virtual bool Pulse(pkgAcquire *Owner) {
+ if (pkgAcquireStatus::Pulse(Owner) && Pulse_(Owner))
+ return true;
+ else {
+ cancelled_ = true;
+ return false;
+ }
+ }
+
+ _finline bool WasCancelled() const {
+ return cancelled_;
+ }
+};
+/* }}} */
+/* DelegateStatus {{{ */
+class CydiaStatus :
+ public CancelStatus
+{
+ private:
+ _transient NSObject *delegate_;
+
+ public:
+ CydiaStatus() :
+ delegate_(nil)
+ {
}
- virtual void IMSHit(pkgAcquire::ItemDesc &item) {
- Done(item);
+ void setDelegate(NSObject *delegate) {
+ delegate_ = delegate;
}
- virtual void Fetch(pkgAcquire::ItemDesc &item) {
- NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]);
- CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:UCLocalize("DOWNLOADING_"), name] ofType:kCydiaProgressEventTypeStatus forItem:item]);
+ virtual void Fetch(pkgAcquire::ItemDesc &desc) {
+ NSString *name([NSString stringWithUTF8String:desc.ShortDesc.c_str()]);
+ CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:UCLocalize("DOWNLOADING_"), name] ofType:kCydiaProgressEventTypeStatus forItemDesc:desc]);
[delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
}
- virtual void Done(pkgAcquire::ItemDesc &item) {
- NSString *name([NSString stringWithUTF8String:item.ShortDesc.c_str()]);
- CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:Colon_, UCLocalize("DONE"), name] ofType:kCydiaProgressEventTypeStatus forItem:item]);
+ virtual void Done(pkgAcquire::ItemDesc &desc) {
+ NSString *name([NSString stringWithUTF8String:desc.ShortDesc.c_str()]);
+ CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithFormat:Colon_, UCLocalize("DONE"), name] ofType:kCydiaProgressEventTypeStatus forItemDesc:desc]);
[delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
}
- virtual void Fail(pkgAcquire::ItemDesc &item) {
+ virtual void Fail(pkgAcquire::ItemDesc &desc) {
if (
- item.Owner->Status == pkgAcquire::Item::StatIdle ||
- item.Owner->Status == pkgAcquire::Item::StatDone
+ desc.Owner->Status == pkgAcquire::Item::StatIdle ||
+ desc.Owner->Status == pkgAcquire::Item::StatDone
)
return;
- std::string &error(item.Owner->ErrorText);
+ std::string &error(desc.Owner->ErrorText);
if (error.empty())
return;
- CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:kCydiaProgressEventTypeError forItem:item]);
+ CydiaProgressEvent *event([CydiaProgressEvent eventWithMessage:[NSString stringWithUTF8String:error.c_str()] ofType:kCydiaProgressEventTypeError forItemDesc:desc]);
[delegate_ performSelectorOnMainThread:@selector(addProgressEvent:) withObject:event waitUntilDone:YES];
}
- virtual bool Pulse(pkgAcquire *Owner) {
- bool value = pkgAcquireStatus::Pulse(Owner);
-
+ virtual bool Pulse_(pkgAcquire *Owner) {
double percent(
double(CurrentBytes + CurrentItems) /
double(TotalBytes + TotalItems)
@@ -969,16 +1098,7 @@ class Status :
[NSNumber numberWithDouble:CurrentCPS], @"Speed",
nil] waitUntilDone:YES];
- if (value && ![delegate_ isProgressCancelled])
- return true;
- else {
- cancelled_ = true;
- return false;
- }
- }
-
- _finline bool WasCancelled() const {
- return cancelled_;
+ return ![delegate_ isProgressCancelled];
}
virtual void Start() {
@@ -1019,7 +1139,7 @@ typedef std::map< unsigned long, _H