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:
parent
262be5a429
commit
c9924d6ec5
@ -26,6 +26,7 @@
|
||||
[_dbClient setupDropboxWithHandler:^{
|
||||
}
|
||||
presenter:nil];
|
||||
[self setup];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@ -86,4 +87,49 @@
|
||||
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
|
||||
|
||||
@ -126,16 +126,30 @@
|
||||
<action selector="dbConnect:" destination="NBp-hT-qnu" eventType="touchUpInside" id="Sjs-Vk-aFg"/>
|
||||
</connections>
|
||||
</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>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<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 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 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="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="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="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"/>
|
||||
@ -147,6 +161,7 @@
|
||||
<connections>
|
||||
<outlet property="dbConnectButton" destination="MYC-QY-v42" id="SjM-EO-W5v"/>
|
||||
<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"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
|
||||
@ -93,8 +93,10 @@
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:error
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
|
||||
}];
|
||||
}
|
||||
@ -103,20 +105,45 @@
|
||||
error:nil]
|
||||
isEqualToDictionary:@{}]) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError
|
||||
errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo]]
|
||||
|
||||
presenter:presenter];
|
||||
if ([[NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
isKindOfClass:[NSDictionary class]]) {
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError
|
||||
errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:@{
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo] :
|
||||
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];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@ -176,22 +203,54 @@
|
||||
if (data2 == nil) {
|
||||
[[NSOperationQueue
|
||||
mainQueue] addOperationWithBlock:^{
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError
|
||||
errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:
|
||||
data
|
||||
options:
|
||||
0
|
||||
error:
|
||||
nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo]]
|
||||
presenter:presenter];
|
||||
if ([[NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
isKindOfClass:[NSDictionary class]]) {
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError
|
||||
errorWithDomain:
|
||||
DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:@{
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:
|
||||
data
|
||||
options:
|
||||
0
|
||||
error:
|
||||
nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo] :
|
||||
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 {
|
||||
@ -202,16 +261,20 @@
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:error
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
|
||||
}];
|
||||
}
|
||||
handler(nil);
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if EXPORT or SAVE in file name
|
||||
* IS synchronus URLRequest, best executed in background thread.
|
||||
*/
|
||||
- (void)downloadFromDropbox:(NSArray *)files
|
||||
presenter:(UIViewController *)presenter
|
||||
@ -231,79 +294,95 @@
|
||||
|
||||
// File Path
|
||||
for (NSString *string in files) {
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:@{
|
||||
NSData *data2 = [NSJSONSerialization dataWithJSONObject:@{
|
||||
@"path" : [NSString stringWithFormat:@"/%@", string]
|
||||
.precomposedStringWithCanonicalMapping
|
||||
}
|
||||
options:0
|
||||
error:nil];
|
||||
NSString *temp =
|
||||
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
options:0
|
||||
error:nil];
|
||||
NSString *temp = [[NSString alloc] initWithData:data2
|
||||
encoding:NSASCIIStringEncoding];
|
||||
temp =
|
||||
[temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
|
||||
|
||||
[request addValue:temp.precomposedStringWithCanonicalMapping
|
||||
[request setValue:temp.precomposedStringWithCanonicalMapping
|
||||
forHTTPHeaderField:(@"Dropbox-API-Arg")
|
||||
.precomposedStringWithCanonicalMapping];
|
||||
|
||||
[NSURLConnection
|
||||
sendAsynchronousRequest:request
|
||||
queue:[[NSOperationQueue alloc] init]
|
||||
completionHandler:^(NSURLResponse *response, NSData *data,
|
||||
NSError *error) {
|
||||
if (error == nil) {
|
||||
if ([[NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:@"error_summary"] == nil) {
|
||||
[data writeToFile:
|
||||
[SharedDeclerations
|
||||
savePathForFile:
|
||||
[string
|
||||
substringFromIndex:
|
||||
[string
|
||||
rangeOfString:@"/"]
|
||||
.location]]
|
||||
atomically:YES];
|
||||
}
|
||||
else {
|
||||
[[NSOperationQueue
|
||||
mainQueue] addOperationWithBlock:^{
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError
|
||||
errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:
|
||||
data
|
||||
options:
|
||||
0
|
||||
error:
|
||||
nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo]]
|
||||
presenter:presenter];
|
||||
}];
|
||||
}
|
||||
}
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSURLResponse *response = nil;
|
||||
NSError *error = nil;
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
NSData *data = [NSURLConnection sendSynchronousRequest:request
|
||||
returningResponse:&response
|
||||
error:&error];
|
||||
|
||||
}];
|
||||
}
|
||||
if (error == nil) {
|
||||
if ([[NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:@"error_summary"] == nil) {
|
||||
[data writeToFile:[SharedDeclerations savePathForFile:string]
|
||||
atomically:YES];
|
||||
}
|
||||
else {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
if ([[NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
isKindOfClass:[NSDictionary class]]) {
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError
|
||||
errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:@{
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo] :
|
||||
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) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
}];
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:error
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if SAVE or OLDSAVE in file name
|
||||
* IS synchronus URLRequest, best executed in background thread.
|
||||
*/
|
||||
- (void)uploadToDropbox:(NSArray *)files
|
||||
presenter:(UIViewController *)presenter
|
||||
@ -323,59 +402,83 @@
|
||||
|
||||
// File Path
|
||||
for (NSString *string in files) {
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:@{
|
||||
NSData *data2 = [NSJSONSerialization dataWithJSONObject:@{
|
||||
@"path" : [NSString stringWithFormat:@"/%@", string]
|
||||
.precomposedStringWithCanonicalMapping,
|
||||
@"mode" : @"overwrite".precomposedStringWithCanonicalMapping,
|
||||
}
|
||||
options:0
|
||||
error:nil];
|
||||
NSString *temp =
|
||||
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||
options:0
|
||||
error:nil];
|
||||
NSString *temp = [[NSString alloc] initWithData:data2
|
||||
encoding:NSASCIIStringEncoding];
|
||||
temp =
|
||||
[temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
|
||||
|
||||
[request addValue:temp.precomposedStringWithCanonicalMapping
|
||||
[request setValue:temp.precomposedStringWithCanonicalMapping
|
||||
forHTTPHeaderField:(@"Dropbox-API-Arg")
|
||||
.precomposedStringWithCanonicalMapping];
|
||||
|
||||
request.HTTPBody = [NSData
|
||||
dataWithContentsOfFile:[SharedDeclerations savePathForFile:string]];
|
||||
|
||||
[NSURLConnection
|
||||
sendAsynchronousRequest:request
|
||||
queue:[[NSOperationQueue alloc] init]
|
||||
completionHandler:^(NSURLResponse *response, NSData *data,
|
||||
NSError *error) {
|
||||
if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
NSURLResponse *response = nil;
|
||||
NSError *error = nil;
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
NSData *data = [NSURLConnection sendSynchronousRequest:request
|
||||
returningResponse:&response
|
||||
error:&error];
|
||||
|
||||
}];
|
||||
}
|
||||
if ([[NSJSONSerialization JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:@"error_summary"] != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError
|
||||
errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo]]
|
||||
presenter:presenter];
|
||||
}];
|
||||
}
|
||||
}];
|
||||
if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations
|
||||
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
|
||||
options:0
|
||||
error:nil]
|
||||
isKindOfClass:[NSDictionary class]]) {
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:
|
||||
[NSError errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:@{
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo] :
|
||||
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();
|
||||
}
|
||||
@ -399,12 +502,14 @@
|
||||
}
|
||||
}
|
||||
if (!exports) {
|
||||
[self createFolderAtPath:@"EXPORTS"
|
||||
presenter:presenter];
|
||||
[self
|
||||
createFolderAtPath:@"EXPORTS"
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
}
|
||||
}
|
||||
presenter:presenter];
|
||||
// NavData (Two files from PMDG Navigraph data
|
||||
// NavData (3 files from QW Navigraph data
|
||||
[self contentsOfPath:nil
|
||||
completion:^(NSArray *data) {
|
||||
BOOL exports = false;
|
||||
@ -416,29 +521,33 @@
|
||||
}
|
||||
}
|
||||
if (!exports) {
|
||||
[self createFolderAtPath:@"NAVDATA"
|
||||
presenter:presenter];
|
||||
[self
|
||||
createFolderAtPath:@"NAVDATA"
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
}
|
||||
}
|
||||
presenter:presenter];
|
||||
presenter:presenter.navigationController.topViewController];
|
||||
// Backups of Saves
|
||||
[self
|
||||
contentsOfPath:nil
|
||||
completion:^(NSArray *data) {
|
||||
BOOL exports = false;
|
||||
for (NSDictionary *dict in data) {
|
||||
if ([[dict valueForKey:@"name"]
|
||||
isEqualToString:@"SAVES"]) {
|
||||
exports = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exports) {
|
||||
[self createFolderAtPath:@"SAVES" presenter:presenter];
|
||||
}
|
||||
}
|
||||
presenter:presenter];
|
||||
// Old saves (FMC Planner + (or X))
|
||||
[self contentsOfPath:nil
|
||||
completion:^(NSArray *data) {
|
||||
BOOL exports = false;
|
||||
for (NSDictionary *dict in data) {
|
||||
if ([[dict valueForKey:@"name"]
|
||||
isEqualToString:@"SAVES"]) {
|
||||
exports = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exports) {
|
||||
[self
|
||||
createFolderAtPath:@"SAVES"
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
}
|
||||
}
|
||||
presenter:presenter.navigationController.topViewController];
|
||||
// Old saves (FMC Planner + (or X?))
|
||||
[self contentsOfPath:nil
|
||||
completion:^(NSArray *data) {
|
||||
BOOL exports = false;
|
||||
@ -450,11 +559,13 @@
|
||||
}
|
||||
}
|
||||
if (!exports) {
|
||||
[self createFolderAtPath:@"OLDSAVES"
|
||||
presenter:presenter];
|
||||
[self
|
||||
createFolderAtPath:@"OLDSAVES"
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
}
|
||||
}
|
||||
presenter:presenter];
|
||||
presenter:presenter.navigationController.topViewController];
|
||||
}];
|
||||
handler();
|
||||
}
|
||||
@ -524,22 +635,28 @@
|
||||
[NSError
|
||||
errorWithDomain:DropboxErrorDomain
|
||||
code:100
|
||||
userInfo:
|
||||
userInfo:@{
|
||||
[[NSJSONSerialization
|
||||
JSONObjectWithData:data
|
||||
options:0
|
||||
error:nil]
|
||||
valueForKey:
|
||||
DropboxErrorUserInfo]]
|
||||
presenter:presenter];
|
||||
DropboxErrorUserInfo] :
|
||||
NSLocalizedDescriptionKey
|
||||
}]
|
||||
presenter:presenter
|
||||
.navigationController
|
||||
.topViewController];
|
||||
}];
|
||||
}
|
||||
}
|
||||
else if (error != nil) {
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
|
||||
[SharedDeclerations presentErrorAlert:error
|
||||
presenter:presenter];
|
||||
[SharedDeclerations
|
||||
presentErrorAlert:error
|
||||
presenter:presenter.navigationController
|
||||
.topViewController];
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ NSString *const DropboxErrorUserInfo = @"error_summary";
|
||||
stringByAppendingString:[NSString stringWithFormat:@"/%@", file]];
|
||||
}
|
||||
|
||||
#pragma mark - Alert for handling displaying Eroor Messages.
|
||||
#pragma mark - Alert for handling displaying Error Messages.
|
||||
|
||||
+ (void)presentErrorAlert:(NSError *)error
|
||||
presenter:(UIViewController *)presenter
|
||||
|
||||
@ -32,7 +32,8 @@ DropboxV2ObjC *dbClient = nil;
|
||||
if ([self.title isEqualToString:@"Manage"] ||
|
||||
[self.title isEqualToString:@"Upload"]) {
|
||||
NSArray *temp = [[NSFileManager defaultManager]
|
||||
contentsOfDirectoryAtPath:[SharedDeclerations savePathForFile:@""]
|
||||
contentsOfDirectoryAtPath:[SharedDeclerations
|
||||
savePathForFile:@"SAVES"]
|
||||
error:nil];
|
||||
|
||||
_dataSource = [[temp
|
||||
@ -85,9 +86,11 @@ DropboxV2ObjC *dbClient = nil;
|
||||
if ([self.title isEqualToString:@"Manage"] ||
|
||||
[self.title isEqualToString:@"Upload"]) {
|
||||
NSDictionary *data = [[NSDictionary alloc]
|
||||
initWithContentsOfFile:[SharedDeclerations
|
||||
savePathForFile:_dataSource[indexPath
|
||||
.row]]];
|
||||
initWithContentsOfFile:
|
||||
[SharedDeclerations
|
||||
savePathForFile:[@"SAVES/"
|
||||
stringByAppendingString:
|
||||
_dataSource[indexPath.row]]]];
|
||||
cell.textLabel.text = [data valueForKey:@"MENU@LSKR1"];
|
||||
}
|
||||
if ([self.title isEqualToString:@"Download"]) {
|
||||
@ -171,26 +174,43 @@ DropboxV2ObjC *dbClient = nil;
|
||||
|
||||
- (void)finishSelection
|
||||
{
|
||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
||||
if ([self.title isEqualToString:@"Download"]) {
|
||||
_sm.dbDownload.enabled = NO;
|
||||
_sm.dbDownload.alpha = 0.5;
|
||||
[dbClient downloadFromDropbox:_markList
|
||||
presenter:self
|
||||
completion:^{
|
||||
_sm.dbDownload.enabled = YES;
|
||||
_sm.dbDownload.alpha = 1.0;
|
||||
}];
|
||||
_main.downloadActive = true;
|
||||
[queue addOperationWithBlock:^{
|
||||
[dbClient downloadFromDropbox:_markList
|
||||
presenter:self
|
||||
completion:^{
|
||||
[[NSOperationQueue mainQueue]
|
||||
addOperationWithBlock:^{
|
||||
_sm.dbDownload.enabled = YES;
|
||||
_sm.dbDownload.alpha = 1.0;
|
||||
_main.downloadActive = false;
|
||||
[self.view setNeedsDisplay];
|
||||
}];
|
||||
}];
|
||||
}];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
if ([self.title isEqualToString:@"Upload"]) {
|
||||
_sm.dbUpload.enabled = NO;
|
||||
_sm.dbUpload.alpha = 0.5;
|
||||
[dbClient uploadToDropbox:_markList
|
||||
presenter:self
|
||||
completion:^{
|
||||
_sm.dbUpload.enabled = YES;
|
||||
_sm.dbUpload.alpha = 1.0;
|
||||
}];
|
||||
_main.uploadActive = true;
|
||||
[queue addOperationWithBlock:^{
|
||||
[dbClient
|
||||
uploadToDropbox:_markList
|
||||
presenter:self
|
||||
completion:^{
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
_sm.dbUpload.enabled = YES;
|
||||
_sm.dbUpload.alpha = 1.0;
|
||||
_main.uploadActive = false;
|
||||
[self.view setNeedsDisplay];
|
||||
}];
|
||||
}];
|
||||
}];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,6 +30,13 @@
|
||||
@property (strong, nonatomic) IBOutlet UIView *backdropKeys;
|
||||
@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
|
||||
|
||||
- (void)loadSave:(NSString *)file;
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#import "ViewController.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewControllerServiceMenu : UIViewController
|
||||
@interface ViewControllerServiceMenu : UIViewController <UIAlertViewDelegate>
|
||||
|
||||
#pragma mark - Refrence to other views in app
|
||||
|
||||
@ -24,10 +24,12 @@
|
||||
@property (strong, nonatomic) IBOutlet UIButton *dbConnectButton;
|
||||
@property (strong, nonatomic) IBOutlet UIButton *dbDownload;
|
||||
@property (strong, nonatomic) IBOutlet UIButton *dbUpload;
|
||||
@property (strong, nonatomic) IBOutlet UIButton *dbNavData;
|
||||
|
||||
#pragma mark - Dropbox authentictaion methods
|
||||
|
||||
- (IBAction)dbConnect:(UIButton *)sender;
|
||||
- (IBAction)dbDisconnect:(UIButton *)sender;
|
||||
- (IBAction)dbGetNavData:(UIButton *)sender;
|
||||
|
||||
@end
|
||||
|
||||
@ -37,6 +37,26 @@
|
||||
action:@selector(dbDisconnect:)
|
||||
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
|
||||
@ -90,4 +110,106 @@
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user