ProjectUtils.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <Atomic/Core/Context.h>
  6. #include <Atomic/IO/FileSystem.h>
  7. #include <Atomic/Graphics/Graphics.h>
  8. #include "ProjectUtils.h"
  9. #include "AEEvents.h"
  10. #include "nfd.h"
  11. #include "../AEEditor.h"
  12. namespace AtomicEditor
  13. {
  14. ProjectUtils::ProjectUtils(Context* context) :
  15. Object(context)
  16. {
  17. SubscribeToEvent(E_EDITORSHUTDOWN, HANDLER(ProjectUtils, HandleEditorShutdown));
  18. }
  19. void ProjectUtils::OpenProjectFileDialog()
  20. {
  21. nfdchar_t *outPath = NULL;
  22. nfdresult_t result = NFD_OpenDialog( "atomic",
  23. NULL,
  24. &outPath);
  25. if (outPath && result == NFD_OKAY)
  26. {
  27. String fullpath = outPath;
  28. Editor* editor = GetSubsystem<Editor>();
  29. editor->LoadProject(fullpath);
  30. }
  31. GetSubsystem<Graphics>()->RaiseWindow();
  32. if (outPath)
  33. free(outPath);
  34. }
  35. String ProjectUtils::GetBuildPath(const String& defaultPath)
  36. {
  37. String buildPath;
  38. nfdchar_t *outPath = NULL;
  39. nfdresult_t result = NFD_ChooseDirectory( "Please choose the build folder",
  40. defaultPath.Length() ? defaultPath.CString() : NULL,
  41. &outPath);
  42. if (outPath && result == NFD_OKAY)
  43. {
  44. buildPath = outPath;
  45. }
  46. if (outPath)
  47. free(outPath);
  48. GetSubsystem<Graphics>()->RaiseWindow();
  49. return GetInternalPath(buildPath);
  50. }
  51. String ProjectUtils::GetMobileProvisionPath()
  52. {
  53. nfdchar_t *outPath = NULL;
  54. nfdresult_t result = NFD_OpenDialog( "mobileprovision",
  55. NULL,
  56. &outPath);
  57. String fullpath;
  58. if (outPath && result == NFD_OKAY)
  59. {
  60. fullpath = outPath;
  61. }
  62. GetSubsystem<Graphics>()->RaiseWindow();
  63. if (outPath)
  64. free(outPath);
  65. return fullpath;
  66. }
  67. String ProjectUtils::GetAndroidSDKPath(const String& defaultPath)
  68. {
  69. String sdkPath;
  70. nfdchar_t *outPath = NULL;
  71. nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder of your Android SDK",
  72. defaultPath.Length() ? defaultPath.CString() : NULL,
  73. &outPath);
  74. if (outPath && result == NFD_OKAY)
  75. {
  76. sdkPath = outPath;
  77. }
  78. if (outPath)
  79. free(outPath);
  80. GetSubsystem<Graphics>()->RaiseWindow();
  81. return GetInternalPath(sdkPath);
  82. }
  83. String ProjectUtils::GetAntPath(const String& defaultPath)
  84. {
  85. String antPath;
  86. nfdchar_t *outPath = NULL;
  87. #ifdef ATOMIC_PLATFORM_WINDOWS
  88. String msg = "Please select the folder which contains ant.bat";
  89. #else
  90. String msg = "Please select the folder which contains the ant executable";
  91. #endif
  92. nfdresult_t result = NFD_ChooseDirectory( msg.CString(),
  93. defaultPath.Length() ? defaultPath.CString() : NULL,
  94. &outPath);
  95. if (outPath && result == NFD_OKAY)
  96. {
  97. antPath = outPath;
  98. }
  99. if (outPath)
  100. free(outPath);
  101. GetSubsystem<Graphics>()->RaiseWindow();
  102. return GetInternalPath(antPath);
  103. }
  104. String ProjectUtils::GetJDKRootPath(const String& defaultPath)
  105. {
  106. String jdkPath;
  107. nfdchar_t *outPath = NULL;
  108. nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder of your JDK",
  109. defaultPath.Length() ? defaultPath.CString() : NULL,
  110. &outPath);
  111. if (outPath && result == NFD_OKAY)
  112. {
  113. jdkPath = outPath;
  114. }
  115. if (outPath)
  116. free(outPath);
  117. GetSubsystem<Graphics>()->RaiseWindow();
  118. return GetInternalPath(jdkPath);
  119. }
  120. String ProjectUtils::NewProjectFileDialog()
  121. {
  122. String projectPath;
  123. nfdchar_t *outPath = NULL;
  124. nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder for your project",
  125. NULL,
  126. &outPath);
  127. if (outPath && result == NFD_OKAY)
  128. {
  129. projectPath = outPath;
  130. }
  131. GetSubsystem<Graphics>()->RaiseWindow();
  132. if (outPath)
  133. free(outPath);
  134. return projectPath;
  135. }
  136. void ProjectUtils::RevealInFinder(const String& fullpath)
  137. {
  138. FileSystem* fs = GetSubsystem<FileSystem>();
  139. if (fs->DirExists(fullpath))
  140. fs->SystemOpen(fullpath);
  141. else if (fs->FileExists(fullpath))
  142. fs->SystemOpen(GetPath(fullpath));
  143. }
  144. ProjectUtils::~ProjectUtils()
  145. {
  146. }
  147. void ProjectUtils::HandleEditorShutdown(StringHash eventType, VariantMap& eventData)
  148. {
  149. context_->RemoveSubsystem(GetType());
  150. }
  151. }