dir_access.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /**************************************************************************/
  2. /* dir_access.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "dir_access.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/io/file_access.h"
  33. #include "core/os/os.h"
  34. #include "core/os/time.h"
  35. #include "core/templates/local_vector.h"
  36. String DirAccess::_get_root_path() const {
  37. switch (_access_type) {
  38. case ACCESS_RESOURCES:
  39. return ProjectSettings::get_singleton()->get_resource_path();
  40. case ACCESS_USERDATA:
  41. return OS::get_singleton()->get_user_data_dir();
  42. default:
  43. return "";
  44. }
  45. }
  46. String DirAccess::_get_root_string() const {
  47. switch (_access_type) {
  48. case ACCESS_RESOURCES:
  49. return "res://";
  50. case ACCESS_USERDATA:
  51. return "user://";
  52. default:
  53. return "";
  54. }
  55. }
  56. int DirAccess::get_current_drive() {
  57. String path = get_current_dir().to_lower();
  58. for (int i = 0; i < get_drive_count(); i++) {
  59. String d = get_drive(i).to_lower();
  60. if (path.begins_with(d)) {
  61. return i;
  62. }
  63. }
  64. return 0;
  65. }
  66. bool DirAccess::drives_are_shortcuts() {
  67. return false;
  68. }
  69. static Error _erase_recursive(DirAccess *da) {
  70. List<String> dirs;
  71. List<String> files;
  72. da->list_dir_begin();
  73. String n = da->get_next();
  74. while (!n.is_empty()) {
  75. if (n != "." && n != "..") {
  76. if (da->current_is_dir() && !da->is_link(n)) {
  77. dirs.push_back(n);
  78. } else {
  79. files.push_back(n);
  80. }
  81. }
  82. n = da->get_next();
  83. }
  84. da->list_dir_end();
  85. for (const String &E : dirs) {
  86. Error err = da->change_dir(E);
  87. if (err == OK) {
  88. err = _erase_recursive(da);
  89. if (err) {
  90. da->change_dir("..");
  91. return err;
  92. }
  93. err = da->change_dir("..");
  94. if (err) {
  95. return err;
  96. }
  97. err = da->remove(da->get_current_dir().path_join(E));
  98. if (err) {
  99. return err;
  100. }
  101. } else {
  102. return err;
  103. }
  104. }
  105. for (const String &E : files) {
  106. Error err = da->remove(da->get_current_dir().path_join(E));
  107. if (err) {
  108. return err;
  109. }
  110. }
  111. return OK;
  112. }
  113. Error DirAccess::erase_contents_recursive() {
  114. return _erase_recursive(this);
  115. }
  116. Error DirAccess::make_dir_recursive(const String &p_dir) {
  117. if (p_dir.length() < 1) {
  118. return OK;
  119. }
  120. String full_dir;
  121. if (p_dir.is_relative_path()) {
  122. //append current
  123. full_dir = get_current_dir().path_join(p_dir);
  124. } else {
  125. full_dir = p_dir;
  126. }
  127. full_dir = full_dir.replace_char('\\', '/');
  128. String base;
  129. if (full_dir.begins_with("res://")) {
  130. base = "res://";
  131. } else if (full_dir.begins_with("user://")) {
  132. base = "user://";
  133. } else if (full_dir.is_network_share_path()) {
  134. int pos = full_dir.find_char('/', 2);
  135. ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
  136. pos = full_dir.find_char('/', pos + 1);
  137. ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
  138. base = full_dir.substr(0, pos + 1);
  139. } else if (full_dir.begins_with("/")) {
  140. base = "/";
  141. } else if (full_dir.contains(":/")) {
  142. base = full_dir.substr(0, full_dir.find(":/") + 2);
  143. } else {
  144. ERR_FAIL_V(ERR_INVALID_PARAMETER);
  145. }
  146. full_dir = full_dir.replace_first(base, "").simplify_path();
  147. Vector<String> subdirs = full_dir.split("/");
  148. String curpath = base;
  149. for (int i = 0; i < subdirs.size(); i++) {
  150. curpath = curpath.path_join(subdirs[i]);
  151. Error err = make_dir(curpath);
  152. if (err != OK && err != ERR_ALREADY_EXISTS) {
  153. ERR_FAIL_V_MSG(err, vformat("Could not create directory: '%s'.", curpath));
  154. }
  155. }
  156. return OK;
  157. }
  158. DirAccess::AccessType DirAccess::get_access_type() const {
  159. return _access_type;
  160. }
  161. String DirAccess::fix_path(const String &p_path) const {
  162. switch (_access_type) {
  163. case ACCESS_RESOURCES: {
  164. if (ProjectSettings::get_singleton()) {
  165. if (p_path.begins_with("res://")) {
  166. String resource_path = ProjectSettings::get_singleton()->get_resource_path();
  167. if (!resource_path.is_empty()) {
  168. return p_path.replace_first("res:/", resource_path);
  169. }
  170. return p_path.replace_first("res://", "");
  171. }
  172. }
  173. } break;
  174. case ACCESS_USERDATA: {
  175. if (p_path.begins_with("user://")) {
  176. String data_dir = OS::get_singleton()->get_user_data_dir();
  177. if (!data_dir.is_empty()) {
  178. return p_path.replace_first("user:/", data_dir);
  179. }
  180. return p_path.replace_first("user://", "");
  181. }
  182. } break;
  183. case ACCESS_FILESYSTEM: {
  184. return p_path;
  185. } break;
  186. case ACCESS_MAX:
  187. break; // Can't happen, but silences warning
  188. }
  189. return p_path;
  190. }
  191. DirAccess::CreateFunc DirAccess::create_func[ACCESS_MAX] = { nullptr, nullptr, nullptr };
  192. Ref<DirAccess> DirAccess::create_for_path(const String &p_path) {
  193. Ref<DirAccess> da;
  194. if (p_path.begins_with("res://")) {
  195. da = create(ACCESS_RESOURCES);
  196. } else if (p_path.begins_with("user://")) {
  197. da = create(ACCESS_USERDATA);
  198. } else {
  199. da = create(ACCESS_FILESYSTEM);
  200. }
  201. return da;
  202. }
  203. Ref<DirAccess> DirAccess::open(const String &p_path, Error *r_error) {
  204. Ref<DirAccess> da = create_for_path(p_path);
  205. ERR_FAIL_COND_V_MSG(da.is_null(), nullptr, vformat("Cannot create DirAccess for path '%s'.", p_path));
  206. Error err = da->change_dir(p_path);
  207. if (r_error) {
  208. *r_error = err;
  209. }
  210. if (err != OK) {
  211. return nullptr;
  212. }
  213. return da;
  214. }
  215. Ref<DirAccess> DirAccess::_open(const String &p_path) {
  216. Error err = OK;
  217. Ref<DirAccess> da = open(p_path, &err);
  218. last_dir_open_error = err;
  219. if (err) {
  220. return Ref<DirAccess>();
  221. }
  222. return da;
  223. }
  224. int DirAccess::_get_drive_count() {
  225. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  226. return d->get_drive_count();
  227. }
  228. String DirAccess::get_drive_name(int p_idx) {
  229. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  230. return d->get_drive(p_idx);
  231. }
  232. Error DirAccess::make_dir_absolute(const String &p_dir) {
  233. Ref<DirAccess> d = DirAccess::create_for_path(p_dir);
  234. return d->make_dir(p_dir);
  235. }
  236. Error DirAccess::make_dir_recursive_absolute(const String &p_dir) {
  237. Ref<DirAccess> d = DirAccess::create_for_path(p_dir);
  238. return d->make_dir_recursive(p_dir);
  239. }
  240. bool DirAccess::dir_exists_absolute(const String &p_dir) {
  241. Ref<DirAccess> d = DirAccess::create_for_path(p_dir);
  242. return d->dir_exists(p_dir);
  243. }
  244. Error DirAccess::copy_absolute(const String &p_from, const String &p_to, int p_chmod_flags) {
  245. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  246. // Support copying from res:// to user:// etc.
  247. String from = ProjectSettings::get_singleton()->globalize_path(p_from);
  248. String to = ProjectSettings::get_singleton()->globalize_path(p_to);
  249. return d->copy(from, to, p_chmod_flags);
  250. }
  251. Error DirAccess::rename_absolute(const String &p_from, const String &p_to) {
  252. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  253. String from = ProjectSettings::get_singleton()->globalize_path(p_from);
  254. String to = ProjectSettings::get_singleton()->globalize_path(p_to);
  255. return d->rename(from, to);
  256. }
  257. Error DirAccess::remove_absolute(const String &p_path) {
  258. Ref<DirAccess> d = DirAccess::create_for_path(p_path);
  259. return d->remove(p_path);
  260. }
  261. Ref<DirAccess> DirAccess::create(AccessType p_access) {
  262. Ref<DirAccess> da = create_func[p_access] ? create_func[p_access]() : nullptr;
  263. if (da.is_valid()) {
  264. da->_access_type = p_access;
  265. // for ACCESS_RESOURCES and ACCESS_FILESYSTEM, current_dir already defaults to where game was started
  266. // in case current directory is force changed elsewhere for ACCESS_RESOURCES
  267. if (p_access == ACCESS_RESOURCES) {
  268. da->change_dir("res://");
  269. } else if (p_access == ACCESS_USERDATA) {
  270. da->change_dir("user://");
  271. }
  272. }
  273. return da;
  274. }
  275. Ref<DirAccess> DirAccess::create_temp(const String &p_prefix, bool p_keep, Error *r_error) {
  276. const String ERROR_COMMON_PREFIX = "Error while creating temporary directory";
  277. if (!p_prefix.is_valid_filename()) {
  278. *r_error = ERR_FILE_BAD_PATH;
  279. ERR_FAIL_V_MSG(Ref<FileAccess>(), vformat(R"(%s: "%s" is not a valid prefix.)", ERROR_COMMON_PREFIX, p_prefix));
  280. }
  281. Ref<DirAccess> dir_access = DirAccess::open(OS::get_singleton()->get_temp_path());
  282. uint32_t suffix_i = 0;
  283. String path;
  284. while (true) {
  285. String datetime = Time::get_singleton()->get_datetime_string_from_system().remove_chars("-T:");
  286. datetime += itos(Time::get_singleton()->get_ticks_usec());
  287. String suffix = datetime + (suffix_i > 0 ? itos(suffix_i) : "");
  288. path = (p_prefix.is_empty() ? "" : p_prefix + "-") + suffix;
  289. if (!path.is_valid_filename()) {
  290. *r_error = ERR_FILE_BAD_PATH;
  291. return Ref<DirAccess>();
  292. }
  293. if (!DirAccess::exists(path)) {
  294. break;
  295. }
  296. suffix_i += 1;
  297. }
  298. Error err = dir_access->make_dir(path);
  299. if (err != OK) {
  300. *r_error = err;
  301. ERR_FAIL_V_MSG(Ref<FileAccess>(), vformat(R"(%s: "%s" couldn't create directory "%s".)", ERROR_COMMON_PREFIX, path));
  302. }
  303. err = dir_access->change_dir(path);
  304. if (err != OK) {
  305. *r_error = err;
  306. return Ref<DirAccess>();
  307. }
  308. dir_access->_is_temp = true;
  309. dir_access->_temp_keep_after_free = p_keep;
  310. dir_access->_temp_path = dir_access->get_current_dir();
  311. *r_error = OK;
  312. return dir_access;
  313. }
  314. Ref<DirAccess> DirAccess::_create_temp(const String &p_prefix, bool p_keep) {
  315. return create_temp(p_prefix, p_keep, &last_dir_open_error);
  316. }
  317. void DirAccess::_delete_temp() {
  318. if (!_is_temp || _temp_keep_after_free) {
  319. return;
  320. }
  321. if (!DirAccess::exists(_temp_path)) {
  322. return;
  323. }
  324. Error err;
  325. {
  326. Ref<DirAccess> dir_access = DirAccess::open(_temp_path, &err);
  327. if (err != OK) {
  328. return;
  329. }
  330. err = dir_access->erase_contents_recursive();
  331. if (err != OK) {
  332. return;
  333. }
  334. }
  335. DirAccess::remove_absolute(_temp_path);
  336. }
  337. Error DirAccess::get_open_error() {
  338. return last_dir_open_error;
  339. }
  340. String DirAccess::get_full_path(const String &p_path, AccessType p_access) {
  341. Ref<DirAccess> d = DirAccess::create(p_access);
  342. if (d.is_null()) {
  343. return p_path;
  344. }
  345. d->change_dir(p_path);
  346. String full = d->get_current_dir();
  347. return full;
  348. }
  349. Error DirAccess::copy(const String &p_from, const String &p_to, int p_chmod_flags) {
  350. ERR_FAIL_COND_V_MSG(p_from == p_to, ERR_INVALID_PARAMETER, "Source and destination path are equal.");
  351. //printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data());
  352. Error err;
  353. {
  354. Ref<FileAccess> fsrc = FileAccess::open(p_from, FileAccess::READ, &err);
  355. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Failed to open '%s'.", p_from));
  356. Ref<FileAccess> fdst = FileAccess::open(p_to, FileAccess::WRITE, &err);
  357. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Failed to open '%s'.", p_to));
  358. const size_t copy_buffer_limit = 65536; // 64 KB
  359. fsrc->seek_end(0);
  360. uint64_t size = fsrc->get_position();
  361. fsrc->seek(0);
  362. err = OK;
  363. size_t buffer_size = MIN(size * sizeof(uint8_t), copy_buffer_limit);
  364. LocalVector<uint8_t> buffer;
  365. buffer.resize(buffer_size);
  366. while (size > 0) {
  367. if (fsrc->get_error() != OK) {
  368. err = fsrc->get_error();
  369. break;
  370. }
  371. if (fdst->get_error() != OK) {
  372. err = fdst->get_error();
  373. break;
  374. }
  375. int bytes_read = fsrc->get_buffer(buffer.ptr(), buffer_size);
  376. if (bytes_read <= 0) {
  377. err = FAILED;
  378. break;
  379. }
  380. fdst->store_buffer(buffer.ptr(), bytes_read);
  381. size -= bytes_read;
  382. }
  383. }
  384. if (err == OK && p_chmod_flags != -1) {
  385. err = FileAccess::set_unix_permissions(p_to, p_chmod_flags);
  386. // If running on a platform with no chmod support (i.e., Windows), don't fail
  387. if (err == ERR_UNAVAILABLE) {
  388. err = OK;
  389. }
  390. }
  391. return err;
  392. }
  393. // Changes dir for the current scope, returning back to the original dir
  394. // when scope exits
  395. class DirChanger {
  396. DirAccess *da;
  397. String original_dir;
  398. public:
  399. DirChanger(DirAccess *p_da, const String &p_dir) :
  400. da(p_da),
  401. original_dir(p_da->get_current_dir()) {
  402. p_da->change_dir(p_dir);
  403. }
  404. ~DirChanger() {
  405. da->change_dir(original_dir);
  406. }
  407. };
  408. Error DirAccess::_copy_dir(Ref<DirAccess> &p_target_da, const String &p_to, int p_chmod_flags, bool p_copy_links) {
  409. List<String> dirs;
  410. String curdir = get_current_dir();
  411. list_dir_begin();
  412. String n = get_next();
  413. while (!n.is_empty()) {
  414. if (n != "." && n != "..") {
  415. if (p_copy_links && is_link(get_current_dir().path_join(n))) {
  416. create_link(read_link(get_current_dir().path_join(n)), p_to + n);
  417. } else if (current_is_dir()) {
  418. dirs.push_back(n);
  419. } else {
  420. const String &rel_path = n;
  421. if (!n.is_relative_path()) {
  422. list_dir_end();
  423. return ERR_BUG;
  424. }
  425. Error err = copy(get_current_dir().path_join(n), p_to + rel_path, p_chmod_flags);
  426. if (err) {
  427. list_dir_end();
  428. return err;
  429. }
  430. }
  431. }
  432. n = get_next();
  433. }
  434. list_dir_end();
  435. for (const String &rel_path : dirs) {
  436. String target_dir = p_to + rel_path;
  437. if (!p_target_da->dir_exists(target_dir)) {
  438. Error err = p_target_da->make_dir(target_dir);
  439. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Cannot create directory '%s'.", target_dir));
  440. }
  441. Error err = change_dir(rel_path);
  442. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Cannot change current directory to '%s'.", rel_path));
  443. err = _copy_dir(p_target_da, p_to + rel_path + "/", p_chmod_flags, p_copy_links);
  444. if (err) {
  445. change_dir("..");
  446. ERR_FAIL_V_MSG(err, "Failed to copy recursively.");
  447. }
  448. err = change_dir("..");
  449. ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to go back.");
  450. }
  451. return OK;
  452. }
  453. Error DirAccess::copy_dir(const String &p_from, String p_to, int p_chmod_flags, bool p_copy_links) {
  454. ERR_FAIL_COND_V_MSG(!dir_exists(p_from), ERR_FILE_NOT_FOUND, "Source directory doesn't exist.");
  455. Ref<DirAccess> target_da = DirAccess::create_for_path(p_to);
  456. ERR_FAIL_COND_V_MSG(target_da.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", p_to));
  457. if (!target_da->dir_exists(p_to)) {
  458. Error err = target_da->make_dir_recursive(p_to);
  459. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Cannot create directory '%s'.", p_to));
  460. }
  461. if (!p_to.ends_with("/")) {
  462. p_to = p_to + "/";
  463. }
  464. DirChanger dir_changer(this, p_from);
  465. Error err = _copy_dir(target_da, p_to, p_chmod_flags, p_copy_links);
  466. return err;
  467. }
  468. bool DirAccess::exists(const String &p_dir) {
  469. Ref<DirAccess> da = DirAccess::create_for_path(p_dir);
  470. return da->change_dir(p_dir) == OK;
  471. }
  472. PackedStringArray DirAccess::get_files() {
  473. return _get_contents(false);
  474. }
  475. PackedStringArray DirAccess::get_files_at(const String &p_path) {
  476. Ref<DirAccess> da = DirAccess::open(p_path);
  477. ERR_FAIL_COND_V_MSG(da.is_null(), PackedStringArray(), vformat("Couldn't open directory at path \"%s\".", p_path));
  478. return da->get_files();
  479. }
  480. PackedStringArray DirAccess::get_directories() {
  481. return _get_contents(true);
  482. }
  483. PackedStringArray DirAccess::get_directories_at(const String &p_path) {
  484. Ref<DirAccess> da = DirAccess::open(p_path);
  485. ERR_FAIL_COND_V_MSG(da.is_null(), PackedStringArray(), vformat("Couldn't open directory at path \"%s\".", p_path));
  486. return da->get_directories();
  487. }
  488. PackedStringArray DirAccess::_get_contents(bool p_directories) {
  489. PackedStringArray ret;
  490. list_dir_begin();
  491. String s = _get_next();
  492. while (!s.is_empty()) {
  493. if (current_is_dir() == p_directories) {
  494. ret.append(s);
  495. }
  496. s = _get_next();
  497. }
  498. ret.sort();
  499. return ret;
  500. }
  501. String DirAccess::_get_next() {
  502. String next = get_next();
  503. while (!next.is_empty() && ((!include_navigational && (next == "." || next == "..")) || (!include_hidden && current_is_hidden()))) {
  504. next = get_next();
  505. }
  506. return next;
  507. }
  508. void DirAccess::set_include_navigational(bool p_enable) {
  509. include_navigational = p_enable;
  510. }
  511. bool DirAccess::get_include_navigational() const {
  512. return include_navigational;
  513. }
  514. void DirAccess::set_include_hidden(bool p_enable) {
  515. include_hidden = p_enable;
  516. }
  517. bool DirAccess::get_include_hidden() const {
  518. return include_hidden;
  519. }
  520. bool DirAccess::is_case_sensitive(const String &p_path) const {
  521. return true;
  522. }
  523. bool DirAccess::is_equivalent(const String &p_path_a, const String &p_path_b) const {
  524. return p_path_a == p_path_b;
  525. }
  526. void DirAccess::_bind_methods() {
  527. ClassDB::bind_static_method("DirAccess", D_METHOD("open", "path"), &DirAccess::_open);
  528. ClassDB::bind_static_method("DirAccess", D_METHOD("get_open_error"), &DirAccess::get_open_error);
  529. ClassDB::bind_static_method("DirAccess", D_METHOD("create_temp", "prefix", "keep"), &DirAccess::_create_temp, DEFVAL(""), DEFVAL(false));
  530. ClassDB::bind_method(D_METHOD("list_dir_begin"), &DirAccess::list_dir_begin);
  531. ClassDB::bind_method(D_METHOD("get_next"), &DirAccess::_get_next);
  532. ClassDB::bind_method(D_METHOD("current_is_dir"), &DirAccess::current_is_dir);
  533. ClassDB::bind_method(D_METHOD("list_dir_end"), &DirAccess::list_dir_end);
  534. ClassDB::bind_method(D_METHOD("get_files"), &DirAccess::get_files);
  535. ClassDB::bind_static_method("DirAccess", D_METHOD("get_files_at", "path"), &DirAccess::get_files_at);
  536. ClassDB::bind_method(D_METHOD("get_directories"), &DirAccess::get_directories);
  537. ClassDB::bind_static_method("DirAccess", D_METHOD("get_directories_at", "path"), &DirAccess::get_directories_at);
  538. ClassDB::bind_static_method("DirAccess", D_METHOD("get_drive_count"), &DirAccess::_get_drive_count);
  539. ClassDB::bind_static_method("DirAccess", D_METHOD("get_drive_name", "idx"), &DirAccess::get_drive_name);
  540. ClassDB::bind_method(D_METHOD("get_current_drive"), &DirAccess::get_current_drive);
  541. ClassDB::bind_method(D_METHOD("change_dir", "to_dir"), &DirAccess::change_dir);
  542. ClassDB::bind_method(D_METHOD("get_current_dir", "include_drive"), &DirAccess::get_current_dir, DEFVAL(true));
  543. ClassDB::bind_method(D_METHOD("make_dir", "path"), &DirAccess::make_dir);
  544. ClassDB::bind_static_method("DirAccess", D_METHOD("make_dir_absolute", "path"), &DirAccess::make_dir_absolute);
  545. ClassDB::bind_method(D_METHOD("make_dir_recursive", "path"), &DirAccess::make_dir_recursive);
  546. ClassDB::bind_static_method("DirAccess", D_METHOD("make_dir_recursive_absolute", "path"), &DirAccess::make_dir_recursive_absolute);
  547. ClassDB::bind_method(D_METHOD("file_exists", "path"), &DirAccess::file_exists);
  548. ClassDB::bind_method(D_METHOD("dir_exists", "path"), &DirAccess::dir_exists);
  549. ClassDB::bind_static_method("DirAccess", D_METHOD("dir_exists_absolute", "path"), &DirAccess::dir_exists_absolute);
  550. ClassDB::bind_method(D_METHOD("get_space_left"), &DirAccess::get_space_left);
  551. ClassDB::bind_method(D_METHOD("copy", "from", "to", "chmod_flags"), &DirAccess::copy, DEFVAL(-1));
  552. ClassDB::bind_static_method("DirAccess", D_METHOD("copy_absolute", "from", "to", "chmod_flags"), &DirAccess::copy_absolute, DEFVAL(-1));
  553. ClassDB::bind_method(D_METHOD("rename", "from", "to"), &DirAccess::rename);
  554. ClassDB::bind_static_method("DirAccess", D_METHOD("rename_absolute", "from", "to"), &DirAccess::rename_absolute);
  555. ClassDB::bind_method(D_METHOD("remove", "path"), &DirAccess::remove);
  556. ClassDB::bind_static_method("DirAccess", D_METHOD("remove_absolute", "path"), &DirAccess::remove_absolute);
  557. ClassDB::bind_method(D_METHOD("is_link", "path"), &DirAccess::is_link);
  558. ClassDB::bind_method(D_METHOD("read_link", "path"), &DirAccess::read_link);
  559. ClassDB::bind_method(D_METHOD("create_link", "source", "target"), &DirAccess::create_link);
  560. ClassDB::bind_method(D_METHOD("is_bundle", "path"), &DirAccess::is_bundle);
  561. ClassDB::bind_method(D_METHOD("set_include_navigational", "enable"), &DirAccess::set_include_navigational);
  562. ClassDB::bind_method(D_METHOD("get_include_navigational"), &DirAccess::get_include_navigational);
  563. ClassDB::bind_method(D_METHOD("set_include_hidden", "enable"), &DirAccess::set_include_hidden);
  564. ClassDB::bind_method(D_METHOD("get_include_hidden"), &DirAccess::get_include_hidden);
  565. ClassDB::bind_method(D_METHOD("get_filesystem_type"), &DirAccess::get_filesystem_type);
  566. ClassDB::bind_method(D_METHOD("is_case_sensitive", "path"), &DirAccess::is_case_sensitive);
  567. ClassDB::bind_method(D_METHOD("is_equivalent", "path_a", "path_b"), &DirAccess::is_equivalent);
  568. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "include_navigational"), "set_include_navigational", "get_include_navigational");
  569. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "include_hidden"), "set_include_hidden", "get_include_hidden");
  570. }
  571. DirAccess::~DirAccess() {
  572. _delete_temp();
  573. }