You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by be...@apache.org on 2012/01/13 16:59:07 UTC
[38/50] git commit: download returns FileEntry instead of string
download returns FileEntry instead of string
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/78aa7f14
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/78aa7f14
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/78aa7f14
Branch: refs/heads/master
Commit: 78aa7f14cf8e10e29ec5de3319218b60b623ce5a
Parents: 2ff8268
Author: Alexander Keller <ak...@aflx.de>
Authored: Tue Nov 29 09:33:32 2011 +0100
Committer: Alexander Keller <ak...@aflx.de>
Committed: Tue Nov 29 09:33:32 2011 +0100
----------------------------------------------------------------------
PhoneGapLib/Classes/FileTransfer.h | 2 --
PhoneGapLib/Classes/FileTransfer.m | 21 ++++++++++++---------
2 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/78aa7f14/PhoneGapLib/Classes/FileTransfer.h
----------------------------------------------------------------------
diff --git a/PhoneGapLib/Classes/FileTransfer.h b/PhoneGapLib/Classes/FileTransfer.h
index 7a752d0..5a0428a 100644
--- a/PhoneGapLib/Classes/FileTransfer.h
+++ b/PhoneGapLib/Classes/FileTransfer.h
@@ -22,8 +22,6 @@ typedef int FileTransferError;
}
-@property (nonatomic, copy) NSString* callbackID;
-
- (void) upload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void) download:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/78aa7f14/PhoneGapLib/Classes/FileTransfer.m
----------------------------------------------------------------------
diff --git a/PhoneGapLib/Classes/FileTransfer.m b/PhoneGapLib/Classes/FileTransfer.m
index d84e8f0..b1050df 100644
--- a/PhoneGapLib/Classes/FileTransfer.m
+++ b/PhoneGapLib/Classes/FileTransfer.m
@@ -8,12 +8,11 @@
*/
#import "FileTransfer.h"
+#import "File.h"
@implementation PGFileTransfer
-@synthesize callbackID;
-
- (void) upload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSString* callbackId = [arguments objectAtIndex:0];
NSString* fileKey = (NSString*)[options objectForKey:@"fileKey"];
@@ -149,6 +148,7 @@
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData* data = [NSData dataWithContentsOfURL: [NSURL URLWithString:sourceUrl] ];
+ NSArray * results = nil;
NSLog(@"Write file %@", filePath);
NSError *error=[[[NSError alloc]init] autorelease];
@@ -163,11 +163,12 @@
if ( response == NO ) {
// send our results back to the main thread
- NSArray * results = [NSArray arrayWithObjects: callbackId, [error description], nil];
+ results = [NSArray arrayWithObjects: callbackId, [error description], nil];
[self performSelectorOnMainThread:@selector(downloadFail:) withObject:results waitUntilDone:YES];
} else {
// jump back to main thread
- [self performSelectorOnMainThread:@selector(downloadSuccess:) withObject:arguments waitUntilDone:YES];
+ results = [NSArray arrayWithObjects: callbackId, filePath, nil];
+ [self performSelectorOnMainThread:@selector(downloadSuccess:) withObject:results waitUntilDone:YES];
}
}
@catch (id exception) {
@@ -183,14 +184,16 @@
-(void) downloadSuccess:(NSMutableArray *)arguments
{
NSString * callbackId = [arguments objectAtIndex:0];
- NSString * filePath = [arguments objectAtIndex:2];
+ NSString * filePath = [arguments objectAtIndex:1];
+
+ BOOL bDirRequest = NO;
NSLog(@"File Transfert Download success");
- PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString:
- [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
-
- [self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];
+ PGFile * file = [[PGFile alloc] init];
+
+ PluginResult* result = [PluginResult resultWithStatus: PGCommandStatus_OK messageAsDictionary: [file getDirectoryEntry: filePath isDirectory: bDirRequest] cast: @"window.localFileSystem._castEntry"];
+ [self writeJavascript: [result toSuccessCallbackString:callbackId]];
}
-(void) downloadFail:(NSMutableArray *)arguments