#include #include #include #include #include #include "FileUtils.h" #include "nfd.h" namespace AtomicEditor { FileUtils::FileUtils(Context* context) : Object(context) { } FileUtils::~FileUtils() { } String FileUtils::OpenProjectFileDialog() { nfdchar_t *outPath = NULL; nfdresult_t result = NFD_OpenDialog( "atomic", NULL, &outPath); String fullpath; if (outPath && result == NFD_OKAY) { fullpath = outPath; } GetSubsystem()->RaiseWindow(); if (outPath) free(outPath); return fullpath; } bool FileUtils::CreateDirs(const String& folder) { FileSystem* fileSystem = GetSubsystem(); Poco::File dirs(folder.CString()); dirs.createDirectories(); return fileSystem->DirExists(folder); } String FileUtils::NewProjectFileDialog() { String projectPath; nfdchar_t *outPath = NULL; nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder for your project", NULL, &outPath); if (outPath && result == NFD_OKAY) { projectPath = outPath; } GetSubsystem()->RaiseWindow(); if (outPath) free(outPath); return projectPath; } String FileUtils::GetBuildPath(const String& defaultPath) { String buildPath; nfdchar_t *outPath = NULL; nfdresult_t result = NFD_ChooseDirectory( "Please choose the build folder", defaultPath.Length() ? defaultPath.CString() : NULL, &outPath); if (outPath && result == NFD_OKAY) { buildPath = outPath; } if (outPath) free(outPath); GetSubsystem()->RaiseWindow(); return GetInternalPath(buildPath); } String FileUtils::GetAndroidSDKPath(const String& defaultPath) { String sdkPath; nfdchar_t *outPath = NULL; nfdresult_t result = NFD_ChooseDirectory( "Please choose the root folder of your Android SDK", defaultPath.Length() ? defaultPath.CString() : NULL, &outPath); if (outPath && result == NFD_OKAY) { sdkPath = outPath; } if (outPath) free(outPath); GetSubsystem()->RaiseWindow(); return GetInternalPath(sdkPath); } void FileUtils::RevealInFinder(const String& fullpath) { FileSystem* fs = GetSubsystem(); if (fs->DirExists(fullpath)) fs->SystemOpen(fullpath); else if (fs->FileExists(fullpath)) fs->SystemOpen(GetPath(fullpath)); } }