godotsharp_dirs.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*************************************************************************/
  2. /* godotsharp_dirs.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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_settings_path().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. if (OS::get_singleton()->has_environment("APPDATA")) {
  63. String app_data = OS::get_singleton()->get_environment("APPDATA").replace("\\", "/");
  64. settings_path = app_data.plus_file(String(_MKSTR(VERSION_SHORT_NAME)).capitalize());
  65. } else if (OS::get_singleton()->has_environment("HOME")) {
  66. String home = OS::get_singleton()->get_environment("HOME");
  67. settings_path = home.plus_file("." + String(_MKSTR(VERSION_SHORT_NAME)).to_lower());
  68. }
  69. }
  70. return settings_path.plus_file("mono");
  71. }
  72. #else
  73. return OS::get_singleton()->get_data_dir().plus_file("mono");
  74. #endif
  75. }
  76. class _GodotSharpDirs {
  77. public:
  78. String res_data_dir;
  79. String res_metadata_dir;
  80. String res_assemblies_dir;
  81. String res_config_dir;
  82. String res_temp_dir;
  83. String res_temp_assemblies_base_dir;
  84. String res_temp_assemblies_dir;
  85. String mono_user_dir;
  86. String mono_logs_dir;
  87. #ifdef TOOLS_ENABLED
  88. String mono_solutions_dir;
  89. String build_logs_dir;
  90. String sln_filepath;
  91. String csproj_filepath;
  92. #endif
  93. private:
  94. _GodotSharpDirs() {
  95. res_data_dir = "res://.mono";
  96. res_metadata_dir = res_data_dir.plus_file("metadata");
  97. res_assemblies_dir = res_data_dir.plus_file("assemblies");
  98. res_config_dir = res_data_dir.plus_file("etc").plus_file("mono");
  99. // TODO use paths from csproj
  100. res_temp_dir = res_data_dir.plus_file("temp");
  101. res_temp_assemblies_base_dir = res_temp_dir.plus_file("bin");
  102. res_temp_assemblies_dir = res_temp_assemblies_base_dir.plus_file(_get_expected_build_config());
  103. mono_user_dir = _get_mono_user_dir();
  104. mono_logs_dir = mono_user_dir.plus_file("mono_logs");
  105. #ifdef TOOLS_ENABLED
  106. mono_solutions_dir = mono_user_dir.plus_file("solutions");
  107. build_logs_dir = mono_user_dir.plus_file("build_logs");
  108. String name = ProjectSettings::get_singleton()->get("application/config/name");
  109. if (name.empty()) {
  110. name = "UnnamedProject";
  111. }
  112. String base_path = String("res://") + name;
  113. sln_filepath = ProjectSettings::get_singleton()->globalize_path(base_path + ".sln");
  114. csproj_filepath = ProjectSettings::get_singleton()->globalize_path(base_path + ".csproj");
  115. #endif
  116. }
  117. _GodotSharpDirs(const _GodotSharpDirs &);
  118. _GodotSharpDirs &operator=(const _GodotSharpDirs &);
  119. public:
  120. static _GodotSharpDirs &get_singleton() {
  121. static _GodotSharpDirs singleton;
  122. return singleton;
  123. }
  124. };
  125. String get_res_data_dir() {
  126. return _GodotSharpDirs::get_singleton().res_data_dir;
  127. }
  128. String get_res_metadata_dir() {
  129. return _GodotSharpDirs::get_singleton().res_metadata_dir;
  130. }
  131. String get_res_assemblies_dir() {
  132. return _GodotSharpDirs::get_singleton().res_assemblies_dir;
  133. }
  134. String get_res_config_dir() {
  135. return _GodotSharpDirs::get_singleton().res_config_dir;
  136. }
  137. String get_res_temp_dir() {
  138. return _GodotSharpDirs::get_singleton().res_temp_dir;
  139. }
  140. String get_res_temp_assemblies_base_dir() {
  141. return _GodotSharpDirs::get_singleton().res_temp_assemblies_base_dir;
  142. }
  143. String get_res_temp_assemblies_dir() {
  144. return _GodotSharpDirs::get_singleton().res_temp_assemblies_dir;
  145. }
  146. String get_mono_user_dir() {
  147. return _GodotSharpDirs::get_singleton().mono_user_dir;
  148. }
  149. String get_mono_logs_dir() {
  150. return _GodotSharpDirs::get_singleton().mono_logs_dir;
  151. }
  152. #ifdef TOOLS_ENABLED
  153. String get_mono_solutions_dir() {
  154. return _GodotSharpDirs::get_singleton().mono_solutions_dir;
  155. }
  156. String get_build_logs_dir() {
  157. return _GodotSharpDirs::get_singleton().build_logs_dir;
  158. }
  159. String get_project_sln_path() {
  160. return _GodotSharpDirs::get_singleton().sln_filepath;
  161. }
  162. String get_project_csproj_path() {
  163. return _GodotSharpDirs::get_singleton().csproj_filepath;
  164. }
  165. #endif
  166. }