godotsharp_dirs.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 "core/os/dir_access.h"
  32. #include "core/os/os.h"
  33. #include "core/project_settings.h"
  34. #ifdef TOOLS_ENABLED
  35. #include "core/version.h"
  36. #include "editor/editor_settings.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. String data_editor_tools_dir;
  87. String data_editor_prebuilt_api_dir;
  88. #endif
  89. String data_mono_etc_dir;
  90. String data_mono_lib_dir;
  91. #ifdef WINDOWS_ENABLED
  92. String data_mono_bin_dir;
  93. #endif
  94. private:
  95. _GodotSharpDirs() {
  96. res_data_dir = "res://.mono";
  97. res_metadata_dir = res_data_dir.plus_file("metadata");
  98. res_assemblies_dir = res_data_dir.plus_file("assemblies");
  99. res_config_dir = res_data_dir.plus_file("etc").plus_file("mono");
  100. // TODO use paths from csproj
  101. res_temp_dir = res_data_dir.plus_file("temp");
  102. res_temp_assemblies_base_dir = res_temp_dir.plus_file("bin");
  103. res_temp_assemblies_dir = res_temp_assemblies_base_dir.plus_file(_get_expected_build_config());
  104. mono_user_dir = _get_mono_user_dir();
  105. mono_logs_dir = mono_user_dir.plus_file("mono_logs");
  106. #ifdef TOOLS_ENABLED
  107. mono_solutions_dir = mono_user_dir.plus_file("solutions");
  108. build_logs_dir = mono_user_dir.plus_file("build_logs");
  109. String name = ProjectSettings::get_singleton()->get("application/config/name");
  110. if (name.empty()) {
  111. name = "UnnamedProject";
  112. }
  113. String base_path = ProjectSettings::get_singleton()->globalize_path("res://");
  114. sln_filepath = base_path.plus_file(name + ".sln");
  115. csproj_filepath = base_path.plus_file(name + ".csproj");
  116. #endif
  117. String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
  118. #ifdef TOOLS_ENABLED
  119. String data_dir_root = exe_dir.plus_file("GodotSharp");
  120. data_editor_tools_dir = data_dir_root.plus_file("Tools");
  121. data_editor_prebuilt_api_dir = data_dir_root.plus_file("Api");
  122. String data_mono_root_dir = data_dir_root.plus_file("Mono");
  123. data_mono_etc_dir = data_mono_root_dir.plus_file("etc");
  124. data_mono_lib_dir = data_mono_root_dir.plus_file("lib");
  125. #ifdef WINDOWS_ENABLED
  126. data_mono_bin_dir = data_mono_root_dir.plus_file("bin");
  127. #endif
  128. #ifdef OSX_ENABLED
  129. if (!DirAccess::exists(data_editor_tools_dir)) {
  130. data_editor_tools_dir = exe_dir.plus_file("../Frameworks/GodotSharp/Tools");
  131. }
  132. if (!DirAccess::exists(data_editor_prebuilt_api_dir)) {
  133. data_editor_prebuilt_api_dir = exe_dir.plus_file("../Frameworks/GodotSharp/Api");
  134. }
  135. if (!DirAccess::exists(data_mono_root_dir)) {
  136. data_mono_etc_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/etc");
  137. data_mono_lib_dir = exe_dir.plus_file("../Frameworks/GodotSharp/Mono/lib");
  138. }
  139. #endif
  140. #else
  141. String appname = OS::get_singleton()->get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/name"));
  142. String data_dir_root = exe_dir.plus_file("data_" + appname);
  143. if (!DirAccess::exists(data_dir_root)) {
  144. data_dir_root = exe_dir.plus_file("data_Godot");
  145. }
  146. String data_mono_root_dir = data_dir_root.plus_file("Mono");
  147. data_mono_etc_dir = data_mono_root_dir.plus_file("etc");
  148. data_mono_lib_dir = data_mono_root_dir.plus_file("lib");
  149. #ifdef WINDOWS_ENABLED
  150. data_mono_bin_dir = data_mono_root_dir.plus_file("bin");
  151. #endif
  152. #ifdef OSX_ENABLED
  153. if (!DirAccess::exists(data_mono_root_dir)) {
  154. data_mono_etc_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/etc");
  155. data_mono_lib_dir = exe_dir.plus_file("../Frameworks/GodotSharp/Mono/lib");
  156. }
  157. #endif
  158. #endif
  159. }
  160. _GodotSharpDirs(const _GodotSharpDirs &);
  161. _GodotSharpDirs &operator=(const _GodotSharpDirs &);
  162. public:
  163. static _GodotSharpDirs &get_singleton() {
  164. static _GodotSharpDirs singleton;
  165. return singleton;
  166. }
  167. };
  168. String get_res_data_dir() {
  169. return _GodotSharpDirs::get_singleton().res_data_dir;
  170. }
  171. String get_res_metadata_dir() {
  172. return _GodotSharpDirs::get_singleton().res_metadata_dir;
  173. }
  174. String get_res_assemblies_dir() {
  175. return _GodotSharpDirs::get_singleton().res_assemblies_dir;
  176. }
  177. String get_res_config_dir() {
  178. return _GodotSharpDirs::get_singleton().res_config_dir;
  179. }
  180. String get_res_temp_dir() {
  181. return _GodotSharpDirs::get_singleton().res_temp_dir;
  182. }
  183. String get_res_temp_assemblies_base_dir() {
  184. return _GodotSharpDirs::get_singleton().res_temp_assemblies_base_dir;
  185. }
  186. String get_res_temp_assemblies_dir() {
  187. return _GodotSharpDirs::get_singleton().res_temp_assemblies_dir;
  188. }
  189. String get_mono_user_dir() {
  190. return _GodotSharpDirs::get_singleton().mono_user_dir;
  191. }
  192. String get_mono_logs_dir() {
  193. return _GodotSharpDirs::get_singleton().mono_logs_dir;
  194. }
  195. #ifdef TOOLS_ENABLED
  196. String get_mono_solutions_dir() {
  197. return _GodotSharpDirs::get_singleton().mono_solutions_dir;
  198. }
  199. String get_build_logs_dir() {
  200. return _GodotSharpDirs::get_singleton().build_logs_dir;
  201. }
  202. String get_project_sln_path() {
  203. return _GodotSharpDirs::get_singleton().sln_filepath;
  204. }
  205. String get_project_csproj_path() {
  206. return _GodotSharpDirs::get_singleton().csproj_filepath;
  207. }
  208. String get_data_editor_tools_dir() {
  209. return _GodotSharpDirs::get_singleton().data_editor_tools_dir;
  210. }
  211. String get_data_editor_prebuilt_api_dir() {
  212. return _GodotSharpDirs::get_singleton().data_editor_prebuilt_api_dir;
  213. }
  214. #endif
  215. String get_data_mono_etc_dir() {
  216. return _GodotSharpDirs::get_singleton().data_mono_etc_dir;
  217. }
  218. String get_data_mono_lib_dir() {
  219. return _GodotSharpDirs::get_singleton().data_mono_lib_dir;
  220. }
  221. #ifdef WINDOWS_ENABLED
  222. String get_data_mono_bin_dir() {
  223. return _GodotSharpDirs::get_singleton().data_mono_bin_dir;
  224. }
  225. #endif
  226. } // namespace GodotSharpDirs