FileUtils.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <Poco/File.h>
  2. #include "AtomicEditor.h"
  3. #include <Atomic/Core/Context.h>
  4. #include <Atomic/Core/StringUtils.h>
  5. #include <Atomic/IO/FileSystem.h>
  6. #include <Atomic/Graphics/Graphics.h>
  7. #include "FileUtils.h"
  8. #include "nfd.h"
  9. namespace AtomicEditor
  10. {
  11. FileUtils::FileUtils(Context* context) :
  12. Object(context)
  13. {
  14. }
  15. FileUtils::~FileUtils()
  16. {
  17. }
  18. String FileUtils::OpenProjectFileDialog()
  19. {
  20. nfdchar_t *outPath = NULL;
  21. nfdresult_t result = NFD_OpenDialog( "atomic",
  22. NULL,
  23. &outPath);
  24. String fullpath;
  25. if (outPath && result == NFD_OKAY)
  26. {
  27. fullpath = outPath;
  28. }
  29. GetSubsystem<Graphics>()->RaiseWindow();
  30. if (outPath)
  31. free(outPath);
  32. return fullpath;
  33. }
  34. bool FileUtils::CreateDirs(const String& folder)
  35. {
  36. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  37. Poco::File dirs(folder.CString());
  38. dirs.createDirectories();
  39. return fileSystem->DirExists(folder);
  40. }
  41. String FileUtils::NewProjectFileDialog()
  42. {
  43. String projectPath;
  44. nfdchar_t *outPath = NULL;
  45. nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder for your project",
  46. NULL,
  47. &outPath);
  48. if (outPath && result == NFD_OKAY)
  49. {
  50. projectPath = outPath;
  51. }
  52. GetSubsystem<Graphics>()->RaiseWindow();
  53. if (outPath)
  54. free(outPath);
  55. return projectPath;
  56. }
  57. void FileUtils::RevealInFinder(const String& fullpath)
  58. {
  59. FileSystem* fs = GetSubsystem<FileSystem>();
  60. if (fs->DirExists(fullpath))
  61. fs->SystemOpen(fullpath);
  62. else if (fs->FileExists(fullpath))
  63. fs->SystemOpen(GetPath(fullpath));
  64. }
  65. }