FileUtils.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. void FileUtils::RevealInFinder(const String& fullpath)
  57. {
  58. FileSystem* fs = GetSubsystem<FileSystem>();
  59. if (fs->DirExists(fullpath))
  60. fs->SystemOpen(fullpath);
  61. else if (fs->FileExists(fullpath))
  62. fs->SystemOpen(GetPath(fullpath));
  63. }
  64. }