Skip to content

Commit c3b5778

Browse files
tripodsanshazron
authored andcommitted
CB-9544 Add file plugin for OSX
- adding osx specific sources - adding osx to plugin.xml and package.json
1 parent 11d6cf0 commit c3b5778

File tree

9 files changed

+2083
-0
lines changed

9 files changed

+2083
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Although in the global scope, it is not available until after the `deviceready`
6363
- Windows 8*
6464
- Windows*
6565
- Browser
66+
- OS X
6667

6768
\* _These platforms do not support `FileReader.readAsArrayBuffer` nor `FileWriter.write(blob)`._
6869

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"amazon-fireos",
1010
"ubuntu",
1111
"ios",
12+
"osx",
1213
"wp7",
1314
"wp8",
1415
"blackberry10",
@@ -29,6 +30,7 @@
2930
"cordova-amazon-fireos",
3031
"cordova-ubuntu",
3132
"cordova-ios",
33+
"cordova-osx",
3234
"cordova-wp7",
3335
"cordova-wp8",
3436
"cordova-blackberry10",

plugin.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,34 @@ to config.xml in order for the application to find previously stored files.
248248
<framework src="MobileCoreServices.framework" />
249249
</platform>
250250

251+
<!-- osx -->
252+
<platform name="osx">
253+
<config-file target="config.xml" parent="/*">
254+
<feature name="File">
255+
<param name="ios-package" value="CDVFile" />
256+
<param name="onload" value="true" />
257+
</feature>
258+
</config-file>
259+
<header-file src="src/osx/CDVFile.h" />
260+
<source-file src="src/osx/CDVFile.m" />
261+
<header-file src="src/osx/CDVLocalFilesystem.h" />
262+
<source-file src="src/osx/CDVLocalFilesystem.m" />
263+
264+
<!-- osx specific file apis -->
265+
<js-module src="www/osx/FileSystem.js" name="osxFileSystem">
266+
<merges target="FileSystem" />
267+
</js-module>
268+
269+
<js-module src="www/fileSystems-roots.js" name="fileSystems-roots">
270+
<runs/>
271+
</js-module>
272+
273+
<js-module src="www/fileSystemPaths.js" name="fileSystemPaths">
274+
<merges target="cordova" />
275+
<runs/>
276+
</js-module>
277+
</platform>
278+
251279
<!-- wp7 -->
252280
<platform name="wp7">
253281
<config-file target="config.xml" parent="/*">

src/osx/CDVFile.h

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
#import <Foundation/Foundation.h>
21+
#import <Cordova/CDVPlugin.h>
22+
23+
NSString* const kCDVAssetsLibraryPrefix;
24+
NSString* const kCDVFilesystemURLPrefix;
25+
26+
enum CDVFileError {
27+
NO_ERROR = 0,
28+
NOT_FOUND_ERR = 1,
29+
SECURITY_ERR = 2,
30+
ABORT_ERR = 3,
31+
NOT_READABLE_ERR = 4,
32+
ENCODING_ERR = 5,
33+
NO_MODIFICATION_ALLOWED_ERR = 6,
34+
INVALID_STATE_ERR = 7,
35+
SYNTAX_ERR = 8,
36+
INVALID_MODIFICATION_ERR = 9,
37+
QUOTA_EXCEEDED_ERR = 10,
38+
TYPE_MISMATCH_ERR = 11,
39+
PATH_EXISTS_ERR = 12
40+
};
41+
typedef int CDVFileError;
42+
43+
@interface CDVFilesystemURL : NSObject {
44+
NSURL *_url;
45+
NSString *_fileSystemName;
46+
NSString *_fullPath;
47+
}
48+
49+
- (id) initWithString:(NSString*)strURL;
50+
- (id) initWithURL:(NSURL*)URL;
51+
+ (CDVFilesystemURL *)fileSystemURLWithString:(NSString *)strURL;
52+
+ (CDVFilesystemURL *)fileSystemURLWithURL:(NSURL *)URL;
53+
54+
- (NSString *)absoluteURL;
55+
56+
@property (atomic) NSURL *url;
57+
@property (atomic) NSString *fileSystemName;
58+
@property (atomic) NSString *fullPath;
59+
60+
@end
61+
62+
@interface CDVFilesystemURLProtocol : NSURLProtocol
63+
@end
64+
65+
@protocol CDVFileSystem
66+
- (CDVPluginResult *)entryForLocalURI:(CDVFilesystemURL *)url;
67+
- (CDVPluginResult *)getFileForURL:(CDVFilesystemURL *)baseURI requestedPath:(NSString *)requestedPath options:(NSDictionary *)options;
68+
- (CDVPluginResult *)getParentForURL:(CDVFilesystemURL *)localURI;
69+
- (CDVPluginResult *)setMetadataForURL:(CDVFilesystemURL *)localURI withObject:(NSDictionary *)options;
70+
- (CDVPluginResult *)removeFileAtURL:(CDVFilesystemURL *)localURI;
71+
- (CDVPluginResult *)recursiveRemoveFileAtURL:(CDVFilesystemURL *)localURI;
72+
- (CDVPluginResult *)readEntriesAtURL:(CDVFilesystemURL *)localURI;
73+
- (CDVPluginResult *)truncateFileAtURL:(CDVFilesystemURL *)localURI atPosition:(unsigned long long)pos;
74+
- (CDVPluginResult *)writeToFileAtURL:(CDVFilesystemURL *)localURL withData:(NSData*)encData append:(BOOL)shouldAppend;
75+
- (void)copyFileToURL:(CDVFilesystemURL *)destURL withName:(NSString *)newName fromFileSystem:(NSObject<CDVFileSystem> *)srcFs atURL:(CDVFilesystemURL *)srcURL copy:(BOOL)bCopy callback:(void (^)(CDVPluginResult *))callback;
76+
- (void)readFileAtURL:(CDVFilesystemURL *)localURL start:(NSInteger)start end:(NSInteger)end callback:(void (^)(NSData*, NSString* mimeType, CDVFileError))callback;
77+
- (void)getFileMetadataForURL:(CDVFilesystemURL *)localURL callback:(void (^)(CDVPluginResult *))callback;
78+
79+
- (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)url;
80+
- (NSDictionary*)makeEntryForPath:(NSString*)fullPath isDirectory:(BOOL)isDir;
81+
82+
@property (nonatomic,strong) NSString *name;
83+
@property (nonatomic, copy) NSURL*(^urlTransformer)(NSURL*);
84+
85+
@optional
86+
- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)localURI;
87+
- (CDVFilesystemURL *)URLforFilesystemPath:(NSString *)path;
88+
89+
@end
90+
91+
@interface CDVFile : CDVPlugin {
92+
NSString* rootDocsPath;
93+
NSString* appDocsPath;
94+
NSString* appLibraryPath;
95+
NSString* appTempPath;
96+
97+
NSMutableArray* fileSystems_;
98+
BOOL userHasAllowed;
99+
}
100+
101+
- (NSNumber*)checkFreeDiskSpace:(NSString*)appPath;
102+
- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir;
103+
- (NSDictionary *)makeEntryForURL:(NSURL *)URL;
104+
- (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath;
105+
106+
- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL;
107+
108+
/* Native Registration API */
109+
- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs;
110+
- (NSObject<CDVFileSystem> *)fileSystemByName:(NSString *)fsName;
111+
112+
/* Exec API */
113+
- (void)requestFileSystem:(CDVInvokedUrlCommand*)command;
114+
- (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command;
115+
- (void)getDirectory:(CDVInvokedUrlCommand*)command;
116+
- (void)getFile:(CDVInvokedUrlCommand*)command;
117+
- (void)getParent:(CDVInvokedUrlCommand*)command;
118+
- (void)removeRecursively:(CDVInvokedUrlCommand*)command;
119+
- (void)remove:(CDVInvokedUrlCommand*)command;
120+
- (void)copyTo:(CDVInvokedUrlCommand*)command;
121+
- (void)moveTo:(CDVInvokedUrlCommand*)command;
122+
- (void)getFileMetadata:(CDVInvokedUrlCommand*)command;
123+
- (void)readEntries:(CDVInvokedUrlCommand*)command;
124+
- (void)readAsText:(CDVInvokedUrlCommand*)command;
125+
- (void)readAsDataURL:(CDVInvokedUrlCommand*)command;
126+
- (void)readAsArrayBuffer:(CDVInvokedUrlCommand*)command;
127+
- (void)write:(CDVInvokedUrlCommand*)command;
128+
- (void)testFileExists:(CDVInvokedUrlCommand*)command;
129+
- (void)testDirectoryExists:(CDVInvokedUrlCommand*)command;
130+
- (void)getFreeDiskSpace:(CDVInvokedUrlCommand*)command;
131+
- (void)truncate:(CDVInvokedUrlCommand*)command;
132+
- (void)doCopyMove:(CDVInvokedUrlCommand*)command isCopy:(BOOL)bCopy;
133+
134+
/* Compatibilty with older File API */
135+
- (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
136+
- (NSDictionary *)getDirectoryEntry:(NSString *)target isDirectory:(BOOL)bDirRequest;
137+
138+
/* Conversion between filesystem paths and URLs */
139+
- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)URL;
140+
141+
/* Internal methods for testing */
142+
- (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command;
143+
144+
@property (nonatomic, strong) NSString* rootDocsPath;
145+
@property (nonatomic, strong) NSString* appDocsPath;
146+
@property (nonatomic, strong) NSString* appLibraryPath;
147+
@property (nonatomic, strong) NSString* appTempPath;
148+
@property (nonatomic, strong) NSString* persistentPath;
149+
@property (nonatomic, strong) NSString* temporaryPath;
150+
@property (nonatomic, strong) NSMutableArray* fileSystems;
151+
152+
@property BOOL userHasAllowed;
153+
154+
@end
155+
156+
#define kW3FileTemporary @"temporary"
157+
#define kW3FilePersistent @"persistent"

0 commit comments

Comments
 (0)