diff --git a/Editor/src/Commands/Commands/Commands.cpp b/Editor/src/Commands/Commands/Commands.cpp index 523bf033..a180c88d 100644 --- a/Editor/src/Commands/Commands/Commands.cpp +++ b/Editor/src/Commands/Commands/Commands.cpp @@ -1,8 +1,11 @@ #include "Commands.h" #include + #include "src/FileSystem/FileSystem.h" +#include + namespace NuakeEditor { bool SaveSceneCommand::Execute() diff --git a/Editor/src/ComponentsPanel/MaterialEditor.cpp b/Editor/src/ComponentsPanel/MaterialEditor.cpp index 20ec0c30..22928088 100644 --- a/Editor/src/ComponentsPanel/MaterialEditor.cpp +++ b/Editor/src/ComponentsPanel/MaterialEditor.cpp @@ -1,9 +1,12 @@ #include "MaterialEditor.h" -#include -#include -#include #include "../Misc/InterfaceFonts.h" +#include #include +#include + +#include +#include + void MaterialEditor::Draw(Ref material) { diff --git a/Editor/src/ComponentsPanel/NetScriptPanel.cpp b/Editor/src/ComponentsPanel/NetScriptPanel.cpp index a9cfe740..ed046e0c 100644 --- a/Editor/src/ComponentsPanel/NetScriptPanel.cpp +++ b/Editor/src/ComponentsPanel/NetScriptPanel.cpp @@ -1,10 +1,14 @@ #include "NetScriptPanel.h" + #include "../Windows/FileSystemUI.h" -#include + +#include #include "src/FileSystem/FileSystem.h" #include +#include #include + void NetScriptPanel::Draw(Nuake::Entity entity) { if (!entity.HasComponent()) diff --git a/Editor/src/ComponentsPanel/ScriptPanel.cpp b/Editor/src/ComponentsPanel/ScriptPanel.cpp index 45eacdb8..e712f7e7 100644 --- a/Editor/src/ComponentsPanel/ScriptPanel.cpp +++ b/Editor/src/ComponentsPanel/ScriptPanel.cpp @@ -1,6 +1,7 @@ #include "ScriptPanel.h" #include "../Windows/FileSystemUI.h" #include +#include "src/FileSystem/FileDialog.h" #include "src/FileSystem/FileSystem.h" void ScriptPanel::Draw(Nuake::Entity entity) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 960e39ed..58ce433d 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -53,6 +53,9 @@ #include #include "../ScriptingContext/ScriptingContext.h" #include + +#include + #include namespace Nuake { diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index fcbc8baa..9a514d56 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 445cc8c5..611e1a32 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -12,9 +12,10 @@ #include #include "../Misc/PopupHelper.h" - +#include #include "src/Scene/Systems/WadConverter.h" #include "../Misc/ThumbnailManager.h" + #include namespace Nuake diff --git a/Editor/src/Windows/MapImporterWindow.cpp b/Editor/src/Windows/MapImporterWindow.cpp index 54e938fd..55548088 100644 --- a/Editor/src/Windows/MapImporterWindow.cpp +++ b/Editor/src/Windows/MapImporterWindow.cpp @@ -7,11 +7,16 @@ #include #include #include +#include #include +#include +#include +#include #include + void MapImporterWindow::Draw() { auto& io = ImGui::GetIO(); diff --git a/Editor/src/Windows/NewProjectWindow.cpp b/Editor/src/Windows/NewProjectWindow.cpp index c7f6eaa2..601ed421 100644 --- a/Editor/src/Windows/NewProjectWindow.cpp +++ b/Editor/src/Windows/NewProjectWindow.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "src/FileSystem/FileSystem.h" #include #include diff --git a/Editor/src/Windows/ProjectInterface.cpp b/Editor/src/Windows/ProjectInterface.cpp index ccc0b87c..512dc2cf 100644 --- a/Editor/src/Windows/ProjectInterface.cpp +++ b/Editor/src/Windows/ProjectInterface.cpp @@ -1,9 +1,12 @@ #include "ProjectInterface.h" -#include + #include "Engine.h" +#include #include "src/FileSystem/FileSystem.h" #include #include + +#include //#include "ImGuiTextHelper.h" namespace Nuake { diff --git a/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp b/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp index 890b99d0..144f0995 100644 --- a/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp +++ b/Editor/src/Windows/ProjectSettings/ProjectSettingsWindow.cpp @@ -1,6 +1,7 @@ #include "ProjectSettingsWindow.h" #include #include "../../Misc/InterfaceFonts.h" +#include #include "src/FileSystem/FileSystem.h" #include "../EditorInterface.h" #include "../../Commands/Commands/Commands.h" diff --git a/Editor/src/Windows/WelcomeWindow.cpp b/Editor/src/Windows/WelcomeWindow.cpp index 9569e59c..7ef977fa 100644 --- a/Editor/src/Windows/WelcomeWindow.cpp +++ b/Editor/src/Windows/WelcomeWindow.cpp @@ -5,6 +5,7 @@ #include "../Misc/InterfaceFonts.h" #include +#include #include "src/FileSystem/FileSystem.h" #include #include diff --git a/Nuake/src/Core/OS.cpp b/Nuake/src/Core/OS.cpp index 6b309198..733a3bb3 100644 --- a/Nuake/src/Core/OS.cpp +++ b/Nuake/src/Core/OS.cpp @@ -22,11 +22,12 @@ #include "GLFW/glfw3.h" #include "GLFW/glfw3native.h" +#include "imgui/imgui.h" #include -#include -#include #include +#include +#include namespace Nuake { diff --git a/Nuake/src/FileSystem/FileDialog.cpp b/Nuake/src/FileSystem/FileDialog.cpp new file mode 100644 index 00000000..4a8e68e5 --- /dev/null +++ b/Nuake/src/FileSystem/FileDialog.cpp @@ -0,0 +1,189 @@ +#include "FileDialog.h" + +#include "Engine.h" + +#include + +// Platform specific stuff +// Windows +#ifdef NK_WIN +#define GLFW_EXPOSE_NATIVE_WIN32 +#include "GLFW/glfw3native.h" +#include +#include +#endif + +// Linux +#ifdef NK_LINUX +#include "gtk/gtk.h" +#endif + + +using namespace Nuake; + +std::string FileDialog::OpenFile(const std::string_view& filter) +{ + std::string filePath; +#ifdef NK_WIN + OPENFILENAMEA ofn; + CHAR szFile[260] = { 0 }; + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle()); + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = filter.data(); + ofn.nFilterIndex = 1; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; + if (GetOpenFileNameA(&ofn) == TRUE) + { + filePath = std::string(ofn.lpstrFile); + } + +#endif + +#ifdef NK_LINUX + GtkWidget *dialog; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; + gint res; + + dialog = gtk_file_chooser_dialog_new("Open File", + NULL, + action, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Open", + GTK_RESPONSE_ACCEPT, + NULL); + + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); + + if (filter) { + GtkFileFilter *file_filter = gtk_file_filter_new(); + gtk_file_filter_set_name(file_filter, "Filter Name"); + gtk_file_filter_add_pattern(file_filter, filter); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter); + } + + res = gtk_dialog_run(GTK_DIALOG(dialog)); + + if (res == GTK_RESPONSE_ACCEPT) { + char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + filePath = filename; + g_free(filename); + } + + gtk_widget_destroy(dialog); +#endif + return filePath; +} + +std::string FileDialog::SaveFile(const std::string_view& filter) +{ +#ifdef NK_WIN + OPENFILENAMEA ofn; + CHAR szFile[260] = { 0 }; + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle()); + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = filter.data(); + ofn.nFilterIndex = 1; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT; + if (GetSaveFileNameA(&ofn) == TRUE) + { + return ofn.lpstrFile; + } +#endif + +#ifdef NK_LINUX + GtkWidget *dialog; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; + gint res; + + gtk_init(NULL, NULL); + + dialog = gtk_file_chooser_dialog_new("Save File", + NULL, + action, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Save", + GTK_RESPONSE_ACCEPT, + NULL); + + GtkFileFilter *file_filter = gtk_file_filter_new(); + gtk_file_filter_set_name(file_filter, filter); + gtk_file_filter_add_pattern(file_filter, "*.*"); // You can customize this pattern + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter); + + res = gtk_dialog_run(GTK_DIALOG(dialog)); + if (res == GTK_RESPONSE_ACCEPT) + { + char *filename; + GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog); + filename = gtk_file_chooser_get_filename(chooser); + std::string result(filename); + g_free(filename); + gtk_widget_destroy(dialog); + return result; + } + else + { + gtk_widget_destroy(dialog); + return std::string(); + } +#endif + + return std::string(); +} + +std::string FileDialog::OpenFolder() +{ + std::string folderPath; + +#ifdef NK_WIN + BROWSEINFOA bi; + CHAR szFolder[260] = { 0 }; + ZeroMemory(&bi, sizeof(BROWSEINFO)); + bi.lpszTitle = "Select a Folder"; + bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; + bi.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle()); + bi.pszDisplayName = szFolder; + LPITEMIDLIST pidl = SHBrowseForFolderA(&bi); + if (pidl != NULL) + { + SHGetPathFromIDListA(pidl, szFolder); + folderPath = std::string(szFolder); + CoTaskMemFree(pidl); + } +#endif + +#ifdef NK_LINUX + GtkWidget* dialog; + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; + gint res; + + dialog = gtk_file_chooser_dialog_new("Select Folder", + NULL, + action, + "_Cancel", + GTK_RESPONSE_CANCEL, + "_Select", + GTK_RESPONSE_ACCEPT, + NULL); + + res = gtk_dialog_run(GTK_DIALOG(dialog)); + + if (res == GTK_RESPONSE_ACCEPT) { + char* foldername = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + folderPath = foldername; + g_free(foldername); + } + + gtk_widget_destroy(dialog); +#endif + + return folderPath; +} \ No newline at end of file diff --git a/Nuake/src/FileSystem/FileDialog.h b/Nuake/src/FileSystem/FileDialog.h new file mode 100644 index 00000000..2ce31930 --- /dev/null +++ b/Nuake/src/FileSystem/FileDialog.h @@ -0,0 +1,14 @@ +#pragma once +#include "src/Core/Core.h" + +namespace Nuake +{ + class FileDialog + { + public: + static std::string OpenFile(const std::string_view& filter); + static std::string SaveFile(const std::string_view& filter); + + static std::string OpenFolder(); + }; +} diff --git a/Nuake/src/FileSystem/FileSystem.cpp b/Nuake/src/FileSystem/FileSystem.cpp index 3da547b8..993afc51 100644 --- a/Nuake/src/FileSystem/FileSystem.cpp +++ b/Nuake/src/FileSystem/FileSystem.cpp @@ -3,437 +3,250 @@ #include "Engine.h" #include "src/Core/OS.h" -#include - -#ifdef NK_WIN -#define GLFW_EXPOSE_NATIVE_WIN32 - -#include "GLFW/glfw3native.h" -#include - -#endif - -#ifdef NK_LINUX -#include "gtk/gtk.h" -#endif - -#include -#include -#include -#include "filewatch/FileWatch.hpp" - #include "Directory.h" #include "File.h" -namespace Nuake -{ - namespace fs = std::filesystem; +#include "filewatch/FileWatch.hpp" - std::string FileDialog::OpenFile(const char* filter) - { - std::string filePath; -#ifdef NK_WIN - OPENFILENAMEA ofn; - CHAR szFile[260] = { 0 }; - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle()); - ofn.lpstrFile = szFile; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = filter; - ofn.nFilterIndex = 1; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; - if (GetOpenFileNameA(&ofn) == TRUE) - { - filePath = std::string(ofn.lpstrFile); - } +#include -#endif +using namespace Nuake; -#ifdef NK_LINUX - GtkWidget *dialog; - GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; - gint res; - - dialog = gtk_file_chooser_dialog_new("Open File", - NULL, - action, - "_Cancel", - GTK_RESPONSE_CANCEL, - "_Open", - GTK_RESPONSE_ACCEPT, - NULL); - - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); - - if (filter) { - GtkFileFilter *file_filter = gtk_file_filter_new(); - gtk_file_filter_set_name(file_filter, "Filter Name"); - gtk_file_filter_add_pattern(file_filter, filter); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter); - } - - res = gtk_dialog_run(GTK_DIALOG(dialog)); - - if (res == GTK_RESPONSE_ACCEPT) { - char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - filePath = filename; - g_free(filename); - } - - gtk_widget_destroy(dialog); -#endif - return filePath; - } - - std::string FileDialog::SaveFile(const char* filter) - { -#ifdef NK_WIN - OPENFILENAMEA ofn; - CHAR szFile[260] = { 0 }; - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle()); - ofn.lpstrFile = szFile; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = filter; - ofn.nFilterIndex = 1; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT; - if (GetSaveFileNameA(&ofn) == TRUE) - { - return ofn.lpstrFile; - } -#endif - -#ifdef NK_LINUX - GtkWidget *dialog; - GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE; - gint res; - - gtk_init(NULL, NULL); - - dialog = gtk_file_chooser_dialog_new("Save File", - NULL, - action, - "_Cancel", - GTK_RESPONSE_CANCEL, - "_Save", - GTK_RESPONSE_ACCEPT, - NULL); - - GtkFileFilter *file_filter = gtk_file_filter_new(); - gtk_file_filter_set_name(file_filter, filter); - gtk_file_filter_add_pattern(file_filter, "*.*"); // You can customize this pattern - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter); - - res = gtk_dialog_run(GTK_DIALOG(dialog)); - if (res == GTK_RESPONSE_ACCEPT) - { - char *filename; - GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog); - filename = gtk_file_chooser_get_filename(chooser); - std::string result(filename); - g_free(filename); - gtk_widget_destroy(dialog); - return result; - } - else - { - gtk_widget_destroy(dialog); - return std::string(); - } -#endif - - return std::string(); - } - - std::string FileDialog::OpenFolder() - { - std::string folderPath; - -#ifdef NK_WIN - BROWSEINFOA bi; - CHAR szFolder[260] = { 0 }; - ZeroMemory(&bi, sizeof(BROWSEINFO)); - bi.lpszTitle = "Select a Folder"; - bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; - bi.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle()); - bi.pszDisplayName = szFolder; - LPITEMIDLIST pidl = SHBrowseForFolderA(&bi); - if (pidl != NULL) - { - SHGetPathFromIDListA(pidl, szFolder); - folderPath = std::string(szFolder); - CoTaskMemFree(pidl); - } -#endif - -#ifdef NK_LINUX - GtkWidget* dialog; - GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; - gint res; - - dialog = gtk_file_chooser_dialog_new("Select Folder", - NULL, - action, - "_Cancel", - GTK_RESPONSE_CANCEL, - "_Select", - GTK_RESPONSE_ACCEPT, - NULL); - - res = gtk_dialog_run(GTK_DIALOG(dialog)); - - if (res == GTK_RESPONSE_ACCEPT) { - char* foldername = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - folderPath = foldername; - g_free(foldername); - } - - gtk_widget_destroy(dialog); -#endif - - return folderPath; - } - - std::string FileSystem::Root = ""; - - Ref FileSystem::RootDirectory; - Ref> FileSystem::RootFileWatch; +std::string FileSystem::Root = ""; +Ref FileSystem::RootDirectory; +Ref> FileSystem::RootFileWatch; - - void FileSystem::ScanDirectory(Ref directory) +void FileSystem::ScanDirectory(Ref directory) +{ + for (const auto& entry : std::filesystem::directory_iterator(directory->FullPath)) { - for (const auto& entry : std::filesystem::directory_iterator(directory->FullPath)) + if (entry.is_directory()) { - if (entry.is_directory()) - { - Ref newDir = CreateRef(); - newDir->FullPath = entry.path().string(); - newDir->Name = entry.path().filename().string(); + Ref newDir = CreateRef(); + newDir->FullPath = entry.path().string(); + newDir->Name = entry.path().filename().string(); - newDir->Parent = directory; - ScanDirectory(newDir); - directory->Directories.push_back(newDir); - } - else if (entry.is_regular_file()) - { - std::filesystem::path currentPath = entry.path(); - std::string absolutePath = currentPath.string(); - std::string name = currentPath.filename().string(); - std::string extension = currentPath.extension().string(); - Ref newFile = CreateRef(directory, absolutePath, name, extension); - directory->Files.push_back(newFile); - } + newDir->Parent = directory; + ScanDirectory(newDir); + directory->Directories.push_back(newDir); + } + else if (entry.is_regular_file()) + { + std::filesystem::path currentPath = entry.path(); + std::string absolutePath = currentPath.string(); + std::string name = currentPath.filename().string(); + std::string extension = currentPath.extension().string(); + Ref newFile = CreateRef(directory, absolutePath, name, extension); + directory->Files.push_back(newFile); } } +} - bool FileSystem::DirectoryExists(const std::string& path, bool absolute) - { - const std::string& finalPath = absolute ? path : Root + path; +bool FileSystem::DirectoryExists(const std::string& path, bool absolute) +{ + const std::string& finalPath = absolute ? path : Root + path; - return std::filesystem::exists(finalPath) && std::filesystem::is_directory(finalPath); - } + return std::filesystem::exists(finalPath) && std::filesystem::is_directory(finalPath); +} - bool FileSystem::MakeDirectory(const std::string& path, bool absolute) - { - return std::filesystem::create_directories(absolute ? path : FileSystem::Root + path); - } +bool FileSystem::MakeDirectory(const std::string& path, bool absolute) +{ + return std::filesystem::create_directories(absolute ? path : FileSystem::Root + path); +} - bool FileSystem::FileExists(const std::string& path, bool absolute) - { - std::string fullPath = absolute ? path : FileSystem::Root + path; - return std::filesystem::exists(fullPath) && std::filesystem::is_regular_file(fullPath); - } +bool FileSystem::FileExists(const std::string& path, bool absolute) +{ + std::string fullPath = absolute ? path : FileSystem::Root + path; + return std::filesystem::exists(fullPath) && std::filesystem::is_regular_file(fullPath); +} - void FileSystem::SetRootDirectory(const std::string path) - { - Root = path; - RootFileWatch = CreateRef>( - path, [&](const std::string& path, const filewatch::Event& event) +void FileSystem::SetRootDirectory(const std::string path) +{ + Root = path; + RootFileWatch = CreateRef>( + path, [&](const std::string& path, const filewatch::Event& event) + { + std::string normalizedPath = String::ReplaceSlash(path); + + // Detect if its a file and not a folder. + if (!FileSystem::FileExists(normalizedPath)) { - std::string normalizedPath = String::ReplaceSlash(path); + return; + } - // Detect if its a file and not a folder. - if (!FileSystem::FileExists(normalizedPath)) + if(Ref file = GetFile(normalizedPath); file) + { + if (file->GetFileType() == FileType::Unkown) { return; } - if(Ref file = GetFile(normalizedPath); file) + Logger::Log(normalizedPath + " event: " + filewatch::event_to_string(event), "filewatcher", VERBOSE); + + if (event == filewatch::Event::modified) { - if (file->GetFileType() == FileType::Unkown) - { - return; - } - - Logger::Log(normalizedPath + " event: " + filewatch::event_to_string(event), "filewatcher", VERBOSE); - - if (event == filewatch::Event::modified) - { - file->SetHasBeenModified(true); - } + file->SetHasBeenModified(true); } + } - } - ); - Scan(); - } + } + ); + Scan(); +} - void FileSystem::Scan() - { - RootDirectory = CreateRef(Root); - ScanDirectory(RootDirectory); - } +void FileSystem::Scan() +{ + RootDirectory = CreateRef(Root); + ScanDirectory(RootDirectory); +} - std::string FileSystem::AbsoluteToRelative(const std::string& path) - { - const fs::path rootPath(Root); - const fs::path absolutePath(path); - return fs::relative(absolutePath, rootPath).generic_string(); - } +std::string FileSystem::AbsoluteToRelative(const std::string& path) +{ + const std::filesystem::path rootPath(Root); + const std::filesystem::path absolutePath(path); + return std::filesystem::relative(absolutePath, rootPath).generic_string(); +} - std::string FileSystem::RelativeToAbsolute(const std::string& path) - { - return Root + path; - } +std::string FileSystem::RelativeToAbsolute(const std::string& path) +{ + return Root + path; +} - std::string FileSystem::GetParentPath(const std::string& fullPath) - { - std::filesystem::path pathObj(fullPath); - auto returnvalue = pathObj.parent_path().string(); - return returnvalue + "/"; - } +std::string FileSystem::GetParentPath(const std::string& fullPath) +{ + std::filesystem::path pathObj(fullPath); + auto returnvalue = pathObj.parent_path().string(); + return returnvalue + "/"; +} - std::string FileSystem::ReadFile(const std::string& path, bool absolute) - { - std::string finalPath = path; - if (!absolute) - finalPath = Root + path; +std::string FileSystem::ReadFile(const std::string& path, bool absolute) +{ + std::string finalPath = path; + if (!absolute) + finalPath = Root + path; - std::ifstream myReadFile(finalPath, std::ios::in | std::ios::binary); - std::string fileContent = ""; - std::string allFile = ""; + std::ifstream myReadFile(finalPath, std::ios::in | std::ios::binary); + std::string fileContent = ""; + std::string allFile = ""; - char bom[3]; - myReadFile.read(bom, 3); + char bom[3]; + myReadFile.read(bom, 3); - // Check for UTF-8 BOM (EF BB BF) - if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) + // Check for UTF-8 BOM (EF BB BF) + if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) + { + myReadFile.seekg(3); + } + else + { + myReadFile.seekg(0); + } + + // Use a while loop together with the getline() function to read the file line by line + while (getline(myReadFile, fileContent)) + { + allFile.append(fileContent + "\n"); + } + + // Close the file + myReadFile.close(); + return allFile; +} + +std::ofstream FileSystem::fileWriter; +bool FileSystem::BeginWriteFile(const std::string path, bool absolute) +{ + fileWriter = std::ofstream(); + fileWriter.open(absolute ? path : FileSystem::Root + path); + + return false; +} + +bool FileSystem::WriteLine(const std::string line) +{ + fileWriter << line.c_str(); + + return true; +} + +void FileSystem::EndWriteFile() +{ + fileWriter.close(); +} + +uintmax_t FileSystem::DeleteFileFromPath(const std::string& path) +{ + return std::remove(path.c_str()); +} + +uintmax_t FileSystem::DeleteFolder(const std::string& path) +{ + return std::filesystem::remove_all(path.c_str()); +} + +std::string FileSystem::GetConfigFolderPath() +{ + std::string subFolderPath = OS::GetConfigFolderPath().append("/Nuake/"); + if (!DirectoryExists(subFolderPath, true)) + { + MakeDirectory(subFolderPath); + } + + return subFolderPath; +} + +Ref FileSystem::GetFileTree() +{ + return RootDirectory; +} + +Ref FileSystem::GetFile(const std::string& path) +{ + // Note, Might be broken on other platforms. + auto splits = String::Split(path, '/'); + + int currentDepth = -1; + std::string currentDirName = "."; + Ref currentDirComparator = RootDirectory; + while (currentDirName == currentDirComparator->Name) + { + currentDepth++; + currentDirName = splits[currentDepth]; + + // Find next directory + for (auto& d : currentDirComparator->Directories) { - myReadFile.seekg(3); - } - else - { - myReadFile.seekg(0); - } - - // Use a while loop together with the getline() function to read the file line by line - while (getline(myReadFile, fileContent)) - { - allFile.append(fileContent + "\n"); - } - - // Close the file - myReadFile.close(); - return allFile; - } - - std::ofstream FileSystem::fileWriter; - bool FileSystem::BeginWriteFile(const std::string path, bool absolute) - { - fileWriter = std::ofstream(); - fileWriter.open(absolute ? path : FileSystem::Root + path); - - return false; - } - - bool FileSystem::WriteLine(const std::string line) - { - fileWriter << line.c_str(); - - return true; - } - - void FileSystem::EndWriteFile() - { - fileWriter.close(); - } - - uintmax_t FileSystem::DeleteFileFromPath(const std::string& path) - { - return std::remove(path.c_str()); - } - - uintmax_t FileSystem::DeleteFolder(const std::string& path) - { - return std::filesystem::remove_all(path.c_str()); - } - - std::string FileSystem::GetConfigFolderPath() - { - std::string subFolderPath = OS::GetConfigFolderPath().append("/Nuake/"); - if (!DirectoryExists(subFolderPath, true)) - { - MakeDirectory(subFolderPath); - } - - return subFolderPath; - } - - Ref FileSystem::GetFileTree() - { - return RootDirectory; - } - - Ref FileSystem::GetFile(const std::string& path) - { - // Note, Might be broken on other platforms. - auto splits = String::Split(path, '/'); - - int currentDepth = -1; - std::string currentDirName = "."; - Ref currentDirComparator = RootDirectory; - while (currentDirName == currentDirComparator->Name) - { - currentDepth++; - currentDirName = splits[currentDepth]; - - // Find next directory - for (auto& d : currentDirComparator->Directories) + if (d->Name == currentDirName) { - if (d->Name == currentDirName) - { - currentDirComparator = d; - } - } - - // Find in files if can't find in directories. - for (auto& f : currentDirComparator->Files) - { - if (f->GetName() == currentDirName) - { - return f; - } + currentDirComparator = d; } } - return nullptr; + // Find in files if can't find in directories. + for (auto& f : currentDirComparator->Files) + { + if (f->GetName() == currentDirName) + { + return f; + } + } } - std::string FileSystem::GetFileNameFromPath(const std::string& path) - { - const auto& split = String::Split(path, '/'); - return String::Split(split[split.size() - 1], '.')[0]; - } + return nullptr; +} + +std::string FileSystem::GetFileNameFromPath(const std::string& path) +{ + const auto& split = String::Split(path, '/'); + return String::Split(split[split.size() - 1], '.')[0]; +} - Directory::Directory(const std::string& path) - { - Files = std::vector>(); - Directories = std::vector>(); - Name = FileSystem::AbsoluteToRelative(path); - FullPath = path; - } -} \ No newline at end of file +Directory::Directory(const std::string& path) +{ + Files = std::vector>(); + Directories = std::vector>(); + Name = FileSystem::AbsoluteToRelative(path); + FullPath = path; +} diff --git a/Nuake/src/FileSystem/FileSystem.h b/Nuake/src/FileSystem/FileSystem.h index b16d3fd1..d527dfa1 100644 --- a/Nuake/src/FileSystem/FileSystem.h +++ b/Nuake/src/FileSystem/FileSystem.h @@ -1,11 +1,5 @@ #pragma once #include "src/Core/Core.h" -#include "String.h" - -#include -#include -#include -#include namespace filewatch { @@ -15,14 +9,6 @@ namespace filewatch namespace Nuake { - class FileDialog - { - public: - static std::string OpenFile(const char* filter); - static std::string SaveFile(const char* filter); - static std::string OpenFolder(); - }; - class Directory; class File; diff --git a/Nuake/src/Resource/Project.cpp b/Nuake/src/Resource/Project.cpp index 56c4214b..350d39a9 100644 --- a/Nuake/src/Resource/Project.cpp +++ b/Nuake/src/Resource/Project.cpp @@ -7,6 +7,7 @@ #include +#include #include #include diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 6b0d72c8..dc5a6689 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -23,6 +23,7 @@ #include "Engine.h" #include "src/Core/Maths.h" #include "src/FileSystem/FileSystem.h" +#include "src/FileSystem/FileDialog.h" #include "src/Scene/Components.h" #include "src/Scene/Components/BoxCollider.h" @@ -31,12 +32,12 @@ #include "src/Scene/Components/SkinnedModelComponent.h" #include "src/Scene/Components/BoneComponent.h" +#include + #include #include #include #include -#include - namespace Nuake { diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index eb1e534e..e5c0bb49 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -11,10 +11,12 @@ #include "NetModules/InputNetAPI.h" #include "NetModules/SceneNetAPI.h" +#include +#include +#include #include #include -#include void ExceptionCallback(std::string_view InMessage) diff --git a/Nuake/src/Scripting/ScriptingEngineNet.h b/Nuake/src/Scripting/ScriptingEngineNet.h index 427249ee..4df07f19 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.h +++ b/Nuake/src/Scripting/ScriptingEngineNet.h @@ -11,6 +11,7 @@ namespace Coral class Type; } +#include #include #include #include diff --git a/Nuake/src/Scripting/WrenScript.cpp b/Nuake/src/Scripting/WrenScript.cpp index 3e613d57..24ebf5a3 100644 --- a/Nuake/src/Scripting/WrenScript.cpp +++ b/Nuake/src/Scripting/WrenScript.cpp @@ -7,6 +7,8 @@ #include +#include + namespace Nuake { WrenScript::WrenScript(Ref file, bool isEntityScript)