Dropbox save structure and on device save structure redone (folders), navdata download implemented (QW files, easiest to parse). Restructure of Dropbox actions -> synchronous NSURLConnection in async block.

This commit is contained in:
Kilian Hofmann 2016-04-08 01:38:40 +02:00
parent 262be5a429
commit c9924d6ec5
8 changed files with 505 additions and 176 deletions

View File

@ -26,6 +26,7 @@
[_dbClient setupDropboxWithHandler:^{ [_dbClient setupDropboxWithHandler:^{
} }
presenter:nil]; presenter:nil];
[self setup];
return YES; return YES;
} }
@ -86,4 +87,49 @@
return YES; return YES;
} }
#pragma mark - Setup of save system
- (void)setup
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsPath = paths[0];
BOOL saves = false;
BOOL oldSaves = false;
BOOL navData = false;
[[NSFileManager defaultManager]
fileExistsAtPath:[documentsPath stringByAppendingString:@"/SAVES"]
isDirectory:&saves];
[[NSFileManager defaultManager]
fileExistsAtPath:[documentsPath stringByAppendingString:@"/OLDSAVES"]
isDirectory:&oldSaves];
[[NSFileManager defaultManager]
fileExistsAtPath:[documentsPath stringByAppendingString:@"/NAVDATA"]
isDirectory:&navData];
if (!saves) {
[[NSFileManager defaultManager]
createDirectoryAtPath:[documentsPath
stringByAppendingString:@"/SAVES"]
withIntermediateDirectories:NO
attributes:nil
error:nil];
}
if (!oldSaves) {
[[NSFileManager defaultManager]
createDirectoryAtPath:
[documentsPath stringByAppendingString:@"/OLDSAVES"]
withIntermediateDirectories:NO
attributes:nil
error:nil];
}
if (!navData) {
[[NSFileManager defaultManager]
createDirectoryAtPath:[documentsPath
stringByAppendingString:@"/NAVDATA"]
withIntermediateDirectories:NO
attributes:nil
error:nil];
}
}
@end @end

View File

@ -126,16 +126,30 @@
<action selector="dbConnect:" destination="NBp-hT-qnu" eventType="touchUpInside" id="Sjs-Vk-aFg"/> <action selector="dbConnect:" destination="NBp-hT-qnu" eventType="touchUpInside" id="Sjs-Vk-aFg"/>
</connections> </connections>
</button> </button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fft-ba-oCA">
<rect key="frame" x="112" y="224" width="97" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="97" id="1fV-Ks-aH1"/>
<constraint firstAttribute="height" constant="30" id="WLI-4o-ris"/>
</constraints>
<state key="normal" title="Load NavData"/>
<connections>
<action selector="dbGetNavData:" destination="NBp-hT-qnu" eventType="touchUpInside" id="TlZ-x2-3gk"/>
</connections>
</button>
</subviews> </subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints> <constraints>
<constraint firstItem="n9p-C2-IND" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="91" id="3OR-Oa-8cl"/> <constraint firstItem="n9p-C2-IND" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="91" id="3OR-Oa-8cl"/>
<constraint firstAttribute="trailing" secondItem="n9p-C2-IND" secondAttribute="trailing" constant="91" id="6nb-b2-JUb"/> <constraint firstAttribute="trailing" secondItem="n9p-C2-IND" secondAttribute="trailing" constant="91" id="6nb-b2-JUb"/>
<constraint firstItem="MYC-QY-v42" firstAttribute="top" secondItem="ggM-lD-yT2" secondAttribute="bottom" constant="8" id="7Aw-oA-8DT"/> <constraint firstItem="MYC-QY-v42" firstAttribute="top" secondItem="ggM-lD-yT2" secondAttribute="bottom" constant="8" id="7Aw-oA-8DT"/>
<constraint firstAttribute="trailing" secondItem="fft-ba-oCA" secondAttribute="trailing" constant="111" id="8mU-OF-jU7"/>
<constraint firstAttribute="trailing" secondItem="MYC-QY-v42" secondAttribute="trailing" constant="71" id="9o7-P0-T70"/> <constraint firstAttribute="trailing" secondItem="MYC-QY-v42" secondAttribute="trailing" constant="71" id="9o7-P0-T70"/>
<constraint firstItem="MYC-QY-v42" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="73" id="Clk-jD-xRP"/> <constraint firstItem="MYC-QY-v42" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="73" id="Clk-jD-xRP"/>
<constraint firstItem="V5o-Hb-Mk0" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="73" id="ISQ-lm-JNH"/> <constraint firstItem="V5o-Hb-Mk0" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="73" id="ISQ-lm-JNH"/>
<constraint firstItem="fft-ba-oCA" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="112" id="LEy-ig-Kbg"/>
<constraint firstItem="xba-tH-5D0" firstAttribute="top" secondItem="V5o-Hb-Mk0" secondAttribute="bottom" constant="8" id="UcB-x5-idK"/> <constraint firstItem="xba-tH-5D0" firstAttribute="top" secondItem="V5o-Hb-Mk0" secondAttribute="bottom" constant="8" id="UcB-x5-idK"/>
<constraint firstItem="fft-ba-oCA" firstAttribute="top" secondItem="xba-tH-5D0" secondAttribute="bottom" constant="8" id="cfI-Sc-hrE"/>
<constraint firstItem="n9p-C2-IND" firstAttribute="top" secondItem="MYC-QY-v42" secondAttribute="bottom" constant="8" id="fvc-m1-XMt"/> <constraint firstItem="n9p-C2-IND" firstAttribute="top" secondItem="MYC-QY-v42" secondAttribute="bottom" constant="8" id="fvc-m1-XMt"/>
<constraint firstItem="xba-tH-5D0" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="106" id="gPD-fO-cXe"/> <constraint firstItem="xba-tH-5D0" firstAttribute="leading" secondItem="Q1M-LV-Smi" secondAttribute="leading" constant="106" id="gPD-fO-cXe"/>
<constraint firstItem="V5o-Hb-Mk0" firstAttribute="top" secondItem="n9p-C2-IND" secondAttribute="bottom" constant="8" id="iyC-R1-ynj"/> <constraint firstItem="V5o-Hb-Mk0" firstAttribute="top" secondItem="n9p-C2-IND" secondAttribute="bottom" constant="8" id="iyC-R1-ynj"/>
@ -147,6 +161,7 @@
<connections> <connections>
<outlet property="dbConnectButton" destination="MYC-QY-v42" id="SjM-EO-W5v"/> <outlet property="dbConnectButton" destination="MYC-QY-v42" id="SjM-EO-W5v"/>
<outlet property="dbDownload" destination="V5o-Hb-Mk0" id="D1j-Gz-x3j"/> <outlet property="dbDownload" destination="V5o-Hb-Mk0" id="D1j-Gz-x3j"/>
<outlet property="dbNavData" destination="fft-ba-oCA" id="zI6-0T-P8I"/>
<outlet property="dbUpload" destination="n9p-C2-IND" id="tIT-Md-AH9"/> <outlet property="dbUpload" destination="n9p-C2-IND" id="tIT-Md-AH9"/>
</connections> </connections>
</viewController> </viewController>

View File

@ -93,8 +93,10 @@
else if (error != nil) { else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations presentErrorAlert:error [SharedDeclerations
presenter:presenter]; presentErrorAlert:error
presenter:presenter.navigationController
.topViewController];
}]; }];
} }
@ -103,20 +105,45 @@
error:nil] error:nil]
isEqualToDictionary:@{}]) { isEqualToDictionary:@{}]) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
if ([[NSJSONSerialization JSONObjectWithData:data
options:0
error:nil]
isKindOfClass:[NSDictionary class]]) {
[SharedDeclerations [SharedDeclerations
presentErrorAlert: presentErrorAlert:
[NSError [NSError
errorWithDomain:DropboxErrorDomain errorWithDomain:DropboxErrorDomain
code:100 code:100
userInfo: userInfo:@{
[[NSJSONSerialization [[NSJSONSerialization
JSONObjectWithData:data JSONObjectWithData:data
options:0 options:0
error:nil] error:nil]
valueForKey: valueForKey:
DropboxErrorUserInfo]] DropboxErrorUserInfo] :
NSLocalizedDescriptionKey
presenter:presenter]; }]
presenter:presenter
.navigationController
.topViewController];
}
else {
[SharedDeclerations
presentErrorAlert:
[NSError
errorWithDomain:DropboxErrorDomain
code:100
userInfo:@{
[[NSString alloc]
initWithData:data
encoding:
NSASCIIStringEncoding] :
NSLocalizedDescriptionKey
}]
presenter:presenter
.navigationController
.topViewController];
}
}]; }];
} }
@ -176,12 +203,18 @@
if (data2 == nil) { if (data2 == nil) {
[[NSOperationQueue [[NSOperationQueue
mainQueue] addOperationWithBlock:^{ mainQueue] addOperationWithBlock:^{
if ([[NSJSONSerialization
JSONObjectWithData:data
options:0
error:nil]
isKindOfClass:[NSDictionary class]]) {
[SharedDeclerations [SharedDeclerations
presentErrorAlert: presentErrorAlert:
[NSError [NSError
errorWithDomain:DropboxErrorDomain errorWithDomain:
DropboxErrorDomain
code:100 code:100
userInfo: userInfo:@{
[[NSJSONSerialization [[NSJSONSerialization
JSONObjectWithData: JSONObjectWithData:
data data
@ -190,8 +223,34 @@
error: error:
nil] nil]
valueForKey: valueForKey:
DropboxErrorUserInfo]] DropboxErrorUserInfo] :
presenter:presenter]; NSLocalizedDescriptionKey
}]
presenter:
presenter
.navigationController
.topViewController];
}
else {
[SharedDeclerations
presentErrorAlert:
[NSError
errorWithDomain:
DropboxErrorDomain
code:100
userInfo:@{
[[NSString alloc]
initWithData:
data
encoding:
NSASCIIStringEncoding] :
NSLocalizedDescriptionKey
}]
presenter:
presenter
.navigationController
.topViewController];
}
}]; }];
} }
else { else {
@ -202,16 +261,20 @@
else if (error != nil) { else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations presentErrorAlert:error [SharedDeclerations
presenter:presenter]; presentErrorAlert:error
presenter:presenter.navigationController
.topViewController];
}]; }];
} }
handler(nil);
}]; }];
} }
/** /**
* Specify if EXPORT or SAVE in file name * Specify if EXPORT or SAVE in file name
* IS synchronus URLRequest, best executed in background thread.
*/ */
- (void)downloadFromDropbox:(NSArray *)files - (void)downloadFromDropbox:(NSArray *)files
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
@ -231,79 +294,95 @@
// File Path // File Path
for (NSString *string in files) { for (NSString *string in files) {
NSData *data = [NSJSONSerialization dataWithJSONObject:@{ NSData *data2 = [NSJSONSerialization dataWithJSONObject:@{
@"path" : [NSString stringWithFormat:@"/%@", string] @"path" : [NSString stringWithFormat:@"/%@", string]
.precomposedStringWithCanonicalMapping .precomposedStringWithCanonicalMapping
} }
options:0 options:0
error:nil]; error:nil];
NSString *temp = NSString *temp = [[NSString alloc] initWithData:data2
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; encoding:NSASCIIStringEncoding];
temp = temp =
[temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"]; [temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
[request addValue:temp.precomposedStringWithCanonicalMapping [request setValue:temp.precomposedStringWithCanonicalMapping
forHTTPHeaderField:(@"Dropbox-API-Arg") forHTTPHeaderField:(@"Dropbox-API-Arg")
.precomposedStringWithCanonicalMapping]; .precomposedStringWithCanonicalMapping];
[NSURLConnection NSURLResponse *response = nil;
sendAsynchronousRequest:request NSError *error = nil;
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response, NSData *data, NSData *data = [NSURLConnection sendSynchronousRequest:request
NSError *error) { returningResponse:&response
error:&error];
if (error == nil) { if (error == nil) {
if ([[NSJSONSerialization JSONObjectWithData:data if ([[NSJSONSerialization JSONObjectWithData:data
options:0 options:0
error:nil] error:nil]
valueForKey:@"error_summary"] == nil) { valueForKey:@"error_summary"] == nil) {
[data writeToFile: [data writeToFile:[SharedDeclerations savePathForFile:string]
[SharedDeclerations
savePathForFile:
[string
substringFromIndex:
[string
rangeOfString:@"/"]
.location]]
atomically:YES]; atomically:YES];
} }
else { else {
[[NSOperationQueue [[NSOperationQueue mainQueue] addOperationWithBlock:^{
mainQueue] addOperationWithBlock:^{ if ([[NSJSONSerialization JSONObjectWithData:data
options:0
error:nil]
isKindOfClass:[NSDictionary class]]) {
[SharedDeclerations [SharedDeclerations
presentErrorAlert: presentErrorAlert:
[NSError [NSError
errorWithDomain:DropboxErrorDomain errorWithDomain:DropboxErrorDomain
code:100 code:100
userInfo: userInfo:@{
[[NSJSONSerialization [[NSJSONSerialization
JSONObjectWithData: JSONObjectWithData:data
data options:0
options: error:nil]
0
error:
nil]
valueForKey: valueForKey:
DropboxErrorUserInfo]] DropboxErrorUserInfo] :
presenter:presenter]; NSLocalizedDescriptionKey
}]
presenter:presenter.navigationController
.topViewController];
}
else {
[SharedDeclerations
presentErrorAlert:
[NSError
errorWithDomain:DropboxErrorDomain
code:100
userInfo:@{
[[NSString alloc]
initWithData:data
encoding:
NSASCIIStringEncoding] :
NSLocalizedDescriptionKey
}]
presenter:presenter.navigationController
.topViewController];
}
}]; }];
} }
} }
else if (error != nil) { else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations presentErrorAlert:error [SharedDeclerations
presenter:presenter]; presentErrorAlert:error
presenter:presenter.navigationController
.topViewController];
}]; }];
} }
}];
} }
handler(); handler();
} }
/** /**
* Specify if SAVE or OLDSAVE in file name * Specify if SAVE or OLDSAVE in file name
* IS synchronus URLRequest, best executed in background thread.
*/ */
- (void)uploadToDropbox:(NSArray *)files - (void)uploadToDropbox:(NSArray *)files
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
@ -323,60 +402,84 @@
// File Path // File Path
for (NSString *string in files) { for (NSString *string in files) {
NSData *data = [NSJSONSerialization dataWithJSONObject:@{ NSData *data2 = [NSJSONSerialization dataWithJSONObject:@{
@"path" : [NSString stringWithFormat:@"/%@", string] @"path" : [NSString stringWithFormat:@"/%@", string]
.precomposedStringWithCanonicalMapping, .precomposedStringWithCanonicalMapping,
@"mode" : @"overwrite".precomposedStringWithCanonicalMapping, @"mode" : @"overwrite".precomposedStringWithCanonicalMapping,
} }
options:0 options:0
error:nil]; error:nil];
NSString *temp = NSString *temp = [[NSString alloc] initWithData:data2
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; encoding:NSASCIIStringEncoding];
temp = temp =
[temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"]; [temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
[request addValue:temp.precomposedStringWithCanonicalMapping [request setValue:temp.precomposedStringWithCanonicalMapping
forHTTPHeaderField:(@"Dropbox-API-Arg") forHTTPHeaderField:(@"Dropbox-API-Arg")
.precomposedStringWithCanonicalMapping]; .precomposedStringWithCanonicalMapping];
request.HTTPBody = [NSData request.HTTPBody = [NSData
dataWithContentsOfFile:[SharedDeclerations savePathForFile:string]]; dataWithContentsOfFile:[SharedDeclerations savePathForFile:string]];
[NSURLConnection NSURLResponse *response = nil;
sendAsynchronousRequest:request NSError *error = nil;
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response, NSData *data, NSData *data = [NSURLConnection sendSynchronousRequest:request
NSError *error) { returningResponse:&response
error:&error];
if (error != nil) { if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations presentErrorAlert:error [SharedDeclerations
presenter:presenter]; presentErrorAlert:error
presenter:presenter.navigationController
.topViewController];
}]; }];
} }
if ([[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]
valueForKey:@"error_summary"] != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if ([[NSJSONSerialization JSONObjectWithData:data if ([[NSJSONSerialization JSONObjectWithData:data
options:0 options:0
error:nil] error:nil]
valueForKey:@"error_summary"] != nil) { isKindOfClass:[NSDictionary class]]) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations [SharedDeclerations
presentErrorAlert: presentErrorAlert:
[NSError [NSError errorWithDomain:DropboxErrorDomain
errorWithDomain:DropboxErrorDomain
code:100 code:100
userInfo: userInfo:@{
[[NSJSONSerialization [[NSJSONSerialization
JSONObjectWithData:data JSONObjectWithData:data
options:0 options:0
error:nil] error:nil]
valueForKey: valueForKey:
DropboxErrorUserInfo]] DropboxErrorUserInfo] :
presenter:presenter]; NSLocalizedDescriptionKey
}]; }]
presenter:presenter.navigationController
.topViewController];
}
else {
[SharedDeclerations
presentErrorAlert:
[NSError
errorWithDomain:DropboxErrorDomain
code:100
userInfo:@{
[[NSString alloc]
initWithData:data
encoding:
NSASCIIStringEncoding] :
NSLocalizedDescriptionKey
}]
presenter:presenter.navigationController
.topViewController];
} }
}]; }];
} }
}
handler(); handler();
} }
@ -399,12 +502,14 @@
} }
} }
if (!exports) { if (!exports) {
[self createFolderAtPath:@"EXPORTS" [self
presenter:presenter]; createFolderAtPath:@"EXPORTS"
presenter:presenter.navigationController
.topViewController];
} }
} }
presenter:presenter]; presenter:presenter];
// NavData (Two files from PMDG Navigraph data // NavData (3 files from QW Navigraph data
[self contentsOfPath:nil [self contentsOfPath:nil
completion:^(NSArray *data) { completion:^(NSArray *data) {
BOOL exports = false; BOOL exports = false;
@ -416,14 +521,15 @@
} }
} }
if (!exports) { if (!exports) {
[self createFolderAtPath:@"NAVDATA"
presenter:presenter];
}
}
presenter:presenter];
// Backups of Saves
[self [self
contentsOfPath:nil createFolderAtPath:@"NAVDATA"
presenter:presenter.navigationController
.topViewController];
}
}
presenter:presenter.navigationController.topViewController];
// Backups of Saves
[self contentsOfPath:nil
completion:^(NSArray *data) { completion:^(NSArray *data) {
BOOL exports = false; BOOL exports = false;
for (NSDictionary *dict in data) { for (NSDictionary *dict in data) {
@ -434,11 +540,14 @@
} }
} }
if (!exports) { if (!exports) {
[self createFolderAtPath:@"SAVES" presenter:presenter]; [self
createFolderAtPath:@"SAVES"
presenter:presenter.navigationController
.topViewController];
} }
} }
presenter:presenter]; presenter:presenter.navigationController.topViewController];
// Old saves (FMC Planner + (or X)) // Old saves (FMC Planner + (or X?))
[self contentsOfPath:nil [self contentsOfPath:nil
completion:^(NSArray *data) { completion:^(NSArray *data) {
BOOL exports = false; BOOL exports = false;
@ -450,11 +559,13 @@
} }
} }
if (!exports) { if (!exports) {
[self createFolderAtPath:@"OLDSAVES" [self
presenter:presenter]; createFolderAtPath:@"OLDSAVES"
presenter:presenter.navigationController
.topViewController];
} }
} }
presenter:presenter]; presenter:presenter.navigationController.topViewController];
}]; }];
handler(); handler();
} }
@ -524,22 +635,28 @@
[NSError [NSError
errorWithDomain:DropboxErrorDomain errorWithDomain:DropboxErrorDomain
code:100 code:100
userInfo: userInfo:@{
[[NSJSONSerialization [[NSJSONSerialization
JSONObjectWithData:data JSONObjectWithData:data
options:0 options:0
error:nil] error:nil]
valueForKey: valueForKey:
DropboxErrorUserInfo]] DropboxErrorUserInfo] :
presenter:presenter]; NSLocalizedDescriptionKey
}]
presenter:presenter
.navigationController
.topViewController];
}]; }];
} }
} }
else if (error != nil) { else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations presentErrorAlert:error [SharedDeclerations
presenter:presenter]; presentErrorAlert:error
presenter:presenter.navigationController
.topViewController];
}]; }];
} }

View File

@ -70,7 +70,7 @@ NSString *const DropboxErrorUserInfo = @"error_summary";
stringByAppendingString:[NSString stringWithFormat:@"/%@", file]]; stringByAppendingString:[NSString stringWithFormat:@"/%@", file]];
} }
#pragma mark - Alert for handling displaying Eroor Messages. #pragma mark - Alert for handling displaying Error Messages.
+ (void)presentErrorAlert:(NSError *)error + (void)presentErrorAlert:(NSError *)error
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter

View File

@ -32,7 +32,8 @@ DropboxV2ObjC *dbClient = nil;
if ([self.title isEqualToString:@"Manage"] || if ([self.title isEqualToString:@"Manage"] ||
[self.title isEqualToString:@"Upload"]) { [self.title isEqualToString:@"Upload"]) {
NSArray *temp = [[NSFileManager defaultManager] NSArray *temp = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:[SharedDeclerations savePathForFile:@""] contentsOfDirectoryAtPath:[SharedDeclerations
savePathForFile:@"SAVES"]
error:nil]; error:nil];
_dataSource = [[temp _dataSource = [[temp
@ -85,9 +86,11 @@ DropboxV2ObjC *dbClient = nil;
if ([self.title isEqualToString:@"Manage"] || if ([self.title isEqualToString:@"Manage"] ||
[self.title isEqualToString:@"Upload"]) { [self.title isEqualToString:@"Upload"]) {
NSDictionary *data = [[NSDictionary alloc] NSDictionary *data = [[NSDictionary alloc]
initWithContentsOfFile:[SharedDeclerations initWithContentsOfFile:
savePathForFile:_dataSource[indexPath [SharedDeclerations
.row]]]; savePathForFile:[@"SAVES/"
stringByAppendingString:
_dataSource[indexPath.row]]]];
cell.textLabel.text = [data valueForKey:@"MENU@LSKR1"]; cell.textLabel.text = [data valueForKey:@"MENU@LSKR1"];
} }
if ([self.title isEqualToString:@"Download"]) { if ([self.title isEqualToString:@"Download"]) {
@ -171,25 +174,42 @@ DropboxV2ObjC *dbClient = nil;
- (void)finishSelection - (void)finishSelection
{ {
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
if ([self.title isEqualToString:@"Download"]) { if ([self.title isEqualToString:@"Download"]) {
_sm.dbDownload.enabled = NO; _sm.dbDownload.enabled = NO;
_sm.dbDownload.alpha = 0.5; _sm.dbDownload.alpha = 0.5;
_main.downloadActive = true;
[queue addOperationWithBlock:^{
[dbClient downloadFromDropbox:_markList [dbClient downloadFromDropbox:_markList
presenter:self presenter:self
completion:^{ completion:^{
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
_sm.dbDownload.enabled = YES; _sm.dbDownload.enabled = YES;
_sm.dbDownload.alpha = 1.0; _sm.dbDownload.alpha = 1.0;
_main.downloadActive = false;
[self.view setNeedsDisplay];
}];
}];
}]; }];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
if ([self.title isEqualToString:@"Upload"]) { if ([self.title isEqualToString:@"Upload"]) {
_sm.dbUpload.enabled = NO; _sm.dbUpload.enabled = NO;
_sm.dbUpload.alpha = 0.5; _sm.dbUpload.alpha = 0.5;
[dbClient uploadToDropbox:_markList _main.uploadActive = true;
[queue addOperationWithBlock:^{
[dbClient
uploadToDropbox:_markList
presenter:self presenter:self
completion:^{ completion:^{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
_sm.dbUpload.enabled = YES; _sm.dbUpload.enabled = YES;
_sm.dbUpload.alpha = 1.0; _sm.dbUpload.alpha = 1.0;
_main.uploadActive = false;
[self.view setNeedsDisplay];
}];
}];
}]; }];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }

View File

@ -30,6 +30,13 @@
@property (strong, nonatomic) IBOutlet UIView *backdropKeys; @property (strong, nonatomic) IBOutlet UIView *backdropKeys;
@property (strong, nonatomic) IBOutlet UIView *backdropScreen; @property (strong, nonatomic) IBOutlet UIView *backdropScreen;
#pragma mark - Network indictaors
@property (nonatomic) BOOL downloadActive;
@property (nonatomic) BOOL uploadActive;
@property (nonatomic) BOOL oldSavesActive;
@property (nonatomic) BOOL exportActive;
@property (nonatomic) BOOL navDataActive;
#pragma mark - Save and loading methods #pragma mark - Save and loading methods
- (void)loadSave:(NSString *)file; - (void)loadSave:(NSString *)file;

View File

@ -13,7 +13,7 @@
#import "ViewController.h" #import "ViewController.h"
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface ViewControllerServiceMenu : UIViewController @interface ViewControllerServiceMenu : UIViewController <UIAlertViewDelegate>
#pragma mark - Refrence to other views in app #pragma mark - Refrence to other views in app
@ -24,10 +24,12 @@
@property (strong, nonatomic) IBOutlet UIButton *dbConnectButton; @property (strong, nonatomic) IBOutlet UIButton *dbConnectButton;
@property (strong, nonatomic) IBOutlet UIButton *dbDownload; @property (strong, nonatomic) IBOutlet UIButton *dbDownload;
@property (strong, nonatomic) IBOutlet UIButton *dbUpload; @property (strong, nonatomic) IBOutlet UIButton *dbUpload;
@property (strong, nonatomic) IBOutlet UIButton *dbNavData;
#pragma mark - Dropbox authentictaion methods #pragma mark - Dropbox authentictaion methods
- (IBAction)dbConnect:(UIButton *)sender; - (IBAction)dbConnect:(UIButton *)sender;
- (IBAction)dbDisconnect:(UIButton *)sender; - (IBAction)dbDisconnect:(UIButton *)sender;
- (IBAction)dbGetNavData:(UIButton *)sender;
@end @end

View File

@ -37,6 +37,26 @@
action:@selector(dbDisconnect:) action:@selector(dbDisconnect:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
} }
_dbDownload.enabled = YES;
_dbDownload.alpha = 1.0;
_dbUpload.enabled = YES;
_dbUpload.alpha = 1.0;
_dbNavData.enabled = YES;
_dbNavData.alpha = 1.0;
if (_main.downloadActive) {
_dbDownload.enabled = NO;
_dbDownload.alpha = 0.5;
}
if (_main.uploadActive) {
_dbUpload.enabled = NO;
_dbUpload.alpha = 0.5;
}
if (_main.navDataActive) {
_dbNavData.enabled = NO;
_dbNavData.alpha = 0.5;
}
} }
- (void)back - (void)back
@ -90,4 +110,106 @@
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
} }
- (IBAction)dbGetNavData:(UIButton *)sender
{
[self alertViewiOS7];
}
- (void)dbGetNavDataHelper
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
_dbNavData.enabled = NO;
_dbNavData.alpha = 0.5;
_main.navDataActive = true;
[queue addOperationWithBlock:^{
DropboxV2ObjC *dbClient =
((AppDelegate *)[UIApplication sharedApplication].delegate)
.dbClient;
[dbClient
contentsOfPath:@"NAVDATA"
completion:^(NSArray *files) {
if (files != nil) {
NSMutableArray *dlList = [[NSMutableArray alloc] init];
for (NSDictionary *file in files) {
[dlList
addObject:[[file valueForKey:@"path_display"]
substringFromIndex:1]];
}
[dbClient
downloadFromDropbox:dlList
presenter:self
completion:^{
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
_main.navDataActive = false;
_dbNavData.enabled = YES;
_dbNavData.alpha = 1.0;
[self.view setNeedsDisplay];
}];
}];
}
else {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
_main.navDataActive = false;
_dbNavData.enabled = YES;
_dbNavData.alpha = 1.0;
[self.view setNeedsDisplay];
}];
}
}
presenter:self];
}];
}
#pragma mark - Delegate for UIAlertView and UIAlertController outsource
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
[self dbGetNavDataHelper];
}
}
- (void)alertViewiOS7
{
if ([UIAlertController class]) {
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"NavData"
message:@"This app requires the QualityWings "
@"NavData "
@"files. Please ensure that you have the "
@"awys.txt, ints.txt and navs.txt inside "
@"the "
@"NAVDATA folder in your Dropbox."
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *defaultAction =
[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil];
UIAlertAction *loadAction =
[UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self dbGetNavDataHelper];
}];
[alert addAction:defaultAction];
[alert addAction:loadAction];
[self presentViewController:alert animated:YES completion:nil];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"NavData"
message:@"This app requires the QualityWings NavData "
@"files. Please ensure that you have the "
@"awys.txt, ints.txt and navs.txt inside the "
@"NAVDATA folder in your Dropbox."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
[alert show];
}
}
@end @end