1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
---@meta
---@class cc.FileUtils
local FileUtils={ }
cc.FileUtils=FileUtils
---* Returns the fullpath for a given filename.<br>
---* First it will try to get a new filename from the "filenameLookup" dictionary.<br>
---* If a new filename can't be found on the dictionary, it will use the original filename.<br>
---* Then it will try to obtain the full path of the filename using the FileUtils search rules: resolutions, and search paths.<br>
---* The file search is based on the array element order of search paths and resolution directories.<br>
---* For instance:<br>
---* We set two elements("/mnt/sdcard/", "internal_dir/") to search paths vector by setSearchPaths,<br>
---* and set three elements("resources-ipadhd/", "resources-ipad/", "resources-iphonehd")<br>
---* to resolutions vector by setSearchResolutionsOrder. The "internal_dir" is relative to "Resources/".<br>
---* If we have a file named 'sprite.png', the mapping in fileLookup dictionary contains `key: sprite.png -> value: sprite.pvr.gz`.<br>
---* Firstly, it will replace 'sprite.png' with 'sprite.pvr.gz', then searching the file sprite.pvr.gz as follows:<br>
---* /mnt/sdcard/resources-ipadhd/sprite.pvr.gz (if not found, search next)<br>
---* /mnt/sdcard/resources-ipad/sprite.pvr.gz (if not found, search next)<br>
---* /mnt/sdcard/resources-iphonehd/sprite.pvr.gz (if not found, search next)<br>
---* /mnt/sdcard/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/resources-ipadhd/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/resources-ipad/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/resources-iphonehd/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/sprite.pvr.gz (if not found, return "sprite.png")<br>
---* If the filename contains relative path like "gamescene/uilayer/sprite.png",<br>
---* and the mapping in fileLookup dictionary contains `key: gamescene/uilayer/sprite.png -> value: gamescene/uilayer/sprite.pvr.gz`.<br>
---* The file search order will be:<br>
---* /mnt/sdcard/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)<br>
---* /mnt/sdcard/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)<br>
---* /mnt/sdcard/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)<br>
---* /mnt/sdcard/gamescene/uilayer/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)<br>
---* internal_dir/gamescene/uilayer/sprite.pvr.gz (if not found, return "gamescene/uilayer/sprite.png")<br>
---* If the new file can't be found on the file system, it will return the parameter filename directly.<br>
---* This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable,<br>
---* you might need to load different resources for a given file in the different platforms.<br>
---* since v2.1
---@param filename string
---@return string
function FileUtils:fullPathForFilename (filename) end
---@overload fun(string:string,function:function):self
---@overload fun(string:string):self
---@param path string
---@param callback function
---@return self
function FileUtils:getStringFromFile (path,callback) end
---* Sets the filenameLookup dictionary.<br>
---* param filenameLookupDict The dictionary for replacing filename.<br>
---* since v2.1
---@param filenameLookupDict map_table
---@return self
function FileUtils:setFilenameLookupDictionary (filenameLookupDict) end
---@overload fun(string:string,function:function):self
---@overload fun(string:string):self
---@param filepath string
---@param callback function
---@return self
function FileUtils:removeFile (filepath,callback) end
---* List all files recursively in a directory, async off the main cocos thread.<br>
---* param dirPath The path of the directory, it could be a relative or an absolute path.<br>
---* param callback The callback to be called once the list operation is complete. <br>
---* Will be called on the main cocos thread.<br>
---* js NA<br>
---* lua NA
---@param dirPath string
---@param callback function
---@return self
function FileUtils:listFilesRecursivelyAsync (dirPath,callback) end
---* Checks whether the path is an absolute path.<br>
---* note On Android, if the parameter passed in is relative to "assets/", this method will treat it as an absolute path.<br>
---* Also on Blackberry, path starts with "app/native/Resources/" is treated as an absolute path.<br>
---* param path The path that needs to be checked.<br>
---* return True if it's an absolute path, false if not.
---@param path string
---@return boolean
function FileUtils:isAbsolutePath (path) end
---@overload fun(string:string,string:string,string:string,function:function):self
---@overload fun(string:string,string:string,string:string):self
---@overload fun(string:string,string:string):self
---@overload fun(string:string,string:string,string2:function):self
---@param path string
---@param oldname string
---@param name string
---@param callback function
---@return self
function FileUtils:renameFile (path,oldname,name,callback) end
---* Get default resource root path.
---@return string
function FileUtils:getDefaultResourceRootPath () end
---* Loads the filenameLookup dictionary from the contents of a filename.<br>
---* note The plist file name should follow the format below:<br>
---* code<br>
---* <?xml version="1.0" encoding="UTF-8"?><br>
---* <!DOCTYPE plist PUBLIC "-AppleDTD PLIST 1.0EN" "http:www.apple.com/DTDs/PropertyList-1.0.dtd"><br>
---* <plist version="1.0"><br>
---* <dict><br>
---* <key>filenames</key><br>
---* <dict><br>
---* <key>sounds/click.wav</key><br>
---* <string>sounds/click.caf</string><br>
---* <key>sounds/endgame.wav</key><br>
---* <string>sounds/endgame.caf</string><br>
---* <key>sounds/gem-0.wav</key><br>
---* <string>sounds/gem-0.caf</string><br>
---* </dict><br>
---* <key>metadata</key><br>
---* <dict><br>
---* <key>version</key><br>
---* <integer>1</integer><br>
---* </dict><br>
---* </dict><br>
---* </plist><br>
---* endcode<br>
---* param filename The plist file name.<br>
---* since v2.1<br>
---* js loadFilenameLookup<br>
---* lua loadFilenameLookup
---@param filename string
---@return self
function FileUtils:loadFilenameLookupDictionaryFromFile (filename) end
---* Checks whether to pop up a message box when failed to load an image.<br>
---* return True if pop up a message box when failed to load an image, false if not.
---@return boolean
function FileUtils:isPopupNotify () end
---*
---@param filename string
---@return array_table
function FileUtils:getValueVectorFromFile (filename) end
---* Gets the array of search paths.<br>
---* return The array of search paths which may contain the prefix of default resource root path. <br>
---* note In best practise, getter function should return the value of setter function passes in.<br>
---* But since we should not break the compatibility, we keep using the old logic. <br>
---* Therefore, If you want to get the original search paths, please call 'getOriginalSearchPaths()' instead.<br>
---* see fullPathForFilename(const char*).<br>
---* lua NA
---@return array_table
function FileUtils:getSearchPaths () end
---* write a ValueMap into a plist file<br>
---* param dict the ValueMap want to save<br>
---* param fullPath The full path to the file you want to save a string<br>
---* return bool
---@param dict map_table
---@param fullPath string
---@return boolean
function FileUtils:writeToFile (dict,fullPath) end
---* Gets the original search path array set by 'setSearchPaths' or 'addSearchPath'.<br>
---* return The array of the original search paths
---@return array_table
function FileUtils:getOriginalSearchPaths () end
---* Gets the new filename from the filename lookup dictionary.<br>
---* It is possible to have a override names.<br>
---* param filename The original filename.<br>
---* return The new filename after searching in the filename lookup dictionary.<br>
---* If the original filename wasn't in the dictionary, it will return the original filename.
---@param filename string
---@return string
function FileUtils:getNewFilename (filename) end
---* List all files in a directory.<br>
---* param dirPath The path of the directory, it could be a relative or an absolute path.<br>
---* return File paths in a string vector
---@param dirPath string
---@return array_table
function FileUtils:listFiles (dirPath) end
---* Converts the contents of a file to a ValueMap.<br>
---* param filename The filename of the file to gets content.<br>
---* return ValueMap of the file contents.<br>
---* note This method is used internally.
---@param filename string
---@return map_table
function FileUtils:getValueMapFromFile (filename) end
---@overload fun(string:string,function:function):self
---@overload fun(string:string):self
---@param filepath string
---@param callback function
---@return self
function FileUtils:getFileSize (filepath,callback) end
---* Converts the contents of a file to a ValueMap.<br>
---* This method is used internally.
---@param filedata char
---@param filesize int
---@return map_table
function FileUtils:getValueMapFromData (filedata,filesize) end
---@overload fun(string:string,function:function):self
---@overload fun(string:string):self
---@param dirPath string
---@param callback function
---@return self
function FileUtils:removeDirectory (dirPath,callback) end
---* Sets the array of search paths.<br>
---* You can use this array to modify the search path of the resources.<br>
---* If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.<br>
---* note This method could access relative path and absolute path.<br>
---* If the relative path was passed to the vector, FileUtils will add the default resource directory before the relative path.<br>
---* For instance:<br>
---* On Android, the default resource root path is "assets/".<br>
---* If "/mnt/sdcard/" and "resources-large" were set to the search paths vector,<br>
---* "resources-large" will be converted to "assets/resources-large" since it was a relative path.<br>
---* param searchPaths The array contains search paths.<br>
---* see fullPathForFilename(const char*)<br>
---* since v2.1<br>
---* In js:var setSearchPaths(var jsval);<br>
---* lua NA
---@param searchPaths array_table
---@return self
function FileUtils:setSearchPaths (searchPaths) end
---@overload fun(string:string,string:string,function:function):self
---@overload fun(string:string,string:string):self
---@param dataStr string
---@param fullPath string
---@param callback function
---@return self
function FileUtils:writeStringToFile (dataStr,fullPath,callback) end
---* Sets the array that contains the search order of the resources.<br>
---* param searchResolutionsOrder The source array that contains the search order of the resources.<br>
---* see getSearchResolutionsOrder(), fullPathForFilename(const char*).<br>
---* since v2.1<br>
---* In js:var setSearchResolutionsOrder(var jsval)<br>
---* lua NA
---@param searchResolutionsOrder array_table
---@return self
function FileUtils:setSearchResolutionsOrder (searchResolutionsOrder) end
---* Append search order of the resources.<br>
---* see setSearchResolutionsOrder(), fullPathForFilename().<br>
---* since v2.1
---@param order string
---@param front boolean
---@return self
function FileUtils:addSearchResolutionsOrder (order,front) end
---* Add search path.<br>
---* since v2.1
---@param path string
---@param front boolean
---@return self
function FileUtils:addSearchPath (path,front) end
---@overload fun(array_table:array_table,string:string,function:function):self
---@overload fun(array_table:array_table,string:string):self
---@param vecData array_table
---@param fullPath string
---@param callback function
---@return self
function FileUtils:writeValueVectorToFile (vecData,fullPath,callback) end
---@overload fun(string:string,function:function):self
---@overload fun(string:string):self
---@param filename string
---@param callback function
---@return self
function FileUtils:isFileExist (filename,callback) end
---* Purges full path caches.
---@return self
function FileUtils:purgeCachedEntries () end
---* Gets full path from a file name and the path of the relative file.<br>
---* param filename The file name.<br>
---* param relativeFile The path of the relative file.<br>
---* return The full path.<br>
---* e.g. filename: hello.png, pszRelativeFile: /User/path1/path2/hello.plist<br>
---* Return: /User/path1/path2/hello.pvr (If there a a key(hello.png)-value(hello.pvr) in FilenameLookup dictionary. )
---@param filename string
---@param relativeFile string
---@return string
function FileUtils:fullPathFromRelativeFile (filename,relativeFile) end
---* Windows fopen can't support UTF-8 filename<br>
---* Need convert all parameters fopen and other 3rd-party libs<br>
---* param filenameUtf8 std::string name file for conversion from utf-8<br>
---* return std::string ansi filename in current locale
---@param filenameUtf8 string
---@return string
function FileUtils:getSuitableFOpen (filenameUtf8) end
---@overload fun(map_table:map_table,string:string,function:function):self
---@overload fun(map_table:map_table,string:string):self
---@param dict map_table
---@param fullPath string
---@param callback function
---@return self
function FileUtils:writeValueMapToFile (dict,fullPath,callback) end
---* Gets filename extension is a suffix (separated from the base filename by a dot) in lower case.<br>
---* Examples of filename extensions are .png, .jpeg, .exe, .dmg and .txt.<br>
---* param filePath The path of the file, it could be a relative or absolute path.<br>
---* return suffix for filename in lower case or empty if a dot not found.
---@param filePath string
---@return string
function FileUtils:getFileExtension (filePath) end
---* Sets writable path.
---@param writablePath string
---@return self
function FileUtils:setWritablePath (writablePath) end
---* Sets whether to pop-up a message box when failed to load an image.
---@param notify boolean
---@return self
function FileUtils:setPopupNotify (notify) end
---@overload fun(string:string,function:function):self
---@overload fun(string:string):self
---@param fullPath string
---@param callback function
---@return self
function FileUtils:isDirectoryExist (fullPath,callback) end
---* Set default resource root path.
---@param path string
---@return self
function FileUtils:setDefaultResourceRootPath (path) end
---* Gets the array that contains the search order of the resources.<br>
---* see setSearchResolutionsOrder(const std::vector<std::string>&), fullPathForFilename(const char*).<br>
---* since v2.1<br>
---* lua NA
---@return array_table
function FileUtils:getSearchResolutionsOrder () end
---@overload fun(string:string,function:function):self
---@overload fun(string:string):self
---@param dirPath string
---@param callback function
---@return self
function FileUtils:createDirectory (dirPath,callback) end
---* List all files in a directory async, off of the main cocos thread.<br>
---* param dirPath The path of the directory, it could be a relative or an absolute path.<br>
---* param callback The callback to be called once the list operation is complete. Will be called on the main cocos thread.<br>
---* js NA<br>
---* lua NA
---@param dirPath string
---@param callback function
---@return self
function FileUtils:listFilesAsync (dirPath,callback) end
---* Gets the writable path.<br>
---* return The path that can be write/read a file in
---@return string
function FileUtils:getWritablePath () end
---* List all files recursively in a directory.<br>
---* param dirPath The path of the directory, it could be a relative or an absolute path.<br>
---* return File paths in a string vector
---@param dirPath string
---@param files array_table
---@return self
function FileUtils:listFilesRecursively (dirPath,files) end
---* Destroys the instance of FileUtils.
---@return self
function FileUtils:destroyInstance () end
---* Gets the instance of FileUtils.
---@return self
function FileUtils:getInstance () end
|