arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-file/src/osx/CDVFile.h
plugins/cordova-plugin-file/src/osx/CDVFile.hRaw
  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
 23NSString* const kCDVFilesystemURLPrefix;
 24
 25/**
 26* The default filesystems if non are specified.
 27*/
 28#define CDV_FILESYSTEMS_DEFAULT @"documents,cache,bundle,root"
 29
 30/**
 31* Preference name of the extra filesystems to be "mounted". the following are supported:
 32* 'bundle'    - mounts the application directory
 33* 'documents' - mounts the users Documents directory (~/Documents)
 34* 'root'      - mounts the root file system
 35* 'cache'     - mounts the caches directory (~/Library/Caches/<bundle-id/)
 36*/
 37#define CDV_PREF_EXTRA_FILESYSTEM @"osxextrafilesystems"
 38
 39enum CDVFileError {
 40    NO_ERROR = 0,
 41    NOT_FOUND_ERR = 1,
 42    SECURITY_ERR = 2,
 43    ABORT_ERR = 3,
 44    NOT_READABLE_ERR = 4,
 45    ENCODING_ERR = 5,
 46    NO_MODIFICATION_ALLOWED_ERR = 6,
 47    INVALID_STATE_ERR = 7,
 48    SYNTAX_ERR = 8,
 49    INVALID_MODIFICATION_ERR = 9,
 50    QUOTA_EXCEEDED_ERR = 10,
 51    TYPE_MISMATCH_ERR = 11,
 52    PATH_EXISTS_ERR = 12
 53};
 54typedef int CDVFileError;
 55
 56@interface CDVFilesystemURL : NSObject  {
 57    NSURL *_url;
 58    NSString *_fileSystemName;
 59    NSString *_fullPath;
 60}
 61
 62- (id) initWithString:(NSString*)strURL;
 63- (id) initWithURL:(NSURL*)URL;
 64+ (CDVFilesystemURL *)fileSystemURLWithString:(NSString *)strURL;
 65+ (CDVFilesystemURL *)fileSystemURLWithURL:(NSURL *)URL;
 66
 67- (NSString *)absoluteURL;
 68
 69@property (atomic) NSURL *url;
 70@property (atomic) NSString *fileSystemName;
 71@property (atomic) NSString *fullPath;
 72
 73@end
 74
 75@interface CDVFilesystemURLProtocol : NSURLProtocol
 76@end
 77
 78@protocol CDVFileSystem
 79- (CDVPluginResult *)entryForLocalURI:(CDVFilesystemURL *)url;
 80- (CDVPluginResult *)getFileForURL:(CDVFilesystemURL *)baseURI requestedPath:(NSString *)requestedPath options:(NSDictionary *)options;
 81- (CDVPluginResult *)getParentForURL:(CDVFilesystemURL *)localURI;
 82- (CDVPluginResult *)setMetadataForURL:(CDVFilesystemURL *)localURI withObject:(NSDictionary *)options;
 83- (CDVPluginResult *)removeFileAtURL:(CDVFilesystemURL *)localURI;
 84- (CDVPluginResult *)recursiveRemoveFileAtURL:(CDVFilesystemURL *)localURI;
 85- (CDVPluginResult *)readEntriesAtURL:(CDVFilesystemURL *)localURI;
 86- (CDVPluginResult *)truncateFileAtURL:(CDVFilesystemURL *)localURI atPosition:(unsigned long long)pos;
 87- (CDVPluginResult *)writeToFileAtURL:(CDVFilesystemURL *)localURL withData:(NSData*)encData append:(BOOL)shouldAppend;
 88- (void)copyFileToURL:(CDVFilesystemURL *)destURL withName:(NSString *)newName fromFileSystem:(NSObject<CDVFileSystem> *)srcFs atURL:(CDVFilesystemURL *)srcURL copy:(BOOL)bCopy callback:(void (^)(CDVPluginResult *))callback;
 89- (void)readFileAtURL:(CDVFilesystemURL *)localURL start:(NSInteger)start end:(NSInteger)end callback:(void (^)(NSData*, NSString* mimeType, CDVFileError))callback;
 90- (void)getFileMetadataForURL:(CDVFilesystemURL *)localURL callback:(void (^)(CDVPluginResult *))callback;
 91
 92- (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)url;
 93- (NSDictionary*)makeEntryForPath:(NSString*)fullPath isDirectory:(BOOL)isDir;
 94
 95@property (nonatomic,strong) NSString *name;
 96@property (nonatomic, copy) NSURL*(^urlTransformer)(NSURL*);
 97
 98@optional
 99- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)localURI;
100- (CDVFilesystemURL *)URLforFilesystemPath:(NSString *)path;
101
102@end
103
104@interface CDVFile : CDVPlugin {
105    NSString* rootDocsPath;
106    NSString* appDocsPath;
107    NSString* appLibraryPath;
108    NSString* appTempPath;
109
110    NSMutableArray* fileSystems_;
111    BOOL userHasAllowed;
112}
113
114- (NSNumber*)checkFreeDiskSpace:(NSString*)appPath;
115- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir;
116- (NSDictionary *)makeEntryForURL:(NSURL *)URL;
117- (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath;
118
119- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL;
120
121/* Native Registration API */
122- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs;
123- (NSObject<CDVFileSystem> *)fileSystemByName:(NSString *)fsName;
124
125/* Exec API */
126- (void)requestFileSystem:(CDVInvokedUrlCommand*)command;
127- (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command;
128- (void)getDirectory:(CDVInvokedUrlCommand*)command;
129- (void)getFile:(CDVInvokedUrlCommand*)command;
130- (void)getParent:(CDVInvokedUrlCommand*)command;
131- (void)removeRecursively:(CDVInvokedUrlCommand*)command;
132- (void)remove:(CDVInvokedUrlCommand*)command;
133- (void)copyTo:(CDVInvokedUrlCommand*)command;
134- (void)moveTo:(CDVInvokedUrlCommand*)command;
135- (void)getFileMetadata:(CDVInvokedUrlCommand*)command;
136- (void)readEntries:(CDVInvokedUrlCommand*)command;
137- (void)readAsText:(CDVInvokedUrlCommand*)command;
138- (void)readAsDataURL:(CDVInvokedUrlCommand*)command;
139- (void)readAsArrayBuffer:(CDVInvokedUrlCommand*)command;
140- (void)write:(CDVInvokedUrlCommand*)command;
141- (void)testFileExists:(CDVInvokedUrlCommand*)command;
142- (void)testDirectoryExists:(CDVInvokedUrlCommand*)command;
143- (void)getFreeDiskSpace:(CDVInvokedUrlCommand*)command;
144- (void)truncate:(CDVInvokedUrlCommand*)command;
145- (void)doCopyMove:(CDVInvokedUrlCommand*)command isCopy:(BOOL)bCopy;
146
147/* Compatibilty with older File API */
148- (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
149- (NSDictionary *)getDirectoryEntry:(NSString *)target isDirectory:(BOOL)bDirRequest;
150
151/* Conversion between filesystem paths and URLs */
152- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)URL;
153
154/* Internal methods for testing */
155- (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command;
156
157/**
158 * local path of the 'documents' file system (~/Documents)
159 */
160@property (nonatomic, strong) NSString* appDocsPath;
161
162/**
163* local path of the 'applicationStorageDirectory' file system (~/Library/Application Support/<bundle-id>)
164*/
165@property (nonatomic, strong) NSString* appSupportPath;
166
167/**
168* local path of the 'persistent' file system (~/Library/Application Support/<bundle-id>/files)
169*/
170@property (nonatomic, strong) NSString* appDataPath;
171
172/**
173* local path of the 'documents' file system (~/Documents)
174*/
175@property (nonatomic, strong) NSString* appTempPath;
176
177/**
178* local path of the 'cache' file system (~/Library/Caches/<bundle-id>)
179*/
180@property (nonatomic, strong) NSString* appCachePath;
181
182/**
183 * registered file systems
184 */
185@property (nonatomic, strong) NSMutableArray* fileSystems;
186
187@property BOOL userHasAllowed;
188
189@end