godotsharp_dirs.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*************************************************************************/
  2. /* godotsharp_dirs.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "godotsharp_dirs.h"
  31. #include "os/os.h"
  32. #ifdef TOOLS_ENABLED
  33. #include "editor/editor_settings.h"
  34. #include "os/dir_access.h"
  35. #include "project_settings.h"
  36. #include "version.h"
  37. #endif
  38. namespace GodotSharpDirs {
  39. String _get_expected_build_config() {
  40. #ifdef TOOLS_ENABLED
  41. return "Tools";
  42. #else
  43. #ifdef DEBUG_ENABLED
  44. return "Debug";
  45. #else
  46. return "Release";
  47. #endif
  48. #endif
  49. }
  50. String _get_mono_user_dir() {
  51. #ifdef TOOLS_ENABLED
  52. if (EditorSettings::get_singleton()) {
  53. return EditorSettings::get_singleton()->get_data_dir().plus_file("mono");
  54. } else {
  55. String settings_path;
  56. String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
  57. DirAccessRef d = DirAccess::create_for_path(exe_dir);
  58. if (d->file_exists("._sc_") || d->file_exists("_sc_")) {
  59. // contain yourself
  60. settings_path = exe_dir.plus_file("editor_data");
  61. } else {
  62. settings_path = OS::get_singleton()->get_data_path().plus_file(OS::get_singleton()->get_godot_dir_name());
  63. }
  64. return settings_path.plus_file("mono");
  65. }
  66. #else
  67. return OS::get_singleton()->get_user_data_dir().plus_file("mono");
  68. #endif
  69. }
  70. class _GodotSharpDirs {
  71. public:
  72. String res_data_dir;
  73. String res_metadata_dir;
  74. String res_assemblies_dir;
  75. String res_config_dir;
  76. String res_temp_dir;
  77. String res_temp_assemblies_base_dir;
  78. String res_temp_assemblies_dir;
  79. String mono_user_dir;
  80. String mono_logs_dir;
  81. #ifdef TOOLS_ENABLED
  82. String mono_solutions_dir;
  83. String build_logs_dir;
  84. String sln_filepath;
  85. String csproj_filepath;
  86. #endif
  87. private:
  88. _GodotSharpDirs() {
  89. res_data_dir = "res://.mono";
  90. res_metadata_dir = res_data_dir.plus_file("metadata");
  91. res_assemblies_dir = res_data_dir.plus_file("assemblies");
  92. res_config_dir = res_data_dir.plus_file("etc").plus_file("mono");
  93. // TODO use paths from csproj
  94. res_temp_dir = res_data_dir.plus_file("temp");
  95. res_temp_assemblies_base_dir = res_temp_dir.plus_file("bin");
  96. res_temp_assemblies_dir = res_temp_assemblies_base_dir.plus_file(_get_expected_build_config());
  97. mono_user_dir = _get_mono_user_dir();
  98. mono_logs_dir = mono_user_dir.plus_file("mono_logs");
  99. #ifdef TOOLS_ENABLED
  100. mono_solutions_dir = mono_user_dir.plus_file("solutions");
  101. build_logs_dir = mono_user_dir.plus_file("build_logs");
  102. String name = ProjectSettings::get_singleton()->get("application/config/name");
  103. if (name.empty()) {
  104. name = "UnnamedProject";
  105. }
  106. String base_path = String("res://") + name;
  107. sln_filepath = ProjectSettings::get_singleton()->globalize_path(base_path + ".sln");
  108. csproj_filepath = ProjectSettings::get_singleton()->globalize_path(base_path + ".csproj");
  109. #endif
  110. }
  111. _GodotSharpDirs(const _GodotSharpDirs &);
  112. _GodotSharpDirs &operator=(const _GodotSharpDirs &);
  113. public:
  114. static _GodotSharpDirs &get_singleton() {
  115. static _GodotSharpDirs singleton;
  116. return singleton;
  117. }
  118. };
  119. String get_res_data_dir() {
  120. return _GodotSharpDirs::get_singleton().res_data_dir;
  121. }
  122. String get_res_metadata_dir() {
  123. return _GodotSharpDirs::get_singleton().res_metadata_dir;
  124. }
  125. String get_res_assemblies_dir() {
  126. return _GodotSharpDirs::get_singleton().res_assemblies_dir;
  127. }
  128. String get_res_config_dir() {
  129. return _GodotSharpDirs::get_singleton().res_config_dir;
  130. }
  131. String get_res_temp_dir() {
  132. return _GodotSharpDirs::get_singleton().res_temp_dir;
  133. }
  134. String get_res_temp_assemblies_base_dir() {
  135. return _GodotSharpDirs::get_singleton().res_temp_assemblies_base_dir;
  136. }
  137. String get_res_temp_assemblies_dir() {
  138. return _GodotSharpDirs::get_singleton().res_temp_assemblies_dir;
  139. }
  140. String get_mono_user_dir() {
  141. return _GodotSharpDirs::get_singleton().mono_user_dir;
  142. }
  143. String get_mono_logs_dir() {
  144. return _GodotSharpDirs::get_singleton().mono_logs_dir;
  145. }
  146. #ifdef TOOLS_ENABLED
  147. String get_mono_solutions_dir() {
  148. return _GodotSharpDirs::get_singleton().mono_solutions_dir;
  149. }
  150. String get_build_logs_dir() {
  151. return _GodotSharpDirs::get_singleton().build_logs_dir;
  152. }
  153. String get_project_sln_path() {
  154. return _GodotSharpDirs::get_singleton().sln_filepath;
  155. }
  156. String get_project_csproj_path() {
  157. return _GodotSharpDirs::get_singleton().csproj_filepath;
  158. }
  159. #endif
  160. } // namespace GodotSharpDirs