From 25c1dafb7565aea86bec1f415896e4ad1431906b Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sat, 12 Mar 2011 14:34:19 -0800 Subject: [PATCH] Separate out Sources.mm. --- MobileCydia.mm | 99 +++++++++++++++++--------------------------------- Sources.h | 49 +++++++++++++++++++++++++ Sources.mm | 93 +++++++++++++++++++++++++++++++++++++++++++++++ makefile | 2 +- 4 files changed, 177 insertions(+), 66 deletions(-) create mode 100644 Sources.h create mode 100644 Sources.mm diff --git a/MobileCydia.mm b/MobileCydia.mm index fb483a86..43217de9 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -121,6 +121,7 @@ extern "C" { #include #include +#include "Sources.h" #include #include "Menes/Menes.h" @@ -705,16 +706,16 @@ static _transient NSString *Role_; static _transient NSMutableDictionary *Packages_; static _transient NSMutableDictionary *Values_; static _transient NSMutableDictionary *Sections_; -static _transient NSMutableDictionary *Sources_; +_H Sources_; static _transient NSNumber *Version_; -static _transient _H CydiaSource_; -static bool Changed_; +_H CydiaSource_; +bool Changed_; static time_t now_; bool IsWildcat_; static CGFloat ScreenScale_; static NSString *Idiom_; -static NSString *Firmware_; +_H Firmware_; static NSString *Major_; static _H SessionData_; @@ -731,50 +732,6 @@ static NSString *kCydiaProgressEventTypeStatus = @"Status"; static NSString *kCydiaProgressEventTypeWarning = @"Warning"; /* }}} */ -static void AddSource(NSDictionary *source) { - [Sources_ setObject:source forKey:[NSString stringWithFormat:@"%@:%@:%@", [source objectForKey:@"Type"], [source objectForKey:@"URI"], [source objectForKey:@"Distribution"]]]; - Changed_ = true; -} - -static void AddSource(NSString *href, NSString *distribution, NSArray *sections = nil) { - AddSource([NSMutableDictionary dictionaryWithObjectsAndKeys: - @"deb", @"Type", - href, @"URI", - distribution, @"Distribution", - sections ?: [NSMutableArray array], @"Sections", - nil]); -} - -static void WriteSources() { - FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w")); - _assert(file != NULL); - - NSString *distribution(@"ios"); - if (Firmware_ != nil) - distribution = [distribution stringByAppendingString:[NSString stringWithFormat:@"-%@", Firmware_]]; - - fprintf(file, "deb http://%s/ %s main\n", - [CydiaSource_ UTF8String], - [distribution UTF8String] - ); - - for (NSString *key in [Sources_ allKeys]) { - NSDictionary *source([Sources_ objectForKey:key]); - - NSArray *sections([source objectForKey:@"Sections"] ?: [NSArray array]); - - fprintf(file, "%s %s %s%s%s\n", - [[source objectForKey:@"Type"] UTF8String], - [[source objectForKey:@"URI"] UTF8String], - [[source objectForKey:@"Distribution"] UTF8String], - [sections count] == 0 ? "" : " ", - [[sections componentsJoinedByString:@" "] UTF8String] - ); - } - - fclose(file); -} - /* Display Helpers {{{ */ inline float Interpolate(float begin, float end, float fraction) { return (end - begin) * fraction + begin; @@ -5531,13 +5488,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { CGRect rect; rect.size = [(UIImage *) icon_ size]; - while (rect.size.width > 32 || rect.size.height > 32) { + while (rect.size.width > 16 || rect.size.height > 16) { rect.size.width /= 2; rect.size.height /= 2; } - rect.origin.x = 14 - rect.size.width / 4; - rect.origin.y = 14 - rect.size.height / 4; + rect.origin.x = 18 - rect.size.width / 2; + rect.origin.y = 18 - rect.size.height / 2; [icon_ drawInRect:rect]; } @@ -5549,8 +5506,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { rect.size.width /= 4; rect.size.height /= 4; - rect.origin.x = 20 - rect.size.width / 4; - rect.origin.y = 20 - rect.size.height / 4; + rect.origin.x = 23 - rect.size.width / 2; + rect.origin.y = 23 - rect.size.height / 2; [badge_ drawInRect:rect]; } @@ -5574,7 +5531,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { CGRect rect; rect.size = [(UIImage *) icon_ size]; - while (rect.size.width > 64 || rect.size.height > 64) { + while (rect.size.width > 32 || rect.size.height > 32) { rect.size.width /= 2; rect.size.height /= 2; } @@ -8097,8 +8054,20 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { bool highlighted(highlighted_); float width(rect.size.width); - if (icon_ != nil) - [icon_ drawInRect:CGRectMake(10, 10, 30, 30)]; + if (icon_ != nil) { + CGRect rect; + rect.size = [(UIImage *) icon_ size]; + + while (rect.size.width > 32 || rect.size.height > 32) { + rect.size.width /= 2; + rect.size.height /= 2; + } + + rect.origin.x = 25 - rect.size.width / 2; + rect.origin.y = 25 - rect.size.height / 2; + + [icon_ drawInRect:rect]; + } if (highlighted) UISetColor(White_); @@ -8985,7 +8954,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } } - WriteSources(); + CydiaWriteSources(); } // Navigation controller for the queuing badge. @@ -9183,15 +9152,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } - (void) addSource:(NSDictionary *) source { - AddSource(source); + CydiaAddSource(source); } - (void) addSource:(NSString *)href withDistribution:(NSString *)distribution andSections:(NSArray *)sections { - AddSource(href, distribution, sections); + CydiaAddSource(href, distribution, sections); } - (void) addTrivialSource:(NSString *)href { - AddSource(href, @"./"); + CydiaAddSource(href, @"./"); } - (void) updateValues { @@ -10276,10 +10245,10 @@ int main(int argc, char *argv[]) { } if ([Version_ unsignedIntValue] == 0) { - AddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]); - AddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]); - AddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]); - AddSource(@"http://repo666.ultrasn0w.com/", @"./"); + CydiaAddSource(@"http://apt.thebigboss.org/repofiles/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]); + CydiaAddSource(@"http://apt.modmyi.com/", @"stable", [NSMutableArray arrayWithObject:@"main"]); + CydiaAddSource(@"http://cydia.zodttd.com/repo/cydia/", @"stable", [NSMutableArray arrayWithObject:@"main"]); + CydiaAddSource(@"http://repo666.ultrasn0w.com/", @"./"); Version_ = [NSNumber numberWithUnsignedInt:1]; [Metadata_ setObject:Version_ forKey:@"Version"]; @@ -10290,7 +10259,7 @@ int main(int argc, char *argv[]) { } /* }}} */ - WriteSources(); + CydiaWriteSources(); _trace(); MetaFile_.Open("/var/lib/cydia/metadata.cb0"); diff --git a/Sources.h b/Sources.h new file mode 100644 index 00000000..5c439e23 --- /dev/null +++ b/Sources.h @@ -0,0 +1,49 @@ +/* Cydia - iPhone UIKit Front-End for Debian APT + * Copyright (C) 2008-2011 Jay Freeman (saurik) +*/ + +/* Modified BSD License {{{ */ +/* + * Redistribution and use in source and binary + * forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 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. + * + * 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. +*/ +/* }}} */ + +#ifndef Sources_H +#define Sources_H + +#include + +void CydiaWriteSources(); +void CydiaAddSource(NSDictionary *source); +void CydiaAddSource(NSString *href, NSString *distribution, NSArray *sections = nil); + +#endif//Sources_H diff --git a/Sources.mm b/Sources.mm new file mode 100644 index 00000000..11a86dc2 --- /dev/null +++ b/Sources.mm @@ -0,0 +1,93 @@ +/* Cydia - iPhone UIKit Front-End for Debian APT + * Copyright (C) 2008-2011 Jay Freeman (saurik) +*/ + +/* Modified BSD License {{{ */ +/* + * Redistribution and use in source and binary + * forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 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. + * + * 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. +*/ +/* }}} */ + +#include +#include +#include + +#include + +extern _H Sources_; +extern _H CydiaSource_; +extern _H Firmware_; +extern bool Changed_; + +void CydiaWriteSources() { + FILE *file(fopen("/etc/apt/sources.list.d/cydia.list", "w")); + _assert(file != NULL); + + NSString *distribution(@"ios"); + if (Firmware_ != nil) + distribution = [distribution stringByAppendingString:[NSString stringWithFormat:@"-%@", (id) Firmware_]]; + + fprintf(file, "deb http://%s/ %s main\n", + [CydiaSource_ UTF8String], + [distribution UTF8String] + ); + + for (NSString *key in [Sources_ allKeys]) { + NSDictionary *source([Sources_ objectForKey:key]); + + NSArray *sections([source objectForKey:@"Sections"] ?: [NSArray array]); + + fprintf(file, "%s %s %s%s%s\n", + [[source objectForKey:@"Type"] UTF8String], + [[source objectForKey:@"URI"] UTF8String], + [[source objectForKey:@"Distribution"] UTF8String], + [sections count] == 0 ? "" : " ", + [[sections componentsJoinedByString:@" "] UTF8String] + ); + } + + fclose(file); +} + +void CydiaAddSource(NSDictionary *source) { + [Sources_ setObject:source forKey:[NSString stringWithFormat:@"%@:%@:%@", [source objectForKey:@"Type"], [source objectForKey:@"URI"], [source objectForKey:@"Distribution"]]]; + Changed_ = true; +} + +void CydiaAddSource(NSString *href, NSString *distribution, NSArray *sections) { + CydiaAddSource([NSMutableDictionary dictionaryWithObjectsAndKeys: + @"deb", @"Type", + href, @"URI", + distribution, @"Distribution", + sections ?: [NSMutableArray array], @"Sections", + nil]); +} diff --git a/makefile b/makefile index 33557d67..6ab3a0d2 100644 --- a/makefile +++ b/makefile @@ -67,7 +67,7 @@ dirs := Menes CyteKit Cydia SDURLCache code := $(foreach dir,$(dirs),$(wildcard $(foreach ext,h hpp c cpp m mm,$(dir)/*.$(ext)))) code := $(filter-out SDURLCache/SDURLCacheTests.m,$(code)) -code += MobileCydia.mm Version.mm iPhonePrivate.h Cytore.hpp lookup3.c +code += MobileCydia.mm Version.mm iPhonePrivate.h Cytore.hpp lookup3.c Sources.h Sources.mm source := $(filter %.m,$(code)) $(filter %.mm,$(code)) source += $(filter %.c,$(code)) $(filter %.cpp,$(code)) -- 2.45.2