FileUtils.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. void FileUtils::RevealInFinder(const String& fullpath)
  89. {
  90. FileSystem* fs = GetSubsystem<FileSystem>();
  91. if (fs->DirExists(fullpath))
  92. fs->SystemOpen(fullpath);
  93. else if (fs->FileExists(fullpath))
  94. fs->SystemOpen(GetPath(fullpath));
  95. }
  96. }