Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgio Calderolla committed Oct 24, 2013
1 parent 2298c32 commit 1cec0ca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 54 deletions.
74 changes: 36 additions & 38 deletions FeedChecker.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,45 @@ - (BOOL) checkFeed {

// This autorelease pool is here because the containing one,
// being in an infinite loop, never gets released. So this
// avoids leaks in this class. God I miss Java.
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

// We don't want these preferences to change while we're working
BOOL organize = [[NSUserDefaults standardUserDefaults] boolForKey:PREFERENCE_KEY_ORGANIZE_TORRENTS];
NSURL* feedURL = [NSURL URLWithString:Preferences.feedURL];

// Flush the cache, we want fresh results
[[NSURLCache sharedURLCache] removeAllCachedResponses];

// Download the feed
NSXMLDocument* feed = [self downloadFeed:feedURL];

if (!feed) return NO;

// Parse the feed
NSArray* fileURLs = [self parseURLs:feed];
NSArray* fileFolders = nil;
if (organize) fileFolders = [self parseFolders:feed];

if (!fileURLs) return NO;

if (!fileFolders || [fileURLs count] != [fileFolders count]) {
// Make sure we have good folders
fileFolders = nil;
if (organize) {
NSLog(@"FeedChecker: bad folders!");
} else {
NSLog(@"FeedChecker: user doesn't want folders");
// keeps the memory usage down.
@autoreleasepool {
// We don't want these preferences to change while we're working
BOOL organize = [[NSUserDefaults standardUserDefaults] boolForKey:PREFERENCE_KEY_ORGANIZE_TORRENTS];
NSURL* feedURL = [NSURL URLWithString:Preferences.feedURL];

// Flush the cache, we want fresh results
[[NSURLCache sharedURLCache] removeAllCachedResponses];

// Download the feed
NSXMLDocument* feed = [self downloadFeed:feedURL];

if (!feed) return NO;

// Parse the feed
NSArray* fileURLs = [self parseURLs:feed];
NSArray* fileFolders = nil;
if (organize) fileFolders = [self parseFolders:feed];

if (!fileURLs) return NO;

if (!fileFolders || [fileURLs count] != [fileFolders count]) {
// Make sure we have good folders
fileFolders = nil;
if (organize) {
NSLog(@"FeedChecker: bad folders!");
} else {
NSLog(@"FeedChecker: user doesn't want folders");
}
}

// Download the files
if (![self downloadFiles:fileURLs inFolders:fileFolders]) {
return NO;
}

NSLog(@"FeedChecker: done!");
}

// Download the files
if (![self downloadFiles:fileURLs inFolders:fileFolders]) {
return NO;
}

NSLog(@"FeedChecker: done!");

[pool drain];

return YES;
}

Expand Down
2 changes: 0 additions & 2 deletions Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@


@interface Scheduler : NSObject {
NSAutoreleasePool* pool;
NSRunLoop* runLoop;
NSTimer* repeatingTimer;
FeedChecker* feedChecker;
int active;
Expand Down
26 changes: 12 additions & 14 deletions Scheduler.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ - (id) initWithFeedChecker:(FeedChecker*)theFeedChecker {
- (void) loopRun {
NSLog(@"Scheduler: running RunLoop");

pool = [[NSAutoreleasePool alloc] init];

runLoop = [[NSRunLoop currentRunLoop] retain];

repeatingTimer = [[NSTimer scheduledTimerWithTimeInterval:FEED_UPDATE_INTERVAL
target:self
selector:@selector(tick:)
userInfo:nil
repeats:YES]
retain];
[runLoop addTimer:repeatingTimer forMode:NSDefaultRunLoopMode];
[runLoop run];

[pool release];
@autoreleasepool {
NSRunLoop *currentRunLoop = NSRunLoop.currentRunLoop;

repeatingTimer = [[NSTimer scheduledTimerWithTimeInterval:FEED_UPDATE_INTERVAL
target:self
selector:@selector(tick:)
userInfo:nil
repeats:YES]
retain];
[currentRunLoop addTimer:repeatingTimer forMode:NSDefaultRunLoopMode];
[currentRunLoop run];
}
}

- (void) reportStatus {
Expand Down

0 comments on commit 1cec0ca

Please sign in to comment.