X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/6057a4f0f6e2060b768c64382eafd6d2d500f11a..51807490b9d639cc4bad27817134e597743e6336:/MobileCydia.mm
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 41cc4e78..787a78e6 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-2013 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?
@@ -69,9 +51,11 @@
#include
#include
+#include
#include
#include
+#include
#include
#include
@@ -126,10 +110,13 @@ extern "C" {
#include
#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"
#include "CyteKit/stringWithUTF8Bytes.h"
#include "Cydia/MIMEAddress.h"
@@ -209,6 +196,10 @@ void PrintTimes() {
#define _end }
/* }}} */
+// XXX: I hate clang. Apple: please get over your petty hatred of GPL and fix your gcc fork
+#define synchronized(lock) \
+ synchronized(static_cast(lock))
+
extern NSString *Cydia_;
#define lprintf(args...) fprintf(stderr, args)
@@ -252,6 +243,39 @@ NSString *Elision_;
static NSString *Error_;
static NSString *Warning_;
+static NSString *Cache_;
+
+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; {
+ SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, name));
+ SCNetworkReachabilityGetFlags(reachability, &flags);
+ CFRelease(reachability);
+ }
+
+ // XXX: this elaborate mess is what Apple is using to determine this? :(
+ // XXX: do we care if the user has to intervene? maybe that's ok?
+ return
+ (flags & kSCNetworkReachabilityFlagsReachable) != 0 && (
+ (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || (
+ (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 ||
+ (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0
+ ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 ||
+ (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0
+ )
+ ;
+}
+
static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
static _finline NSString *CydiaURL(NSString *path) {
@@ -647,7 +671,7 @@ class CYColor {
/* }}} */
/* Random Global Variables {{{ */
-static const int PulseInterval_ = 50000;
+static int PulseInterval_ = 500000;
static const NSString *UI_;
@@ -663,6 +687,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_;
@@ -681,6 +706,7 @@ static BOOL Ignored_;
static _H Font12_;
static _H Font12Bold_;
static _H Font14_;
+static _H Font18_;
static _H Font18Bold_;
static _H Font22Bold_;
@@ -690,7 +716,7 @@ 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_;
@@ -702,7 +728,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_;
@@ -839,6 +864,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;
@@ -850,44 +885,34 @@ static NSString *CYHex(NSData *data, bool reverse = false) {
- (void) removePackage:(Package *)package;
- (void) beginUpdate;
- (BOOL) updating;
+- (bool) requestUpdate;
- (void) distUpgrade;
- (void) loadData;
- (void) updateData;
+- (void) _saveConfig;
- (void) syncData;
- (void) addSource:(NSDictionary *)source;
- (void) addTrivialSource:(NSString *)href;
-- (void) showSettings;
- (UIProgressHUD *) addProgressHUD;
- (void) removeProgressHUD:(UIProgressHUD *)hud;
-- (CyteViewController *) pageForPackage:(NSString *)name;
- (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
- (void) reloadDataWithInvocation:(NSInvocation *)invocation;
@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;
- }
-
- NSObject *getDelegate() const {
- return delegate_;
- }
-
virtual bool MediaChange(std::string media, std::string drive) {
return false;
}
@@ -896,6 +921,39 @@ class Status :
Done(item);
}
+ 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)
+ {
+ }
+
+ 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]);
@@ -923,9 +981,7 @@ class Status :
[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)
@@ -939,16 +995,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() {
@@ -989,7 +1036,7 @@ typedef std::map< unsigned long, _H