csharp_project.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*************************************************************************/
  2. /* csharp_project.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
  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 "csharp_project.h"
  31. #include "core/os/os.h"
  32. #include "core/project_settings.h"
  33. #include "../mono_gd/gd_mono_class.h"
  34. #include "../mono_gd/gd_mono_marshal.h"
  35. namespace CSharpProject {
  36. String generate_core_api_project(const String &p_dir, const Vector<String> &p_files) {
  37. _GDMONO_SCOPE_DOMAIN_(TOOLS_DOMAIN)
  38. GDMonoClass *klass = GDMono::get_singleton()->get_editor_tools_assembly()->get_class("GodotSharpTools.Project", "ProjectGenerator");
  39. Variant dir = p_dir;
  40. Variant compile_items = p_files;
  41. const Variant *args[2] = { &dir, &compile_items };
  42. MonoException *exc = NULL;
  43. MonoObject *ret = klass->get_method("GenCoreApiProject", 2)->invoke(NULL, args, &exc);
  44. if (exc) {
  45. GDMonoUtils::debug_print_unhandled_exception(exc);
  46. ERR_FAIL_V(String());
  47. }
  48. return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : String();
  49. }
  50. String generate_editor_api_project(const String &p_dir, const String &p_core_dll_path, const Vector<String> &p_files) {
  51. _GDMONO_SCOPE_DOMAIN_(TOOLS_DOMAIN)
  52. GDMonoClass *klass = GDMono::get_singleton()->get_editor_tools_assembly()->get_class("GodotSharpTools.Project", "ProjectGenerator");
  53. Variant dir = p_dir;
  54. Variant core_dll_path = p_core_dll_path;
  55. Variant compile_items = p_files;
  56. const Variant *args[3] = { &dir, &core_dll_path, &compile_items };
  57. MonoException *exc = NULL;
  58. MonoObject *ret = klass->get_method("GenEditorApiProject", 3)->invoke(NULL, args, &exc);
  59. if (exc) {
  60. GDMonoUtils::debug_print_unhandled_exception(exc);
  61. ERR_FAIL_V(String());
  62. }
  63. return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : String();
  64. }
  65. String generate_game_project(const String &p_dir, const String &p_name, const Vector<String> &p_files) {
  66. _GDMONO_SCOPE_DOMAIN_(TOOLS_DOMAIN)
  67. GDMonoClass *klass = GDMono::get_singleton()->get_editor_tools_assembly()->get_class("GodotSharpTools.Project", "ProjectGenerator");
  68. Variant dir = p_dir;
  69. Variant name = p_name;
  70. Variant compile_items = p_files;
  71. const Variant *args[3] = { &dir, &name, &compile_items };
  72. MonoException *exc = NULL;
  73. MonoObject *ret = klass->get_method("GenGameProject", 3)->invoke(NULL, args, &exc);
  74. if (exc) {
  75. GDMonoUtils::debug_print_unhandled_exception(exc);
  76. ERR_FAIL_V(String());
  77. }
  78. return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : String();
  79. }
  80. void add_item(const String &p_project_path, const String &p_item_type, const String &p_include) {
  81. _GDMONO_SCOPE_DOMAIN_(TOOLS_DOMAIN)
  82. GDMonoClass *klass = GDMono::get_singleton()->get_editor_tools_assembly()->get_class("GodotSharpTools.Project", "ProjectUtils");
  83. Variant project_path = p_project_path;
  84. Variant item_type = p_item_type;
  85. Variant include = p_include;
  86. const Variant *args[3] = { &project_path, &item_type, &include };
  87. MonoException *exc = NULL;
  88. klass->get_method("AddItemToProjectChecked", 3)->invoke(NULL, args, &exc);
  89. if (exc) {
  90. GDMonoUtils::debug_print_unhandled_exception(exc);
  91. ERR_FAIL();
  92. }
  93. }
  94. } // namespace CSharpProject