editor_export_preset.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /**************************************************************************/
  2. /* editor_export_preset.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 "editor_export.h"
  31. bool EditorExportPreset::_set(const StringName &p_name, const Variant &p_value) {
  32. if (values.has(p_name)) {
  33. values[p_name] = p_value;
  34. EditorExport::singleton->save_presets();
  35. if (update_visibility[p_name]) {
  36. notify_property_list_changed();
  37. }
  38. return true;
  39. }
  40. return false;
  41. }
  42. bool EditorExportPreset::_get(const StringName &p_name, Variant &r_ret) const {
  43. if (values.has(p_name)) {
  44. r_ret = values[p_name];
  45. return true;
  46. }
  47. return false;
  48. }
  49. void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const {
  50. for (const PropertyInfo &E : properties) {
  51. if (platform->get_export_option_visibility(this, E.name, values)) {
  52. p_list->push_back(E);
  53. }
  54. }
  55. }
  56. Ref<EditorExportPlatform> EditorExportPreset::get_platform() const {
  57. return platform;
  58. }
  59. void EditorExportPreset::update_files() {
  60. {
  61. Vector<String> to_remove;
  62. for (const String &E : selected_files) {
  63. if (!FileAccess::exists(E)) {
  64. to_remove.push_back(E);
  65. }
  66. }
  67. for (int i = 0; i < to_remove.size(); ++i) {
  68. selected_files.erase(to_remove[i]);
  69. }
  70. }
  71. {
  72. Vector<String> to_remove;
  73. for (const KeyValue<String, FileExportMode> &E : customized_files) {
  74. if (!FileAccess::exists(E.key) && !DirAccess::exists(E.key)) {
  75. to_remove.push_back(E.key);
  76. }
  77. }
  78. for (int i = 0; i < to_remove.size(); ++i) {
  79. customized_files.erase(to_remove[i]);
  80. }
  81. }
  82. }
  83. Vector<String> EditorExportPreset::get_files_to_export() const {
  84. Vector<String> files;
  85. for (const String &E : selected_files) {
  86. files.push_back(E);
  87. }
  88. return files;
  89. }
  90. Dictionary EditorExportPreset::get_customized_files() const {
  91. Dictionary files;
  92. for (const KeyValue<String, FileExportMode> &E : customized_files) {
  93. String mode;
  94. switch (E.value) {
  95. case MODE_FILE_NOT_CUSTOMIZED: {
  96. continue;
  97. } break;
  98. case MODE_FILE_STRIP: {
  99. mode = "strip";
  100. } break;
  101. case MODE_FILE_KEEP: {
  102. mode = "keep";
  103. } break;
  104. case MODE_FILE_REMOVE: {
  105. mode = "remove";
  106. }
  107. }
  108. files[E.key] = mode;
  109. }
  110. return files;
  111. }
  112. int EditorExportPreset::get_customized_files_count() const {
  113. return customized_files.size();
  114. }
  115. void EditorExportPreset::set_customized_files(const Dictionary &p_files) {
  116. for (const Variant *key = p_files.next(nullptr); key; key = p_files.next(key)) {
  117. EditorExportPreset::FileExportMode mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;
  118. String value = p_files[*key];
  119. if (value == "strip") {
  120. mode = EditorExportPreset::MODE_FILE_STRIP;
  121. } else if (value == "keep") {
  122. mode = EditorExportPreset::MODE_FILE_KEEP;
  123. } else if (value == "remove") {
  124. mode = EditorExportPreset::MODE_FILE_REMOVE;
  125. }
  126. set_file_export_mode(*key, mode);
  127. }
  128. }
  129. void EditorExportPreset::set_name(const String &p_name) {
  130. name = p_name;
  131. EditorExport::singleton->save_presets();
  132. }
  133. String EditorExportPreset::get_name() const {
  134. return name;
  135. }
  136. void EditorExportPreset::set_runnable(bool p_enable) {
  137. runnable = p_enable;
  138. EditorExport::singleton->save_presets();
  139. }
  140. bool EditorExportPreset::is_runnable() const {
  141. return runnable;
  142. }
  143. void EditorExportPreset::set_dedicated_server(bool p_enable) {
  144. dedicated_server = p_enable;
  145. EditorExport::singleton->save_presets();
  146. }
  147. bool EditorExportPreset::is_dedicated_server() const {
  148. return dedicated_server;
  149. }
  150. void EditorExportPreset::set_export_filter(ExportFilter p_filter) {
  151. export_filter = p_filter;
  152. EditorExport::singleton->save_presets();
  153. }
  154. EditorExportPreset::ExportFilter EditorExportPreset::get_export_filter() const {
  155. return export_filter;
  156. }
  157. void EditorExportPreset::set_include_filter(const String &p_include) {
  158. include_filter = p_include;
  159. EditorExport::singleton->save_presets();
  160. }
  161. String EditorExportPreset::get_include_filter() const {
  162. return include_filter;
  163. }
  164. void EditorExportPreset::set_export_path(const String &p_path) {
  165. export_path = p_path;
  166. /* NOTE(SonerSound): if there is a need to implement a PropertyHint that specifically indicates a relative path,
  167. * this should be removed. */
  168. if (export_path.is_absolute_path()) {
  169. String res_path = OS::get_singleton()->get_resource_dir();
  170. export_path = res_path.path_to_file(export_path);
  171. }
  172. EditorExport::singleton->save_presets();
  173. }
  174. String EditorExportPreset::get_export_path() const {
  175. return export_path;
  176. }
  177. void EditorExportPreset::set_exclude_filter(const String &p_exclude) {
  178. exclude_filter = p_exclude;
  179. EditorExport::singleton->save_presets();
  180. }
  181. String EditorExportPreset::get_exclude_filter() const {
  182. return exclude_filter;
  183. }
  184. void EditorExportPreset::add_export_file(const String &p_path) {
  185. selected_files.insert(p_path);
  186. EditorExport::singleton->save_presets();
  187. }
  188. void EditorExportPreset::remove_export_file(const String &p_path) {
  189. selected_files.erase(p_path);
  190. EditorExport::singleton->save_presets();
  191. }
  192. bool EditorExportPreset::has_export_file(const String &p_path) {
  193. return selected_files.has(p_path);
  194. }
  195. void EditorExportPreset::set_file_export_mode(const String &p_path, EditorExportPreset::FileExportMode p_mode) {
  196. if (p_mode == FileExportMode::MODE_FILE_NOT_CUSTOMIZED) {
  197. customized_files.erase(p_path);
  198. } else {
  199. customized_files.insert(p_path, p_mode);
  200. }
  201. EditorExport::singleton->save_presets();
  202. }
  203. EditorExportPreset::FileExportMode EditorExportPreset::get_file_export_mode(const String &p_path, EditorExportPreset::FileExportMode p_default) const {
  204. HashMap<String, FileExportMode>::ConstIterator i = customized_files.find(p_path);
  205. if (i) {
  206. return i->value;
  207. }
  208. return p_default;
  209. }
  210. void EditorExportPreset::set_custom_features(const String &p_custom_features) {
  211. custom_features = p_custom_features;
  212. EditorExport::singleton->save_presets();
  213. }
  214. String EditorExportPreset::get_custom_features() const {
  215. return custom_features;
  216. }
  217. void EditorExportPreset::set_enc_in_filter(const String &p_filter) {
  218. enc_in_filters = p_filter;
  219. EditorExport::singleton->save_presets();
  220. }
  221. String EditorExportPreset::get_enc_in_filter() const {
  222. return enc_in_filters;
  223. }
  224. void EditorExportPreset::set_enc_ex_filter(const String &p_filter) {
  225. enc_ex_filters = p_filter;
  226. EditorExport::singleton->save_presets();
  227. }
  228. String EditorExportPreset::get_enc_ex_filter() const {
  229. return enc_ex_filters;
  230. }
  231. void EditorExportPreset::set_enc_pck(bool p_enabled) {
  232. enc_pck = p_enabled;
  233. EditorExport::singleton->save_presets();
  234. }
  235. bool EditorExportPreset::get_enc_pck() const {
  236. return enc_pck;
  237. }
  238. void EditorExportPreset::set_enc_directory(bool p_enabled) {
  239. enc_directory = p_enabled;
  240. EditorExport::singleton->save_presets();
  241. }
  242. bool EditorExportPreset::get_enc_directory() const {
  243. return enc_directory;
  244. }
  245. void EditorExportPreset::set_script_encryption_key(const String &p_key) {
  246. script_key = p_key;
  247. EditorExport::singleton->save_presets();
  248. }
  249. String EditorExportPreset::get_script_encryption_key() const {
  250. return script_key;
  251. }
  252. EditorExportPreset::EditorExportPreset() {}