Skip to content

Commit 3f96346

Browse files
committed
Refreshing should be faster now, some optimization
1 parent fbe92e4 commit 3f96346

File tree

8 files changed

+88
-72
lines changed

8 files changed

+88
-72
lines changed

APTOFileParser.m

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
22
// APTOFileParser.m
33
//
44
//
@@ -22,20 +22,23 @@ - (instancetype)initWithFilePath:(NSString*)filePath {
2222
return self;
2323
}
2424
- (void)enumeratePackageContentsUsingBlock:(void(^)(NSString *packageContents))block {
25-
FILE *file = fopen([_filePath UTF8String], "r");
26-
27-
int lineBuffer = 256;
28-
char buffer[lineBuffer];
29-
30-
NSString *packageContents = @"";
31-
while (fgets(buffer, sizeof(char)*lineBuffer, file) != NULL){
32-
NSString *line = [NSString stringWithUTF8String:buffer];
25+
@autoreleasepool {
26+
FILE *file = fopen([_filePath UTF8String], "r");
27+
if (!file) return;
28+
29+
int lineBuffer = 256;
30+
char buffer[lineBuffer];
3331

34-
if ([line isEqualToString:@"\n"]) {
35-
block(packageContents);
36-
packageContents = @"";
37-
} else {
38-
packageContents = [packageContents stringByAppendingString:line];
32+
NSString *packageContents = @"";
33+
while (fgets(buffer, sizeof(char)*lineBuffer, file) != NULL){
34+
NSString *line = [NSString stringWithUTF8String:buffer];
35+
36+
if ([line isEqualToString:@"\n"]) {
37+
block(packageContents);
38+
packageContents = @"";
39+
} else {
40+
packageContents = [packageContents stringByAppendingString:line];
41+
}
3942
}
4043
}
4144
}

APTOPackageManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef void (^PackageManagerCallBack)(NSString *line);
2121
- (APTOPackage*)packageWithBundleIdentifier:(NSString*)bundleIdentifer;
2222
- (NSArray*)installedPackages;
2323
- (BOOL)install:(APTOPackage*)package callBack:(PackageManagerCallBack)callBack;
24+
- (BOOL)remove:(APTOPackage*)package callBack:(PackageManagerCallBack)callBack;
2425
- (NSArray*)dependanciesForPackage:(APTOPackage*)package error:(NSError**)error;
2526
- (NSArray*)conflictsForPackage:(APTOPackage*)package error:(NSError**)error;
2627

APTOPackageManager.m

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,26 @@ - (BOOL)updatePackages {
4747
#endif
4848
/* -------------------- */
4949

50+
__block NSInteger processes = [_sourceManager.sources count]-1;
51+
for (APTOSource *source in _sourceManager.sources) {
52+
dispatch_queue_t backgroundQueue1 = dispatch_queue_create([source.srcUrl UTF8String], 0);
53+
dispatch_async(backgroundQueue1, ^{
54+
BOOL success;
55+
56+
NSRange range = NSMakeRange([source.packageURL length]-3, 3);
57+
if ([[source.packageURL substringWithRange:range] isEqualToString:@"bz2"]) {
58+
success = [self downloadSpecialPackage:source.packageURL];
59+
} else {
60+
success = [self downloadPackageList:source.packageURL];
61+
}
62+
if (output == YES) output = success;
63+
processes--;
64+
});
65+
}
5066

51-
[_sourceManager iterateThroughSources:^(APTOSource *source) {
52-
BOOL success;
53-
54-
NSRange range = NSMakeRange([source.packageURL length]-3, 3);
55-
if ([[source.packageURL substringWithRange:range] isEqualToString:@"bz2"]) {
56-
success = [self downloadSpecialPackage:source.packageURL];
57-
} else {
58-
success = [self downloadPackage:source.packageURL];
59-
}
60-
if (output == YES) output = success;
61-
}];
67+
while (processes > 0) {
68+
[NSThread sleepForTimeInterval:0];
69+
}
6270

6371
return output;
6472
}
@@ -188,16 +196,31 @@ - (BOOL)install:(APTOPackage*)package callBack:(PackageManagerCallBack)callBack
188196

189197
if (dependancies) {
190198
for (APTOPackage *_package in dependancies) {
191-
NSLog(@"%@",_package.pkgName);
199+
[self install:_package callBack:^(NSString *line) {
200+
if (callBack) callBack(line);
201+
}];
192202
}
193203
}
194204

195205
if (conflicts) {
196206
for (APTOPackage *_package in conflicts) {
197-
NSLog(@"%@",_package.pkgName);
207+
[self remove:_package callBack:^(NSString *line) {
208+
if (callBack) callBack(line);
209+
}];
198210
}
199211
}
200212

213+
214+
215+
// XXX: Actually install package
216+
217+
return output;
218+
}
219+
- (BOOL)remove:(APTOPackage*)package callBack:(PackageManagerCallBack)callBack {
220+
BOOL output = NO;
221+
222+
// XXX: Actually remove package
223+
201224
return output;
202225
}
203226
- (NSArray*)conflictsForPackage:(APTOPackage*)package error:(NSError**)error {
@@ -206,7 +229,6 @@ - (NSArray*)conflictsForPackage:(APTOPackage*)package error:(NSError**)error {
206229
BOOL firmwareCheck = NO;
207230

208231
for (NSString *item in package.pkgConflicts) {
209-
NSLog(@"%@",item);
210232
NSString *bundleIdentifier = item;
211233
NSString *version = nil;
212234

@@ -245,7 +267,6 @@ - (NSArray*)conflictsForPackage:(APTOPackage*)package error:(NSError**)error {
245267
firmwareCheck = YES;
246268
} else {
247269
APTOPackage *_package = [self packageWithBundleIdentifier:bundleIdentifier];
248-
NSLog(@"Input: %@\nOutput: %@",bundleIdentifier, _package.pkgPackage);
249270

250271
if (_package) {
251272
if ([version containsString:@">>"]) { /* greater than */
@@ -327,7 +348,6 @@ - (NSArray*)dependanciesForPackage:(APTOPackage*)package error:(NSError**)error
327348
firmwareCheck = YES;
328349
} else {
329350
APTOPackage *_package = [self packageWithBundleIdentifier:bundleIdentifier];
330-
NSLog(@"Input: %@\nOutput: %@",bundleIdentifier, _package.pkgPackage);
331351

332352
if (_package) {
333353
if ([version containsString:@">>"]) { /* greater than */
@@ -367,7 +387,7 @@ - (NSArray*)dependanciesForPackage:(APTOPackage*)package error:(NSError**)error
367387
}
368388

369389
#pragma mark - Other
370-
- (BOOL)downloadPackage:(NSString*)url {
390+
- (BOOL)downloadPackageList:(NSString*)url {
371391
NSData *urlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
372392

373393
if (urlData) {

APTOSourceManager.m

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,33 +107,44 @@ - (BOOL)removeSource:(NSString *)url {
107107
return [newFile writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
108108
}
109109
- (BOOL)updateSources {
110-
BOOL output = YES;
111-
112110
NSArray *directory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_manager.sourceFile error:nil];
111+
112+
__block NSInteger processes = [directory count]-1;
113113
for (NSString *file in directory) {
114-
NSString *content = [self contentsOfFile:[NSString stringWithFormat:@"%@/%@",_manager.sourceFile,file]];
115-
if (![content isEqualToString:@""] && content != nil) {
116-
NSArray *aryList = [content componentsSeparatedByString:@"\n"];
117-
118-
for (NSString *item in aryList) {
119-
if ([item length] < 4 || ![[item substringWithRange:NSMakeRange(0,3)] isEqualToString:@"deb"]) continue;
120-
121-
NSString *url = [item substringWithRange:NSMakeRange(4, [item length]-4)];
122-
url = [url stringByReplacingOccurrencesOfString:@" ./" withString:@""];
114+
dispatch_queue_t backgroundQueue1 = dispatch_queue_create([file UTF8String], 0);
115+
dispatch_async(backgroundQueue1, ^{
116+
NSString *content = [self contentsOfFile:[NSString stringWithFormat:@"%@/%@",_manager.sourceFile,file]];
117+
if (![content isEqualToString:@""] && content != nil) {
118+
NSArray *aryList = [content componentsSeparatedByString:@"\n"];
123119

124-
NSRange original = [url rangeOfString:@" "];
125-
if (NSNotFound != original.location) {
126-
url = [url stringByReplacingCharactersInRange:original withString:@"dists/"];
120+
for (NSString *item in aryList) {
121+
dispatch_queue_t backgroundQueue2 = dispatch_queue_create([item UTF8String], 0);
122+
dispatch_async(backgroundQueue2, ^{
123+
if ([item length] < 4 || ![[item substringWithRange:NSMakeRange(0,3)] isEqualToString:@"deb"]) return;
124+
125+
NSString *url = [item substringWithRange:NSMakeRange(4, [item length]-4)];
126+
url = [url stringByReplacingOccurrencesOfString:@" ./" withString:@""];
127+
128+
NSRange original = [url rangeOfString:@" "];
129+
if (NSNotFound != original.location) {
130+
url = [url stringByReplacingCharactersInRange:original withString:@"dists/"];
131+
}
132+
url = [url stringByReplacingOccurrencesOfString:@" main" withString:@""];
133+
134+
[self downloadRelease:url];
135+
[self downloadIcon:url];
136+
});
127137
}
128-
url = [url stringByReplacingOccurrencesOfString:@" main" withString:@""];
129-
130-
[self downloadRelease:url];
131-
[self downloadIcon:url];
132138
}
133-
}
139+
processes--;
140+
});
134141
}
135142

136-
return output;
143+
while (processes > 0) {
144+
[NSThread sleepForTimeInterval:0];
145+
}
146+
147+
return YES;
137148
}
138149
- (NSString*)filePathForSource:(NSString*)url {
139150
NSString *_url;

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
**Known Bugs:**
66
- Installation and remove of packages is not yet supported (not sure how this will work in sandbox unless we can break it or run as root?)
7-
- May have some restrictions on what repos can be removed (can be modified)
8-
- Currently refreshes one source at a time verses all at once (may need to be changed)
9-
- Sandboxing has lead to a new version being installed will overwrite source.list resetting a persons source list
7+
- Sandboxing has lead to a new version being installed will overwrite source.list resetting a persons source list (possibly only a simulator bug?)
108

119
**Fixed Bugs:**
1210
- Package files are being miss read. Currently trying to load such a large file will cause it to crash. Attempted to load only the needed part of the file at a time. Some lines are being misses modification to the following should work (APTOFileParser):
1311
- Package dependancies are fixed
1412
- Package conflicts are fixed
1513
- Currently supports Cydia and Works in sandbox
14+
- Somewhat optomized for speed. Refreshes all sources at the same time. Refreshes all package lists at the same time

libAPTObjc/.DS_Store

0 Bytes
Binary file not shown.

libAPTObjc/libAPTObjc.xcodeproj/xcuserdata/bolencki13.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,4 @@
22
<Bucket
33
type = "1"
44
version = "2.0">
5-
<Breakpoints>
6-
<BreakpointProxy
7-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8-
<BreakpointContent
9-
shouldBeEnabled = "No"
10-
ignoreCount = "0"
11-
continueAfterRunningActions = "No"
12-
filePath = "../APTOPackageManager.m"
13-
timestampString = "501441079.040615"
14-
startingColumnNumber = "9223372036854775807"
15-
endingColumnNumber = "9223372036854775807"
16-
startingLineNumber = "159"
17-
endingLineNumber = "159"
18-
landmarkName = "-packageWithBundleIdentifier:"
19-
landmarkType = "7">
20-
</BreakpointContent>
21-
</BreakpointProxy>
22-
</Breakpoints>
235
</Bucket>

0 commit comments

Comments
 (0)