Progress towards in-launcher download ui. Works, but is very fragile.
This commit is contained in:
@@ -8,14 +8,6 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
typedef enum {
|
||||
Initializing,
|
||||
Downloading,
|
||||
Complete,
|
||||
Cancelled,
|
||||
Error
|
||||
} DownloadStatus;
|
||||
|
||||
@class GameInstall;
|
||||
@interface Download : NSObject
|
||||
{
|
||||
@@ -24,12 +16,12 @@ typedef enum {
|
||||
NSString *filename;
|
||||
GameInstall *game;
|
||||
NSTask *task;
|
||||
DownloadStatus status;
|
||||
NSString * status;
|
||||
int bytesCompleted;
|
||||
int bytesTotal;
|
||||
}
|
||||
@property(readonly) NSString *key;
|
||||
@property(readonly) DownloadStatus status;
|
||||
@property(readonly) NSString *status;
|
||||
@property(readonly) int bytesCompleted;
|
||||
@property(readonly) int bytesTotal;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
filename = [aFilename retain];
|
||||
key = [aKey retain];
|
||||
game = [aGame retain];
|
||||
status = Initializing;
|
||||
status = @"Initializing";
|
||||
bytesCompleted = -1;
|
||||
bytesTotal = -1;
|
||||
|
||||
@@ -65,17 +65,17 @@
|
||||
|
||||
if ([type isEqualToString:@"Error"])
|
||||
{
|
||||
status = Error;
|
||||
status = @"Error";
|
||||
}
|
||||
else if ([type isEqualToString:@"Status"])
|
||||
{
|
||||
if ([message isEqualToString:@"Initializing"])
|
||||
{
|
||||
status = Initializing;
|
||||
status = @"Initializing";
|
||||
}
|
||||
else if ([message isEqualToString:@"Completed"])
|
||||
{
|
||||
status = Complete;
|
||||
status = @"Complete";
|
||||
}
|
||||
|
||||
// Parse download status info
|
||||
@@ -97,7 +97,7 @@
|
||||
- (void)cancel
|
||||
{
|
||||
NSLog(@"Cancelling");
|
||||
status = Cancelled;
|
||||
status = @"Cancelled";
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc removeObserver:self name:NSFileHandleReadCompletionNotification object:[[task standardOutput] fileHandleForReading]];
|
||||
[nc removeObserver:self name:NSTaskDidTerminateNotification object:task];
|
||||
|
||||
@@ -42,13 +42,13 @@ static JSBridge *SharedInstance;
|
||||
methods = [[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"launchMod", NSStringFromSelector(@selector(launchMod:)),
|
||||
@"log", NSStringFromSelector(@selector(log:)),
|
||||
@"existsInMod", NSStringFromSelector(@selector(exists:inMod:)),
|
||||
@"existsInMod", NSStringFromSelector(@selector(fileExists:inMod:)),
|
||||
|
||||
// File downloading
|
||||
@"existsInCache", NSStringFromSelector(@selector(existsInCache:)),
|
||||
@"downloadToCache", NSStringFromSelector(@selector(downloadUrl:withName:key:)),
|
||||
@"cancelDownload", NSStringFromSelector(@selector(cancelDownload:)),
|
||||
@"isDownloading", NSStringFromSelector(@selector(isDownloading:)),
|
||||
@"downloadStatus", NSStringFromSelector(@selector(downloadStatus:)),
|
||||
@"bytesCompleted", NSStringFromSelector(@selector(bytesCompleted:)),
|
||||
@"bytesTotal", NSStringFromSelector(@selector(bytesTotal:)),
|
||||
nil] retain];
|
||||
@@ -124,9 +124,13 @@ static JSBridge *SharedInstance;
|
||||
[controller cancelDownload:key];
|
||||
}
|
||||
|
||||
- (BOOL)isDownloading:(NSString *)key
|
||||
- (NSString *)downloadStatus:(NSString *)key
|
||||
{
|
||||
return [controller downloadWithKey:key] != nil;
|
||||
Download *d = [controller downloadWithKey:key];
|
||||
if (d == nil)
|
||||
return @"Invalid";
|
||||
|
||||
return [d status];
|
||||
}
|
||||
|
||||
- (int)bytesCompleted:(NSString *)key
|
||||
|
||||
Reference in New Issue
Block a user