moonlight-ios/Limelight/Network/AppAssetRetriever.m

45 lines
1.6 KiB
Mathematica
Raw Normal View History

//
// AppAssetRetriever.m
// Moonlight
//
// Created by Diego Waxemberg on 1/31/15.
// Copyright (c) 2015 Moonlight Stream. All rights reserved.
//
#import "AppAssetRetriever.h"
#import "HttpManager.h"
#import "CryptoManager.h"
#import "AppAssetResponse.h"
#import "HttpRequest.h"
#import "IdManager.h"
@implementation AppAssetRetriever
2015-02-10 16:13:06 -05:00
static const double RETRY_DELAY = 2; // seconds
static const int MAX_ATTEMPTS = 5;
- (void) main {
2015-02-10 16:13:06 -05:00
int attempts = 0;
2018-08-27 01:54:58 -07:00
while (![self isCancelled] && attempts++ < MAX_ATTEMPTS) {
2018-12-22 00:05:48 -08:00
HttpManager* hMan = [[HttpManager alloc] initWithHost:_host.activeAddress uniqueId:[IdManager getUniqueId] serverCert:_host.serverCert];
AppAssetResponse* appAssetResp = [[AppAssetResponse alloc] init];
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appAssetResp withUrlRequest:[hMan newAppAssetRequestWithAppId:self.app.id]]];
2018-08-27 01:54:58 -07:00
if (appAssetResp.data != nil) {
NSString* boxArtPath = [AppAssetManager boxArtPathForApp:self.app];
[[NSFileManager defaultManager] createDirectoryAtPath:[boxArtPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
[appAssetResp.data writeToFile:boxArtPath atomically:NO];
break;
}
2018-08-27 01:54:58 -07:00
if (![self isCancelled]) {
[NSThread sleepForTimeInterval:RETRY_DELAY];
}
}
[self performSelectorOnMainThread:@selector(sendCallbackForApp:) withObject:self.app waitUntilDone:NO];
}
- (void) sendCallbackForApp:(TemporaryApp*)app {
[self.callback receivedAssetForApp:app];
}
@end