@@ -34,7 +34,6 @@ THE SOFTWARE.
34
34
// #include "base/ccUtils.h"
35
35
36
36
#include " tinyxml2/tinyxml2.h"
37
- #include " tinydir/tinydir.h"
38
37
#ifdef MINIZIP_FROM_SYSTEM
39
38
#include < minizip/unzip.h>
40
39
#else // from our embedded sources
@@ -1167,65 +1166,6 @@ void FileUtils::getFileSize(const std::string &filepath, std::function<void(long
1167
1166
}, std::move (callback));
1168
1167
}
1169
1168
1170
- std::vector<std::string> FileUtils::listFiles (const std::string& dirPath) const
1171
- {
1172
- std::string fullpath = fullPathForFilename (dirPath);
1173
- std::vector<std::string> files;
1174
- if (isDirectoryExist (fullpath))
1175
- {
1176
- tinydir_dir dir;
1177
- #ifdef UNICODE
1178
- unsigned int length = MultiByteToWideChar (CP_UTF8, 0 , &fullpath[0 ], (int )fullpath.size (), NULL , 0 );
1179
- if (length != fullpath.size ())
1180
- {
1181
- return files;
1182
- }
1183
- std::wstring fullpathstr (length, 0 );
1184
- MultiByteToWideChar (CP_UTF8, 0 , &fullpath[0 ], (int )fullpath.size (), &fullpathstr[0 ], length);
1185
- #else
1186
- std::string fullpathstr = fullpath;
1187
- #endif
1188
- if (tinydir_open (&dir, &fullpathstr[0 ]) != -1 )
1189
- {
1190
- while (dir.has_next )
1191
- {
1192
- tinydir_file file;
1193
- if (tinydir_readfile (&dir, &file) == -1 )
1194
- {
1195
- // Error getting file
1196
- break ;
1197
- }
1198
-
1199
- #ifdef UNICODE
1200
- std::wstring path = file.path ;
1201
- length = WideCharToMultiByte (CP_UTF8, 0 , &path[0 ], (int )path.size (), NULL , 0 , NULL , NULL );
1202
- std::string filepath;
1203
- if (length > 0 )
1204
- {
1205
- filepath.resize (length);
1206
- WideCharToMultiByte (CP_UTF8, 0 , &path[0 ], (int )path.size (), &filepath[0 ], length, NULL , NULL );
1207
- }
1208
- #else
1209
- std::string filepath = file.path ;
1210
- #endif
1211
- if (file.is_dir )
1212
- {
1213
- filepath.append (" /" );
1214
- }
1215
- files.push_back (filepath);
1216
-
1217
- if (tinydir_next (&dir) == -1 )
1218
- {
1219
- // Error getting next file
1220
- break ;
1221
- }
1222
- }
1223
- }
1224
- tinydir_close (&dir);
1225
- }
1226
- return files;
1227
- }
1228
-
1229
1169
void FileUtils::listFilesAsync (const std::string& dirPath, std::function<void (std::vector<std::string>)> callback) const
1230
1170
{
1231
1171
auto fullPath = fullPathForFilename (dirPath);
@@ -1234,71 +1174,6 @@ void FileUtils::listFilesAsync(const std::string& dirPath, std::function<void(st
1234
1174
}, std::move (callback));
1235
1175
}
1236
1176
1237
- void FileUtils::listFilesRecursively (const std::string& dirPath, std::vector<std::string> *files) const
1238
- {
1239
- std::string fullpath = fullPathForFilename (dirPath);
1240
- if (isDirectoryExist (fullpath))
1241
- {
1242
- tinydir_dir dir;
1243
- #ifdef UNICODE
1244
- unsigned int length = MultiByteToWideChar (CP_UTF8, 0 , &fullpath[0 ], (int )fullpath.size (), NULL , 0 );
1245
- if (length != fullpath.size ())
1246
- {
1247
- return ;
1248
- }
1249
- std::wstring fullpathstr (length, 0 );
1250
- MultiByteToWideChar (CP_UTF8, 0 , &fullpath[0 ], (int )fullpath.size (), &fullpathstr[0 ], length);
1251
- #else
1252
- std::string fullpathstr = fullpath;
1253
- #endif
1254
- if (tinydir_open (&dir, &fullpathstr[0 ]) != -1 )
1255
- {
1256
- while (dir.has_next )
1257
- {
1258
- tinydir_file file;
1259
- if (tinydir_readfile (&dir, &file) == -1 )
1260
- {
1261
- // Error getting file
1262
- break ;
1263
- }
1264
-
1265
- #ifdef UNICODE
1266
- std::wstring path = file.path ;
1267
- length = WideCharToMultiByte (CP_UTF8, 0 , &path[0 ], (int )path.size (), NULL , 0 , NULL , NULL );
1268
- std::string filepath;
1269
- if (length > 0 )
1270
- {
1271
- filepath.resize (length);
1272
- WideCharToMultiByte (CP_UTF8, 0 , &path[0 ], (int )path.size (), &filepath[0 ], length, NULL , NULL );
1273
- }
1274
- #else
1275
- std::string filepath = file.path ;
1276
- #endif
1277
- if (file.name [0 ] != ' .' )
1278
- {
1279
- if (file.is_dir )
1280
- {
1281
- filepath.append (" /" );
1282
- files->push_back (filepath);
1283
- listFilesRecursively (filepath, files);
1284
- }
1285
- else
1286
- {
1287
- files->push_back (filepath);
1288
- }
1289
- }
1290
-
1291
- if (tinydir_next (&dir) == -1 )
1292
- {
1293
- // Error getting next file
1294
- break ;
1295
- }
1296
- }
1297
- }
1298
- tinydir_close (&dir);
1299
- }
1300
- }
1301
-
1302
1177
void FileUtils::listFilesRecursivelyAsync (const std::string& dirPath, std::function<void (std::vector<std::string>)> callback) const
1303
1178
{
1304
1179
auto fullPath = fullPathForFilename (dirPath);
@@ -1359,7 +1234,20 @@ long FileUtils::getFileSize(const std::string &filepath)
1359
1234
return 0 ;
1360
1235
}
1361
1236
1237
+ std::vector<std::string> FileUtils::listFiles (const std::string& dirPath) const
1238
+ {
1239
+ CCASSERT (false , " FileUtils not support listFiles" );
1240
+ return std::vector<std::string>();
1241
+ }
1242
+
1243
+ void FileUtils::listFilesRecursively (const std::string& dirPath, std::vector<std::string> *files) const
1244
+ {
1245
+ CCASSERT (false , " FileUtils not support listFilesRecursively" );
1246
+ return ;
1247
+ }
1248
+
1362
1249
#else
1250
+ #include " tinydir/tinydir.h"
1363
1251
// default implements for unix like os
1364
1252
#include < sys/types.h>
1365
1253
#include < errno.h>
@@ -1491,7 +1379,6 @@ std::string FileUtils::getSuitableFOpen(const std::string& filenameUtf8) const
1491
1379
return filenameUtf8;
1492
1380
}
1493
1381
1494
-
1495
1382
long FileUtils::getFileSize (const std::string &filepath)
1496
1383
{
1497
1384
CCASSERT (!filepath.empty (), " Invalid path" );
@@ -1519,6 +1406,92 @@ long FileUtils::getFileSize(const std::string &filepath)
1519
1406
return (long )(info.st_size );
1520
1407
}
1521
1408
}
1409
+
1410
+ std::vector<std::string> FileUtils::listFiles (const std::string& dirPath) const
1411
+ {
1412
+ std::vector<std::string> files;
1413
+ std::string fullpath = fullPathForFilename (dirPath);
1414
+ if (isDirectoryExist (fullpath))
1415
+ {
1416
+ tinydir_dir dir;
1417
+ std::string fullpathstr = fullpath;
1418
+
1419
+ if (tinydir_open (&dir, &fullpathstr[0 ]) != -1 )
1420
+ {
1421
+ while (dir.has_next )
1422
+ {
1423
+ tinydir_file file;
1424
+ if (tinydir_readfile (&dir, &file) == -1 )
1425
+ {
1426
+ // Error getting file
1427
+ break ;
1428
+ }
1429
+ std::string filepath = file.path ;
1430
+
1431
+ if (file.is_dir )
1432
+ {
1433
+ filepath.append (" /" );
1434
+ }
1435
+ files.push_back (filepath);
1436
+
1437
+ if (tinydir_next (&dir) == -1 )
1438
+ {
1439
+ // Error getting next file
1440
+ break ;
1441
+ }
1442
+ }
1443
+ }
1444
+ tinydir_close (&dir);
1445
+ }
1446
+ return files;
1447
+ }
1448
+
1449
+ void FileUtils::listFilesRecursively (const std::string& dirPath, std::vector<std::string> *files) const
1450
+ {
1451
+ std::string fullpath = fullPathForFilename (dirPath);
1452
+ if (isDirectoryExist (fullpath))
1453
+ {
1454
+ tinydir_dir dir;
1455
+ std::string fullpathstr = fullpath;
1456
+
1457
+ if (tinydir_open (&dir, &fullpathstr[0 ]) != -1 )
1458
+ {
1459
+ while (dir.has_next )
1460
+ {
1461
+ tinydir_file file;
1462
+ if (tinydir_readfile (&dir, &file) == -1 )
1463
+ {
1464
+ // Error getting file
1465
+ break ;
1466
+ }
1467
+ std::string fileName = file.name ;
1468
+
1469
+ if (fileName != " ." && fileName != " .." )
1470
+ {
1471
+ std::string filepath = file.path ;
1472
+ if (file.is_dir )
1473
+ {
1474
+ filepath.append (" /" );
1475
+ files->push_back (filepath);
1476
+ listFilesRecursively (filepath, files);
1477
+ }
1478
+ else
1479
+ {
1480
+ files->push_back (filepath);
1481
+ }
1482
+ }
1483
+
1484
+ if (tinydir_next (&dir) == -1 )
1485
+ {
1486
+ // Error getting next file
1487
+ break ;
1488
+ }
1489
+ }
1490
+ }
1491
+ tinydir_close (&dir);
1492
+ }
1493
+ }
1494
+
1522
1495
#endif
1523
1496
1524
1497
// ////////////////////////////////////////////////////////////////////////
0 commit comments