Refactor download mechanism to allow multiple concurrent downloads. Allow downloads to be cancelled. Allow js to query if files exist in the cache. Fix some compiler warnings.

This commit is contained in:
Paul Chote
2010-11-19 13:41:24 +13:00
parent c3521a2490
commit 0ee1d39bac
10 changed files with 201 additions and 66 deletions

View File

@@ -12,14 +12,16 @@
#import "GameInstall.h"
#import "ImageAndTextCell.h"
#import "JSBridge.h"
#import "Download.h"
@implementation Controller
@synthesize allMods;
@synthesize webView;
- (void) awakeFromNib
{
game = [[GameInstall alloc] initWithURL:[NSURL URLWithString:@"/Users/paul/src/OpenRA"]];
[[JSBridge sharedInstance] setController:self];
downloads = [[NSMutableDictionary alloc] init];
NSTableColumn *col = [outlineView tableColumnWithIdentifier:@"mods"];
ImageAndTextCell *imageAndTextCell = [[[ImageAndTextCell alloc] init] autorelease];
@@ -50,6 +52,7 @@
- (void)dealloc
{
[sidebarItems release]; sidebarItems = nil;
[downloads release]; downloads = nil;
[super dealloc];
}
@@ -90,10 +93,24 @@
[game launchMod:mod];
}
- (BOOL)downloadUrl:(NSString *)url intoCache:(NSString *)filename withId:(NSString *)key
- (BOOL)downloadUrl:(NSString *)url toFile:(NSString *)path withId:(NSString *)key
{
id path = [[@"~/Library/Application Support/OpenRA/Downloads/" stringByAppendingPathComponent:filename] stringByExpandingTildeInPath];
return [game downloadUrl:url toPath:path withId:key];
if ([downloads objectForKey:key] != nil)
{
NSLog(@"Download already in progress for %@",key);
return NO;
}
Download *download = [Download downloadWithURL:url filename:path key:key game:game];
[downloads setObject:download forKey:key];
return YES;
}
- (void)cancelDownload:(NSString *)key
{
[[downloads objectForKey:key] cancel];
[downloads removeObjectForKey:key];
}
#pragma mark Sidebar Datasource and Delegate