FileUtils.cpp 4.6 KB

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