FileUtils.cpp 4.3 KB

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