dir_access_flash.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*************************************************/
  2. /* dir_access_psp.cpp */
  3. /*************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /*************************************************/
  7. /* Source code within this file is: */
  8. /* (c) 2007-2010 Juan Linietsky, Ariel Manzur */
  9. /* All Rights Reserved. */
  10. /*************************************************/
  11. #include "dir_access_flash.h"
  12. #include "print_string.h"
  13. DirAccess* DirAccessFlash::create_flash() {
  14. return memnew( DirAccessFlash );
  15. };
  16. void DirAccessFlash::make_default() {
  17. instance_func=create_flash;
  18. }
  19. bool DirAccessFlash::list_dir_begin() {
  20. list_dir_end();
  21. dir_stream = opendir(current_dir.utf8().get_data());
  22. if (!dir_stream)
  23. return true; //error!
  24. return false;
  25. };
  26. String DirAccessFlash::get_next() {
  27. if (!dir_stream)
  28. return "";
  29. dirent *entry;
  30. entry=readdir(dir_stream);
  31. if (entry==NULL) {
  32. list_dir_end();
  33. return "";
  34. }
  35. //typedef struct stat Stat;
  36. struct stat flags;
  37. String fname;
  38. if (fname.parse_utf8(entry->d_name))
  39. fname=entry->d_name; //no utf8, maybe latin?
  40. String f=current_dir+"/"+fname;
  41. if (stat(f.utf8().get_data(),&flags)==0) {
  42. if (S_ISDIR(flags.st_mode)) {
  43. _cisdir=true;
  44. } else {
  45. _cisdir=false;
  46. }
  47. } else {
  48. _cisdir=false;
  49. }
  50. return fname;
  51. };
  52. bool DirAccessFlash::current_is_dir() const {
  53. return _cisdir;
  54. };
  55. void DirAccessFlash::list_dir_end() {
  56. if (dir_stream)
  57. closedir(dir_stream);
  58. dir_stream=0;
  59. _cisdir=false;
  60. };
  61. int DirAccessFlash::get_drive_count() {
  62. return 1;
  63. };
  64. String DirAccessFlash::get_drive(int p_drive) {
  65. return "host0";
  66. };
  67. Error DirAccessFlash::change_dir(String p_dir) {
  68. if (p_dir==".")
  69. return OK;
  70. if (p_dir.is_rel_path())
  71. current_dir+="/"+p_dir;
  72. else
  73. current_dir=fix_path(p_dir);
  74. current_dir=current_dir.simplify_path();
  75. if (current_dir.length()>1 && current_dir.ends_with("/") && !current_dir.ends_with("//"))
  76. current_dir=current_dir.substr(0,current_dir.length()-1);
  77. return OK;
  78. };
  79. String DirAccessFlash::get_current_dir() {
  80. return current_dir;
  81. };
  82. uint64_t DirAccessFlash::get_modified_time(String p_file) {
  83. return 0;
  84. };
  85. Error DirAccessFlash::make_dir(String p_dir) {
  86. return ERR_UNAVAILABLE;
  87. };
  88. bool DirAccessFlash::file_exists(String p_file) {
  89. GLOBAL_LOCK_FUNCTION
  90. if (p_file.is_rel_path())
  91. p_file=current_dir+"/"+p_file;
  92. else
  93. p_file=fix_path(p_file);
  94. struct stat flags;
  95. bool success = (stat(p_file.utf8().get_data(),&flags)==0);
  96. if (success && S_ISDIR(flags.st_mode)) {
  97. success=false;
  98. }
  99. return success;
  100. };
  101. bool DirAccessFlash::dir_exists(String p_dir) {
  102. GLOBAL_LOCK_FUNCTION
  103. if (p_dir.is_rel_path())
  104. p_dir=current_dir+"/"+p_dir;
  105. else
  106. p_dir=fix_path(p_dir);
  107. struct stat flags;
  108. bool success = (stat(p_dir.utf8().get_data(),&flags)==0);
  109. if (success && S_ISDIR(flags.st_mode)) {
  110. return true;
  111. }
  112. return false;
  113. };
  114. size_t DirAccessFlash::get_space_left() {
  115. return 0;
  116. };
  117. Error DirAccessFlash::rename(String p_from, String p_to) {
  118. return FAILED;
  119. };
  120. Error DirAccessFlash::remove(String p_name) {
  121. return FAILED;
  122. };
  123. extern char* psp_drive;
  124. DirAccessFlash::DirAccessFlash() {
  125. dir_stream=0;
  126. current_dir=".";
  127. _cisdir=false;
  128. /* determine drive count */
  129. change_dir(current_dir);
  130. }
  131. DirAccessFlash::~DirAccessFlash() {
  132. list_dir_end();
  133. };