Zip extraction support.

This commit is contained in:
Paul Chote
2010-11-25 16:56:45 +13:00
parent eff5e409c0
commit 10f9e3e787
5 changed files with 146 additions and 34 deletions

View File

@@ -52,6 +52,7 @@ static JSBridge *SharedInstance;
@"downloadError", NSStringFromSelector(@selector(downloadError:)),
@"bytesCompleted", NSStringFromSelector(@selector(bytesCompleted:)),
@"bytesTotal", NSStringFromSelector(@selector(bytesTotal:)),
@"extractDownload", NSStringFromSelector(@selector(extractDownload:toPath:inMod:)),
nil] retain];
}
return self;
@@ -153,6 +154,40 @@ static JSBridge *SharedInstance;
[NSString stringWithFormat:@"downloadProgressed('%@')",[download key]]];
}
- (void)notifyExtractProgress:(Download *)download
{
[[[controller webView] windowScriptObject] evaluateWebScript:
[NSString stringWithFormat:@"extractProgressed('%@')",[download key]]];
}
- (BOOL)extractDownload:(NSString *)key toPath:(NSString *)aFile inMod:(NSString *)aMod
{
Download *d = [controller downloadWithKey:key];
if (d == nil)
{
NSLog(@"Unknown download");
return NO;
}
if (![[d status] isEqualToString:@"DOWNLOADED"])
{
NSLog(@"Invalid download status");
return NO;
}
id mod = [[controller allMods] objectForKey:aMod];
if (mod == nil)
{
NSLog(@"Invalid or unknown mod: %@", aMod);
return NO;
}
// Disallow traversing up the directory tree
id path = [aMod stringByAppendingPathComponent:[aFile stringByReplacingOccurrencesOfString:@"../"
withString:@""]];
[d extractToPath:path];
return YES;
}
- (void)log:(NSString *)message
{