editor_export_preset.cpp 9.5 KB

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