updating progress indicator work

This commit is contained in:
dante ruiz 2019-07-02 20:56:49 -07:00
parent fb8027bdf5
commit f210be32dc
5 changed files with 48 additions and 7 deletions

View file

@ -3,6 +3,7 @@
@interface DownloadDomainContent : NSObject<NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLDownloadDelegate> { @interface DownloadDomainContent : NSObject<NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLDownloadDelegate> {
} }
@property (nonatomic, assign) double progressPercentage; @property (nonatomic, assign) double progressPercentage;
@property (nonatomic, assign) double taskProgressPercentage;
- (void) downloadDomainContent:(NSString*) domainContentUrl; - (void) downloadDomainContent:(NSString*) domainContentUrl;
- (double) getProgressPercentage; - (double) getProgressPercentage;

View file

@ -5,12 +5,13 @@
- (double) getProgressPercentage - (double) getProgressPercentage
{ {
return self.progressPercentage; return (self.progressPercentage * .90) + (self.taskProgressPercentage * .10);
} }
- (void) downloadDomainContent:(NSString *)domainContentUrl - (void) downloadDomainContent:(NSString *)domainContentUrl
{ {
self.progressPercentage = 0.0; self.progressPercentage = 0.0;
self.taskProgressPercentage = 0.0;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:domainContentUrl] NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:domainContentUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0]; timeoutInterval:60.0];
@ -36,6 +37,11 @@
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
NSLog(@"Did finish downloading to url"); NSLog(@"Did finish downloading to url");
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
target: self
selector: @selector(updatePercentage:)
userInfo:nil
repeats: YES];
NSError *error = nil; NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent;
@ -56,6 +62,7 @@
if (error) { if (error) {
NSLog(@"DownlodDomainContent: failed to move file to destintation -> error: %@", error); NSLog(@"DownlodDomainContent: failed to move file to destintation -> error: %@", error);
[timer invalidate];
[sharedLauncher displayErrorPage]; [sharedLauncher displayErrorPage];
return; return;
} }
@ -64,18 +71,27 @@
BOOL extractionSuccessful = [sharedLauncher extractZipFileAtDestination:[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:@"content"] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:[sharedLauncher getDownloadContentFilename]]]; BOOL extractionSuccessful = [sharedLauncher extractZipFileAtDestination:[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:@"content"] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:[sharedLauncher getDownloadContentFilename]]];
if (!extractionSuccessful) { if (!extractionSuccessful) {
[timer invalidate];
[sharedLauncher displayErrorPage]; [sharedLauncher displayErrorPage];
return; return;
} }
NSLog(@"finished extracting content file"); NSLog(@"finished extracting content file");
[timer invalidate];
self.taskProgressPercentage = 100.0;
[sharedLauncher updateProgressIndicator];
[sharedLauncher domainContentDownloadFinished]; [sharedLauncher domainContentDownloadFinished];
} }
-(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
NSLog(@"completed; error: %@", error); NSLog(@"completed; error: %@", error);
if (error) { if (error) {
[[Launcher sharedLauncher] displayErrorPage]; [[Launcher sharedLauncher] displayErrorPage];
} }
} }
- (void) updatePercentage:(NSTimer*) timer {
self.taskProgressPercentage += 3.0;
[[Launcher sharedLauncher] updateProgressIndicator];
}
@end @end

View file

@ -4,8 +4,9 @@
} }
@property (nonatomic, assign) NSString* finalFilePath; @property (nonatomic, assign) NSString* finalFilePath;
@property (nonatomic, assign) double progressPercentage; @property (nonatomic, assign) double progressPercentage;
@property (nonatomic, assign) double taskProgressPercentage;
- (void) downloadInterface:(NSString*) downloadUrl; - (void) downloadInterface:(NSString*) downloadUrl;
- (double) getProgressPercentage; - (double) getProgressPercentage;
@end @end

View file

@ -7,6 +7,7 @@
- (void) downloadInterface:(NSString*) downloadUrl - (void) downloadInterface:(NSString*) downloadUrl
{ {
self.progressPercentage = 0.0; self.progressPercentage = 0.0;
self.taskProgressPercentage = 0.0;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl] NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0]; timeoutInterval:60.0];
@ -29,7 +30,7 @@
- (double) getProgressPercentage - (double) getProgressPercentage
{ {
return self.progressPercentage; return (self.progressPercentage * 0.90) + (self.taskProgressPercentage * 0.10);
} }
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes {
@ -38,6 +39,11 @@
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
NSLog(@"Did finish downloading to url"); NSLog(@"Did finish downloading to url");
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
target: self
selector: @selector(updateTaskPercentage:)
userInfo:nil
repeats: YES];
NSError *error = nil; NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent;
@ -53,6 +59,7 @@
if (error) { if (error) {
NSLog(@"Download Interface: failed to move file to destination -> error: %@", error); NSLog(@"Download Interface: failed to move file to destination -> error: %@", error);
[timer invalidate];
[sharedLauncher displayErrorPage]; [sharedLauncher displayErrorPage];
return; return;
} }
@ -63,6 +70,7 @@
NSLog(@"extract interface zip"); NSLog(@"extract interface zip");
BOOL success = [sharedLauncher extractZipFileAtDestination:appPath :[appPath stringByAppendingString:downloadFileName]]; BOOL success = [sharedLauncher extractZipFileAtDestination:appPath :[appPath stringByAppendingString:downloadFileName]];
if (!success) { if (!success) {
[timer invalidate];
[sharedLauncher displayErrorPage]; [sharedLauncher displayErrorPage];
return; return;
} }
@ -80,6 +88,9 @@
NSString* launcherPath = [appPath stringByAppendingString:@"Launcher"]; NSString* launcherPath = [appPath stringByAppendingString:@"Launcher"];
[[Settings sharedSettings] setLauncherPath:launcherPath]; [[Settings sharedSettings] setLauncherPath:launcherPath];
[timer invalidate];
self.taskProgressPercentage = 100.0;
[sharedLauncher updateProgressIndicator];
[sharedLauncher interfaceFinishedDownloading]; [sharedLauncher interfaceFinishedDownloading];
} }
@ -90,5 +101,10 @@
} }
} }
- (void) updateTaskPercentage:(NSTimer*) timer {
self.taskProgressPercentage += 3.0;
[[Launcher sharedLauncher] updateProgressIndicator];
}
@end @end

View file

@ -84,13 +84,20 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
- (void) updateProgressIndicator - (void) updateProgressIndicator
{ {
NSProgressIndicator* progressIndicator = [self getProgressView]; NSProgressIndicator* progressIndicator = [self getProgressView];
//double oldValue = progressIndicator.doubleValue; double oldValue = progressIndicator.doubleValue;
double contentPercentage = [self.downloadDomainContent getProgressPercentage]; double contentPercentage = [self.downloadDomainContent getProgressPercentage];
double interfacePercentage = [self.downloadInterface getProgressPercentage]; double interfacePercentage = [self.downloadInterface getProgressPercentage];
//double currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5); double currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5);
//[progressIndicator incrementBy: (currentTotalPercentage - oldValue)]; //[progressIndicator incrementBy: (currentTotalPercentage - oldValue)];
progressIndicator.doubleValue = (contentPercentage * 0.4) + (interfacePercentage * 0.4); progressIndicator.doubleValue = [self lerp:oldValue :currentTotalPercentage :0.7];
}
- (double) lerp:(double) pointA :(double) pointB :(double) interp
{
double lerpValue = pointA + interp * (pointB - pointA);
NSLog(@"----> lerp value: %f", lerpValue);
return lerpValue;
} }
- (BOOL) extractZipFileAtDestination:(NSString *)destination :(NSString*)file - (BOOL) extractZipFileAtDestination:(NSString *)destination :(NSString*)file