editor_file_system.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*************************************************************************/
  2. /* editor_file_system.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef EDITOR_FILE_SYSTEM_H
  30. #define EDITOR_FILE_SYSTEM_H
  31. #include "scene/main/node.h"
  32. #include "os/thread.h"
  33. #include "os/dir_access.h"
  34. #include "set.h"
  35. #include "os/thread_safe.h"
  36. class FileAccess;
  37. class EditorProgressBG;
  38. class EditorFileSystemDirectory : public Object {
  39. OBJ_TYPE( EditorFileSystemDirectory,Object );
  40. String name;
  41. EditorFileSystemDirectory *parent;
  42. Vector<EditorFileSystemDirectory*> subdirs;
  43. struct ImportMeta {
  44. struct Source {
  45. String path;
  46. String md5;
  47. uint64_t modified_time;
  48. bool missing;
  49. };
  50. Vector<Source> sources;
  51. String import_editor;
  52. bool enabled;
  53. };
  54. struct FileInfo {
  55. String file;
  56. String type;
  57. uint64_t modified_time;
  58. ImportMeta meta;
  59. };
  60. Vector<FileInfo> files;
  61. static void _bind_methods();
  62. friend class EditorFileSystem;
  63. public:
  64. String get_name();
  65. String get_path() const;
  66. int get_subdir_count() const;
  67. EditorFileSystemDirectory *get_subdir(int p_idx);
  68. int get_file_count() const;
  69. String get_file(int p_idx) const;
  70. String get_file_path(int p_idx) const;
  71. String get_file_type(int p_idx) const;
  72. bool get_file_meta(int p_idx) const;
  73. bool is_missing_sources(int p_idx) const;
  74. Vector<String> get_missing_sources(int p_idx) const;
  75. EditorFileSystemDirectory *get_parent();
  76. EditorFileSystemDirectory();
  77. ~EditorFileSystemDirectory();
  78. };
  79. class EditorFileSystem : public Node {
  80. OBJ_TYPE( EditorFileSystem, Node );
  81. _THREAD_SAFE_CLASS_
  82. struct SceneItem {
  83. String file;
  84. String path;
  85. String type;
  86. uint64_t modified_time;
  87. EditorFileSystemDirectory::ImportMeta meta;
  88. };
  89. struct DirItem {
  90. uint64_t modified_time;
  91. String path;
  92. String name;
  93. Vector<DirItem*> dirs;
  94. Vector<SceneItem*> files;
  95. ~DirItem();
  96. };
  97. float total;
  98. bool use_threads;
  99. Thread *thread;
  100. static void _thread_func(void *_userdata);
  101. DirItem *scandir;
  102. DirItem *rootdir;
  103. bool abort_scan;
  104. bool scanning;
  105. EditorFileSystemDirectory* _update_tree(DirItem *p_item);
  106. void _scan_scenes();
  107. void _load_type_cache();
  108. EditorFileSystemDirectory *filesystem;
  109. static EditorFileSystem *singleton;
  110. struct FileCache {
  111. String type;
  112. uint64_t modification_time;
  113. EditorFileSystemDirectory::ImportMeta meta;
  114. };
  115. struct DirCache {
  116. uint64_t modification_time;
  117. Set<String> files;
  118. Set<String> subdirs;
  119. };
  120. static EditorFileSystemDirectory::ImportMeta _get_meta(const String& p_path);
  121. bool _check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta,EditorProgressBG *ep=NULL);
  122. DirItem* _scan_dir(DirAccess *da,Set<String> &extensions,String p_name,float p_from,float p_range,const String& p_path,HashMap<String,FileCache> &file_cache,HashMap<String,DirCache> &dir_cache,EditorProgressBG& p_prog);
  123. void _save_type_cache_fs(DirItem *p_dir,FileAccess *p_file);
  124. bool _find_file(const String& p_file,EditorFileSystemDirectory ** r_d, int &r_file_pos) const;
  125. void _scan_sources(EditorFileSystemDirectory *p_dir,EditorProgressBG *ep);
  126. int md_count;
  127. Thread *thread_sources;
  128. bool scanning_sources;
  129. bool scanning_sources_done;
  130. int ss_amount;
  131. static void _thread_func_sources(void *_userdata);
  132. List<String> sources_changed;
  133. static void _resource_saved(const String& p_path);
  134. protected:
  135. void _notification(int p_what);
  136. static void _bind_methods();
  137. public:
  138. static EditorFileSystem* get_singleton() { return singleton; }
  139. EditorFileSystemDirectory *get_filesystem();
  140. bool is_scanning() const;
  141. float get_scanning_progress() const;
  142. void scan();
  143. void scan_sources();
  144. void get_changed_sources(List<String> *r_changed);
  145. void update_file(const String& p_file);
  146. EditorFileSystemDirectory *get_path(const String& p_path);
  147. String get_file_type(const String& p_file) const;
  148. EditorFileSystem();
  149. ~EditorFileSystem();
  150. };
  151. #endif // EDITOR_FILE_SYSTEM_H